home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / lynx-2.4 / WWW / Library / Implementation / HTFormat.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-28  |  10.6 KB  |  390 lines

  1. /*                                            HTFormat: The format manager in the WWW Library
  2.                             MANAGE DIFFERENT DOCUMENT FORMATS
  3.                                              
  4.    Here we describe the functions of the HTFormat module which handles conversion between
  5.    different data representations.  (In MIME parlance, a representation is known as a
  6.    content-type. In WWW  the term "format" is often used as it is shorter).
  7.    
  8.    This module is implemented by HTFormat.c . This hypertext document is used to generate
  9.    the HTFormat.h include file.  Part of the WWW library .
  10.    
  11. Preamble
  12.  
  13.  */
  14. #ifndef HTFORMAT_H
  15. #define HTFORMAT_H
  16.  
  17. #ifndef HTUTILS_H
  18. #include "HTUtils.h"
  19. #endif /* HTUTILS_H */
  20. #include "HTStream.h"
  21. #include "HTAtom.h"
  22. #include "HTList.h"
  23.  
  24. #ifdef SHORT_NAMES
  25. #define HTOutputSource HTOuSour
  26. #define HTOutputBinary HTOuBina
  27. #endif
  28.  
  29. /*
  30.  
  31. The HTFormat type
  32.  
  33.    We use the HTAtom object for holding representations. This allows faster manipulation
  34.    (comparison and copying) that if we stayed with strings.
  35.    
  36.  */
  37. typedef HTAtom * HTFormat;
  38.                         
  39. /*
  40.  
  41.    These macros (which used to be constants) define some basic internally referenced
  42.    representations.  The www/xxx ones are of course not MIME standard.
  43.    
  44.    www/source  is an output format which leaves the input untouched. It is useful for
  45.    diagnostics, and for users who want to see the original, whatever it is.
  46.    
  47.  */
  48.                         /* Internal ones */
  49. #define WWW_SOURCE HTAtom_for("www/source")     /* Whatever it was originally*/
  50.  
  51. /*
  52.  
  53.    www/present represents the user's perception of the document.  If you convert to
  54.    www/present, you present the material to the user.
  55.    
  56.  */
  57. #define WWW_PRESENT HTAtom_for("www/present")   /* The user's perception */
  58.  
  59. /*
  60.  
  61.    The message/rfc822 format means a MIME message or a plain text message with no MIME
  62.    header. This is what is returned by an HTTP server.
  63.    
  64.  */
  65. #define WWW_MIME HTAtom_for("www/mime")         /* A MIME message */
  66.  
  67. /*
  68.  
  69.    www/print is like www/present except it represents a printed copy.
  70.    
  71.  */
  72. #define WWW_PRINT HTAtom_for("www/print")       /* A printed copy */
  73.  
  74. /*
  75.  
  76.    www/unknown is a really unknown type. Some default action is appropriate.
  77.    
  78.  */
  79. #define WWW_UNKNOWN     HTAtom_for("www/unknown")
  80.  
  81. #ifdef DIRED_SUPPORT
  82. /*
  83.    www/dired signals directory edit mode.
  84. */
  85. #define WWW_DIRED      HTAtom_for("www/dired")
  86. #endif
  87.  
  88. /*
  89.  
  90.    These are regular MIME types.  HTML is assumed to be added by the W3 code.
  91.    application/octet-stream was mistakenly application/binary in earlier libwww versions
  92.    (pre 2.11).
  93.    
  94.  */
  95. #define WWW_PLAINTEXT   HTAtom_for("text/plain")
  96. #define WWW_POSTSCRIPT  HTAtom_for("application/postscript")
  97. #define WWW_RICHTEXT    HTAtom_for("application/rtf")
  98. #define WWW_AUDIO       HTAtom_for("audio/basic")
  99. #define WWW_HTML        HTAtom_for("text/html")
  100. #define WWW_BINARY      HTAtom_for("application/octet-stream")
  101.  
  102. /*
  103.  
  104.    We must include the following file after defining HTFormat, to which it makes
  105.    reference.
  106.    
  107. The HTEncoding type
  108.  
  109.  */
  110. typedef HTAtom* HTEncoding;
  111.  
  112. /*
  113.  
  114.    The following are values for the MIME types:
  115.    
  116.  */
  117. #define WWW_ENC_7BIT            HTAtom_for("7bit")
  118. #define WWW_ENC_8BIT            HTAtom_for("8bit")
  119. #define WWW_ENC_BINARY          HTAtom_for("binary")
  120.  
  121. /*
  122.  
  123.    We also add
  124.    
  125.  */
  126. #define WWW_ENC_COMPRESS        HTAtom_for("compress")
  127.  
  128. #include "HTAnchor.h"
  129.  
  130. /*
  131.  
  132. The HTPresentation and HTConverter types
  133.  
  134.    This HTPresentation structure represents a possible conversion algorithm from one
  135.    format to annother.  It includes a pointer to a conversion routine. The conversion
  136.    routine returns a stream to which data should be fed. See also HTStreamStack which
  137.    scans the list of registered converters and calls one. See the initialisation module
  138.    for a list of conversion routines.
  139.    
  140.  */
  141. typedef struct _HTPresentation HTPresentation;
  142.  
  143. typedef HTStream * HTConverter PARAMS((
  144.         HTPresentation *        pres,
  145.         HTParentAnchor *        anchor,
  146.         HTStream *              sink));
  147.         
  148. struct _HTPresentation {
  149.         HTAtom* rep;            /* representation name atmoized */
  150.         HTAtom* rep_out;        /* resulting representation */
  151.         HTConverter *converter; /* The routine to gen the stream stack */
  152.         char *  command;        /* MIME-format string */
  153.         float   quality;        /* Between 0 (bad) and 1 (good) */
  154.         float   secs;
  155.         float   secs_per_byte;
  156. };
  157.  
  158. /*
  159.  
  160.    The list of presentations is kept by this module.  It is also scanned by modules which
  161.    want to know the set of formats supported. for example.
  162.    
  163.  */
  164. extern HTList * HTPresentations;
  165.  
  166. /*
  167.  
  168.    The default presentation is used when no other is appriporate
  169.    
  170.  */
  171. extern  HTPresentation* default_presentation;
  172.  
  173. /*
  174.  
  175. HTSetPresentation: Register a system command to present a format
  176.  
  177.   ON ENTRY,
  178.   
  179.   rep                     is the MIME - style format name
  180.                          
  181.   command                 is the MAILCAP - style command template
  182.                          
  183.   quality                 A degradation faction 0..1
  184.                          
  185.   maxbytes                A limit on the length acceptable as input (0 infinite)
  186.                          
  187.   maxsecs                 A limit on the time user will wait (0 for infinity)
  188.                          
  189.  */
  190. extern void HTSetPresentation PARAMS((
  191.         CONST char * representation,
  192.         CONST char * command,
  193.         float   quality,
  194.         float   secs,
  195.         float   secs_per_byte
  196. ));
  197.  
  198.  
  199. /*
  200.  
  201. HTSetConversion:   Register a converstion routine
  202.  
  203.   ON ENTRY,
  204.   
  205.   rep_in                  is the content-type input
  206.                          
  207.   rep_out                 is the resulting content-type
  208.                          
  209.   converter               is the routine to make the stream to do it
  210.                          
  211.  */
  212.  
  213. extern void HTSetConversion PARAMS((
  214.         CONST char *    rep_in,
  215.         CONST char *    rep_out,
  216.         HTConverter *   converter,
  217.         float           quality,
  218.         float           secs,
  219.         float           secs_per_byte
  220. ));
  221.  
  222.  
  223. /*
  224.  
  225. HTStreamStack:   Create a stack of streams
  226.  
  227.    This is the routine which actually sets up the conversion. It currently checks only for
  228.    direct conversions, but multi-stage conversions are forseen. It takes a stream into
  229.    which the output should be sent in the final format, builds the conversion stack, and
  230.    returns a stream into which the data in the input format should be fed.  The anchor is
  231.    passed because hypertxet objects load information into the anchor object which
  232.    represents them.
  233.    
  234.  */
  235. extern HTStream * HTStreamStack PARAMS((
  236.         HTFormat                format_in,
  237.         HTFormat                format_out,
  238.         HTStream*               stream_out,
  239.         HTParentAnchor*         anchor));
  240.  
  241. /*
  242.  
  243. HTStackValue: Find the cost of a filter stack
  244.  
  245.    Must return the cost of the same stack which HTStreamStack would set up.
  246.    
  247.   ON ENTRY,
  248.   
  249.   format_in               The fomat of the data to be converted
  250.                          
  251.   format_out              The format required
  252.                          
  253.   initial_value           The intrinsic "value" of the data before conversion on a scale
  254.                          from 0 to 1
  255.                          
  256.   length                  The number of bytes expected in the input format
  257.                          
  258.  */
  259. extern float HTStackValue PARAMS((
  260.         HTFormat                format_in,
  261.         HTFormat                rep_out,
  262.         float                   initial_value,
  263.         long int                length));
  264.  
  265. #define NO_VALUE_FOUND  -1e20           /* returned if none found */
  266.  
  267. /*
  268.  
  269. HTCopy:  Copy a socket to a stream
  270.  
  271.    This is used by the protocol engines to send data down a stream, typically one which
  272.    has been generated by HTStreamStack.
  273.    
  274.  */
  275. extern int HTCopy PARAMS((
  276.         int                     file_number,
  277.         HTStream*               sink));
  278.  
  279.         
  280. /*
  281.  
  282. HTFileCopy:  Copy a file to a stream
  283.  
  284.    This is used by the protocol engines to send data down a stream, typically one which
  285.    has been generated by HTStreamStack. It is currently called by HTParseFile
  286.    
  287.  */
  288. extern void HTFileCopy PARAMS((
  289.         FILE*                   fp,
  290.         HTStream*               sink));
  291.  
  292.         
  293. /*
  294.  
  295. HTCopyNoCR: Copy a socket to a stream, stripping CR characters.
  296.  
  297.    It is slower than HTCopy .
  298.    
  299.  */
  300.  
  301. extern void HTCopyNoCR PARAMS((
  302.         int                     file_number,
  303.         HTStream*               sink));
  304.  
  305.  
  306. /*
  307.  
  308. Clear input buffer and set file number
  309.  
  310.    This routine and the one below provide simple character input from sockets. (They are
  311.    left over from the older architecure and may not be used very much.)  The existence of
  312.    a common routine and buffer saves memory space in small implementations.
  313.    
  314.  */
  315. extern void HTInitInput PARAMS((int file_number));
  316.  
  317. /*
  318.  
  319. Get next character from buffer
  320.  
  321.  */
  322. extern char HTGetCharacter NOPARAMS;
  323.  
  324.  
  325. /*
  326.  
  327. HTParseSocket: Parse a socket given its format
  328.  
  329.    This routine is called by protocol modules to load an object.  uses HTStreamStack and
  330.    the copy routines above.  Returns HT_LOADED if succesful, <0 if not.
  331.    
  332.  */
  333. extern int HTParseSocket PARAMS((
  334.         HTFormat        format_in,
  335.         HTFormat        format_out,
  336.         HTParentAnchor  *anchor,
  337.         int             file_number,
  338.         HTStream*       sink));
  339.  
  340. /*
  341.  
  342. HTParseFile: Parse a File through a file pointer
  343.  
  344.    This routine is called by protocols modules to load an object. uses HTStreamStack and
  345.    HTFileCopy .  Returns HT_LOADED if succesful, <0 if not.
  346.    
  347.  */
  348. extern int HTParseFile PARAMS((
  349.         HTFormat        format_in,
  350.         HTFormat        format_out,
  351.         HTParentAnchor  *anchor,
  352.         FILE            *fp,
  353.         HTStream*       sink));
  354.  
  355. /*
  356.  
  357. HTNetToText: Convert Net ASCII to local representation
  358.  
  359.    This is a filter stream suitable for taking text from a socket and passing it into a
  360.    stream which expects text in the local C representation. It does ASCII and newline
  361.    conversion. As usual, pass its output stream to it when creating it.
  362.    
  363.  */
  364. extern HTStream *  HTNetToText PARAMS ((HTStream * sink));
  365.  
  366. /*
  367.  
  368. HTFormatInit: Set up default presentations and conversions
  369.  
  370.    These are defined in HTInit.c or HTSInit.c if these have been replaced. If you don't
  371.    call this routine, and you don't define any presentations, then this routine will
  372.    automatically be called the first time a conversion is needed. However, if you
  373.    explicitly add some conversions (eg using HTLoadRules) then you may want also to
  374.    explicitly call this to get the defaults as well.
  375.    
  376.  */
  377. extern void HTFormatInit NOPARAMS;
  378.  
  379. /*
  380.  
  381. Epilogue
  382.  
  383.  */
  384. extern BOOL HTOutputSource;     /* Flag: shortcut parser */
  385. #endif
  386.  
  387. /*
  388.  
  389.    end */
  390.