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