Annotation of libwww/Library/src/HTLib.c, revision 2.8

2.1       frystyk     1: /*
                      2: **     GENEREAL LIBRARY INFORMATION
                      3: **
                      4: **     (c) COPYRIGHT MIT 1995.
                      5: **     Please first read the full copyright statement in the file COPYRIGH.
2.8     ! frystyk     6: **     @(#) $Id: HTLib.c,v 2.7 1996/09/16 21:33:47 eric Exp $
2.1       frystyk     7: **
                      8: ** Authors
                      9: **     HFN     Henrik Frystyk Nielsen, frystyk@w3.org
                     10: */
                     11: 
                     12: #if !defined(HT_DIRECT_WAIS) && !defined(HT_DEFAULT_WAIS_GATEWAY)
                     13: #define HT_DEFAULT_WAIS_GATEWAY "http://www.w3.org:8001/"
                     14: #endif
                     15: 
                     16: /* Library include files */
                     17: #include "WWWUtil.h"
                     18: #include "HTBind.h"
                     19: #include "HTAnchor.h"
                     20: #include "HTProt.h"
                     21: #include "HTDNS.h"
2.3       frystyk    22: #include "HTUTree.h"
2.1       frystyk    23: #include "HTLib.h"                                      /* Implemented here */
                     24: 
                     25: #ifndef W3C_VERSION
                     26: #define W3C_VERSION    "unknown"
                     27: #endif
                     28: 
                     29: #ifndef HT_DEFAULT_USER
                     30: #define HT_DEFAULT_USER                "LIBWWW_GENERIC_USER"
                     31: #endif
                     32: 
                     33: PRIVATE char * HTAppName = NULL;         /* Application name: please supply */
                     34: PRIVATE char * HTAppVersion = NULL;    /* Application version: please supply */
                     35: 
                     36: PRIVATE char * HTLibName = "libwww";
                     37: PRIVATE char * HTLibVersion = W3C_VERSION;
                     38: 
                     39: PRIVATE BOOL   HTSecure = NO;           /* Can we access local file system? */
                     40: 
2.4       frystyk    41: PRIVATE BOOL   initialized = NO;
                     42: 
2.1       frystyk    43: PRIVATE HTUserProfile * UserProfile = NULL;         /* Default user profile */
                     44: 
                     45: /* --------------------------------------------------------------------------*/
                     46: 
                     47: /*     Information about the Application
                     48: **     ---------------------------------
                     49: */
                     50: PUBLIC const char * HTLib_appName (void)
                     51: {
                     52:     return HTAppName ? HTAppName : "UNKNOWN";
                     53: }
                     54: 
                     55: PUBLIC const char * HTLib_appVersion (void)
                     56: {
                     57:     return HTAppVersion ? HTAppVersion : "0.0";
                     58: }
                     59: 
                     60: /*     Information about libwww
                     61: **     ------------------------
                     62: */
                     63: PUBLIC const char * HTLib_name (void)
                     64: {
                     65:     return HTLibName ? HTLibName : "UNKNOWN";
                     66: }
                     67: 
                     68: PUBLIC const char * HTLib_version (void)
                     69: {
                     70:     return HTLibVersion ? HTLibVersion : "0.0";
                     71: }
                     72: 
                     73: /*     Default User Profile
                     74: **     --------------------
                     75: */
                     76: PUBLIC HTUserProfile * HTLib_userProfile (void)
                     77: {
                     78:     return UserProfile;
                     79: }
                     80: 
                     81: PUBLIC BOOL HTLib_setUserProfile (HTUserProfile * up)
                     82: {
                     83:     if (up) {
                     84:        UserProfile = up;
                     85:        return YES;
                     86:     }
                     87:     return NO;
                     88: }
                     89: 
                     90: /*     Access Local File System
                     91: **     ------------------------
                     92: **     In this mode we do not tough the local file system at all
                     93: */
                     94: PUBLIC BOOL HTLib_secure (void)
                     95: {
                     96:     return HTSecure;
                     97: }
                     98: 
                     99: PUBLIC void HTLib_setSecure (BOOL mode)
                    100: {
                    101:     HTSecure = mode;
                    102: }
                    103: 
2.4       frystyk   104: /*     Have application initalized
                    105: **     ---------------------------
                    106: */
                    107: PUBLIC BOOL HTLib_isInitialized (void)
                    108: {
                    109:     return initialized;
                    110: }
                    111: 
2.1       frystyk   112: /*                                                                  HTLibInit
                    113: **
                    114: **     This function initiates the Library and it MUST be called when
                    115: **     starting up an application. See also HTLibTerminate()
                    116: */
                    117: PUBLIC BOOL HTLibInit (const char * AppName, const char * AppVersion)
                    118: {
                    119:     if (WWWTRACE)
                    120:        HTTrace("WWWLibInit.. INITIALIZING LIBRARY OF COMMON CODE\n");
                    121: 
                    122:     /* Set the application name and version */
                    123:     if (AppName) {
                    124:        char *ptr;
                    125:        StrAllocCopy(HTAppName, AppName);
                    126:        ptr = HTAppName;
                    127:        while (*ptr) {
                    128:            if (WHITE(*ptr)) *ptr = '_';
                    129:            ptr++;
                    130:        }
                    131:     }
                    132:     if (AppVersion) {
                    133:        char *ptr;
                    134:        StrAllocCopy(HTAppVersion, AppVersion);
                    135:        ptr = HTAppVersion;
                    136:        while (*ptr) {
                    137:            if (WHITE(*ptr)) *ptr = '_';
                    138:            ptr++;
                    139:        }
                    140:     }
                    141: 
2.2       frystyk   142:     /* Create a default user profile and initialize it */
2.1       frystyk   143:     UserProfile = HTUserProfile_new(HT_DEFAULT_USER, NULL);
2.2       frystyk   144:     HTUserProfile_localize(UserProfile);
                    145: 
2.1       frystyk   146:     /* Initialize bindings */
                    147:     HTBind_init();
                    148: 
                    149: #ifdef WWWLIB_SIG
                    150:     /* On Solaris (and others?) we get a BROKEN PIPE signal when connecting
                    151:     ** to a port where we should get `connection refused'. We ignore this 
                    152:     ** using the following function call
                    153:     */
                    154:     HTSetSignal();                                /* Set signals in library */
                    155: #endif
                    156: 
2.4       frystyk   157:     initialized = YES;
2.1       frystyk   158:     return YES;
                    159: }
                    160: 
                    161: 
                    162: /*     HTLibTerminate
                    163: **     --------------
                    164: **     This function HT_FREEs memory kept by the Library and should be called
                    165: **     before exit of an application (if you are on a PC platform)
                    166: */
                    167: PUBLIC BOOL HTLibTerminate (void)
                    168: {
                    169:     if (WWWTRACE) HTTrace("WWWLibTerm.. Cleaning up LIBRARY OF COMMON CODE\n");
2.5       eric      170: 
                    171:     HTNet_killAll();
2.8     ! frystyk   172:     HTChannel_deleteAll();                     /* Delete remaining channels */
2.1       frystyk   173: 
                    174:     HT_FREE(HTAppName);                /* Freed thanks to Wade Ogden <wade@ebt.com> */
                    175:     HT_FREE(HTAppVersion);
                    176: 
                    177:     HTAtom_deleteAll();                                         /* Remove the atoms */
                    178:     HTDNS_deleteAll();                         /* Remove the DNS host cache */
                    179:     HTAnchor_deleteAll(NULL);          /* Delete anchors and drop hyperdocs */
                    180: 
                    181:     HTProtocol_deleteAll();  /* Remove bindings between access and protocols */
                    182:     HTBind_deleteAll();            /* Remove bindings between suffixes, media types */
                    183: 
                    184:     HTUserProfile_delete(UserProfile);     /* Free our default User profile */
2.3       frystyk   185: 
                    186:     HTUTree_deleteAll();                            /* Delete all URL Trees */
2.1       frystyk   187: 
2.4       frystyk   188:     initialized = NO;
2.1       frystyk   189:     return YES;
                    190: }
                    191: 

Webmaster