Annotation of libwww/Library/src/HTInit.c, revision 2.73.2.3
2.20 frystyk 1: /* HTInit.c
2: ** CONFIGURATION-SPECIFIC INITIALIALIZATION
3: **
2.25 frystyk 4: ** (c) COPYRIGHT MIT 1995.
2.20 frystyk 5: ** Please first read the full copyright statement in the file COPYRIGH.
2.73.2.3! frystyk 6: ** @(#) $Id: HTInit.c,v 2.73.2.2 1996/10/30 23:21:57 frystyk Exp $
2.9 duns 7: **
2.20 frystyk 8: ** Define a basic set of suffixes and presentations
2.1 timbl 9: */
10:
2.22 frystyk 11: /* Library include files */
2.52 frystyk 12: #include "sysdep.h"
2.59 frystyk 13: #include "WWWUtil.h"
14: #include "WWWCore.h"
2.73.2.2 frystyk 15: #include "WWWMux.h"
16:
2.22 frystyk 17: #include "HTInit.h" /* Implemented here */
2.1 timbl 18:
2.65 frystyk 19: #ifndef W3C_ICONS
20: #define W3C_ICONS "/tmp"
21: #endif
22:
23: #define ICON_LOCATION "/internal-icon/"
24:
2.29 frystyk 25: /* ------------------------------------------------------------------------- */
26:
2.23 frystyk 27: /* BINDINGS BETWEEN A SOURCE MEDIA TYPE AND A DEST MEDIA TYPE (CONVERSION)
28: ** ----------------------------------------------------------------------
2.47 frystyk 29: ** Not done automaticly - may be done by application!
2.23 frystyk 30: */
2.38 frystyk 31: PUBLIC void HTConverterInit (HTList * c)
2.23 frystyk 32: {
2.31 frystyk 33: /*
2.49 frystyk 34: ** You can get debug information out through the debug stream if you set
35: ** the debug format appropriately
36: */
37: HTConversion_add(c,"*/*", "www/debug", HTBlackHoleConverter, 1.0, 0.0, 0.0);
38:
39: /*
2.31 frystyk 40: ** These are converters that converts to something other than www/present,
41: ** that is not directly outputting someting to the user on the screen
42: */
2.43 frystyk 43: HTConversion_add(c,"message/rfc822", "*/*", HTMIMEConvert, 1.0, 0.0, 0.0);
2.55 frystyk 44: HTConversion_add(c,"message/x-rfc822-foot", "*/*", HTMIMEFooter, 1.0, 0.0, 0.0);
2.72 frystyk 45: HTConversion_add(c,"message/x-rfc822-head", "*/*", HTMIMEHeader, 1.0, 0.0, 0.0);
2.73 frystyk 46: HTConversion_add(c,"message/x-rfc822-partial","*/*", HTMIMEPartial, 1.0, 0.0, 0.0);
2.43 frystyk 47: HTConversion_add(c,"multipart/*", "*/*", HTBoundary, 1.0, 0.0, 0.0);
2.38 frystyk 48: HTConversion_add(c,"text/plain", "text/html", HTPlainToHTML, 1.0, 0.0, 0.0);
2.39 frystyk 49:
50: /*
51: ** The following conversions are converting ASCII output from various
52: ** protocols to HTML objects.
53: */
2.51 frystyk 54: HTConversion_add(c,"text/x-http", "*/*", HTTPStatus_new, 1.0, 0.0, 0.0);
2.68 frystyk 55:
2.42 frystyk 56: #if 0
57: HTConversion_add(c,"text/x-gopher", "www/present", HTGopherMenu, 1.0, 0.0, 0.0);
58: HTConversion_add(c,"text/x-cso", "www/present", HTGopherCSO, 1.0, 0.0, 0.0);
2.68 frystyk 59: HTConversion_add(c,"text/x-wais-source", "*/*", HTWSRCConvert, 1.0, 0.0, 0.0);
60: #endif
61:
2.48 frystyk 62: HTConversion_add(c,"text/x-nntp-list", "*/*", HTNewsList, 1.0, 0.0, 0.0);
63: HTConversion_add(c,"text/x-nntp-over", "*/*", HTNewsGroup, 1.0, 0.0, 0.0);
2.43 frystyk 64:
2.31 frystyk 65: /*
2.45 frystyk 66: ** We also register a special content type guess stream that can figure out
67: ** the content type by reading the first bytes of the stream
68: */
69: HTConversion_add(c,"www/unknown", "*/*", HTGuess_new, 1.0, 0.0, 0.0);
2.46 frystyk 70:
71: /*
2.72 frystyk 72: ** Register a persistent cache stream which can save an object to local
73: ** file
74: */
75: HTConversion_add(c,"www/cache", "*/*", HTCacheWriter, 1.0, 0.0, 0.0);
2.73 frystyk 76: HTConversion_add(c,"www/cache-append", "*/*", HTCacheAppend, 1.0, 0.0, 0.0);
2.72 frystyk 77:
78: /*
2.46 frystyk 79: ** Handling Rule files is handled just like any other stream
80: ** This converter reads a rule file and generates the rules
81: */
2.48 frystyk 82: HTConversion_add(c,"application/x-www-rules","*/*", HTRules, 1.0, 0.0, 0.0);
2.46 frystyk 83:
2.45 frystyk 84: /*
2.34 frystyk 85: ** This dumps all other formats to local disk without any further
2.31 frystyk 86: ** action taken
87: */
2.38 frystyk 88: HTConversion_add(c,"*/*", "www/present", HTSaveLocally, 0.3, 0.0, 0.0);
2.23 frystyk 89: }
90:
91: /* BINDINGS BETWEEN MEDIA TYPES AND EXTERNAL VIEWERS/PRESENTERS
92: ** ------------------------------------------------------------
2.47 frystyk 93: ** Not done automaticly - may be done by application!
2.23 frystyk 94: ** The data objects are stored in temporary files before the external
95: ** program is called
96: */
2.38 frystyk 97: PUBLIC void HTPresenterInit (HTList * c)
2.1 timbl 98: {
99: #ifdef NeXT
2.38 frystyk 100: HTPresentation_add(c,"application/postscript", "open %s", NULL, 1.0, 2.0, 0.0);
2.10 luotonen 101: /* The following needs the GIF previewer -- you might not have it. */
2.19 howcome 102:
2.38 frystyk 103: HTPresentation_add(c,"image/gif", "open %s", NULL, 0.3, 2.0, 0.0);
2.44 frystyk 104: HTPresentation_add(c,"image/tiff", "open %s", NULL, 1.0, 2.0, 0.0);
2.41 frystyk 105: HTPresentation_add(c,"audio/basic", "open %s", NULL, 1.0, 2.0, 0.0);
106: HTPresentation_add(c,"*/*", "open %s", NULL, 0.05, 0.0, 0.0);
2.1 timbl 107: #else
2.10 luotonen 108: if (getenv("DISPLAY")) { /* Must have X11 */
2.38 frystyk 109: HTPresentation_add(c,"application/postscript", "ghostview %s", NULL, 1.0, 3.0, 0.0);
2.41 frystyk 110: HTPresentation_add(c,"image/gif", "xv %s", NULL, 1.0, 3.0, 0.0);
2.44 frystyk 111: HTPresentation_add(c,"image/tiff", "xv %s", NULL, 1.0, 3.0, 0.0);
2.38 frystyk 112: HTPresentation_add(c,"image/jpeg", "xv %s", NULL, 1.0, 3.0, 0.0);
2.44 frystyk 113: HTPresentation_add(c,"image/png", "xv %s", NULL, 1.0, 3.0, 0.0);
2.10 luotonen 114: }
2.1 timbl 115: #endif
2.15 frystyk 116: }
117:
118:
2.23 frystyk 119: /* PRESENTERS AND CONVERTERS AT THE SAME TIME
120: ** ------------------------------------------
2.47 frystyk 121: ** Not done automaticly - may be done by application!
2.23 frystyk 122: ** This function is only defined in order to preserve backward
123: ** compatibility.
124: */
2.38 frystyk 125: PUBLIC void HTFormatInit (HTList * c)
2.15 frystyk 126: {
2.23 frystyk 127: HTConverterInit(c);
128: HTPresenterInit(c);
129:
2.1 timbl 130: }
131:
2.55 frystyk 132: /* BINDINGS BETWEEN A ENCODING AND CODERS / DECODERS
133: ** --------------------------- ---------------------
134: ** Not done automaticly - may be done by application!
135: */
136: PUBLIC void HTEncoderInit (HTList * c)
137: {
2.63 frystyk 138: HTCoding_add(c, "chunked", HTChunkedEncoder, HTChunkedDecoder, 1.0);
2.55 frystyk 139: }
2.47 frystyk 140:
2.64 frystyk 141: /* REGISTER BEFORE FILTERS
142: ** -----------------------
143: ** The BEFORE filters handle proxies, caches, rule files etc.
144: ** The filters are called in the order by which the are registered
145: ** Not done automaticly - may be done by application!
146: */
147: PUBLIC void HTBeforeInit (void)
148: {
2.73 frystyk 149: HTNet_addBefore(HTMemoryCacheFilter, NULL, NULL, 5);
150: HTNet_addBefore(HTCacheFilter, "http://*", NULL, 5);
151: HTNet_addBefore(HTCredentialsFilter, "http://*", NULL, 6);
152: HTNet_addBefore(HTPEP_beforeFilter, "http://*", NULL, 6);
153: HTNet_addBefore(HTRuleFilter, NULL, NULL, 10);
154: HTNet_addBefore(HTProxyFilter, NULL, NULL, 10);
2.64 frystyk 155: }
156:
157: /* REGISTER AFTER FILTERS
158: ** ----------------------
159: ** The AFTER filters handle error messages, logging, redirection,
160: ** authentication etc.
161: ** The filters are called in the order by which the are registered
162: ** Not done automaticly - may be done by application!
163: */
164: PUBLIC void HTAfterInit (void)
165: {
2.73 frystyk 166: HTNet_addAfter(HTAuthFilter, "http://*", NULL, HT_NO_ACCESS, 5);
167: HTNet_addAfter(HTPEP_afterFilter, "http://*", NULL, HT_ALL, 5);
168: HTNet_addAfter(HTRedirectFilter, "http://*", NULL, HT_TEMP_REDIRECT, 5);
169: HTNet_addAfter(HTRedirectFilter, "http://*", NULL, HT_PERM_REDIRECT, 5);
170: HTNet_addAfter(HTUseProxyFilter, "http://*", NULL, HT_USE_PROXY, 5);
171: HTNet_addAfter(HTCacheUpdateFilter, "http://*", NULL, HT_NOT_MODIFIED, 5);
172: HTNet_addAfter(HTLogFilter, NULL, NULL, HT_ALL, HT_FILTER_LAST);
173: HTNet_addAfter(HTInfoFilter, NULL, NULL, HT_ALL, HT_FILTER_LAST);
2.64 frystyk 174: }
175:
176: /* REGISTER DEFAULT AUTHENTICATION SCHEMES
177: ** ---------------------------------------
178: ** This function registers the BASIC access authentication
179: */
180: PUBLIC void HTAAInit (void)
181: {
182: HTAA_newModule ("basic", HTBasic_generate, HTBasic_parse, HTBasic_delete);
183: }
184:
185: /* REGISTER BEFORE AND AFTER FILTERS
186: ** ---------------------------------
187: ** We register a commonly used set of BEFORE and AFTER filters.
2.47 frystyk 188: ** Not done automaticly - may be done by application!
189: */
190: PUBLIC void HTNetInit (void)
191: {
2.64 frystyk 192: HTBeforeInit();
193: HTAfterInit();
2.47 frystyk 194: }
195:
196:
197: /* REGISTER CALLBACKS FOR THE ALERT MANAGER
198: ** ----------------------------------------
199: ** We register a set of alert messages
200: ** Not done automaticly - may be done by application!
201: */
202: PUBLIC void HTAlertInit (void)
203: {
204: HTAlert_add(HTProgress, HT_A_PROGRESS);
205: HTAlert_add(HTError_print, HT_A_MESSAGE);
206: HTAlert_add(HTConfirm, HT_A_CONFIRM);
207: HTAlert_add(HTPrompt, HT_A_PROMPT);
208: HTAlert_add(HTPromptPassword, HT_A_SECRET);
209: HTAlert_add(HTPromptUsernameAndPassword, HT_A_USER_PW);
210: }
211:
2.53 frystyk 212: /* REGISTER ALL KNOWN TRANSPORTS IN THE LIBRARY
213: ** --------------------------------------------
214: ** Not done automaticly - may be done by application!
215: */
216: PUBLIC void HTTransportInit (void)
217: {
2.69 frystyk 218: HTTransport_add("tcp", HT_TP_SINGLE, HTReader_new, HTWriter_new);
219: HTTransport_add("buffered_tcp", HT_TP_SINGLE, HTReader_new, HTBufferWriter_new);
2.73.2.3! frystyk 220: #ifdef HT_MUX
2.73.2.2 frystyk 221: HTTransport_add("mux", HT_TP_INTERLEAVE, HTReader_new, HTMuxBuffer_new);
2.73.2.3! frystyk 222: #endif /* HT_MUX */
2.54 frystyk 223: #ifndef NO_UNIX_IO
2.69 frystyk 224: HTTransport_add("local", HT_TP_SINGLE, HTReader_new, HTWriter_new);
2.54 frystyk 225: #else
2.69 frystyk 226: HTTransport_add("local", HT_TP_SINGLE, HTANSIReader_new, HTANSIWriter_new);
2.54 frystyk 227: #endif
2.53 frystyk 228: }
2.47 frystyk 229:
2.24 frystyk 230: /* REGISTER ALL KNOWN PROTOCOLS IN THE LIBRARY
231: ** -------------------------------------------
2.47 frystyk 232: ** Not done automaticly - may be done by application!
2.24 frystyk 233: */
2.73.2.1 eric 234: #ifndef FTP_PORT
235: #define FTP_PORT 21
236: #endif
237: #ifndef NEWS_PORT
238: #define NEWS_PORT 119
239: #endif
240: #ifndef GOPHER_PORT
241: #define GOPHER_PORT 70
242: #endif
243: #ifndef WAIS_PORT
244: #define WAIS_PORT 666
245: #endif
246: #ifndef HTTP_PORT
247: #define HTTP_PORT 80
248: #endif
249:
2.63 frystyk 250: PUBLIC void HTProtocolInit (void)
2.24 frystyk 251: {
252: #ifndef DECNET
2.73.2.1 eric 253: HTProtocol_add("ftp", "tcp", FTP_PORT, NO, HTLoadFTP, NULL);
254: HTProtocol_add("nntp", "tcp", NEWS_PORT, NO, HTLoadNews, NULL);
255: HTProtocol_add("news", "tcp", NEWS_PORT, NO, HTLoadNews, NULL);
256: HTProtocol_add("gopher", "tcp", GOPHER_PORT, NO, HTLoadGopher, NULL);
2.24 frystyk 257: #ifdef HT_DIRECT_WAIS
2.73.2.1 eric 258: HTProtocol_add("wais", "", WAIS_PORT, YES, HTLoadWAIS, NULL);
2.24 frystyk 259: #endif
260: #endif /* DECNET */
2.73.2.3! frystyk 261: #ifdef HT_MUX
2.73.2.2 frystyk 262: HTProtocol_add("http", "mux", HTTP_PORT, NO, HTLoadHTTP, NULL);
2.73.2.3! frystyk 263: #else
! 264: HTProtocol_add("http", "buffered_tcp", HTTP_PORT, NO, HTLoadHTTP, NULL);
! 265: #endif /* !HT_MUX */
2.73.2.1 eric 266: HTProtocol_add("file", "local", 0, NO, HTLoadFile, NULL);
267: HTProtocol_add("cache", "local", 0, NO, HTLoadCache, NULL);
268: HTProtocol_add("telnet", "", 0, YES, HTLoadTelnet, NULL);
269: HTProtocol_add("tn3270", "", 0, YES, HTLoadTelnet, NULL);
270: HTProtocol_add("rlogin", "", 0, YES, HTLoadTelnet, NULL);
2.24 frystyk 271: }
2.1 timbl 272:
2.65 frystyk 273: /* REGISTER ALL KNOWN PROTOCOLS IN THE LIBRARY PREEMPTIVELY
274: ** --------------------------------------------------------
275: ** Not done automaticly - may be done by application!
276: */
277: PUBLIC void HTProtocolPreemptiveInit (void)
278: {
279: #ifndef DECNET
2.73.2.1 eric 280: HTProtocol_add("ftp", "tcp", FTP_PORT, YES, HTLoadFTP, NULL);
281: HTProtocol_add("nntp", "tcp", NEWS_PORT, YES, HTLoadNews, NULL);
282: HTProtocol_add("news", "tcp", NEWS_PORT, YES, HTLoadNews, NULL);
283: HTProtocol_add("gopher", "tcp", GOPHER_PORT, YES, HTLoadGopher, NULL);
2.65 frystyk 284: #ifdef HT_DIRECT_WAIS
2.73.2.1 eric 285: HTProtocol_add("wais", "", WAIS_PORT, YES, HTLoadWAIS, NULL);
2.65 frystyk 286: #endif
287: #endif /* DECNET */
288:
2.73.2.1 eric 289: HTProtocol_add("http", "buffered_tcp", HTTP_PORT, YES, HTLoadHTTP, NULL);
290: HTProtocol_add("file", "local", 0, YES, HTLoadFile, NULL);
291: HTProtocol_add("telnet", "", 0, YES, HTLoadTelnet, NULL);
292: HTProtocol_add("tn3270", "", 0, YES, HTLoadTelnet, NULL);
293: HTProtocol_add("rlogin", "", 0, YES, HTLoadTelnet, NULL);
294: HTProtocol_add("cache","local",0,YES,HTLoadCache, NULL);
2.61 frystyk 295: }
296:
2.48 frystyk 297: /* BINDINGS BETWEEN ICONS AND MEDIA TYPES
298: ** --------------------------------------
299: ** Not done automaticly - may be done by application!
300: ** For directory listings etc. you can bind a set of icons to a set of
301: ** media types and special icons for directories and other objects that
302: ** do not have a media type.
303: */
2.61 frystyk 304: PUBLIC void HTIconInit (const char * url_prefix)
2.58 eric 305: {
2.65 frystyk 306: const char * prefix = url_prefix ? url_prefix : ICON_LOCATION;
2.58 eric 307:
2.61 frystyk 308: HTIcon_addBlank("blank.xbm", prefix, NULL);
309: HTIcon_addDir("directory.xbm", prefix, "DIR");
310: HTIcon_addParent("back.xbm", prefix, "UP");
311: HTIcon_addUnknown("unknown.xbm", prefix, NULL);
312:
313: HTIcon_add("unknown.xbm", prefix, NULL, "*/*");
314: HTIcon_add("binary.xbm", prefix, "BIN", "binary");
315: HTIcon_add("unknown.xbm", prefix, NULL, "www/unknown");
316: HTIcon_add("text.xbm", prefix, "TXT", "text/*");
317: HTIcon_add("image.xbm", prefix, "IMG", "image/*");
318: HTIcon_add("movie.xbm", prefix, "MOV", "video/*");
319: HTIcon_add("sound.xbm", prefix, "AU", "audio/*");
320: HTIcon_add("tar.xbm", prefix, "TAR", "multipart/x-tar");
321: HTIcon_add("tar.xbm", prefix, "TAR", "multipart/x-gtar");
322: HTIcon_add("compressed.xbm",prefix, "CMP", "x-compress");
323: HTIcon_add("compressed.xbm",prefix, "GZP", "x-gzip");
324: HTIcon_add("index.xbm", prefix, "IDX", "application/x-gopher-index");
325: HTIcon_add("index2.xbm", prefix, "CSO", "application/x-gopher-cso");
326: HTIcon_add("telnet.xbm", prefix, "TEL", "application/x-gopher-telnet");
327: HTIcon_add("unknown.xbm", prefix, "DUP", "application/x-gopher-duplicate");
328: HTIcon_add("unknown.xbm", prefix, "TN", "application/x-gopher-tn3270");
2.65 frystyk 329:
330: /* Add global mapping to where to find the internal icons */
331: HTRule_addGlobal(HT_Pass, ICON_LOCATION, W3C_ICONS);
2.58 eric 332: }
333:
2.57 eric 334: /* REGISTER ALL HTTP/1.1 MIME HEADERS
335: ** --------------------------------------------
336: ** Not done automaticly - may be done by application!
337: */
2.64 frystyk 338: PUBLIC void HTMIMEInit (void)
2.57 eric 339: {
340: struct {
341: char * string;
342: HTParserCallback * pHandler;
343: } fixedHandlers[] = {
2.61 frystyk 344: {"accept", &HTMIME_accept},
345: {"accept-charset", &HTMIME_acceptCharset},
346: {"accept-encoding", &HTMIME_acceptEncoding},
347: {"accept-language", &HTMIME_acceptLanguage},
348: {"accept-ranges", &HTMIME_acceptRanges},
349: {"authorization", NULL},
2.72 frystyk 350: {"cache-control", &HTMIME_cacheControl},
2.61 frystyk 351: {"connection", &HTMIME_connection},
352: {"content-encoding", &HTMIME_contentEncoding},
353: {"content-length", &HTMIME_contentLength},
354: {"content-range", &HTMIME_contentRange},
355: {"content-transfer-encoding", &HTMIME_contentTransferEncoding},
356: {"content-type", &HTMIME_contentType},
357: {"digest-MessageDigest", &HTMIME_messageDigest},
2.57 eric 358: {"keep-alive", NULL},
2.61 frystyk 359: {"link", &HTMIME_link},
360: {"location", &HTMIME_location},
361: {"max-forwards", &HTMIME_maxForwards},
2.57 eric 362: {"mime-version", NULL},
2.61 frystyk 363: {"pragma", &HTMIME_pragma},
2.73 frystyk 364: {"protocol", &HTMIME_protocol},
365: {"protocol-info", &HTMIME_protocolInfo},
366: {"protocol-request", &HTMIME_protocolRequest},
2.66 frystyk 367: {"proxy-authenticate", &HTMIME_authenticate},
2.61 frystyk 368: {"proxy-authorization", &HTMIME_proxyAuthorization},
369: {"public", &HTMIME_public},
370: {"range", &HTMIME_range},
371: {"referer", &HTMIME_referer},
372: {"retry-after", &HTMIME_retryAfter},
2.62 frystyk 373: {"server", &HTMIME_server},
2.61 frystyk 374: {"transfer-encoding", &HTMIME_contentTransferEncoding},
375: {"upgrade", &HTMIME_upgrade},
376: {"user-agent", &HTMIME_userAgent},
377: {"vary", &HTMIME_vary},
378: {"via", &HTMIME_via},
379: {"warning", &HTMIME_warning},
380: {"www-authenticate", &HTMIME_authenticate},
2.57 eric 381: };
382: int i;
383:
384: for (i = 0; i < sizeof(fixedHandlers)/sizeof(fixedHandlers[0]); i++)
385: HTHeader_addParser(fixedHandlers[i].string, NO,
386: fixedHandlers[i].pHandler);
387: }
388:
Webmaster