nxt_application.h (718:f6866084cc80) nxt_application.h (743:e0f0cd7d244a)
1
2/*
3 * Copyright (C) Max Romanov
4 * Copyright (C) Valentin V. Bartenev
5 * Copyright (C) NGINX, Inc.
6 */
7
8#ifndef _NXT_APPLICATION_H_INCLUDED_
9#define _NXT_APPLICATION_H_INCLUDED_
10
11
12#include <nxt_conf.h>
13
1
2/*
3 * Copyright (C) Max Romanov
4 * Copyright (C) Valentin V. Bartenev
5 * Copyright (C) NGINX, Inc.
6 */
7
8#ifndef _NXT_APPLICATION_H_INCLUDED_
9#define _NXT_APPLICATION_H_INCLUDED_
10
11
12#include <nxt_conf.h>
13
14#include <nxt_unit_typedefs.h>
14
15
16
15typedef enum {
16 NXT_APP_PYTHON,
17 NXT_APP_PHP,
18 NXT_APP_GO,
19 NXT_APP_PERL,
20 NXT_APP_RUBY,
21
22 NXT_APP_UNKNOWN,
23} nxt_app_type_t;
24
25
17typedef enum {
18 NXT_APP_PYTHON,
19 NXT_APP_PHP,
20 NXT_APP_GO,
21 NXT_APP_PERL,
22 NXT_APP_RUBY,
23
24 NXT_APP_UNKNOWN,
25} nxt_app_type_t;
26
27
26typedef struct nxt_app_module_s nxt_application_module_t;
27typedef struct nxt_app_module_s nxt_app_module_t;
28
29
30typedef struct {
31 nxt_app_type_t type;
32 u_char *version;
33 char *file;
28typedef struct nxt_app_module_s nxt_app_module_t;
29
30
31typedef struct {
32 nxt_app_type_t type;
33 u_char *version;
34 char *file;
34 nxt_application_module_t *module;
35 nxt_app_module_t *module;
35} nxt_app_lang_module_t;
36
37
38typedef struct nxt_common_app_conf_s nxt_common_app_conf_t;
39
40
41typedef struct {
42 char *home;

--- 81 unchanged lines hidden (view full) ---

124
125 nxt_str_t remote;
126 nxt_str_t local;
127} nxt_app_request_t;
128
129
130typedef struct nxt_app_parse_ctx_s nxt_app_parse_ctx_t;
131
36} nxt_app_lang_module_t;
37
38
39typedef struct nxt_common_app_conf_s nxt_common_app_conf_t;
40
41
42typedef struct {
43 char *home;

--- 81 unchanged lines hidden (view full) ---

125
126 nxt_str_t remote;
127 nxt_str_t local;
128} nxt_app_request_t;
129
130
131typedef struct nxt_app_parse_ctx_s nxt_app_parse_ctx_t;
132
133
132struct nxt_app_parse_ctx_s {
133 nxt_app_request_t r;
134 nxt_http_request_t *request;
135 nxt_timer_t timer;
136 void *timer_data;
137 nxt_http_request_parse_t parser;
138 nxt_http_request_parse_t resp_parser;
139 nxt_mp_t *mem_pool;
140};
141
142
143nxt_int_t nxt_app_http_req_done(nxt_task_t *task, nxt_app_parse_ctx_t *ctx);
144
145
134struct nxt_app_parse_ctx_s {
135 nxt_app_request_t r;
136 nxt_http_request_t *request;
137 nxt_timer_t timer;
138 void *timer_data;
139 nxt_http_request_parse_t parser;
140 nxt_http_request_parse_t resp_parser;
141 nxt_mp_t *mem_pool;
142};
143
144
145nxt_int_t nxt_app_http_req_done(nxt_task_t *task, nxt_app_parse_ctx_t *ctx);
146
147
146typedef struct nxt_app_wmsg_s nxt_app_wmsg_t;
147typedef struct nxt_app_rmsg_s nxt_app_rmsg_t;
148
149struct nxt_app_wmsg_s {
150 nxt_port_t *port; /* where prepared buf will be sent */
151 nxt_buf_t *write;
152 nxt_buf_t **buf;
153 uint32_t stream;
154};
155
156
157struct nxt_app_rmsg_s {
158 nxt_buf_t *buf; /* current buffer to read */
159};
160
161
162nxt_inline u_char *
163nxt_app_msg_write_length(u_char *dst, size_t length);
164
165/* TODO asynchronous mmap buffer assignment */
166NXT_EXPORT u_char *nxt_app_msg_write_get_buf(nxt_task_t *task,
167 nxt_app_wmsg_t *msg, size_t size);
168
169NXT_EXPORT nxt_int_t nxt_app_msg_write(nxt_task_t *task, nxt_app_wmsg_t *msg,
170 u_char *c, size_t size);
171
172NXT_EXPORT nxt_int_t nxt_app_msg_write_prefixed_upcase(nxt_task_t *task,
173 nxt_app_wmsg_t *msg, const nxt_str_t *prefix, u_char *c, size_t size);
174
175nxt_inline nxt_int_t
176nxt_app_msg_write_nvp_(nxt_task_t *task, nxt_app_wmsg_t *msg,
177 u_char *n, size_t nsize, u_char *v, size_t vsize);
178
179
180#define nxt_app_msg_write_const(task, msg, c) \
181 nxt_app_msg_write((task), (msg), (u_char *) (c), nxt_length(c))
182
183#define nxt_app_msg_write_str(task, msg, str) \
184 nxt_app_msg_write((task), (msg), (str)->start, (str)->length)
185
186#define nxt_app_msg_write_cstr(task, msg, c) \
187 nxt_app_msg_write((task), (msg), (c), nxt_strlen(c))
188
189#define nxt_app_msg_write_nvp(task, msg, n, v) \
190 nxt_app_msg_write_nvp_((task), (msg), (u_char *) (n), nxt_length(n), \
191 (v)->start, (v)->length)
192
193nxt_inline nxt_int_t nxt_app_msg_write_size(nxt_task_t *task,
194 nxt_app_wmsg_t *msg, size_t size);
195
196NXT_EXPORT nxt_int_t nxt_app_msg_flush(nxt_task_t *task, nxt_app_wmsg_t *msg,
197 nxt_bool_t last);
198
199NXT_EXPORT nxt_int_t nxt_app_msg_write_raw(nxt_task_t *task,
200 nxt_app_wmsg_t *msg, const u_char *c, size_t size);
201
202NXT_EXPORT nxt_int_t nxt_app_msg_read_str(nxt_task_t *task, nxt_app_rmsg_t *msg,
203 nxt_str_t *str);
204
205NXT_EXPORT size_t nxt_app_msg_read_raw(nxt_task_t *task,
206 nxt_app_rmsg_t *msg, void *buf, size_t size);
207
208NXT_EXPORT nxt_int_t nxt_app_msg_read_nvp(nxt_task_t *task,
209 nxt_app_rmsg_t *rmsg, nxt_str_t *n, nxt_str_t *v);
210
211NXT_EXPORT nxt_int_t nxt_app_msg_read_size(nxt_task_t *task,
212 nxt_app_rmsg_t *rmsg, size_t *size);
213
214
215struct nxt_app_module_s {
216 size_t compat_length;
217 uint32_t *compat;
218
219 nxt_str_t type;
220 const char *version;
221
222 nxt_int_t (*init)(nxt_task_t *task,
223 nxt_common_app_conf_t *conf);
148struct nxt_app_module_s {
149 size_t compat_length;
150 uint32_t *compat;
151
152 nxt_str_t type;
153 const char *version;
154
155 nxt_int_t (*init)(nxt_task_t *task,
156 nxt_common_app_conf_t *conf);
224 nxt_int_t (*run)(nxt_task_t *task,
225 nxt_app_rmsg_t *rmsg,
226 nxt_app_wmsg_t *wmsg);
227 void (*atexit)(nxt_task_t *task);
228};
229
230
157};
158
159
231nxt_int_t nxt_app_http_read_body(nxt_app_request_t *r, u_char *data,
232 size_t len);
233nxt_int_t nxt_app_write(nxt_app_request_t *r, const u_char *data, size_t len);
234
235nxt_inline u_char *
236nxt_app_msg_write_length(u_char *dst, size_t length)
237{
238 if (length < 128) {
239 *dst = length;
240 dst++;
241
242 } else {
243 dst[0] = 0x80U | (length >> 24);
244 dst[1] = 0xFFU & (length >> 16);
245 dst[2] = 0xFFU & (length >> 8);
246 dst[3] = 0xFFU & length;
247 dst += 4;
248 }
249
250 return dst;
251}
252
253
254nxt_inline nxt_int_t
255nxt_app_msg_write_nvp_(nxt_task_t *task, nxt_app_wmsg_t *msg,
256 u_char *n, size_t nsize, u_char *v, size_t vsize)
257{
258 nxt_int_t rc;
259
260 rc = nxt_app_msg_write(task, msg, n, nsize);
261 if (nxt_slow_path(rc != NXT_OK)) {
262 return rc;
263 }
264
265 return nxt_app_msg_write(task, msg, v, vsize);
266}
267
268
269nxt_inline nxt_int_t
270nxt_app_msg_write_size(nxt_task_t *task, nxt_app_wmsg_t *msg, size_t size)
271{
272 u_char *dst;
273 size_t dst_length;
274
275 dst_length = size < 128 ? 1 : 4;
276
277 dst = nxt_app_msg_write_get_buf(task, msg, dst_length);
278 if (nxt_slow_path(dst == NULL)) {
279 return NXT_ERROR;
280 }
281
282 nxt_app_msg_write_length(dst, size);
283
284 return NXT_OK;
285}
286
287
288nxt_inline u_char *
289nxt_app_msg_read_length(u_char *src, size_t *length)
290{
291 if (src[0] < 128) {
292 *length = src[0];
293 src++;
294
295 } else {
296 *length = ((src[0] & 0x7FU) << 24)
297 + ( src[1] << 16)
298 + ( src[2] << 8)
299 + src[3];
300 src += 4;
301 }
302
303 return src;
304}
305
306
307nxt_app_lang_module_t *nxt_app_lang_module(nxt_runtime_t *rt, nxt_str_t *name);
308nxt_app_type_t nxt_app_parse_type(u_char *p, size_t length);
309
160nxt_app_lang_module_t *nxt_app_lang_module(nxt_runtime_t *rt, nxt_str_t *name);
161nxt_app_type_t nxt_app_parse_type(u_char *p, size_t length);
162
310NXT_EXPORT extern nxt_str_t nxt_server;
311extern nxt_application_module_t nxt_go_module;
163NXT_EXPORT extern nxt_str_t nxt_server;
164extern nxt_app_module_t nxt_go_module;
312
165
166NXT_EXPORT nxt_int_t nxt_unit_default_init(nxt_task_t *task,
167 nxt_unit_init_t *init);
313
168
169
314#endif /* _NXT_APPLICATION_H_INCLIDED_ */
170#endif /* _NXT_APPLICATION_H_INCLIDED_ */