Annotation of libwww/Library/src/HTAccess.c, revision 1.90
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.61 frystyk 59: if (TRACE)
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)) {
102: if (TRACE)
103: fprintf(TDEST, "WWWLibInit.. Can't initialize WinSoc\n");
104: WSACleanup();
105: return NO;
106: }
107: if (wsadata.wVersion < MINIMUM_WINSOCK_VERSION) {
108: if (TRACE)
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: {
131: if (TRACE)
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.
! 338: ** Returns YES if request accepted, else NO
1.70 frystyk 339: */
1.90 ! frystyk 340: PUBLIC BOOL HTCopyAnchor (HTAnchor * src_anchor, HTRequest * main_req)
1.80 frystyk 341: {
1.78 frystyk 342: HTRequest *src_req;
1.85 frystyk 343: if (!src_anchor || !main_req)
1.90 ! frystyk 344: return NO;
1.70 frystyk 345:
1.80 frystyk 346: /* Build the POST web if not already there */
1.85 frystyk 347: if (!main_req->source) {
1.80 frystyk 348: src_req = HTRequest_new(); /* First set up the source */
349: HTAnchor_clearHeader((HTParentAnchor *) src_anchor);
1.85 frystyk 350: src_req->reload = HT_MEM_REFRESH;
1.80 frystyk 351: src_req->source = src_req; /* Point to myself */
352: src_req->output_format = WWW_SOURCE; /* We want source (for now) */
353:
354: /* Set up the main link in the source anchor */
355: {
1.85 frystyk 356: HTLink *main_link = HTAnchor_findMainLink(src_anchor);
357: HTAnchor *main_anchor = HTAnchor_linkDest(main_link);
358: HTMethod method = HTAnchor_linkMethod(main_link);
359: if (!main_link || method==METHOD_INVALID) {
1.80 frystyk 360: if (TRACE)
361: fprintf(TDEST, "Copy Anchor. No destination found or unspecified method");
362: HTRequest_delete(src_req);
1.90 ! frystyk 363: return NO;
1.80 frystyk 364: }
1.85 frystyk 365: if (HTAnchor_linkResult(main_link) == HT_LINK_NONE) {
366: main_req->GenMask |= HT_DATE; /* Send date header */
367: main_req->source = src_req;
368: main_req->reload = HT_CACHE_REFRESH;
369: main_req->method = method;
370: HTRequest_addDestination(src_req, main_req);
371: main_req->input_format = WWW_SOURCE; /* for now :-( @@@ */
1.90 ! frystyk 372: if (HTLoadAnchor(main_anchor, main_req) == NO)
! 373: return NO;
1.85 frystyk 374: }
1.80 frystyk 375: }
1.78 frystyk 376:
1.80 frystyk 377: /* For all other links in the source anchor */
378: if (src_anchor->links) {
379: HTList *cur = src_anchor->links;
380: HTLink *pres;
1.85 frystyk 381: while ((pres = (HTLink *) HTList_nextObject(cur)) &&
382: HTAnchor_linkResult(pres) == HT_LINK_NONE) {
383: HTAnchor *dest = HTAnchor_linkDest(pres);
384: HTMethod method = HTAnchor_linkMethod(pres);
1.80 frystyk 385: HTRequest *dest_req;
386: if (!dest || method==METHOD_INVALID) {
387: if (TRACE)
388: fprintf(TDEST, "Copy Anchor. Bad anchor setup %p\n",
389: dest);
1.90 ! frystyk 390: return NO;
1.80 frystyk 391: }
392: dest_req = HTRequest_new();
1.85 frystyk 393: dest_req->GenMask |= HT_DATE; /* Send date header */
1.80 frystyk 394: dest_req->source = src_req;
1.85 frystyk 395: dest_req->reload = HT_CACHE_REFRESH;
1.80 frystyk 396: dest_req->method = method;
397: HTRequest_addDestination(src_req, dest_req);
398: dest_req->input_format = WWW_SOURCE; /* for now :-( @@@ */
1.90 ! frystyk 399: if (HTLoadAnchor(dest, dest_req) == NO)
! 400: return NO;
1.80 frystyk 401: }
402: }
403: } else { /* Use the existing Post Web and restart it */
1.85 frystyk 404: src_req = main_req->source;
1.80 frystyk 405: if (src_req->mainDestination)
1.90 ! frystyk 406: if (HTLoadDocument(main_req, NO) == NO)
! 407: return NO;
1.80 frystyk 408: if (src_req->destinations) {
409: HTList *cur = src_anchor->links;
410: HTRequest *pres;
411: while ((pres = (HTRequest *) HTList_nextObject(cur)) != NULL) {
1.90 ! frystyk 412: if (HTLoadDocument(pres, NO) == NO)
! 413: return NO;
1.80 frystyk 414: }
415: }
1.78 frystyk 416: }
417:
1.80 frystyk 418: /* Now open the source */
419: return HTLoadAnchor(src_anchor, src_req);
1.70 frystyk 420: }
421:
422:
1.90 ! frystyk 423: /* Upload an Anchor
1.70 frystyk 424: ** ----------------
1.90 ! frystyk 425: ** Send the contents (in hyperdoc) of the source anchor using either PUT
! 426: ** or POST to the remote destination using HTTP. The caller can decide the
! 427: ** exact method used and which HTTP header fields to transmit by setting
! 428: ** the user fields in the request structure.
! 429: ** Returns YES if request accepted, else NO
! 430: */
! 431: PUBLIC BOOL HTUploadAnchor (HTAnchor * src_anchor,
! 432: HTParentAnchor * dest_anchor,
! 433: HTRequest * dest_req)
1.70 frystyk 434: {
1.90 ! frystyk 435: if (!src_anchor || !dest_anchor || !dest_req)
! 436: return NO;
1.70 frystyk 437: if (!(dest_anchor->methods & dest_req->method)) {
438: char buf[80];
439: sprintf(buf, "It might not be allowed to %s to this destination, continue?", HTMethod_name(dest_req->method));
1.86 frystyk 440: if (!HTConfirm(dest_req, buf))
1.90 ! frystyk 441: return NO;
1.70 frystyk 442: }
1.77 frystyk 443:
444: /* @@@ NOT FINISHED @@@ */
1.70 frystyk 445:
1.90 ! frystyk 446: return NO;
1.70 frystyk 447: }
448:
449: /* --------------------------------------------------------------------------*/
450: /* Anchor help routines */
451: /* --------------------------------------------------------------------------*/
1.57 howcome 452:
453: /*
454: ** Find Related Name
455: **
456: ** Creates a string that can be used as a related name when
457: ** calling HTParse initially.
458: **
459: ** The code for this routine originates from the Linemode
1.79 frystyk 460: ** browser and was moved here by howcome@w3.org
1.57 howcome 461: ** in order for all clients to take advantage.
462: **
1.59 frystyk 463: ** The string returned must be freed by the caller
1.57 howcome 464: */
465: PUBLIC char * HTFindRelatedName NOARGS
466: {
1.59 frystyk 467: char* default_default = NULL; /* Parse home relative to this */
468: CONST char *host = HTGetHostName();
1.57 howcome 469: StrAllocCopy(default_default, "file://");
1.59 frystyk 470: if (host)
471: StrAllocCat(default_default, host);
472: else
473: StrAllocCat(default_default, "localhost");
474: {
475: char wd[HT_MAX_PATH+1];
1.67 frystyk 476:
477: #ifdef NO_GETWD
478: #ifdef HAS_GETCWD /* System V variant SIGN CHANGED TBL 921006 !! */
479: char *result = (char *) getcwd(wd, sizeof(wd));
480: #else
481: char *result = NULL;
482: HTAlert("This platform does not support neither getwd nor getcwd\n");
483: #endif
484: #else
485: char *result = (char *) getwd(wd);
486: #endif
1.59 frystyk 487: *(wd+HT_MAX_PATH) = '\0';
1.57 howcome 488: if (result) {
489: #ifdef VMS
490: /* convert directory name to Unix-style syntax */
491: char * disk = strchr (wd, ':');
492: char * dir = strchr (wd, '[');
493: if (disk) {
494: *disk = '\0';
495: StrAllocCat (default_default, "/"); /* needs delimiter */
496: StrAllocCat (default_default, wd);
497: }
498: if (dir) {
499: char *p;
500: *dir = '/'; /* Convert leading '[' */
501: for (p = dir ; *p != ']'; ++p)
502: if (*p == '.') *p = '/';
503: *p = '\0'; /* Cut on final ']' */
504: StrAllocCat (default_default, dir);
505: }
1.74 frystyk 506: #else /* not VMS */
1.70 frystyk 507: #ifdef WIN32
508: char * p = wd ; /* a colon */
509: StrAllocCat(default_default, "/");
510: while( *p != 0 ) {
511: if (*p == '\\') /* change to one true slash */
512: *p = '/' ;
513: p++;
514: }
1.74 frystyk 515: StrAllocCat( default_default, wd);
516: #else /* not WIN32 */
1.57 howcome 517: StrAllocCat (default_default, wd);
1.70 frystyk 518: #endif /* not WIN32 */
1.67 frystyk 519: #endif /* not VMS */
1.57 howcome 520: }
1.67 frystyk 521: }
1.57 howcome 522: StrAllocCat(default_default, "/default.html");
523: return default_default;
1.2 timbl 524: }
525:
526:
527: /* Generate the anchor for the home page
528: ** -------------------------------------
529: **
530: ** As it involves file access, this should only be done once
531: ** when the program first runs.
1.10 timbl 532: ** This is a default algorithm -- browser don't HAVE to use this.
533: ** But consistency betwen browsers is STRONGLY recommended!
1.2 timbl 534: **
1.10 timbl 535: ** Priority order is:
536: **
537: ** 1 WWW_HOME environment variable (logical name, etc)
538: ** 2 ~/WWW/default.html
539: ** 3 /usr/local/bin/default.html
1.70 frystyk 540: ** 4 http://www.w3.org/default.html
1.10 timbl 541: **
1.2 timbl 542: */
543: PUBLIC HTParentAnchor * HTHomeAnchor NOARGS
544: {
1.12 timbl 545: char * my_home_document = NULL;
1.70 frystyk 546: char * home = (char *) getenv(LOGICAL_DEFAULT);
1.2 timbl 547: char * ref;
548: HTParentAnchor * anchor;
1.1 timbl 549:
1.70 frystyk 550: /* Someone telnets in, they get a special home */
1.12 timbl 551: if (home) {
552: StrAllocCopy(my_home_document, home);
1.70 frystyk 553: } else if (HTClientHost) { /* Telnet server */
1.12 timbl 554: FILE * fp = fopen(REMOTE_POINTER, "r");
555: char * status;
556: if (fp) {
1.59 frystyk 557: my_home_document = (char*) malloc(HT_MAX_PATH);
558: status = fgets(my_home_document, HT_MAX_PATH, fp);
1.12 timbl 559: if (!status) {
560: free(my_home_document);
561: my_home_document = NULL;
562: }
563: fclose(fp);
564: }
565: if (!my_home_document) StrAllocCopy(my_home_document, REMOTE_ADDRESS);
566: }
567:
1.67 frystyk 568: #ifdef unix
1.10 timbl 569: if (!my_home_document) {
570: FILE * fp = NULL;
1.70 frystyk 571: char * home = (char *) getenv("HOME");
1.10 timbl 572: if (home) {
573: my_home_document = (char *)malloc(
574: strlen(home)+1+ strlen(PERSONAL_DEFAULT)+1);
575: if (my_home_document == NULL) outofmem(__FILE__, "HTLocalName");
576: sprintf(my_home_document, "%s/%s", home, PERSONAL_DEFAULT);
577: fp = fopen(my_home_document, "r");
578: }
579:
580: if (!fp) {
581: StrAllocCopy(my_home_document, LOCAL_DEFAULT_FILE);
582: fp = fopen(my_home_document, "r");
583: }
1.2 timbl 584: if (fp) {
585: fclose(fp);
586: } else {
1.62 frystyk 587: if (TRACE)
1.67 frystyk 588: fprintf(TDEST,
1.62 frystyk 589: "HTBrowse: No local home document ~/%s or %s\n",
590: PERSONAL_DEFAULT, LOCAL_DEFAULT_FILE);
1.11 timbl 591: free(my_home_document);
592: my_home_document = NULL;
1.2 timbl 593: }
594: }
1.67 frystyk 595: #endif
1.70 frystyk 596: ref = HTParse(my_home_document ? my_home_document :
597: HTClientHost ? REMOTE_ADDRESS : LAST_RESORT, "file:",
598: PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION);
1.10 timbl 599: if (my_home_document) {
1.62 frystyk 600: if (TRACE)
1.67 frystyk 601: fprintf(TDEST,
1.62 frystyk 602: "HTAccess.... `%s\' used for custom home page as\n`%s\'\n",
603: my_home_document, ref);
1.10 timbl 604: free(my_home_document);
1.2 timbl 605: }
606: anchor = (HTParentAnchor*) HTAnchor_findAddress(ref);
607: free(ref);
608: return anchor;
1.1 timbl 609: }
1.26 frystyk 610:
Webmaster