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
58 typedef struct _HTTPConnection
{
64 HTTPRequestPtr request
;
65 HTTPRequestPtr request_last
;
68 TimeEventHandlerPtr timeout
;
76 /* For server connections */
78 struct _HTTPServer
*server
;
81 } HTTPConnectionRec
, *HTTPConnectionPtr
;
83 /* connection->flags */
86 #define CONN_SIDE_READER 4
88 #define CONN_BIGREQBUF 16
91 #define METHOD_UNKNOWN -1
92 #define METHOD_NONE -1
95 #define METHOD_CONDITIONAL_GET 2
96 #define METHOD_CONNECT 3
100 #define REQUEST_SIDE(request) ((request)->method >= METHOD_POST)
102 /* server->version */
105 #define HTTP_UNKNOWN -1
108 #define TE_IDENTITY 0
110 #define TE_UNKNOWN -1
112 /* connection->connecting */
113 #define CONNECTING_DNS 1
114 #define CONNECTING_CONNECT 2
115 #define CONNECTING_SOCKS 3
117 /* the results of a conditional request. 200, 304 and 412. */
118 #define CONDITION_MATCH 0
119 #define CONDITION_NOT_MODIFIED 1
120 #define CONDITION_FAILED 2
122 extern int disableProxy
;
123 extern AtomPtr proxyName
;
124 extern int proxyPort
;
125 extern int clientTimeout
, serverTimeout
;
126 extern int bigBufferSize
;
127 extern AtomPtr proxyAddress
;
128 extern int proxyOffline
;
129 extern int relaxTransparency
;
130 extern AtomPtr authRealm
;
131 extern AtomPtr authCredentials
;
132 extern AtomPtr parentAuthCredentials
;
133 extern AtomListPtr allowedClients
;
134 extern NetAddressPtr allowedNets
;
135 extern IntListPtr allowedPorts
;
136 extern IntListPtr tunnelAllowedPorts
;
137 extern int expectContinue
;
138 extern AtomPtr atom100Continue
;
139 extern int disableVia
;
141 void preinitHttp(void);
144 int httpTimeoutHandler(TimeEventHandlerPtr
);
145 int httpSetTimeout(HTTPConnectionPtr connection
, int secs
);
146 int httpWriteObjectHeaders(char *buf
, int offset
, int len
,
147 ObjectPtr object
, int from
, int to
);
148 int httpPrintCacheControl(char*, int, int, int, CacheControlPtr
);
149 char *httpMessage(int) ATTRIBUTE((pure
));
150 int htmlString(char *buf
, int n
, int len
, char *s
, int slen
);
151 void htmlPrint(FILE *out
, char *s
, int slen
);
152 HTTPConnectionPtr
httpMakeConnection(void);
153 void httpDestroyConnection(HTTPConnectionPtr connection
);
154 void httpConnectionDestroyBuf(HTTPConnectionPtr connection
);
155 void httpConnectionDestroyReqbuf(HTTPConnectionPtr connection
);
156 HTTPRequestPtr
httpMakeRequest(void);
157 void httpDestroyRequest(HTTPRequestPtr request
);
158 void httpQueueRequest(HTTPConnectionPtr
, HTTPRequestPtr
);
159 HTTPRequestPtr
httpDequeueRequest(HTTPConnectionPtr connection
);
160 int httpConnectionBigify(HTTPConnectionPtr
);
161 int httpConnectionBigifyReqbuf(HTTPConnectionPtr
);
162 int httpConnectionUnbigify(HTTPConnectionPtr
);
163 int httpConnectionUnbigifyReqbuf(HTTPConnectionPtr
);
164 HTTPConditionPtr
httpMakeCondition(void);
165 void httpDestroyCondition(HTTPConditionPtr condition
);
166 int httpCondition(ObjectPtr
, HTTPConditionPtr
);
167 int httpWriteErrorHeaders(char *buf
, int size
, int offset
, int do_body
,
168 int code
, AtomPtr message
, int close
, AtomPtr
,
169 char *url
, int url_len
, char *etag
);
170 AtomListPtr
urlDecode(char*, int);