Make exitFlag static in the Windows case.
[polipo.git] / http.h
blob08f402e0eeac71131e4edcd66d6f176a9bc70cc3
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
58 typedef struct _HTTPConnection {
59 int flags;
60 int fd;
61 char *buf;
62 int len;
63 int offset;
64 HTTPRequestPtr request;
65 HTTPRequestPtr request_last;
66 int serviced;
67 int version;
68 TimeEventHandlerPtr timeout;
69 int te;
70 char *reqbuf;
71 int reqlen;
72 int reqbegin;
73 int reqoffset;
74 int bodylen;
75 int reqte;
76 /* For server connections */
77 int chunk_remaining;
78 struct _HTTPServer *server;
79 int pipelined;
80 int connecting;
81 } HTTPConnectionRec, *HTTPConnectionPtr;
83 /* connection->flags */
84 #define CONN_READER 1
85 #define CONN_WRITER 2
86 #define CONN_SIDE_READER 4
87 #define CONN_BIGBUF 8
88 #define CONN_BIGREQBUF 16
90 /* request->method */
91 #define METHOD_UNKNOWN -1
92 #define METHOD_NONE -1
93 #define METHOD_GET 0
94 #define METHOD_HEAD 1
95 #define METHOD_CONDITIONAL_GET 2
96 #define METHOD_CONNECT 3
97 #define METHOD_POST 4
98 #define METHOD_PUT 5
100 #define REQUEST_SIDE(request) ((request)->method >= METHOD_POST)
102 /* server->version */
103 #define HTTP_10 0
104 #define HTTP_11 1
105 #define HTTP_UNKNOWN -1
107 /* connection->te */
108 #define TE_IDENTITY 0
109 #define TE_CHUNKED 1
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);
142 void initHttp(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);