Annotation of libwww/Library/src/HTLib.c, revision 2.11
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.11 ! frystyk 6: ** @(#) $Id: HTLib.c,v 2.10 1998/10/15 20:09:34 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.11 ! frystyk 155:
! 156: /* Initialize the timezone */
! 157: #ifdef HAVE_TZSET
! 158: tzset();
! 159: #endif
2.1 frystyk 160:
2.2 frystyk 161: /* Create a default user profile and initialize it */
2.1 frystyk 162: UserProfile = HTUserProfile_new(HT_DEFAULT_USER, NULL);
2.2 frystyk 163: HTUserProfile_localize(UserProfile);
164:
2.1 frystyk 165: /* Initialize bindings */
166: HTBind_init();
167:
168: #ifdef WWWLIB_SIG
169: /* On Solaris (and others?) we get a BROKEN PIPE signal when connecting
170: ** to a port where we should get `connection refused'. We ignore this
171: ** using the following function call
172: */
173: HTSetSignal(); /* Set signals in library */
174: #endif
175:
2.4 frystyk 176: initialized = YES;
2.1 frystyk 177: return YES;
178: }
179:
180:
181: /* HTLibTerminate
182: ** --------------
183: ** This function HT_FREEs memory kept by the Library and should be called
184: ** before exit of an application (if you are on a PC platform)
185: */
186: PUBLIC BOOL HTLibTerminate (void)
187: {
188: if (WWWTRACE) HTTrace("WWWLibTerm.. Cleaning up LIBRARY OF COMMON CODE\n");
2.5 eric 189:
190: HTNet_killAll();
2.8 frystyk 191: HTChannel_deleteAll(); /* Delete remaining channels */
2.1 frystyk 192:
193: HT_FREE(HTAppName); /* Freed thanks to Wade Ogden <wade@ebt.com> */
194: HT_FREE(HTAppVersion);
195:
196: HTAtom_deleteAll(); /* Remove the atoms */
197: HTDNS_deleteAll(); /* Remove the DNS host cache */
198: HTAnchor_deleteAll(NULL); /* Delete anchors and drop hyperdocs */
199:
200: HTProtocol_deleteAll(); /* Remove bindings between access and protocols */
201: HTBind_deleteAll(); /* Remove bindings between suffixes, media types */
202:
203: HTUserProfile_delete(UserProfile); /* Free our default User profile */
2.3 frystyk 204:
205: HTUTree_deleteAll(); /* Delete all URL Trees */
2.1 frystyk 206:
2.4 frystyk 207: initialized = NO;
2.1 frystyk 208: return YES;
209: }
210:
Webmaster