Update CHANGES; fix a bogus entry, and mention Jake's work.
[polipo.git] / http.h
blobd56281605ae804d45e92ecca383c198e8fca81e6
1 /*
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
20 THE SOFTWARE.
23 typedef struct _HTTPCondition {
24 time_t ims;
25 time_t inms;
26 char *im;
27 char *inm;
28 char *ifrange;
29 } HTTPConditionRec, *HTTPConditionPtr;
31 typedef struct _HTTPRequest {
32 int flags;
33 struct _HTTPConnection *connection;
34 ObjectPtr object;
35 int method;
36 int from;
37 int to;
38 CacheControlRec cache_control;
39 HTTPConditionPtr condition;
40 AtomPtr via;
41 struct _ConditionHandler *chandler;
42 ObjectPtr can_mutate;
43 int error_code;
44 struct _Atom *error_message;
45 struct _Atom *error_headers;
46 AtomPtr headers;
47 struct timeval time0, time1;
48 struct _HTTPRequest *request;
49 struct _HTTPRequest *next;
50 } HTTPRequestRec, *HTTPRequestPtr;
52 /* request->flags */
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 {
60 int flags;
61 int fd;
62 char *buf;
63 int len;
64 int offset;
65 HTTPRequestPtr request;
66 HTTPRequestPtr request_last;
67 int serviced;
68 int version;
69 int time;
70 TimeEventHandlerPtr timeout;
71 int te;
72 char *reqbuf;
73 int reqlen;
74 int reqbegin;
75 int reqoffset;
76 int bodylen;
77 int reqte;
78 /* For server connections */
79 int chunk_remaining;
80 struct _HTTPServer *server;
81 int pipelined;
82 int connecting;
83 } HTTPConnectionRec, *HTTPConnectionPtr;
85 /* connection->flags */
86 #define CONN_READER 1
87 #define CONN_WRITER 2
88 #define CONN_SIDE_READER 4
89 #define CONN_BIGBUF 8
90 #define CONN_BIGREQBUF 16
92 /* request->method */
93 #define METHOD_UNKNOWN -1
94 #define METHOD_NONE -1
95 #define METHOD_GET 0
96 #define METHOD_HEAD 1
97 #define METHOD_CONDITIONAL_GET 2
98 #define METHOD_CONNECT 3
99 #define METHOD_POST 4
100 #define METHOD_PUT 5
102 #define REQUEST_SIDE(request) ((request)->method >= METHOD_POST)
104 /* server->version */
105 #define HTTP_10 0
106 #define HTTP_11 1
107 #define HTTP_UNKNOWN -1
109 /* connection->te */
110 #define TE_IDENTITY 0
111 #define TE_CHUNKED 1
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);
145 void initHttp(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);