Annotation of libwww/Library/src/HTFormat.html, revision 2.55

2.10      timbl       1: <HTML>
                      2: <HEAD>
2.45      frystyk     3: <TITLE>Format Negotiation Manager</TITLE>
2.55    ! frystyk     4: <!-- Changed by: Henrik Frystyk Nielsen, 15-Nov-1995 -->
2.15      timbl       5: <NEXTID N="z18">
2.10      timbl       6: </HEAD>
2.1       timbl       7: <BODY>
2.27      frystyk     8: 
2.31      frystyk     9: <H1>The Format Manager</H1>
2.33      frystyk    10: 
                     11: <PRE>
                     12: /*
2.41      frystyk    13: **     (c) COPYRIGHT MIT 1995.
2.33      frystyk    14: **     Please first read the full copyright statement in the file COPYRIGH.
                     15: */
                     16: </PRE>
2.31      frystyk    17: 
                     18: Here we describe the functions of the HTFormat module which handles
                     19: conversion between different data representations. (In MIME parlance,
                     20: a representation is known as a content-type. In <A
2.46      frystyk    21: HREF="http://www.w3.org/pub/WWW/TheProject.html">WWW</A> the
2.31      frystyk    22: term <EM>format</EM> is often used as it is shorter). The content of
                     23: this module is:
                     24: 
                     25: <UL>
2.42      frystyk    26: <LI><A HREF="#converter">Converters</A>
2.50      frystyk    27: <LI><A HREF="#user">Generic preferences (media type, language, charset etc.)</A>
                     28: <LI><A HREF="#global">Global Preferences</A>
2.42      frystyk    29: <LI><A HREF="#Rank">Content Negotiation</A>
2.31      frystyk    30: <LI><A HREF="#z3">The Stream Stack</A>
                     31: </UL>
                     32: 
                     33: This module is implemented by <A HREF="HTFormat.c">HTFormat.c</A>, and
2.49      frystyk    34: it is a part of the <A HREF="http://www.w3.org/pub/WWW/Library/"> W3C
                     35: Reference Library</A>.
2.27      frystyk    36: 
2.31      frystyk    37: <PRE>
                     38: #ifndef HTFORMAT_H
2.1       timbl      39: #define HTFORMAT_H
                     40: 
2.31      frystyk    41: #include <A HREF="HTUtils.html">"HTUtils.h"</A>
                     42: #include <A HREF="HTStream.html">"HTStream.h"</A>
                     43: #include <A HREF="HTAtom.html">"HTAtom.h"</A>
                     44: #include <A HREF="HTList.html">"HTList.h"</A>
2.42      frystyk    45: #include <A HREF="HTAnchor.html">"HTAnchor.h"</A>
2.47      frystyk    46: #include <A HREF="HTReq.html">"HTReq.h"</A>
2.31      frystyk    47: </PRE>
2.1       timbl      48: 
2.42      frystyk    49: <A NAME="converter"><H2>Stream Converters</H2></A>
2.18      luotonen   50: 
2.42      frystyk    51: A <CODE><A NAME="z12">converter</A></CODE> is a stream with a special
                     52: set of parameters and which is registered as capable of converting
                     53: from a MIME type to something else (maybe another MIME-type). A
                     54: converter is defined to be a function returning a stream and accepting
                     55: the following parameters. The content type elements are atoms for
                     56: which we have defined a prototype.
2.18      luotonen   57: 
2.31      frystyk    58: <PRE>
2.52      frystyk    59: typedef HTStream * HTConverter (HTRequest *    request,
                     60:                                 void *         param,
                     61:                                 HTFormat       input_format,
                     62:                                 HTFormat       output_format,
                     63:                                 HTStream *     output_stream);
2.42      frystyk    64: </PRE>
2.18      luotonen   65: 
2.50      frystyk    66: <A NAME="user"><H2>Generic Preferences</H2></A>
2.31      frystyk    67: 
2.42      frystyk    68: The Library contains functionality for letting the application (or
                     69: user) express the preferences for the rendition of a given data object
                     70: when issuing a request. The categories supported are:
                     71: 
                     72: <UL>
                     73: <LI>Content type (media type)
                     74: <LI>Encoding
                     75: <LI>Language
                     76: <LI>Charset
                     77: </UL>
2.17      luotonen   78: 
2.42      frystyk    79: <A NAME="FormatTypes"><H3>Registration of Accepted Content Types</H3></A>
2.17      luotonen   80: 
2.42      frystyk    81: A <CODE>presenter</CODE> is a module (possibly an external program)
                     82: which can present a graphic object of a certain MIME type to the
                     83: user. That is, <CODE>presenters</CODE> are normally used to present
                     84: objects that the <CODE>converters</CODE> are not able to handle. Data
                     85: is transferred to the external program using for example the <A
                     86: HREF="HTFWrite.html">HTSaveAndExecute</A> stream which writes to a
                     87: local file. Both presenters and converters are of the type <A
                     88: HREF="#converter">HTConverter</A>.
2.31      frystyk    89: 
                     90: <PRE>
2.42      frystyk    91: typedef struct _HTPresentation {
                     92:     HTFormat   rep;                         /* representation name atomized */
                     93:     HTFormat   rep_out;                         /* resulting representation */
                     94:     HTConverter *converter;          /* The routine to gen the stream stack */
                     95:     char *     command;                               /* MIME-format string */
                     96:     char *     test_command;                          /* MIME-format string */
                     97:     double     quality;                     /* Between 0 (bad) and 1 (good) */
                     98:     double     secs;
                     99:     double     secs_per_byte;
                    100: } HTPresentation;
2.28      frystyk   101: </PRE>
                    102: 
2.42      frystyk   103: <H4>Predefined Content Types</H4>
2.28      frystyk   104: 
2.42      frystyk   105: These macros (which used to be constants) define some basic internally
                    106: referenced representations. The <CODE>www/xxx</CODE> ones are of
2.52      frystyk   107: course not MIME standard. They are internal representations used in
                    108: the Library but they can't be exported to other apps!
2.28      frystyk   109: 
                    110: <PRE>
                    111: #define WWW_SOURCE     HTAtom_for("*/*")      /* Whatever it was originally */
                    112: </PRE>
                    113: 
2.52      frystyk   114: <CODE>WWW_SOURCE</CODE> is an output format which leaves the input
2.54      frystyk   115: untouched <EM>exactly</EM> as it is received by the protocol
                    116: module. For example, in the case of FTP, this format returns raw ASCII
                    117: objects for directory listings; for HTTP, everything including the
                    118: header is returned, for Gopher, a raw ASCII object is returned for a
                    119: menu etc.
2.10      timbl     120: 
2.28      frystyk   121: <PRE>
                    122: #define WWW_PRESENT    HTAtom_for("www/present")   /* The user's perception */
                    123: </PRE>
                    124: 
2.52      frystyk   125: <CODE>WWW_PRESENT</CODE> represents the user's perception of the
                    126: document.  If you convert to <CODE>WWW_PRESENT</CODE>, you present the
                    127: material to the user.
2.28      frystyk   128: 
                    129: <PRE>
2.52      frystyk   130: #define WWW_UNKNOWN     HTAtom_for("www/unknown")
2.28      frystyk   131: </PRE>
                    132: 
2.52      frystyk   133: <CODE>WWW_UNKNOWN</CODE> is a really unknown type. It differs from the
                    134: real MIME type <EM>"application/octet-stream"</EM> in that we haven't
                    135: even tried to figure out the content type at this point.<P>
2.28      frystyk   136: 
2.31      frystyk   137: These are regular MIME types defined. Others can be added!
2.28      frystyk   138: 
                    139: <PRE>
2.52      frystyk   140: #define WWW_HTML       HTAtom_for("text/html")
2.28      frystyk   141: #define WWW_PLAINTEXT  HTAtom_for("text/plain")
2.52      frystyk   142: 
                    143: #define WWW_MIME       HTAtom_for("message/rfc822")
                    144: 
2.10      timbl     145: #define WWW_AUDIO       HTAtom_for("audio/basic")
2.52      frystyk   146: 
2.26      frystyk   147: #define WWW_VIDEO      HTAtom_for("video/mpeg")
2.52      frystyk   148: 
2.38      frystyk   149: #define WWW_GIF        HTAtom_for("image/gif")
2.52      frystyk   150: #define WWW_PNG        HTAtom_for("image/png")
                    151: 
                    152: #define WWW_BINARY     HTAtom_for("application/octet-stream")
                    153: #define WWW_POSTSCRIPT         HTAtom_for("application/postscript")
                    154: #define WWW_RICHTEXT   HTAtom_for("application/rtf")
2.48      frystyk   155: </PRE>
                    156: 
2.52      frystyk   157: We also have some MIME types that come from the various protocols when
                    158: we convert from ASCII to HTML.
2.48      frystyk   159: 
                    160: <PRE>
                    161: #define WWW_GOPHER_MENU HTAtom_for("text/x-gopher")
2.53      frystyk   162: #define WWW_CSO_SEARCH HTAtom_for("text/x-cso")
2.48      frystyk   163: 
                    164: #define WWW_FTP_LNST   HTAtom_for("text/x-ftp-lnst")
                    165: #define WWW_FTP_LIST   HTAtom_for("text/x-ftp-list")
                    166: 
                    167: #define WWW_NNTP_LIST   HTAtom_for("text/x-nntp-list")
                    168: #define WWW_NNTP_OVER  HTAtom_for("text/x-nntp-over")
                    169: #define WWW_NNTP_HEAD  HTAtom_for("text/x-nntp-head")
2.55    ! frystyk   170: </PRE>
        !           171: 
        !           172: Finally we have defined a special format for our RULE files as they
        !           173: can be handled by a special converter.
        !           174: 
        !           175: <PRE>
        !           176: #define WWW_RULES      HTAtom_for("text/x-www-rules")
2.28      frystyk   177: </PRE>
                    178: 
2.50      frystyk   179: <H4>Add a Presenter</H4>
                    180: 
                    181: This function creates a presenter object and adds to the list of
                    182: conversions.
2.31      frystyk   183: 
2.1       timbl     184: <DL>
2.31      frystyk   185: <DT>conversions
                    186: <DD>The list of <CODE>conveters</CODE> and <CODE>presenters</CODE>
2.50      frystyk   187: <DT>rep_in
2.42      frystyk   188: <DD>the MIME-style format name
2.50      frystyk   189: <DT>rep_out
                    190: <DD>is the resulting content-type after the conversion
                    191: <DT>converter
                    192: <DD>is the routine to call which actually does the conversion
2.1       timbl     193: <DT>quality
2.31      frystyk   194: <DD>A degradation faction [0..1]
2.1       timbl     195: <DT>maxbytes
2.31      frystyk   196: <DD>A limit on the length acceptable as input (0 infinite)
2.1       timbl     197: <DT>maxsecs
2.31      frystyk   198: <DD>A limit on the time user will wait (0 for infinity)
2.1       timbl     199: </DL>
                    200: 
2.31      frystyk   201: <PRE>
2.49      frystyk   202: extern void HTPresentation_add (HTList *       conversions,
                    203:                                CONST char *    representation,
                    204:                                CONST char *    command,
                    205:                                CONST char *    test_command,
                    206:                                double          quality,
                    207:                                double          secs, 
                    208:                                double          secs_per_byte);
2.31      frystyk   209: </PRE>
2.1       timbl     210: 
2.50      frystyk   211: <H4>Delete a list of Presenters</H4>
                    212: 
                    213: <PRE>
                    214: extern void HTPresentation_deleteAll   (HTList * list);
                    215: </PRE>
                    216: 
                    217: <H4>Add a Converter</H4>
                    218: 
                    219: This function creates a presenter object and adds to the list of
                    220: conversions.
2.1       timbl     221: 
                    222: <DL>
2.31      frystyk   223: <DT>conversions
                    224: <DD>The list of <CODE>conveters</CODE> and <CODE>presenters</CODE>
2.1       timbl     225: <DT>rep_in
2.42      frystyk   226: <DD>the MIME-style format name
2.1       timbl     227: <DT>rep_out
2.31      frystyk   228: <DD>is the resulting content-type after the conversion
2.1       timbl     229: <DT>converter
2.31      frystyk   230: <DD>is the routine to call which actually does the conversion
                    231: <DT>quality
                    232: <DD>A degradation faction [0..1]
                    233: <DT>maxbytes
                    234: <DD>A limit on the length acceptable as input (0 infinite)
                    235: <DT>maxsecs
                    236: <DD>A limit on the time user will wait (0 for infinity)
2.1       timbl     237: </DL>
                    238: 
                    239: <PRE>
2.49      frystyk   240: extern void HTConversion_add   (HTList *       conversions,
                    241:                                CONST char *    rep_in,
                    242:                                CONST char *    rep_out,
                    243:                                HTConverter *   converter,
                    244:                                double          quality,
                    245:                                double          secs, 
                    246:                                double          secs_per_byte);
2.42      frystyk   247: </PRE>
                    248: 
2.50      frystyk   249: <H4>Delete a list of Converters</H4>
                    250: 
                    251: <PRE>
                    252: extern void HTConversion_deleteAll     (HTList * list);
                    253: </PRE>
                    254: 
2.42      frystyk   255: <A NAME="Encoding"><H3>Registration of Accepted Content Encodings</H3></A>
                    256: 
                    257: Encodings are the HTTP extension of transfer encodings. Encodings
2.50      frystyk   258: include compress, gzip etc.
2.42      frystyk   259: 
                    260: <PRE>
                    261: typedef struct _HTAcceptNode {
                    262:     HTAtom *   atom;
                    263:     double     quality;
                    264: } HTAcceptNode;
                    265: </PRE>
                    266: 
                    267: <H4>Predefined Encoding Types</H4>
                    268: 
                    269: <PRE>
                    270: #define WWW_ENC_7BIT           HTAtom_for("7bit")
                    271: #define WWW_ENC_8BIT           HTAtom_for("8bit")
                    272: #define WWW_ENC_BINARY         HTAtom_for("binary")
                    273: #define WWW_ENC_BASE64         HTAtom_for("base64")
                    274: #define WWW_ENC_COMPRESS       HTAtom_for("compress")
                    275: #define WWW_ENC_GZIP           HTAtom_for("gzip")
                    276: </PRE>
                    277: 
                    278: <H4>Register an Encoding</H4>
                    279: 
                    280: <PRE>
2.50      frystyk   281: extern void HTEncoding_add (HTList *           list,
                    282:                            CONST char *        enc,
                    283:                            double              quality);
2.42      frystyk   284: </PRE>
2.31      frystyk   285: 
2.50      frystyk   286: <H4>Delete a list of Encoders</H4>
2.31      frystyk   287: 
2.50      frystyk   288: <PRE>
2.51      frystyk   289: extern void HTEncoding_deleteAll (HTList * list);
2.50      frystyk   290: </PRE>
                    291: 
                    292: <H3><A NAME="charset">Accepted Charsets</A></H3>
2.31      frystyk   293: 
2.42      frystyk   294: <H4>Register a Charset</H4>
                    295: 
                    296: <PRE>
2.50      frystyk   297: extern void HTCharset_add (HTList *            list,
                    298:                           CONST char *         charset,
                    299:                           double               quality);
2.42      frystyk   300: </PRE>
                    301: 
2.50      frystyk   302: <H4>Delete a list of Charsets</H4>
2.42      frystyk   303: 
2.50      frystyk   304: <PRE>
                    305: extern void HTCharset_deleteAll        (HTList * list);
                    306: </PRE>
                    307: 
                    308: <A NAME="Language"><H3>Accepted Content Languages</H3></A>
2.31      frystyk   309: 
2.42      frystyk   310: <H4>Register a Language</H4>
2.31      frystyk   311: 
                    312: <PRE>
2.50      frystyk   313: extern void HTLanguage_add (HTList *           list,
                    314:                            CONST char *        lang,
                    315:                            double              quality);
                    316: </PRE>
                    317: 
                    318: <H4>Delete a list of Languages</H4>
                    319: 
                    320: <PRE>
2.51      frystyk   321: extern void HTLanguage_deleteAll (HTList * list);
2.50      frystyk   322: </PRE>
                    323: 
                    324: <A NAME="global"><H2>Global Registrations</H2></A>
                    325: 
                    326: There are two places where these preferences can be registered: in a
                    327: <EM>global</EM> list valid for <B>all</B> requests and a
                    328: <EM>local</EM> list valid for a particular request only. These are
                    329: valid for <EM>all</EM> requests. See the <A HREF="HTReq.html">Request
                    330: Manager</A> fro local sets.
                    331: 
2.51      frystyk   332: <H3>Converters and Presenters</H3>
2.50      frystyk   333: 
                    334: The <EM>global</EM> list of specific conversions which the format
                    335: manager can do in order to fulfill the request.  There is also a <A
                    336: HREF="HTReq.html"><EM>local</EM></A> list of conversions which
                    337: contains a generic set of possible conversions.
                    338: 
                    339: <PRE>
                    340: extern void HTFormat_setConversion     (HTList *list);
                    341: extern HTList * HTFormat_conversion    (void);
2.31      frystyk   342: </PRE>
                    343: 
2.50      frystyk   344: <H3>Content Encodings</H3>
2.42      frystyk   345: 
2.50      frystyk   346: <PRE>
                    347: extern void HTFormat_setEncoding       (HTList *list);
                    348: extern HTList * HTFormat_encoding      (void);
                    349: </PRE>
2.1       timbl     350: 
2.51      frystyk   351: <H3>Content Languages</H3>
2.50      frystyk   352: 
                    353: <PRE>
                    354: extern void HTFormat_setLanguage       (HTList *list);
                    355: extern HTList * HTFormat_language      (void);
                    356: </PRE>
2.42      frystyk   357: 
2.51      frystyk   358: <H3>Content Charsets</H3>
2.1       timbl     359: 
2.31      frystyk   360: <PRE>
2.50      frystyk   361: extern void HTFormat_setCharset                (HTList *list);
                    362: extern HTList * HTFormat_charset       (void);
2.31      frystyk   363: </PRE>
                    364: 
2.50      frystyk   365: <H3>Delete All Global Lists</H3>
2.42      frystyk   366: 
2.50      frystyk   367: This is a convenience function that might make life easier.
2.34      frystyk   368: 
                    369: <PRE>
2.50      frystyk   370: extern void HTFormat_deleteAll (void);
2.34      frystyk   371: </PRE>
2.31      frystyk   372: 
                    373: <A NAME="Rank"><H2>Ranking of Accepted Formats</H2></A>
                    374: 
2.36      frystyk   375: This function is used when the best match among several possible
                    376: documents is to be found as a function of the accept headers sent in
                    377: the client request.
2.31      frystyk   378: 
                    379: <PRE>
2.42      frystyk   380: typedef struct _HTContentDescription {
                    381:     char *     filename;
                    382:     HTAtom *   content_type;
                    383:     HTAtom *   content_language;
                    384:     HTAtom *   content_encoding;
                    385:     int                content_length;
                    386:     double     quality;
                    387: } HTContentDescription;
                    388: 
2.52      frystyk   389: extern BOOL HTRank (HTList * possibilities,
                    390:                    HTList * accepted_content_types,
                    391:                    HTList * accepted_content_languages,
                    392:                    HTList * accepted_content_encodings);
2.1       timbl     393: </PRE>
2.31      frystyk   394: 
2.42      frystyk   395: <H2><A NAME="z3">The Stream Stack</A></H2>
2.31      frystyk   396: 
                    397: This is the routine which actually sets up the conversion. It
                    398: currently checks only for direct conversions, but multi-stage
                    399: conversions are forseen.  It takes a stream into which the output
                    400: should be sent in the final format, builds the conversion stack, and
                    401: returns a stream into which the data in the input format should be
2.42      frystyk   402: fed. If <CODE>guess</CODE> is true and input format is
2.31      frystyk   403: <CODE>www/unknown</CODE>, try to guess the format by looking at the
                    404: first few bytes of the stream. <P>
2.1       timbl     405: 
2.31      frystyk   406: <PRE>
2.52      frystyk   407: extern HTStream * HTStreamStack (HTFormat      rep_in,
                    408:                                 HTFormat       rep_out,
                    409:                                 HTStream *     output_stream,
                    410:                                 HTRequest *    request,
                    411:                                 BOOL           guess);
2.1       timbl     412: </PRE>
2.31      frystyk   413: 
2.42      frystyk   414: <H2>Cost of a Stream Stack</H2>
2.31      frystyk   415: 
                    416: Must return the cost of the same stack which HTStreamStack would set
2.1       timbl     417: up.
                    418: 
2.31      frystyk   419: <PRE>
2.52      frystyk   420: extern double HTStackValue     (HTList *       conversions,
                    421:                                 HTFormat       format_in,
                    422:                                 HTFormat       format_out,
                    423:                                 double         initial_value,
                    424:                                 long int       length);
2.31      frystyk   425: 
2.42      frystyk   426: #endif /* HTFORMAT */
2.38      frystyk   427: </PRE>
                    428: 
2.42      frystyk   429: End of declaration module
2.31      frystyk   430: 
                    431: </BODY>
2.10      timbl     432: </HTML>

Webmaster