HTInit.c
上传用户:zlh9724
上传日期:2007-01-04
资源大小:1991k
文件大小:8k
源码类别:

浏览器

开发平台:

Unix_Linux

  1. /*        HTInit.c
  2. ** CONFIGURATION-SPECIFIC INITIALIALIZATION
  3. **
  4. ** (c) COPYRIGHT MIT 1995.
  5. ** Please first read the full copyright statement in the file COPYRIGH.
  6. **
  7. ** Define a basic set of suffixes and presentations
  8. */
  9. /* Library include files */
  10. #include "tcp.h"
  11. #include "HTUtils.h"
  12. #include "HTFormat.h"
  13. #include "HTList.h"
  14. #include "HTProt.h"
  15. #include "HTInit.h"          /* Implemented here */
  16. /* ------------------------------------------------------------------------- */
  17. /* BINDINGS BETWEEN A SOURCE MEDIA TYPE AND A DEST MEDIA TYPE (CONVERSION)
  18. ** ----------------------------------------------------------------------
  19. ** Not done automaticly - may be done by application!
  20. */
  21. PUBLIC void HTConverterInit (HTList * c)
  22. {
  23.     /*
  24.     ** This set of converters uses the HTML/HText interface.
  25.     ** If you do not want this interface then replace them!
  26.     */
  27.     HTConversion_add(c,"text/html", "www/present", HTMLPresent, 1.0, 0.0, 0.0);
  28.     HTConversion_add(c,"text/plain", "www/present", HTPlainPresent, 1.0, 0.0, 0.0);
  29.     HTConversion_add(c,"text/html", "text/x-c", HTMLToC, 0.5, 0.0, 0.0);
  30.     HTConversion_add(c,"text/html", "text/plain", HTMLToPlain, 0.5, 0.0, 0.0);
  31.     HTConversion_add(c,"text/html",         "text/latex", HTMLToTeX, 1.0, 0.0, 0.0);
  32.     /*
  33.     ** You can get debug information out through the debug stream if you set
  34.     ** the debug format appropriately
  35.     */
  36.     HTConversion_add(c,"*/*", "www/debug", HTBlackHoleConverter, 1.0, 0.0, 0.0);
  37.     /*
  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.     */
  41.     HTConversion_add(c,"message/rfc822", "*/*", HTMIMEConvert, 1.0, 0.0, 0.0);
  42.     HTConversion_add(c,"multipart/*", "*/*", HTBoundary, 1.0, 0.0, 0.0);
  43.     HTConversion_add(c,"text/plain", "text/html", HTPlainToHTML, 1.0, 0.0, 0.0);
  44.     /*
  45.     ** The following conversions are converting ASCII output from various
  46.     ** protocols to HTML objects.
  47.     */
  48.     HTConversion_add(c,"text/x-http", "*/*", HTTPStatus_new, 1.0, 0.0, 0.0);
  49. #if 0
  50.     HTConversion_add(c,"text/x-gopher", "www/present", HTGopherMenu, 1.0, 0.0, 0.0);
  51.     HTConversion_add(c,"text/x-cso", "www/present", HTGopherCSO, 1.0, 0.0, 0.0);
  52. #endif
  53.     HTConversion_add(c,"text/x-nntp-list", "*/*", HTNewsList, 1.0, 0.0, 0.0);
  54.     HTConversion_add(c,"text/x-nntp-over", "*/*", HTNewsGroup, 1.0, 0.0, 0.0);
  55.     HTConversion_add(c,"text/x-wais-source", "*/*", HTWSRCConvert,  1.0, 0.0, 0.0);
  56.     /*
  57.     ** We also register a special content type guess stream that can figure out
  58.     ** the content type by reading the first bytes of the stream
  59.     */
  60.     HTConversion_add(c,"www/unknown", "*/*", HTGuess_new, 1.0, 0.0, 0.0);
  61.     /*
  62.     ** Handling Rule files is handled just like any other stream
  63.     ** This converter reads a rule file and generates the rules
  64.     */
  65.     HTConversion_add(c,"application/x-www-rules","*/*", HTRules, 1.0, 0.0, 0.0);
  66.     /*
  67.     ** This dumps all other formats to local disk without any further
  68.     ** action taken
  69.     */
  70.     HTConversion_add(c,"*/*", "www/present", HTSaveLocally, 0.3, 0.0, 0.0);
  71. }
  72. /* BINDINGS BETWEEN MEDIA TYPES AND EXTERNAL VIEWERS/PRESENTERS
  73. ** ------------------------------------------------------------
  74. ** Not done automaticly - may be done by application!
  75. ** The data objects are stored in temporary files before the external
  76. ** program is called
  77. */
  78. PUBLIC void HTPresenterInit (HTList * c)
  79. {
  80. #ifdef NeXT
  81.     HTPresentation_add(c,"application/postscript", "open %s", NULL, 1.0, 2.0, 0.0);
  82.     /* The following needs the GIF previewer -- you might not have it. */
  83.     HTPresentation_add(c,"image/gif",  "open %s",  NULL, 0.3, 2.0, 0.0);
  84.     HTPresentation_add(c,"image/tiff",  "open %s",  NULL, 1.0, 2.0, 0.0);
  85.     HTPresentation_add(c,"audio/basic",  "open %s",  NULL, 1.0, 2.0, 0.0);
  86.     HTPresentation_add(c,"*/*",  "open %s",  NULL, 0.05, 0.0, 0.0); 
  87. #else
  88.     if (getenv("DISPLAY")) { /* Must have X11 */
  89. HTPresentation_add(c,"application/postscript", "ghostview %s", NULL, 1.0, 3.0, 0.0);
  90. HTPresentation_add(c,"image/gif",  "xv %s", NULL, 1.0, 3.0, 0.0);
  91. HTPresentation_add(c,"image/tiff",  "xv %s", NULL, 1.0, 3.0, 0.0);
  92. HTPresentation_add(c,"image/jpeg",  "xv %s", NULL, 1.0, 3.0, 0.0);
  93.   HTPresentation_add(c,"image/png", "xv %s", NULL, 1.0, 3.0, 0.0);
  94.     }
  95. #endif
  96. }
  97. /* PRESENTERS AND CONVERTERS AT THE SAME TIME
  98. ** ------------------------------------------
  99. ** Not done automaticly - may be done by application!
  100. ** This function is only defined in order to preserve backward
  101. ** compatibility.
  102. */
  103. PUBLIC void HTFormatInit (HTList * c)
  104. {
  105.     HTConverterInit(c);
  106.     HTPresenterInit(c);
  107. }
  108. /* REGISTER CALLBACKS FOR THE NET MANAGER
  109. ** --------------------------------------
  110. ** We register two often used callback functions:
  111. ** a BEFORE and a AFTER callback
  112. ** Not done automaticly - may be done by application!
  113. */
  114. PUBLIC void HTNetInit (void)
  115. {
  116.     HTNetCall_addBefore(HTLoadStart, 0);
  117.     HTNetCall_addAfter(HTLoadTerminate, HT_ALL);
  118. }
  119. /* REGISTER CALLBACKS FOR THE ALERT MANAGER
  120. ** ----------------------------------------
  121. ** We register a set of alert messages
  122. ** Not done automaticly - may be done by application!
  123. */
  124. PUBLIC void HTAlertInit (void)
  125. {
  126.     HTAlert_add(HTProgress, HT_A_PROGRESS);
  127.     HTAlert_add(HTError_print, HT_A_MESSAGE);
  128.     HTAlert_add(HTConfirm, HT_A_CONFIRM);
  129.     HTAlert_add(HTPrompt, HT_A_PROMPT);
  130.     HTAlert_add(HTPromptPassword, HT_A_SECRET);
  131.     HTAlert_add(HTPromptUsernameAndPassword, HT_A_USER_PW);
  132. }
  133. /* REGISTER ALL KNOWN PROTOCOLS IN THE LIBRARY
  134. ** -------------------------------------------
  135. ** Not done automaticly - may be done by application!
  136. */
  137. PUBLIC void HTAccessInit (void)
  138. {
  139. #ifndef DECNET
  140.     HTProtocol_add("ftp", NO, HTLoadFTP, NULL);
  141.     HTProtocol_add("nntp", NO, HTLoadNews, NULL);
  142.     HTProtocol_add("news", NO, HTLoadNews, NULL);
  143.     HTProtocol_add("gopher", NO, HTLoadGopher, NULL);
  144. #ifdef HT_DIRECT_WAIS
  145.     HTProtocol_add("wais", YES, HTLoadWAIS, NULL);
  146. #endif
  147. #endif /* DECNET */
  148.     HTProtocol_add("http", NO, HTLoadHTTP, NULL);
  149.     HTProtocol_add("file", NO, HTLoadFile, NULL);
  150.     HTProtocol_add("telnet", YES, HTLoadTelnet, NULL);
  151.     HTProtocol_add("tn3270", YES, HTLoadTelnet, NULL);
  152.     HTProtocol_add("rlogin", YES, HTLoadTelnet, NULL);
  153. }
  154. #if 0
  155. /* BINDINGS BETWEEN ICONS AND MEDIA TYPES
  156. ** --------------------------------------
  157. ** Not done automaticly - may be done by application!
  158. ** For directory listings etc. you can bind a set of icons to a set of
  159. ** media types and special icons for directories and other objects that
  160. ** do not have a media type.
  161. */
  162. /* PUBLIC void HTStdIconInit (CONST char * url_prefix) */
  163. {
  164.     CONST char * p = url_prefix ? url_prefix : "/internal-icon/";
  165.     HTAddBlankIcon  (prefixed(p,"blank.xbm"), NULL );
  166.     HTAddDirIcon    (prefixed(p,"directory.xbm"),"DIR" );
  167.     HTAddParentIcon (prefixed(p,"back.xbm"), "UP" );
  168.     HTAddUnknownIcon(prefixed(p,"unknown.xbm"), NULL );
  169.     HTAddIcon(prefixed(p,"unknown.xbm"), NULL, "*/*");
  170.     HTAddIcon(prefixed(p,"binary.xbm"), "BIN", "binary");
  171.     HTAddIcon(prefixed(p,"unknown.xbm"), NULL, "www/unknown");
  172.     HTAddIcon(prefixed(p,"text.xbm"), "TXT", "text/*");
  173.     HTAddIcon(prefixed(p,"image.xbm"), "IMG", "image/*");
  174.     HTAddIcon(prefixed(p,"movie.xbm"), "MOV", "video/*");
  175.     HTAddIcon(prefixed(p,"sound.xbm"), "AU", "audio/*");
  176.     HTAddIcon(prefixed(p,"tar.xbm"), "TAR", "multipart/x-tar");
  177.     HTAddIcon(prefixed(p,"tar.xbm"), "TAR", "multipart/x-gtar");
  178.     HTAddIcon(prefixed(p,"compressed.xbm"), "CMP", "x-compress");
  179.     HTAddIcon(prefixed(p,"compressed.xbm"), "GZP", "x-gzip");
  180.     HTAddIcon(prefixed(p,"index.xbm"), "IDX", "application/x-gopher-index");
  181.     HTAddIcon(prefixed(p,"index2.xbm"), "CSO", "application/x-gopher-cso");
  182.     HTAddIcon(prefixed(p,"telnet.xbm"), "TEL", "application/x-gopher-telnet");
  183.     HTAddIcon(prefixed(p,"unknown.xbm"),        "DUP", "application/x-gopher-duplicate");
  184.     HTAddIcon(prefixed(p,"unknown.xbm"), "TN", "application/x-gopher-tn3270");
  185. }
  186. #endif