This module is implemented by HTFormat.c. The module is a part of the WWW library.
#ifndef HTFORMAT_H #define HTFORMAT_H #include "HTUtils.h" #include "HTStream.h" #include "HTAtom.h" #include "HTList.h" #ifdef SHORT_NAMES #define HTOutputSource HTOuSour #define HTOutputBinary HTOuBina #endif typedef struct _HTContentDescription { char * filename; HTAtom * content_type; HTAtom * content_language; HTAtom * content_encoding; int content_length; float quality; } HTContentDescription; PUBLIC void HTAcceptEncoding PARAMS((HTList * list, char * enc, float quality)); PUBLIC void HTAcceptLanguage PARAMS((HTList * list, char * lang, float quality)); PUBLIC BOOL HTRank PARAMS((HTList * possibilities, HTList * accepted_content_types, HTList * accepted_content_languages, HTList * accepted_content_encodings));
#define INPUT_BUFFER_SIZE 4096 /* Tradeoff spped vs memory*/ typedef struct _socket_buffer { char input_buffer[INPUT_BUFFER_SIZE]; char * input_pointer; char * input_limit; int input_file_number; BOOL s_do_buffering; char * s_buffer; int s_buffer_size; char * s_buffer_cur; } HTInputSocket;
extern HTInputSocket* HTInputSocket_new PARAMS((int file_number));
extern int HTInputSocket_getCharacter PARAMS((HTInputSocket* isoc));
extern char * HTInputSocket_getBlock PARAMS((HTInputSocket * isoc, int * len));
extern void HTInputSocket_free PARAMS((HTInputSocket * isoc)); PUBLIC char * HTInputSocket_getLine PARAMS((HTInputSocket * isoc)); PUBLIC char * HTInputSocket_getUnfoldedLine PARAMS((HTInputSocket * isoc)); PUBLIC char * HTInputSocket_getStatusLine PARAMS((HTInputSocket * isoc)); PUBLIC BOOL HTInputSocket_seemsBinary PARAMS((HTInputSocket * isoc));
HTInputSocket_getStatusLine()
,
HTInputSocket_getUnfoldedLine()
and
HTInputSocket_getLine()
gets buffered after a call to
HTInputSocket_startBuffering()
until either
HTInputSocket_stopBuffering()
is called, or an empty line is
returned by any of these functions (end of body section).
HTInputSocket_getBuffer()
returns the number of
characters buffered, and sets the given buffer pointer to point to
internal buffer. This buffer exists until HTInputSocket
object is freed.
PUBLIC void HTInputSocket_startBuffering PARAMS((HTInputSocket * isoc)); PUBLIC void HTInputSocket_stopBuffering PARAMS((HTInputSocket * isoc)); PUBLIC int HTInputSocket_getBuffer PARAMS((HTInputSocket * isoc, char ** buffer_ptr));
The following have to be defined in advance of the other include files because of circular references.
typedef HTAtom * HTFormat; #include "HTAccess.h" /* Required for HTRequest definition */These macros (which used to be constants) define some basic internally referenced representations.
star/star is an output format which leaves the input untouched. It is useful for diagnostics, and for users who want to see the original, whatever it is.
#define WWW_SOURCE HTAtom_for("*/*") /* Whatever it was originally */www/present represents the user's perception of the document. If you convert to www/present, you present the material to the user.
#define WWW_PRESENT HTAtom_for("www/present") /* The user's perception */The message/rfc822 format means a MIME message or a plain text message with no MIME header. This is what is returned by an HTTP server.
#define WWW_MIME HTAtom_for("www/mime") /* A MIME message */www/print is like www/present except it represents a printed copy.
#define WWW_PRINT HTAtom_for("www/print") /* A printed copy */www/unknown is a really unknown type. Some default action is appropriate.
#define WWW_UNKNOWN HTAtom_for("www/unknown")
#define WWW_PLAINTEXT HTAtom_for("text/plain") #define WWW_POSTSCRIPT HTAtom_for("application/postscript") #define WWW_RICHTEXT HTAtom_for("application/rtf") #define WWW_AUDIO HTAtom_for("audio/basic") #define WWW_HTML HTAtom_for("text/html") #define WWW_BINARY HTAtom_for("application/octet-stream") #define WWW_VIDEO HTAtom_for("video/mpeg")Extra types used in the library
#define WWW_NEWSLIST HTAtom_for("text/newslist")We must include the following file after defining HTFormat, to which it makes reference.
typedef HTAtom* HTEncoding;The following are values for the MIME types:
#define WWW_ENC_7BIT HTAtom_for("7bit") #define WWW_ENC_8BIT HTAtom_for("8bit") #define WWW_ENC_BINARY HTAtom_for("binary")We also add
#define WWW_ENC_COMPRESS HTAtom_for("compress") #include "HTAnchor.h"
typedef struct _HTPresentation HTPresentation; typedef HTStream * HTConverter PARAMS(( HTRequest * request, void * param, HTFormat input_format, HTFormat output_format, HTStream * output_stream)); struct _HTPresentation { HTAtom* rep; /* representation name atomized */ HTAtom* rep_out; /* resulting representation */ HTConverter *converter; /* The routine to gen the stream stack */ char * command; /* MIME-format string */ float quality; /* Between 0 (bad) and 1 (good) */ float secs; float secs_per_byte; };A global list of converters is kept by this module. It is also scanned by modules which want to know the set of formats supported. for example. Note there is also an additional list associated with each request.
extern HTList * HTConversions ;
extern void HTSetPresentation PARAMS(( HTList * conversions, CONST char * representation, CONST char * command, float quality, float secs, float secs_per_byte ));
extern void HTSetConversion PARAMS(( HTList * conversions, CONST char * rep_in, CONST char * rep_out, HTConverter * converter, float quality, float secs, float secs_per_byte ));
If guess
is true and input format is
www/unknown
, try to guess the format
by looking at the first few butes of the stream.
extern HTStream * HTStreamStack PARAMS(( HTFormat format_in, HTRequest * request, BOOL guess));
extern float HTStackValue PARAMS(( HTList * conversions, HTFormat format_in, HTFormat format_out, float initial_value, long int length)); #define NO_VALUE_FOUND -1e20 /* returned if none found */
extern int HTCopy PARAMS(( int file_number, HTStream* sink));
extern void HTFileCopy PARAMS(( FILE* fp, HTStream* sink));
extern void HTCopyNoCR PARAMS(( int file_number, HTStream* sink));
extern int HTParseSocket PARAMS(( HTFormat format_in, int file_number, HTRequest * request));
extern int HTParseFile PARAMS(( HTFormat format_in, FILE *fp, HTRequest * request));
extern HTStream * HTNetToText PARAMS ((HTStream * sink));
extern void HTFormatInit PARAMS((HTList * conversions));
extern void HTFormatInitNIM PARAMS((HTList * conversions));
extern void HTFormatDelete PARAMS((HTList * conversions));
extern BOOL HTOutputSource; /* Flag: shortcut parser */ #endifend