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

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.3     ! frystyk     6: **     @(#) $Id: HTLib.c,v 2.2 1996/07/02 22:54:37 frystyk 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: 
                     41: PRIVATE HTUserProfile * UserProfile = NULL;         /* Default user profile */
                     42: 
                     43: /* --------------------------------------------------------------------------*/
                     44: 
                     45: /*     Information about the Application
                     46: **     ---------------------------------
                     47: */
                     48: PUBLIC const char * HTLib_appName (void)
                     49: {
                     50:     return HTAppName ? HTAppName : "UNKNOWN";
                     51: }
                     52: 
                     53: PUBLIC const char * HTLib_appVersion (void)
                     54: {
                     55:     return HTAppVersion ? HTAppVersion : "0.0";
                     56: }
                     57: 
                     58: /*     Information about libwww
                     59: **     ------------------------
                     60: */
                     61: PUBLIC const char * HTLib_name (void)
                     62: {
                     63:     return HTLibName ? HTLibName : "UNKNOWN";
                     64: }
                     65: 
                     66: PUBLIC const char * HTLib_version (void)
                     67: {
                     68:     return HTLibVersion ? HTLibVersion : "0.0";
                     69: }
                     70: 
                     71: /*     Default User Profile
                     72: **     --------------------
                     73: */
                     74: PUBLIC HTUserProfile * HTLib_userProfile (void)
                     75: {
                     76:     return UserProfile;
                     77: }
                     78: 
                     79: PUBLIC BOOL HTLib_setUserProfile (HTUserProfile * up)
                     80: {
                     81:     if (up) {
                     82:        UserProfile = up;
                     83:        return YES;
                     84:     }
                     85:     return NO;
                     86: }
                     87: 
                     88: /*     Access Local File System
                     89: **     ------------------------
                     90: **     In this mode we do not tough the local file system at all
                     91: */
                     92: PUBLIC BOOL HTLib_secure (void)
                     93: {
                     94:     return HTSecure;
                     95: }
                     96: 
                     97: PUBLIC void HTLib_setSecure (BOOL mode)
                     98: {
                     99:     HTSecure = mode;
                    100: }
                    101: 
                    102: /*                                                                  HTLibInit
                    103: **
                    104: **     This function initiates the Library and it MUST be called when
                    105: **     starting up an application. See also HTLibTerminate()
                    106: */
                    107: PUBLIC BOOL HTLibInit (const char * AppName, const char * AppVersion)
                    108: {
                    109:     if (WWWTRACE)
                    110:        HTTrace("WWWLibInit.. INITIALIZING LIBRARY OF COMMON CODE\n");
                    111: 
                    112:     /* Set the application name and version */
                    113:     if (AppName) {
                    114:        char *ptr;
                    115:        StrAllocCopy(HTAppName, AppName);
                    116:        ptr = HTAppName;
                    117:        while (*ptr) {
                    118:            if (WHITE(*ptr)) *ptr = '_';
                    119:            ptr++;
                    120:        }
                    121:     }
                    122:     if (AppVersion) {
                    123:        char *ptr;
                    124:        StrAllocCopy(HTAppVersion, AppVersion);
                    125:        ptr = HTAppVersion;
                    126:        while (*ptr) {
                    127:            if (WHITE(*ptr)) *ptr = '_';
                    128:            ptr++;
                    129:        }
                    130:     }
                    131: 
2.2       frystyk   132:     /* Create a default user profile and initialize it */
2.1       frystyk   133:     UserProfile = HTUserProfile_new(HT_DEFAULT_USER, NULL);
2.2       frystyk   134:     HTUserProfile_localize(UserProfile);
                    135: 
2.1       frystyk   136:     /* Initialize bindings */
                    137:     HTBind_init();
                    138: 
                    139: #ifdef WWWLIB_SIG
                    140:     /* On Solaris (and others?) we get a BROKEN PIPE signal when connecting
                    141:     ** to a port where we should get `connection refused'. We ignore this 
                    142:     ** using the following function call
                    143:     */
                    144:     HTSetSignal();                                /* Set signals in library */
                    145: #endif
                    146: 
                    147: 
                    148: #ifdef _WINSOCKAPI_
                    149:     /*
                    150:     ** Initialise WinSock DLL. This must also be shut down! PMH
                    151:     */
                    152:     {
                    153:         WSADATA            wsadata;
                    154:        if (WSAStartup(DESIRED_WINSOCK_VERSION, &wsadata)) {
                    155:            if (WWWTRACE)
                    156:                HTTrace("WWWLibInit.. Can't initialize WinSoc\n");
                    157:             WSACleanup();
                    158:             return NO;
                    159:         }
                    160:         if (wsadata.wVersion < MINIMUM_WINSOCK_VERSION) {
                    161:             if (WWWTRACE)
                    162:                HTTrace("WWWLibInit.. Bad version of WinSoc\n");
                    163:             WSACleanup();
                    164:             return NO;
                    165:         }
                    166:     }
                    167: #endif /* _WINSOCKAPI_ */
                    168: 
                    169:     return YES;
                    170: }
                    171: 
                    172: 
                    173: /*     HTLibTerminate
                    174: **     --------------
                    175: **     This function HT_FREEs memory kept by the Library and should be called
                    176: **     before exit of an application (if you are on a PC platform)
                    177: */
                    178: PUBLIC BOOL HTLibTerminate (void)
                    179: {
                    180:     if (WWWTRACE) HTTrace("WWWLibTerm.. Cleaning up LIBRARY OF COMMON CODE\n");
                    181: 
                    182:     HT_FREE(HTAppName);                /* Freed thanks to Wade Ogden <wade@ebt.com> */
                    183:     HT_FREE(HTAppVersion);
                    184: 
                    185:     HTAtom_deleteAll();                                         /* Remove the atoms */
                    186:     HTDNS_deleteAll();                         /* Remove the DNS host cache */
                    187:     HTAnchor_deleteAll(NULL);          /* Delete anchors and drop hyperdocs */
                    188: 
                    189:     HTProtocol_deleteAll();  /* Remove bindings between access and protocols */
                    190:     HTBind_deleteAll();            /* Remove bindings between suffixes, media types */
                    191: 
                    192:     HTUserProfile_delete(UserProfile);     /* Free our default User profile */
2.3     ! frystyk   193: 
        !           194:     HTUTree_deleteAll();                            /* Delete all URL Trees */
2.1       frystyk   195: 
                    196: #ifdef _WINSOCKAPI_
                    197:     WSACleanup();
                    198: #endif
                    199: 
                    200:     return YES;
                    201: }
                    202: 

Webmaster