HTReq.h
上传用户:zlh9724
上传日期:2007-01-04
资源大小:1991k
文件大小:21k
源码类别:

浏览器

开发平台:

Unix_Linux

  1. /*                                                      Public Declaration of Request Manager
  2.                           PUBLIC DECLARATION OF REQUEST MANAGER
  3.                                              
  4.  */
  5. /*
  6. **      (c) COPYRIGHT MIT 1995.
  7. **      Please first read the full copyright statement in the file COPYRIGH.
  8. */
  9. /*
  10.    The request manager consists of two parts: a public part and a private part. The public
  11.    part contains all the information needed to define a request the parameters to be used
  12.    when requesting a resource from the network or local file system. When a request is
  13.    handled, all kinds of things about it need to be passed along together with a request.
  14.    
  15.    This module is implemented by HTReqMan.c, and it is a part of the  W3C Reference
  16.    Library.
  17.    
  18.  */
  19. #ifndef HTREQ_H
  20. #define HTREQ_H
  21. typedef long HTRequestID;
  22. typedef struct _HTRequest HTRequest;
  23. #include "HTList.h"
  24. #include "HTFormat.h"
  25. #include "HTStream.h"
  26. #include "HTEvntrg.h"
  27. #include "HTError.h"
  28. #include "HTNet.h"
  29. /*
  30. Request a resource
  31.    This is an internal routine, which has an address AND a matching anchor.  (The public
  32.    routines are called with one OR the other.)
  33.    
  34.  */
  35. extern BOOL HTLoad (HTRequest * request, BOOL recursive);
  36. /*
  37. Creation and Deletion Methods
  38.    The request object is intended to live as long as the request is still active, but can
  39.    be deleted as soon as it has terminatedk, for example in one of the request termination
  40.    callback functions as described in the Net Manager. Only the anchor object stays around
  41.    after the request itself is terminated.
  42.    
  43.   CREATE NEW OBJECT
  44.   
  45.    Creates a new request object with a default set of options -- in most cases it will
  46.    need some information added which can be done using the methods in this module, but it
  47.    will work as is for a simple request.
  48.    
  49.  */
  50. extern HTRequest * HTRequest_new (void);
  51. /*
  52.   CLEAR A REQUEST OBJECT
  53.   
  54.    Clears all protocol specific information so that the request object can be used for
  55.    another request. It should be use with care as application specific information is not
  56.    re-initialized. Returns YES if OK, else NO.
  57.    
  58.  */
  59. extern BOOL HTRequest_clear (HTRequest * me);
  60. /*
  61.   CREATE A DUPLICATE
  62.   
  63.    Creates a new HTRequest object as a duplicate of the src request. Returns YES if OK,
  64.    else NO
  65.    
  66.  */
  67. extern HTRequest * HTRequest_dup (HTRequest * src);
  68. /*
  69.     Create a duplicate for Internal use
  70.     
  71.    Creates a new HTRequest object as a duplicate of the src request.  The difference to
  72.    the HTRequest_dup function is that we don't copy the error_stack and other information
  73.    that the application keeps in its copy of the request object. Otherwise it will be
  74.    freed multiple times. Returns YES if OK, else NO
  75.    
  76.  */
  77. extern HTRequest * HTRequest_dupInternal (HTRequest * src);
  78. /*
  79.   DELETE OBJECT
  80.   
  81.    This function deletes the object and cleans up the memory.
  82.    
  83.  */
  84. extern void HTRequest_delete (HTRequest * request);
  85. /*
  86. Bind an Anchor to a Request Object
  87.    Every request object has an anchor associated with it. The anchor normally lives until
  88.    the application terminates but a request object only lives as long as the request is
  89.    being serviced.
  90.    
  91.  */
  92. extern void HTRequest_setAnchor (HTRequest *request, HTAnchor *anchor);
  93. extern HTParentAnchor * HTRequest_anchor (HTRequest *request);
  94. /*
  95. Bind an Access to a request
  96.    This is done if you are a server. In this case you do not need an anchor
  97.    
  98.  */
  99. #if 0
  100. extern void HTRequest_setAccess (HTRequest * request, char * access);
  101. extern CONST char * HTRequest_access (HTRequest * request);
  102. #endif
  103. /*
  104. Set the Method
  105.    The Method is the operation to be executed on the requested object. The default set if
  106.    the set of operations defined by the HTTP protocol, that is "GET", "HEAD", "PUT",
  107.    "POST", "LINK", "UNLINK", and "DELETE" but many of these can be used in other protocols
  108.    as well. The important thing is to think of the requested element as an object on which
  109.    you want to perform an operation. Then it is for the specific protocol implementation
  110.    to try and carry this operation out. However, not all operations can be implemented (or
  111.    make sense) in all protocols.
  112.    
  113.    Methods are handled by the Method Module, and the default value is "GET".
  114.    
  115.  */
  116. extern void HTRequest_setMethod (HTRequest *request, HTMethod method);
  117. extern HTMethod HTRequest_method (HTRequest *request);
  118. /*
  119. Update, Reload, or Refresh a Document
  120.    The Library has two concepts of caching: in memory and on file. When loading a
  121.    document, this flag can be set in order to define who can give a response to the
  122.    request. IMS means that a "If-Modified-Since" Header is used in a HTTP request.
  123.    
  124.  */
  125. typedef enum _HTReload {
  126.     HT_ANY_VERSION      = 0x0,          /* Use any version available */
  127.     HT_MEM_REFRESH      = 0x1,          /* Reload from file cache or network */
  128.     HT_CACHE_REFRESH    = 0x2,          /* Update from network with IMS */
  129.     HT_FORCE_RELOAD     = 0x4           /* Update from network with no-cache */
  130. } HTReload;
  131. extern void HTRequest_setReloadMode (HTRequest *request, HTReload mode);
  132. extern HTReload HTRequest_reloadMode (HTRequest *request);
  133. /*
  134. Redirections
  135.    When a redirection response is returned to the Library, for example from a remote HTTP
  136.    server, this code is passed back to the application. The application can then decide
  137.    whether a new request should be established or not. These two methods return the
  138.    redirection information required to issue a new request, that is the new anchor and any
  139.    list of keywords associated with this anchor.
  140.    
  141.  */
  142. extern HTAnchor * HTRequest_redirection (HTRequest * request);
  143. /*
  144. Max number of Retrys for a Down Load
  145.    Automatic reload can happen in two situations:
  146.    
  147.       The server sends a redirection response
  148.       
  149.       The document has expired
  150.       
  151.    In order to avoid the Library going into an infinite loop, it is necessary to keep
  152.    track of the number of automatic reloads. Loops can occur if the server has a reload to
  153.    the same document or if the server sends back a Expires header which has already
  154.    expired. The default maximum number of automatic reloads is 6.
  155.    
  156.  */
  157. extern BOOL HTRequest_setMaxRetry (int newmax);
  158. extern int  HTRequest_maxRetry (void);
  159. extern BOOL HTRequest_retry (HTRequest *request);
  160. /*
  161. Retry Request After
  162.    Some services, for example HTTP, can in case they are unavailable at the time the
  163.    request is issued send back a time and date stamp to the client telling when they are
  164.    expected to back online. In case a request results in a HT_RETRY status, the
  165.    application can use any time indicated in this field to retry the request at a later
  166.    time. The Library does not initiate any request on its own - it's for the application
  167.    to do. The time returned by this function is in calendar time or -1 if not available.
  168.    
  169.  */
  170. extern time_t HTRequest_retryTime (HTRequest * request);
  171. /*
  172. Accept Headers
  173.    The Accept family of headers is an important part of HTTP handling the format
  174.    negotiation. The Library supports both a global set of accept headers that are used in
  175.    all HTTP requests and a local set of accept headers that are used in specific requests
  176.    only. The global ones are defined in the Format Manager.
  177.    
  178.    Each request can have its local set of accept headers that either are added to the
  179.    global set or replaces the global set of accept headers. Non of the headers have to be
  180.    set. If the global set is sufficient for all requests then this us perfectly fine. If
  181.    the parameter "override" is set then only local accept headers are used, else both
  182.    local and global headers are used.
  183.    
  184.   CONTENT TYPES
  185.   
  186.    The local list of specific conversions which the format manager can do in order to
  187.    fulfill the request.  It typically points to a list set up on initialisation time for
  188.    example by HTInit(). There is also a global list of conversions which contains a
  189.    generic set of possible conversions.
  190.    
  191.  */
  192. extern void HTRequest_setConversion (HTRequest *request, HTList *type, BOOL override);
  193. extern HTList * HTRequest_conversion (HTRequest *request);
  194. /*
  195.   CONTENT ENCODINGS
  196.   
  197.    The list of encodings acceptable in the output stream.
  198.    
  199.  */
  200. extern void HTRequest_setEncoding (HTRequest *request, HTList *enc, BOOL override);
  201. extern HTList * HTRequest_encoding (HTRequest *request);
  202. /*
  203.   CONTENT-LANGUAGES
  204.   
  205.    The list of (human) language values acceptable in the response. The default is all
  206.    languages.
  207.    
  208.  */
  209. extern void HTRequest_setLanguage (HTRequest *request, HTList *lang, BOOL override);
  210. extern HTList * HTRequest_language (HTRequest *request);
  211. /*
  212.   CHARSET
  213.   
  214.    The list of charsets accepted by the application
  215.    
  216.  */
  217. extern void HTRequest_setCharset (HTRequest *request, HTList *charset, BOOL override);
  218. extern HTList * HTRequest_charset (HTRequest *request);
  219. /*
  220. Handling Metainformation (RFC822 Headers)
  221.    The Library supports a large set of headers that can be sent along with a request (or a
  222.    response for that matter). All headers can be either disabled or enabled using bit
  223.    flags that are defined in the following.
  224.    
  225.   GENERAL HTTP HEADER MASK
  226.   
  227.    There are a few header fields which have general applicability for both request and
  228.    response mesages, but which do not apply to the communication parties or theentity
  229.    being transferred. This mask enables and disables these headers. If the bit is not
  230.    turned on they are not sent. All headers are optional and the default value is NO
  231.    GENERAL HEADERS
  232.    
  233.  */
  234. typedef enum _HTGnHd {
  235.     HT_G_DATE           = 0x1,
  236.     HT_G_FORWARDED      = 0x2,
  237.     HT_G_MESSAGE_ID     = 0x4,
  238.     HT_G_MIME           = 0x8,
  239.     HT_G_CONNECTION     = 0x10,
  240.     HT_G_NO_CACHE       = 0x20                                     /* Pragma */
  241. } HTGnHd;
  242. #define DEFAULT_GENERAL_HEADERS         HT_G_CONNECTION
  243. extern void HTRequest_setGnHd (HTRequest *request, HTGnHd gnhd);
  244. extern void HTRequest_addGnHd (HTRequest *request, HTGnHd gnhd);
  245. extern HTGnHd HTRequest_gnHd (HTRequest *request);
  246. /*
  247.   REQUEST HEADERS
  248.   
  249.    The request header fields allow the client to pass additional information about the
  250.    request (and about the client itself) to the server. All headers are optional but the
  251.    default value is all request headers if present except From and Pragma.
  252.    
  253.  */
  254. typedef enum _HTRqHd {
  255.     HT_C_ACCEPT_TYPE    = 0x1,
  256.     HT_C_ACCEPT_CHAR    = 0x2,
  257.     HT_C_ACCEPT_ENC     = 0x4,
  258.     HT_C_ACCEPT_LAN     = 0x8,
  259.     HT_C_FROM           = 0x10,
  260.     HT_C_IMS            = 0x20,
  261.     HT_C_HOST           = 0x40,
  262.     HT_C_REFERER        = 0x80,
  263.     HT_C_USER_AGENT     = 0x200
  264. } HTRqHd;
  265. #define DEFAULT_REQUEST_HEADERS 
  266.         HT_C_ACCEPT_TYPE+HT_C_ACCEPT_CHAR+ 
  267.         HT_C_ACCEPT_ENC+HT_C_ACCEPT_LAN+HT_C_REFERER+HT_C_USER_AGENT
  268. extern void HTRequest_setRqHd (HTRequest *request, HTRqHd rqhd);
  269. extern void HTRequest_addRqHd (HTRequest *request, HTRqHd rqhd);
  270. extern HTRqHd HTRequest_rqHd (HTRequest *request);
  271. /*
  272.   RESPONSE HEADERS
  273.   
  274.    The response header fields allow the server to pass additional information about the
  275.    response (and about the server itself) to the client. All headers are optional.
  276.    
  277.  */
  278. typedef enum _HTRsHd {
  279.     HT_S_LOCATION       = 0x1,
  280.     HT_S_PROXY_AUTH     = 0x2,
  281.     HT_S_PUBLIC         = 0x4,
  282.     HT_S_RETRY_AFTER    = 0x8,
  283.     HT_S_SERVER         = 0x10,
  284.     HT_S_WWW_AUTH       = 0x20
  285. } HTRsHd;
  286. #define DEFAULT_RESPONSE_HEADERS HT_S_SERVER
  287. extern void HTRequest_setRsHd (HTRequest * request, HTRsHd rshd);
  288. extern void HTRequest_addRsHd (HTRequest * request, HTRsHd rshd);
  289. extern HTRsHd HTRequest_rsHd (HTRequest * request);
  290. /*
  291.   ENTITY HEADER MASK
  292.   
  293.    The entity headers contain information about the object sent in the HTTP transaction.
  294.    See the Anchor module, for the storage of entity headers. This flag defines which
  295.    headers are to be sent in a request together with an entity body. All headers are
  296.    optional but the default value is ALL ENTITY HEADERS IF PRESENT
  297.    
  298.  */
  299. typedef enum _HTEnHd {
  300.     HT_E_ALLOW          = 0x1,
  301.     HT_E_CONTENT_ENCODING = 0x2,
  302.     HT_E_CONTENT_LANGUAGE = 0x4,
  303.     HT_E_CONTENT_LENGTH = 0x8,
  304.     HT_E_CTE            = 0x10,                 /* Content-Transfer-Encoding */
  305.     HT_E_CONTENT_TYPE   = 0x20,
  306.     HT_E_DERIVED_FROM   = 0x40,
  307.     HT_E_EXPIRES        = 0x80,
  308.     HT_E_LAST_MODIFIED  = 0x200,
  309.     HT_E_LINK           = 0x400,
  310.     HT_E_TITLE          = 0x800,
  311.     HT_E_URI            = 0x1000,
  312.     HT_E_VERSION        = 0x2000
  313. } HTEnHd;
  314. #define DEFAULT_ENTITY_HEADERS          0xFFFF                        /* all */
  315. extern void HTRequest_setEnHd (HTRequest *request, HTEnHd enhd);
  316. extern void HTRequest_addEnHd (HTRequest *request, HTEnHd enhd);
  317. extern HTEnHd HTRequest_enHd (HTRequest *request);
  318. /*
  319.   REFERER FIELD
  320.   
  321.    If this parameter is set then a `Referer: <parent address> can be generated in the
  322.    request to the server, see Referer field in a HTTP Request
  323.    
  324.  */
  325. extern void HTRequest_setParent (HTRequest *request, HTParentAnchor *parent);
  326. extern HTParentAnchor * HTRequest_parent (HTRequest *request);
  327. /*
  328.   SENDING DATA TO THE NETWORK
  329.   
  330.    The Library supports two ways of posting a data object to a remote destination: Input
  331.    comes from a socket descriptor or from memory. In the case where you want to copy a
  332.    URL, for example from local file system or from a remote HTTP server then you must use
  333.    the POSTWeb design. This model operates by using at least two request objects which
  334.    gets linked to eachother as part of the POSTWeb model. However, if you are posting from
  335.    memory, we only use one request object to perform the operation. In order to do this,
  336.    the application must register a callback function that can be called when the HTTP
  337.    client module is ready for accepting data. be included as part of the body and/or as
  338.    extra metainformation. In the latter case you need to register a callback function of
  339.    the following type using the methods provided in the next section.
  340.    
  341.  */
  342. typedef int HTPostCallback (HTRequest * request, HTStream * target);
  343. /*
  344.   EXTRA HEADERS
  345.   
  346.    Extra header information can be send along with a request using this variable. The text
  347.    is sent as is so it must be preformatted with <CRLF> line terminators. This will get
  348.    changed at some point so that you can register a header together with a handler in the
  349.    MIME parser.
  350.    
  351.  */
  352. extern void HTRequest_setGenerator (HTRequest *request, HTList *gens, BOOL override);
  353. extern HTList * HTRequest_generator (HTRequest *request, BOOL *override);
  354. extern void HTRequest_setParser (HTRequest *request, HTList *pars, BOOL override);
  355. extern HTList * HTRequest_parser (HTRequest *request, BOOL *override);
  356. /*
  357. Streams From Network to Application
  358.   DEFAULT OUTPUT STREAM
  359.   
  360.    The output stream is to be used to put data down to as they come in from the network
  361.    and back to the application. The default value is NULL which means that the stream goes
  362.    to the user (display).
  363.    
  364.  */
  365. extern void HTRequest_setOutputStream (HTRequest *request, HTStream *output);
  366. extern HTStream *HTRequest_outputStream (HTRequest *request);
  367. /*
  368.    The desired format of the output stream. This can be used to get unconverted data etc.
  369.    from the library. If NULL, then WWW_PRESENT is default value.
  370.    
  371.  */
  372. extern void HTRequest_setOutputFormat (HTRequest *request, HTFormat format);
  373. extern HTFormat HTRequest_outputFormat (HTRequest *request);
  374. /*
  375.   DEBUG STREAM
  376.   
  377.    All object bodies sent from the server with status codes different from 200 OK will be
  378.    put down this stream. This can be used for redirecting body information in status codes
  379.    different from "200 OK" to for example a debug window. If the value is NULL (default)
  380.    then the stream is not set up.
  381.    
  382.  */
  383. extern void HTRequest_setDebugStream (HTRequest *request, HTStream *debug);
  384. extern HTStream *HTRequest_debugStream (HTRequest *request);
  385. /*
  386.    The desired format of the error stream. This can be used to get unconverted data etc.
  387.    from the library. The default value if WWW_HTML as a character based only has one
  388.    WWW_PRESENT.
  389.    
  390.  */
  391. extern void HTRequest_setDebugFormat (HTRequest *request, HTFormat format);
  392. extern HTFormat HTRequest_debugFormat (HTRequest *request);
  393. /*
  394. Context Swapping
  395.    In multi threaded applications it is often required to keep track of the context of a
  396.    request so that when the Library returns a result of a request, it can be put into the
  397.    context it was in before the request was first passed to the Library. This call back
  398.    function allows the application to do this.
  399.    
  400.  */
  401. typedef int HTRequestCallback (HTRequest * request, void *param);
  402. extern void HTRequest_setCallback (HTRequest *request, HTRequestCallback *cb);
  403. extern HTRequestCallback *HTRequest_callback (HTRequest *request);
  404. /*
  405.    The callback function can be passed an arbitrary pointer (the void part) which can
  406.    describe the context of the current request structure. If such context information is
  407.    required then it can be set using the following methods:
  408.    
  409.  */
  410. extern void HTRequest_setContext (HTRequest *request, void *context);
  411. extern void *HTRequest_context (HTRequest *request);
  412. /*
  413. Using a proxy server
  414.    As a HTTP request looks different when it is directed to a proxy server than to a
  415.    origin server, we need to know whether we are using a proxy for this particular request
  416.    or not. These two methods can be used to set and check the current state whether we are
  417.    going to a proxy or not.
  418.    
  419.  */
  420. extern void HTRequest_setProxying (HTRequest * request, BOOL proxying);
  421. extern BOOL HTRequest_proxying (HTRequest * request);
  422. /*
  423. Preemptive or Non-preemptive Access
  424.    A access scheme is defined with a default for using either preemptive (blocking I/O) or
  425.    non-premitve (non-blocking I/O). This is basically a result of the implementation of
  426.    the protocol module itself. However, if non-blocking I/O is the default then some times
  427.    it is nice to be able to set the mode to blocking instead. For example when loading the
  428.    first document (the home page) then blocking can be used instead of non-blocking.
  429.    
  430.  */
  431. extern void HTRequest_setPreemptive (HTRequest *request, BOOL mode);
  432. extern BOOL HTRequest_preemptive (HTRequest *request);
  433. /*
  434. Priority Management
  435.    The request can be assigned an initial priority which then gets inherited by all HTNet
  436.    objects and other requests objects created as a result of this one. You can also assign
  437.    a separate priority to an indicidual HTNet object by using the methods in the Net
  438.    manager.
  439.    
  440.  */
  441. extern HTPriority HTRequest_priority (HTRequest * request);
  442. extern BOOL HTRequest_setPriority (HTRequest * request, HTPriority priority);
  443. /*
  444. Get an set the HTNet Object
  445.    If a request is actually going on the net then the Net MAnager is contacted to handle
  446.    the request. The Net manager creates a HTNEt object and links it to the Request object.
  447.    You can get to the HTNet object using the following functions.
  448.    
  449.  */
  450. extern HTNet * HTRequest_net (HTRequest * request);
  451. extern BOOL HTRequest_setNet (HTRequest * request, HTNet * net);
  452. /*
  453. Format Negotiation
  454.    When accessing the local file system, the Library is capable of performing content
  455.    negotioation as described by the HTTP protocol. This is mainly for server applications,
  456.    but some client applications might also want to use content negotiation when accessing
  457.    the local file system. This method enables or disables content negotiation - the
  458.    default value is ON.
  459.    
  460.  */
  461. extern void HTRequest_setNegotiation (HTRequest *request, BOOL mode);
  462. extern BOOL HTRequest_negotiation (HTRequest *request);
  463. /*
  464. Error Manager
  465.    Errors are like almost anything kept in lists and a error list can be associated with a
  466.    request using the following functions. In order to make life easier, there are also
  467.    some easy mapping functions to the real HTError module, so that you can add an error
  468.    directly to a request object.
  469.    
  470.  */
  471. extern HTList * HTRequest_error (HTRequest * request);
  472. extern void HTRequest_setError  (HTRequest * request, HTList * list);
  473. /*
  474.    These are the cover functions that go directly to the Error manager
  475.    
  476.  */
  477. extern BOOL HTRequest_addError (HTRequest *     request,
  478.                                 HTSeverity      severity,
  479.                                 BOOL            ignore,
  480.                                 int             element,
  481.                                 void *          par,
  482.                                 unsigned int    length,
  483.                                 char *          where);
  484. extern BOOL HTRequest_addSystemError (HTRequest *       request,
  485.                                       HTSeverity        severity,
  486.                                       int               errornumber,
  487.                                       BOOL              ignore,
  488.                                       char *            syscall);
  489. /*
  490. Bytes Read or Written in a Request
  491.    This function returns the bytes read in the current request. For a deeper description
  492.    of what the current request is, please read the user's guide. This function can be used
  493.    in for example the HTAlert module to give the number of bytes read or written in a
  494.    progress message.
  495.    
  496.  */
  497. extern long HTRequest_bytesRead (HTRequest * request);
  498. extern long HTRequest_bytesWritten (HTRequest * request);
  499. /*
  500. Kill a Request
  501.    This function kills this particular request, see HTNet module for a function that kills
  502.    them all.
  503.    
  504.  */
  505. extern BOOL HTRequest_kill(HTRequest * request);
  506. /*
  507.  */
  508. #endif /* HTREQ_H */
  509. /*
  510.    End of declaration */