implement Rooster; include "sys.m"; sys: Sys; include "draw.m"; draw: Draw; Context: import Draw; include "bufio.m"; bufio: Bufio; Iobuf: import bufio; include "string.m"; str: String; include "encoding.m"; enc : Encoding; include "ppm.m"; images : Images; Image : import images; include "vnc.m"; vnc : Vnc; Server, Rect : import vnc; Rooster: module { init: fn(nil: ref Context, nil: list of string); }; loadmods() { sys = load Sys Sys->PATH; draw = load Draw Draw->PATH; bufio = load Bufio Bufio->PATH; str = load String String->PATH; enc = load Encoding Encoding->BASE64PATH; vnc = load Vnc "/usr/maht/rooster/vnc.dis"; vnc->init(nil, nil); images = load Images "/usr/maht/rooster/ppm.dis"; images->init(nil, nil); } listener(s : chan of ref Iobuf, conn : Sys->Connection) { while(1) { (i, c) := sys->listen(conn); if(i==-1) return; c.dfd = sys->open(c.dir + "/data", sys->ORDWR); b := bufio->fopen(c.dfd, bufio->ORDWR); t := b.gets('\n'); while(t != nil && len(t) != 2) { sys->print("%s", t); t = b.gets('\n'); } b.puts("HTTP/1.1 200 OK \nContent-Type: text/javascript \n \n"); s <-= b; } } init(nil: ref Draw->Context, nil: list of string) { loadmods(); (i, c) := sys->announce("tcp!*!4005"); if(i==-1) return; s := chan of ref Iobuf; spawn listener(s, c); urlfd := bufio->open("/usr/maht/rooster/x", bufio->OREAD); url : string; b64 := ""; v : ref Server; for(b :=<- s; b!= nil; b =<- s) { if(b64 == "") { sys->sleep(10000); v = vnc->new_server("tcp!127.0.0.1!5902", "", 3, 1, 0); } else { v.send_framebuffer_request(0, ref Rect(0, 0, 1024, 768)); images->create_ppm(v.image, b64 + ".ppm"); } url = urlfd.gets('\n'); if(url[len(url)-1] == '\n') url = url[0:len(url)-1]; b64 = enc->enc(array of byte url); sys->print("b64 %s\n", b64); b.puts(sys->sprint("go('%s');\n", url)); b.flush(); b.close(); } }