Annotation of libwww/Library/src/HTProfil.c, revision 2.31
2.1 frystyk 1: /*
2: ** APPLICATION PROFILES INITALIZATION
3: **
4: ** (c) COPYRIGHT MIT 1995.
5: ** Please first read the full copyright statement in the file COPYRIGH.
2.31 ! vbancrof 6: ** @(#) $Id: HTProfil.c,v 2.30 2001/08/14 16:15:50 kahan Exp $
2.1 frystyk 7: **
8: ** Defines a set of application profiles
9: */
10:
11: /* Library include files */
2.18 frystyk 12: #include "wwwsys.h"
2.1 frystyk 13: #include "WWWUtil.h"
14: #include "WWWCore.h"
2.6 frystyk 15: #include "WWWCache.h"
2.25 frystyk 16: #include "WWWStream.h"
2.27 frystyk 17: #include "HTInit.h"
2.1 frystyk 18: #include "HTProfil.h" /* Implemented here */
19:
20: PRIVATE HTList * converters = NULL;
2.13 frystyk 21: PRIVATE HTList * transfer_encodings = NULL;
22: PRIVATE HTList * content_encodings = NULL;
2.1 frystyk 23: PRIVATE BOOL preemptive = NO;
24:
25: /* ------------------------------------------------------------------------- */
26:
27: PUBLIC void HTProfile_delete (void)
28: {
2.4 eric 29: if (!preemptive) HTEventTerminate();
2.1 frystyk 30: if (HTLib_isInitialized()) {
2.6 frystyk 31:
32: /* Clean up the persistent cache (if any) */
2.7 frystyk 33: HTCacheTerminate();
2.6 frystyk 34:
35: /* Clean up all the global preferences */
2.1 frystyk 36: HTFormat_deleteAll();
2.24 frystyk 37:
2.25 frystyk 38: /* The following lists have been cleaned up by HTFormat_deleteAll */
39: transfer_encodings = 0;
40: content_encodings = 0;
41: converters = 0;
42:
43: /* Remove bindings between suffixes, media types */
44: HTBind_deleteAll();
2.6 frystyk 45:
46: /* Terminate libwww */
2.1 frystyk 47: HTLibTerminate();
48: }
49: }
50:
2.7 frystyk 51: PRIVATE void client_profile (const char * AppName, const char * AppVersion,
2.21 frystyk 52: BOOL preemptive, BOOL cache, BOOL HTMLParser)
2.1 frystyk 53: {
54: /* If the Library is not already initialized then do it */
55: if (!HTLib_isInitialized()) HTLibInit(AppName, AppVersion);
56:
2.16 frystyk 57: /* Register the default set of messages and dialog functions */
58: HTAlertInit();
59: HTAlert_setInteractive(YES);
60:
2.31 ! vbancrof 61: if (!converters) {
! 62: converters = HTList_new();
! 63: /* Register the default set of converters */
! 64: HTConverterInit(converters);
! 65: /* Register the default libwww HTML parser */
! 66: if (HTMLParser) HTMLInit(converters);
! 67: /* Set the converters as global converters for all requests */
! 68: HTFormat_setConversion(converters);
! 69: }
! 70:
! 71: if (!transfer_encodings) {
! 72: transfer_encodings = HTList_new();
! 73: /* Register the default set of transfer encoders and decoders */
! 74: HTTransferEncoderInit(transfer_encodings);
! 75: HTFormat_setTransferCoding(transfer_encodings);
! 76: }
! 77:
! 78: if (!content_encodings) {
! 79: content_encodings = HTList_new();
! 80: /* Register the default set of content encoders and decoders */
! 81: HTContentEncoderInit(content_encodings);
! 82: if (HTList_count(content_encodings) > 0)
! 83: HTFormat_setContentCoding(content_encodings);
! 84: else {
! 85: HTList_delete(content_encodings);
! 86: content_encodings = NULL;
! 87: }
! 88: }
2.1 frystyk 89:
90: /* Register the default set of transport protocols */
91: HTTransportInit();
92:
2.7 frystyk 93: /* Register the default set of application protocol modules */
94: if (preemptive)
95: HTProtocolPreemptiveInit();
96: else
97: HTProtocolInit();
98:
2.25 frystyk 99: /* Initialize suffix bindings for local files */
100: HTBind_init();
101:
2.19 frystyk 102: /* Set max number of sockets we want open simultanously */
2.23 frystyk 103: HTNet_setMaxSocket(32);
2.19 frystyk 104:
2.14 frystyk 105: /* The persistent cache does not work in preemptive mode */
2.17 frystyk 106: if (cache) HTCacheInit(NULL, 20);
2.1 frystyk 107:
108: /* Register the default set of BEFORE and AFTER filters */
109: HTNetInit();
2.6 frystyk 110:
2.1 frystyk 111: /* Set up the default set of Authentication schemes */
112: HTAAInit();
113:
114: /* Get any proxy or gateway environment variables */
115: HTProxy_getEnvVar();
116:
117: /* Register the default set of MIME header parsers */
118: HTMIMEInit();
119:
120: /* Register the default set of file suffix bindings */
121: HTFileInit();
122:
123: /* Register the default set of Icons for directory listings */
124: HTIconInit(NULL);
125: }
126:
127: PUBLIC void HTProfile_newClient (const char * AppName, const char * AppVersion)
2.4 eric 128: {
2.5 frystyk 129: /* Do the default setup */
2.21 frystyk 130: client_profile(AppName, AppVersion, NO, YES, NO);
131:
132: /* Set up default event loop */
133: HTEventInit();
134: }
135:
136: PUBLIC void HTProfile_newHTMLClient (const char * AppName, const char * AppVersion)
137: {
138: /* Do the default setup */
139: client_profile(AppName, AppVersion, NO, YES, YES);
2.5 frystyk 140:
141: /* Set up default event loop */
2.4 eric 142: HTEventInit();
2.1 frystyk 143: }
144:
145: PUBLIC void HTProfile_newPreemptiveClient (const char * AppName,
146: const char * AppVersion)
147: {
2.5 frystyk 148: /* Do the default setup */
2.21 frystyk 149: client_profile(AppName, AppVersion, YES, NO, NO);
2.1 frystyk 150:
2.30 kahan 151: /* Set up default event loop */
2.26 frystyk 152: HTEventInit();
2.1 frystyk 153: /* Remember that we are loading preemptively */
154: preemptive = YES;
2.17 frystyk 155: }
156:
157: PUBLIC void HTProfile_newNoCacheClient (const char * AppName,
158: const char * AppVersion)
159: {
160: /* Do the default setup */
2.21 frystyk 161: client_profile(AppName, AppVersion, NO, NO, NO);
162:
163: /* Set up default event loop */
164: HTEventInit();
165: }
166:
167: PUBLIC void HTProfile_newHTMLNoCacheClient (const char * AppName,
168: const char * AppVersion)
169: {
170: /* Do the default setup */
171: client_profile(AppName, AppVersion, NO, NO, YES);
2.17 frystyk 172:
173: /* Set up default event loop */
174: HTEventInit();
2.1 frystyk 175: }
176:
177: PRIVATE void robot_profile (const char * AppName, const char * AppVersion)
178: {
179: /* If the Library is not already initialized then do it */
180: if (!HTLib_isInitialized()) HTLibInit(AppName, AppVersion);
181:
2.31 ! vbancrof 182: if (!converters) {
! 183: converters = HTList_new();
! 184: /* Register the default set of converters including the HTML parser */
! 185: HTConverterInit(converters);
! 186: HTMLInit(converters);
! 187: /* Set the converters as global converters for all requests */
! 188: HTFormat_setConversion(converters);
! 189: }
! 190:
! 191: if (!transfer_encodings) {
! 192: transfer_encodings = HTList_new();
! 193: /* Register the default set of transfer encoders and decoders */
! 194: HTTransferEncoderInit(transfer_encodings);
! 195: HTFormat_setTransferCoding(transfer_encodings);
! 196: }
! 197:
! 198: if (!content_encodings) {
! 199: content_encodings = HTList_new();
! 200: /* Register the default set of content encoders and decoders */
! 201: HTContentEncoderInit(content_encodings);
! 202: if (HTList_count(content_encodings) > 0)
! 203: HTFormat_setContentCoding(content_encodings);
! 204: else {
! 205: HTList_delete(content_encodings);
! 206: content_encodings = NULL;
! 207: }
! 208: }
2.1 frystyk 209:
210: /* Register the default set of transport protocols */
211: HTTransportInit();
212:
213: /* Register the default set of application protocol modules */
214: HTProtocolInit();
2.25 frystyk 215:
216: /* Initialize suffix bindings for local files */
217: HTBind_init();
2.1 frystyk 218:
219: /* Set max number of sockets we want open simultanously */
2.23 frystyk 220: HTNet_setMaxSocket(32);
2.1 frystyk 221:
222: /* Register some default set of BEFORE and AFTER filters */
2.10 frystyk 223: HTNet_addBefore(HTRuleFilter, NULL, NULL, HT_FILTER_MIDDLE);
224: HTNet_addBefore(HTProxyFilter, NULL, NULL, HT_FILTER_MIDDLE);
225: HTNet_addAfter(HTInfoFilter, NULL, NULL, HT_ALL, HT_FILTER_LATE);
2.1 frystyk 226:
227: /* Get any proxy or gateway environment variables */
228: HTProxy_getEnvVar();
229:
230: /* Register the default set of MIME header parsers */
231: HTMIMEInit();
232:
233: /* Register the default set of file suffix bindings */
234: HTFileInit();
235:
236: /* Register the default set of Icons for directory listings */
237: HTIconInit(NULL);
238:
239: /* Register some default messages and dialog functions */
240: if (HTAlert_interactive()) {
241: HTAlert_add(HTError_print, HT_A_MESSAGE);
242: HTAlert_add(HTConfirm, HT_A_CONFIRM);
243: HTAlert_add(HTPrompt, HT_A_PROMPT);
244: HTAlert_add(HTPromptPassword, HT_A_SECRET);
245: HTAlert_add(HTPromptUsernameAndPassword, HT_A_USER_PW);
246: }
247: HTAlert_setInteractive(YES);
248: }
249:
250: PUBLIC void HTProfile_newRobot (const char * AppName, const char * AppVersion)
251: {
2.4 eric 252: /* set up default event loop */
253: HTEventInit();
2.1 frystyk 254: robot_profile(AppName, AppVersion);
255:
256: /* Register the default set of application protocol modules */
257: HTProtocolInit();
258: }
259:
260: PUBLIC void HTProfile_newPreemptiveRobot (const char * AppName,
261: const char * AppVersion)
262: {
263: robot_profile(AppName, AppVersion);
264:
265: /* Register the default set of application protocol modules */
266: HTProtocolPreemptiveInit();
267:
268: /* Remember that we are loading preemptively */
269: preemptive = YES;
270: }
271:
272:
273:
274:
275:
276:
277:
Webmaster