http.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. Copyright (c) 2003-2006 by Juliusz Chroboczek
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. typedef struct _HTTPCondition {
  20. time_t ims;
  21. time_t inms;
  22. char *im;
  23. char *inm;
  24. char *ifrange;
  25. } HTTPConditionRec, *HTTPConditionPtr;
  26. typedef struct _HTTPRequest {
  27. int flags;
  28. struct _HTTPConnection *connection;
  29. ObjectPtr object;
  30. int method;
  31. int from;
  32. int to;
  33. CacheControlRec cache_control;
  34. HTTPConditionPtr condition;
  35. AtomPtr via;
  36. struct _ConditionHandler *chandler;
  37. ObjectPtr can_mutate;
  38. int error_code;
  39. struct _Atom *error_message;
  40. struct _Atom *error_headers;
  41. AtomPtr headers;
  42. struct timeval time0, time1;
  43. struct _HTTPRequest *request;
  44. struct _HTTPRequest *next;
  45. } HTTPRequestRec, *HTTPRequestPtr;
  46. /* request->flags */
  47. /* If not present, drop the connection after this request. */
  48. #define REQUEST_PERSISTENT 1
  49. /* This client-side request has already been requested on the server-side. */
  50. #define REQUEST_REQUESTED 2
  51. /* This request is waiting for continue from the server. */
  52. #define REQUEST_WAIT_CONTINUE 4
  53. /* Force an error unconditionally -- used for client auth failures. */
  54. #define REQUEST_FORCE_ERROR 8
  55. /* This server-side request was pipelined. */
  56. #define REQUEST_PIPELINED 16
  57. /* This client-side request has already switched objects once. */
  58. #define REQUEST_SUPERSEDED 32
  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;
  84. /* connection->flags */
  85. #define CONN_READER 1
  86. #define CONN_WRITER 2
  87. #define CONN_SIDE_READER 4
  88. #define CONN_BIGBUF 8
  89. #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
  99. #define METHOD_OPTIONS 6
  100. #define METHOD_DELETE 7
  101. #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
  106. /* connection->te */
  107. #define TE_IDENTITY 0
  108. #define TE_CHUNKED 1
  109. #define TE_UNKNOWN -1
  110. /* connection->connecting */
  111. #define CONNECTING_DNS 1
  112. #define CONNECTING_CONNECT 2
  113. #define CONNECTING_SOCKS 3
  114. /* the results of a conditional request. 200, 304 and 412. */
  115. #define CONDITION_MATCH 0
  116. #define CONDITION_NOT_MODIFIED 1
  117. #define CONDITION_FAILED 2
  118. extern int disableProxy;
  119. extern AtomPtr proxyName;
  120. extern int proxyPort;
  121. extern int clientTimeout, serverTimeout, serverIdleTimeout;
  122. extern int bigBufferSize;
  123. extern AtomPtr proxyAddress;
  124. extern int proxyOffline;
  125. extern int relaxTransparency;
  126. extern AtomPtr authRealm;
  127. extern AtomPtr authCredentials;
  128. extern AtomPtr parentAuthCredentials;
  129. extern AtomListPtr allowedClients;
  130. extern NetAddressPtr allowedNets;
  131. extern IntListPtr allowedPorts;
  132. extern IntListPtr tunnelAllowedPorts;
  133. extern int expectContinue;
  134. extern AtomPtr atom100Continue;
  135. extern int disableVia;
  136. extern int dontTrustVaryETag;
  137. void preinitHttp(void);
  138. void initHttp(void);
  139. int httpTimeoutHandler(TimeEventHandlerPtr);
  140. int httpSetTimeout(HTTPConnectionPtr connection, int secs);
  141. int httpWriteObjectHeaders(char *buf, int offset, int len,
  142. ObjectPtr object, int from, int to);
  143. int httpPrintCacheControl(char*, int, int, int, CacheControlPtr);
  144. char *httpMessage(int) ATTRIBUTE((pure));
  145. int htmlString(char *buf, int n, int len, char *s, int slen);
  146. void htmlPrint(FILE *out, char *s, int slen);
  147. HTTPConnectionPtr httpMakeConnection(void);
  148. void httpDestroyConnection(HTTPConnectionPtr connection);
  149. void httpConnectionDestroyBuf(HTTPConnectionPtr connection);
  150. void httpConnectionDestroyReqbuf(HTTPConnectionPtr connection);
  151. HTTPRequestPtr httpMakeRequest(void);
  152. void httpDestroyRequest(HTTPRequestPtr request);
  153. void httpQueueRequest(HTTPConnectionPtr, HTTPRequestPtr);
  154. HTTPRequestPtr httpDequeueRequest(HTTPConnectionPtr connection);
  155. int httpConnectionBigify(HTTPConnectionPtr);
  156. int httpConnectionBigifyReqbuf(HTTPConnectionPtr);
  157. int httpConnectionUnbigify(HTTPConnectionPtr);
  158. int httpConnectionUnbigifyReqbuf(HTTPConnectionPtr);
  159. HTTPConditionPtr httpMakeCondition(void);
  160. void httpDestroyCondition(HTTPConditionPtr condition);
  161. int httpCondition(ObjectPtr, HTTPConditionPtr);
  162. int httpWriteErrorHeaders(char *buf, int size, int offset, int do_body,
  163. int code, AtomPtr message, int close, AtomPtr,
  164. char *url, int url_len, char *etag);
  165. AtomListPtr urlDecode(char*, int);
  166. void httpTweakCachability(ObjectPtr);
  167. int httpHeaderMatch(AtomPtr header, AtomPtr headers1, AtomPtr headers2);