File: http.h

package info (click to toggle)
polipo 1.1.1-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,204 kB
  • ctags: 1,694
  • sloc: ansic: 20,882; python: 238; sh: 234; makefile: 139
file content (182 lines) | stat: -rw-r--r-- 5,958 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
Copyright (c) 2003-2006 by Juliusz Chroboczek

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

typedef struct _HTTPCondition {
    time_t ims;
    time_t inms;
    char *im;
    char *inm;
    char *ifrange;
} HTTPConditionRec, *HTTPConditionPtr;

typedef struct _HTTPRequest {
    int flags;
    struct _HTTPConnection *connection;
    ObjectPtr object;
    int method;
    int from;
    int to;
    CacheControlRec cache_control;
    HTTPConditionPtr condition;
    AtomPtr via;
    struct _ConditionHandler *chandler;
    ObjectPtr can_mutate;
    int error_code;
    struct _Atom *error_message;
    struct _Atom *error_headers;
    AtomPtr headers;
    struct timeval time0, time1;
    struct _HTTPRequest *request;
    struct _HTTPRequest *next;
} HTTPRequestRec, *HTTPRequestPtr;

/* request->flags */
/* If not present, drop the connection after this request. */
#define REQUEST_PERSISTENT 1
/* This client-side request has already been requested on the server-side. */
#define REQUEST_REQUESTED 2
/* This request is waiting for continue from the server. */
#define REQUEST_WAIT_CONTINUE 4
/* Force an error unconditionally -- used for client auth failures. */
#define REQUEST_FORCE_ERROR 8
/* This server-side request was pipelined. */
#define REQUEST_PIPELINED 16
/* This client-side request has already switched objects once. */
#define REQUEST_SUPERSEDED 32

typedef struct _HTTPConnection {
    int flags;
    int fd;
    char *buf;
    int len;
    int offset;
    HTTPRequestPtr request;
    HTTPRequestPtr request_last;
    int serviced;
    int version;
    int time;
    TimeEventHandlerPtr timeout;
    int te;
    char *reqbuf;
    int reqlen;
    int reqbegin;
    int reqoffset;
    int bodylen;
    int reqte;
    /* For server connections */
    int chunk_remaining;
    struct _HTTPServer *server;
    int pipelined;
    int connecting;
} HTTPConnectionRec, *HTTPConnectionPtr;

/* connection->flags */
#define CONN_READER 1
#define CONN_WRITER 2
#define CONN_SIDE_READER 4
#define CONN_BIGBUF 8
#define CONN_BIGREQBUF 16

/* request->method */
#define METHOD_UNKNOWN -1
#define METHOD_NONE -1
#define METHOD_GET 0
#define METHOD_HEAD 1
#define METHOD_CONDITIONAL_GET 2
#define METHOD_CONNECT 3
#define METHOD_POST 4
#define METHOD_PUT 5

#define REQUEST_SIDE(request) ((request)->method >= METHOD_POST)

/* server->version */
#define HTTP_10 0
#define HTTP_11 1
#define HTTP_UNKNOWN -1

/* connection->te */
#define TE_IDENTITY 0
#define TE_CHUNKED 1
#define TE_UNKNOWN -1

/* connection->connecting */
#define CONNECTING_DNS 1
#define CONNECTING_CONNECT 2
#define CONNECTING_SOCKS 3

/* the results of a conditional request.  200, 304 and 412. */
#define CONDITION_MATCH 0
#define CONDITION_NOT_MODIFIED 1
#define CONDITION_FAILED 2

extern int disableProxy;
extern AtomPtr proxyName;
extern int proxyPort;
extern int clientTimeout, serverTimeout, serverIdleTimeout;
extern int bigBufferSize;
extern AtomPtr proxyAddress;
extern int proxyOffline;
extern int relaxTransparency;
extern AtomPtr authRealm;
extern AtomPtr authCredentials;
extern AtomPtr parentAuthCredentials;
extern AtomListPtr allowedClients;
extern NetAddressPtr allowedNets;
extern IntListPtr allowedPorts;
extern IntListPtr tunnelAllowedPorts;
extern int expectContinue;
extern AtomPtr atom100Continue;
extern int disableVia;
extern int dontTrustVaryETag;

void preinitHttp(void);
void initHttp(void);

int httpTimeoutHandler(TimeEventHandlerPtr);
int httpSetTimeout(HTTPConnectionPtr connection, int secs);
int httpWriteObjectHeaders(char *buf, int offset, int len, 
                           ObjectPtr object, int from, int to);
int httpPrintCacheControl(char*, int, int, int, CacheControlPtr);
char *httpMessage(int) ATTRIBUTE((pure));
int htmlString(char *buf, int n, int len, char *s, int slen);
void htmlPrint(FILE *out, char *s, int slen);
HTTPConnectionPtr httpMakeConnection(void);
void httpDestroyConnection(HTTPConnectionPtr connection);
void httpConnectionDestroyBuf(HTTPConnectionPtr connection);
void httpConnectionDestroyReqbuf(HTTPConnectionPtr connection);
HTTPRequestPtr httpMakeRequest(void);
void httpDestroyRequest(HTTPRequestPtr request);
void httpQueueRequest(HTTPConnectionPtr, HTTPRequestPtr);
HTTPRequestPtr httpDequeueRequest(HTTPConnectionPtr connection);
int httpConnectionBigify(HTTPConnectionPtr);
int httpConnectionBigifyReqbuf(HTTPConnectionPtr);
int httpConnectionUnbigify(HTTPConnectionPtr);
int httpConnectionUnbigifyReqbuf(HTTPConnectionPtr);
HTTPConditionPtr httpMakeCondition(void);
void httpDestroyCondition(HTTPConditionPtr condition);
int httpCondition(ObjectPtr, HTTPConditionPtr);
int httpWriteErrorHeaders(char *buf, int size, int offset, int do_body,
                          int code, AtomPtr message, int close, AtomPtr,
                          char *url, int url_len, char *etag);
AtomListPtr urlDecode(char*, int);
void httpTweakCachability(ObjectPtr);
int httpHeaderMatch(AtomPtr header, AtomPtr headers1, AtomPtr headers2);