1 /*
2 **	GENEREAL LIBRARY INFORMATION
3 **
4 **	(c) COPYRIGHT MIT 1995.
5 **	Please first read the full copyright statement in the file COPYRIGH.
6 **	@(#) $Id$
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"
21 #include "HTUTree.h"
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 
40 PRIVATE BOOL   initialized = NO;
41 
42 PRIVATE HTUserProfile * UserProfile = NULL;	     /* Default user profile */
43 
44 /* --------------------------------------------------------------------------*/
45 
46 /*	Information about the Application
47 **	---------------------------------
48 */
HTLib_appName(void)49 PUBLIC const char * HTLib_appName (void)
50 {
51     return HTAppName ? HTAppName : "UNKNOWN";
52 }
53 
HTLib_setAppName(const char * name)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 
HTLib_appVersion(void)69 PUBLIC const char * HTLib_appVersion (void)
70 {
71     return HTAppVersion ? HTAppVersion : "0.0";
72 }
73 
HTLib_setAppVersion(const char * version)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 
89 /*	Information about libwww
90 **	------------------------
91 */
HTLib_name(void)92 PUBLIC const char * HTLib_name (void)
93 {
94     return HTLibName ? HTLibName : "UNKNOWN";
95 }
96 
HTLib_version(void)97 PUBLIC const char * HTLib_version (void)
98 {
99     return HTLibVersion ? HTLibVersion : "0.0";
100 }
101 
102 /*	Default User Profile
103 **	--------------------
104 */
HTLib_userProfile(void)105 PUBLIC HTUserProfile * HTLib_userProfile (void)
106 {
107     return UserProfile;
108 }
109 
HTLib_setUserProfile(HTUserProfile * up)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 */
HTLib_secure(void)123 PUBLIC BOOL HTLib_secure (void)
124 {
125     return HTSecure;
126 }
127 
HTLib_setSecure(BOOL mode)128 PUBLIC void HTLib_setSecure (BOOL mode)
129 {
130     HTSecure = mode;
131 }
132 
133 /*	Have application initalized
134 **	---------------------------
135 */
HTLib_isInitialized(void)136 PUBLIC BOOL HTLib_isInitialized (void)
137 {
138     return initialized;
139 }
140 
141 /*								     HTLibInit
142 **
143 **	This function initiates the Library and it MUST be called when
144 **	starting up an application. See also HTLibTerminate()
145 */
HTLibInit(const char * AppName,const char * AppVersion)146 PUBLIC BOOL HTLibInit (const char * AppName, const char * AppVersion)
147 {
148     HTTRACE(CORE_TRACE, "WWWLibInit.. INITIALIZING LIBRARY OF COMMON CODE\n");
149 
150     /* Set the application name and version */
151     HTLib_setAppName(AppName);
152     HTLib_setAppVersion(AppVersion);
153 
154     /* Initialize the timezone */
155 #ifdef HAVE_TZSET
156     tzset();
157 #endif
158 
159     /* Create a default user profile and initialize it */
160     UserProfile = HTUserProfile_new(HT_DEFAULT_USER, NULL);
161     HTUserProfile_localize(UserProfile);
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 
171     initialized = YES;
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 */
HTLibTerminate(void)181 PUBLIC BOOL HTLibTerminate (void)
182 {
183     HTTRACE(CORE_TRACE, "WWWLibTerm.. Cleaning up LIBRARY OF COMMON CODE\n");
184 
185     HTNet_killAll();
186     HTHost_deleteAll();		/* Delete remaining hosts */
187     HTChannel_deleteAll();			/* Delete remaining channels */
188 
189     HT_FREE(HTAppName);	        /* Freed thanks to Wade Ogden <wade@ebt.com> */
190     HT_FREE(HTAppVersion);
191 
192     HTAtom_deleteAll();					 /* Remove the atoms */
193     HTDNS_deleteAll();				/* Remove the DNS host cache */
194     HTAnchor_deleteAll(NULL);		/* Delete anchors and drop hyperdocs */
195 
196     HTProtocol_deleteAll();  /* Remove bindings between access and protocols */
197 
198     HTUserProfile_delete(UserProfile);	    /* Free our default User profile */
199 
200     HTUTree_deleteAll();			     /* Delete all URL Trees */
201 
202     initialized = NO;
203     return YES;
204 }
205 
206