2 Copyright (c) 2003-2006 by Juliusz Chroboczek
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 typedef struct _HTTPCondition
{
29 } HTTPConditionRec
, *HTTPConditionPtr
;
31 typedef struct _HTTPRequest
{
33 struct _HTTPConnection
*connection
;
38 CacheControlRec cache_control
;
39 HTTPConditionPtr condition
;
41 struct _ConditionHandler
*chandler
;
44 struct _Atom
*error_message
;
45 struct _Atom
*error_headers
;
47 struct timeval time0
, time1
;
48 struct _HTTPRequest
*request
;
49 struct _HTTPRequest
*next
;
50 } HTTPRequestRec
, *HTTPRequestPtr
;
53 #define REQUEST_PERSISTENT 1
54 #define REQUEST_REQUESTED 2
55 #define REQUEST_WAIT_CONTINUE 4
56 #define REQUEST_FORCE_ERROR 8
57 #define REQUEST_PIPELINED 16
59 typedef struct _HTTPConnection
{
65 HTTPRequestPtr request
;
66 HTTPRequestPtr request_last
;
70 TimeEventHandlerPtr timeout
;
78 /* For server connections */
80 struct _HTTPServer
*server
;
83 } HTTPConnectionRec
, *HTTPConnectionPtr
;
85 /* connection->flags */
88 #define CONN_SIDE_READER 4
90 #define CONN_BIGREQBUF 16
93 #define METHOD_UNKNOWN -1
94 #define METHOD_NONE -1
97 #define METHOD_CONDITIONAL_GET 2
98 #define METHOD_CONNECT 3
102 #define REQUEST_SIDE(request) ((request)->method >= METHOD_POST)
104 /* server->version */
107 #define HTTP_UNKNOWN -1
110 #define TE_IDENTITY 0
112 #define TE_UNKNOWN -1
114 /* connection->connecting */
115 #define CONNECTING_DNS 1
116 #define CONNECTING_CONNECT 2
117 #define CONNECTING_SOCKS 3
119 /* the results of a conditional request. 200, 304 and 412. */
120 #define CONDITION_MATCH 0
121 #define CONDITION_NOT_MODIFIED 1
122 #define CONDITION_FAILED 2
124 extern int disableProxy
;
125 extern AtomPtr proxyName
;
126 extern int proxyPort
;
127 extern int clientTimeout
, serverTimeout
, serverIdleTimeout
;
128 extern int bigBufferSize
;
129 extern AtomPtr proxyAddress
;
130 extern int proxyOffline
;
131 extern int relaxTransparency
;
132 extern AtomPtr authRealm
;
133 extern AtomPtr authCredentials
;
134 extern AtomPtr parentAuthCredentials
;
135 extern AtomListPtr allowedClients
;
136 extern NetAddressPtr allowedNets
;
137 extern IntListPtr allowedPorts
;
138 extern IntListPtr tunnelAllowedPorts
;
139 extern int expectContinue
;
140 extern AtomPtr atom100Continue
;
141 extern int disableVia
;
142 extern int dontTrustVaryETag
;
144 void preinitHttp(void);
147 int httpTimeoutHandler(TimeEventHandlerPtr
);
148 int httpSetTimeout(HTTPConnectionPtr connection
, int secs
);
149 int httpWriteObjectHeaders(char *buf
, int offset
, int len
,
150 ObjectPtr object
, int from
, int to
);
151 int httpPrintCacheControl(char*, int, int, int, CacheControlPtr
);
152 char *httpMessage(int) ATTRIBUTE((pure
));
153 int htmlString(char *buf
, int n
, int len
, char *s
, int slen
);
154 void htmlPrint(FILE *out
, char *s
, int slen
);
155 HTTPConnectionPtr
httpMakeConnection(void);
156 void httpDestroyConnection(HTTPConnectionPtr connection
);
157 void httpConnectionDestroyBuf(HTTPConnectionPtr connection
);
158 void httpConnectionDestroyReqbuf(HTTPConnectionPtr connection
);
159 HTTPRequestPtr
httpMakeRequest(void);
160 void httpDestroyRequest(HTTPRequestPtr request
);
161 void httpQueueRequest(HTTPConnectionPtr
, HTTPRequestPtr
);
162 HTTPRequestPtr
httpDequeueRequest(HTTPConnectionPtr connection
);
163 int httpConnectionBigify(HTTPConnectionPtr
);
164 int httpConnectionBigifyReqbuf(HTTPConnectionPtr
);
165 int httpConnectionUnbigify(HTTPConnectionPtr
);
166 int httpConnectionUnbigifyReqbuf(HTTPConnectionPtr
);
167 HTTPConditionPtr
httpMakeCondition(void);
168 void httpDestroyCondition(HTTPConditionPtr condition
);
169 int httpCondition(ObjectPtr
, HTTPConditionPtr
);
170 int httpWriteErrorHeaders(char *buf
, int size
, int offset
, int do_body
,
171 int code
, AtomPtr message
, int close
, AtomPtr
,
172 char *url
, int url_len
, char *etag
);
173 AtomListPtr
urlDecode(char*, int);
174 void httpTweakCachability(ObjectPtr
);
175 int httpHeaderMatch(AtomPtr header
, AtomPtr headers1
, AtomPtr headers2
);