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

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

Webmaster