PageRenderTime 33ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/http-server.h

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
C++ Header | 208 lines | 151 code | 28 blank | 29 comment | 0 complexity | 866dcf338e147529310905e816a93bbc MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /*
  2. http-server.h - generic HTTP server
  3. Copyright (C) 2008 siliconforks.com
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #ifndef HTTP_SERVER_H_
  17. #define HTTP_SERVER_H_
  18. #include <stdbool.h>
  19. #include <stdint.h>
  20. #include <stdlib.h>
  21. #ifdef __MINGW32__
  22. #include <winsock2.h>
  23. typedef int socklen_t;
  24. #else
  25. #include <arpa/inet.h>
  26. #include <netdb.h>
  27. #include <netinet/in.h>
  28. #include <sys/socket.h>
  29. #include <unistd.h>
  30. typedef int SOCKET;
  31. #define INVALID_SOCKET (-1)
  32. #define closesocket close
  33. #endif
  34. #include "stream.h"
  35. #define HTTP_ACCEPT "Accept"
  36. #define HTTP_ACCEPT_CHARSET "Accept-Charset"
  37. #define HTTP_ACCEPT_ENCODING "Accept-Encoding"
  38. #define HTTP_ACCEPT_LANGUAGE "Accept-Language"
  39. #define HTTP_ACCEPT_RANGES "Accept-Ranges"
  40. #define HTTP_AGE "Age"
  41. #define HTTP_ALLOW "Allow"
  42. #define HTTP_AUTHORIZATION "Authorization"
  43. #define HTTP_CACHE_CONTROL "Cache-Control"
  44. #define HTTP_CONNECTION "Connection"
  45. #define HTTP_CONTENT_ENCODING "Content-Encoding"
  46. #define HTTP_CONTENT_LANGUAGE "Content-Language"
  47. #define HTTP_CONTENT_LENGTH "Content-Length"
  48. #define HTTP_CONTENT_LOCATION "Content-Location"
  49. #define HTTP_CONTENT_MD5 "Content-MD5"
  50. #define HTTP_CONTENT_RANGE "Content-Range"
  51. #define HTTP_CONTENT_TYPE "Content-Type"
  52. #define HTTP_DATE "Date"
  53. #define HTTP_ETAG "ETag"
  54. #define HTTP_EXPECT "Expect"
  55. #define HTTP_EXPIRES "Expires"
  56. #define HTTP_FROM "From"
  57. #define HTTP_HOST "Host"
  58. #define HTTP_IF_MATCH "If-Match"
  59. #define HTTP_IF_MODIFIED_SINCE "If-Modified-Since"
  60. #define HTTP_IF_NONE_MATCH "If-None-Match"
  61. #define HTTP_IF_RANGE "If-Range"
  62. #define HTTP_IF_UNMODIFIED_SINCE "If-Unmodified-Since"
  63. #define HTTP_LAST_MODIFIED "Last-Modified"
  64. #define HTTP_LOCATION "Location"
  65. #define HTTP_MAX_FORWARDS "Max-Forwards"
  66. #define HTTP_PRAGMA "Pragma"
  67. #define HTTP_PROXY_AUTHENTICATE "Proxy-Authenticate"
  68. #define HTTP_PROXY_AUTHORIZATION "Proxy-Authorization"
  69. #define HTTP_RANGE "Range"
  70. #define HTTP_REFERER "Referer"
  71. #define HTTP_RETRY_AFTER "Retry-After"
  72. #define HTTP_SERVER "Server"
  73. #define HTTP_TE "TE"
  74. #define HTTP_TRAILER "Trailer"
  75. #define HTTP_TRANSFER_ENCODING "Transfer-Encoding"
  76. #define HTTP_UPGRADE "Upgrade"
  77. #define HTTP_USER_AGENT "User-Agent"
  78. #define HTTP_VARY "Vary"
  79. #define HTTP_VIA "Via"
  80. #define HTTP_WARNING "Warning"
  81. #define HTTP_WWW_AUTHENTICATE "WWW-Authenticate"
  82. typedef struct HTTPHeader {
  83. char * name;
  84. char * value;
  85. struct HTTPHeader * next;
  86. } HTTPHeader;
  87. typedef struct HTTPMessage HTTPMessage;
  88. typedef struct HTTPExchange HTTPExchange;
  89. typedef struct HTTPConnection HTTPConnection;
  90. typedef void (*HTTPServerHandler)(HTTPExchange * exchange);
  91. /* HTTPConnection */
  92. HTTPConnection * HTTPConnection_new_server(SOCKET s);
  93. HTTPConnection * HTTPConnection_new_client(const char * host, uint16_t port) __attribute__((warn_unused_result));
  94. int HTTPConnection_delete(HTTPConnection * connection) __attribute__((warn_unused_result));
  95. int HTTPConnection_get_peer(HTTPConnection * connection, struct sockaddr_in * peer) __attribute__((warn_unused_result));
  96. int HTTPConnection_read_octet(HTTPConnection * connection, int * octet) __attribute__((warn_unused_result));
  97. int HTTPConnection_peek_octet(HTTPConnection * connection, int * octet) __attribute__((warn_unused_result));
  98. int HTTPConnection_write(HTTPConnection * connection, const void * p, size_t size) __attribute__((warn_unused_result));
  99. int HTTPConnection_flush(HTTPConnection * connection) __attribute__((warn_unused_result));
  100. /* HTTPMessage */
  101. HTTPMessage * HTTPMessage_new(HTTPConnection * connection);
  102. void HTTPMessage_delete(HTTPMessage * message);
  103. HTTPConnection * HTTPMessage_get_connection(const HTTPMessage * message);
  104. const char * HTTPMessage_get_start_line(const HTTPMessage * message);
  105. void HTTPMessage_set_start_line(HTTPMessage * message, const char * start_line);
  106. const HTTPHeader * HTTPMessage_get_headers(const HTTPMessage * message);
  107. const char * HTTPMessage_find_header(const HTTPMessage * message, const char * name);
  108. void HTTPMessage_add_header(HTTPMessage * message, const char * name, const char * value);
  109. void HTTPMessage_set_header(HTTPMessage * message, const char * name, const char * value);
  110. char * HTTPMessage_get_charset(const HTTPMessage * message);
  111. void HTTPMessage_set_content_length(HTTPMessage * message, size_t value);
  112. int HTTPMessage_read_start_line_and_headers(HTTPMessage * message) __attribute__((warn_unused_result));
  113. int HTTPMessage_write_start_line_and_headers(HTTPMessage * message) __attribute__((warn_unused_result));
  114. bool HTTPMessage_has_sent_headers(const HTTPMessage * message);
  115. int HTTPMessage_write(HTTPMessage * message, const void * p, size_t size) __attribute__((warn_unused_result));
  116. int HTTPMessage_flush(HTTPMessage * message) __attribute__((warn_unused_result));
  117. /*
  118. This function reads the entire entity body from a message. If the message uses
  119. the "chunked" Transfer-Encoding, this function will decode it, so that the
  120. result will be the original entity.
  121. */
  122. int HTTPMessage_read_entire_entity_body(HTTPMessage * message, Stream * input_stream) __attribute__((warn_unused_result));
  123. /*
  124. This function makes no attempt to decode the Transfer-Encoding.
  125. */
  126. int HTTPMessage_read_message_body(HTTPMessage * message, void * p, size_t capacity, size_t * bytes_read) __attribute__((warn_unused_result));
  127. /* HTTPExchange */
  128. HTTPExchange * HTTPExchange_new(HTTPConnection * connection);
  129. void HTTPExchange_delete(HTTPExchange * exchange);
  130. int HTTPExchange_get_peer(const HTTPExchange * exchange, struct sockaddr_in * peer) __attribute__((warn_unused_result));
  131. HTTPMessage * HTTPExchange_get_request_message(const HTTPExchange * exchange);
  132. const char * HTTPExchange_get_request_line(const HTTPExchange * exchange);
  133. const char * HTTPExchange_get_method(const HTTPExchange * exchange);
  134. const char * HTTPExchange_get_request_uri(const HTTPExchange * exchange);
  135. const char * HTTPExchange_get_request_http_version(const HTTPExchange * exchange);
  136. const char * HTTPExchange_get_host(const HTTPExchange * exchange);
  137. uint16_t HTTPExchange_get_port(const HTTPExchange * exchange);
  138. const char * HTTPExchange_get_abs_path(const HTTPExchange * exchange);
  139. void HTTPExchange_set_method(HTTPExchange * exchange, const char * method);
  140. void HTTPExchange_set_request_uri(HTTPExchange * exchange, const char * request_uri);
  141. const HTTPHeader * HTTPExchange_get_request_headers(const HTTPExchange * exchange);
  142. const char * HTTPExchange_find_request_header(const HTTPExchange * exchange, const char * name);
  143. void HTTPExchange_add_request_header(HTTPExchange * exchange, const char * name, const char * value);
  144. void HTTPExchange_set_request_header(HTTPExchange * exchange, const char * name, const char * value);
  145. void HTTPExchange_set_request_content_length(HTTPExchange * exchange, size_t value);
  146. int HTTPExchange_read_request_headers(HTTPExchange * exchange) __attribute__((warn_unused_result));
  147. int HTTPExchange_write_request_headers(HTTPExchange * exchange) __attribute__((warn_unused_result));
  148. bool HTTPExchange_request_has_body(const HTTPExchange * exchange);
  149. int HTTPExchange_read_entire_request_entity_body(HTTPExchange * exchange, Stream * stream) __attribute__((warn_unused_result));
  150. int HTTPExchange_flush_request(HTTPExchange * exchange) __attribute__((warn_unused_result));
  151. HTTPMessage * HTTPExchange_get_response_message(const HTTPExchange * exchange);
  152. uint16_t HTTPExchange_get_status_code(const HTTPExchange * exchange);
  153. const char * HTTPExchange_get_response_http_version(const HTTPExchange * exchange);
  154. void HTTPExchange_set_status_code(HTTPExchange * exchange, uint16_t status_code);
  155. const HTTPHeader * HTTPExchange_get_response_headers(const HTTPExchange * exchange);
  156. const char * HTTPExchange_find_response_header(const HTTPExchange * exchange, const char * name);
  157. void HTTPExchange_add_response_header(HTTPExchange * exchange, const char * name, const char * value);
  158. void HTTPExchange_set_response_header(HTTPExchange * exchange, const char * name, const char * value);
  159. void HTTPExchange_set_response_content_length(HTTPExchange * exchange, size_t value);
  160. int HTTPExchange_read_response_headers(HTTPExchange * exchange) __attribute__((warn_unused_result));
  161. int HTTPExchange_write_response_headers(HTTPExchange * exchange) __attribute__((warn_unused_result));
  162. bool HTTPExchange_response_has_body(const HTTPExchange * exchange);
  163. int HTTPExchange_read_entire_response_entity_body(HTTPExchange * exchange, Stream * stream) __attribute__((warn_unused_result));
  164. int HTTPExchange_write_response(HTTPExchange * exchange, const void * p, size_t size) __attribute__((warn_unused_result));
  165. int HTTPExchange_flush_response(HTTPExchange * exchange) __attribute__((warn_unused_result));
  166. void HTTPServer_run(const char * ip_address, uint16_t port, HTTPServerHandler handler);
  167. void HTTPServer_shutdown(void);
  168. void HTTPServer_log_out(const char * format, ...) __attribute__((__format__(printf, 1, 2)));
  169. void HTTPServer_log_err(const char * format, ...) __attribute__((__format__(printf, 1, 2)));
  170. int URL_parse(const char * url, char ** host, uint16_t * port, char ** abs_path, char ** query) __attribute__((warn_unused_result));
  171. int URL_parse_host_and_port(const char * s, char ** host, uint16_t * port) __attribute__((warn_unused_result));
  172. int URL_parse_abs_path_and_query(const char * s, char ** abs_path, char ** query) __attribute__((warn_unused_result));
  173. int xgethostbyname(const char * host, struct in_addr * result) __attribute__((warn_unused_result));
  174. #ifndef HAVE_INET_ATON
  175. int inet_aton(const char * name, struct in_addr * a);
  176. #endif
  177. #endif /* HTTP_SERVER_H_ */