Import polipo--devel--0--base-0.
[polipo.git] / http.h
blob375f9d8e40c886881361f87ec9400d7f89674c9c
1 /*
2 Copyright (c) 2003, 2004 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 struct _HTTPConnection *connection;
33 ObjectPtr object;
34 int method;
35 int from;
36 int to;
37 CacheControlRec cache_control;
38 HTTPConditionPtr condition;
39 AtomPtr via;
40 int persistent;
41 int wait_continue;
42 ObjectHandlerPtr ohandler;
43 int requested;
44 int force_error;
45 int error_code;
46 struct _Atom *error_message;
47 struct _Atom *error_headers;
48 AtomPtr headers;
49 struct timeval time0, time1;
50 struct _HTTPRequest *request;
51 struct _HTTPRequest *next;
52 } HTTPRequestRec, *HTTPRequestPtr;
54 typedef struct _HTTPConnection {
55 int flags;
56 int fd;
57 char *buf;
58 int len;
59 int offset;
60 HTTPRequestPtr request;
61 HTTPRequestPtr request_last;
62 int serviced;
63 int version;
64 TimeEventHandlerPtr timeout;
65 int te;
66 char *reqbuf;
67 int reqlen;
68 int reqbegin;
69 int reqoffset;
70 int bodylen;
71 int reqte;
72 /* For server connections */
73 int chunk_remaining;
74 struct _HTTPServer *server;
75 int pipelined;
76 int connecting;
77 } HTTPConnectionRec, *HTTPConnectionPtr;
79 /* connection->flags */
80 #define CONN_READER 1
81 #define CONN_WRITER 2
83 /* request->method */
84 #define METHOD_UNKNOWN -1
85 #define METHOD_NONE -1
86 #define METHOD_GET 0
87 #define METHOD_HEAD 1
88 #define METHOD_CONDITIONAL_GET 2
89 #define METHOD_CONNECT 3
90 #define METHOD_POST 4
91 #define METHOD_PUT 5
93 #define REQUEST_SIDE(request) ((request)->method >= METHOD_POST)
95 /* server->version */
96 #define HTTP_10 0
97 #define HTTP_11 1
98 #define HTTP_UNKNOWN -1
100 /* connection->te */
101 #define TE_IDENTITY 0
102 #define TE_CHUNKED 1
103 #define TE_UNKNOWN -1
105 /* connection->connecting */
106 #define CONNECTING_DNS 1
107 #define CONNECTING_CONNECT 2
109 /* the results of a conditional request. 200, 304 and 412. */
110 #define CONDITION_MATCH 0
111 #define CONDITION_NOT_MODIFIED 1
112 #define CONDITION_FAILED 2
114 extern AtomPtr proxyName;
115 extern int proxyPort;
116 extern AtomPtr proxyAddress;
117 extern int proxyOffline;
118 extern int relaxTransparency;
119 extern AtomPtr authRealm;
120 extern AtomPtr authCredentials;
121 extern AtomListPtr allowedClients;
122 extern NetAddressPtr allowedNets;
123 extern IntListPtr allowedPorts;
124 extern IntListPtr tunnelAllowedPorts;
125 extern int expectContinue;
126 extern AtomPtr atom100Continue;
128 void preinitHttp(void);
129 void initHttp(void);
131 int httpTimeoutHandler(TimeEventHandlerPtr);
132 int httpSetTimeout(HTTPConnectionPtr connection, int secs);
133 int httpWriteObjectHeaders(char *buf, int offset, int len,
134 ObjectPtr object, int from, int to);
135 int httpPrintCacheControl(char*, int, int, int, CacheControlPtr);
136 char *httpMessage(int) ATTRIBUTE((pure));
137 int htmlString(char *buf, int n, int len, char *s, int slen);
138 void htmlPrint(FILE *out, char *s, int slen);
139 HTTPConnectionPtr httpMakeConnection(void);
140 void httpDestroyConnection(HTTPConnectionPtr connection);
141 HTTPRequestPtr httpMakeRequest(void);
142 void httpDestroyRequest(HTTPRequestPtr request);
143 void httpQueueRequest(HTTPConnectionPtr, HTTPRequestPtr);
144 HTTPRequestPtr httpDequeueRequest(HTTPConnectionPtr connection);
145 HTTPConditionPtr httpMakeCondition(void);
146 void httpDestroyCondition(HTTPConditionPtr condition);
147 int httpCondition(ObjectPtr, HTTPConditionPtr);
148 int httpWriteErrorHeaders(char *buf, int size, int offset, int do_body,
149 int code, AtomPtr message, int close, AtomPtr,
150 char *url, int url_len, char *etag);