root/src/noit_http.h

Revision 5aafe929cf70ac47fd158efa700b0c5c45cd5abb, 7.6 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 2 years ago)

add accessor for request start_time

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  *       notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  *       copyright notice, this list of conditions and the following
13  *       disclaimer in the documentation and/or other materials provided
14  *       with the distribution.
15  *     * Neither the name OmniTI Computer Consulting, Inc. nor the names
16  *       of its contributors may be used to endorse or promote products
17  *       derived from this software without specific prior written
18  *       permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _NOIT_HTTP_H
34 #define _NOIT_HTTP_H
35
36 #include "noit_defines.h"
37 #include <libxml/tree.h>
38 #include "eventer/eventer.h"
39 #include "utils/noit_hash.h"
40 #include "utils/noit_atomic.h"
41 #include "utils/noit_hooks.h"
42 #include "noit_listener.h"
43
44 typedef enum {
45   NOIT_HTTP_OTHER, NOIT_HTTP_GET, NOIT_HTTP_HEAD, NOIT_HTTP_POST
46 } noit_http_method;
47 typedef enum {
48   NOIT_HTTP09, NOIT_HTTP10, NOIT_HTTP11
49 } noit_http_protocol;
50
51 #define NOIT_HTTP_CHUNKED 0x0001
52 #define NOIT_HTTP_CLOSE   0x0002
53 #define NOIT_HTTP_GZIP    0x0010
54 #define NOIT_HTTP_DEFLATE 0x0020
55
56 typedef enum {
57   BCHAIN_INLINE = 0,
58   BCHAIN_MMAP
59 } bchain_type_t;
60
61 struct bchain;
62
63 #define DEFAULT_MAXWRITE 1<<14 /* 32k */
64 #define DEFAULT_BCHAINSIZE ((1 << 15)-(offsetof(struct bchain, _buff)))
65 /* 64k - delta */
66 #define DEFAULT_BCHAINMINREAD (DEFAULT_BCHAINSIZE/4)
67 #define BCHAIN_SPACE(a) ((a)->allocd - (a)->size - (a)->start)
68
69 struct noit_http_connection;
70 typedef struct noit_http_connection noit_http_connection;
71 struct noit_http_request;
72 typedef struct noit_http_request noit_http_request;
73 struct noit_http_response;
74 typedef struct noit_http_response noit_http_response;
75
76 struct bchain {
77   bchain_type_t type;
78   struct bchain *next, *prev;
79   size_t start; /* where data starts (buff + start) */
80   size_t size;  /* data length (past start) */
81   size_t allocd;/* total allocation */
82   char *buff;
83   char _buff[1]; /* over allocate as needed */
84 };
85
86 struct noit_http_session_ctx;
87 typedef struct noit_http_session_ctx noit_http_session_ctx;
88 typedef int (*noit_http_dispatch_func) (noit_http_session_ctx *);
89
90 API_EXPORT(noit_http_session_ctx *)
91   noit_http_session_ctx_new(noit_http_dispatch_func, void *, eventer_t,
92                             acceptor_closure_t *);
93 API_EXPORT(void)
94   noit_http_ctx_session_release(noit_http_session_ctx *ctx);
95 API_EXPORT(uint32_t)
96   noit_http_session_ref_cnt(noit_http_session_ctx *);
97 API_EXPORT(uint32_t)
98   noit_http_session_ref_dec(noit_http_session_ctx *);
99 API_EXPORT(uint32_t)
100   noit_http_session_ref_inc(noit_http_session_ctx *);
101 API_EXPORT(void)
102   noit_http_session_trigger(noit_http_session_ctx *, int state);
103
104 API_EXPORT(noit_http_request *)
105   noit_http_session_request(noit_http_session_ctx *);
106 API_EXPORT(noit_http_response *)
107   noit_http_session_response(noit_http_session_ctx *);
108 API_EXPORT(noit_http_connection *)
109   noit_http_session_connection(noit_http_session_ctx *);
110
111 API_EXPORT(void *)
112   noit_http_session_dispatcher_closure(noit_http_session_ctx *);
113 API_EXPORT(void)
114   noit_http_session_set_dispatcher(noit_http_session_ctx *,
115                                    int (*)(noit_http_session_ctx *), void *);
116
117 API_EXPORT(eventer_t)
118   noit_http_connection_event(noit_http_connection *);
119
120 API_EXPORT(void)
121   noit_http_request_start_time(noit_http_request *, struct timeval *);
122 API_EXPORT(const char *)
123   noit_http_request_uri_str(noit_http_request *);
124 API_EXPORT(const char *)
125   noit_http_request_method_str(noit_http_request *);
126 API_EXPORT(const char *)
127   noit_http_request_protocol_str(noit_http_request *);
128 API_EXPORT(size_t)
129   noit_http_request_content_length(noit_http_request *);
130 API_EXPORT(const char *)
131   noit_http_request_querystring(noit_http_request *, const char *);
132 API_EXPORT(noit_hash_table *)
133   noit_http_request_querystring_table(noit_http_request *);
134 API_EXPORT(noit_hash_table *)
135   noit_http_request_headers_table(noit_http_request *);
136
137 API_EXPORT(noit_boolean)
138   noit_http_response_closed(noit_http_response *);
139 API_EXPORT(noit_boolean)
140   noit_http_response_complete(noit_http_response *);
141
142 API_EXPORT(void)
143   noit_http_ctx_acceptor_free(void *); /* just calls noit_http_session_ctx_release */
144
145 API_EXPORT(void)
146   noit_http_process_querystring(noit_http_request *);
147
148 API_EXPORT(int)
149   noit_http_session_drive(eventer_t, int, void *, struct timeval *, int *done);
150
151 API_EXPORT(noit_boolean)
152   noit_http_session_prime_input(noit_http_session_ctx *, const void *, size_t);
153 API_EXPORT(int)
154   noit_http_session_req_consume(noit_http_session_ctx *ctx,
155                                 void *buf, size_t len, int *mask);
156 API_EXPORT(noit_boolean)
157   noit_http_response_status_set(noit_http_session_ctx *, int, const char *);
158 API_EXPORT(noit_boolean)
159   noit_http_response_header_set(noit_http_session_ctx *,
160                                 const char *, const char *);
161 API_EXPORT(noit_boolean)
162   noit_http_response_option_set(noit_http_session_ctx *, u_int32_t);
163 API_EXPORT(noit_boolean)
164   noit_http_response_append(noit_http_session_ctx *, const void *, size_t);
165 API_EXPORT(noit_boolean)
166   noit_http_response_append_bchain(noit_http_session_ctx *, struct bchain *);
167 API_EXPORT(noit_boolean)
168   noit_http_response_append_mmap(noit_http_session_ctx *,
169                                  int fd, size_t len, int flags, off_t offset);
170 API_EXPORT(noit_boolean)
171   noit_http_response_flush(noit_http_session_ctx *, noit_boolean);
172 API_EXPORT(noit_boolean)
173   noit_http_response_flush_asynch(noit_http_session_ctx *, noit_boolean);
174 API_EXPORT(noit_boolean) noit_http_response_end(noit_http_session_ctx *);
175
176 #define noit_http_response_server_error(ctx, type) \
177   noit_http_response_standard(ctx, 500, "ERROR", type)
178 #define noit_http_response_ok(ctx, type) \
179   noit_http_response_standard(ctx, 200, "OK", type)
180 #define noit_http_response_not_found(ctx, type) \
181   noit_http_response_standard(ctx, 404, "NOT FOUND", type)
182 #define noit_http_response_denied(ctx, type) \
183   noit_http_response_standard(ctx, 403, "DENIED", type)
184
185 #define noit_http_response_standard(ctx, code, name, type) do { \
186   noit_http_response_status_set(ctx, code, name); \
187   noit_http_response_header_set(ctx, "Content-Type", type); \
188   if(noit_http_response_option_set(ctx, NOIT_HTTP_CHUNKED) == noit_false) \
189     noit_http_response_option_set(ctx, NOIT_HTTP_CLOSE); \
190   noit_http_response_option_set(ctx, NOIT_HTTP_GZIP); \
191 } while(0)
192
193 API_EXPORT(void)
194   noit_http_response_xml(noit_http_session_ctx *, xmlDocPtr);
195
196 API_EXPORT(void)
197   noit_http_init();
198
199 NOIT_HOOK_PROTO(http_request_log,
200                 (noit_http_session_ctx *ctx),
201                 void *, closure,
202                 (void *closure, noit_http_session_ctx *ctx))
203
204 #endif
Note: See TracBrowser for help on using the browser.