#include #include #include #include #include <9p.h> #include "dat.h" #include "fns.h" void gopher(Url *u, Buq *qbody) { int p[2]; char buf[16*1024]; int n; switch(rfork(RFPROC|RFMEM|RFNOWAIT)) { case -1: buclose(qbody, "can't fork"); bufree(qbody); break; case 0: qbody->hdr = addkey(qbody->hdr, "Content-Type", "text/html"); qbody->url = u; pipe(p); switch(fork()) { case -1: buclose(qbody, "can't fork"); bufree(qbody); break; case 0: dup(p[0], 1); close(p[0]); close(p[1]); execl("/bin/aux/gopher2html", "gopher2html", u->host ? u->host : "", u->port ? u->port : "gopher", u->path ? u->path+1 : "", nil); buclose(qbody, "exec gopher2html: %r"); bufree(qbody); exits("exec gopher2html"); default: close(p[0]); while((n = read(p[1], buf, sizeof buf)) > 0) buwrite(qbody, buf, n); if(n < 0) { rerrstr(buf, sizeof buf); buclose(qbody, buf); bufree(qbody); } else { buclose(qbody, nil); } close(p[1]); exits(nil); } } }