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