| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | typedef struct _HTTPCondition { |
|---|
| 24 | time_t ims; |
|---|
| 25 | time_t inms; |
|---|
| 26 | char *im; |
|---|
| 27 | char *inm; |
|---|
| 28 | char *ifrange; |
|---|
| 29 | } HTTPConditionRec, *HTTPConditionPtr; |
|---|
| 30 | |
|---|
| 31 | typedef struct _HTTPRequest { |
|---|
| 32 | int flags; |
|---|
| 33 | struct _HTTPConnection *connection; |
|---|
| 34 | ObjectPtr object; |
|---|
| 35 | int method; |
|---|
| 36 | int from; |
|---|
| 37 | int to; |
|---|
| 38 | int replaying; |
|---|
| 39 | CacheControlRec cache_control; |
|---|
| 40 | HTTPConditionPtr condition; |
|---|
| 41 | AtomPtr via; |
|---|
| 42 | AtomPtr referer; |
|---|
| 43 | struct _ConditionHandler *chandler; |
|---|
| 44 | ObjectPtr can_mutate; |
|---|
| 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; |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | #define REQUEST_PERSISTENT 1 |
|---|
| 56 | #define REQUEST_REQUESTED 2 |
|---|
| 57 | #define REQUEST_WAIT_CONTINUE 4 |
|---|
| 58 | #define REQUEST_FORCE_ERROR 8 |
|---|
| 59 | #define REQUEST_PIPELINED 16 |
|---|
| 60 | |
|---|
| 61 | typedef struct _HTTPConnection { |
|---|
| 62 | int flags; |
|---|
| 63 | int fd; |
|---|
| 64 | char *buf; |
|---|
| 65 | int len; |
|---|
| 66 | int offset; |
|---|
| 67 | HTTPRequestPtr request; |
|---|
| 68 | HTTPRequestPtr request_last; |
|---|
| 69 | int serviced; |
|---|
| 70 | int version; |
|---|
| 71 | TimeEventHandlerPtr timeout; |
|---|
| 72 | int te; |
|---|
| 73 | char *reqbuf; |
|---|
| 74 | int reqlen; |
|---|
| 75 | int reqbegin; |
|---|
| 76 | int reqoffset; |
|---|
| 77 | int bodylen; |
|---|
| 78 | int reqte; |
|---|
| 79 | |
|---|
| 80 | int chunk_remaining; |
|---|
| 81 | struct _HTTPServer *server; |
|---|
| 82 | int pipelined; |
|---|
| 83 | int connecting; |
|---|
| 84 | } HTTPConnectionRec, *HTTPConnectionPtr; |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | #define CONN_READER 1 |
|---|
| 88 | #define CONN_WRITER 2 |
|---|
| 89 | #define CONN_SIDE_READER 4 |
|---|
| 90 | #define CONN_BIGBUF 8 |
|---|
| 91 | #define CONN_BIGREQBUF 16 |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | #define METHOD_UNKNOWN -1 |
|---|
| 95 | #define METHOD_NONE -1 |
|---|
| 96 | #define METHOD_GET 0 |
|---|
| 97 | #define METHOD_HEAD 1 |
|---|
| 98 | #define METHOD_CONDITIONAL_GET 2 |
|---|
| 99 | #define METHOD_CONNECT 3 |
|---|
| 100 | #define METHOD_POST 4 |
|---|
| 101 | #define METHOD_PUT 5 |
|---|
| 102 | |
|---|
| 103 | #define REQUEST_SIDE(request) ((request)->method >= METHOD_POST) |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | #define HTTP_10 0 |
|---|
| 107 | #define HTTP_11 1 |
|---|
| 108 | #define HTTP_UNKNOWN -1 |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | #define TE_IDENTITY 0 |
|---|
| 112 | #define TE_CHUNKED 1 |
|---|
| 113 | #define TE_UNKNOWN -1 |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | #define CONNECTING_DNS 1 |
|---|
| 117 | #define CONNECTING_CONNECT 2 |
|---|
| 118 | #define CONNECTING_SOCKS 3 |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | #define CONDITION_MATCH 0 |
|---|
| 122 | #define CONDITION_NOT_MODIFIED 1 |
|---|
| 123 | #define CONDITION_FAILED 2 |
|---|
| 124 | |
|---|
| 125 | extern int disableProxy; |
|---|
| 126 | extern AtomPtr proxyName; |
|---|
| 127 | extern int proxyPort; |
|---|
| 128 | extern int clientTimeout, serverTimeout, offlineTimeout; |
|---|
| 129 | extern int bigBufferSize; |
|---|
| 130 | extern AtomPtr proxyAddress; |
|---|
| 131 | extern int proxyOffline; |
|---|
| 132 | extern int relaxTransparency; |
|---|
| 133 | extern AtomPtr authRealm; |
|---|
| 134 | extern AtomPtr authCredentials; |
|---|
| 135 | extern AtomPtr parentAuthCredentials; |
|---|
| 136 | extern AtomListPtr allowedClients; |
|---|
| 137 | extern NetAddressPtr allowedNets; |
|---|
| 138 | extern IntListPtr allowedPorts; |
|---|
| 139 | extern IntListPtr tunnelAllowedPorts; |
|---|
| 140 | extern int expectContinue; |
|---|
| 141 | extern AtomPtr atom100Continue; |
|---|
| 142 | extern int disableVia; |
|---|
| 143 | extern int dontTrustVaryETag; |
|---|
| 144 | extern AtomPtr testDomain; |
|---|
| 145 | extern AtomPtr testDomainAddress; |
|---|
| 146 | |
|---|
| 147 | void preinitHttp(void); |
|---|
| 148 | void initHttp(void); |
|---|
| 149 | |
|---|
| 150 | int httpTimeoutHandler(TimeEventHandlerPtr); |
|---|
| 151 | int httpSetTimeout(HTTPConnectionPtr connection, int secs); |
|---|
| 152 | int httpWriteObjectHeaders(char *buf, int offset, int len, |
|---|
| 153 | ObjectPtr object, int from, int to); |
|---|
| 154 | int httpPrintCacheControl(char*, int, int, int, CacheControlPtr); |
|---|
| 155 | char *httpMessage(int) ATTRIBUTE((pure)); |
|---|
| 156 | int htmlString(char *buf, int n, int len, char *s, int slen); |
|---|
| 157 | void htmlPrint(FILE *out, char *s, int slen); |
|---|
| 158 | HTTPConnectionPtr httpMakeConnection(void); |
|---|
| 159 | void httpDestroyConnection(HTTPConnectionPtr connection); |
|---|
| 160 | void httpConnectionDestroyBuf(HTTPConnectionPtr connection); |
|---|
| 161 | void httpConnectionDestroyReqbuf(HTTPConnectionPtr connection); |
|---|
| 162 | HTTPRequestPtr httpMakeRequest(void); |
|---|
| 163 | void httpDestroyRequest(HTTPRequestPtr request, int destroyEverything); |
|---|
| 164 | void httpQueueRequest(HTTPConnectionPtr, HTTPRequestPtr); |
|---|
| 165 | HTTPRequestPtr httpDequeueRequest(HTTPConnectionPtr connection); |
|---|
| 166 | int httpConnectionBigify(HTTPConnectionPtr); |
|---|
| 167 | int httpConnectionBigifyReqbuf(HTTPConnectionPtr); |
|---|
| 168 | int httpConnectionUnbigify(HTTPConnectionPtr); |
|---|
| 169 | int httpConnectionUnbigifyReqbuf(HTTPConnectionPtr); |
|---|
| 170 | HTTPConditionPtr httpMakeCondition(void); |
|---|
| 171 | void httpDestroyCondition(HTTPConditionPtr condition); |
|---|
| 172 | int httpCondition(ObjectPtr, HTTPConditionPtr); |
|---|
| 173 | int httpWriteErrorHeaders(char *buf, int size, int offset, int do_body, |
|---|
| 174 | int code, AtomPtr message, int close, AtomPtr, |
|---|
| 175 | char *url, int url_len, char *etag); |
|---|
| 176 | AtomListPtr urlDecode(char*, int); |
|---|
| 177 | void httpTweakCachability(ObjectPtr); |
|---|
| 178 | int httpHeaderMatch(AtomPtr header, AtomPtr headers1, AtomPtr headers2); |
|---|