Annotation of libwww/Library/src/HTInit.c, revision 2.66

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

Webmaster