Annotation of libwww/Library/src/HTLib.c, revision 2.16
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.16 ! frystyk 6: ** @(#) $Id: HTLib.c,v 2.15 1999/02/22 22:10:11 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 "HTAnchor.h"
19: #include "HTProt.h"
20: #include "HTDNS.h"
2.3 frystyk 21: #include "HTUTree.h"
2.1 frystyk 22: #include "HTLib.h" /* Implemented here */
23:
24: #ifndef W3C_VERSION
25: #define W3C_VERSION "unknown"
26: #endif
27:
28: #ifndef HT_DEFAULT_USER
29: #define HT_DEFAULT_USER "LIBWWW_GENERIC_USER"
30: #endif
31:
32: PRIVATE char * HTAppName = NULL; /* Application name: please supply */
33: PRIVATE char * HTAppVersion = NULL; /* Application version: please supply */
34:
35: PRIVATE char * HTLibName = "libwww";
36: PRIVATE char * HTLibVersion = W3C_VERSION;
37:
38: PRIVATE BOOL HTSecure = NO; /* Can we access local file system? */
39:
2.4 frystyk 40: PRIVATE BOOL initialized = NO;
41:
2.1 frystyk 42: PRIVATE HTUserProfile * UserProfile = NULL; /* Default user profile */
43:
44: /* --------------------------------------------------------------------------*/
45:
46: /* Information about the Application
47: ** ---------------------------------
48: */
49: PUBLIC const char * HTLib_appName (void)
50: {
51: return HTAppName ? HTAppName : "UNKNOWN";
52: }
53:
2.10 frystyk 54: PUBLIC BOOL HTLib_setAppName (const char * name)
55: {
56: if (name) {
57: char * ptr;
58: StrAllocCopy(HTAppName, name);
59: ptr = HTAppName;
60: while (*ptr) {
61: if (isspace((int) *ptr)) *ptr = '_';
62: ptr++;
63: }
64: return YES;
65: }
66: return NO;
67: }
68:
2.1 frystyk 69: PUBLIC const char * HTLib_appVersion (void)
70: {
71: return HTAppVersion ? HTAppVersion : "0.0";
72: }
73:
2.10 frystyk 74: PUBLIC BOOL HTLib_setAppVersion (const char * version)
75: {
76: if (version) {
77: char * ptr;
78: StrAllocCopy(HTAppVersion, version);
79: ptr = HTAppVersion;
80: while (*ptr) {
81: if (isspace((int) *ptr)) *ptr = '_';
82: ptr++;
83: }
84: return YES;
85: }
86: return NO;
87: }
88:
2.1 frystyk 89: /* Information about libwww
90: ** ------------------------
91: */
92: PUBLIC const char * HTLib_name (void)
93: {
94: return HTLibName ? HTLibName : "UNKNOWN";
95: }
96:
97: PUBLIC const char * HTLib_version (void)
98: {
99: return HTLibVersion ? HTLibVersion : "0.0";
100: }
101:
102: /* Default User Profile
103: ** --------------------
104: */
105: PUBLIC HTUserProfile * HTLib_userProfile (void)
106: {
107: return UserProfile;
108: }
109:
110: PUBLIC BOOL HTLib_setUserProfile (HTUserProfile * up)
111: {
112: if (up) {
113: UserProfile = up;
114: return YES;
115: }
116: return NO;
117: }
118:
119: /* Access Local File System
120: ** ------------------------
121: ** In this mode we do not tough the local file system at all
122: */
123: PUBLIC BOOL HTLib_secure (void)
124: {
125: return HTSecure;
126: }
127:
128: PUBLIC void HTLib_setSecure (BOOL mode)
129: {
130: HTSecure = mode;
131: }
132:
2.4 frystyk 133: /* Have application initalized
134: ** ---------------------------
135: */
136: PUBLIC BOOL HTLib_isInitialized (void)
137: {
138: return initialized;
139: }
140:
2.1 frystyk 141: /* HTLibInit
142: **
143: ** This function initiates the Library and it MUST be called when
144: ** starting up an application. See also HTLibTerminate()
145: */
146: PUBLIC BOOL HTLibInit (const char * AppName, const char * AppVersion)
147: {
2.15 frystyk 148: HTTRACE(CORE_TRACE, "WWWLibInit.. INITIALIZING LIBRARY OF COMMON CODE\n");
2.1 frystyk 149:
150: /* Set the application name and version */
2.10 frystyk 151: HTLib_setAppName(AppName);
152: HTLib_setAppVersion(AppVersion);
2.11 frystyk 153:
154: /* Initialize the timezone */
155: #ifdef HAVE_TZSET
156: tzset();
2.12 frystyk 157: #endif
158:
159: /* If we are using tempnam() then unset any TMPDIR env var */
160: #ifdef HAVE_TEMPNAM
161: putenv("TMPDIR=");
2.11 frystyk 162: #endif
2.1 frystyk 163:
2.2 frystyk 164: /* Create a default user profile and initialize it */
2.1 frystyk 165: UserProfile = HTUserProfile_new(HT_DEFAULT_USER, NULL);
2.2 frystyk 166: HTUserProfile_localize(UserProfile);
167:
2.1 frystyk 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: {
2.15 frystyk 188: HTTRACE(CORE_TRACE, "WWWLibTerm.. Cleaning up LIBRARY OF COMMON CODE\n");
2.5 eric 189:
190: HTNet_killAll();
2.16 ! frystyk 191: HTHost_deleteAll(); /* Delete remaining hosts */
2.8 frystyk 192: HTChannel_deleteAll(); /* Delete remaining channels */
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:
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