patch follows to cleanup the httpd mkfile and remove imagemap, netlib_find, and netlib_history. these auxillary programs are pretty old. is there any argument for not removing these? i'd also like to get rid of the strange logging to /sys/log/httpd/^(0 1). diff -r 786a65cf4eb9 sys/man/8/httpd --- a/sys/man/8/httpd Wed May 20 15:38:56 2015 -0700 +++ b/sys/man/8/httpd Wed May 20 16:58:47 2015 -0700 @@ -1,6 +1,6 @@ .TH HTTPD 8 .SH NAME -httpd, save, imagemap, man2html, webls \- HTTP server +httpd, save, man2html, webls \- HTTP server .SH SYNOPSIS .B ip/httpd/httpd .RB [ -a @@ -30,9 +30,6 @@ .I method version uri .RI [ search ] .br -.B ip/httpd/imagemap -.I ... -.br .B ip/httpd/man2html .I ... .br @@ -201,18 +198,6 @@ or the first line of the body from a POST. It is used to record form submissions. .PP -.I Imagemap -processes an HTML imagemap query. -It looks up the point -.I search -in the image map file given by -.IR uri , -and returns a redirection to the appropriate page. -The map file defaults to NCSA format. -Any entries after a line starting with the word -.B #cern -are interpreted in CERN format. -.PP .I Man2html converts .IR man (6) diff -r 786a65cf4eb9 sys/src/cmd/ip/httpd/imagemap.c --- a/sys/src/cmd/ip/httpd/imagemap.c Wed May 20 15:38:56 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,320 +0,0 @@ -#include -#include -#include -#include "httpd.h" -#include "httpsrv.h" - -typedef struct Point Point; -typedef struct OkPoint OkPoint; -typedef struct Strings Strings; - -struct Point -{ - int x; - int y; -}; - -struct OkPoint -{ - Point p; - int ok; -}; - -struct Strings -{ - char *s1; - char *s2; -}; - -static char *me; - -int polytest(int, Point, Point, Point); -Strings getfield(char*); -OkPoint pt(char*); -char* translate(HConnect*, char*, char*); -Point sub(Point, Point); -float dist(Point, Point); - -void -main(int argc, char **argv) -{ - HConnect *c; - Hio *hout; - char *dest; - - me = "imagemap"; - c = init(argc, argv); - hout = &c->hout; - if(hparseheaders(c, HSTIMEOUT) < 0) - exits("failed"); - anonymous(c); - - if(strcmp(c->req.meth, "GET") != 0 && strcmp(c->req.meth, "HEAD") != 0){ - hunallowed(c, "GET, HEAD"); - exits("unallowed"); - } - if(c->head.expectother || c->head.expectcont){ - hfail(c, HExpectFail, nil); - exits("failed"); - } - dest = translate(c, c->req.uri, c->req.search); - - if(dest == nil){ - if(c->req.vermaj){ - hokheaders(c); - hprint(hout, "Content-type: text/html\r\n"); - hprint(hout, "\r\n"); - } - hprint(hout, "Nothing Found\n"); - hprint(hout, "Nothing satisfying your search request could be found.\n\n"); - hflush(hout); - writelog(c, "Reply: 200 imagemap %ld %ld\n", hout->seek, hout->seek); - exits(nil); - } - - if(http11(c) && strcmp(c->req.meth, "POST") == 0) - hredirected(c, "303 See Other", dest); - else - hredirected(c, "302 Found", dest); - exits(nil); -} - -char* -translate(HConnect *c, char *uri, char *search) -{ - Biobuf *b; - Strings ss; - OkPoint okp; - Point p, cen, q, start; - float close, d; - char *line, *to, *def, *s, *dst; - int n, inside, r, ncsa; - - if(search == nil){ - hfail(c, HNoData, me); - exits("failed"); - } - okp = pt(search); - if(!okp.ok){ - hfail(c, HBadSearch, me); - exits("failed"); - } - p = okp.p; - - b = Bopen(uri, OREAD); - if(b == nil){ - hfail(c, HNotFound, uri); - exits("failed"); - } - - to = nil; - def = nil; - dst = nil; - close = 0.; - ncsa = 1; - while(line = Brdline(b, '\n')){ - line[Blinelen(b)-1] = 0; - - ss = getfield(line); - s = ss.s1; - line = ss.s2; - if(ncsa){ - ss = getfield(line); - dst = ss.s1; - line = ss.s2; - } - if(strcmp(s, "#cern") == 0){ - ncsa = 0; - continue; - } - if(strcmp(s, "rect") == 0){ - ss = getfield(line); - s = ss.s1; - line = ss.s2; - okp = pt(s); - q = okp.p; - if(!okp.ok || q.x > p.x || q.y > p.y) - continue; - ss = getfield(line); - s = ss.s1; - line = ss.s2; - okp = pt(s); - q = okp.p; - if(!okp.ok || q.x < p.x || q.y < p.y) - continue; - if(!ncsa){ - ss = getfield(line); - dst = ss.s1; - } - return dst; - }else if(strcmp(s, "circle") == 0){ - ss = getfield(line); - s = ss.s1; - line = ss.s2; - okp = pt(s); - cen = okp.p; - if(!okp.ok) - continue; - ss = getfield(line); - s = ss.s1; - line = ss.s2; - if(ncsa){ - okp = pt(s); - if(!okp.ok) - continue; - if(dist(okp.p, cen) >= dist(p, cen)) - return dst; - }else{ - r = strtol(s, nil, 10); - ss = getfield(line); - dst = ss.s1; - d = (float)r * r; - if(d >= dist(p, cen)) - return dst; - } - }else if(strcmp(s, "poly") == 0){ - ss = getfield(line); - s = ss.s1; - line = ss.s2; - okp = pt(s); - start = okp.p; - if(!okp.ok) - continue; - inside = 0; - cen = start; - for(n = 1; ; n++){ - ss = getfield(line); - s = ss.s1; - line = ss.s2; - okp = pt(s); - q = okp.p; - if(!okp.ok) - break; - inside = polytest(inside, p, cen, q); - cen = q; - } - inside = polytest(inside, p, cen, start); - if(!ncsa) - dst = s; - if(n >= 3 && inside) - return dst; - }else if(strcmp(s, "point") == 0){ - ss = getfield(line); - s = ss.s1; - line = ss.s2; - okp = pt(s); - q = okp.p; - if(!okp.ok) - continue; - d = dist(p, q); - if(!ncsa){ - ss = getfield(line); - dst = ss.s1; - } - if(d == 0.) - return dst; - if(close == 0. || d < close){ - close = d; - to = dst; - } - }else if(strcmp(s, "default") == 0){ - if(!ncsa){ - ss = getfield(line); - dst = ss.s1; - } - def = dst; - } - } - if(to == nil) - to = def; - return to; -} - -int -polytest(int inside, Point p, Point b, Point a) -{ - Point pa, ba; - - if(b.y>a.y){ - pa=sub(p, a); - ba=sub(b, a); - }else{ - pa=sub(p, b); - ba=sub(a, b); - } - if(0<=pa.y && pa.y /tmp/search - sed 17q /tmp/search - -$LIBS: $LIBSOFILES - ar vu $LIBS $newprereq - rm $newprereq - # rm $newmember - cannot do this because of mk race - - -re:N: v.re - v.re redirect.urls - -none:VQ: - echo usage: mk all, install, installall, '$O'.cmd, cmd.install, or cmd.installall - echo usage: mk safeinstall, safeinstallall, cmd.safeinstallall, or cmd.safeinstallall - -$O.9down: 9down.$O whois.$O classify.$O $LIB - $LD -o $target $prereq - -$O.test9down: 9down4e.$O whois.$O classify.$O $LIB - $LD -o $target $prereq - -$O.testclassify: testclassify.$O whois.$O classify.$O $LIB - $LD -o $target $prereq - +$LIB: $LIBOFILES + ar vu $LIB $newprereq diff -r 786a65cf4eb9 sys/src/cmd/ip/httpd/netlib_find.c --- a/sys/src/cmd/ip/httpd/netlib_find.c Wed May 20 15:38:56 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,278 +0,0 @@ -/* invoked from /netlib/pub/search.html */ - -#include -#include -#include -#include "httpd.h" -#include "httpsrv.h" - -void bib_fmt(char*,char*); -void index_fmt(char*,char*); -void no_fmt(char*,char*); -int send(HConnect*); - -Hio *hout; - -/********** table of databases ************/ - -typedef struct DB DB; -struct DB -{ - int SELECT; /* value from search.html */ - char *log; /* abbreviation for logfile */ - int maxhit; /* maximum number of hits to return */ - char *file; /* searchfs database */ - void (*fmt)(char*,char*); /* convert one record to HTML */ - char *postlude; /* trailer text */ -}; - -DB db[] = -{ - {0, "netlib", 250, "/srv/netlib_DEFAULT", index_fmt, - "
browse netlib\r\n"}, - {1, "BibNet", 250, "/srv/netlib_bibnet", bib_fmt, - "
browse BibNet\r\n"}, - {2, "compgeom", 250, "/srv/netlib_compgeom", no_fmt, "\r\n"}, - {3, "approx", 250, "/srv/netlib_approximation", no_fmt, - "
hierarchical catalog\r\n"}, - {4, "siam", 50, "/srv/netlib_siam-Secret", no_fmt, "\r\n"}, - {-1,"",0,"",no_fmt,""} -}; - - - -/********** reformat database record as HTML ************/ - -void /* tr '\015' '\012' ("uncombline") */ -no_fmt(char*s,char*e) -{ - /* s = start, e = (one past) end of database record */ - char *p; - for(p = s; p%s\r\n",filename); - for(p = s; p%s\r\n",filename); - for(p = s; p%s", - filename,filename); - } - } -} - - -/********** main() calls httpheadget() calls send() ************/ - -void -main(int argc, char **argv) -{ - HConnect *c; - - c = init(argc, argv); - hout = &c->hout; - if(hparseheaders(c, HSTIMEOUT) >= 0) - send(c); - exits(nil); -} - -Biobuf Blist; - -Biobuf* -init800fs(char*name,char*pat) -{ - int fd800fs, n; - char*search; - - fd800fs = open(name, ORDWR); - if(fd800fs < 0) - exits("can't connect to 800fs server"); - if(mount(fd800fs, -1, "/mnt", MREPL, "") < 0) - exits("can't mount /mnt"); - fd800fs = open("/mnt/search", ORDWR); - n = strlen("search=")+strlen(pat)+1; - search = ezalloc(n); - strcpy(search,"search="); - strcat(search,pat); - write(fd800fs,search,n); - free(search); - Binit(&Blist, fd800fs,OREAD); - return(&Blist); -} - - -static char * -hq(char *text) -{ - int textlen = strlen(text), escapedlen = textlen; - char *escaped, *s, *w; - - for(s = text; *s; s++) - if(*s=='<' || *s=='>' || *s=='&') - escapedlen += 4; - escaped = ezalloc(escapedlen+1); - for(s = text, w = escaped; *s; s++){ - if(*s == '<'){ - strcpy(w, "<"); - w += 4; - }else if(*s == '>'){ - strcpy(w, ">"); - w += 4; - }else if(*s == '&'){ - strcpy(w, "&"); - w += 5; - }else{ - *w++ = *s; - } - } - return escaped; -} - -int -send(HConnect *c) -{ - Biobuf*blist; - int m, n, dbi, nmatch; - char *pat, *s, *e; - HSPairs *q; - - if(strcmp(c->req.meth, "GET") != 0 && strcmp(c->req.meth, "HEAD") != 0) - return hunallowed(c, "GET, HEAD"); - if(c->head.expectother || c->head.expectcont) - return hfail(c, HExpectFail, nil); - if(c->req.search == nil || !*c->req.search) - return hfail(c, HNoData, "netlib_find"); - s = c->req.search; - while((s = strchr(s, '+')) != nil) - *s++ = ' '; - dbi = -1; - pat = nil; - for(q = hparsequery(c, hstrdup(c, c->req.search)); q; q = q->next){ - if(strcmp(q->s, "db") == 0){ - m = atoi(q->t); - for(dbi = 0; m!=db[dbi].SELECT; dbi++) - if(db[dbi].SELECT<0) - exits("unrecognized db"); - }else if(strcmp(q->s, "pat") == 0){ - pat = q->t; - } - } - if(dbi < 0) - exits("missing db field in query"); - if(pat == nil) - exits("missing pat field in query"); - logit(c, "netlib_find %s %s", db[dbi].log,pat); - - blist = init800fs(db[dbi].file,pat); - - if(c->req.vermaj){ - hokheaders(c); - hprint(hout, "Content-type: text/html\r\n"); - hprint(hout, "\r\n"); - } - if(strcmp(c->req.meth, "HEAD") == 0){ - writelog(c, "Reply: 200 netlib_find 0\n"); - hflush(hout); - exits(nil); - } - - hprint(hout, "%s/%s\r\n\r\n", - db[dbi].log,hq(pat)); - nmatch = 0; - - while(s = Brdline(blist, '\n')){ /* get next database record */ - n = Blinelen(blist); - e = s+n; - hprint(hout, "
");
- (*db[dbi].fmt)(s,e);
- hprint(hout, "
\r\n"); - if(nmatch++>=db[dbi].maxhit){ - hprint(hout, "

reached limit at %d hits

\n\r",nmatch); - break; - } - } - if(nmatch==0) - hprint(hout, "

Nothing Found.

\r\n"); - hprint(hout, db[dbi].postlude); - hflush(hout); - writelog(c, "Reply: 200 netlib_find %ld %ld\n", hout->seek, hout->seek); - return 1; -} diff -r 786a65cf4eb9 sys/src/cmd/ip/httpd/netlib_history.c --- a/sys/src/cmd/ip/httpd/netlib_history.c Wed May 20 15:38:56 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,218 +0,0 @@ -#include -#include -#include -#include "httpd.h" -#include "httpsrv.h" - -Hio *HO; -int diffb; - -enum{ DAY = 24*60*60 }; - -void -lastbefore(ulong t, char *f, char *b) -{ - Tm *tm; - Dir *dir; - int try; - ulong t0, mtime; - - t0 = t; - for(try=0; try<10; try++) { - tm = localtime(t); - t -= DAY; - sprint(b,"%.4d/%.2d%.2d/netlib/pub/%s",tm->year+1900,tm->mon+1,tm->mday,f); - dir = dirstat(b); - if(dir == nil) - continue; - mtime = dir->mtime; - free(dir); - if(mtime > t0) - continue; - return; - } - strcpy(b, "filenotfound"); -} - -// create explicit file for diff, which otherwise would create a -// mode 0600 file that it couldn't read (because running as none) -void -gunzip(char *f, char *tmp) -{ - int fd = open(tmp, OWRITE); - - if(fd < 0) // can't happen - return; - switch(fork()){ - case 0: - dup(fd, 1); - close(fd); - close(0); - execl("/bin/gunzip", "gunzip", "-c", f, nil); - hprint(HO, "can't exec gunzip: %r\n"); - break; - case -1: - hprint(HO, "fork failed: %r\n"); - default: - while(waitpid() != -1) - ; - break; - } - close(fd); -} - -void -netlibhistory(char *file) -{ - char buf[500], pair[2][500], tmpf[2][30], *f; - int toggle = 0, started = 0, limit; - Dir *dir; - ulong otime, dt; - int i, fd, tmpcnt; - - if(strncmp(file, "../", 3) == 0 || strstr(file, "/../") || - strlen(file) >= sizeof(buf) - strlen("1997/0204/netlib/pub/0")) - return; - limit = 50; - if(diffb){ - limit = 10; - // create two tmp files for gunzip - for(i = 0, tmpcnt = 0; i < 2 && tmpcnt < 20; tmpcnt++){ - snprint(tmpf[i], sizeof(tmpf[0]), "/tmp/d%x", tmpcnt); - if(access(buf, AEXIST) == 0) - continue; - fd = create(tmpf[i], OWRITE, 0666); - if(fd < 0) - goto done; - close(fd); - i++; - } - } - otime = time(0); - hprint(HO,"
    \n"); - while(limit--){ - lastbefore(otime, file, buf); - dir = dirstat(buf); - if(dir == nil) - goto done; - dt = DAY/2; - while(otime <= dir->mtime){ - lastbefore(otime-dt, file, buf); - free(dir); - dir = dirstat(buf); - if(dir == nil) - goto done; - dt += DAY/2; - } - f = pair[toggle]; - strcpy(f, buf); - if(diffb && strcmp(f+strlen(f)-3, ".gz") == 0){ - gunzip(f, tmpf[toggle]); - strcpy(f, tmpf[toggle]); - } - if(diffb && started){ - hprint(HO, "
    \n");
    - hflush(HO);
    - switch(fork()){
    - case 0:
    - execl("/bin/diff", "diff", "-nb",
    - pair[1-toggle], pair[toggle], nil);
    - hprint(HO, "can't exec diff: %r\n");
    - break;
    - case -1:
    - hprint(HO, "fork failed: %r\n");
    - break;
    - default:
    - while(waitpid() != -1)
    - ;
    - break;
    - }
    - hprint(HO, "
    \n"); - } - hprint(HO,"
  • %s %lld bytes\n", - buf, 4+asctime(gmtime(dir->mtime)), dir->length); - if(diffb) - hprint(HO," (%s)\n", pair[toggle]); - toggle = 1-toggle; - started = 1; - otime = dir->mtime; - free(dir); - } - hprint(HO,"
  • ...\n"); -done: - hprint(HO,"
\n"); - if(diffb){ - remove(tmpf[0]); - remove(tmpf[1]); - } -} - -int -send(HConnect *c) -{ - char *file, *s; - HSPairs *q; - - if(strcmp(c->req.meth, "GET") != 0 && strcmp(c->req.meth, "HEAD") != 0) - return hunallowed(c, "GET, HEAD"); - if(c->head.expectother || c->head.expectcont) - return hfail(c, HExpectFail, nil); - if(c->req.search == nil || !*c->req.search) - return hfail(c, HNoData, "netlib_history"); - s = c->req.search; - while((s = strchr(s, '+')) != nil) - *s++ = ' '; - file = nil; - for(q = hparsequery(c, hstrdup(c, c->req.search)); q; q = q->next){ - if(strcmp(q->s, "file") == 0) - file = q->t; - else if(strcmp(q->s, "diff") == 0) - diffb = 1; - } - if(file == nil) - return hfail(c, HNoData, "netlib_history missing file field"); - logit(c, "netlib_hist %s%s", file, diffb?" DIFF":""); - - if(c->req.vermaj){ - hokheaders(c); - hprint(HO, "Content-type: text/html\r\n"); - hprint(HO, "\r\n"); - } - if(strcmp(c->req.meth, "HEAD") == 0){ - writelog(c, "Reply: 200 netlib_history 0\n"); - hflush(HO); - exits(nil); - } - - hprint(HO, "%s history\n\n",file); - hprint(HO, "

%s history

\n",file); - hprint(HO, "Netlib's copy of %s was changed\n", file); - hprint(HO, "on the dates shown.
Click on the date link\n"); - hprint(HO, "to retrieve the corresponding version.
\n"); - if(diffb){ - hprint(HO, "
Lines beginning with < are for the\n"); - hprint(HO, "newer of the two versions.\n"); - } - - if(chdir("/usr/web/historic") < 0) - hprint(HO, "chdir failed: %r\n"); - netlibhistory(file); - - hprint(HO, "
Eric Grosse\n"); - hprint(HO, "\n"); - hflush(HO); - writelog(c, "Reply: 200 netlib_history %ld %ld\n", HO->seek, HO->seek); - return 1; -} - -void -main(int argc, char **argv) -{ - HConnect *c; - - c = init(argc, argv); - HO = &c->hout; - if(hparseheaders(c, HSTIMEOUT) >= 0) - send(c); - exits(nil); -}