Annotation of libwww/Library/src/HTAccess.c, revision 1.92
1.61 frystyk 1: /* HTAccess.c
2: ** ACCESS MANAGER
3: **
1.75 frystyk 4: ** (c) COPYRIGHT MIT 1995.
1.61 frystyk 5: ** Please first read the full copyright statement in the file COPYRIGH.
1.1 timbl 6: **
7: ** Authors
1.79 frystyk 8: ** TBL Tim Berners-Lee timbl@w3.org
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.88 frystyk 22: ** Sep 95 Rewritten, HFN
1.1 timbl 23: */
24:
1.68 frystyk 25: #if !defined(HT_DIRECT_WAIS) && !defined(HT_DEFAULT_WAIS_GATEWAY)
26: #define HT_DEFAULT_WAIS_GATEWAY "http://www.w3.org:8001/"
1.54 frystyk 27: #endif
1.8 timbl 28:
1.67 frystyk 29: /* Library include files */
1.88 frystyk 30: #include "WWWLib.h"
31: #include "HTReqMan.h" /* @@@@@@@@@@@@@@@@@@@@@@@@ */
32:
1.70 frystyk 33: #include "HTInit.h"
1.67 frystyk 34: #include "HTAccess.h" /* Implemented here */
1.2 timbl 35:
1.59 frystyk 36: /* --------------------------------------------------------------------------*/
1.61 frystyk 37: /* Initialization and Termination of the Library */
38: /* --------------------------------------------------------------------------*/
39:
40: /* HTLibInit
41: **
42: ** This function initiates the Library and it MUST be called when
43: ** starting up an application. See also HTLibTerminate()
44: */
1.90 frystyk 45: PUBLIC BOOL HTLibInit (void)
1.61 frystyk 46: {
1.67 frystyk 47: #ifdef NO_STDIO /* Open trace file */
48: if ((TDEST = fopen(TRACE_FILE, "a")) != NULL) {
49: if (setvbuf(TDEST, NULL, _IOLBF, 0) < 0) { /* Change to line buffer */
1.70 frystyk 50: printf("WWWLibInit.. Can't initialize TRACE buffer - no TRACE\n");
1.67 frystyk 51: fclose(TDEST);
52: TDEST = NULL;
53: WWW_TraceFlag = 0;
54: }
55: } else
56: WWW_TraceFlag = 0;
57: #endif
58:
1.91 frystyk 59: if (WWWTRACE)
1.67 frystyk 60: fprintf(TDEST, "WWWLibInit.. INITIALIZING LIBRARY OF COMMON CODE\n");
1.63 frystyk 61:
1.77 frystyk 62: /* Set up User preferences, but leave initialization to the application */
1.73 frystyk 63: if (!HTConversions)
64: HTConversions = HTList_new();
1.77 frystyk 65: if (!HTEncodings)
66: HTEncodings = HTList_new();
67: if (!HTLanguages)
68: HTLanguages = HTList_new();
69: if (!HTCharsets)
70: HTCharsets = HTList_new();
71:
72: /* Set up bindings to the local file system */
73: HTBind_init();
1.73 frystyk 74:
1.70 frystyk 75: #ifndef HT_NO_INIT
76: HTAccessInit(); /* Bind access schemes and protocol modules */
77: HTFileInit(); /* Bind file extensions and media types */
1.63 frystyk 78: #endif
1.61 frystyk 79:
1.77 frystyk 80: #ifndef HT_DIRECT_WAIS
81: HTProxy_setGateway("wais", HT_DEFAULT_WAIS_GATEWAY);
82: #endif
83:
1.88 frystyk 84: /* Register a call back function for the Net Manager */
85: HTNet_register (HTLoad_terminate, HT_ALL);
86:
1.62 frystyk 87: #ifdef WWWLIB_SIG
1.61 frystyk 88: /* On Solaris (and others?) we get a BROKEN PIPE signal when connecting
1.67 frystyk 89: ** to a port where we should get `connection refused'. We ignore this
1.61 frystyk 90: ** using the following function call
91: */
92: HTSetSignal(); /* Set signals in library */
1.1 timbl 93: #endif
94:
1.67 frystyk 95: #ifdef _WINDOWS
96: /*
97: ** Initialise WinSock DLL. This must also be shut down! PMH
98: */
99: {
100: WSADATA wsadata;
101: if (WSAStartup(DESIRED_WINSOCK_VERSION, &wsadata)) {
1.91 frystyk 102: if (WWWTRACE)
1.67 frystyk 103: fprintf(TDEST, "WWWLibInit.. Can't initialize WinSoc\n");
104: WSACleanup();
105: return NO;
106: }
107: if (wsadata.wVersion < MINIMUM_WINSOCK_VERSION) {
1.91 frystyk 108: if (WWWTRACE)
1.67 frystyk 109: fprintf(TDEST, "WWWLibInit.. Bad version of WinSoc\n");
110: WSACleanup();
111: return NO;
112: }
113: }
114: #endif /* _WINDOWS */
115:
1.71 frystyk 116: #ifndef NO_TIMEGM
117: HTGetTimeZoneOffset(); /* Find offset from GMT if using mktime() */
118: #endif
1.70 frystyk 119: HTTmp_setRoot(NULL); /* Set up default tmp directory */
1.61 frystyk 120: return YES;
121: }
122:
123:
1.90 frystyk 124: /* HTLibTerminate
125: ** --------------
1.61 frystyk 126: ** This function frees memory kept by the Library and should be called
1.63 frystyk 127: ** before exit of an application (if you are on a PC platform)
1.61 frystyk 128: */
129: PUBLIC BOOL HTLibTerminate NOARGS
130: {
1.91 frystyk 131: if (WWWTRACE)
1.67 frystyk 132: fprintf(TDEST, "WWWLibTerm.. Cleaning up LIBRARY OF COMMON CODE\n");
1.63 frystyk 133: HTAtom_deleteAll();
134: HTDisposeConversions();
1.89 frystyk 135: HTDNS_deleteAll();
1.73 frystyk 136:
137: #ifndef HT_NO_INIT
1.81 frystyk 138: HTProtocol_deleteAll(); /* Remove bindings between access and protocols */
1.73 frystyk 139: HTBind_deleteAll(); /* Remove bindings between suffixes, media types */
140: #endif
141:
1.77 frystyk 142: HTProxy_deleteProxy(); /* Clean up lists of proxies and gateways */
143: HTProxy_deleteNoProxy();
144: HTProxy_deleteGateway();
145:
146: HTFreeHostName(); /* Free up some internal strings */
1.63 frystyk 147: HTFreeMailAddress();
1.70 frystyk 148: HTCache_freeRoot();
1.84 frystyk 149: HTCache_clearMem(); /* Keep the disk versions! */
1.70 frystyk 150: HTTmp_freeRoot();
1.67 frystyk 151:
152: #ifdef _WINDOWS
153: WSACleanup();
154: #endif
155:
156: #ifdef NO_STDIO /* Close trace file */
157: if (TDEST) {
158: fclose(TDEST);
159: TDEST = NULL;
160: WWW_TraceFlag = 0;
161: }
162: #endif
1.61 frystyk 163: return YES;
164: }
165:
1.59 frystyk 166: /* --------------------------------------------------------------------------*/
1.88 frystyk 167: /* Access functions */
1.59 frystyk 168: /* --------------------------------------------------------------------------*/
1.33 luotonen 169:
1.90 frystyk 170: /* Request a document
171: ** -----------------
172: ** Private version that requests a document from the request manager
173: ** Returns YES if request accepted, else NO
1.88 frystyk 174: */
1.90 frystyk 175: PRIVATE BOOL HTLoadDocument ARGS2(HTRequest *, request, BOOL, recursive)
1.88 frystyk 176: {
177: if (PROT_TRACE) {
1.90 frystyk 178: HTParentAnchor *anchor = HTRequest_anchor(request);
179: char * full_address = HTAnchor_address((HTAnchor *) anchor);
1.88 frystyk 180: fprintf (TDEST, "HTAccess.... Accessing document %s\n", full_address);
181: free(full_address);
182: }
183: return HTLoad(request, recursive, 0); /* @@@@ PRIORITY @@@@ */
1.58 frystyk 184: }
1.1 timbl 185:
186:
1.90 frystyk 187: /* Request a document from absolute name
188: ** -------------------------------------
189: ** Request a document referencd by an absolute URL.
190: ** Returns YES if request accepted, else NO
191: */
192: PUBLIC BOOL HTLoadAbsolute (CONST char * url, HTRequest* request)
193: {
194: if (url && request) {
195: HTAnchor * anchor = HTAnchor_findAddress(url);
196: HTRequest_setAnchor(request, anchor);
197: return HTLoadDocument(request, NO);
198: }
199: return NO;
200: }
201:
202:
203: /* Request a document from absolute name to stream
204: ** -----------------------------------------------
205: ** Request a document referencd by an absolute URL and sending the data
206: ** down a stream. This is _excactly_ the same as HTLoadAbsolute as
207: ** the ourputstream is specified using the function
208: ** HTRequest_setOutputStream(). 'filter' is ignored!
209: ** Returns YES if request accepted, else NO
210: */
211: PUBLIC BOOL HTLoadToStream (CONST char * url, BOOL filter, HTRequest *request)
212: {
213: return HTLoadAbsolute(url, request);
214: }
215:
216:
217: /* Request a document from relative name
218: ** -------------------------------------
219: ** Request a document referenced by a relative URL. The relative URL is
220: ** made absolute by resolving it relative to the address of the 'base'
221: ** anchor.
222: ** Returns YES if request accepted, else NO
223: */
224: PUBLIC BOOL HTLoadRelative (CONST char * relative,
225: HTParentAnchor * base,
226: HTRequest * request)
227: {
228: BOOL status = NO;
229: if (relative && base && request) {
230: char * rel = NULL;
231: char * full_url = NULL;
232: char * base_url = HTAnchor_address((HTAnchor *) base);
233: StrAllocCopy(rel, relative);
234: full_url = HTParse(HTStrip(rel), base_url,
235: PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION);
236: status = HTLoadAbsolute(full_url, request);
237: free(rel);
238: free(full_url);
239: free(base_url);
240: }
241: return status;
242: }
243:
244:
245: /* Request an anchor
246: ** -----------------
247: ** Request the document referenced by the anchor
248: ** Returns YES if request accepted, else NO
249: */
250: PUBLIC BOOL HTLoadAnchor (HTAnchor * anchor, HTRequest * request)
251: {
252: if (anchor && request) {
253: HTRequest_setAnchor(request, anchor);
254: return HTLoadDocument(request, NO);
255: }
256: return NO;
257: }
258:
259:
260: /* Request an anchor
261: ** -----------------
262: ** Same as HTLoadAnchor but any information in the Error Stack in the
263: ** request object is kept, so that any error messages in one
1.52 frystyk 264: ** This function is almost identical to HTLoadAnchor, but it doesn't
265: ** clear the error stack so that the information in there is kept.
1.90 frystyk 266: ** Returns YES if request accepted, else NO
267: */
268: PUBLIC BOOL HTLoadAnchorRecursive (HTAnchor * anchor, HTRequest * request)
269: {
270: if (anchor && request) {
271: HTRequest_setAnchor(request, anchor);
272: return HTLoadDocument(request, YES);
273: }
274: return NO;
275: }
276:
277:
278: /* Search an Anchor
279: ** ----------------
280: ** Performs a keyword search on word given by the user. Adds the keyword
281: ** to the end of the current address and attempts to open the new address.
282: ** The list of keywords must be a space-separated list and spaces will
283: ** be converted to '+' before the request is issued.
284: ** Search can also be performed by HTLoadAbsolute() etc.
285: ** Returns YES if request accepted, else NO
286: */
287: PUBLIC BOOL HTSearch (CONST char * keywords,
288: HTParentAnchor * base,
289: HTRequest * request)
290: {
291: if (keywords && base && request) {
292: char *base_url = HTAnchor_address((HTAnchor *) base);
293: if (*keywords) {
294: char *plus;
295: StrAllocCat(base_url, "?");
296: StrAllocCat(base_url, keywords);
297: plus = strchr(base_url, '?');
298: while (*plus) {
299: if (*plus == ' ') *plus = '+';
300: plus++;
301: }
1.2 timbl 302: }
1.90 frystyk 303: return HTLoadAbsolute(base_url, request);
304: }
305: return NO;
1.2 timbl 306: }
307:
308:
1.90 frystyk 309: /* Search a document from absolute name
310: ** ------------------------------------
311: ** Request a document referencd by an absolute URL appended with the
312: ** keywords given. The URL can NOT contain any fragment identifier!
313: ** The list of keywords must be a space-separated list and spaces will
314: ** be converted to '+' before the request is issued.
315: ** Returns YES if request accepted, else NO
316: */
317: PUBLIC BOOL HTSearchAbsolute (CONST char * keywords,
318: CONST char * url,
319: HTRequest * request)
320: {
321: if (url && request) {
322: HTAnchor * anchor = HTAnchor_findAddress(url);
323: return HTSearch(keywords, HTAnchor_parent(anchor), request);
324: }
325: return NO;
1.57 howcome 326: }
327:
1.70 frystyk 328: /* --------------------------------------------------------------------------*/
329: /* Document Poster */
330: /* --------------------------------------------------------------------------*/
331:
1.90 frystyk 332: /* Copy an anchor
1.70 frystyk 333: ** --------------
1.90 frystyk 334: ** Fetch the URL (possibly local file URL) and send it using either PUT
335: ** or POST to the remote destination using HTTP. The caller can decide the
336: ** exact method used and which HTTP header fields to transmit by setting
337: ** the user fields in the request structure.
1.92 ! frystyk 338: ** If posting to NNTP then we can't dispatch at this level but must pass
! 339: ** the source anchor to the news module that then takes all the refs
! 340: ** to NNTP and puts into the "newsgroups" header
1.90 frystyk 341: ** Returns YES if request accepted, else NO
1.70 frystyk 342: */
1.90 frystyk 343: PUBLIC BOOL HTCopyAnchor (HTAnchor * src_anchor, HTRequest * main_req)
1.80 frystyk 344: {
1.78 frystyk 345: HTRequest *src_req;
1.85 frystyk 346: if (!src_anchor || !main_req)
1.90 frystyk 347: return NO;
1.70 frystyk 348:
1.80 frystyk 349: /* Build the POST web if not already there */
1.85 frystyk 350: if (!main_req->source) {
1.80 frystyk 351: src_req = HTRequest_new(); /* First set up the source */
352: HTAnchor_clearHeader((HTParentAnchor *) src_anchor);
1.85 frystyk 353: src_req->reload = HT_MEM_REFRESH;
1.80 frystyk 354: src_req->source = src_req; /* Point to myself */
355: src_req->output_format = WWW_SOURCE; /* We want source (for now) */
356:
357: /* Set up the main link in the source anchor */
358: {
1.85 frystyk 359: HTLink *main_link = HTAnchor_findMainLink(src_anchor);
360: HTAnchor *main_anchor = HTAnchor_linkDest(main_link);
361: HTMethod method = HTAnchor_linkMethod(main_link);
362: if (!main_link || method==METHOD_INVALID) {
1.91 frystyk 363: if (WWWTRACE)
1.80 frystyk 364: fprintf(TDEST, "Copy Anchor. No destination found or unspecified method");
365: HTRequest_delete(src_req);
1.90 frystyk 366: return NO;
1.80 frystyk 367: }
1.85 frystyk 368: if (HTAnchor_linkResult(main_link) == HT_LINK_NONE) {
369: main_req->GenMask |= HT_DATE; /* Send date header */
370: main_req->source = src_req;
371: main_req->reload = HT_CACHE_REFRESH;
372: main_req->method = method;
373: HTRequest_addDestination(src_req, main_req);
374: main_req->input_format = WWW_SOURCE; /* for now :-( @@@ */
1.90 frystyk 375: if (HTLoadAnchor(main_anchor, main_req) == NO)
376: return NO;
1.85 frystyk 377: }
1.80 frystyk 378: }
1.78 frystyk 379:
1.80 frystyk 380: /* For all other links in the source anchor */
381: if (src_anchor->links) {
382: HTList *cur = src_anchor->links;
383: HTLink *pres;
1.85 frystyk 384: while ((pres = (HTLink *) HTList_nextObject(cur)) &&
385: HTAnchor_linkResult(pres) == HT_LINK_NONE) {
386: HTAnchor *dest = HTAnchor_linkDest(pres);
387: HTMethod method = HTAnchor_linkMethod(pres);
1.80 frystyk 388: HTRequest *dest_req;
389: if (!dest || method==METHOD_INVALID) {
1.91 frystyk 390: if (WWWTRACE)
1.80 frystyk 391: fprintf(TDEST, "Copy Anchor. Bad anchor setup %p\n",
392: dest);
1.90 frystyk 393: return NO;
1.80 frystyk 394: }
395: dest_req = HTRequest_new();
1.85 frystyk 396: dest_req->GenMask |= HT_DATE; /* Send date header */
1.80 frystyk 397: dest_req->source = src_req;
1.85 frystyk 398: dest_req->reload = HT_CACHE_REFRESH;
1.80 frystyk 399: dest_req->method = method;
400: HTRequest_addDestination(src_req, dest_req);
401: dest_req->input_format = WWW_SOURCE; /* for now :-( @@@ */
1.90 frystyk 402: if (HTLoadAnchor(dest, dest_req) == NO)
403: return NO;
1.80 frystyk 404: }
405: }
406: } else { /* Use the existing Post Web and restart it */
1.85 frystyk 407: src_req = main_req->source;
1.80 frystyk 408: if (src_req->mainDestination)
1.90 frystyk 409: if (HTLoadDocument(main_req, NO) == NO)
410: return NO;
1.80 frystyk 411: if (src_req->destinations) {
412: HTList *cur = src_anchor->links;
413: HTRequest *pres;
414: while ((pres = (HTRequest *) HTList_nextObject(cur)) != NULL) {
1.90 frystyk 415: if (HTLoadDocument(pres, NO) == NO)
416: return NO;
1.80 frystyk 417: }
418: }
1.78 frystyk 419: }
420:
1.80 frystyk 421: /* Now open the source */
422: return HTLoadAnchor(src_anchor, src_req);
1.70 frystyk 423: }
424:
425:
1.90 frystyk 426: /* Upload an Anchor
1.70 frystyk 427: ** ----------------
1.90 frystyk 428: ** Send the contents (in hyperdoc) of the source anchor using either PUT
429: ** or POST to the remote destination using HTTP. The caller can decide the
430: ** exact method used and which HTTP header fields to transmit by setting
431: ** the user fields in the request structure.
432: ** Returns YES if request accepted, else NO
433: */
434: PUBLIC BOOL HTUploadAnchor (HTAnchor * src_anchor,
435: HTParentAnchor * dest_anchor,
436: HTRequest * dest_req)
1.70 frystyk 437: {
1.90 frystyk 438: if (!src_anchor || !dest_anchor || !dest_req)
439: return NO;
1.70 frystyk 440: if (!(dest_anchor->methods & dest_req->method)) {
441: char buf[80];
442: sprintf(buf, "It might not be allowed to %s to this destination, continue?", HTMethod_name(dest_req->method));
1.86 frystyk 443: if (!HTConfirm(dest_req, buf))
1.90 frystyk 444: return NO;
1.70 frystyk 445: }
1.77 frystyk 446:
447: /* @@@ NOT FINISHED @@@ */
1.70 frystyk 448:
1.90 frystyk 449: return NO;
1.70 frystyk 450: }
451:
452: /* --------------------------------------------------------------------------*/
453: /* Anchor help routines */
454: /* --------------------------------------------------------------------------*/
1.57 howcome 455:
456: /*
457: ** Find Related Name
458: **
459: ** Creates a string that can be used as a related name when
460: ** calling HTParse initially.
461: **
462: ** The code for this routine originates from the Linemode
1.79 frystyk 463: ** browser and was moved here by howcome@w3.org
1.57 howcome 464: ** in order for all clients to take advantage.
465: **
1.59 frystyk 466: ** The string returned must be freed by the caller
1.57 howcome 467: */
468: PUBLIC char * HTFindRelatedName NOARGS
469: {
1.59 frystyk 470: char* default_default = NULL; /* Parse home relative to this */
471: CONST char *host = HTGetHostName();
1.57 howcome 472: StrAllocCopy(default_default, "file://");
1.59 frystyk 473: if (host)
474: StrAllocCat(default_default, host);
475: else
476: StrAllocCat(default_default, "localhost");
477: {
478: char wd[HT_MAX_PATH+1];
1.67 frystyk 479:
480: #ifdef NO_GETWD
481: #ifdef HAS_GETCWD /* System V variant SIGN CHANGED TBL 921006 !! */
482: char *result = (char *) getcwd(wd, sizeof(wd));
483: #else
484: char *result = NULL;
485: HTAlert("This platform does not support neither getwd nor getcwd\n");
486: #endif
487: #else
488: char *result = (char *) getwd(wd);
489: #endif
1.59 frystyk 490: *(wd+HT_MAX_PATH) = '\0';
1.57 howcome 491: if (result) {
492: #ifdef VMS
493: /* convert directory name to Unix-style syntax */
494: char * disk = strchr (wd, ':');
495: char * dir = strchr (wd, '[');
496: if (disk) {
497: *disk = '\0';
498: StrAllocCat (default_default, "/"); /* needs delimiter */
499: StrAllocCat (default_default, wd);
500: }
501: if (dir) {
502: char *p;
503: *dir = '/'; /* Convert leading '[' */
504: for (p = dir ; *p != ']'; ++p)
505: if (*p == '.') *p = '/';
506: *p = '\0'; /* Cut on final ']' */
507: StrAllocCat (default_default, dir);
508: }
1.74 frystyk 509: #else /* not VMS */
1.70 frystyk 510: #ifdef WIN32
511: char * p = wd ; /* a colon */
512: StrAllocCat(default_default, "/");
513: while( *p != 0 ) {
514: if (*p == '\\') /* change to one true slash */
515: *p = '/' ;
516: p++;
517: }
1.74 frystyk 518: StrAllocCat( default_default, wd);
519: #else /* not WIN32 */
1.57 howcome 520: StrAllocCat (default_default, wd);
1.70 frystyk 521: #endif /* not WIN32 */
1.67 frystyk 522: #endif /* not VMS */
1.57 howcome 523: }
1.67 frystyk 524: }
1.57 howcome 525: StrAllocCat(default_default, "/default.html");
526: return default_default;
1.2 timbl 527: }
528:
529:
530: /* Generate the anchor for the home page
531: ** -------------------------------------
532: **
533: ** As it involves file access, this should only be done once
534: ** when the program first runs.
1.10 timbl 535: ** This is a default algorithm -- browser don't HAVE to use this.
536: ** But consistency betwen browsers is STRONGLY recommended!
1.2 timbl 537: **
1.10 timbl 538: ** Priority order is:
539: **
540: ** 1 WWW_HOME environment variable (logical name, etc)
541: ** 2 ~/WWW/default.html
542: ** 3 /usr/local/bin/default.html
1.70 frystyk 543: ** 4 http://www.w3.org/default.html
1.10 timbl 544: **
1.2 timbl 545: */
546: PUBLIC HTParentAnchor * HTHomeAnchor NOARGS
547: {
1.12 timbl 548: char * my_home_document = NULL;
1.70 frystyk 549: char * home = (char *) getenv(LOGICAL_DEFAULT);
1.2 timbl 550: char * ref;
551: HTParentAnchor * anchor;
1.1 timbl 552:
1.70 frystyk 553: /* Someone telnets in, they get a special home */
1.12 timbl 554: if (home) {
555: StrAllocCopy(my_home_document, home);
1.70 frystyk 556: } else if (HTClientHost) { /* Telnet server */
1.12 timbl 557: FILE * fp = fopen(REMOTE_POINTER, "r");
558: char * status;
559: if (fp) {
1.59 frystyk 560: my_home_document = (char*) malloc(HT_MAX_PATH);
561: status = fgets(my_home_document, HT_MAX_PATH, fp);
1.12 timbl 562: if (!status) {
563: free(my_home_document);
564: my_home_document = NULL;
565: }
566: fclose(fp);
567: }
568: if (!my_home_document) StrAllocCopy(my_home_document, REMOTE_ADDRESS);
569: }
570:
1.67 frystyk 571: #ifdef unix
1.10 timbl 572: if (!my_home_document) {
573: FILE * fp = NULL;
1.70 frystyk 574: char * home = (char *) getenv("HOME");
1.10 timbl 575: if (home) {
576: my_home_document = (char *)malloc(
577: strlen(home)+1+ strlen(PERSONAL_DEFAULT)+1);
578: if (my_home_document == NULL) outofmem(__FILE__, "HTLocalName");
579: sprintf(my_home_document, "%s/%s", home, PERSONAL_DEFAULT);
580: fp = fopen(my_home_document, "r");
581: }
582:
583: if (!fp) {
584: StrAllocCopy(my_home_document, LOCAL_DEFAULT_FILE);
585: fp = fopen(my_home_document, "r");
586: }
1.2 timbl 587: if (fp) {
588: fclose(fp);
589: } else {
1.91 frystyk 590: if (WWWTRACE)
1.67 frystyk 591: fprintf(TDEST,
1.62 frystyk 592: "HTBrowse: No local home document ~/%s or %s\n",
593: PERSONAL_DEFAULT, LOCAL_DEFAULT_FILE);
1.11 timbl 594: free(my_home_document);
595: my_home_document = NULL;
1.2 timbl 596: }
597: }
1.67 frystyk 598: #endif
1.70 frystyk 599: ref = HTParse(my_home_document ? my_home_document :
600: HTClientHost ? REMOTE_ADDRESS : LAST_RESORT, "file:",
601: PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION);
1.10 timbl 602: if (my_home_document) {
1.91 frystyk 603: if (WWWTRACE)
1.67 frystyk 604: fprintf(TDEST,
1.62 frystyk 605: "HTAccess.... `%s\' used for custom home page as\n`%s\'\n",
606: my_home_document, ref);
1.10 timbl 607: free(my_home_document);
1.2 timbl 608: }
609: anchor = (HTParentAnchor*) HTAnchor_findAddress(ref);
610: free(ref);
611: return anchor;
1.1 timbl 612: }
1.26 frystyk 613:
Webmaster