?? htformat.h
字號(hào):
/* W3C Sample Code Library libwww Stream Pipe Manager! The Stream Pipe Manager!*//*** (c) COPYRIGHT MIT 1995.** Please first read the full copyright statement in the file COPYRIGH.*//*The Stream Pipe Manager is responsible for setting up the stream pipe fromthe Channel Object to theRequest Object when data is arriving, for exampleas a response to s HTTP Get request. As dataarrives, we start to parse it and the more we know the more we can buildup our stream pipe. For example, in the case of HTTP, we first have a streamthat can parse the HTTP response line containing "200 OK". Thenwe have a MIME parser for handling the MIME headers.When the MIME headers have been parsed, we know the content type and anyencoding of the MIME body. If we need to decode a chunked encoding then weset up a chunked decoder, and if we have to parse a HTML object then we setup a HTML parser.The Format Manager is also responsible for keeping track of the"preferences" of the application and/or user. It is an integral partof the Web and HTTP, that the client application can express its preferencesas a set of "accept" headers in a HTTP request. This task is highly relatedto the task mentioned above as we there use the modules that are registeredand here tell the remote server what we are capable of doing and what wewould prefer.Note: The library core does not define any default decodersor parsers - they are all considered part of the application. The librarycomes with a default set of parsers including the ones mentioned above whichcan be initiated using the functions in HTInitmodule. There are different initialization functions for content typeparsers and content encodings respectively. o Content Type Converters and Presenters o Content Encoders and Decoders o Content Charsets o Natural Languages The application can assign its preferences in two ways: either locallyto a single request or globally to all requests. The local assignmentcan either add to or override the global settings dependingon how they are registered. All local registration is handled by theRequest Object and the global registration is handledby the Format Manager.This module is implemented by HTFormat.c, and itis a part of the W3C Sample CodeLibrary.*/#ifndef HTFORMAT_H#define HTFORMAT_H#include "HTUtils.h"#include "HTStream.h"#include "HTAtom.h"#include "HTList.h"#include "HTAnchor.h"#include "HTReq.h"/*. Converters and Presenters.All content type converters are subclassed from the Generic stream objetc.That way, we allow the application to do very fast progressive display ofincoming data. In other words, the stream model of the Library provides dataas soon as it arrives from the network, the application does not have towait until the whole document has been down loaded before it starts parsingit.( Predefined Content Types)These macros (which used to be constants) define some basic internally referencedrepresentations. The www/xxx ones are of course not MIME standard.They are internal representations used in the Library but they can't be exportedto other apps!*/#define WWW_INTERNAL HTAtom_for("www/*") /* All internal formats *//*WWW_INTERNAL represent all internal formats. This can for examplebe used to match using the HTMIMEMatch(...).*/#define WWW_RAW HTAtom_for("www/void") /* Raw output from Protocol *//*WWW_RAW is an output format which leaves the input untouchedexactly as it is received by the protocol module. For example, inthe case of FTP, this format returns raw ASCII objects for directory listings;for HTTP, everything including the header is returned, for Gopher, a rawASCII object is returned for a menu etc.*/#define WWW_SOURCE HTAtom_for("*/*")/*WWW_SOURCE is an output format which leaves the input untouchedexactly as it is received by the protocol module IF not asuitable converter has been registered with a quality factor higher than1 (for example 2). In this case the SUPER CONVERTER is preferredfor the raw output. This can be used as a filter effect that allows conversionfrom, for example raw FTPdirectory listings into HTML but passes a MIME bodyuntouched.*/#define WWW_PRESENT HTAtom_for("www/present")/*WWW_PRESENT represents the user's perception of the document.If you convert to WWW_PRESENT, you present the material to theuser.*/#define WWW_DEBUG HTAtom_for("www/debug")/*WWW_DEBUG represents the user's perception of debug information,for example sent as a HTML document in a HTTP redirection message.*/#define WWW_UNKNOWN HTAtom_for("www/unknown")/*WWW_UNKNOWN is a really unknown type. It differs from the realMIME type "application/octet-stream" in that we haven't even triedto figure out the content type at this point.*/#define WWW_CACHE HTAtom_for("www/cache")#define WWW_CACHE_APPEND HTAtom_for("www/cache-append")/*WWW_CACHE is the internal content-type designated for a persistentcache module which can store the object to local storage. The cache appendformat is special in that we append information to an already existing cacheentry. This can happen if we have issued a If-Range requestand got back a "206 Partial response".These are regular MIME types defined. Others can be added!*/#define WWW_HTML HTAtom_for("text/html")#define WWW_PLAINTEXT HTAtom_for("text/plain")#define WWW_FORM HTAtom_for("application/x-www-form-urlencoded")#define WWW_MIME HTAtom_for("message/rfc822")#define WWW_MIME_HEAD HTAtom_for("message/x-rfc822-head")#define WWW_MIME_FOOT HTAtom_for("message/x-rfc822-foot")#define WWW_MIME_PART HTAtom_for("message/x-rfc822-partial")#define WWW_MIME_CONT HTAtom_for("message/x-rfc822-cont")#define WWW_MIME_UPGRADE HTAtom_for("message/x-rfc822-upgrade")#define WWW_MIME_COPYHEADERS HTAtom_for("www/x-rfc822-headers")#define WWW_AUDIO HTAtom_for("audio/basic")#define WWW_VIDEO HTAtom_for("video/mpeg")#define WWW_GIF HTAtom_for("image/gif")#define WWW_JPEG HTAtom_for("image/jpeg")#define WWW_TIFF HTAtom_for("image/tiff")#define WWW_PNG HTAtom_for("image/png")#define WWW_BINARY HTAtom_for("application/octet-stream")#define WWW_POSTSCRIPT HTAtom_for("application/postscript")#define WWW_RICHTEXT HTAtom_for("application/rtf")/*We also have some MIME types that come from the various protocols when weconvert from ASCII to HTML.*/#define WWW_GOPHER_MENU HTAtom_for("text/x-gopher")#define WWW_CSO_SEARCH HTAtom_for("text/x-cso")#define WWW_FTP_LNST HTAtom_for("text/x-ftp-lnst")#define WWW_FTP_LIST HTAtom_for("text/x-ftp-list")#define WWW_NNTP_LIST HTAtom_for("text/x-nntp-list")#define WWW_NNTP_OVER HTAtom_for("text/x-nntp-over")#define WWW_NNTP_HEAD HTAtom_for("text/x-nntp-head")#define WWW_HTTP HTAtom_for("text/x-http")/*Finally we have defined a special format for our RULE files as they can behandled by a special converter.*/#define WWW_RULES HTAtom_for("application/x-www-rules")/*( The Quality Factor)Characteristic for all preferences is that there is a quality factor associatedwith each member. The quality factor is a real number between 0 and 1 with0 meaning "very bad" and 1 means "perfect". By registering a natural languageor any or other preference in this group together with a quality factor youcan specify "how well the preference is handled" either by the applicationor by the user. In the case of the user the quality factor of a natural languageis how well the user understands the language. In my case, the quality factorsfor, for example Greek would be close to zero and 1 for Danish (nothing badsaid about Greek!).It is a bit different for converters where it is often the application'sability of handling the data format rather than the user's perception. Asan example it is often faster to use a converter than a presenter as it takestime to launch the external application and libwww can not use progressivedisplay mechanisms which is often the case for converters. Therefore, asan example, if we capable of handling an image in png format inlinebut rely on an external viewer for presenting postscript, we might set upthe following list:HTConversion_add (converters, "image", "www/present", GifPresenter,1.0, 0.0, 0.0);HTPresentation_add (presenters, "application/postscript", "ghostview %s",NULL, 0.5, 0.0, 0.0);>where the gif converter is registered with a quality factor of 1.0and the postscript presenter with a quality factor of 0.5.RegisterPresenters( The Converter Class)A converter is a stream with a special set of parameters andwhich is registered as capable of converting from a MIME type to somethingelse (maybe another MIME-type). A converter is defined to be a function returninga stream and accepting the following parameters. The content type elementsare atoms for which we have defined a prototype.*/typedef HTStream * HTConverter (HTRequest * request, void * param, HTFormat input_format, HTFormat output_format, HTStream * output_stream);extern void HTConversion_add (HTList * conversions, const char * rep_in, const char * rep_out, HTConverter * converter, double quality, double secs, double secs_per_byte);extern void HTConversion_deleteAll (HTList * list);/*( The Presenter Class)A presenter is a module (possibly an external program) whichcan present a graphic object of a certain MIME type to the user. That is,presenters are normally used to present objects that theconverters are not able to handle. Data is transferred to theexternal program using a special "presenter stream" which for example canuse the local disk to transfer the data from libwww to the external program.Libwww provides a default HTSaveAndExecutestream which you may want to use for this purpose. However, any streamthat is of type HTConverter will do. You can manage thespecial presenter stream using the following methods:*/extern void HTPresentation_setConverter (HTConverter * pconv);extern HTConverter * HTPresentation_converter (void);/*Both presenters and converters are of the typeHTConverter.*/extern void HTPresentation_add (HTList * conversions, const char * representation, const char * command, const char * test_command, double quality, double secs, double secs_per_byte);extern void HTPresentation_deleteAll (HTList * list);/*( Basic Converters)We have a small set of basic converters that can be hooked in anywhere. Theydon't "convert" anything but are nice to have.*/extern HTConverter HTThroughLine;extern HTConverter HTBlackHoleConverter;extern HTConverter HTSaveConverter;/*. Content and Transfer Encoders and Decoders.Content codins are transformations applied to an entity object after it wascreated in its original form. The Library handles two types of codings: Content Codings Content codings values indicate an encoding transformation that has been applied to a resource. Content cosings are primarily used to allow a document to be compressed or encrypted without loosing the identity of its underlying media type. Content Transfer Codings Content transfer codings values are used to indicate an encoding transformation that has been, can be, or may be need to be applied to an enity body in order to ensure safe transport through the network. This differs from a content coding in that the transfer coding is a property of the message, not the original message.Both types of encodings use the same registration mechanism in the Librarywhich we describe below:( Encoders and Decoders)Encoders and decoders are subclassed from thegeneric stream class. Encoders are capableof adding a content coding to a data object and decoders can removea content coding.*/typedef HTStream * HTCoder (HTRequest * request, void * param, HTEncoding coding, HTStream * target);/*The encoding is the name of the encoding mechanism reporesentedas an atom, for example "zip", "chunked", etc.Encodings are registered in lists and content encodings are separated fromtransfer encodings by registering them in different lists.( Basic Encoders)We have a small set of basic coders that can be hooked in anywhere.
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -