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