Annotation of libwww/Library/src/HTFormat.html, revision 2.57
2.10 timbl 1: <HTML>
2: <HEAD>
2.45 frystyk 3: <TITLE>Format Negotiation Manager</TITLE>
2.57 ! frystyk 4: <!-- Changed by: Henrik Frystyk Nielsen, 25-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>
2.57 ! frystyk 111: #define WWW_RAW HTAtom_for("www/void") /* Raw output from Protocol */
2.28 frystyk 112: </PRE>
113:
2.57 ! frystyk 114: <CODE>WWW_RAW</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>
2.57 ! frystyk 122: #define WWW_SOURCE HTAtom_for("*/*") /* Almost what it was originally */
! 123: </PRE>
! 124:
! 125: <CODE>WWW_SOURCE</CODE> is an output format which leaves the input
! 126: untouched <EM>exactly</EM> as it is received by the protocol module
! 127: <B>IF</B> not a suitable converter has been registered with a quality
! 128: factor higher than 1 (for example 2). In this case the <EM>SUPER
! 129: CONVERTER</EM> is preferred for the raw output. This can be used as a
! 130: filter effect that allows conversion from, for example raw
! 131: FTPdirectory listings into HTML but passes a MIME body untouched.
! 132:
! 133: <PRE>
2.28 frystyk 134: #define WWW_PRESENT HTAtom_for("www/present") /* The user's perception */
135: </PRE>
136:
2.52 frystyk 137: <CODE>WWW_PRESENT</CODE> represents the user's perception of the
138: document. If you convert to <CODE>WWW_PRESENT</CODE>, you present the
139: material to the user.
2.28 frystyk 140:
141: <PRE>
2.52 frystyk 142: #define WWW_UNKNOWN HTAtom_for("www/unknown")
2.28 frystyk 143: </PRE>
144:
2.52 frystyk 145: <CODE>WWW_UNKNOWN</CODE> is a really unknown type. It differs from the
146: real MIME type <EM>"application/octet-stream"</EM> in that we haven't
147: even tried to figure out the content type at this point.<P>
2.28 frystyk 148:
2.31 frystyk 149: These are regular MIME types defined. Others can be added!
2.28 frystyk 150:
151: <PRE>
2.52 frystyk 152: #define WWW_HTML HTAtom_for("text/html")
2.28 frystyk 153: #define WWW_PLAINTEXT HTAtom_for("text/plain")
2.52 frystyk 154:
155: #define WWW_MIME HTAtom_for("message/rfc822")
156:
2.10 timbl 157: #define WWW_AUDIO HTAtom_for("audio/basic")
2.52 frystyk 158:
2.26 frystyk 159: #define WWW_VIDEO HTAtom_for("video/mpeg")
2.52 frystyk 160:
2.38 frystyk 161: #define WWW_GIF HTAtom_for("image/gif")
2.52 frystyk 162: #define WWW_PNG HTAtom_for("image/png")
163:
164: #define WWW_BINARY HTAtom_for("application/octet-stream")
165: #define WWW_POSTSCRIPT HTAtom_for("application/postscript")
166: #define WWW_RICHTEXT HTAtom_for("application/rtf")
2.48 frystyk 167: </PRE>
168:
2.52 frystyk 169: We also have some MIME types that come from the various protocols when
170: we convert from ASCII to HTML.
2.48 frystyk 171:
172: <PRE>
173: #define WWW_GOPHER_MENU HTAtom_for("text/x-gopher")
2.53 frystyk 174: #define WWW_CSO_SEARCH HTAtom_for("text/x-cso")
2.48 frystyk 175:
176: #define WWW_FTP_LNST HTAtom_for("text/x-ftp-lnst")
177: #define WWW_FTP_LIST HTAtom_for("text/x-ftp-list")
178:
179: #define WWW_NNTP_LIST HTAtom_for("text/x-nntp-list")
180: #define WWW_NNTP_OVER HTAtom_for("text/x-nntp-over")
181: #define WWW_NNTP_HEAD HTAtom_for("text/x-nntp-head")
2.55 frystyk 182: </PRE>
183:
184: Finally we have defined a special format for our RULE files as they
185: can be handled by a special converter.
186:
187: <PRE>
2.57 ! frystyk 188: #define WWW_RULES HTAtom_for("application/x-www-rules")
2.28 frystyk 189: </PRE>
190:
2.50 frystyk 191: <H4>Add a Presenter</H4>
192:
193: This function creates a presenter object and adds to the list of
194: conversions.
2.31 frystyk 195:
2.1 timbl 196: <DL>
2.31 frystyk 197: <DT>conversions
198: <DD>The list of <CODE>conveters</CODE> and <CODE>presenters</CODE>
2.50 frystyk 199: <DT>rep_in
2.42 frystyk 200: <DD>the MIME-style format name
2.50 frystyk 201: <DT>rep_out
202: <DD>is the resulting content-type after the conversion
203: <DT>converter
204: <DD>is the routine to call which actually does the conversion
2.1 timbl 205: <DT>quality
2.31 frystyk 206: <DD>A degradation faction [0..1]
2.1 timbl 207: <DT>maxbytes
2.31 frystyk 208: <DD>A limit on the length acceptable as input (0 infinite)
2.1 timbl 209: <DT>maxsecs
2.31 frystyk 210: <DD>A limit on the time user will wait (0 for infinity)
2.1 timbl 211: </DL>
212:
2.31 frystyk 213: <PRE>
2.49 frystyk 214: extern void HTPresentation_add (HTList * conversions,
215: CONST char * representation,
216: CONST char * command,
217: CONST char * test_command,
218: double quality,
219: double secs,
220: double secs_per_byte);
2.31 frystyk 221: </PRE>
2.1 timbl 222:
2.50 frystyk 223: <H4>Delete a list of Presenters</H4>
224:
225: <PRE>
226: extern void HTPresentation_deleteAll (HTList * list);
227: </PRE>
228:
229: <H4>Add a Converter</H4>
230:
231: This function creates a presenter object and adds to the list of
232: conversions.
2.1 timbl 233:
234: <DL>
2.31 frystyk 235: <DT>conversions
236: <DD>The list of <CODE>conveters</CODE> and <CODE>presenters</CODE>
2.1 timbl 237: <DT>rep_in
2.42 frystyk 238: <DD>the MIME-style format name
2.1 timbl 239: <DT>rep_out
2.31 frystyk 240: <DD>is the resulting content-type after the conversion
2.1 timbl 241: <DT>converter
2.31 frystyk 242: <DD>is the routine to call which actually does the conversion
243: <DT>quality
244: <DD>A degradation faction [0..1]
245: <DT>maxbytes
246: <DD>A limit on the length acceptable as input (0 infinite)
247: <DT>maxsecs
248: <DD>A limit on the time user will wait (0 for infinity)
2.1 timbl 249: </DL>
250:
251: <PRE>
2.49 frystyk 252: extern void HTConversion_add (HTList * conversions,
253: CONST char * rep_in,
254: CONST char * rep_out,
255: HTConverter * converter,
256: double quality,
257: double secs,
258: double secs_per_byte);
2.42 frystyk 259: </PRE>
260:
2.50 frystyk 261: <H4>Delete a list of Converters</H4>
262:
263: <PRE>
264: extern void HTConversion_deleteAll (HTList * list);
265: </PRE>
266:
2.42 frystyk 267: <A NAME="Encoding"><H3>Registration of Accepted Content Encodings</H3></A>
268:
269: Encodings are the HTTP extension of transfer encodings. Encodings
2.50 frystyk 270: include compress, gzip etc.
2.42 frystyk 271:
272: <PRE>
273: typedef struct _HTAcceptNode {
274: HTAtom * atom;
275: double quality;
276: } HTAcceptNode;
277: </PRE>
278:
279: <H4>Predefined Encoding Types</H4>
280:
281: <PRE>
282: #define WWW_ENC_7BIT HTAtom_for("7bit")
283: #define WWW_ENC_8BIT HTAtom_for("8bit")
284: #define WWW_ENC_BINARY HTAtom_for("binary")
285: #define WWW_ENC_BASE64 HTAtom_for("base64")
286: #define WWW_ENC_COMPRESS HTAtom_for("compress")
287: #define WWW_ENC_GZIP HTAtom_for("gzip")
288: </PRE>
289:
290: <H4>Register an Encoding</H4>
291:
292: <PRE>
2.50 frystyk 293: extern void HTEncoding_add (HTList * list,
294: CONST char * enc,
295: double quality);
2.42 frystyk 296: </PRE>
2.31 frystyk 297:
2.50 frystyk 298: <H4>Delete a list of Encoders</H4>
2.31 frystyk 299:
2.50 frystyk 300: <PRE>
2.51 frystyk 301: extern void HTEncoding_deleteAll (HTList * list);
2.50 frystyk 302: </PRE>
303:
304: <H3><A NAME="charset">Accepted Charsets</A></H3>
2.31 frystyk 305:
2.42 frystyk 306: <H4>Register a Charset</H4>
307:
308: <PRE>
2.50 frystyk 309: extern void HTCharset_add (HTList * list,
310: CONST char * charset,
311: double quality);
2.42 frystyk 312: </PRE>
313:
2.50 frystyk 314: <H4>Delete a list of Charsets</H4>
2.42 frystyk 315:
2.50 frystyk 316: <PRE>
317: extern void HTCharset_deleteAll (HTList * list);
318: </PRE>
319:
320: <A NAME="Language"><H3>Accepted Content Languages</H3></A>
2.31 frystyk 321:
2.42 frystyk 322: <H4>Register a Language</H4>
2.31 frystyk 323:
324: <PRE>
2.50 frystyk 325: extern void HTLanguage_add (HTList * list,
326: CONST char * lang,
327: double quality);
328: </PRE>
329:
330: <H4>Delete a list of Languages</H4>
331:
332: <PRE>
2.51 frystyk 333: extern void HTLanguage_deleteAll (HTList * list);
2.50 frystyk 334: </PRE>
335:
336: <A NAME="global"><H2>Global Registrations</H2></A>
337:
338: There are two places where these preferences can be registered: in a
339: <EM>global</EM> list valid for <B>all</B> requests and a
340: <EM>local</EM> list valid for a particular request only. These are
341: valid for <EM>all</EM> requests. See the <A HREF="HTReq.html">Request
342: Manager</A> fro local sets.
343:
2.51 frystyk 344: <H3>Converters and Presenters</H3>
2.50 frystyk 345:
346: The <EM>global</EM> list of specific conversions which the format
347: manager can do in order to fulfill the request. There is also a <A
348: HREF="HTReq.html"><EM>local</EM></A> list of conversions which
349: contains a generic set of possible conversions.
350:
351: <PRE>
352: extern void HTFormat_setConversion (HTList *list);
353: extern HTList * HTFormat_conversion (void);
2.31 frystyk 354: </PRE>
355:
2.50 frystyk 356: <H3>Content Encodings</H3>
2.42 frystyk 357:
2.50 frystyk 358: <PRE>
359: extern void HTFormat_setEncoding (HTList *list);
360: extern HTList * HTFormat_encoding (void);
361: </PRE>
2.1 timbl 362:
2.51 frystyk 363: <H3>Content Languages</H3>
2.50 frystyk 364:
365: <PRE>
366: extern void HTFormat_setLanguage (HTList *list);
367: extern HTList * HTFormat_language (void);
368: </PRE>
2.42 frystyk 369:
2.51 frystyk 370: <H3>Content Charsets</H3>
2.1 timbl 371:
2.31 frystyk 372: <PRE>
2.50 frystyk 373: extern void HTFormat_setCharset (HTList *list);
374: extern HTList * HTFormat_charset (void);
2.31 frystyk 375: </PRE>
376:
2.50 frystyk 377: <H3>Delete All Global Lists</H3>
2.42 frystyk 378:
2.50 frystyk 379: This is a convenience function that might make life easier.
2.34 frystyk 380:
381: <PRE>
2.50 frystyk 382: extern void HTFormat_deleteAll (void);
2.34 frystyk 383: </PRE>
2.31 frystyk 384:
385: <A NAME="Rank"><H2>Ranking of Accepted Formats</H2></A>
386:
2.36 frystyk 387: This function is used when the best match among several possible
388: documents is to be found as a function of the accept headers sent in
389: the client request.
2.31 frystyk 390:
391: <PRE>
2.42 frystyk 392: typedef struct _HTContentDescription {
393: char * filename;
394: HTAtom * content_type;
395: HTAtom * content_language;
396: HTAtom * content_encoding;
397: int content_length;
398: double quality;
399: } HTContentDescription;
400:
2.52 frystyk 401: extern BOOL HTRank (HTList * possibilities,
402: HTList * accepted_content_types,
403: HTList * accepted_content_languages,
404: HTList * accepted_content_encodings);
2.1 timbl 405: </PRE>
2.31 frystyk 406:
2.42 frystyk 407: <H2><A NAME="z3">The Stream Stack</A></H2>
2.31 frystyk 408:
409: This is the routine which actually sets up the conversion. It
410: currently checks only for direct conversions, but multi-stage
411: conversions are forseen. It takes a stream into which the output
412: should be sent in the final format, builds the conversion stack, and
413: returns a stream into which the data in the input format should be
2.42 frystyk 414: fed. If <CODE>guess</CODE> is true and input format is
2.31 frystyk 415: <CODE>www/unknown</CODE>, try to guess the format by looking at the
416: first few bytes of the stream. <P>
2.1 timbl 417:
2.31 frystyk 418: <PRE>
2.52 frystyk 419: extern HTStream * HTStreamStack (HTFormat rep_in,
420: HTFormat rep_out,
421: HTStream * output_stream,
422: HTRequest * request,
423: BOOL guess);
2.1 timbl 424: </PRE>
2.31 frystyk 425:
2.42 frystyk 426: <H2>Cost of a Stream Stack</H2>
2.31 frystyk 427:
428: Must return the cost of the same stack which HTStreamStack would set
2.1 timbl 429: up.
430:
2.31 frystyk 431: <PRE>
2.52 frystyk 432: extern double HTStackValue (HTList * conversions,
433: HTFormat format_in,
434: HTFormat format_out,
435: double initial_value,
436: long int length);
2.31 frystyk 437:
2.42 frystyk 438: #endif /* HTFORMAT */
2.38 frystyk 439: </PRE>
440:
2.42 frystyk 441: End of declaration module
2.31 frystyk 442:
443: </BODY>
2.10 timbl 444: </HTML>
Webmaster