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

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.5     ! eric        6: **     @(#) $Id: HTLib.c,v 2.4 1996/07/16 02:27:00 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: 
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: 
                    157: 
                    158: #ifdef _WINSOCKAPI_
                    159:     /*
                    160:     ** Initialise WinSock DLL. This must also be shut down! PMH
                    161:     */
                    162:     {
                    163:         WSADATA            wsadata;
                    164:        if (WSAStartup(DESIRED_WINSOCK_VERSION, &wsadata)) {
                    165:            if (WWWTRACE)
                    166:                HTTrace("WWWLibInit.. Can't initialize WinSoc\n");
                    167:             WSACleanup();
                    168:             return NO;
                    169:         }
                    170:         if (wsadata.wVersion < MINIMUM_WINSOCK_VERSION) {
                    171:             if (WWWTRACE)
                    172:                HTTrace("WWWLibInit.. Bad version of WinSoc\n");
                    173:             WSACleanup();
                    174:             return NO;
                    175:         }
                    176:     }
                    177: #endif /* _WINSOCKAPI_ */
2.4       frystyk   178:     initialized = YES;
2.1       frystyk   179:     return YES;
                    180: }
                    181: 
                    182: 
                    183: /*     HTLibTerminate
                    184: **     --------------
                    185: **     This function HT_FREEs memory kept by the Library and should be called
                    186: **     before exit of an application (if you are on a PC platform)
                    187: */
                    188: PUBLIC BOOL HTLibTerminate (void)
                    189: {
                    190:     if (WWWTRACE) HTTrace("WWWLibTerm.. Cleaning up LIBRARY OF COMMON CODE\n");
2.5     ! eric      191: 
        !           192:     HTNet_killAll();
2.1       frystyk   193: 
                    194:     HT_FREE(HTAppName);                /* Freed thanks to Wade Ogden <wade@ebt.com> */
                    195:     HT_FREE(HTAppVersion);
                    196: 
                    197:     HTAtom_deleteAll();                                         /* Remove the atoms */
                    198:     HTDNS_deleteAll();                         /* Remove the DNS host cache */
                    199:     HTAnchor_deleteAll(NULL);          /* Delete anchors and drop hyperdocs */
                    200: 
                    201:     HTProtocol_deleteAll();  /* Remove bindings between access and protocols */
                    202:     HTBind_deleteAll();            /* Remove bindings between suffixes, media types */
                    203: 
                    204:     HTUserProfile_delete(UserProfile);     /* Free our default User profile */
2.3       frystyk   205: 
                    206:     HTUTree_deleteAll();                            /* Delete all URL Trees */
2.1       frystyk   207: 
                    208: #ifdef _WINSOCKAPI_
                    209:     WSACleanup();
                    210: #endif
2.4       frystyk   211:     initialized = NO;
2.1       frystyk   212:     return YES;
                    213: }
                    214: 

Webmaster