Annotation of libwww/Library/src/HTAccess.c, revision 1.65
1.61 frystyk 1: /* HTAccess.c
2: ** ACCESS MANAGER
3: **
4: ** (c) COPYRIGHT CERN 1994.
5: ** Please first read the full copyright statement in the file COPYRIGH.
1.1 timbl 6: **
7: ** Authors
8: ** TBL Tim Berners-Lee timbl@info.cern.ch
1.4 timbl 9: ** JFG Jean-Francois Groff jfg@dxcern.cern.ch
1.1 timbl 10: ** DD Denis DeLaRoca (310) 825-4580 <CSP1DWD@mvs.oac.ucla.edu>
11: ** History
12: ** 8 Jun 92 Telnet hopping prohibited as telnet is not secure TBL
13: ** 26 Jun 92 When over DECnet, suppressed FTP, Gopher and News. JFG
1.42 frystyk 14: ** 6 Oct 92 Moved HTClientHost and HTlogfile into here. TBL
1.1 timbl 15: ** 17 Dec 92 Tn3270 added, bug fix. DD
1.2 timbl 16: ** 4 Feb 93 Access registration, Search escapes bad chars TBL
1.9 timbl 17: ** PARAMETERS TO HTSEARCH AND HTLOADRELATIVE CHANGED
18: ** 28 May 93 WAIS gateway explicit if no WAIS library linked in.
1.19 timbl 19: ** Dec 93 Bug change around, more reentrant, etc
1.42 frystyk 20: ** 09 May 94 logfile renamed to HTlogfile to avoid clash with WAIS
1.53 duns 21: ** 8 Jul 94 Insulate free() from _free structure element.
1.2 timbl 22: ** Bugs
23: ** This module assumes that that the graphic object is hypertext, as it
1.9 timbl 24: ** needs to select it when it has been loaded. A superclass needs to be
1.2 timbl 25: ** defined which accepts select and select_anchor.
1.1 timbl 26: */
27:
1.9 timbl 28: #ifndef DEFAULT_WAIS_GATEWAY
1.8 timbl 29: #define DEFAULT_WAIS_GATEWAY "http://info.cern.ch:8001/"
1.54 frystyk 30: #endif
1.8 timbl 31:
1.1 timbl 32: /* Implements:
33: */
34: #include "HTAccess.h"
35:
36: /* Uses:
37: */
38:
39: #include "HTParse.h"
40: #include "HTUtils.h"
1.4 timbl 41: #include "HTML.h" /* SCW */
1.2 timbl 42:
43: #ifndef NO_RULES
44: #include "HTRules.h"
45: #endif
46:
47: #include "HTList.h"
48: #include "HText.h" /* See bugs above */
49: #include "HTAlert.h"
1.17 timbl 50: #include "HTFWriter.h" /* for cache stuff */
51: #include "HTTee.h"
1.46 frystyk 52: #include "HTError.h"
1.57 howcome 53: #include "HTTCP.h" /* HWL: for HTFindRelatedName */
1.63 frystyk 54: #include "HTFile.h"
1.59 frystyk 55: #include "HTThread.h"
1.63 frystyk 56: #include "HTEvent.h"
1.2 timbl 57:
1.54 frystyk 58: /* These flags may be set to modify the operation of this module */
59: PUBLIC char * HTCacheDir = NULL; /* Root for cached files or 0 for no cache */
60: PUBLIC char * HTSaveLocallyDir = SAVE_LOCALLY_HOME_DIR; /* Save & exe files */
61: PUBLIC char * HTClientHost = 0; /* Name of remote login host if any */
62: PUBLIC FILE * HTlogfile = 0; /* File to which to output one-liners */
1.41 luotonen 63:
1.34 frystyk 64: PUBLIC BOOL HTForceReload = NO; /* Force reload from cache or net */
1.12 timbl 65: PUBLIC BOOL HTSecure = NO; /* Disable access for telnet users? */
1.27 luotonen 66: PUBLIC BOOL using_proxy = NO; /* are we using a proxy gateway? */
1.43 luotonen 67: PUBLIC char * HTImServer = NULL;/* cern_httpd sets this to the translated URL*/
1.27 luotonen 68: PUBLIC BOOL HTImProxy = NO; /* cern_httpd as a proxy? */
1.1 timbl 69:
1.63 frystyk 70: PRIVATE HTList * protocols = NULL; /* List of registered protocols */
1.43 luotonen 71:
1.63 frystyk 72: /* Superclass defn */
1.24 timbl 73: struct _HTStream {
74: HTStreamClass * isa;
75: /* ... */
76: };
77:
1.59 frystyk 78: /* --------------------------------------------------------------------------*/
79: /* Management of the HTRequest structure */
80: /* --------------------------------------------------------------------------*/
81:
1.15 timbl 82: /* Create a request structure
83: ** ---------------------------
84: */
85: PUBLIC HTRequest * HTRequest_new NOARGS
86: {
1.28 luotonen 87: HTRequest * me = (HTRequest*) calloc(1, sizeof(*me)); /* zero fill */
1.15 timbl 88: if (!me) outofmem(__FILE__, "HTRequest_new()");
89:
1.20 luotonen 90: me->conversions = HTList_new(); /* No conversions registerd yet */
91: me->output_format = WWW_PRESENT; /* default it to present to user */
92:
1.15 timbl 93: return me;
94: }
95:
96:
1.49 frystyk 97: /* Clear a request structure
98: ** ---------------------------
99: ** This function clears the reguest structure so that only the
100: ** conversions remain. Everything else is as if it was created from
101: ** scratch.
102: */
103: PUBLIC void HTRequest_clear ARGS1(HTRequest *, req)
104: {
105: HTList *conversions;
106: if (!req) {
107: if (TRACE)
108: fprintf(stderr, "Clear....... request: Bad argument!\n");
109: return;
110: }
111: conversions = req->conversions; /* Save the conversions */
112: HTErrorFree(req);
113: HTAACleanup(req);
114: memset(req, '\0', sizeof(HTRequest));
115:
116: /* Now initialize as from scratch but with the old list of conversions */
117: req->conversions = conversions;
118: req->output_format = WWW_PRESENT; /* default it to present to user */
119: }
120:
121:
1.20 luotonen 122: /* Delete a request structure
123: ** --------------------------
124: */
125: PUBLIC void HTRequest_delete ARGS1(HTRequest *, req)
126: {
127: if (req) {
1.59 frystyk 128: FREE(req->redirect);
129: FREE(req->authenticate);
130: HTFormatDelete(req);
1.46 frystyk 131: HTErrorFree(req);
1.34 frystyk 132: HTAACleanup(req);
1.61 frystyk 133:
134: /* These are temporary until we get a MIME thingy */
135: FREE(req->redirect);
136: FREE(req->WWWAAScheme);
137: FREE(req->WWWAARealm);
138: FREE(req->WWWprotection);
139:
1.34 frystyk 140: FREE(req);
1.20 luotonen 141: }
142: }
143:
1.59 frystyk 144: /* --------------------------------------------------------------------------*/
145: /* Management of HTTP Methods */
146: /* --------------------------------------------------------------------------*/
1.20 luotonen 147:
1.22 luotonen 148: PRIVATE char * method_names[(int)MAX_METHODS + 1] =
149: {
150: "INVALID-METHOD",
151: "GET",
152: "HEAD",
153: "POST",
154: "PUT",
155: "DELETE",
156: "CHECKOUT",
157: "CHECKIN",
158: "SHOWMETHOD",
159: "LINK",
160: "UNLINK",
161: NULL
162: };
163:
164: /* Get method enum value
165: ** ---------------------
166: */
167: PUBLIC HTMethod HTMethod_enum ARGS1(char *, name)
168: {
169: if (name) {
170: int i;
171: for (i=1; i < (int)MAX_METHODS; i++)
172: if (!strcmp(name, method_names[i]))
173: return (HTMethod)i;
174: }
175: return METHOD_INVALID;
176: }
177:
178:
179: /* Get method name
180: ** ---------------
181: */
182: PUBLIC char * HTMethod_name ARGS1(HTMethod, method)
183: {
184: if ((int)method > (int)METHOD_INVALID &&
185: (int)method < (int)MAX_METHODS)
186: return method_names[(int)method];
187: else
188: return method_names[(int)METHOD_INVALID];
189: }
190:
191:
192: /* Is method in a list of method names?
193: ** -----------------------------------
194: */
195: PUBLIC BOOL HTMethod_inList ARGS2(HTMethod, method,
196: HTList *, list)
197: {
198: char * method_name = HTMethod_name(method);
199: HTList *cur = list;
200: char *item;
201:
202: while (NULL != (item = (char*)HTList_nextObject(cur))) {
203: CTRACE(stderr, " %s", item);
204: if (0==strcasecomp(item, method_name))
205: return YES;
206: }
207: return NO; /* Not found */
208: }
209:
210:
1.59 frystyk 211: /* --------------------------------------------------------------------------*/
212: /* Management of the HTProtocol structure */
213: /* --------------------------------------------------------------------------*/
1.22 luotonen 214:
1.63 frystyk 215: /*
216: ** Register a Protocol as an active access method
1.1 timbl 217: */
1.56 frystyk 218: PUBLIC BOOL HTRegisterProtocol ARGS1(HTProtocol *, protocol)
1.1 timbl 219: {
220: if (!protocols) protocols = HTList_new();
1.59 frystyk 221: HTList_addObject(protocols, (void *) protocol);
1.1 timbl 222: return YES;
223: }
224:
1.63 frystyk 225:
226: /*
227: ** Delete the list of registered access methods. This is called from
228: ** within HTLibTerminate. Written by Eric Sink, eric@spyglass.com
229: */
230: PUBLIC void HTDisposeProtocols NOARGS
231: {
232: if (protocols) {
233: HTList_delete(protocols);
234: protocols = NULL;
235: }
236: }
237:
238:
239: /*
1.65 ! frystyk 240: ** Is a protocol registered as BLOCKING? The default behavior registered
! 241: ** when the protocol module was registered can be overridden by the
! 242: ** BlockingIO field in the HTRequest structure
1.63 frystyk 243: */
1.59 frystyk 244: PUBLIC BOOL HTProtocolBlocking ARGS1(HTRequest *, me)
245: {
1.65 ! frystyk 246: if (me) {
! 247: return (me->BlockingIO || (me->anchor && me->anchor->protocol &&
! 248: ((HTProtocol *) (me->anchor->protocol))->block == SOC_BLOCK));
! 249: }
! 250: return NO;
1.59 frystyk 251: }
252:
1.61 frystyk 253: /* --------------------------------------------------------------------------*/
254: /* Initialization and Termination of the Library */
255: /* --------------------------------------------------------------------------*/
256:
1.1 timbl 257: /* Register all known protocols
258: ** ----------------------------
259: **
1.61 frystyk 260: ** Add to or subtract from this list if you add or remove protocol
261: ** modules. This function is called from HTLibInit()
1.1 timbl 262: **
263: ** Compiling with NO_INIT prevents all known protocols from being forced
264: ** in at link time.
265: */
1.61 frystyk 266: PRIVATE void HTAccessInit NOARGS
1.1 timbl 267: {
1.59 frystyk 268: GLOBALREF HTProtocol HTTP, HTFile, HTTelnet, HTTn3270, HTRlogin;
1.1 timbl 269: #ifndef DECNET
1.54 frystyk 270: #ifdef NEW_CODE
1.59 frystyk 271: GLOBALREF HTProtocol HTFTP, HTNews, HTNNTP, HTGopher;
272: #endif
273: GLOBALREF HTProtocol HTFTP, HTNews, HTGopher;
274: #ifdef DIRECT_WAIS
275: GLOBALREF HTProtocol HTWAIS;
1.54 frystyk 276: #endif
1.42 frystyk 277:
1.2 timbl 278: HTRegisterProtocol(&HTFTP);
279: HTRegisterProtocol(&HTNews);
1.54 frystyk 280: #ifdef NEW_CODE
281: HTRegisterProtocol(&HTNNTP);
282: #endif
1.2 timbl 283: HTRegisterProtocol(&HTGopher);
1.42 frystyk 284:
1.3 timbl 285: #ifdef DIRECT_WAIS
286: HTRegisterProtocol(&HTWAIS);
287: #endif
1.1 timbl 288:
1.54 frystyk 289: #endif /* DECNET */
1.2 timbl 290: HTRegisterProtocol(&HTTP);
291: HTRegisterProtocol(&HTFile);
292: HTRegisterProtocol(&HTTelnet);
293: HTRegisterProtocol(&HTTn3270);
294: HTRegisterProtocol(&HTRlogin);
1.1 timbl 295: }
1.61 frystyk 296:
297:
298: /* HTLibInit
299: **
300: ** This function initiates the Library and it MUST be called when
301: ** starting up an application. See also HTLibTerminate()
302: */
303: PUBLIC BOOL HTLibInit NOARGS
304: {
305: if (TRACE)
306: fprintf(stderr, "WWWLibInit.. INITIALIZING LIBRARY OF COMMON CODE\n");
1.63 frystyk 307:
308: #ifndef NO_INIT
1.61 frystyk 309: if (!protocols)
1.62 frystyk 310: HTAccessInit(); /* Initilizing protocol modules */
1.63 frystyk 311: #endif
1.61 frystyk 312:
1.62 frystyk 313: #ifdef WWWLIB_SIG
1.61 frystyk 314: /* On Solaris (and others?) we get a BROKEN PIPE signal when connecting
315: ** to a port where er should get `connection refused'. We ignore this
316: ** using the following function call
317: */
318: HTSetSignal(); /* Set signals in library */
1.1 timbl 319: #endif
320:
1.61 frystyk 321: HTThreadInit(); /* Initialize bit arrays */
322: return YES;
323: }
324:
325:
326: /* HTLibTerminate
327: **
328: ** This function frees memory kept by the Library and should be called
1.63 frystyk 329: ** before exit of an application (if you are on a PC platform)
1.61 frystyk 330: */
331: PUBLIC BOOL HTLibTerminate NOARGS
332: {
333: if (TRACE)
1.63 frystyk 334: fprintf(stderr, "WWWLibTerm.. Cleaning up LIBRARY OF COMMON CODE\n");
335: HTAtom_deleteAll();
336: HTDisposeProtocols();
337: HTDisposeConversions();
338: HTFile_deleteSuffixes();
339: HTTCPCacheRemoveAll();
340: HTFreeHostName();
341: HTFreeMailAddress();
1.61 frystyk 342: return YES;
343: }
344:
345:
1.59 frystyk 346: /* --------------------------------------------------------------------------*/
347: /* Physical Anchor Address Manager */
348: /* --------------------------------------------------------------------------*/
1.33 luotonen 349:
350: /* override_proxy()
351: **
352: ** Check the no_proxy environment variable to get the list
353: ** of hosts for which proxy server is not consulted.
354: **
355: ** no_proxy is a comma- or space-separated list of machine
356: ** or domain names, with optional :port part. If no :port
357: ** part is present, it applies to all ports on that domain.
358: **
359: ** Example:
360: ** no_proxy="cern.ch,some.domain:8001"
361: **
362: */
363: PRIVATE BOOL override_proxy ARGS1(CONST char *, addr)
364: {
365: CONST char * no_proxy = getenv("no_proxy");
366: char * p = NULL;
367: char * host = NULL;
368: int port = 0;
369: int h_len = 0;
370:
371: if (!no_proxy || !addr || !(host = HTParse(addr, "", PARSE_HOST)))
372: return NO;
373: if (!*host) { free(host); return NO; }
374:
1.34 frystyk 375: if ((p = strchr(host, ':')) != NULL) { /* Port specified */
1.33 luotonen 376: *p++ = 0; /* Chop off port */
377: port = atoi(p);
378: }
379: else { /* Use default port */
380: char * access = HTParse(addr, "", PARSE_ACCESS);
381: if (access) {
382: if (!strcmp(access,"http")) port = 80;
383: else if (!strcmp(access,"gopher")) port = 70;
384: else if (!strcmp(access,"ftp")) port = 21;
385: free(access);
386: }
387: }
388: if (!port) port = 80; /* Default */
389: h_len = strlen(host);
390:
391: while (*no_proxy) {
392: CONST char * end;
393: CONST char * colon = NULL;
394: int templ_port = 0;
395: int t_len;
396:
397: while (*no_proxy && (WHITE(*no_proxy) || *no_proxy==','))
398: no_proxy++; /* Skip whitespace and separators */
399:
400: end = no_proxy;
401: while (*end && !WHITE(*end) && *end != ',') { /* Find separator */
402: if (*end==':') colon = end; /* Port number given */
403: end++;
404: }
405:
406: if (colon) {
407: templ_port = atoi(colon+1);
408: t_len = colon - no_proxy;
409: }
410: else {
411: t_len = end - no_proxy;
412: }
413:
414: if ((!templ_port || templ_port == port) &&
415: (t_len > 0 && t_len <= h_len &&
416: !strncmp(host + h_len - t_len, no_proxy, t_len))) {
417: free(host);
418: return YES;
419: }
420: if (*end) no_proxy = end+1;
421: else break;
422: }
423:
424: free(host);
425: return NO;
426: }
427:
428:
429:
1.2 timbl 430: /* Find physical name and access protocol
431: ** --------------------------------------
1.1 timbl 432: **
433: **
434: ** On entry,
435: ** addr must point to the fully qualified hypertext reference.
436: ** anchor a pareent anchor with whose address is addr
437: **
1.59 frystyk 438: ** On exit,
439: ** returns HT_NO_ACCESS no protocol module found
440: ** HT_FORBIDDEN Error has occured.
1.2 timbl 441: ** HT_OK Success
1.1 timbl 442: **
443: */
1.21 luotonen 444: PRIVATE int get_physical ARGS1(HTRequest *, req)
445: {
1.1 timbl 446: char * access=0; /* Name of access method */
1.21 luotonen 447: char * addr = HTAnchor_address((HTAnchor*)req->anchor); /* free me */
1.27 luotonen 448:
1.2 timbl 449: #ifndef NO_RULES
1.47 luotonen 450: if (HTImServer) { /* cern_httpd has already done its own translations */
1.45 luotonen 451: HTAnchor_setPhysical(req->anchor, HTImServer);
1.47 luotonen 452: StrAllocCopy(addr, HTImServer); /* Oops, queries thru many proxies */
453: /* didn't work without this -- AL */
454: }
1.21 luotonen 455: else {
1.27 luotonen 456: char * physical = HTTranslate(addr);
1.21 luotonen 457: if (!physical) {
1.47 luotonen 458: free(addr);
1.21 luotonen 459: return HT_FORBIDDEN;
460: }
461: HTAnchor_setPhysical(req->anchor, physical);
462: free(physical); /* free our copy */
1.2 timbl 463: }
464: #else
1.21 luotonen 465: HTAnchor_setPhysical(req->anchor, addr);
1.2 timbl 466: #endif
467:
1.21 luotonen 468: access = HTParse(HTAnchor_physical(req->anchor),
1.27 luotonen 469: "file:", PARSE_ACCESS);
1.1 timbl 470:
471: /* Check whether gateway access has been set up for this
1.8 timbl 472: **
473: ** This function can be replaced by the rule system above.
1.1 timbl 474: */
1.8 timbl 475: #define USE_GATEWAYS
1.1 timbl 476: #ifdef USE_GATEWAYS
1.39 luotonen 477:
478: /* make sure the using_proxy variable is false */
479: using_proxy = NO;
480:
1.33 luotonen 481: if (!override_proxy(addr)) {
1.27 luotonen 482: char * gateway_parameter, *gateway, *proxy;
483:
1.2 timbl 484: gateway_parameter = (char *)malloc(strlen(access)+20);
485: if (gateway_parameter == NULL) outofmem(__FILE__, "HTLoad");
1.27 luotonen 486:
487: /* search for proxy gateways */
1.2 timbl 488: strcpy(gateway_parameter, "WWW_");
489: strcat(gateway_parameter, access);
490: strcat(gateway_parameter, "_GATEWAY");
491: gateway = (char *)getenv(gateway_parameter); /* coerce for decstation */
1.27 luotonen 492:
493: /* search for proxy servers */
494: strcpy(gateway_parameter, access);
495: strcat(gateway_parameter, "_proxy");
496: proxy = (char *)getenv(gateway_parameter);
497:
1.2 timbl 498: free(gateway_parameter);
1.27 luotonen 499:
500: if (TRACE && gateway)
1.60 frystyk 501: fprintf(stderr,"Gateway..... Found: `%s\'\n", gateway);
1.27 luotonen 502: if (TRACE && proxy)
1.60 frystyk 503: fprintf(stderr,"Proxy....... Found: `%s\'\n", proxy);
1.27 luotonen 504:
1.8 timbl 505: #ifndef DIRECT_WAIS
1.9 timbl 506: if (!gateway && 0==strcmp(access, "wais")) {
1.8 timbl 507: gateway = DEFAULT_WAIS_GATEWAY;
508: }
509: #endif
1.27 luotonen 510:
511: /* proxy servers have precedence over gateway servers */
1.60 frystyk 512: if (proxy && *proxy) {
1.27 luotonen 513: char * gatewayed=0;
514:
515: StrAllocCopy(gatewayed,proxy);
516: StrAllocCat(gatewayed,addr);
517: using_proxy = YES;
518: HTAnchor_setPhysical(req->anchor, gatewayed);
519: free(gatewayed);
520: free(access);
521:
522: access = HTParse(HTAnchor_physical(req->anchor),
523: "http:", PARSE_ACCESS);
1.60 frystyk 524: } else if (gateway && *gateway) {
1.9 timbl 525: char * path = HTParse(addr, "",
526: PARSE_HOST + PARSE_PATH + PARSE_PUNCTUATION);
527: /* Chop leading / off to make host into part of path */
528: char * gatewayed = HTParse(path+1, gateway, PARSE_ALL);
529: free(path);
1.21 luotonen 530: HTAnchor_setPhysical(req->anchor, gatewayed);
1.9 timbl 531: free(gatewayed);
1.2 timbl 532: free(access);
1.9 timbl 533:
1.21 luotonen 534: access = HTParse(HTAnchor_physical(req->anchor),
1.8 timbl 535: "http:", PARSE_ACCESS);
1.2 timbl 536: }
537: }
1.1 timbl 538: #endif
539:
1.19 timbl 540: free(addr);
1.1 timbl 541:
1.61 frystyk 542: /* Search registered protocols to find suitable one */
1.1 timbl 543: {
1.61 frystyk 544: HTList *cur = protocols;
1.20 luotonen 545: HTProtocol *p;
1.61 frystyk 546: if (!cur) {
547: if (TRACE)
548: fprintf(stderr, "HTAccess.... NO PROTOCOL MODULES INITIATED\n");
549: } else {
550: while ((p = (HTProtocol*)HTList_nextObject(cur))) {
551: if (strcmp(p->name, access)==0) {
552: HTAnchor_setProtocol(req->anchor, p);
553: free(access);
554: return (HT_OK);
555: }
1.1 timbl 556: }
557: }
558: }
559: free(access);
1.2 timbl 560: return HT_NO_ACCESS;
1.1 timbl 561: }
562:
1.59 frystyk 563: /* --------------------------------------------------------------------------*/
564: /* Document Poster */
565: /* --------------------------------------------------------------------------*/
566:
567: /* Get a save stream for a document
568: ** --------------------------------
569: */
570: PUBLIC HTStream *HTSaveStream ARGS1(HTRequest *, request)
571: {
572: HTProtocol * p;
573: int status;
574: request->method = METHOD_PUT;
575: status = get_physical(request);
576: if (status == HT_FORBIDDEN) {
577: char *url = HTAnchor_address((HTAnchor *) request->anchor);
578: if (url) {
579: HTUnEscape(url);
580: HTErrorAdd(request, ERR_FATAL, NO, HTERR_FORBIDDEN,
581: (void *) url, (int) strlen(url), "HTLoad");
582: free(url);
583: } else {
584: HTErrorAdd(request, ERR_FATAL, NO, HTERR_FORBIDDEN,
585: NULL, 0, "HTLoad");
586: }
587: return NULL; /* should return error status? */
588: }
589: if (status < 0) return NULL; /* @@ error. Can't resolve or forbidden */
590:
591: p = (HTProtocol *) HTAnchor_protocol(request->anchor);
592: if (!p) return NULL;
593:
594: return (*p->saveStream)(request);
595:
596: }
597:
598:
599: /* --------------------------------------------------------------------------*/
600: /* Document Loader */
601: /* --------------------------------------------------------------------------*/
1.1 timbl 602:
603: /* Load a document
604: ** ---------------
605: **
1.2 timbl 606: ** This is an internal routine, which has an address AND a matching
607: ** anchor. (The public routines are called with one OR the other.)
608: **
609: ** On entry,
1.15 timbl 610: ** request->
1.35 luotonen 611: ** anchor a parent anchor with fully qualified
612: ** hypertext reference as its address set
1.15 timbl 613: ** output_format valid
614: ** output_stream valid on NULL
1.2 timbl 615: **
616: ** On exit,
1.59 frystyk 617: ** returns HT_WOULD_BLOCK An I/O operation would block
618: ** HT_ERROR Error has occured
1.2 timbl 619: ** HT_LOADED Success
620: ** HT_NO_DATA Success, but no document loaded.
1.8 timbl 621: ** (telnet sesssion started etc)
1.2 timbl 622: **
623: */
1.52 frystyk 624: PUBLIC int HTLoad ARGS2(HTRequest *, request, BOOL, keep_error_stack)
1.2 timbl 625: {
1.25 frystyk 626: char *arg = NULL;
627: HTProtocol *p;
628: int status;
629:
1.22 luotonen 630: if (request->method == METHOD_INVALID)
631: request->method = METHOD_GET;
1.52 frystyk 632: if (!keep_error_stack) {
633: HTErrorFree(request);
634: request->error_block = NO;
635: }
636:
1.59 frystyk 637: if ((status = get_physical(request)) < 0) {
638: if (status == HT_FORBIDDEN) {
639: char *url = HTAnchor_address((HTAnchor *) request->anchor);
640: if (url) {
641: HTUnEscape(url);
642: HTErrorAdd(request, ERR_FATAL, NO, HTERR_FORBIDDEN,
643: (void *) url, (int) strlen(url), "HTLoad");
644: free(url);
645: } else {
646: HTErrorAdd(request, ERR_FATAL, NO, HTERR_FORBIDDEN,
647: NULL, 0, "HTLoad");
648: }
649: }
650: return HT_ERROR; /* Can't resolve or forbidden */
1.2 timbl 651: }
1.25 frystyk 652:
653: if(!(arg = HTAnchor_physical(request->anchor)) || !*arg)
1.59 frystyk 654: return HT_ERROR;
1.27 luotonen 655:
1.56 frystyk 656: p = (HTProtocol *) HTAnchor_protocol(request->anchor);
1.17 timbl 657: return (*(p->load))(request);
1.2 timbl 658: }
659:
660:
1.61 frystyk 661: /* Terminate a LOAD
662: ** ----------------
663: **
664: ** This function looks at the status code from the HTLoadDocument
665: ** function and updates logfiles, creates error messages etc.
666: **
667: ** On Entry,
668: ** Status code from load function
669: */
670: PUBLIC BOOL HTLoadTerminate ARGS2(HTRequest *, request, int, status)
671: {
672: char * uri = HTAnchor_address((HTAnchor*)request->anchor);
673:
674: /* Log the access if necessary */
675: if (HTlogfile) {
676: time_t theTime;
677: time(&theTime);
678: fprintf(HTlogfile, "%24.24s %s %s %s\n",
679: ctime(&theTime),
680: HTClientHost ? HTClientHost : "local",
681: status<0 ? "FAIL" : "GET", uri);
682: fflush(HTlogfile); /* Actually update it on disk */
683: if (PROT_TRACE) fprintf(stderr, "Log: %24.24s %s %s %s\n",
684: ctime(&theTime),
685: HTClientHost ? HTClientHost : "local",
686: status<0 ? "FAIL" : "GET", uri);
687: }
688:
689: /* The error stack might contain general information to the client
690: about what has been going on in the library (not only errors) */
691: if (!HTImProxy && request->error_stack)
692: HTErrorMsg(request);
693:
694: switch (status) {
695: case HT_LOADED:
696: if (PROT_TRACE) {
697: fprintf(stderr, "HTAccess.... OK: `%s' has been accessed.\n", uri);
698: }
699: break;
700:
701: case HT_NO_DATA:
702: if (PROT_TRACE) {
703: fprintf(stderr, "HTAccess.... OK BUT NO DATA: `%s'\n", uri);
704: }
705: break;
706:
707: case HT_WOULD_BLOCK:
708: if (PROT_TRACE) {
709: fprintf(stderr, "HTAccess.... WOULD BLOCK: `%s'\n", uri);
710: }
711: break;
712:
713: case HT_ERROR:
714: if (HTImProxy)
715: HTErrorMsg(request); /* Only on a real error */
716: if (PROT_TRACE) {
717: fprintf(stderr, "HTAccess.... ERROR: Can't access `%s'\n", uri);
718: }
719: break;
720:
721: default:
722: if (PROT_TRACE) {
723: fprintf(stderr, "HTAccess.... Internal software error in CERN WWWLib version %s ****\n\nPlease mail www-bug@info.cern.ch quoting what software and what version you are using\nand the URL: %s that caused the problem, thanks!\n",
724: HTLibraryVersion, uri);
725: }
726: break;
727: }
728: free(uri);
729: return YES;
730: }
731:
732:
1.2 timbl 733: /* Load a document - with logging etc
734: ** ----------------------------------
735: **
736: ** - Checks or documents already loaded
737: ** - Logs the access
738: ** - Allows stdin filter option
739: ** - Trace ouput and error messages
740: **
1.1 timbl 741: ** On Entry,
1.19 timbl 742: ** request->anchor valid for of the document to be accessed.
743: ** request->childAnchor optional anchor within doc to be selected
744: **
1.2 timbl 745: ** filter if YES, treat stdin as HTML
1.1 timbl 746: **
1.15 timbl 747: ** request->anchor is the node_anchor for the document
748: ** request->output_format is valid
749: **
1.59 frystyk 750: ** On exit,
751: ** returns HT_WOULD_BLOCK An I/O operation would block
752: ** HT_ERROR Error has occured
753: ** HT_LOADED Success
754: ** HT_NO_DATA Success, but no document loaded.
755: ** (telnet sesssion started etc)
1.1 timbl 756: */
1.59 frystyk 757: PRIVATE int HTLoadDocument ARGS2(HTRequest *, request,
758: BOOL, keep_error_stack)
1.1 timbl 759:
760: {
761: int status;
762: HText * text;
1.19 timbl 763: char * full_address = HTAnchor_address((HTAnchor*)request->anchor);
1.54 frystyk 764:
1.59 frystyk 765: if (PROT_TRACE) fprintf (stderr, "HTAccess.... Loading document %s\n",
766: full_address);
1.1 timbl 767:
1.18 timbl 768: request->using_cache = NULL;
769:
1.15 timbl 770: if (!request->output_format) request->output_format = WWW_PRESENT;
1.25 frystyk 771:
1.63 frystyk 772: /* Check if document is already loaded */
1.31 frystyk 773: if (!HTForceReload && (text=(HText *)HTAnchor_document(request->anchor)))
1.63 frystyk 774: {
1.59 frystyk 775: if (PROT_TRACE)
776: fprintf(stderr, "HTAccess.... Document already in memory.\n");
1.19 timbl 777: if (request->childAnchor) {
778: HText_selectAnchor(text, request->childAnchor);
779: } else {
780: HText_select(text);
781: }
782: free(full_address);
1.59 frystyk 783: return HT_LOADED;
1.1 timbl 784: }
1.17 timbl 785:
1.34 frystyk 786: /* Check the Cache */
1.17 timbl 787: /* Bug: for each format, we only check whether it is ok, we
788: don't check them all and chose the best */
1.54 frystyk 789: if (request->anchor->cacheItems) {
1.17 timbl 790: HTList * list = request->anchor->cacheItems;
1.20 luotonen 791: HTList * cur = list;
792: HTCacheItem * item;
793:
794: while ((item = (HTCacheItem*)HTList_nextObject(cur))) {
1.18 timbl 795: HTStream * s;
796:
797: request->using_cache = item;
798:
1.59 frystyk 799: s = HTStreamStack(item->format, request->output_format,
800: request->output_stream, request, NO);
1.17 timbl 801: if (s) { /* format was suitable */
802: FILE * fp = fopen(item->filename, "r");
1.59 frystyk 803: if (PROT_TRACE)
1.57 howcome 804: fprintf(stderr, "Cache: HIT file %s for %s\n",
1.20 luotonen 805: item->filename,
806: full_address);
1.17 timbl 807: if (fp) {
808: HTFileCopy(fp, s);
1.53 duns 809: (*s->isa->_free)(s); /* close up pipeline */
1.17 timbl 810: fclose(fp);
1.19 timbl 811: free(full_address);
1.59 frystyk 812: return HT_LOADED;
1.17 timbl 813: } else {
814: fprintf(stderr, "***** Can't read cache file %s !\n",
1.20 luotonen 815: item->filename);
1.17 timbl 816: } /* file open ok */
817: } /* stream ok */
818: } /* next cache item */
819: } /* if cache available for this anchor */
1.1 timbl 820:
1.61 frystyk 821: if ((status = HTLoad(request, keep_error_stack)) != HT_WOULD_BLOCK)
822: HTLoadTerminate(request, status);
1.19 timbl 823: free(full_address);
1.59 frystyk 824: return status;
1.58 frystyk 825: }
1.1 timbl 826:
827:
828: /* Load a document from absolute name
829: ** ---------------
830: **
1.59 frystyk 831: ** On Entry,
1.1 timbl 832: ** addr The absolute address of the document to be accessed.
833: ** filter if YES, treat document as HTML
834: **
1.59 frystyk 835: ** On exit,
836: ** returns HT_WOULD_BLOCK An I/O operation would block
837: ** HT_ERROR Error has occured
838: ** HT_LOADED Success
839: ** HT_NO_DATA Success, but no document loaded.
840: ** (telnet sesssion started etc)
1.1 timbl 841: */
842:
1.59 frystyk 843: PUBLIC int HTLoadAbsolute ARGS2(CONST char *,addr, HTRequest*, request)
1.2 timbl 844: {
1.19 timbl 845: HTAnchor * anchor = HTAnchor_findAddress(addr);
846: request->anchor = HTAnchor_parent(anchor);
847: request->childAnchor = ((HTAnchor*)request->anchor == anchor) ?
848: NULL : (HTChildAnchor*) anchor;
1.52 frystyk 849: return HTLoadDocument(request, NO);
1.2 timbl 850: }
851:
852:
853: /* Load a document from absolute name to stream
854: ** --------------------------------------------
855: **
1.59 frystyk 856: ** On Entry,
1.2 timbl 857: ** addr The absolute address of the document to be accessed.
1.15 timbl 858: ** request->output_stream if non-NULL, send data down this stream
1.2 timbl 859: **
1.59 frystyk 860: ** On exit,
861: ** returns HT_WOULD_BLOCK An I/O operation would block
862: ** HT_ERROR Error has occured
863: ** HT_LOADED Success
864: ** HT_NO_DATA Success, but no document loaded.
865: ** (telnet sesssion started etc)
1.2 timbl 866: */
867:
1.59 frystyk 868: PUBLIC int HTLoadToStream ARGS3(CONST char *, addr,
869: BOOL, filter,
870: HTRequest*, request)
1.1 timbl 871: {
1.63 frystyk 872: HTAnchor * anchor = HTAnchor_findAddress(addr);
873: request->anchor = HTAnchor_parent(anchor);
874: request->childAnchor = ((HTAnchor*)request->anchor == anchor) ? NULL :
1.19 timbl 875: (HTChildAnchor*) anchor;
1.15 timbl 876: request->output_stream = request->output_stream;
1.52 frystyk 877: return HTLoadDocument(request, NO);
1.1 timbl 878: }
879:
880:
881: /* Load a document from relative name
882: ** ---------------
883: **
1.59 frystyk 884: ** On Entry,
1.2 timbl 885: ** relative_name The relative address of the document
886: ** to be accessed.
1.1 timbl 887: **
1.59 frystyk 888: ** On exit,
889: ** returns HT_WOULD_BLOCK An I/O operation would block
890: ** HT_ERROR Error has occured
891: ** HT_LOADED Success
892: ** HT_NO_DATA Success, but no document loaded.
893: ** (telnet sesssion started etc)
1.1 timbl 894: */
895:
1.59 frystyk 896: PUBLIC int HTLoadRelative ARGS3(CONST char *, relative_name,
897: HTParentAnchor *, here,
898: HTRequest *, request)
1.1 timbl 899: {
900: char * full_address = 0;
1.65 ! frystyk 901: int result;
1.1 timbl 902: char * mycopy = 0;
903: char * stripped = 0;
904: char * current_address =
1.2 timbl 905: HTAnchor_address((HTAnchor*)here);
1.1 timbl 906:
907: StrAllocCopy(mycopy, relative_name);
908:
909: stripped = HTStrip(mycopy);
910: full_address = HTParse(stripped,
911: current_address,
912: PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION);
1.15 timbl 913: result = HTLoadAbsolute(full_address, request);
1.1 timbl 914: free(full_address);
915: free(current_address);
916: free(mycopy); /* Memory leak fixed 10/7/92 -- JFG */
917: return result;
918: }
919:
920:
921: /* Load if necessary, and select an anchor
922: ** --------------------------------------
923: **
1.59 frystyk 924: ** On Entry,
1.1 timbl 925: ** destination The child or parenet anchor to be loaded.
926: **
1.59 frystyk 927: ** On exit,
928: ** returns HT_WOULD_BLOCK An I/O operation would block
929: ** HT_ERROR Error has occured
930: ** HT_LOADED Success
931: ** HT_NO_DATA Success, but no document loaded.
932: ** (telnet sesssion started etc)
1.1 timbl 933: */
934:
1.59 frystyk 935: PUBLIC int HTLoadAnchor ARGS2(HTAnchor*, anchor, HTRequest *, request)
1.1 timbl 936: {
1.59 frystyk 937: if (!anchor) return HT_ERROR; /* No link */
1.1 timbl 938:
1.15 timbl 939: request->anchor = HTAnchor_parent(anchor);
1.59 frystyk 940: request->childAnchor = ((HTAnchor *) request->anchor == anchor) ?
941: NULL : (HTChildAnchor*) anchor;
942: return HTLoadDocument(request, NO);
943: }
1.52 frystyk 944:
945:
946: /* Load if necessary, and select an anchor
947: ** --------------------------------------
948: **
949: ** This function is almost identical to HTLoadAnchor, but it doesn't
950: ** clear the error stack so that the information in there is kept.
951: **
1.59 frystyk 952: ** On Entry,
1.52 frystyk 953: ** destination The child or parenet anchor to be loaded.
954: **
1.59 frystyk 955: ** On exit,
956: ** returns HT_WOULD_BLOCK An I/O operation would block
957: ** HT_ERROR Error has occured
958: ** HT_LOADED Success
959: ** HT_NO_DATA Success, but no document loaded.
960: ** (telnet sesssion started etc)
1.52 frystyk 961: */
962:
1.59 frystyk 963: PUBLIC int HTLoadAnchorRecursive ARGS2(HTAnchor*, anchor,
964: HTRequest *, request)
1.52 frystyk 965: {
1.59 frystyk 966: if (!anchor) return HT_ERROR; /* No link */
1.52 frystyk 967:
968: request->anchor = HTAnchor_parent(anchor);
1.59 frystyk 969: request->childAnchor = ((HTAnchor *) request->anchor == anchor) ?
970: NULL : (HTChildAnchor*) anchor;
1.52 frystyk 971:
1.59 frystyk 972: return HTLoadDocument(request, YES);
973: }
1.1 timbl 974:
975:
976: /* Search
977: ** ------
978: ** Performs a keyword search on word given by the user. Adds the keyword to
979: ** the end of the current address and attempts to open the new address.
980: **
981: ** On Entry,
982: ** *keywords space-separated keyword list or similar search list
1.2 timbl 983: ** here is anchor search is to be done on.
1.59 frystyk 984: **
985: ** On exit,
986: ** returns HT_WOULD_BLOCK An I/O operation would block
987: ** HT_ERROR Error has occured
988: ** HT_LOADED Success
989: ** HT_NO_DATA Success, but no document loaded.
990: ** (telnet sesssion started etc)
1.1 timbl 991: */
992:
1.56 frystyk 993: PRIVATE char hex ARGS1(int, i)
1.2 timbl 994: {
1.13 timbl 995: char * hexchars = "0123456789ABCDEF";
996: return hexchars[i];
1.2 timbl 997: }
1.1 timbl 998:
1.59 frystyk 999: PUBLIC int HTSearch ARGS3(CONST char *, keywords,
1000: HTParentAnchor *, here,
1001: HTRequest *, request)
1.1 timbl 1002: {
1.2 timbl 1003:
1004: #define acceptable \
1005: "1234567890abcdefghijlkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_"
1006:
1007: char *q, *u;
1008: CONST char * p, *s, *e; /* Pointers into keywords */
1009: char * address = HTAnchor_address((HTAnchor*)here);
1.65 ! frystyk 1010: int result;
1.56 frystyk 1011: char * escaped = (char *) malloc(strlen(keywords)*3+1);
1.2 timbl 1012:
1.29 frystyk 1013: /* static CONST BOOL isAcceptable[96] = */
1014: /* static AND const is not good for a gnu compiler! Frystyk 25/02-94 */
1.30 luotonen 1015: static BOOL isAcceptable[96] =
1.2 timbl 1016: /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
1017: { 0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,0, /* 2x !"#$%&'()*+,-./ */
1018: 1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0, /* 3x 0123456789:;<=>? */
1019: 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 4x @ABCDEFGHIJKLMNO */
1020: 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1, /* 5X PQRSTUVWXYZ[\]^_ */
1021: 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 6x `abcdefghijklmno */
1022: 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0 }; /* 7X pqrstuvwxyz{\}~ DEL */
1023:
1024: if (escaped == NULL) outofmem(__FILE__, "HTSearch");
1025:
1.29 frystyk 1026: /* Convert spaces to + and hex escape unacceptable characters */
1.2 timbl 1027:
1.29 frystyk 1028: for(s=keywords; *s && WHITE(*s); s++); /*scan */ /* Skip white space */
1029: for(e = s + strlen(s); e>s && WHITE(*(e-1)) ; e--); /* Skip trailers */
1030: for(q=escaped, p=s; p<e; p++) { /* scan stripped field */
1.2 timbl 1031: int c = (int)TOASCII(*p);
1032: if (WHITE(*p)) {
1033: *q++ = '+';
1.29 frystyk 1034: } else if (c>=32 && c<=127 && isAcceptable[c-32] != 0) {
1.13 timbl 1035: *q++ = *p; /* 930706 TBL for MVS bug */
1.2 timbl 1036: } else {
1037: *q++ = '%';
1038: *q++ = hex(c / 16);
1039: *q++ = hex(c % 16);
1040: }
1041: } /* Loop over string */
1.1 timbl 1042:
1.2 timbl 1043: *q=0;
1044: /* terminate escaped sctring */
1045: u=strchr(address, '?'); /* Find old search string */
1046: if (u) *u = 0; /* Chop old search off */
1.1 timbl 1047:
1048: StrAllocCat(address, "?");
1.2 timbl 1049: StrAllocCat(address, escaped);
1050: free(escaped);
1.15 timbl 1051: result = HTLoadRelative(address, here, request);
1.1 timbl 1052: free(address);
1.2 timbl 1053:
1.1 timbl 1054: return result;
1.2 timbl 1055: }
1056:
1057:
1058: /* Search Given Indexname
1059: ** ------
1060: ** Performs a keyword search on word given by the user. Adds the keyword to
1061: ** the end of the current address and attempts to open the new address.
1062: **
1.59 frystyk 1063: ** On Entry,
1.2 timbl 1064: ** *keywords space-separated keyword list or similar search list
1065: ** *addres is name of object search is to be done on.
1.59 frystyk 1066: ** On exit,
1067: ** returns HT_WOULD_BLOCK An I/O operation would block
1068: ** HT_ERROR Error has occured
1069: ** HT_LOADED Success
1070: ** HT_NO_DATA Success, but no document loaded.
1071: ** (telnet sesssion started etc)
1.2 timbl 1072: */
1073:
1.59 frystyk 1074: PUBLIC int HTSearchAbsolute ARGS3(CONST char *, keywords,
1075: CONST char *, indexname,
1076: HTRequest *, request)
1.2 timbl 1077: {
1078: HTParentAnchor * anchor =
1079: (HTParentAnchor*) HTAnchor_findAddress(indexname);
1.15 timbl 1080: return HTSearch(keywords, anchor, request);
1.57 howcome 1081: }
1082:
1083:
1084: /*
1085: ** Find Related Name
1086: **
1087: ** Creates a string that can be used as a related name when
1088: ** calling HTParse initially.
1089: **
1090: ** The code for this routine originates from the Linemode
1091: ** browser and was moved here by howcome@dxcern.cern.ch
1092: ** in order for all clients to take advantage.
1093: **
1.59 frystyk 1094: ** The string returned must be freed by the caller
1.57 howcome 1095: */
1096: PUBLIC char * HTFindRelatedName NOARGS
1097: {
1.59 frystyk 1098: char* default_default = NULL; /* Parse home relative to this */
1099: CONST char *host = HTGetHostName();
1.57 howcome 1100: StrAllocCopy(default_default, "file://");
1.59 frystyk 1101: if (host)
1102: StrAllocCat(default_default, host);
1103: else
1104: StrAllocCat(default_default, "localhost");
1105: {
1106: char wd[HT_MAX_PATH+1];
1.57 howcome 1107:
1.59 frystyk 1108: #ifdef NO_GETWD
1109: #ifdef HAS_GETCWD /* System V variant SIGN CHANGED TBL 921006 !! */
1110: char *result = (char *) getcwd(wd, sizeof(wd));
1111: #else
1112: char *result = NULL;
1113: HTAlert("This platform does not support neither getwd nor getcwd\n");
1.57 howcome 1114: #endif
1.59 frystyk 1115: #else
1116: char *result = (char *) getwd(wd);
1117: #endif
1118: *(wd+HT_MAX_PATH) = '\0';
1.57 howcome 1119: if (result) {
1120: #ifdef VMS
1121: /* convert directory name to Unix-style syntax */
1122: char * disk = strchr (wd, ':');
1123: char * dir = strchr (wd, '[');
1124: if (disk) {
1125: *disk = '\0';
1126: StrAllocCat (default_default, "/"); /* needs delimiter */
1127: StrAllocCat (default_default, wd);
1128: }
1129: if (dir) {
1130: char *p;
1131: *dir = '/'; /* Convert leading '[' */
1132: for (p = dir ; *p != ']'; ++p)
1133: if (*p == '.') *p = '/';
1134: *p = '\0'; /* Cut on final ']' */
1135: StrAllocCat (default_default, dir);
1136: }
1137: #else /* not VMS */
1138: StrAllocCat (default_default, wd);
1.59 frystyk 1139: #endif /* not VMS */
1.57 howcome 1140: }
1.59 frystyk 1141: }
1.57 howcome 1142: StrAllocCat(default_default, "/default.html");
1143: return default_default;
1.2 timbl 1144: }
1145:
1146:
1147: /* Generate the anchor for the home page
1148: ** -------------------------------------
1149: **
1150: ** As it involves file access, this should only be done once
1151: ** when the program first runs.
1.10 timbl 1152: ** This is a default algorithm -- browser don't HAVE to use this.
1153: ** But consistency betwen browsers is STRONGLY recommended!
1.2 timbl 1154: **
1.10 timbl 1155: ** Priority order is:
1156: **
1157: ** 1 WWW_HOME environment variable (logical name, etc)
1158: ** 2 ~/WWW/default.html
1159: ** 3 /usr/local/bin/default.html
1160: ** 4 http://info.cern.ch/default.html
1161: **
1.2 timbl 1162: */
1163: PUBLIC HTParentAnchor * HTHomeAnchor NOARGS
1164: {
1.12 timbl 1165: char * my_home_document = NULL;
1166: char * home = (char *)getenv(LOGICAL_DEFAULT);
1.2 timbl 1167: char * ref;
1168: HTParentAnchor * anchor;
1.1 timbl 1169:
1.12 timbl 1170: if (home) {
1171: StrAllocCopy(my_home_document, home);
1172:
1173: /* Someone telnets in, they get a special home.
1174: */
1175: } else if (HTClientHost) { /* Telnet server */
1176: FILE * fp = fopen(REMOTE_POINTER, "r");
1177: char * status;
1178: if (fp) {
1.59 frystyk 1179: my_home_document = (char*) malloc(HT_MAX_PATH);
1180: status = fgets(my_home_document, HT_MAX_PATH, fp);
1.12 timbl 1181: if (!status) {
1182: free(my_home_document);
1183: my_home_document = NULL;
1184: }
1185: fclose(fp);
1186: }
1187: if (!my_home_document) StrAllocCopy(my_home_document, REMOTE_ADDRESS);
1188: }
1189:
1190:
1191:
1.2 timbl 1192: #ifdef unix
1.12 timbl 1193:
1.10 timbl 1194: if (!my_home_document) {
1195: FILE * fp = NULL;
1196: CONST char * home = (CONST char*)getenv("HOME");
1197: if (home) {
1198: my_home_document = (char *)malloc(
1199: strlen(home)+1+ strlen(PERSONAL_DEFAULT)+1);
1200: if (my_home_document == NULL) outofmem(__FILE__, "HTLocalName");
1201: sprintf(my_home_document, "%s/%s", home, PERSONAL_DEFAULT);
1202: fp = fopen(my_home_document, "r");
1203: }
1204:
1205: if (!fp) {
1206: StrAllocCopy(my_home_document, LOCAL_DEFAULT_FILE);
1207: fp = fopen(my_home_document, "r");
1208: }
1.2 timbl 1209: if (fp) {
1210: fclose(fp);
1211: } else {
1.62 frystyk 1212: if (TRACE)
1213: fprintf(stderr,
1214: "HTBrowse: No local home document ~/%s or %s\n",
1215: PERSONAL_DEFAULT, LOCAL_DEFAULT_FILE);
1.11 timbl 1216: free(my_home_document);
1217: my_home_document = NULL;
1.2 timbl 1218: }
1219: }
1220: #endif
1.10 timbl 1221: ref = HTParse( my_home_document ? my_home_document :
1222: HTClientHost ? REMOTE_ADDRESS
1223: : LAST_RESORT,
1224: "file:",
1.2 timbl 1225: PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION);
1.10 timbl 1226: if (my_home_document) {
1.62 frystyk 1227: if (TRACE)
1228: fprintf(stderr,
1229: "HTAccess.... `%s\' used for custom home page as\n`%s\'\n",
1230: my_home_document, ref);
1.10 timbl 1231: free(my_home_document);
1.2 timbl 1232: }
1233: anchor = (HTParentAnchor*) HTAnchor_findAddress(ref);
1234: free(ref);
1235: return anchor;
1.1 timbl 1236: }
1.26 frystyk 1237:
1238:
1239: /* Bind an Anchor to the request structure
1240: ** ---------------------------------------
1241: **
1242: ** On Entry,
1243: ** anchor The child or parenet anchor to be binded
1244: ** request The request sturcture
1245: ** On Exit,
1246: ** returns YES Success
1247: ** NO Failure
1248: **
1249: ** Note: Actually the same as HTLoadAnchor() but DOES NOT do the loading
1250: ** Henrik Frystyk 17/02-94
1251: */
1252:
1253: PUBLIC BOOL HTBindAnchor ARGS2(HTAnchor*, anchor, HTRequest *, request)
1254: {
1255: if (!anchor) return NO; /* No link */
1256:
1257: request->anchor = HTAnchor_parent(anchor);
1258: request->childAnchor = ((HTAnchor*)request->anchor == anchor) ? NULL
1259: : (HTChildAnchor*) anchor;
1260:
1.29 frystyk 1261: return YES;
1.26 frystyk 1262: } /* HTBindAnchor */
1.59 frystyk 1263:
1.26 frystyk 1264:
Webmaster