Back to index

avfs  1.0.1
http_private.h
Go to the documentation of this file.
00001 /* 
00002    HTTP Request Handling
00003    Copyright (C) 1999-2001, Joe Orton <joe@light.plus.com>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009    
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00018    MA 02111-1307, USA
00019 
00020 */
00021 
00022 /* THIS IS NOT A PUBLIC INTERFACE. You CANNOT include this header file
00023  * from an application.  */
00024  
00025 #ifndef HTTP_PRIVATE_H
00026 #define HTTP_PRIVATE_H
00027 
00028 #include "http_auth.h"
00029 
00030 struct host_info {
00031     /* hostname is not const since it changes on redirects. */
00032     char *hostname;
00033     int port;
00034     struct in_addr addr;
00035     char *hostport; /* URI hostport segment */
00036     http_auth_session auth;
00037     http_request_auth auth_callback;
00038     void *auth_userdata;
00039 };
00040 
00041 typedef enum {
00042     body_buffer,
00043     body_stream,
00044     body_none
00045 } request_body;
00046 
00047 /* This is called with each of the headers in the response */
00048 struct header_handler {
00049     char *name;
00050     http_header_handler handler;
00051     void *userdata;
00052     struct header_handler *next;
00053 };
00054 
00055 /* TODO: could unify these all into a generic callback list */
00056 
00057 struct body_reader {
00058     http_block_reader handler;
00059     http_accept_response accept_response;
00060     unsigned int use:1;
00061     void *userdata;
00062     struct body_reader *next;
00063 };
00064 
00065 /* Store hook information */
00066 struct hook {
00067     const http_request_hooks *hooks;
00068     void *private;
00069     struct hook *next;
00070 };
00071 
00072 /* Per-request store for hooks.
00073  * This is a bit noddy really. */
00074 struct hook_request {
00075     struct hook *hook;
00076     void *cookie;
00077     struct hook_request *next;
00078 };
00079 
00080 #define HAVE_HOOK(st,func) (st->hook->hooks->func != NULL)
00081 #define HOOK_FUNC(st, func) (*st->hook->hooks->func)
00082 
00083 /* Session support. */
00084 struct http_session_s {
00085     /* Connection information */
00086     nsocket *socket;
00087 
00088     struct host_info server, proxy;
00089 
00090     /* Connection states:
00091      *   0:  Not connected at all.
00092      *   1:  We have a TCP connection to the next-hop server.
00093      *   2:  We have a negotiated an SSL connection over the proxy's 
00094      *       TCP tunnel.
00095      *
00096      * Note, 1 is all we need if we don't have a proxy server, or
00097      * if we do have a proxy server and we're not using SSL.
00098      */
00099     unsigned int connected:2;
00100 
00101     /* Settings */
00102     unsigned int have_proxy:1; /* do we have a proxy server? */
00103     unsigned int no_persist:1; /* set to disable persistent connections */
00104     unsigned int use_secure:1; /* whether a secure connection is required */
00105     int expect100_works:2; /* known state of 100-continue support */
00106     unsigned int in_connect:1; /* doing a proxy CONNECT */
00107     unsigned int request_secure_upgrade:1; 
00108     unsigned int accept_secure_upgrade:1;
00109 
00110     http_use_proxy proxy_decider;
00111     void *proxy_decider_udata;
00112 
00113     nssl_context *ssl_context;
00114 
00115     struct hook *hooks;
00116 
00117     char *location; /* 302 redirect location of last request */
00118 
00119     char *user_agent; /* full User-Agent string */
00120 
00121     /* The last HTTP-Version returned by the server */
00122     int version_major;
00123     int version_minor;
00124 
00125     /* Error string */
00126     char error[BUFSIZ];
00127 };
00128 
00129 struct http_req_s {
00130     const char *method;
00131     char *uri, *abs_path;
00132     
00133     /*** Request ***/
00134 
00135     sbuffer headers;
00136     request_body body;
00137     FILE *body_stream;
00138     const char *body_buffer;
00139     size_t body_size;
00140 
00141     /**** Response ***/
00142 
00143     /* The transfer encoding types */
00144     struct http_response {
00145        unsigned int is_chunked; /* Are we using chunked TE? */
00146        int length;            /* Response entity-body content-length */
00147        int left;              /* Bytes left to read */
00148        long int chunk_left;   /* Bytes of chunk left to read */
00149     } resp;
00150 
00151     /* List of callbacks which are passed response headers */
00152     struct header_handler *header_catchers;
00153     
00154     /* We store response header handlers in a hash table.  The hash is
00155      * derived from the header name in lower case. */
00156 
00157     /* 53 is magic, of course.  For a standard http_get (with
00158      * redirects), 9 header handlers are defined.  Two of these are
00159      * for Content-Length (which is a bug, and should be fixed
00160      * really).  Ignoring that hash clash, the 8 *different* handlers
00161      * all hash uniquely into the hash table of size 53.  */
00162 #define HH_HASHSIZE 53
00163     
00164     struct header_handler *header_handlers[HH_HASHSIZE];
00165     /* List of callbacks which are passed response body blocks */
00166     struct body_reader *body_readers;
00167 
00168     /*** Miscellaneous ***/
00169     unsigned int method_is_head:1;
00170     unsigned int use_proxy:1;
00171     unsigned int use_expect100:1;
00172     unsigned int can_persist:1;
00173     unsigned int forced_close:1;
00174     unsigned int upgrade_to_tls:1;
00175 
00176     http_session *session;
00177     http_status status;
00178 
00179     /* stores request-private hook info */
00180     struct hook_request *hook_store;
00181 
00182 #ifdef USE_DAV_LOCKS
00183     /* TODO: move this to hooks... list of locks to submit */
00184     struct dav_submit_locks *if_locks;
00185 #endif
00186 
00187 };
00188 
00189 #endif /* HTTP_PRIVATE_H */