root/src/noit_http.h

Revision 675173e454538d1f10ec589f954faf96472b1a66, 8.0 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 6 months ago)

hit a strange bug fixed by dropping memlevel to the default 8

  • 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 struct noit_http_connection;
64 typedef struct noit_http_connection noit_http_connection;
65 struct noit_http_request;
66 typedef struct noit_http_request noit_http_request;
67 struct noit_http_response;
68 typedef struct noit_http_response noit_http_response;
69
70 struct bchain {
71   bchain_type_t type;
72   struct bchain *next, *prev;
73   size_t start; /* where data starts (buff + start) */
74   size_t size;  /* data length (past start) */
75   size_t allocd;/* total allocation */
76   char *buff;
77   char _buff[1]; /* over allocate as needed */
78 };
79
80 struct noit_http_session_ctx;
81 typedef struct noit_http_session_ctx noit_http_session_ctx;
82 typedef int (*noit_http_dispatch_func) (noit_http_session_ctx *);
83
84 API_EXPORT(noit_http_session_ctx *)
85   noit_http_session_ctx_new(noit_http_dispatch_func, void *, eventer_t,
86                             acceptor_closure_t *);
87 API_EXPORT(void)
88   noit_http_ctx_session_release(noit_http_session_ctx *ctx);
89 API_EXPORT(uint32_t)
90   noit_http_session_ref_cnt(noit_http_session_ctx *);
91 API_EXPORT(uint32_t)
92   noit_http_session_ref_dec(noit_http_session_ctx *);
93 API_EXPORT(uint32_t)
94   noit_http_session_ref_inc(noit_http_session_ctx *);
95 API_EXPORT(void)
96   noit_http_session_trigger(noit_http_session_ctx *, int state);
97
98 API_EXPORT(noit_http_request *)
99   noit_http_session_request(noit_http_session_ctx *);
100 API_EXPORT(noit_http_response *)
101   noit_http_session_response(noit_http_session_ctx *);
102 API_EXPORT(noit_http_connection *)
103   noit_http_session_connection(noit_http_session_ctx *);
104
105 API_EXPORT(void *)
106   noit_http_session_dispatcher_closure(noit_http_session_ctx *);
107 API_EXPORT(void)
108   noit_http_session_set_dispatcher(noit_http_session_ctx *,
109                                    int (*)(noit_http_session_ctx *), void *);
110
111 API_EXPORT(eventer_t)
112   noit_http_connection_event(noit_http_connection *);
113
114 /* Internally copies and returns the old one */
115 API_EXPORT(eventer_t)
116   noit_http_connection_event_float(noit_http_connection *);
117
118 API_EXPORT(void)
119   noit_http_request_start_time(noit_http_request *, struct timeval *);
120 API_EXPORT(const char *)
121   noit_http_request_uri_str(noit_http_request *);
122 API_EXPORT(const char *)
123   noit_http_request_method_str(noit_http_request *);
124 API_EXPORT(const char *)
125   noit_http_request_protocol_str(noit_http_request *);
126 API_EXPORT(size_t)
127   noit_http_request_content_length(noit_http_request *);
128 API_EXPORT(noit_boolean)
129   noit_http_request_payload_chunked(noit_http_request *);
130 API_EXPORT(noit_boolean)
131   noit_http_request_has_payload(noit_http_request *);
132 API_EXPORT(const char *)
133   noit_http_request_querystring(noit_http_request *, const char *);
134 API_EXPORT(noit_hash_table *)
135   noit_http_request_querystring_table(noit_http_request *);
136 API_EXPORT(noit_hash_table *)
137   noit_http_request_headers_table(noit_http_request *);
138 API_EXPORT(void)
139   noit_http_request_set_upload(noit_http_request *,
140                                void *data, int64_t size,
141                                void (*freefunc)(void *, int64_t, void *),
142                                void *closure);
143 API_EXPORT(const void *)
144   noit_http_request_get_upload(noit_http_request *, int64_t *size);
145
146
147 API_EXPORT(noit_boolean)
148   noit_http_response_closed(noit_http_response *);
149 API_EXPORT(noit_boolean)
150   noit_http_response_complete(noit_http_response *);
151 API_EXPORT(size_t)
152   noit_http_response_bytes_written(noit_http_response *);
153
154 API_EXPORT(void)
155   noit_http_ctx_acceptor_free(void *); /* just calls noit_http_session_ctx_release */
156
157 API_EXPORT(void)
158   noit_http_process_querystring(noit_http_request *);
159
160 API_EXPORT(int)
161   noit_http_session_drive(eventer_t, int, void *, struct timeval *, int *done);
162
163 API_EXPORT(noit_boolean)
164   noit_http_session_prime_input(noit_http_session_ctx *, const void *, size_t);
165 API_EXPORT(int)
166   noit_http_session_req_consume(noit_http_session_ctx *ctx,
167                                 void *buf, size_t len, size_t blen, int *mask);
168 API_EXPORT(noit_boolean)
169   noit_http_response_status_set(noit_http_session_ctx *, int, const char *);
170 API_EXPORT(noit_boolean)
171   noit_http_response_header_set(noit_http_session_ctx *,
172                                 const char *, const char *);
173 API_EXPORT(noit_boolean)
174   noit_http_response_option_set(noit_http_session_ctx *, u_int32_t);
175 API_EXPORT(noit_boolean)
176   noit_http_response_append(noit_http_session_ctx *, const void *, size_t);
177 API_EXPORT(noit_boolean)
178   noit_http_response_append_bchain(noit_http_session_ctx *, struct bchain *);
179 API_EXPORT(noit_boolean)
180   noit_http_response_append_mmap(noit_http_session_ctx *,
181                                  int fd, size_t len, int flags, off_t offset);
182 API_EXPORT(noit_boolean)
183   noit_http_response_flush(noit_http_session_ctx *, noit_boolean);
184 API_EXPORT(noit_boolean)
185   noit_http_response_flush_asynch(noit_http_session_ctx *, noit_boolean);
186 API_EXPORT(noit_boolean) noit_http_response_end(noit_http_session_ctx *);
187
188 #define noit_http_response_server_error(ctx, type) \
189   noit_http_response_standard(ctx, 500, "ERROR", type)
190 #define noit_http_response_ok(ctx, type) \
191   noit_http_response_standard(ctx, 200, "OK", type)
192 #define noit_http_response_not_found(ctx, type) \
193   noit_http_response_standard(ctx, 404, "NOT FOUND", type)
194 #define noit_http_response_denied(ctx, type) \
195   noit_http_response_standard(ctx, 403, "DENIED", type)
196
197 #define noit_http_response_standard(ctx, code, name, type) do { \
198   noit_http_response_status_set(ctx, code, name); \
199   noit_http_response_header_set(ctx, "Content-Type", type); \
200   if(noit_http_response_option_set(ctx, NOIT_HTTP_CHUNKED) == noit_false) \
201     noit_http_response_option_set(ctx, NOIT_HTTP_CLOSE); \
202   noit_http_response_option_set(ctx, NOIT_HTTP_GZIP); \
203 } while(0)
204
205 API_EXPORT(void)
206   noit_http_response_xml(noit_http_session_ctx *, xmlDocPtr);
207
208 API_EXPORT(void)
209   noit_http_init();
210
211 NOIT_HOOK_PROTO(http_request_log,
212                 (noit_http_session_ctx *ctx),
213                 void *, closure,
214                 (void *closure, noit_http_session_ctx *ctx))
215
216 #endif
Note: See TracBrowser for help on using the browser.