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

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.74    ! frystyk     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.74    ! frystyk   147:     HTNet_addBefore(HTMemoryCacheFilter,       NULL,           NULL, HT_FILTER_MIDDLE);
        !           148:     HTNet_addBefore(HTCacheFilter,             "http://*",     NULL, HT_FILTER_MIDDLE);
        !           149:     HTNet_addBefore(HTCredentialsFilter,       "http://*",     NULL, HT_FILTER_LATE);
        !           150:     HTNet_addBefore(HTPEP_beforeFilter,        "http://*",     NULL, HT_FILTER_LATE);
        !           151:     HTNet_addBefore(HTRuleFilter,              NULL,           NULL, HT_FILTER_LATE);
        !           152:     HTNet_addBefore(HTProxyFilter,             NULL,           NULL, HT_FILTER_LATE);
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.74    ! frystyk   164:     HTNet_addAfter(HTAuthFilter,       "http://*",     NULL, HT_NO_ACCESS,     HT_FILTER_MIDDLE);
        !           165:     HTNet_addAfter(HTPEP_afterFilter,  "http://*",     NULL, HT_ALL,           HT_FILTER_MIDDLE);
        !           166:     HTNet_addAfter(HTRedirectFilter,   "http://*",     NULL, HT_TEMP_REDIRECT, HT_FILTER_MIDDLE);
        !           167:     HTNet_addAfter(HTRedirectFilter,   "http://*",     NULL, HT_PERM_REDIRECT, HT_FILTER_MIDDLE);
        !           168:     HTNet_addAfter(HTUseProxyFilter,   "http://*",     NULL, HT_USE_PROXY,     HT_FILTER_MIDDLE);
        !           169:     HTNet_addAfter(HTCacheUpdateFilter, "http://*",    NULL, HT_NOT_MODIFIED,  HT_FILTER_MIDDLE);
        !           170:     HTNet_addAfter(HTLogFilter,        NULL,           NULL, HT_ALL,           HT_FILTER_LATE);
        !           171:     HTNet_addAfter(HTInfoFilter,       NULL,           NULL, HT_ALL,           HT_FILTER_LATE);
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.63      frystyk   229: PUBLIC void HTProtocolInit (void)
2.24      frystyk   230: {
                    231: #ifndef DECNET
2.72      frystyk   232:     HTProtocol_add("ftp",      "tcp",          NO,     HTLoadFTP,      NULL);
                    233:     HTProtocol_add("nntp",     "tcp",          NO,     HTLoadNews,     NULL);
                    234:     HTProtocol_add("news",     "tcp",          NO,     HTLoadNews,     NULL);
                    235:     HTProtocol_add("gopher",   "tcp",          NO,     HTLoadGopher,   NULL);
2.24      frystyk   236: #ifdef HT_DIRECT_WAIS
2.72      frystyk   237:     HTProtocol_add("wais",     "",             YES,    HTLoadWAIS,     NULL);
2.24      frystyk   238: #endif
                    239: #endif /* DECNET */
                    240: 
2.72      frystyk   241:     HTProtocol_add("http",     "buffered_tcp", NO,     HTLoadHTTP,     NULL);
                    242:     HTProtocol_add("file",     "local",        NO,     HTLoadFile,     NULL);
                    243:     HTProtocol_add("cache",    "local",        NO,     HTLoadCache,    NULL);
                    244:     HTProtocol_add("telnet",   "",             YES,    HTLoadTelnet,   NULL);
                    245:     HTProtocol_add("tn3270",   "",             YES,    HTLoadTelnet,   NULL);
                    246:     HTProtocol_add("rlogin",   "",             YES,    HTLoadTelnet,   NULL);
2.24      frystyk   247: }
2.1       timbl     248: 
2.65      frystyk   249: /*     REGISTER ALL KNOWN PROTOCOLS IN THE LIBRARY PREEMPTIVELY
                    250: **     --------------------------------------------------------
                    251: **     Not done automaticly - may be done by application!
                    252: */
                    253: PUBLIC void HTProtocolPreemptiveInit (void)
                    254: {
                    255: #ifndef DECNET
                    256:     HTProtocol_add("ftp", "tcp", YES, HTLoadFTP, NULL);
                    257:     HTProtocol_add("nntp", "tcp", YES, HTLoadNews, NULL);
                    258:     HTProtocol_add("news", "tcp", YES, HTLoadNews, NULL);
                    259:     HTProtocol_add("gopher", "tcp", YES, HTLoadGopher, NULL);
                    260: #ifdef HT_DIRECT_WAIS
                    261:     HTProtocol_add("wais", "", YES, HTLoadWAIS, NULL);
                    262: #endif
                    263: #endif /* DECNET */
                    264: 
                    265:     HTProtocol_add("http", "buffered_tcp", YES, HTLoadHTTP, NULL);
                    266:     HTProtocol_add("file", "local", YES, HTLoadFile, NULL);
                    267:     HTProtocol_add("telnet", "", YES, HTLoadTelnet, NULL);
                    268:     HTProtocol_add("tn3270", "", YES, HTLoadTelnet, NULL);
                    269:     HTProtocol_add("rlogin", "", YES, HTLoadTelnet, NULL);
2.61      frystyk   270: }
                    271: 
2.48      frystyk   272: /*     BINDINGS BETWEEN ICONS AND MEDIA TYPES
                    273: **     --------------------------------------
                    274: **     Not done automaticly - may be done by application!
                    275: **     For directory listings etc. you can bind a set of icons to a set of
                    276: **     media types and special icons for directories and other objects that
                    277: **     do not have a media type.
                    278: */
2.61      frystyk   279: PUBLIC void HTIconInit (const char * url_prefix)
2.58      eric      280: {
2.65      frystyk   281:     const char * prefix = url_prefix ? url_prefix : ICON_LOCATION;
2.58      eric      282: 
2.61      frystyk   283:     HTIcon_addBlank("blank.xbm",       prefix, NULL);
                    284:     HTIcon_addDir("directory.xbm",     prefix, "DIR");
                    285:     HTIcon_addParent("back.xbm",       prefix, "UP");
                    286:     HTIcon_addUnknown("unknown.xbm",   prefix, NULL);
                    287: 
                    288:     HTIcon_add("unknown.xbm",  prefix, NULL,   "*/*");
                    289:     HTIcon_add("binary.xbm",   prefix, "BIN",  "binary");
                    290:     HTIcon_add("unknown.xbm",  prefix, NULL,   "www/unknown");
                    291:     HTIcon_add("text.xbm",     prefix, "TXT",  "text/*");
                    292:     HTIcon_add("image.xbm",    prefix, "IMG",  "image/*");
                    293:     HTIcon_add("movie.xbm",    prefix, "MOV",  "video/*");
                    294:     HTIcon_add("sound.xbm",    prefix, "AU",   "audio/*");
                    295:     HTIcon_add("tar.xbm",      prefix, "TAR",  "multipart/x-tar");
                    296:     HTIcon_add("tar.xbm",      prefix, "TAR",  "multipart/x-gtar");
                    297:     HTIcon_add("compressed.xbm",prefix,        "CMP",  "x-compress");
                    298:     HTIcon_add("compressed.xbm",prefix,        "GZP",  "x-gzip");
                    299:     HTIcon_add("index.xbm",    prefix, "IDX",  "application/x-gopher-index");
                    300:     HTIcon_add("index2.xbm",   prefix, "CSO",  "application/x-gopher-cso");
                    301:     HTIcon_add("telnet.xbm",   prefix, "TEL",  "application/x-gopher-telnet");
                    302:     HTIcon_add("unknown.xbm",  prefix, "DUP",  "application/x-gopher-duplicate");
                    303:     HTIcon_add("unknown.xbm",  prefix, "TN",   "application/x-gopher-tn3270");
2.65      frystyk   304: 
                    305:     /* Add global  mapping to where to find the internal icons */
                    306:     HTRule_addGlobal(HT_Pass, ICON_LOCATION, W3C_ICONS);
2.58      eric      307: }
                    308: 
2.57      eric      309: /*     REGISTER ALL HTTP/1.1 MIME HEADERS
                    310: **     --------------------------------------------
                    311: **     Not done automaticly - may be done by application!
                    312: */
2.64      frystyk   313: PUBLIC void HTMIMEInit (void)
2.57      eric      314: {
                    315:     struct {
                    316:         char * string;
                    317:        HTParserCallback * pHandler;
                    318:     } fixedHandlers[] = {
2.61      frystyk   319:        {"accept", &HTMIME_accept}, 
                    320:        {"accept-charset", &HTMIME_acceptCharset}, 
                    321:        {"accept-encoding", &HTMIME_acceptEncoding}, 
                    322:        {"accept-language", &HTMIME_acceptLanguage}, 
                    323:        {"accept-ranges", &HTMIME_acceptRanges}, 
                    324:        {"authorization", NULL},
2.72      frystyk   325:        {"cache-control", &HTMIME_cacheControl},
2.61      frystyk   326:        {"connection", &HTMIME_connection}, 
                    327:        {"content-encoding", &HTMIME_contentEncoding}, 
                    328:        {"content-length", &HTMIME_contentLength}, 
                    329:        {"content-range", &HTMIME_contentRange},
                    330:        {"content-transfer-encoding", &HTMIME_contentTransferEncoding}, 
                    331:        {"content-type", &HTMIME_contentType},
                    332:        {"digest-MessageDigest", &HTMIME_messageDigest}, 
2.57      eric      333:        {"keep-alive", NULL}, 
2.61      frystyk   334:        {"link", &HTMIME_link},
                    335:        {"location", &HTMIME_location},
                    336:        {"max-forwards", &HTMIME_maxForwards}, 
2.57      eric      337:        {"mime-version", NULL}, 
2.61      frystyk   338:        {"pragma", &HTMIME_pragma},
2.73      frystyk   339:         {"protocol", &HTMIME_protocol},
                    340:         {"protocol-info", &HTMIME_protocolInfo},
                    341:         {"protocol-request", &HTMIME_protocolRequest},
2.66      frystyk   342:        {"proxy-authenticate", &HTMIME_authenticate},
2.61      frystyk   343:        {"proxy-authorization", &HTMIME_proxyAuthorization},
                    344:        {"public", &HTMIME_public},
                    345:        {"range", &HTMIME_range},
                    346:        {"referer", &HTMIME_referer},
                    347:        {"retry-after", &HTMIME_retryAfter}, 
2.62      frystyk   348:        {"server", &HTMIME_server}, 
2.61      frystyk   349:        {"transfer-encoding", &HTMIME_contentTransferEncoding}, 
                    350:        {"upgrade", &HTMIME_upgrade},
                    351:        {"user-agent", &HTMIME_userAgent},
                    352:        {"vary", &HTMIME_vary},
                    353:        {"via", &HTMIME_via},
                    354:        {"warning", &HTMIME_warning},
                    355:        {"www-authenticate", &HTMIME_authenticate}, 
2.57      eric      356:     };
                    357:     int i;
                    358: 
                    359:     for (i = 0; i < sizeof(fixedHandlers)/sizeof(fixedHandlers[0]); i++)
                    360:         HTHeader_addParser(fixedHandlers[i].string, NO, 
                    361:                           fixedHandlers[i].pHandler);
                    362: }
                    363: 

Webmaster