root/src/noit_http.h

Revision ab0fdf4bbb1ce96f103dc9065c9873e717ae30d1, 8.3 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 1 year ago)

provide a float API

  • 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 /* Internally copies and returns the old one */
121 API_EXPORT(eventer_t)
122   noit_http_connection_event_float(noit_http_connection *);
123
124 API_EXPORT(void)
125   noit_http_request_start_time(noit_http_request *, struct timeval *);
126 API_EXPORT(const char *)
127   noit_http_request_uri_str(noit_http_request *);
128 API_EXPORT(const char *)
129   noit_http_request_method_str(noit_http_request *);
130 API_EXPORT(const char *)
131   noit_http_request_protocol_str(noit_http_request *);
132 API_EXPORT(size_t)
133   noit_http_request_content_length(noit_http_request *);
134 API_EXPORT(noit_boolean)
135   noit_http_request_payload_chunked(noit_http_request *);
136 API_EXPORT(noit_boolean)
137   noit_http_request_has_payload(noit_http_request *);
138 API_EXPORT(const char *)
139   noit_http_request_querystring(noit_http_request *, const char *);
140 API_EXPORT(noit_hash_table *)
141   noit_http_request_querystring_table(noit_http_request *);
142 API_EXPORT(noit_hash_table *)
143   noit_http_request_headers_table(noit_http_request *);
144 API_EXPORT(void)
145   noit_http_request_set_upload(noit_http_request *,
146                                void *data, int64_t size,
147                                void (*freefunc)(void *, int64_t, void *),
148                                void *closure);
149 API_EXPORT(const void *)
150   noit_http_request_get_upload(noit_http_request *, int64_t *size);
151
152
153 API_EXPORT(noit_boolean)
154   noit_http_response_closed(noit_http_response *);
155 API_EXPORT(noit_boolean)
156   noit_http_response_complete(noit_http_response *);
157 API_EXPORT(size_t)
158   noit_http_response_bytes_written(noit_http_response *);
159
160 API_EXPORT(void)
161   noit_http_ctx_acceptor_free(void *); /* just calls noit_http_session_ctx_release */
162
163 API_EXPORT(void)
164   noit_http_process_querystring(noit_http_request *);
165
166 API_EXPORT(int)
167   noit_http_session_drive(eventer_t, int, void *, struct timeval *, int *done);
168
169 API_EXPORT(noit_boolean)
170   noit_http_session_prime_input(noit_http_session_ctx *, const void *, size_t);
171 API_EXPORT(int)
172   noit_http_session_req_consume(noit_http_session_ctx *ctx,
173                                 void *buf, size_t len, size_t blen, int *mask);
174 API_EXPORT(noit_boolean)
175   noit_http_response_status_set(noit_http_session_ctx *, int, const char *);
176 API_EXPORT(noit_boolean)
177   noit_http_response_header_set(noit_http_session_ctx *,
178                                 const char *, const char *);
179 API_EXPORT(noit_boolean)
180   noit_http_response_option_set(noit_http_session_ctx *, u_int32_t);
181 API_EXPORT(noit_boolean)
182   noit_http_response_append(noit_http_session_ctx *, const void *, size_t);
183 API_EXPORT(noit_boolean)
184   noit_http_response_append_bchain(noit_http_session_ctx *, struct bchain *);
185 API_EXPORT(noit_boolean)
186   noit_http_response_append_mmap(noit_http_session_ctx *,
187                                  int fd, size_t len, int flags, off_t offset);
188 API_EXPORT(noit_boolean)
189   noit_http_response_flush(noit_http_session_ctx *, noit_boolean);
190 API_EXPORT(noit_boolean)
191   noit_http_response_flush_asynch(noit_http_session_ctx *, noit_boolean);
192 API_EXPORT(noit_boolean) noit_http_response_end(noit_http_session_ctx *);
193
194 #define noit_http_response_server_error(ctx, type) \
195   noit_http_response_standard(ctx, 500, "ERROR", type)
196 #define noit_http_response_ok(ctx, type) \
197   noit_http_response_standard(ctx, 200, "OK", type)
198 #define noit_http_response_not_found(ctx, type) \
199   noit_http_response_standard(ctx, 404, "NOT FOUND", type)
200 #define noit_http_response_denied(ctx, type) \
201   noit_http_response_standard(ctx, 403, "DENIED", type)
202
203 #define noit_http_response_standard(ctx, code, name, type) do { \
204   noit_http_response_status_set(ctx, code, name); \
205   noit_http_response_header_set(ctx, "Content-Type", type); \
206   if(noit_http_response_option_set(ctx, NOIT_HTTP_CHUNKED) == noit_false) \
207     noit_http_response_option_set(ctx, NOIT_HTTP_CLOSE); \
208   noit_http_response_option_set(ctx, NOIT_HTTP_GZIP); \
209 } while(0)
210
211 API_EXPORT(void)
212   noit_http_response_xml(noit_http_session_ctx *, xmlDocPtr);
213
214 API_EXPORT(void)
215   noit_http_init();
216
217 NOIT_HOOK_PROTO(http_request_log,
218                 (noit_http_session_ctx *ctx),
219                 void *, closure,
220                 (void *closure, noit_http_session_ctx *ctx))
221
222 #endif
Note: See TracBrowser for help on using the browser.