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