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