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