Annotation of libwww/Library/src/HTFormat.html, revision 2.40
2.10 timbl 1: <HTML>
2: <HEAD>
2.31 frystyk 3: <TITLE>The Format Manager in the WWW Library</TITLE>
2.15 timbl 4: <NEXTID N="z18">
2.10 timbl 5: </HEAD>
2.1 timbl 6: <BODY>
2.27 frystyk 7:
2.31 frystyk 8: <H1>The Format Manager</H1>
2.33 frystyk 9:
10: <PRE>
11: /*
12: ** (c) COPYRIGHT CERN 1994.
13: ** Please first read the full copyright statement in the file COPYRIGH.
14: */
15: </PRE>
2.31 frystyk 16:
17: Here we describe the functions of the HTFormat module which handles
18: conversion between different data representations. (In MIME parlance,
19: a representation is known as a content-type. In <A
2.38 frystyk 20: HREF="http://www.w3.org/hypertext/WWW/TheProject.html">WWW</A> the
2.31 frystyk 21: term <EM>format</EM> is often used as it is shorter). The content of
22: this module is:
23:
24: <UL>
25: <LI><A HREF="#z15">Buffering for I/O</A>
26: <LI><A HREF="#FormatTypes">Predefined Format Types</A>
27: <LI><A HREF="#Encoding">Registration of Accepted Content Encodings</A>
28: <LI><A HREF="#Language">Registration of Accepted Content Languages</A>
29: <LI><A HREF="#Type">Registration of Accepted Converters and Presenters</A>
30: <LI><A HREF="#Rank">Ranking of Accepted Formats</A>
31: <LI><A HREF="#z3">The Stream Stack</A>
2.38 frystyk 32: <LI><A HREF="#Read">Read from a Socket</A>
2.31 frystyk 33: </UL>
34:
35: This module is implemented by <A HREF="HTFormat.c">HTFormat.c</A>, and
36: it is a part of the <A NAME="z10"
2.38 frystyk 37: HREF="http://www.w3.org/hypertext/WWW/Library/User/Guide/Guide.html">Library
2.31 frystyk 38: of Common Code</A>.
2.27 frystyk 39:
2.31 frystyk 40: <PRE>
41: #ifndef HTFORMAT_H
2.1 timbl 42: #define HTFORMAT_H
43:
2.31 frystyk 44: #include <A HREF="HTUtils.html">"HTUtils.h"</A>
45: #include <A HREF="HTStream.html">"HTStream.h"</A>
46: #include <A HREF="HTAtom.html">"HTAtom.h"</A>
47: #include <A HREF="HTList.html">"HTList.h"</A>
48: </PRE>
2.1 timbl 49:
2.31 frystyk 50: <H2><A NAME="z15">Buffering for network I/O</A></H2>
2.18 luotonen 51:
2.31 frystyk 52: This routines provide buffering for READ (and future WRITE) to the
53: network. It is used by all the protocol modules. The size of the
54: buffer, <CODE>INPUT_BUFFER_SIZE</CODE>, is a compromis between speed
55: and memory.
2.18 luotonen 56:
2.31 frystyk 57: <PRE>
58: #define INPUT_BUFFER_SIZE 8192
2.18 luotonen 59:
2.17 luotonen 60: typedef struct _socket_buffer {
2.36 frystyk 61: char input_buffer[INPUT_BUFFER_SIZE];
62: char * input_pointer;
63: char * input_limit;
64: SOCKFD input_file_number;
2.17 luotonen 65: } HTInputSocket;
2.31 frystyk 66: </PRE>
67:
68: <H3>Create an Input Buffer</H3>
2.17 luotonen 69:
2.31 frystyk 70: This function allocates a input buffer and binds it to the socket
71: descriptor given as parameter.
72:
73: <PRE>
2.36 frystyk 74: extern HTInputSocket* HTInputSocket_new PARAMS((SOCKFD file_number));
2.17 luotonen 75: </PRE>
76:
2.31 frystyk 77: <H3>Free an Input Buffer</H3>
78:
79: <PRE>
80: extern void HTInputSocket_free PARAMS((HTInputSocket * isoc));
2.17 luotonen 81: </PRE>
82:
2.31 frystyk 83: <A NAME="FormatTypes"><H2>The HTFormat types</H2></A>
2.25 luotonen 84:
2.31 frystyk 85: We use the <A HREF="HTAtom.html">HTAtom</A> object for holding
86: representations. This allows faster manipulation (comparison and
87: copying) that if we stayed with strings. These macros (which used to
88: be constants) define some basic internally referenced
89: representations.<P>
2.25 luotonen 90:
2.31 frystyk 91: <PRE>
92: typedef HTAtom * HTFormat;
2.38 frystyk 93: typedef HTAtom * HTCharset;
2.39 frystyk 94: typedef HTAtom * HTLevel;
2.28 frystyk 95: </PRE>
96:
97: <H3>Internal ones</H3>
98:
2.31 frystyk 99: The <CODE>www/xxx</CODE> ones are of course not MIME
100: standard. <P>
2.28 frystyk 101:
2.31 frystyk 102: <CODE>star/star</CODE> is an output format which leaves the input
103: untouched. It is useful for diagnostics, and for users who want to see
104: the original, whatever it is.
2.28 frystyk 105:
106: <PRE>
107: #define WWW_SOURCE HTAtom_for("*/*") /* Whatever it was originally */
108: </PRE>
109:
2.31 frystyk 110: <CODE>www/present</CODE> represents the user's perception of the
111: document. If you convert to www/present, you present the material to
112: the user.
2.10 timbl 113:
2.28 frystyk 114: <PRE>
115: #define WWW_PRESENT HTAtom_for("www/present") /* The user's perception */
116: </PRE>
117:
118: The message/rfc822 format means a MIME message or a plain text message
119: with no MIME header. This is what is returned by an HTTP server.
120:
121: <PRE>
122: #define WWW_MIME HTAtom_for("www/mime") /* A MIME message */
123: </PRE>
124:
2.31 frystyk 125: <CODE>www/print</CODE> is like www/present except it represents a
126: printed copy.
2.28 frystyk 127:
128: <PRE>
129: #define WWW_PRINT HTAtom_for("www/print") /* A printed copy */
130: </PRE>
2.13 timbl 131:
2.31 frystyk 132: <CODE>www/unknown</CODE> is a really unknown type. Some default
133: action is appropriate.
2.13 timbl 134:
2.28 frystyk 135: <PRE>
136: #define WWW_UNKNOWN HTAtom_for("www/unknown")
2.13 timbl 137: </PRE>
2.28 frystyk 138:
139:
2.31 frystyk 140: <H3>MIME ones</H3>
2.28 frystyk 141:
2.31 frystyk 142: These are regular MIME types defined. Others can be added!
2.28 frystyk 143:
144: <PRE>
145: #define WWW_PLAINTEXT HTAtom_for("text/plain")
2.1 timbl 146: #define WWW_POSTSCRIPT HTAtom_for("application/postscript")
147: #define WWW_RICHTEXT HTAtom_for("application/rtf")
2.10 timbl 148: #define WWW_AUDIO HTAtom_for("audio/basic")
2.1 timbl 149: #define WWW_HTML HTAtom_for("text/html")
2.11 timbl 150: #define WWW_BINARY HTAtom_for("application/octet-stream")
2.26 frystyk 151: #define WWW_VIDEO HTAtom_for("video/mpeg")
2.38 frystyk 152: #define WWW_GIF HTAtom_for("image/gif")
2.28 frystyk 153: </PRE>
154:
2.31 frystyk 155: Extra types used in the library (EXPERIMENT)
2.28 frystyk 156:
157: <PRE>
158: #define WWW_NEWSLIST HTAtom_for("text/newslist")
159: </PRE>
2.7 timbl 160:
2.28 frystyk 161: We must include the following file after defining HTFormat, to which
2.10 timbl 162: it makes reference.
2.28 frystyk 163:
2.10 timbl 164: <H2>The HTEncoding type</H2>
165:
2.31 frystyk 166: <PRE>
2.40 ! frystyk 167: typedef HTAtom * HTLanguage;
2.38 frystyk 168: typedef HTAtom * HTEncoding;
169: typedef HTAtom * HTCte; /* Content transfer encoding */
2.31 frystyk 170: </PRE>
171:
172: The following are values for the MIME types:
173:
174: <PRE>
175: #define WWW_ENC_7BIT HTAtom_for("7bit")
2.10 timbl 176: #define WWW_ENC_8BIT HTAtom_for("8bit")
177: #define WWW_ENC_BINARY HTAtom_for("binary")
2.38 frystyk 178: #define WWW_ENC_BASE64 HTAtom_for("base64")
2.31 frystyk 179: </PRE>
180:
181: We also add
182:
183: <PRE>
184: #define WWW_ENC_COMPRESS HTAtom_for("compress")
185: </PRE>
2.10 timbl 186:
2.31 frystyk 187: <A NAME="Encoding"><H2>Registration of Accepted Content Encodings</H2></A>
2.1 timbl 188:
2.31 frystyk 189: <PRE>
190: typedef struct _HTContentDescription {
191: char * filename;
192: HTAtom * content_type;
193: HTAtom * content_language;
194: HTAtom * content_encoding;
195: int content_length;
2.37 frystyk 196: double quality;
2.31 frystyk 197: } HTContentDescription;
198:
2.32 frystyk 199: extern void HTAcceptEncoding PARAMS((HTList * list,
2.31 frystyk 200: char * enc,
2.37 frystyk 201: double quality));
2.1 timbl 202: </PRE>
203:
2.31 frystyk 204: <A NAME="Language"><H2>Registration of Accepted Content Languages</H2></A>
2.28 frystyk 205:
2.31 frystyk 206: This function is not currently used.
2.28 frystyk 207:
208: <PRE>
2.32 frystyk 209: extern void HTAcceptLanguage PARAMS((HTList * list,
2.31 frystyk 210: char * lang,
2.37 frystyk 211: double quality));
2.31 frystyk 212: </PRE>
2.28 frystyk 213:
2.31 frystyk 214: <A NAME="Type"><H2>Registration of Accepted Converters and
215: Presenters</H2></A>
216:
217: A <CODE><A NAME="z12">converter</A></CODE> is a stream with a special
218: set of parameters and which is registered as capable of converting
219: from a MIME type to something else (maybe another MIME-type). A
220: <CODE>presenter</CODE> is a module (possibly an external program)
221: which can present a graphic object of a certain MIME type to the
222: user. That is, <CODE>presenters</CODE> are normally used to present
223: graphic objects that the <CODE>converters</CODE> are not able to
224: handle. Data is transferred to the external program using the <A
2.36 frystyk 225: HREF="HTFWrite.html">HTSaveAndExecute</A> stream which writes to a
2.31 frystyk 226: local file. This stream is actually a normal <CODE>converter</CODE>,
227: e.g., at strem having the following set of parameters:<P>
228:
229: <PRE>
230: #include "HTAccess.h" /* Required for HTRequest definition */
231:
232: typedef HTStream * HTConverter PARAMS((HTRequest * request,
233: void * param,
234: HTFormat input_format,
235: HTFormat output_format,
236: HTStream * output_stream));
237: </PRE>
238:
239: Both <CODE>converters</CODE> and <CODE>presenters</CODE> are set up in
240: a list which is used by the <A HREF="#z3">StreamStack</A> module to
241: find the best way to pass the information to the user. <P>
242:
243: The <CODE>HTPresentation</CODE> structure contains both
244: <CODE>converters</CODE> and <CODE>presenters</CODE>, and it is defined
245: as:
246:
247: <PRE>
248: typedef struct _HTPresentation {
249: HTAtom* rep; /* representation name atomized */
250: HTAtom* rep_out; /* resulting representation */
251: HTConverter *converter; /* The routine to gen the stream stack */
252: char * command; /* MIME-format string */
253: char * test_command; /* MIME-format string */
2.37 frystyk 254: double quality; /* Between 0 (bad) and 1 (good) */
255: double secs;
256: double secs_per_byte;
2.31 frystyk 257: } HTPresentation;
2.28 frystyk 258: </PRE>
259:
2.1 timbl 260:
2.31 frystyk 261: <A NAME="z17"><H3>Global List of Converters</H3>
2.1 timbl 262:
2.31 frystyk 263: This module keeps a global list of converters. This can be used to get
264: the set of supported formats. <P>
2.12 timbl 265:
2.31 frystyk 266: <B>NOTE:</B> There is also a conversion list associated with each
2.38 frystyk 267: request in the <A HREF="HTAccess.html#z1">HTRequest
268: structure</A>. This list can be used to expand the core set of
269: conversions in the global list. The <A HREF="#z3">StreamStack</A> uses
270: both lists.
2.31 frystyk 271:
272: <PRE>
273: extern HTList * HTConversions;
2.1 timbl 274: </PRE>
2.31 frystyk 275:
276: <H3>Register a Presenter</H3>
277:
2.1 timbl 278: <DL>
2.31 frystyk 279: <DT>conversions
280: <DD>The list of <CODE>conveters</CODE> and <CODE>presenters</CODE>
281: <DT>representation
282: <DD>the <A HREF="#Type">MIME-style</A> format name
2.1 timbl 283: <DT>command
2.31 frystyk 284: <DD>the MAILCAP-style command template
2.1 timbl 285: <DT>quality
2.31 frystyk 286: <DD>A degradation faction [0..1]
2.1 timbl 287: <DT>maxbytes
2.31 frystyk 288: <DD>A limit on the length acceptable as input (0 infinite)
2.1 timbl 289: <DT>maxsecs
2.31 frystyk 290: <DD>A limit on the time user will wait (0 for infinity)
2.1 timbl 291: </DL>
292:
2.31 frystyk 293: <PRE>
294: extern void HTSetPresentation PARAMS((HTList * conversions,
295: CONST char * representation,
296: CONST char * command,
297: CONST char * test_command,
2.37 frystyk 298: double quality,
299: double secs,
300: double secs_per_byte));
2.31 frystyk 301: </PRE>
2.1 timbl 302:
2.31 frystyk 303: <H3>Register a Converter</H3>
2.1 timbl 304:
305: <DL>
2.31 frystyk 306: <DT>conversions
307: <DD>The list of <CODE>conveters</CODE> and <CODE>presenters</CODE>
2.1 timbl 308: <DT>rep_in
2.31 frystyk 309: <DD>the <A HREF="#Type">MIME-style</A> format name
2.1 timbl 310: <DT>rep_out
2.31 frystyk 311: <DD>is the resulting content-type after the conversion
2.1 timbl 312: <DT>converter
2.31 frystyk 313: <DD>is the routine to call which actually does the conversion
314: <DT>quality
315: <DD>A degradation faction [0..1]
316: <DT>maxbytes
317: <DD>A limit on the length acceptable as input (0 infinite)
318: <DT>maxsecs
319: <DD>A limit on the time user will wait (0 for infinity)
2.1 timbl 320: </DL>
321:
322: <PRE>
2.31 frystyk 323: extern void HTSetConversion PARAMS((HTList * conversions,
324: CONST char * rep_in,
325: CONST char * rep_out,
326: HTConverter * converter,
2.37 frystyk 327: double quality,
328: double secs,
329: double secs_per_byte));
2.31 frystyk 330: </PRE>
331:
332: <H3>Set up Default Presenters and Converters</H3>
333:
334: A default set of <CODE>converters</CODE> and <CODE>presenters</CODE>
335: are defined in <A HREF="HTInit.c">HTInit.c</A> (or <A
336: HREF="../../Daemon/Inplementation/HTSUtils.c">HTSInit.c</A> in the
337: server). <P>
338:
339: <B>NOTE: </B> No automatic initialization is done in the Library, so
340: this is for the application to do
341:
342: <PRE>
343: extern void HTFormatInit PARAMS((HTList * conversions));
344: </PRE>
345:
346: This function also exists in a version where no
347: <CODE>presenters</CODE> are initialized. This is intended for Non
348: Interactive Mode, e.g., in the Line Mode Browser.
349:
350: <PRE>
351: extern void HTFormatInitNIM PARAMS((HTList * conversions));
352: </PRE>
353:
354: <H3>Remove presentations and conversions</H3>
2.1 timbl 355:
2.34 frystyk 356: This function deletes the <EM>LOCAL </EM>list of
357: <CODE>converters</CODE> and <CODE>presenters</CODE> associated with
358: each <A HREF="HTAccess.html#z1">HTRequest structure</A>.
2.1 timbl 359:
2.31 frystyk 360: <PRE>
361: extern void HTFormatDelete PARAMS((HTRequest * request));
362: </PRE>
363:
2.34 frystyk 364: This function cleans up the <EM>GLOBAL</EM> list of converters. The
365: function is called from <A
366: HREF="HTAccess.html#Library">HTLibTerminate</A>.
367:
368: <PRE>
369: extern void HTDisposeConversions NOPARAMS;
370: </PRE>
2.31 frystyk 371:
372: <A NAME="Rank"><H2>Ranking of Accepted Formats</H2></A>
373:
2.36 frystyk 374: This function is used when the best match among several possible
375: documents is to be found as a function of the accept headers sent in
376: the client request.
2.31 frystyk 377:
378: <PRE>
2.32 frystyk 379: extern BOOL HTRank PARAMS((HTList * possibilities,
2.31 frystyk 380: HTList * accepted_content_types,
381: HTList * accepted_content_languages,
382: HTList * accepted_content_encodings));
2.1 timbl 383: </PRE>
2.31 frystyk 384:
385: <H2><A NAME="z3">HTStreamStack</A></H2>
386:
387: This is the routine which actually sets up the conversion. It
388: currently checks only for direct conversions, but multi-stage
389: conversions are forseen. It takes a stream into which the output
390: should be sent in the final format, builds the conversion stack, and
391: returns a stream into which the data in the input format should be
392: fed.<P>
393:
2.23 luotonen 394: If <CODE>guess</CODE> is true and input format is
2.31 frystyk 395: <CODE>www/unknown</CODE>, try to guess the format by looking at the
396: first few bytes of the stream. <P>
2.1 timbl 397:
2.31 frystyk 398: <PRE>
2.32 frystyk 399: extern HTStream * HTStreamStack PARAMS((HTFormat rep_in,
2.31 frystyk 400: HTFormat rep_out,
401: HTStream * output_stream,
402: HTRequest * request,
403: BOOL guess));
2.1 timbl 404: </PRE>
2.31 frystyk 405:
406: <H3>Find the cost of a filter stack</H3>
407:
408: Must return the cost of the same stack which HTStreamStack would set
2.1 timbl 409: up.
410:
2.31 frystyk 411: <PRE>
2.1 timbl 412: #define NO_VALUE_FOUND -1e20 /* returned if none found */
413:
2.37 frystyk 414: extern double HTStackValue PARAMS((HTList * conversions,
2.31 frystyk 415: HTFormat format_in,
416: HTFormat format_out,
2.37 frystyk 417: double initial_value,
2.31 frystyk 418: long int length));
2.1 timbl 419: </PRE>
2.31 frystyk 420:
2.38 frystyk 421: <A NAME="Read"><H2>Read Data from a Socket</H2></A>
422:
423: This function has replaced many other functions for doing read from a
424: socket. It automaticly converts from ASCII if we are on a NON-ASCII
425: machine. This assumes that we do <B>not</B> use this function to read
426: a local file on a NON-ASCII machine. The following type definition is
427: to make life easier when having a state machine looking for a
428: <CODE><CRLF></CODE> sequence.
429:
430: <PRE>
431: typedef enum _HTSocketEOL {
432: EOL_ERR = -1,
433: EOL_BEGIN = 0,
434: EOL_FCR,
435: EOL_FLF,
436: EOL_DOT,
437: EOL_SCR,
438: EOL_SLF
439: } HTSocketEOL;
440:
441: extern int HTSocketRead PARAMS((HTRequest * request, HTStream * target));
442: </PRE>
443:
2.31 frystyk 444: <HR>
445:
446: <B><IMG
2.38 frystyk 447: ALIGN=middle SRC="http://www.w3.org/hypertext/WWW/Icons/32x32/caution.gif"> ATTENTION <IMG ALIGN=middle SRC="http://www.w3.org/hypertext/WWW/Icons/32x32/caution.gif"> <P>
2.31 frystyk 448:
449: THE REST OF THE FUNCTION DEFINED IN THIS MODULE ARE GOING TO BE
450: OBSOLETE SO DO NOT USE THEM - THEY ARE NOT REENTRANT.</B>
451:
452: <HR>
453:
2.1 timbl 454: <H2><A
2.10 timbl 455: NAME="z1">HTCopy: Copy a socket to a stream</A></H2>This is used by the protocol engines
2.6 secret 456: to send data down a stream, typically
2.22 timbl 457: one which has been generated by HTStreamStack.
458: Returns the number of bytes transferred.
2.1 timbl 459:
2.36 frystyk 460: <PRE>
461: extern int HTCopy PARAMS((SOCKFD file_number,
462: HTStream * sink));
2.6 secret 463: </PRE>
2.36 frystyk 464:
2.6 secret 465: <H2><A
2.10 timbl 466: NAME="c6">HTFileCopy: Copy a file to a stream</A></H2>This is used by the protocol engines
2.6 secret 467: to send data down a stream, typically
2.7 timbl 468: one which has been generated by HTStreamStack.
469: It is currently called by <A
2.12 timbl 470: NAME="z9" HREF="#c7">HTParseFile</A>
2.6 secret 471: <PRE>extern void HTFileCopy PARAMS((
472: FILE* fp,
473: HTStream* sink));
474:
475:
2.7 timbl 476: </PRE>
477: <H2><A
2.10 timbl 478: NAME="c2">HTCopyNoCR: Copy a socket to a stream,
2.7 timbl 479: stripping CR characters.</A></H2>It is slower than <A
2.12 timbl 480: NAME="z2" HREF="#z1">HTCopy</A> .
2.1 timbl 481: <PRE>
482: extern void HTCopyNoCR PARAMS((
2.36 frystyk 483: SOCKFD file_number,
2.1 timbl 484: HTStream* sink));
485:
2.16 luotonen 486:
487: </PRE>
2.1 timbl 488: <H2>HTParseSocket: Parse a socket given
489: its format</H2>This routine is called by protocol
490: modules to load an object. uses<A
2.12 timbl 491: NAME="z4" HREF="#z3">
2.1 timbl 492: HTStreamStack</A> and the copy routines
493: above. Returns HT_LOADED if succesful,
494: <0 if not.
495: <PRE>extern int HTParseSocket PARAMS((
496: HTFormat format_in,
2.36 frystyk 497: SOCKFD file_number,
2.13 timbl 498: HTRequest * request));
2.6 secret 499:
500: </PRE>
501: <H2><A
2.10 timbl 502: NAME="c1">HTParseFile: Parse a File through
2.7 timbl 503: a file pointer</A></H2>This routine is called by protocols
504: modules to load an object. uses<A
2.12 timbl 505: NAME="z4" HREF="#z3"> HTStreamStack</A>
2.7 timbl 506: and <A
2.12 timbl 507: NAME="c7" HREF="#c6">HTFileCopy</A> . Returns HT_LOADED
2.7 timbl 508: if succesful, <0 if not.
2.6 secret 509: <PRE>extern int HTParseFile PARAMS((
510: HTFormat format_in,
511: FILE *fp,
2.13 timbl 512: HTRequest * request));
2.8 timbl 513:
514: </PRE>
2.21 frystyk 515:
2.31 frystyk 516:
517: <H3>Get next character from buffer</H3>
518:
519: <PRE>extern int HTInputSocket_getCharacter PARAMS((HTInputSocket* isoc));
2.21 frystyk 520: </PRE>
521:
2.31 frystyk 522: <H3>Read block from input socket</H3>Read *len characters and return a
523: buffer (don't free) containing *len
524: characters ( *len may have changed).
525: Buffer is not NULL-terminated.
526: <PRE>extern char * HTInputSocket_getBlock PARAMS((HTInputSocket * isoc,
527: int * len));
528:
2.32 frystyk 529: extern char * HTInputSocket_getLine PARAMS((HTInputSocket * isoc));
530: extern char * HTInputSocket_getUnfoldedLine PARAMS((HTInputSocket * isoc));
531: extern char * HTInputSocket_getStatusLine PARAMS((HTInputSocket * isoc));
532: extern BOOL HTInputSocket_seemsBinary PARAMS((HTInputSocket * isoc));
2.31 frystyk 533:
2.1 timbl 534: #endif
535:
2.31 frystyk 536: </PRE>
537:
538:
539: End of definition module
540:
541: </BODY>
2.10 timbl 542: </HTML>
Webmaster