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

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

Webmaster