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