http_struct.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
  3. * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  18. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  19. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef _EVENT2_HTTP_STRUCT_H_
  28. #define _EVENT2_HTTP_STRUCT_H_
  29. /** @file event2/http_struct.h
  30. Data structures for http. Using these structures may hurt forward
  31. compatibility with later versions of Libevent: be careful!
  32. */
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. #include <event2/event-config.h>
  37. #ifdef _EVENT_HAVE_SYS_TYPES_H
  38. #include <sys/types.h>
  39. #endif
  40. #ifdef _EVENT_HAVE_SYS_TIME_H
  41. #include <sys/time.h>
  42. #endif
  43. /* For int types. */
  44. #include <event2/util.h>
  45. /**
  46. * the request structure that a server receives.
  47. * WARNING: expect this structure to change. I will try to provide
  48. * reasonable accessors.
  49. */
  50. struct evhttp_request {
  51. #if defined(TAILQ_ENTRY)
  52. TAILQ_ENTRY(evhttp_request) next;
  53. #else
  54. struct {
  55. struct evhttp_request *tqe_next;
  56. struct evhttp_request **tqe_prev;
  57. } next;
  58. #endif
  59. /* the connection object that this request belongs to */
  60. struct evhttp_connection *evcon;
  61. int flags;
  62. /** The request obj owns the evhttp connection and needs to free it */
  63. #define EVHTTP_REQ_OWN_CONNECTION 0x0001
  64. /** Request was made via a proxy */
  65. #define EVHTTP_PROXY_REQUEST 0x0002
  66. /** The request object is owned by the user; the user must free it */
  67. #define EVHTTP_USER_OWNED 0x0004
  68. /** The request will be used again upstack; freeing must be deferred */
  69. #define EVHTTP_REQ_DEFER_FREE 0x0008
  70. /** The request should be freed upstack */
  71. #define EVHTTP_REQ_NEEDS_FREE 0x0010
  72. struct evkeyvalq *input_headers;
  73. struct evkeyvalq *output_headers;
  74. /* address of the remote host and the port connection came from */
  75. char *remote_host;
  76. ev_uint16_t remote_port;
  77. /* cache of the hostname for evhttp_request_get_host */
  78. char *host_cache;
  79. enum evhttp_request_kind kind;
  80. enum evhttp_cmd_type type;
  81. size_t headers_size;
  82. size_t body_size;
  83. char *uri; /* uri after HTTP request was parsed */
  84. struct evhttp_uri *uri_elems; /* uri elements */
  85. char major; /* HTTP Major number */
  86. char minor; /* HTTP Minor number */
  87. int response_code; /* HTTP Response code */
  88. char *response_code_line; /* Readable response */
  89. struct evbuffer *input_buffer; /* read data */
  90. ev_int64_t ntoread;
  91. unsigned chunked:1, /* a chunked request */
  92. userdone:1; /* the user has sent all data */
  93. struct evbuffer *output_buffer; /* outgoing post or data */
  94. /* Callback */
  95. void (*cb)(struct evhttp_request *, void *);
  96. void *cb_arg;
  97. /*
  98. * Chunked data callback - call for each completed chunk if
  99. * specified. If not specified, all the data is delivered via
  100. * the regular callback.
  101. */
  102. void (*chunk_cb)(struct evhttp_request *, void *);
  103. };
  104. #ifdef __cplusplus
  105. }
  106. #endif
  107. #endif /* _EVENT2_HTTP_STRUCT_H_ */