Annotation of libwww/Library/src/HTAccess.c, revision 1.96

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

Webmaster