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

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.57    ! eric        6: **     @(#) $Id: HTInit.c,v 2.56 1996/05/16 19:03:05 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.22      frystyk    13: #include "HTUtils.h"
2.24      frystyk    14: #include "HTFormat.h"
                     15: #include "HTList.h"
2.28      frystyk    16: #include "HTProt.h"
2.57    ! eric       17: #include "HTReqMan.h"
2.22      frystyk    18: #include "HTInit.h"                                     /* Implemented here */
2.1       timbl      19: 
2.29      frystyk    20: /* ------------------------------------------------------------------------- */
                     21: 
2.23      frystyk    22: /*     BINDINGS BETWEEN A SOURCE MEDIA TYPE AND A DEST MEDIA TYPE (CONVERSION)
                     23: **     ----------------------------------------------------------------------
2.47      frystyk    24: **     Not done automaticly - may be done by application!
2.23      frystyk    25: */
2.38      frystyk    26: PUBLIC void HTConverterInit (HTList * c)
2.23      frystyk    27: {
2.31      frystyk    28:     /*
                     29:     ** This set of converters uses the HTML/HText interface.
2.34      frystyk    30:     ** If you do not want this interface then replace them!
2.31      frystyk    31:     */
2.38      frystyk    32:     HTConversion_add(c,"text/html",            "www/present",  HTMLPresent,    1.0, 0.0, 0.0);
                     33:     HTConversion_add(c,"text/plain",           "www/present",  HTPlainPresent, 1.0, 0.0, 0.0);
                     34:     HTConversion_add(c,"text/html",            "text/x-c",     HTMLToC,        0.5, 0.0, 0.0);
                     35:     HTConversion_add(c,"text/html",            "text/plain",   HTMLToPlain,    0.5, 0.0, 0.0);
                     36:     HTConversion_add(c,"text/html",            "text/latex",   HTMLToTeX,      1.0, 0.0, 0.0);
2.31      frystyk    37: 
                     38:     /*
2.49      frystyk    39:     ** You can get debug information out through the debug stream if you set
                     40:     ** the debug format appropriately
                     41:     */
                     42:     HTConversion_add(c,"*/*",                  "www/debug",    HTBlackHoleConverter,   1.0, 0.0, 0.0);
                     43: 
                     44:     /*
2.31      frystyk    45:     ** These are converters that converts to something other than www/present,
                     46:     ** that is not directly outputting someting to the user on the screen
                     47:     */
2.43      frystyk    48:     HTConversion_add(c,"message/rfc822",       "*/*",          HTMIMEConvert,  1.0, 0.0, 0.0);
2.55      frystyk    49:     HTConversion_add(c,"message/x-rfc822-foot",        "*/*",          HTMIMEFooter,   1.0, 0.0, 0.0);
2.43      frystyk    50:     HTConversion_add(c,"multipart/*",          "*/*",          HTBoundary,     1.0, 0.0, 0.0);
2.38      frystyk    51:     HTConversion_add(c,"text/plain",           "text/html",    HTPlainToHTML,  1.0, 0.0, 0.0);
2.39      frystyk    52: 
                     53:     /*
                     54:     ** The following conversions are converting ASCII output from various
                     55:     ** protocols to HTML objects.
                     56:     */
2.51      frystyk    57:     HTConversion_add(c,"text/x-http",          "*/*",          HTTPStatus_new, 1.0, 0.0, 0.0);
2.42      frystyk    58: #if 0
                     59:     HTConversion_add(c,"text/x-gopher",                "www/present",  HTGopherMenu,   1.0, 0.0, 0.0);
                     60:     HTConversion_add(c,"text/x-cso",           "www/present",  HTGopherCSO,    1.0, 0.0, 0.0);
2.48      frystyk    61:     HTConversion_add(c,"text/x-nntp-list",     "*/*",          HTNewsList,     1.0, 0.0, 0.0);
                     62:     HTConversion_add(c,"text/x-nntp-over",     "*/*",          HTNewsGroup,    1.0, 0.0, 0.0);
                     63:     HTConversion_add(c,"text/x-wais-source",   "*/*",          HTWSRCConvert,  1.0, 0.0, 0.0);
2.53      frystyk    64: #endif
2.43      frystyk    65: 
2.31      frystyk    66:     /*
2.45      frystyk    67:     ** We also register a special content type guess stream that can figure out
                     68:     ** the content type by reading the first bytes of the stream
                     69:     */
                     70:     HTConversion_add(c,"www/unknown",          "*/*",          HTGuess_new,    1.0, 0.0, 0.0);
2.46      frystyk    71: 
                     72:     /*
                     73:     ** Handling Rule files is handled just like any other stream
                     74:     ** This converter reads a rule file and generates the rules
                     75:     */
2.48      frystyk    76:     HTConversion_add(c,"application/x-www-rules","*/*",                HTRules,        1.0, 0.0, 0.0);
2.46      frystyk    77: 
2.45      frystyk    78:     /*
2.34      frystyk    79:     ** This dumps all other formats to local disk without any further
2.31      frystyk    80:     ** action taken
                     81:     */
2.38      frystyk    82:     HTConversion_add(c,"*/*",                  "www/present",  HTSaveLocally,  0.3, 0.0, 0.0);
2.23      frystyk    83: }
                     84: 
                     85: /*     BINDINGS BETWEEN MEDIA TYPES AND EXTERNAL VIEWERS/PRESENTERS
                     86: **     ------------------------------------------------------------
2.47      frystyk    87: **     Not done automaticly - may be done by application!
2.23      frystyk    88: **     The data objects are stored in temporary files before the external
                     89: **     program is called
                     90: */
2.38      frystyk    91: PUBLIC void HTPresenterInit (HTList * c)
2.1       timbl      92: {
                     93: #ifdef NeXT
2.38      frystyk    94:     HTPresentation_add(c,"application/postscript", "open %s",  NULL, 1.0, 2.0, 0.0);
2.10      luotonen   95:     /* The following needs the GIF previewer -- you might not have it. */
2.19      howcome    96: 
2.38      frystyk    97:     HTPresentation_add(c,"image/gif",          "open %s",      NULL, 0.3, 2.0, 0.0);
2.44      frystyk    98:     HTPresentation_add(c,"image/tiff",         "open %s",      NULL, 1.0, 2.0, 0.0);
2.41      frystyk    99:     HTPresentation_add(c,"audio/basic",        "open %s",      NULL, 1.0, 2.0, 0.0);
                    100:     HTPresentation_add(c,"*/*",                "open %s",      NULL, 0.05, 0.0, 0.0); 
2.1       timbl     101: #else
2.10      luotonen  102:     if (getenv("DISPLAY")) {   /* Must have X11 */
2.38      frystyk   103:        HTPresentation_add(c,"application/postscript", "ghostview %s",  NULL, 1.0, 3.0, 0.0);
2.41      frystyk   104:        HTPresentation_add(c,"image/gif",       "xv %s",        NULL, 1.0, 3.0, 0.0);
2.44      frystyk   105:        HTPresentation_add(c,"image/tiff",      "xv %s",        NULL, 1.0, 3.0, 0.0);
2.38      frystyk   106:        HTPresentation_add(c,"image/jpeg",      "xv %s",        NULL, 1.0, 3.0, 0.0);
2.44      frystyk   107:        HTPresentation_add(c,"image/png",       "xv %s",        NULL, 1.0, 3.0, 0.0);
2.10      luotonen  108:     }
2.1       timbl     109: #endif
2.15      frystyk   110: }
                    111: 
                    112: 
2.23      frystyk   113: /*     PRESENTERS AND CONVERTERS AT THE SAME TIME
                    114: **     ------------------------------------------
2.47      frystyk   115: **     Not done automaticly - may be done by application!
2.23      frystyk   116: **     This function is only defined in order to preserve backward
                    117: **     compatibility.
                    118: */
2.38      frystyk   119: PUBLIC void HTFormatInit (HTList * c)
2.15      frystyk   120: {
2.23      frystyk   121:     HTConverterInit(c);
                    122:     HTPresenterInit(c);
                    123: 
2.1       timbl     124: }
                    125: 
2.55      frystyk   126: /*     BINDINGS BETWEEN A ENCODING AND CODERS / DECODERS
                    127: **     --------------------------- ---------------------
                    128: **     Not done automaticly - may be done by application!
                    129: */
                    130: PUBLIC void HTEncoderInit (HTList * c)
                    131: {
                    132:     HTCoding_add(c, "chunked", NULL, HTChunkedDecoder, 1.0);
                    133: }
2.47      frystyk   134: 
                    135: /*     REGISTER CALLBACKS FOR THE NET MANAGER
                    136: **     --------------------------------------
                    137: **     We register two often used callback functions:
                    138: **     a BEFORE and a AFTER callback
                    139: **     Not done automaticly - may be done by application!
                    140: */
                    141: PUBLIC void HTNetInit (void)
                    142: {
2.54      frystyk   143:     HTNetCall_addBefore(HTLoadStart, NULL, 0);
                    144:     HTNetCall_addAfter(HTLoadTerminate, NULL, HT_ALL);
2.47      frystyk   145: }
                    146: 
                    147: 
                    148: /*     REGISTER CALLBACKS FOR THE ALERT MANAGER
                    149: **     ----------------------------------------
                    150: **     We register a set of alert messages
                    151: **     Not done automaticly - may be done by application!
                    152: */
                    153: PUBLIC void HTAlertInit (void)
                    154: {
                    155:     HTAlert_add(HTProgress, HT_A_PROGRESS);
                    156:     HTAlert_add(HTError_print, HT_A_MESSAGE);
                    157:     HTAlert_add(HTConfirm, HT_A_CONFIRM);
                    158:     HTAlert_add(HTPrompt, HT_A_PROMPT);
                    159:     HTAlert_add(HTPromptPassword, HT_A_SECRET);
                    160:     HTAlert_add(HTPromptUsernameAndPassword, HT_A_USER_PW);
                    161: }
                    162: 
2.53      frystyk   163: /*     REGISTER ALL KNOWN TRANSPORTS IN THE LIBRARY
                    164: **     --------------------------------------------
                    165: **     Not done automaticly - may be done by application!
                    166: */
                    167: PUBLIC void HTTransportInit (void)
                    168: {
2.54      frystyk   169:     HTTransport_add("tcp", HT_CH_SINGLE, HTReader_new, HTWriter_new);
                    170:     HTTransport_add("buffered_tcp", HT_CH_SINGLE, HTReader_new, HTBufferWriter_new);
                    171: #ifndef NO_UNIX_IO
                    172:     HTTransport_add("local", HT_CH_SINGLE, HTReader_new, HTWriter_new);
                    173: #else
                    174:     HTTransport_add("local", HT_CH_SINGLE, HTANSIReader_new, HTANSIWriter_new);
                    175: #endif
2.53      frystyk   176: }
2.47      frystyk   177: 
2.24      frystyk   178: /*     REGISTER ALL KNOWN PROTOCOLS IN THE LIBRARY
                    179: **     -------------------------------------------
2.47      frystyk   180: **     Not done automaticly - may be done by application!
2.24      frystyk   181: */
2.33      frystyk   182: PUBLIC void HTAccessInit (void)
2.24      frystyk   183: {
                    184: #ifndef DECNET
2.53      frystyk   185:     HTProtocol_add("ftp", "tcp", NO, HTLoadFTP, NULL);
                    186:     HTProtocol_add("nntp", "tcp", NO, HTLoadNews, NULL);
                    187:     HTProtocol_add("news", "tcp", NO, HTLoadNews, NULL);
                    188:     HTProtocol_add("gopher", "tcp", NO, HTLoadGopher, NULL);
2.24      frystyk   189: #ifdef HT_DIRECT_WAIS
2.53      frystyk   190:     HTProtocol_add("wais", "", YES, HTLoadWAIS, NULL);
2.24      frystyk   191: #endif
                    192: #endif /* DECNET */
                    193: 
2.54      frystyk   194:     HTProtocol_add("http", "buffered_tcp", NO, HTLoadHTTP, NULL);
2.53      frystyk   195:     HTProtocol_add("file", "local", NO, HTLoadFile, NULL);
                    196:     HTProtocol_add("telnet", "", YES, HTLoadTelnet, NULL);
                    197:     HTProtocol_add("tn3270", "", YES, HTLoadTelnet, NULL);
                    198:     HTProtocol_add("rlogin", "", YES, HTLoadTelnet, NULL);
2.56      frystyk   199: }
                    200: 
                    201: /*     REGISTER DEFULT EVENT MANAGER
                    202: **     -----------------------------
                    203: **     Not done automaticly - may be done by application!
                    204: */
                    205: PUBLIC void HTEventInit (void)
                    206: {
                    207:     HTEvent_setRegisterCallback(HTEventrg_register);
                    208:     HTEvent_setUnregisterCallback(HTEventrg_unregister);
2.24      frystyk   209: }
2.1       timbl     210: 
2.48      frystyk   211: #if 0
                    212: /*     BINDINGS BETWEEN ICONS AND MEDIA TYPES
                    213: **     --------------------------------------
                    214: **     Not done automaticly - may be done by application!
                    215: **     For directory listings etc. you can bind a set of icons to a set of
                    216: **     media types and special icons for directories and other objects that
                    217: **     do not have a media type.
                    218: */
2.52      frystyk   219: /* PUBLIC void HTStdIconInit (const char * url_prefix) */
2.48      frystyk   220: {
2.52      frystyk   221:     const char * p = url_prefix ? url_prefix : "/internal-icon/";
2.48      frystyk   222: 
                    223:     HTAddBlankIcon  (prefixed(p,"blank.xbm"),  NULL    );
                    224:     HTAddDirIcon    (prefixed(p,"directory.xbm"),"DIR" );
                    225:     HTAddParentIcon (prefixed(p,"back.xbm"),   "UP"    );
                    226:     HTAddUnknownIcon(prefixed(p,"unknown.xbm"),        NULL    );
                    227:     HTAddIcon(prefixed(p,"unknown.xbm"),       NULL,   "*/*");
                    228:     HTAddIcon(prefixed(p,"binary.xbm"),                "BIN",  "binary");
                    229:     HTAddIcon(prefixed(p,"unknown.xbm"),       NULL,   "www/unknown");
                    230:     HTAddIcon(prefixed(p,"text.xbm"),          "TXT",  "text/*");
                    231:     HTAddIcon(prefixed(p,"image.xbm"),         "IMG",  "image/*");
                    232:     HTAddIcon(prefixed(p,"movie.xbm"),         "MOV",  "video/*");
                    233:     HTAddIcon(prefixed(p,"sound.xbm"),         "AU",   "audio/*");
                    234:     HTAddIcon(prefixed(p,"tar.xbm"),           "TAR",  "multipart/x-tar");
                    235:     HTAddIcon(prefixed(p,"tar.xbm"),           "TAR",  "multipart/x-gtar");
                    236:     HTAddIcon(prefixed(p,"compressed.xbm"),    "CMP",  "x-compress");
                    237:     HTAddIcon(prefixed(p,"compressed.xbm"),    "GZP",  "x-gzip");
                    238:     HTAddIcon(prefixed(p,"index.xbm"),         "IDX",  "application/x-gopher-index");
                    239:     HTAddIcon(prefixed(p,"index2.xbm"),                "CSO",  "application/x-gopher-cso");
                    240:     HTAddIcon(prefixed(p,"telnet.xbm"),                "TEL",  "application/x-gopher-telnet");
                    241:     HTAddIcon(prefixed(p,"unknown.xbm"),               "DUP",  "application/x-gopher-duplicate");
                    242:     HTAddIcon(prefixed(p,"unknown.xbm"),       "TN",   "application/x-gopher-tn3270");
                    243: }
                    244: #endif
2.57    ! eric      245: 
        !           246: /*     REGISTER ALL HTTP/1.1 MIME HEADERS
        !           247: **     --------------------------------------------
        !           248: **     Not done automaticly - may be done by application!
        !           249: */
        !           250: #include "mimeFuncs.c"
        !           251: 
        !           252: PUBLIC void HTMIMEInit()
        !           253: {
        !           254:     struct {
        !           255:         char * string;
        !           256:        HTParserCallback * pHandler;
        !           257:     } fixedHandlers[] = {
        !           258:        {"allow", &allow}, 
        !           259:        {"accept-language", NULL}, 
        !           260:        {"accept-charset", NULL}, 
        !           261:        {"accept", NULL}, 
        !           262:        {"accept-encoding", NULL}, 
        !           263:        {"connection", &connection}, 
        !           264:        {"content-encoding", &content_encoding}, 
        !           265:        {"content-language", &content_language}, 
        !           266:        {"content-length", &content_length}, 
        !           267:        {"content-transfer-encoding", &content_transfer_encoding}, 
        !           268:        {"content-type", &content_type},
        !           269:        {"date", &mime_date}, 
        !           270:        {"derived-from", &derived_from}, 
        !           271:        {"digest-MessageDigest", &message_digest}, 
        !           272:         {"expires", &expires}, 
        !           273:        {"keep-alive", NULL}, 
        !           274:        {"last-modified", &last_modified}, 
        !           275: /*     {"link", &link},  */
        !           276:        {"location", &location}, 
        !           277:        {"mime-version", NULL}, 
        !           278:        {"newsgroups", &newsgroups}, 
        !           279:        {"retry-after", &retry_after}, 
        !           280:        {"server", NULL}, 
        !           281:        {"title", &title}, 
        !           282:        {"transfer-encoding", &content_transfer_encoding}, 
        !           283: /*     {"uri", &uri_header},  */
        !           284:        {"version", &version}, 
        !           285:        {"www-authenticate", &authenticate}, 
        !           286:     };
        !           287:     int i;
        !           288: 
        !           289:     for (i = 0; i < sizeof(fixedHandlers)/sizeof(fixedHandlers[0]); i++)
        !           290:         HTHeader_addParser(fixedHandlers[i].string, NO, 
        !           291:                           fixedHandlers[i].pHandler);
        !           292: }
        !           293: 

Webmaster