1 /* invoked from /netlib/pub/search.html */
9 void bib_fmt(char*,char*);
10 void index_fmt(char*,char*);
11 void no_fmt(char*,char*);
16 /********** table of databases ************/
21 int SELECT; /* value from search.html */
22 char *log; /* abbreviation for logfile */
23 int maxhit; /* maximum number of hits to return */
24 char *file; /* searchfs database */
25 void (*fmt)(char*,char*); /* convert one record to HTML */
26 char *postlude; /* trailer text */
31 {0, "netlib", 250, "/srv/netlib_DEFAULT", index_fmt,
32 "<HR><A HREF=\"/netlib/master\">browse netlib</A></BODY>\r\n"},
33 {1, "BibNet", 250, "/srv/netlib_bibnet", bib_fmt,
34 "<HR><A HREF=\"/netlib/bibnet\">browse BibNet</A></BODY>\r\n"},
35 {2, "compgeom", 250, "/srv/netlib_compgeom", no_fmt, "</BODY>\r\n"},
36 {3, "approx", 250, "/srv/netlib_approximation", no_fmt,
37 "<HR><A HREF=\"/netlib/a/catalog.html.gz\">hierarchical catalog</A></BODY>\r\n"},
38 {4, "siam", 50, "/srv/netlib_siam-Secret", no_fmt, "</BODY>\r\n"},
39 {-1,"",0,"",no_fmt,""}
44 /********** reformat database record as HTML ************/
46 void /* tr '\015' '\012' ("uncombline") */
49 /* s = start, e = (one past) end of database record */
59 int /* should the filename have .gz appended? */
65 if(!filename || *filename==0)
68 if(strncmp(".html",filename+n-5,5)==0)
73 strcpy(z,"/netlib/pub/");
84 void /* add HREF to "file:" lines */
85 index_fmt(char*s,char*e)
88 if(strncmp(s,"file",4)==0 && (s[4]==' '||s[4]=='\t')){
89 for(filename = s+4; strchr(" \t",*filename); filename++){}
90 for(s = filename; *s && strchr("\r\n",*s)==nil; s++){}
93 hprint(hout, "file: <A HREF=\"/netlib/%s",filename);
96 hprint(hout, "\">%s</A>\r\n",filename);
103 }else if(strncmp(s,"lib",3)==0 && (s[3]==' '||s[3]=='\t')){
104 for(filename = s+3; strchr(" \t",*filename); filename++){}
105 for(s = filename; *s && strchr("\r\n",*s)==nil; s++){}
108 hprint(hout, "lib: <A HREF=\"/netlib/%s",filename);
109 hprint(hout, "\">%s</A>\r\n",filename);
121 void /* add HREF to "URL" lines */
122 bib_fmt(char*s,char*e)
130 if(strncmp(s," URL =",6)==0 &&
131 (filename = strchr(s+6,'"'))!=nil){
133 for(s = filename; *s && strchr("\"\r\n",*s)==nil; s++){}
136 hprint(hout, " URL =<A HREF=\"%s\">%s</A>",
143 /********** main() calls httpheadget() calls send() ************/
146 main(int argc, char **argv)
150 c = init(argc, argv);
152 if(hparseheaders(c, HSTIMEOUT) >= 0)
160 init800fs(char*name,char*pat)
165 fd800fs = open(name, ORDWR);
167 exits("can't connect to 800fs server");
168 if(mount(fd800fs, -1, "/mnt", MREPL, "") < 0)
169 exits("can't mount /mnt");
170 fd800fs = open("/mnt/search", ORDWR);
171 n = strlen("search=")+strlen(pat)+1;
173 strcpy(search,"search=");
175 write(fd800fs,search,n);
177 Binit(&Blist, fd800fs,OREAD);
185 int textlen = strlen(text), escapedlen = textlen;
186 char *escaped, *s, *w;
188 for(s = text; *s; s++)
189 if(*s=='<' || *s=='>' || *s=='&')
191 escaped = ezalloc(escapedlen+1);
192 for(s = text, w = escaped; *s; s++){
213 int m, n, dbi, nmatch;
217 if(strcmp(c->req.meth, "GET") != 0 && strcmp(c->req.meth, "HEAD") != 0)
218 return hunallowed(c, "GET, HEAD");
219 if(c->head.expectother || c->head.expectcont)
220 return hfail(c, HExpectFail, nil);
221 if(c->req.search == nil || !*c->req.search)
222 return hfail(c, HNoData, "netlib_find");
224 while((s = strchr(s, '+')) != nil)
228 for(q = hparsequery(c, hstrdup(c, c->req.search)); q; q = q->next){
229 if(strcmp(q->s, "db") == 0){
231 for(dbi = 0; m!=db[dbi].SELECT; dbi++)
233 exits("unrecognized db");
234 }else if(strcmp(q->s, "pat") == 0){
239 exits("missing db field in query");
241 exits("missing pat field in query");
242 logit(c, "netlib_find %s %s", db[dbi].log,pat);
244 blist = init800fs(db[dbi].file,pat);
248 hprint(hout, "Content-type: text/html\r\n");
249 hprint(hout, "\r\n");
251 if(strcmp(c->req.meth, "HEAD") == 0){
252 writelog(c, "Reply: 200 netlib_find 0\n");
257 hprint(hout, "<HEAD><TITLE>%s/%s</TITLE></HEAD>\r\n<BODY>\r\n",
258 db[dbi].log,hq(pat));
261 while(s = Brdline(blist, '\n')){ /* get next database record */
264 hprint(hout, "<PRE>");
266 hprint(hout, "</PRE>\r\n");
267 if(nmatch++>=db[dbi].maxhit){
268 hprint(hout, "<H4>reached limit at %d hits</H4>\n\r",nmatch);
273 hprint(hout, "<H4>Nothing Found.</H4>\r\n");
274 hprint(hout, db[dbi].postlude);
276 writelog(c, "Reply: 200 netlib_find %ld %ld\n", hout->seek, hout->seek);