xref: /unit/src/nxt_application.h (revision 967:d693ed6d0209)
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>
15 
16 
17 typedef enum {
18     NXT_APP_EXTERNAL,
19     NXT_APP_PYTHON,
20     NXT_APP_PHP,
21     NXT_APP_PERL,
22     NXT_APP_RUBY,
23 
24     NXT_APP_UNKNOWN,
25 } nxt_app_type_t;
26 
27 
28 typedef struct nxt_app_module_s  nxt_app_module_t;
29 
30 
31 typedef struct {
32     nxt_app_type_t            type;
33     u_char                    *version;
34     char                      *file;
35     nxt_app_module_t          *module;
36 } nxt_app_lang_module_t;
37 
38 
39 typedef struct nxt_common_app_conf_s nxt_common_app_conf_t;
40 
41 
42 typedef struct {
43     char                       *executable;
44     nxt_conf_value_t           *arguments;
45 } nxt_external_app_conf_t;
46 
47 
48 typedef struct {
49     char       *home;
50     nxt_str_t  path;
51     nxt_str_t  module;
52 } nxt_python_app_conf_t;
53 
54 
55 typedef struct {
56     char                       *root;
57     nxt_str_t                  script;
58     nxt_str_t                  index;
59     nxt_conf_value_t           *options;
60 } nxt_php_app_conf_t;
61 
62 
63 typedef struct {
64     char       *script;
65 } nxt_perl_app_conf_t;
66 
67 
68 typedef struct {
69     nxt_str_t  script;
70 } nxt_ruby_app_conf_t;
71 
72 
73 struct nxt_common_app_conf_s {
74     nxt_str_t                  name;
75     nxt_str_t                  type;
76     nxt_str_t                  user;
77     nxt_str_t                  group;
78 
79     char                       *working_directory;
80     nxt_conf_value_t           *environment;
81 
82     union {
83         nxt_external_app_conf_t  external;
84         nxt_python_app_conf_t    python;
85         nxt_php_app_conf_t       php;
86         nxt_perl_app_conf_t      perl;
87         nxt_ruby_app_conf_t      ruby;
88     } u;
89 };
90 
91 
92 typedef struct {
93     nxt_str_t                  method;
94     nxt_str_t                  target;
95     nxt_str_t                  version;
96     nxt_str_t                  path;
97     nxt_str_t                  query;
98     nxt_str_t                  server_name;
99 
100     nxt_list_t                 *fields;
101 
102     nxt_str_t                  cookie;
103     nxt_str_t                  content_length;
104     nxt_str_t                  content_type;
105 
106     off_t                      parsed_content_length;
107     nxt_bool_t                 done;
108 
109     size_t                     bufs;
110     nxt_buf_t                  *buf;
111 } nxt_app_request_header_t;
112 
113 
114 typedef struct {
115     size_t                     preread_size;
116     nxt_bool_t                 done;
117 
118     nxt_buf_t                  *buf;
119 } nxt_app_request_body_t;
120 
121 
122 typedef struct {
123     nxt_app_request_header_t   header;
124     nxt_app_request_body_t     body;
125 
126     nxt_str_t                  remote;
127     nxt_str_t                  local;
128 } nxt_app_request_t;
129 
130 
131 typedef struct nxt_app_parse_ctx_s  nxt_app_parse_ctx_t;
132 
133 
134 struct 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 
145 nxt_int_t nxt_app_http_req_done(nxt_task_t *task, nxt_app_parse_ctx_t *ctx);
146 
147 
148 struct 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);
157 };
158 
159 
160 nxt_app_lang_module_t *nxt_app_lang_module(nxt_runtime_t *rt, nxt_str_t *name);
161 nxt_app_type_t nxt_app_parse_type(u_char *p, size_t length);
162 
163 NXT_EXPORT extern nxt_str_t  nxt_server;
164 extern nxt_app_module_t      nxt_external_module;
165 
166 NXT_EXPORT nxt_int_t nxt_unit_default_init(nxt_task_t *task,
167     nxt_unit_init_t *init);
168 
169 
170 #endif /* _NXT_APPLICATION_H_INCLIDED_ */
171