Annotation of libwww/Library/src/HTInit.c, revision 2.60
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.60 ! eric 6: ** @(#) $Id: HTInit.c,v 2.59 1996/06/08 01:52:16 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"
15: #include "HTReqMan.h" /* @@@ Should be removed */
2.22 frystyk 16: #include "HTInit.h" /* Implemented here */
2.1 timbl 17:
2.29 frystyk 18: /* ------------------------------------------------------------------------- */
19:
2.23 frystyk 20: /* BINDINGS BETWEEN A SOURCE MEDIA TYPE AND A DEST MEDIA TYPE (CONVERSION)
21: ** ----------------------------------------------------------------------
2.47 frystyk 22: ** Not done automaticly - may be done by application!
2.23 frystyk 23: */
2.38 frystyk 24: PUBLIC void HTConverterInit (HTList * c)
2.23 frystyk 25: {
2.31 frystyk 26: /*
2.49 frystyk 27: ** You can get debug information out through the debug stream if you set
28: ** the debug format appropriately
29: */
30: HTConversion_add(c,"*/*", "www/debug", HTBlackHoleConverter, 1.0, 0.0, 0.0);
31:
32: /*
2.31 frystyk 33: ** These are converters that converts to something other than www/present,
34: ** that is not directly outputting someting to the user on the screen
35: */
2.43 frystyk 36: HTConversion_add(c,"message/rfc822", "*/*", HTMIMEConvert, 1.0, 0.0, 0.0);
2.55 frystyk 37: HTConversion_add(c,"message/x-rfc822-foot", "*/*", HTMIMEFooter, 1.0, 0.0, 0.0);
2.43 frystyk 38: HTConversion_add(c,"multipart/*", "*/*", HTBoundary, 1.0, 0.0, 0.0);
2.38 frystyk 39: HTConversion_add(c,"text/plain", "text/html", HTPlainToHTML, 1.0, 0.0, 0.0);
2.39 frystyk 40:
41: /*
42: ** The following conversions are converting ASCII output from various
43: ** protocols to HTML objects.
44: */
2.51 frystyk 45: HTConversion_add(c,"text/x-http", "*/*", HTTPStatus_new, 1.0, 0.0, 0.0);
2.42 frystyk 46: #if 0
47: HTConversion_add(c,"text/x-gopher", "www/present", HTGopherMenu, 1.0, 0.0, 0.0);
48: HTConversion_add(c,"text/x-cso", "www/present", HTGopherCSO, 1.0, 0.0, 0.0);
2.48 frystyk 49: HTConversion_add(c,"text/x-nntp-list", "*/*", HTNewsList, 1.0, 0.0, 0.0);
50: HTConversion_add(c,"text/x-nntp-over", "*/*", HTNewsGroup, 1.0, 0.0, 0.0);
51: HTConversion_add(c,"text/x-wais-source", "*/*", HTWSRCConvert, 1.0, 0.0, 0.0);
2.53 frystyk 52: #endif
2.43 frystyk 53:
2.31 frystyk 54: /*
2.45 frystyk 55: ** We also register a special content type guess stream that can figure out
56: ** the content type by reading the first bytes of the stream
57: */
58: HTConversion_add(c,"www/unknown", "*/*", HTGuess_new, 1.0, 0.0, 0.0);
2.46 frystyk 59:
60: /*
61: ** Handling Rule files is handled just like any other stream
62: ** This converter reads a rule file and generates the rules
63: */
2.48 frystyk 64: HTConversion_add(c,"application/x-www-rules","*/*", HTRules, 1.0, 0.0, 0.0);
2.46 frystyk 65:
2.45 frystyk 66: /*
2.34 frystyk 67: ** This dumps all other formats to local disk without any further
2.31 frystyk 68: ** action taken
69: */
2.38 frystyk 70: HTConversion_add(c,"*/*", "www/present", HTSaveLocally, 0.3, 0.0, 0.0);
2.23 frystyk 71: }
72:
73: /* BINDINGS BETWEEN MEDIA TYPES AND EXTERNAL VIEWERS/PRESENTERS
74: ** ------------------------------------------------------------
2.47 frystyk 75: ** Not done automaticly - may be done by application!
2.23 frystyk 76: ** The data objects are stored in temporary files before the external
77: ** program is called
78: */
2.38 frystyk 79: PUBLIC void HTPresenterInit (HTList * c)
2.1 timbl 80: {
81: #ifdef NeXT
2.38 frystyk 82: HTPresentation_add(c,"application/postscript", "open %s", NULL, 1.0, 2.0, 0.0);
2.10 luotonen 83: /* The following needs the GIF previewer -- you might not have it. */
2.19 howcome 84:
2.38 frystyk 85: HTPresentation_add(c,"image/gif", "open %s", NULL, 0.3, 2.0, 0.0);
2.44 frystyk 86: HTPresentation_add(c,"image/tiff", "open %s", NULL, 1.0, 2.0, 0.0);
2.41 frystyk 87: HTPresentation_add(c,"audio/basic", "open %s", NULL, 1.0, 2.0, 0.0);
88: HTPresentation_add(c,"*/*", "open %s", NULL, 0.05, 0.0, 0.0);
2.1 timbl 89: #else
2.10 luotonen 90: if (getenv("DISPLAY")) { /* Must have X11 */
2.38 frystyk 91: HTPresentation_add(c,"application/postscript", "ghostview %s", NULL, 1.0, 3.0, 0.0);
2.41 frystyk 92: HTPresentation_add(c,"image/gif", "xv %s", NULL, 1.0, 3.0, 0.0);
2.44 frystyk 93: HTPresentation_add(c,"image/tiff", "xv %s", NULL, 1.0, 3.0, 0.0);
2.38 frystyk 94: HTPresentation_add(c,"image/jpeg", "xv %s", NULL, 1.0, 3.0, 0.0);
2.44 frystyk 95: HTPresentation_add(c,"image/png", "xv %s", NULL, 1.0, 3.0, 0.0);
2.10 luotonen 96: }
2.1 timbl 97: #endif
2.15 frystyk 98: }
99:
100:
2.23 frystyk 101: /* PRESENTERS AND CONVERTERS AT THE SAME TIME
102: ** ------------------------------------------
2.47 frystyk 103: ** Not done automaticly - may be done by application!
2.23 frystyk 104: ** This function is only defined in order to preserve backward
105: ** compatibility.
106: */
2.38 frystyk 107: PUBLIC void HTFormatInit (HTList * c)
2.15 frystyk 108: {
2.23 frystyk 109: HTConverterInit(c);
110: HTPresenterInit(c);
111:
2.1 timbl 112: }
113:
2.55 frystyk 114: /* BINDINGS BETWEEN A ENCODING AND CODERS / DECODERS
115: ** --------------------------- ---------------------
116: ** Not done automaticly - may be done by application!
117: */
118: PUBLIC void HTEncoderInit (HTList * c)
119: {
120: HTCoding_add(c, "chunked", NULL, HTChunkedDecoder, 1.0);
121: }
2.47 frystyk 122:
123: /* REGISTER CALLBACKS FOR THE NET MANAGER
124: ** --------------------------------------
125: ** We register two often used callback functions:
126: ** a BEFORE and a AFTER callback
127: ** Not done automaticly - may be done by application!
128: */
129: PUBLIC void HTNetInit (void)
130: {
2.54 frystyk 131: HTNetCall_addBefore(HTLoadStart, NULL, 0);
132: HTNetCall_addAfter(HTLoadTerminate, NULL, HT_ALL);
2.47 frystyk 133: }
134:
135:
136: /* REGISTER CALLBACKS FOR THE ALERT MANAGER
137: ** ----------------------------------------
138: ** We register a set of alert messages
139: ** Not done automaticly - may be done by application!
140: */
141: PUBLIC void HTAlertInit (void)
142: {
143: HTAlert_add(HTProgress, HT_A_PROGRESS);
144: HTAlert_add(HTError_print, HT_A_MESSAGE);
145: HTAlert_add(HTConfirm, HT_A_CONFIRM);
146: HTAlert_add(HTPrompt, HT_A_PROMPT);
147: HTAlert_add(HTPromptPassword, HT_A_SECRET);
148: HTAlert_add(HTPromptUsernameAndPassword, HT_A_USER_PW);
149: }
150:
2.53 frystyk 151: /* REGISTER ALL KNOWN TRANSPORTS IN THE LIBRARY
152: ** --------------------------------------------
153: ** Not done automaticly - may be done by application!
154: */
155: PUBLIC void HTTransportInit (void)
156: {
2.54 frystyk 157: HTTransport_add("tcp", HT_CH_SINGLE, HTReader_new, HTWriter_new);
158: HTTransport_add("buffered_tcp", HT_CH_SINGLE, HTReader_new, HTBufferWriter_new);
159: #ifndef NO_UNIX_IO
160: HTTransport_add("local", HT_CH_SINGLE, HTReader_new, HTWriter_new);
161: #else
162: HTTransport_add("local", HT_CH_SINGLE, HTANSIReader_new, HTANSIWriter_new);
163: #endif
2.53 frystyk 164: }
2.47 frystyk 165:
2.24 frystyk 166: /* REGISTER ALL KNOWN PROTOCOLS IN THE LIBRARY
167: ** -------------------------------------------
2.47 frystyk 168: ** Not done automaticly - may be done by application!
2.24 frystyk 169: */
2.33 frystyk 170: PUBLIC void HTAccessInit (void)
2.24 frystyk 171: {
172: #ifndef DECNET
2.53 frystyk 173: HTProtocol_add("ftp", "tcp", NO, HTLoadFTP, NULL);
174: HTProtocol_add("nntp", "tcp", NO, HTLoadNews, NULL);
175: HTProtocol_add("news", "tcp", NO, HTLoadNews, NULL);
176: HTProtocol_add("gopher", "tcp", NO, HTLoadGopher, NULL);
2.24 frystyk 177: #ifdef HT_DIRECT_WAIS
2.53 frystyk 178: HTProtocol_add("wais", "", YES, HTLoadWAIS, NULL);
2.24 frystyk 179: #endif
180: #endif /* DECNET */
181:
2.54 frystyk 182: HTProtocol_add("http", "buffered_tcp", NO, HTLoadHTTP, NULL);
2.53 frystyk 183: HTProtocol_add("file", "local", NO, HTLoadFile, NULL);
184: HTProtocol_add("telnet", "", YES, HTLoadTelnet, NULL);
185: HTProtocol_add("tn3270", "", YES, HTLoadTelnet, NULL);
186: HTProtocol_add("rlogin", "", YES, HTLoadTelnet, NULL);
2.24 frystyk 187: }
2.1 timbl 188:
2.48 frystyk 189: #if 0
190: /* BINDINGS BETWEEN ICONS AND MEDIA TYPES
191: ** --------------------------------------
192: ** Not done automaticly - may be done by application!
193: ** For directory listings etc. you can bind a set of icons to a set of
194: ** media types and special icons for directories and other objects that
195: ** do not have a media type.
196: */
2.52 frystyk 197: /* PUBLIC void HTStdIconInit (const char * url_prefix) */
2.48 frystyk 198: {
2.52 frystyk 199: const char * p = url_prefix ? url_prefix : "/internal-icon/";
2.48 frystyk 200:
201: HTAddBlankIcon (prefixed(p,"blank.xbm"), NULL );
202: HTAddDirIcon (prefixed(p,"directory.xbm"),"DIR" );
203: HTAddParentIcon (prefixed(p,"back.xbm"), "UP" );
204: HTAddUnknownIcon(prefixed(p,"unknown.xbm"), NULL );
205: HTAddIcon(prefixed(p,"unknown.xbm"), NULL, "*/*");
206: HTAddIcon(prefixed(p,"binary.xbm"), "BIN", "binary");
207: HTAddIcon(prefixed(p,"unknown.xbm"), NULL, "www/unknown");
208: HTAddIcon(prefixed(p,"text.xbm"), "TXT", "text/*");
209: HTAddIcon(prefixed(p,"image.xbm"), "IMG", "image/*");
210: HTAddIcon(prefixed(p,"movie.xbm"), "MOV", "video/*");
211: HTAddIcon(prefixed(p,"sound.xbm"), "AU", "audio/*");
212: HTAddIcon(prefixed(p,"tar.xbm"), "TAR", "multipart/x-tar");
213: HTAddIcon(prefixed(p,"tar.xbm"), "TAR", "multipart/x-gtar");
214: HTAddIcon(prefixed(p,"compressed.xbm"), "CMP", "x-compress");
215: HTAddIcon(prefixed(p,"compressed.xbm"), "GZP", "x-gzip");
216: HTAddIcon(prefixed(p,"index.xbm"), "IDX", "application/x-gopher-index");
217: HTAddIcon(prefixed(p,"index2.xbm"), "CSO", "application/x-gopher-cso");
218: HTAddIcon(prefixed(p,"telnet.xbm"), "TEL", "application/x-gopher-telnet");
219: HTAddIcon(prefixed(p,"unknown.xbm"), "DUP", "application/x-gopher-duplicate");
220: HTAddIcon(prefixed(p,"unknown.xbm"), "TN", "application/x-gopher-tn3270");
221: }
222: #endif
2.57 eric 223:
2.58 eric 224: /* standard MIME parsers
225: */
226: PRIVATE int allow (HTRequest * request, char * token, char * value)
227: {
228: char * field;
229: HTParentAnchor * anchor = HTRequest_anchor(request);
230: while ((field = HTNextField(&value)) != NULL) {
231: HTMethod new_method;
232: /* We treat them as case-insensitive! */
233: if ((new_method = HTMethod_enum(field)) != METHOD_INVALID)
234: HTAnchor_appendMethods(anchor, new_method);
235: }
236: if (STREAM_TRACE)
237: HTTrace("MIMEParser.. Methods allowed: %d\n",
238: HTAnchor_methods(anchor));
239: return HT_OK;
240: }
241:
242: PRIVATE int authenticate (HTRequest * request, char * token, char * value)
243: {
244: if (!request->challenge) request->challenge = HTAssocList_new();
245:
246: StrAllocCopy(request->scheme, "basic"); /* @@@@@@@@@ */
247:
248: HTAssocList_add(request->challenge, "WWW-authenticate", value);
249: return HT_OK;
250: }
251:
252: PRIVATE int connection (HTRequest * request, char * token, char * value)
253: {
254: char * field;
255: if ((field = HTNextField(&value)) != NULL) {
256: if (!strcasecomp(field, "keep-alive")) {
257: HTNet_setPersistent(request->net, YES);
258: if (STREAM_TRACE) HTTrace("MIMEParser.. Persistent Connection\n");
259: }
260: }
261: return HT_OK;
262: }
263:
264: PRIVATE int content_encoding (HTRequest * request, char * token, char * value)
265: {
266: char * field;
267: HTParentAnchor * anchor = HTRequest_anchor(request);
268: while ((field = HTNextField(&value)) != NULL) {
269: char * lc = field;
270: while ((*lc = TOLOWER(*lc))) lc++;
271: HTAnchor_addEncoding(anchor, HTAtom_for(field));
272: }
273: return HT_OK;
274: }
275:
276: PRIVATE int content_language (HTRequest * request, char * token, char * value)
277: {
278: char * field;
279: HTParentAnchor * anchor = HTRequest_anchor(request);
280: while ((field = HTNextField(&value)) != NULL) {
281: char * lc = field;
282: while ((*lc = TOLOWER(*lc))) lc++;
283: HTAnchor_addLanguage(anchor, HTAtom_for(field));
284: }
285: return HT_OK;
286: }
287:
288: PRIVATE int content_length (HTRequest * request, char * token, char * value)
289: {
290: char * field;
291: HTParentAnchor * anchor = HTRequest_anchor(request);
292: if ((field = HTNextField(&value)) != NULL)
293: HTAnchor_setLength(anchor, atol(field));
294: return HT_OK;
295: }
296:
297: PRIVATE int content_transfer_encoding (HTRequest * request, char * token, char * value)
298: {
299: char * field;
300: HTParentAnchor * anchor = HTRequest_anchor(request);
301: if ((field = HTNextField(&value)) != NULL) {
302: char *lc = field;
303: while ((*lc = TOLOWER(*lc))) lc++;
304: HTAnchor_setTransfer(anchor, HTAtom_for(field));
305: }
306: return HT_OK;
307: }
308:
309: PRIVATE int content_type (HTRequest * request, char * token, char * value)
310: {
311: char * field;
312: HTParentAnchor * anchor = HTRequest_anchor(request);
313: if ((field = HTNextField(&value)) != NULL) {
314: char *lc = field;
315: while ((*lc = TOLOWER(*lc))) lc++;
316: HTAnchor_setFormat(anchor, HTAtom_for(field));
317: while ((field = HTNextField(&value)) != NULL) {
318: if (!strcasecomp(field, "charset")) {
319: if ((field = HTNextField(&value)) != NULL) {
320: lc = field;
321: while ((*lc = TOLOWER(*lc))) lc++;
322: HTAnchor_setCharset(anchor, HTAtom_for(field));
323: }
324: } else if (!strcasecomp(field, "level")) {
325: if ((field = HTNextField(&value)) != NULL) {
326: lc = field;
327: while ((*lc = TOLOWER(*lc))) lc++;
328: HTAnchor_setLevel(anchor, HTAtom_for(field));
329: }
330: } else if (!strcasecomp(field, "boundary")) {
331: if ((field = HTNextField(&value)) != NULL) {
332: StrAllocCopy(request->boundary, field);
333: }
334: }
335: }
336: }
337: return HT_OK;
338: }
339:
340: PRIVATE int derived_from (HTRequest * request, char * token, char * value)
341: {
342: char * field;
343: HTParentAnchor * anchor = HTRequest_anchor(request);
344: if ((field = HTNextField(&value)) != NULL)
345: HTAnchor_setDerived(anchor, field);
346: return HT_OK;
347: }
348:
349: PRIVATE int expires (HTRequest * request, char * token, char * value)
350: {
351: HTParentAnchor * anchor = HTRequest_anchor(request);
352: HTAnchor_setExpires(anchor, HTParseTime(value,
353: HTRequest_userProfile(request)));
354: return HT_OK;
355: }
356:
357: PRIVATE int last_modified (HTRequest * request, char * token, char * value)
358: {
359: HTParentAnchor * anchor = HTRequest_anchor(request);
360: HTAnchor_setLastModified(anchor, HTParseTime(value,
361: HTRequest_userProfile(request)));
362: return HT_OK;
363: }
364:
365: PRIVATE int location (HTRequest * request, char * token, char * value)
366: {
367: request->redirectionAnchor = HTAnchor_findAddress(HTStrip(value));
368: return HT_OK;
369: }
370:
371: PRIVATE int message_digest (HTRequest * request, char * token, char * value)
372: {
373: if (!request->challenge) request->challenge = HTAssocList_new();
374: HTAssocList_add(request->challenge, "Digest-MessageDigest", value);
375: return HT_OK;
376: }
377:
378: PRIVATE int mime_date (HTRequest * request, char * token, char * value)
379: {
380: HTParentAnchor * anchor = HTRequest_anchor(request);
381: HTAnchor_setDate(anchor, HTParseTime(value,
382: HTRequest_userProfile(request)));
383: return HT_OK;
384: }
385:
386: PRIVATE int newsgroups (HTRequest * request, char * token, char * value)
387: {
388: /* HTRequest_net(request)->nntp = YES; */ /* Due to news brain damage */
389: return HT_OK;
390: }
391:
392: PRIVATE int retry_after (HTRequest * request, char * token, char * value)
393: {
394: request->retry_after = HTParseTime(value,
395: HTRequest_userProfile(request));
396: return HT_OK;
397: }
398:
399: PRIVATE int title (HTRequest * request, char * token, char * value)
400: {
401: char * field;
402: HTParentAnchor * anchor = HTRequest_anchor(request);
403: if ((field = HTNextField(&value)) != NULL)
404: HTAnchor_setTitle(anchor, field);
405: return HT_OK;
406: }
407:
408: PRIVATE int version (HTRequest * request, char * token, char * value)
409: {
410: char * field;
411: HTParentAnchor * anchor = HTRequest_anchor(request);
412: if ((field = HTNextField(&value)) != NULL)
413: HTAnchor_setVersion(anchor, field);
414: return HT_OK;
415: }
416:
417:
2.57 eric 418: /* REGISTER ALL HTTP/1.1 MIME HEADERS
419: ** --------------------------------------------
420: ** Not done automaticly - may be done by application!
421: */
422: PUBLIC void HTMIMEInit()
423: {
424: struct {
425: char * string;
426: HTParserCallback * pHandler;
427: } fixedHandlers[] = {
428: {"allow", &allow},
429: {"accept-language", NULL},
430: {"accept-charset", NULL},
431: {"accept", NULL},
432: {"accept-encoding", NULL},
433: {"connection", &connection},
434: {"content-encoding", &content_encoding},
435: {"content-language", &content_language},
436: {"content-length", &content_length},
437: {"content-transfer-encoding", &content_transfer_encoding},
438: {"content-type", &content_type},
439: {"date", &mime_date},
440: {"derived-from", &derived_from},
441: {"digest-MessageDigest", &message_digest},
442: {"expires", &expires},
443: {"keep-alive", NULL},
444: {"last-modified", &last_modified},
445: /* {"link", &link}, */
446: {"location", &location},
447: {"mime-version", NULL},
448: {"newsgroups", &newsgroups},
449: {"retry-after", &retry_after},
450: {"server", NULL},
451: {"title", &title},
452: {"transfer-encoding", &content_transfer_encoding},
453: /* {"uri", &uri_header}, */
454: {"version", &version},
455: {"www-authenticate", &authenticate},
456: };
457: int i;
458:
459: for (i = 0; i < sizeof(fixedHandlers)/sizeof(fixedHandlers[0]); i++)
460: HTHeader_addParser(fixedHandlers[i].string, NO,
461: fixedHandlers[i].pHandler);
462: }
463:
Webmaster