Annotation of libwww/Library/src/HTAccess.c, revision 1.18
1.1 timbl 1: /* Access Manager HTAccess.c
2: ** ==============
3: **
4: ** Authors
5: ** TBL Tim Berners-Lee timbl@info.cern.ch
1.4 timbl 6: ** JFG Jean-Francois Groff jfg@dxcern.cern.ch
1.1 timbl 7: ** DD Denis DeLaRoca (310) 825-4580 <CSP1DWD@mvs.oac.ucla.edu>
8: ** History
9: ** 8 Jun 92 Telnet hopping prohibited as telnet is not secure TBL
10: ** 26 Jun 92 When over DECnet, suppressed FTP, Gopher and News. JFG
11: ** 6 Oct 92 Moved HTClientHost and logfile into here. TBL
12: ** 17 Dec 92 Tn3270 added, bug fix. DD
1.2 timbl 13: ** 4 Feb 93 Access registration, Search escapes bad chars TBL
1.9 timbl 14: ** PARAMETERS TO HTSEARCH AND HTLOADRELATIVE CHANGED
15: ** 28 May 93 WAIS gateway explicit if no WAIS library linked in.
1.2 timbl 16: **
17: ** Bugs
18: ** This module assumes that that the graphic object is hypertext, as it
1.9 timbl 19: ** needs to select it when it has been loaded. A superclass needs to be
1.2 timbl 20: ** defined which accepts select and select_anchor.
1.1 timbl 21: */
22:
1.9 timbl 23: #ifndef DEFAULT_WAIS_GATEWAY
1.8 timbl 24: #define DEFAULT_WAIS_GATEWAY "http://info.cern.ch:8001/"
1.9 timbl 25: #endif
1.8 timbl 26:
1.1 timbl 27: /* Implements:
28: */
29: #include "HTAccess.h"
30:
31: /* Uses:
32: */
33:
34: #include "HTParse.h"
35: #include "HTUtils.h"
1.4 timbl 36: #include "HTML.h" /* SCW */
1.2 timbl 37:
38: #ifndef NO_RULES
39: #include "HTRules.h"
40: #endif
41:
1.1 timbl 42: #include <stdio.h>
43:
1.2 timbl 44: #include "HTList.h"
45: #include "HText.h" /* See bugs above */
46: #include "HTAlert.h"
1.17 timbl 47: #include "HTFWriter.h" /* for cache stuff */
48: #include "HTTee.h"
1.2 timbl 49:
1.1 timbl 50: /* These flags may be set to modify the operation of this module
51: */
52: PUBLIC char * HTClientHost = 0; /* Name of remote login host if any */
53: PUBLIC FILE * logfile = 0; /* File to which to output one-liners */
1.12 timbl 54: PUBLIC BOOL HTSecure = NO; /* Disable access for telnet users? */
1.1 timbl 55:
1.2 timbl 56: /* To generate other things, play with these:
57: */
58:
1.15 timbl 59: /* PUBLIC HTFormat HTOutputFormat = NULL; use request->output_format */
60: /* PUBLIC HTStream* HTOutputStream = NULL; use request->output_stream */
1.1 timbl 61:
62: PRIVATE HTList * protocols = NULL; /* List of registered protocol descriptors */
63:
64:
1.15 timbl 65: /* Create a request structure
66: ** ---------------------------
67: */
68:
69: PUBLIC HTRequest * HTRequest_new NOARGS
70: {
71: HTRequest * me = (HTRequest*) calloc(sizeof(*me), 1); /* zero fill */
72: if (!me) outofmem(__FILE__, "HTRequest_new()");
73:
74: me->output_format = WWW_PRESENT; /* default it to present to user */
1.16 timbl 75: me->conversions = HTList_new(); /* No conversions registerd yet */
1.15 timbl 76: return me;
77: }
78:
79:
1.1 timbl 80: /* Register a Protocol HTRegisterProtocol
81: ** -------------------
82: */
83:
84: PUBLIC BOOL HTRegisterProtocol(protocol)
85: HTProtocol * protocol;
86: {
87: if (!protocols) protocols = HTList_new();
88: HTList_addObject(protocols, protocol);
89: return YES;
90: }
91:
92:
93: /* Register all known protocols
94: ** ----------------------------
95: **
96: ** Add to or subtract from this list if you add or remove protocol modules.
97: ** This routine is called the first time the protocol list is needed,
98: ** unless any protocols are already registered, in which case it is not called.
99: ** Therefore the application can override this list.
100: **
101: ** Compiling with NO_INIT prevents all known protocols from being forced
102: ** in at link time.
103: */
104: #ifndef NO_INIT
105: PRIVATE void HTAccessInit NOARGS /* Call me once */
106: {
1.14 duns 107: GLOBALREF HTProtocol HTTP, HTFile, HTTelnet, HTTn3270, HTRlogin;
1.1 timbl 108: #ifndef DECNET
1.14 duns 109: GLOBALREF HTProtocol HTFTP, HTNews, HTGopher;
1.3 timbl 110: #ifdef DIRECT_WAIS
1.14 duns 111: GLOBALREF HTProtocol HTWAIS;
1.3 timbl 112: #endif
1.2 timbl 113: HTRegisterProtocol(&HTFTP);
114: HTRegisterProtocol(&HTNews);
115: HTRegisterProtocol(&HTGopher);
1.3 timbl 116: #ifdef DIRECT_WAIS
117: HTRegisterProtocol(&HTWAIS);
118: #endif
1.1 timbl 119: #endif
120:
1.2 timbl 121: HTRegisterProtocol(&HTTP);
122: HTRegisterProtocol(&HTFile);
123: HTRegisterProtocol(&HTTelnet);
124: HTRegisterProtocol(&HTTn3270);
125: HTRegisterProtocol(&HTRlogin);
1.1 timbl 126: }
127: #endif
128:
129:
1.2 timbl 130: /* Find physical name and access protocol
131: ** --------------------------------------
1.1 timbl 132: **
133: **
134: ** On entry,
135: ** addr must point to the fully qualified hypertext reference.
136: ** anchor a pareent anchor with whose address is addr
137: **
138: ** On exit,
1.2 timbl 139: ** returns HT_NO_ACCESS Error has occured.
140: ** HT_OK Success
1.1 timbl 141: **
142: */
1.2 timbl 143: PRIVATE int get_physical ARGS2(
144: CONST char *, addr,
145: HTParentAnchor *, anchor)
1.1 timbl 146: {
147: char * access=0; /* Name of access method */
1.2 timbl 148: char * physical = 0;
1.1 timbl 149:
1.2 timbl 150: #ifndef NO_RULES
151: physical = HTTranslate(addr);
152: if (!physical) {
153: return HT_FORBIDDEN;
154: }
155: HTAnchor_setPhysical(anchor, physical);
156: free(physical); /* free our copy */
157: #else
158: HTAnchor_setPhysical(anchor, addr);
159: #endif
160:
161: access = HTParse(HTAnchor_physical(anchor),
162: "file:", PARSE_ACCESS);
1.1 timbl 163:
164: /* Check whether gateway access has been set up for this
1.8 timbl 165: **
166: ** This function can be replaced by the rule system above.
1.1 timbl 167: */
1.8 timbl 168: #define USE_GATEWAYS
1.1 timbl 169: #ifdef USE_GATEWAYS
1.2 timbl 170: {
1.9 timbl 171: char * gateway_parameter, *gateway;
1.2 timbl 172: gateway_parameter = (char *)malloc(strlen(access)+20);
173: if (gateway_parameter == NULL) outofmem(__FILE__, "HTLoad");
174: strcpy(gateway_parameter, "WWW_");
175: strcat(gateway_parameter, access);
176: strcat(gateway_parameter, "_GATEWAY");
177: gateway = (char *)getenv(gateway_parameter); /* coerce for decstation */
178: free(gateway_parameter);
1.8 timbl 179:
180: #ifndef DIRECT_WAIS
1.9 timbl 181: if (!gateway && 0==strcmp(access, "wais")) {
1.8 timbl 182: gateway = DEFAULT_WAIS_GATEWAY;
183: }
184: #endif
1.2 timbl 185: if (gateway) {
1.9 timbl 186: char * path = HTParse(addr, "",
187: PARSE_HOST + PARSE_PATH + PARSE_PUNCTUATION);
188: /* Chop leading / off to make host into part of path */
189: char * gatewayed = HTParse(path+1, gateway, PARSE_ALL);
190: free(path);
1.8 timbl 191: HTAnchor_setPhysical(anchor, gatewayed);
1.9 timbl 192: free(gatewayed);
1.2 timbl 193: free(access);
1.9 timbl 194:
1.8 timbl 195: access = HTParse(HTAnchor_physical(anchor),
196: "http:", PARSE_ACCESS);
1.2 timbl 197: }
198: }
1.1 timbl 199: #endif
200:
201:
202:
203: /* Search registered protocols to find suitable one
204: */
205: {
206: int i, n;
207: #ifndef NO_INIT
1.2 timbl 208: if (!protocols) HTAccessInit();
1.1 timbl 209: #endif
210: n = HTList_count(protocols);
211: for (i=0; i<n; i++) {
1.2 timbl 212: HTProtocol *p = HTList_objectAt(protocols, i);
213: if (strcmp(p->name, access)==0) {
214: HTAnchor_setProtocol(anchor, p);
215: free(access);
216: return (HT_OK);
1.1 timbl 217: }
218: }
219: }
220:
221: free(access);
1.2 timbl 222: return HT_NO_ACCESS;
1.1 timbl 223: }
224:
225:
226: /* Load a document
227: ** ---------------
228: **
1.2 timbl 229: ** This is an internal routine, which has an address AND a matching
230: ** anchor. (The public routines are called with one OR the other.)
231: **
232: ** On entry,
233: ** addr must point to the fully qualified hypertext reference.
1.15 timbl 234: ** request->
235: ** anchor a parent anchor with whose address is addr
236: ** output_format valid
237: ** output_stream valid on NULL
1.2 timbl 238: **
239: ** On exit,
240: ** returns <0 Error has occured.
241: ** HT_LOADED Success
242: ** HT_NO_DATA Success, but no document loaded.
1.8 timbl 243: ** (telnet sesssion started etc)
1.2 timbl 244: **
245: */
1.15 timbl 246: PRIVATE int HTLoad ARGS2(
1.2 timbl 247: CONST char *, addr,
1.15 timbl 248: HTRequest *, request)
1.2 timbl 249: {
250: HTProtocol* p;
1.15 timbl 251: int status = get_physical(addr, request->anchor);
1.2 timbl 252: if (status == HT_FORBIDDEN) {
1.15 timbl 253: return HTLoadError(request->output_stream, 500,
254: "Access forbidden by rule");
1.2 timbl 255: }
256: if (status < 0) return status; /* Can't resolve or forbidden */
257:
1.15 timbl 258: p = HTAnchor_protocol(request->anchor);
1.17 timbl 259: return (*(p->load))(request);
1.2 timbl 260: }
261:
262:
263: /* Get a save stream for a document
264: ** --------------------------------
265: */
1.15 timbl 266: PUBLIC HTStream *HTSaveStream ARGS2(
267: HTParentAnchor *, anchor,
268: HTRequest *, request)
269: {
270: HTProtocol * p;
271: request->anchor = anchor;
272: p = HTAnchor_protocol(request->anchor);
1.2 timbl 273: if (!p) return NULL;
274:
1.15 timbl 275: return (*p->saveStream)(request);
1.2 timbl 276:
277: }
278:
279:
280: /* Load a document - with logging etc
281: ** ----------------------------------
282: **
283: ** - Checks or documents already loaded
284: ** - Logs the access
285: ** - Allows stdin filter option
286: ** - Trace ouput and error messages
287: **
1.1 timbl 288: ** On Entry,
289: ** full_address The address of the document to be accessed.
1.2 timbl 290: ** filter if YES, treat stdin as HTML
1.1 timbl 291: **
1.15 timbl 292: ** request->anchor is the node_anchor for the document
293: ** request->output_format is valid
294: **
1.1 timbl 295: ** On Exit,
296: ** returns YES Success in opening document
297: ** NO Failure
298: **
299: */
300:
1.15 timbl 301: PRIVATE BOOL HTLoadDocument ARGS2(
1.2 timbl 302: CONST char *, full_address,
1.15 timbl 303: HTRequest *, request)
1.1 timbl 304:
305: {
306: int status;
307: HText * text;
308:
309: if (TRACE) fprintf (stderr,
310: "HTAccess: loading document %s\n", full_address);
311:
1.18 ! timbl 312: request->using_cache = NULL;
! 313:
1.15 timbl 314: if (!request->output_format) request->output_format = WWW_PRESENT;
315:
316: if (text=(HText *)HTAnchor_document(request->anchor))
317: { /* Already loaded */
1.1 timbl 318: if (TRACE) fprintf(stderr, "HTAccess: Document already in memory.\n");
319: HText_select(text);
320: return YES;
321: }
1.17 timbl 322:
323: /* Check the Cache
324: */
325: /* Bug: for each format, we only check whether it is ok, we
326: don't check them all and chose the best */
327: if (request->anchor->cacheItems) {
328: HTList * list = request->anchor->cacheItems;
329: int i;
330: int n = HTList_count(list);
331: for(i=0; i<n; i++) {
332: HTCacheItem * item = HTList_objectAt(list, i);
1.18 ! timbl 333: HTStream * s;
! 334:
! 335: request->using_cache = item;
! 336:
! 337: s = HTStreamStack(item->format, request);
1.17 timbl 338: if (s) { /* format was suitable */
339: FILE * fp = fopen(item->filename, "r");
1.18 ! timbl 340: if (TRACE) fprintf(stderr, "Cache: HIT file %s for %s\n",
! 341: item->filename,
! 342: full_address);
1.17 timbl 343: if (fp) {
344: HTFileCopy(fp, s);
345: fclose(fp);
346: return YES;
347: } else {
348: fprintf(stderr, "***** Can't read cache file %s !\n",
349: item->filename);
350: } /* file open ok */
351: } /* stream ok */
352: } /* next cache item */
353: } /* if cache available for this anchor */
1.1 timbl 354:
1.15 timbl 355: status = HTLoad(full_address, request);
1.2 timbl 356:
357:
1.1 timbl 358: /* Log the access if necessary
359: */
360: if (logfile) {
361: time_t theTime;
362: time(&theTime);
363: fprintf(logfile, "%24.24s %s %s %s\n",
364: ctime(&theTime),
365: HTClientHost ? HTClientHost : "local",
366: status<0 ? "FAIL" : "GET",
367: full_address);
368: fflush(logfile); /* Actually update it on disk */
369: if (TRACE) fprintf(stderr, "Log: %24.24s %s %s %s\n",
370: ctime(&theTime),
371: HTClientHost ? HTClientHost : "local",
372: status<0 ? "FAIL" : "GET",
373: full_address);
374: }
375:
376:
377: if (status == HT_LOADED) {
378: if (TRACE) {
379: fprintf(stderr, "HTAccess: `%s' has been accessed.\n",
380: full_address);
381: }
382: return YES;
383: }
384:
385: if (status == HT_NO_DATA) {
386: if (TRACE) {
387: fprintf(stderr,
388: "HTAccess: `%s' has been accessed, No data left.\n",
389: full_address);
390: }
391: return NO;
392: }
393:
1.2 timbl 394: if (status<0) { /* Failure in accessing a document */
1.1 timbl 395: #ifdef CURSES
396: user_message("Can't access `%s'", full_address);
397: #else
1.5 timbl 398: if (TRACE) fprintf(stderr,
399: "HTAccess: Can't access `%s'\n", full_address);
1.1 timbl 400: #endif
1.15 timbl 401: HTLoadError(request->output_stream, 500, "Unable to access document.");
1.1 timbl 402: return NO;
403: }
1.9 timbl 404:
405: /* If you get this, then please find which routine is returning
406: a positive unrecognised error code! */
407:
1.1 timbl 408: fprintf(stderr,
1.2 timbl 409: "**** HTAccess: socket or file number returned by obsolete load routine!\n");
1.9 timbl 410: fprintf(stderr,
411: "**** HTAccess: Internal software error. Please mail www-bug@info.cern.ch!\n");
1.1 timbl 412: exit(-6996);
413:
1.2 timbl 414: } /* HTLoadDocument */
1.1 timbl 415:
416:
417:
418: /* Load a document from absolute name
419: ** ---------------
420: **
421: ** On Entry,
422: ** addr The absolute address of the document to be accessed.
423: ** filter if YES, treat document as HTML
424: **
425: ** On Exit,
426: ** returns YES Success in opening document
427: ** NO Failure
428: **
429: **
430: */
431:
1.15 timbl 432: PUBLIC BOOL HTLoadAbsolute ARGS2(CONST char *,addr, HTRequest*, request)
1.2 timbl 433: {
1.15 timbl 434: request->anchor = HTAnchor_parent(HTAnchor_findAddress(addr));
435:
436: return HTLoadDocument( addr, request);
1.2 timbl 437: }
438:
439:
440: /* Load a document from absolute name to stream
441: ** --------------------------------------------
442: **
443: ** On Entry,
444: ** addr The absolute address of the document to be accessed.
1.15 timbl 445: ** request->output_stream if non-NULL, send data down this stream
1.2 timbl 446: **
447: ** On Exit,
448: ** returns YES Success in opening document
449: ** NO Failure
450: **
451: **
452: */
453:
454: PUBLIC BOOL HTLoadToStream ARGS3(
455: CONST char *, addr,
456: BOOL, filter,
1.15 timbl 457: HTRequest*, request)
1.1 timbl 458: {
1.15 timbl 459: request->output_stream = request->output_stream;
460: request->anchor = HTAnchor_parent(HTAnchor_findAddress(addr));
461: return HTLoadDocument(addr, request);
1.1 timbl 462: }
463:
464:
1.2 timbl 465:
466:
1.1 timbl 467: /* Load a document from relative name
468: ** ---------------
469: **
470: ** On Entry,
1.2 timbl 471: ** relative_name The relative address of the document
472: ** to be accessed.
1.1 timbl 473: **
474: ** On Exit,
475: ** returns YES Success in opening document
476: ** NO Failure
477: **
478: **
479: */
480:
1.15 timbl 481: PUBLIC BOOL HTLoadRelative ARGS3(
1.2 timbl 482: CONST char *, relative_name,
1.15 timbl 483: HTParentAnchor *, here,
484: HTRequest*, request)
1.1 timbl 485: {
486: char * full_address = 0;
487: BOOL result;
488: char * mycopy = 0;
489: char * stripped = 0;
490: char * current_address =
1.2 timbl 491: HTAnchor_address((HTAnchor*)here);
1.1 timbl 492:
493: StrAllocCopy(mycopy, relative_name);
494:
495: stripped = HTStrip(mycopy);
496: full_address = HTParse(stripped,
497: current_address,
498: PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION);
1.15 timbl 499: result = HTLoadAbsolute(full_address, request);
1.1 timbl 500: free(full_address);
501: free(current_address);
502: free(mycopy); /* Memory leak fixed 10/7/92 -- JFG */
503: return result;
504: }
505:
506:
507: /* Load if necessary, and select an anchor
508: ** --------------------------------------
509: **
510: ** On Entry,
511: ** destination The child or parenet anchor to be loaded.
512: **
513: ** On Exit,
514: ** returns YES Success
515: ** NO Failure
516: **
517: */
518:
1.15 timbl 519: PUBLIC BOOL HTLoadAnchor ARGS2(HTAnchor*, anchor, HTRequest *, request)
1.1 timbl 520: {
521: BOOL loaded = NO;
1.15 timbl 522: if (!anchor) return NO; /* No link */
1.1 timbl 523:
1.15 timbl 524: request->anchor = HTAnchor_parent(anchor);
1.1 timbl 525:
1.15 timbl 526: if (HTAnchor_document(request->anchor) == NULL) {/* If not alread loaded */
1.1 timbl 527: BOOL result;
1.15 timbl 528: char * address = HTAnchor_address((HTAnchor*) request->anchor);
529: result = HTLoadDocument(address, request);
1.1 timbl 530: free(address);
531: if (!result) return NO;
532: loaded = YES;
533: }
534:
535: {
1.15 timbl 536: HText *text = (HText*)HTAnchor_document(request->anchor);
537: if (anchor != (HTAnchor *)request->anchor) { /* If child anchor */
1.1 timbl 538: HText_selectAnchor(text,
1.15 timbl 539: (HTChildAnchor*)anchor); /* Double display? @@ */
1.1 timbl 540: } else {
541: if (!loaded) HText_select(text);
542: }
543: }
544: return YES;
545:
546: } /* HTLoadAnchor */
547:
548:
549: /* Search
550: ** ------
551: ** Performs a keyword search on word given by the user. Adds the keyword to
552: ** the end of the current address and attempts to open the new address.
553: **
554: ** On Entry,
555: ** *keywords space-separated keyword list or similar search list
1.2 timbl 556: ** here is anchor search is to be done on.
1.1 timbl 557: */
558:
1.2 timbl 559: PRIVATE char hex(i)
560: int i;
561: {
1.13 timbl 562: char * hexchars = "0123456789ABCDEF";
563: return hexchars[i];
1.2 timbl 564: }
1.1 timbl 565:
1.15 timbl 566: PUBLIC BOOL HTSearch ARGS3(
1.2 timbl 567: CONST char *, keywords,
1.15 timbl 568: HTParentAnchor *, here,
569: HTRequest *, request)
1.1 timbl 570: {
1.2 timbl 571:
572: #define acceptable \
573: "1234567890abcdefghijlkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_"
574:
575: char *q, *u;
576: CONST char * p, *s, *e; /* Pointers into keywords */
577: char * address = HTAnchor_address((HTAnchor*)here);
1.1 timbl 578: BOOL result;
1.2 timbl 579: char * escaped = malloc(strlen(keywords)*3+1);
580:
581: static CONST BOOL isAcceptable[96] =
582:
583: /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
584: { 0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,0, /* 2x !"#$%&'()*+,-./ */
585: 1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0, /* 3x 0123456789:;<=>? */
586: 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 4x @ABCDEFGHIJKLMNO */
587: 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1, /* 5X PQRSTUVWXYZ[\]^_ */
588: 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 6x `abcdefghijklmno */
589: 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0 }; /* 7X pqrstuvwxyz{\}~ DEL */
590:
591: if (escaped == NULL) outofmem(__FILE__, "HTSearch");
592:
593:
594: /* Convert spaces to + and hex escape unacceptable characters
595: */
596: for(s=keywords; *s && WHITE(*s); s++) /*scan */ ; /* Skip white space */
597: for(e = s + strlen(s); e>s && WHITE(*(e-1)) ; e--); /* Skip trailers */
598: for(q=escaped, p=s; p<e; p++) { /* scan stripped field */
599: int c = (int)TOASCII(*p);
600: if (WHITE(*p)) {
601: *q++ = '+';
602: } else if (c>=32 && c<=(char)127 && isAcceptable[c-32]) {
1.13 timbl 603: *q++ = *p; /* 930706 TBL for MVS bug */
1.2 timbl 604: } else {
605: *q++ = '%';
606: *q++ = hex(c / 16);
607: *q++ = hex(c % 16);
608: }
609: } /* Loop over string */
1.1 timbl 610:
1.2 timbl 611: *q=0;
612: /* terminate escaped sctring */
613: u=strchr(address, '?'); /* Find old search string */
614: if (u) *u = 0; /* Chop old search off */
1.1 timbl 615:
616: StrAllocCat(address, "?");
1.2 timbl 617: StrAllocCat(address, escaped);
618: free(escaped);
1.15 timbl 619: result = HTLoadRelative(address, here, request);
1.1 timbl 620: free(address);
1.2 timbl 621:
1.1 timbl 622: return result;
1.2 timbl 623: }
624:
625:
626: /* Search Given Indexname
627: ** ------
628: ** Performs a keyword search on word given by the user. Adds the keyword to
629: ** the end of the current address and attempts to open the new address.
630: **
631: ** On Entry,
632: ** *keywords space-separated keyword list or similar search list
633: ** *addres is name of object search is to be done on.
634: */
635:
1.15 timbl 636: PUBLIC BOOL HTSearchAbsolute ARGS3(
1.2 timbl 637: CONST char *, keywords,
1.15 timbl 638: CONST char *, indexname,
639: HTRequest *, request)
1.2 timbl 640: {
641: HTParentAnchor * anchor =
642: (HTParentAnchor*) HTAnchor_findAddress(indexname);
1.15 timbl 643: return HTSearch(keywords, anchor, request);
1.2 timbl 644: }
645:
646:
647: /* Generate the anchor for the home page
648: ** -------------------------------------
649: **
650: ** As it involves file access, this should only be done once
651: ** when the program first runs.
1.10 timbl 652: ** This is a default algorithm -- browser don't HAVE to use this.
653: ** But consistency betwen browsers is STRONGLY recommended!
1.2 timbl 654: **
1.10 timbl 655: ** Priority order is:
656: **
657: ** 1 WWW_HOME environment variable (logical name, etc)
658: ** 2 ~/WWW/default.html
659: ** 3 /usr/local/bin/default.html
660: ** 4 http://info.cern.ch/default.html
661: **
1.2 timbl 662: */
663: PUBLIC HTParentAnchor * HTHomeAnchor NOARGS
664: {
1.12 timbl 665: char * my_home_document = NULL;
666: char * home = (char *)getenv(LOGICAL_DEFAULT);
1.2 timbl 667: char * ref;
668: HTParentAnchor * anchor;
1.1 timbl 669:
1.12 timbl 670: if (home) {
671: StrAllocCopy(my_home_document, home);
672:
673: /* Someone telnets in, they get a special home.
674: */
675: #define MAX_FILE_NAME 1024 /* @@@ */
676: } else if (HTClientHost) { /* Telnet server */
677: FILE * fp = fopen(REMOTE_POINTER, "r");
678: char * status;
679: if (fp) {
680: my_home_document = (char*) malloc(MAX_FILE_NAME);
681: status = fgets(my_home_document, MAX_FILE_NAME, fp);
682: if (!status) {
683: free(my_home_document);
684: my_home_document = NULL;
685: }
686: fclose(fp);
687: }
688: if (!my_home_document) StrAllocCopy(my_home_document, REMOTE_ADDRESS);
689: }
690:
691:
692:
1.2 timbl 693: #ifdef unix
1.12 timbl 694:
1.10 timbl 695: if (!my_home_document) {
696: FILE * fp = NULL;
697: CONST char * home = (CONST char*)getenv("HOME");
698: if (home) {
699: my_home_document = (char *)malloc(
700: strlen(home)+1+ strlen(PERSONAL_DEFAULT)+1);
701: if (my_home_document == NULL) outofmem(__FILE__, "HTLocalName");
702: sprintf(my_home_document, "%s/%s", home, PERSONAL_DEFAULT);
703: fp = fopen(my_home_document, "r");
704: }
705:
706: if (!fp) {
707: StrAllocCopy(my_home_document, LOCAL_DEFAULT_FILE);
708: fp = fopen(my_home_document, "r");
709: }
1.2 timbl 710: if (fp) {
711: fclose(fp);
712: } else {
713: if (TRACE) fprintf(stderr,
1.10 timbl 714: "HTBrowse: No local home document ~/%s or %s\n",
715: PERSONAL_DEFAULT, LOCAL_DEFAULT_FILE);
1.11 timbl 716: free(my_home_document);
717: my_home_document = NULL;
1.2 timbl 718: }
719: }
720: #endif
1.10 timbl 721: ref = HTParse( my_home_document ? my_home_document :
722: HTClientHost ? REMOTE_ADDRESS
723: : LAST_RESORT,
724: "file:",
1.2 timbl 725: PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION);
1.10 timbl 726: if (my_home_document) {
1.2 timbl 727: if (TRACE) fprintf(stderr,
728: "HTAccess: Using custom home page %s i.e. address %s\n",
1.10 timbl 729: my_home_document, ref);
730: free(my_home_document);
1.2 timbl 731: }
732: anchor = (HTParentAnchor*) HTAnchor_findAddress(ref);
733: free(ref);
734: return anchor;
1.1 timbl 735: }
736:
737:
Webmaster