Annotation of libwww/Library/src/HTHome.c, revision 2.1

2.1     ! frystyk     1: /*                                                                  HTHome.c
        !             2: **     GENERATION OF THE HOME ANCHOR
        !             3: **
        !             4: **     (c) COPYRIGHT MIT 1995.
        !             5: **     Please first read the full copyright statement in the file COPYRIGH.
        !             6: **
        !             7: ** Authors
        !             8: **     TBL     Tim Berners-Lee timbl@w3.org
        !             9: **     JFG     Jean-Francois Groff jfg@dxcern.cern.ch
        !            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
        !            14: **      6 Oct 92 Moved HTClientHost and HTlogfile into here. TBL
        !            15: **     17 Dec 92 Tn3270 added, bug fix. DD
        !            16: **      4 Feb 93 Access registration, Search escapes bad chars TBL
        !            17: **               PARAMETERS TO HTSEARCH AND HTLOADRELATIVE CHANGED
        !            18: **     28 May 93 WAIS gateway explicit if no WAIS library linked in.
        !            19: **        Dec 93 Bug change around, more reentrant, etc
        !            20: **     09 May 94 logfile renamed to HTlogfile to avoid clash with WAIS
        !            21: **      8 Jul 94 Insulate free() from _free structure element.
        !            22: **        Sep 95 Rewritten, HFN
        !            23: **        Nov 95 Spawned from HTAccess.c
        !            24: */
        !            25: 
        !            26: /* Library include files */
        !            27: #include "WWWLib.h"
        !            28: #include "HTHome.h"                                     /* Implemented here */
        !            29: 
        !            30: /* ------------------------------------------------------------------------- */
        !            31: 
        !            32: /*     Find Related Name
        !            33: **     -----------------
        !            34: **     Creates a string that can be used as a related name when 
        !            35: **     calling HTParse initially. 
        !            36: **  
        !            37: **     The code for this routine originates from the Linemode 
        !            38: **     browser and was moved here by howcome@w3.org
        !            39: **     in order for all clients to take advantage.
        !            40: **     The string returned must be freed by the caller
        !            41: */
        !            42: PUBLIC char * HTFindRelatedName (void)
        !            43: {
        !            44:     char* default_default = NULL;            /* Parse home relative to this */
        !            45:     CONST char *host = HTGetHostName(); 
        !            46:     StrAllocCopy(default_default, "file://");
        !            47:     if (host)
        !            48:        StrAllocCat(default_default, host);
        !            49:     else
        !            50:        StrAllocCat(default_default, "localhost");
        !            51:     {
        !            52:        char wd[HT_MAX_PATH+1];
        !            53: 
        !            54: #ifdef NO_GETWD
        !            55: #ifdef HAS_GETCWD            /* System V variant SIGN CHANGED TBL 921006 !! */
        !            56:        char *result = (char *) getcwd(wd, sizeof(wd)); 
        !            57: #else
        !            58:        char *result = NULL;
        !            59:        HTAlert("This platform does not support neither getwd nor getcwd\n");
        !            60: #endif
        !            61: #else
        !            62:        char *result = (char *) getwd(wd);
        !            63: #endif
        !            64:        *(wd+HT_MAX_PATH) = '\0';
        !            65:        if (result) {
        !            66: #ifdef VMS 
        !            67:             /* convert directory name to Unix-style syntax */
        !            68:            char * disk = strchr (wd, ':');
        !            69:            char * dir = strchr (wd, '[');
        !            70:            if (disk) {
        !            71:                *disk = '\0';
        !            72:                StrAllocCat (default_default, "/");  /* needs delimiter */
        !            73:                StrAllocCat (default_default, wd);
        !            74:            }
        !            75:            if (dir) {
        !            76:                char *p;
        !            77:                *dir = '/';  /* Convert leading '[' */
        !            78:                for (p = dir ; *p != ']'; ++p)
        !            79:                        if (*p == '.') *p = '/';
        !            80:                *p = '\0';  /* Cut on final ']' */
        !            81:                StrAllocCat (default_default, dir);
        !            82:            }
        !            83: #else  /* not VMS */
        !            84: #ifdef WIN32
        !            85:            char * p = wd ;     /* a colon */
        !            86:            StrAllocCat(default_default, "/");
        !            87:            while( *p != 0 ) { 
        !            88:                if (*p == '\\')                  /* change to one true slash */
        !            89:                    *p = '/' ;
        !            90:                p++;
        !            91:            }
        !            92:            StrAllocCat( default_default, wd);
        !            93: #else /* not WIN32 */
        !            94:            StrAllocCat (default_default, wd);
        !            95: #endif /* not WIN32 */
        !            96: #endif /* not VMS */
        !            97:        }
        !            98:     }
        !            99:     StrAllocCat(default_default, "/default.html");
        !           100:     return default_default;
        !           101: }
        !           102: 
        !           103: 
        !           104: /*     Generate the anchor for the home page
        !           105: **     -------------------------------------
        !           106: **
        !           107: **     As it involves file access, this should only be done once
        !           108: **     when the program first runs.
        !           109: **     This is a default algorithm -- browser don't HAVE to use this.
        !           110: **     But consistency betwen browsers is STRONGLY recommended!
        !           111: **
        !           112: **     Priority order is:
        !           113: **
        !           114: **             1       WWW_HOME environment variable (logical name, etc)
        !           115: **             2       ~/WWW/default.html
        !           116: **             3       /usr/local/bin/default.html
        !           117: **             4       http://www.w3.org/default.html
        !           118: **
        !           119: */
        !           120: PUBLIC HTParentAnchor * HTHomeAnchor (void)
        !           121: {
        !           122:     char * my_home_document = NULL;
        !           123:     char * home = (char *) getenv(LOGICAL_DEFAULT);
        !           124:     char * ref;
        !           125:     HTParentAnchor * anchor;
        !           126:     
        !           127:     /* Someone telnets in, they get a special home */
        !           128:     if (home) {
        !           129:         StrAllocCopy(my_home_document, home);
        !           130:     } else  if (HTLib_secure()) {                                  /* Telnet server */
        !           131:        FILE * fp = fopen(REMOTE_POINTER, "r");
        !           132:        char * status;
        !           133:        if (fp) {
        !           134:            my_home_document = (char*) malloc(HT_MAX_PATH);
        !           135:            status = fgets(my_home_document, HT_MAX_PATH, fp);
        !           136:            if (!status) {
        !           137:                free(my_home_document);
        !           138:                my_home_document = NULL;
        !           139:            }
        !           140:            fclose(fp);
        !           141:        }
        !           142:        if (!my_home_document) StrAllocCopy(my_home_document, REMOTE_ADDRESS);
        !           143:     }
        !           144: 
        !           145: #ifdef unix
        !           146:     if (!my_home_document) {
        !           147:        FILE * fp = NULL;
        !           148:        char * home = (char *) getenv("HOME");
        !           149:        if (home) { 
        !           150:            my_home_document = (char *)malloc(
        !           151:                strlen(home)+1+ strlen(PERSONAL_DEFAULT)+1);
        !           152:            if (my_home_document == NULL) outofmem(__FILE__, "HTLocalName");
        !           153:            sprintf(my_home_document, "%s/%s", home, PERSONAL_DEFAULT);
        !           154:            fp = fopen(my_home_document, "r");
        !           155:        }
        !           156:        
        !           157:        if (!fp) {
        !           158:            StrAllocCopy(my_home_document, LOCAL_DEFAULT_FILE);
        !           159:            fp = fopen(my_home_document, "r");
        !           160:        }
        !           161:        if (fp) {
        !           162:            fclose(fp);
        !           163:        } else {
        !           164:            if (WWWTRACE)
        !           165:                TTYPrint(TDEST,
        !           166:                        "HTBrowse: No local home document ~/%s or %s\n",
        !           167:                        PERSONAL_DEFAULT, LOCAL_DEFAULT_FILE);
        !           168:            free(my_home_document);
        !           169:            my_home_document = NULL;
        !           170:        }
        !           171:     }
        !           172: #endif
        !           173:     ref = HTParse(my_home_document ? my_home_document :
        !           174:                  HTLib_secure() ? REMOTE_ADDRESS : LAST_RESORT, "file:",
        !           175:                  PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION);
        !           176:     if (my_home_document) {
        !           177:        if (WWWTRACE)
        !           178:            TTYPrint(TDEST,
        !           179:                   "HTAccess.... `%s\' used for custom home page as\n`%s\'\n",
        !           180:                    my_home_document, ref);
        !           181:        free(my_home_document);
        !           182:     }
        !           183:     anchor = (HTParentAnchor*) HTAnchor_findAddress(ref);
        !           184:     free(ref);
        !           185:     return anchor;
        !           186: }

Webmaster