9front - general discussion about 9front
 help / color / mirror / Atom feed
* ip/httpd cleanup
@ 2015-05-21  0:03 Nick Owens
  0 siblings, 0 replies; only message in thread
From: Nick Owens @ 2015-05-21  0:03 UTC (permalink / raw)
  To: 9front

[-- Attachment #1: Type: text/plain, Size: 19723 bytes --]

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 <u.h>
-#include <libc.h>
-#include <bio.h>
-#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, "<head><title>Nothing Found</title></head><body>\n");
- hprint(hout, "Nothing satisfying your search request could be
found.\n</body>\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<ba.y && pa.y*ba.x<=pa.x*ba.y)
- inside = !inside;
- return inside;
-}
-
-Point
-sub(Point p, Point q)
-{
- p.x -= q.x;
- p.y -= q.y;
- return p;
-}
-
-float
-dist(Point p, Point q)
-{
- p.x -= q.x;
- p.y -= q.y;
- return (float)p.x * p.x + (float)p.y * p.y;
-}
-
-OkPoint
-pt(char *s)
-{
- OkPoint okp;
- Point p;
- char *t, *e;
-
- if(*s == '(')
- s++;
- t = strchr(s, ')');
- if(t != nil)
- *t = 0;
- p.x = 0;
- p.y = 0;
- t = strchr(s, ',');
- if(t == nil){
- okp.p = p;
- okp.ok = 0;
- return okp;
- }
- e = nil;
- p.x = strtol(s, &e, 10);
- if(e != t){
- okp.p = p;
- okp.ok = 0;
- return okp;
- }
- p.y = strtol(t+1, &e, 10);
- if(e == nil || *e != 0){
- okp.p = p;
- okp.ok = 0;
- return okp;
- }
- okp.p = p;
- okp.ok = 1;
- return okp;
-}
-
-Strings
-getfield(char *s)
-{
- Strings ss;
- char *f;
-
- while(*s == '\t' || *s == ' ')
- s++;
- f = s;
- while(*s && *s != '\t' && *s != ' ')
- s++;
- if(*s)
- *s++ = 0;
- ss.s1 = f;
- ss.s2 = s;
- return ss;
-}
diff -r 786a65cf4eb9 sys/src/cmd/ip/httpd/mkfile
--- a/sys/src/cmd/ip/httpd/mkfile Wed May 20 15:38:56 2015 -0700
+++ b/sys/src/cmd/ip/httpd/mkfile Wed May 20 16:58:47 2015 -0700
@@ -6,27 +6,14 @@

 TARG=\
  httpd\
- imagemap\
  man2html\
  save\
- netlib_find\
- netlib_history\
  webls\
  wikipost\

-XTARG=\
- httpd\
- imagemap\
- netlib_find\
- netlib_history\
- man2html\
- save\
- wikipost\
-
 LIB=libhttps.a$O

-LIBS=libhttps.a$O
-LIBSOFILES=\
+LIBOFILES=\
  anonymous.$O\
  content.$O\
  emem.$O\
@@ -39,41 +26,7 @@

 BIN=/$objtype/bin/ip/httpd

-UPDATE=\
- $HFILES\
- ${LIBSOFILES:%.$O=%.c}\
- ${XTARG:%=%.c}\
-
 </sys/src/cmd/mkmany

-trial: $O.netlib_history
- # should first   mount -b /srv/histnetlib /usr/web/historic
- echo '
- ' | $O.netlib_history GET HTTP/1.0 xxx 'file=fp%2Fdtoa.c.gz'
-
-trial2: $O.netlib_find
- echo "\n" | $O.netlib_find GET HTTP/1.0 xxx 'db=1&pat=Hearing' >
/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 <u.h>
-#include <libc.h>
-#include <bio.h>
-#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,
- "<HR><A HREF=\"/netlib/master\">browse netlib</A></BODY>\r\n"},
- {1, "BibNet", 250, "/srv/netlib_bibnet", bib_fmt,
- "<HR><A HREF=\"/netlib/bibnet\">browse BibNet</A></BODY>\r\n"},
- {2, "compgeom", 250, "/srv/netlib_compgeom", no_fmt, "</BODY>\r\n"},
- {3, "approx", 250, "/srv/netlib_approximation", no_fmt,
- "<HR><A HREF=\"/netlib/a/catalog.html.gz\">hierarchical
catalog</A></BODY>\r\n"},
- {4, "siam", 50, "/srv/netlib_siam-Secret", no_fmt, "</BODY>\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<e; p++)
- if(*p=='\r'){
- hwrite(hout, s,p-s);
- hprint(hout, "\n");
- s = p+1;
- }
-}
-
-int /* should the filename have .gz appended? */
-suffix(char*filename)
-{
- int n;
- char *z;
-
- if(!filename || *filename==0)
- return(0);
- n = strlen(filename);
- if(strncmp(".html",filename+n-5,5)==0)
- return(0);
- z = malloc(n+50);
- if(z == nil)
- return(0);
- strcpy(z,"/netlib/pub/");
- strcat(z,filename);
- strcat(z,".gz");
- if(access(z,4)==0){
- free(z);
- return(1);
- }
- free(z);
- return(0);
-}
-
-void /* add HREF to "file:" lines */
-index_fmt(char*s,char*e)
-{
- char *p, *filename;
- if(strncmp(s,"file",4)==0 && (s[4]==' '||s[4]=='\t')){
- for(filename = s+4; strchr(" \t",*filename); filename++){}
- for(s = filename; *s && strchr("\r\n",*s)==nil; s++){}
- *s++ = '\0';
- if(*s=='\n') s++;
- hprint(hout, "file:   <A HREF=\"/netlib/%s",filename);
- if(suffix(filename))
- hprint(hout, ".gz");
- hprint(hout, "\">%s</A>\r\n",filename);
- for(p = s; p<e; p++)
- if(*p=='\r'){
- hwrite(hout, s,p-s);
- hprint(hout, "\n");
- s = p+1;
- }
- }else if(strncmp(s,"lib",3)==0 && (s[3]==' '||s[3]=='\t')){
- for(filename = s+3; strchr(" \t",*filename); filename++){}
- for(s = filename; *s && strchr("\r\n",*s)==nil; s++){}
- *s++ = '\0';
- if(*s=='\n') s++;
- hprint(hout, "lib:    <A HREF=\"/netlib/%s",filename);
- hprint(hout, "\">%s</A>\r\n",filename);
- for(p = s; p<e; p++)
- if(*p=='\r'){
- hwrite(hout, s,p-s);
- hprint(hout, "\n");
- s = p+1;
- }
- }else{
- no_fmt(s,e);
- }
-}
-
-void /* add HREF to "URL" lines */
-bib_fmt(char*s,char*e)
-{
- char *p, *filename;
- for(p = s; p<e; p++)
- if(*p=='\r'){
- hwrite(hout, s,p-s);
- hprint(hout, "\n");
- s = p+1;
- if(strncmp(s," URL =",6)==0 &&
- (filename = strchr(s+6,'"'))!=nil){
- filename++;
- for(s = filename; *s && strchr("\"\r\n",*s)==nil; s++){}
- *s++ = '\0';
- p = s;
- hprint(hout, " URL =<A HREF=\"%s\">%s</A>",
- 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, "&lt;");
- w += 4;
- }else if(*s == '>'){
- strcpy(w, "&gt;");
- w += 4;
- }else if(*s == '&'){
- strcpy(w, "&amp;");
- 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, "<HEAD><TITLE>%s/%s</TITLE></HEAD>\r\n<BODY>\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, "<PRE>");
- (*db[dbi].fmt)(s,e);
- hprint(hout, "</PRE>\r\n");
- if(nmatch++>=db[dbi].maxhit){
- hprint(hout, "<H4>reached limit at %d hits</H4>\n\r",nmatch);
- break;
- }
- }
- if(nmatch==0)
- hprint(hout, "<H4>Nothing Found.</H4>\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 <u.h>
-#include <libc.h>
-#include <bio.h>
-#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,"<UL>\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, "<PRE>\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, "</PRE>\n");
- }
- hprint(HO,"<LI><A HREF=\"/historic/%s\">%s</A> %lld bytes\n",
- buf, 4+asctime(gmtime(dir->mtime)), dir->length);
- if(diffb)
- hprint(HO," <FONT SIZE=-1>(%s)</FONT>\n", pair[toggle]);
- toggle = 1-toggle;
- started = 1;
- otime = dir->mtime;
- free(dir);
- }
- hprint(HO,"<LI>...\n");
-done:
- hprint(HO,"</UL>\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, "<HEAD><TITLE>%s history</TITLE></HEAD>\n<BODY>\n",file);
- hprint(HO, "<H2>%s history</H2>\n",file);
- hprint(HO, "<I>Netlib's copy of %s was changed\n", file);
- hprint(HO, "on the dates shown.  <BR>Click on the date link\n");
- hprint(HO, "to retrieve the corresponding version.</I>\n");
- if(diffb){
- hprint(HO, "<BR><I>Lines beginning with &lt; are for the\n");
- hprint(HO, "newer of the two versions.</I>\n");
- }
-
- if(chdir("/usr/web/historic") < 0)
- hprint(HO, "chdir failed: %r\n");
- netlibhistory(file);
-
- hprint(HO, "<BR><A HREF=\"http://cm.bell-labs.com/who/ehg\">Eric
Grosse</A>\n");
- hprint(HO, "</BODY></HTML>\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);
-}

[-- Attachment #2: Type: text/html, Size: 25633 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-05-21  0:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-21  0:03 ip/httpd cleanup Nick Owens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).