Update and clean Tomato RAF files
[tomato.git] / release / src / router / nginx / src / http / ngx_http_core_module.h
blob5b38000d8db1c55674031acf0ed364b06df8ee04
2 /*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
5 */
8 #ifndef _NGX_HTTP_CORE_H_INCLUDED_
9 #define _NGX_HTTP_CORE_H_INCLUDED_
12 #include <ngx_config.h>
13 #include <ngx_core.h>
14 #include <ngx_http.h>
17 #define NGX_HTTP_GZIP_PROXIED_OFF 0x0002
18 #define NGX_HTTP_GZIP_PROXIED_EXPIRED 0x0004
19 #define NGX_HTTP_GZIP_PROXIED_NO_CACHE 0x0008
20 #define NGX_HTTP_GZIP_PROXIED_NO_STORE 0x0010
21 #define NGX_HTTP_GZIP_PROXIED_PRIVATE 0x0020
22 #define NGX_HTTP_GZIP_PROXIED_NO_LM 0x0040
23 #define NGX_HTTP_GZIP_PROXIED_NO_ETAG 0x0080
24 #define NGX_HTTP_GZIP_PROXIED_AUTH 0x0100
25 #define NGX_HTTP_GZIP_PROXIED_ANY 0x0200
28 #define NGX_HTTP_AIO_OFF 0
29 #define NGX_HTTP_AIO_ON 1
30 #define NGX_HTTP_AIO_SENDFILE 2
33 #define NGX_HTTP_SATISFY_ALL 0
34 #define NGX_HTTP_SATISFY_ANY 1
37 #define NGX_HTTP_LINGERING_OFF 0
38 #define NGX_HTTP_LINGERING_ON 1
39 #define NGX_HTTP_LINGERING_ALWAYS 2
42 #define NGX_HTTP_IMS_OFF 0
43 #define NGX_HTTP_IMS_EXACT 1
44 #define NGX_HTTP_IMS_BEFORE 2
47 #define NGX_HTTP_KEEPALIVE_DISABLE_NONE 0x0002
48 #define NGX_HTTP_KEEPALIVE_DISABLE_MSIE6 0x0004
49 #define NGX_HTTP_KEEPALIVE_DISABLE_SAFARI 0x0008
52 typedef struct ngx_http_location_tree_node_s ngx_http_location_tree_node_t;
53 typedef struct ngx_http_core_loc_conf_s ngx_http_core_loc_conf_t;
56 typedef struct {
57 union {
58 struct sockaddr sockaddr;
59 struct sockaddr_in sockaddr_in;
60 #if (NGX_HAVE_INET6)
61 struct sockaddr_in6 sockaddr_in6;
62 #endif
63 #if (NGX_HAVE_UNIX_DOMAIN)
64 struct sockaddr_un sockaddr_un;
65 #endif
66 u_char sockaddr_data[NGX_SOCKADDRLEN];
67 } u;
69 socklen_t socklen;
71 unsigned set:1;
72 unsigned default_server:1;
73 unsigned bind:1;
74 unsigned wildcard:1;
75 #if (NGX_HTTP_SSL)
76 unsigned ssl:1;
77 #endif
78 #if (NGX_HTTP_SPDY)
79 unsigned spdy:1;
80 #endif
81 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
82 unsigned ipv6only:1;
83 #endif
84 unsigned so_keepalive:2;
86 int backlog;
87 int rcvbuf;
88 int sndbuf;
89 #if (NGX_HAVE_SETFIB)
90 int setfib;
91 #endif
92 #if (NGX_HAVE_KEEPALIVE_TUNABLE)
93 int tcp_keepidle;
94 int tcp_keepintvl;
95 int tcp_keepcnt;
96 #endif
98 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
99 char *accept_filter;
100 #endif
101 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
102 ngx_uint_t deferred_accept;
103 #endif
105 u_char addr[NGX_SOCKADDR_STRLEN + 1];
106 } ngx_http_listen_opt_t;
109 typedef enum {
110 NGX_HTTP_POST_READ_PHASE = 0,
112 NGX_HTTP_SERVER_REWRITE_PHASE,
114 NGX_HTTP_FIND_CONFIG_PHASE,
115 NGX_HTTP_REWRITE_PHASE,
116 NGX_HTTP_POST_REWRITE_PHASE,
118 NGX_HTTP_PREACCESS_PHASE,
120 NGX_HTTP_ACCESS_PHASE,
121 NGX_HTTP_POST_ACCESS_PHASE,
123 NGX_HTTP_TRY_FILES_PHASE,
124 NGX_HTTP_CONTENT_PHASE,
126 NGX_HTTP_LOG_PHASE
127 } ngx_http_phases;
129 typedef struct ngx_http_phase_handler_s ngx_http_phase_handler_t;
131 typedef ngx_int_t (*ngx_http_phase_handler_pt)(ngx_http_request_t *r,
132 ngx_http_phase_handler_t *ph);
134 struct ngx_http_phase_handler_s {
135 ngx_http_phase_handler_pt checker;
136 ngx_http_handler_pt handler;
137 ngx_uint_t next;
141 typedef struct {
142 ngx_http_phase_handler_t *handlers;
143 ngx_uint_t server_rewrite_index;
144 ngx_uint_t location_rewrite_index;
145 } ngx_http_phase_engine_t;
148 typedef struct {
149 ngx_array_t handlers;
150 } ngx_http_phase_t;
153 typedef struct {
154 ngx_array_t servers; /* ngx_http_core_srv_conf_t */
156 ngx_http_phase_engine_t phase_engine;
158 ngx_hash_t headers_in_hash;
160 ngx_hash_t variables_hash;
162 ngx_array_t variables; /* ngx_http_variable_t */
163 ngx_uint_t ncaptures;
165 ngx_uint_t server_names_hash_max_size;
166 ngx_uint_t server_names_hash_bucket_size;
168 ngx_uint_t variables_hash_max_size;
169 ngx_uint_t variables_hash_bucket_size;
171 ngx_hash_keys_arrays_t *variables_keys;
173 ngx_array_t *ports;
175 ngx_uint_t try_files; /* unsigned try_files:1 */
177 ngx_http_phase_t phases[NGX_HTTP_LOG_PHASE + 1];
178 } ngx_http_core_main_conf_t;
181 typedef struct {
182 /* array of the ngx_http_server_name_t, "server_name" directive */
183 ngx_array_t server_names;
185 /* server ctx */
186 ngx_http_conf_ctx_t *ctx;
188 ngx_str_t server_name;
190 size_t connection_pool_size;
191 size_t request_pool_size;
192 size_t client_header_buffer_size;
194 ngx_bufs_t large_client_header_buffers;
196 ngx_msec_t client_header_timeout;
198 ngx_flag_t ignore_invalid_headers;
199 ngx_flag_t merge_slashes;
200 ngx_flag_t underscores_in_headers;
202 unsigned listen:1;
203 #if (NGX_PCRE)
204 unsigned captures:1;
205 #endif
207 ngx_http_core_loc_conf_t **named_locations;
208 } ngx_http_core_srv_conf_t;
211 /* list of structures to find core_srv_conf quickly at run time */
214 typedef struct {
215 #if (NGX_PCRE)
216 ngx_http_regex_t *regex;
217 #endif
218 ngx_http_core_srv_conf_t *server; /* virtual name server conf */
219 ngx_str_t name;
220 } ngx_http_server_name_t;
223 typedef struct {
224 ngx_hash_combined_t names;
226 ngx_uint_t nregex;
227 ngx_http_server_name_t *regex;
228 } ngx_http_virtual_names_t;
231 struct ngx_http_addr_conf_s {
232 /* the default server configuration for this address:port */
233 ngx_http_core_srv_conf_t *default_server;
235 ngx_http_virtual_names_t *virtual_names;
237 #if (NGX_HTTP_SSL)
238 unsigned ssl:1;
239 #endif
240 #if (NGX_HTTP_SPDY)
241 unsigned spdy:1;
242 #endif
246 typedef struct {
247 in_addr_t addr;
248 ngx_http_addr_conf_t conf;
249 } ngx_http_in_addr_t;
252 #if (NGX_HAVE_INET6)
254 typedef struct {
255 struct in6_addr addr6;
256 ngx_http_addr_conf_t conf;
257 } ngx_http_in6_addr_t;
259 #endif
262 typedef struct {
263 /* ngx_http_in_addr_t or ngx_http_in6_addr_t */
264 void *addrs;
265 ngx_uint_t naddrs;
266 } ngx_http_port_t;
269 typedef struct {
270 ngx_int_t family;
271 in_port_t port;
272 ngx_array_t addrs; /* array of ngx_http_conf_addr_t */
273 } ngx_http_conf_port_t;
276 typedef struct {
277 ngx_http_listen_opt_t opt;
279 ngx_hash_t hash;
280 ngx_hash_wildcard_t *wc_head;
281 ngx_hash_wildcard_t *wc_tail;
283 #if (NGX_PCRE)
284 ngx_uint_t nregex;
285 ngx_http_server_name_t *regex;
286 #endif
288 /* the default server configuration for this address:port */
289 ngx_http_core_srv_conf_t *default_server;
290 ngx_array_t servers; /* array of ngx_http_core_srv_conf_t */
291 } ngx_http_conf_addr_t;
294 typedef struct {
295 ngx_int_t status;
296 ngx_int_t overwrite;
297 ngx_http_complex_value_t value;
298 ngx_str_t args;
299 } ngx_http_err_page_t;
302 typedef struct {
303 ngx_array_t *lengths;
304 ngx_array_t *values;
305 ngx_str_t name;
307 unsigned code:10;
308 unsigned test_dir:1;
309 } ngx_http_try_file_t;
312 struct ngx_http_core_loc_conf_s {
313 ngx_str_t name; /* location name */
315 #if (NGX_PCRE)
316 ngx_http_regex_t *regex;
317 #endif
319 unsigned noname:1; /* "if () {}" block or limit_except */
320 unsigned lmt_excpt:1;
321 unsigned named:1;
323 unsigned exact_match:1;
324 unsigned noregex:1;
326 unsigned auto_redirect:1;
327 #if (NGX_HTTP_GZIP)
328 unsigned gzip_disable_msie6:2;
329 #if (NGX_HTTP_DEGRADATION)
330 unsigned gzip_disable_degradation:2;
331 #endif
332 #endif
334 ngx_http_location_tree_node_t *static_locations;
335 #if (NGX_PCRE)
336 ngx_http_core_loc_conf_t **regex_locations;
337 #endif
339 /* pointer to the modules' loc_conf */
340 void **loc_conf;
342 uint32_t limit_except;
343 void **limit_except_loc_conf;
345 ngx_http_handler_pt handler;
347 /* location name length for inclusive location with inherited alias */
348 size_t alias;
349 ngx_str_t root; /* root, alias */
350 ngx_str_t post_action;
352 ngx_array_t *root_lengths;
353 ngx_array_t *root_values;
355 ngx_array_t *types;
356 ngx_hash_t types_hash;
357 ngx_str_t default_type;
359 off_t client_max_body_size; /* client_max_body_size */
360 off_t directio; /* directio */
361 off_t directio_alignment; /* directio_alignment */
363 size_t client_body_buffer_size; /* client_body_buffer_size */
364 size_t send_lowat; /* send_lowat */
365 size_t postpone_output; /* postpone_output */
366 size_t limit_rate; /* limit_rate */
367 size_t limit_rate_after; /* limit_rate_after */
368 size_t sendfile_max_chunk; /* sendfile_max_chunk */
369 size_t read_ahead; /* read_ahead */
371 ngx_msec_t client_body_timeout; /* client_body_timeout */
372 ngx_msec_t send_timeout; /* send_timeout */
373 ngx_msec_t keepalive_timeout; /* keepalive_timeout */
374 ngx_msec_t lingering_time; /* lingering_time */
375 ngx_msec_t lingering_timeout; /* lingering_timeout */
376 ngx_msec_t resolver_timeout; /* resolver_timeout */
378 ngx_resolver_t *resolver; /* resolver */
380 time_t keepalive_header; /* keepalive_timeout */
382 ngx_uint_t keepalive_requests; /* keepalive_requests */
383 ngx_uint_t keepalive_disable; /* keepalive_disable */
384 ngx_uint_t satisfy; /* satisfy */
385 ngx_uint_t lingering_close; /* lingering_close */
386 ngx_uint_t if_modified_since; /* if_modified_since */
387 ngx_uint_t max_ranges; /* max_ranges */
388 ngx_uint_t client_body_in_file_only; /* client_body_in_file_only */
390 ngx_flag_t client_body_in_single_buffer;
391 /* client_body_in_singe_buffer */
392 ngx_flag_t internal; /* internal */
393 ngx_flag_t sendfile; /* sendfile */
394 #if (NGX_HAVE_FILE_AIO)
395 ngx_flag_t aio; /* aio */
396 #endif
397 ngx_flag_t tcp_nopush; /* tcp_nopush */
398 ngx_flag_t tcp_nodelay; /* tcp_nodelay */
399 ngx_flag_t reset_timedout_connection; /* reset_timedout_connection */
400 ngx_flag_t server_name_in_redirect; /* server_name_in_redirect */
401 ngx_flag_t port_in_redirect; /* port_in_redirect */
402 ngx_flag_t msie_padding; /* msie_padding */
403 ngx_flag_t msie_refresh; /* msie_refresh */
404 ngx_flag_t log_not_found; /* log_not_found */
405 ngx_flag_t log_subrequest; /* log_subrequest */
406 ngx_flag_t recursive_error_pages; /* recursive_error_pages */
407 ngx_flag_t server_tokens; /* server_tokens */
408 ngx_flag_t chunked_transfer_encoding; /* chunked_transfer_encoding */
409 ngx_flag_t etag; /* etag */
411 #if (NGX_HTTP_GZIP)
412 ngx_flag_t gzip_vary; /* gzip_vary */
414 ngx_uint_t gzip_http_version; /* gzip_http_version */
415 ngx_uint_t gzip_proxied; /* gzip_proxied */
417 #if (NGX_PCRE)
418 ngx_array_t *gzip_disable; /* gzip_disable */
419 #endif
420 #endif
422 #if (NGX_HAVE_OPENAT)
423 ngx_uint_t disable_symlinks; /* disable_symlinks */
424 ngx_http_complex_value_t *disable_symlinks_from;
425 #endif
427 ngx_array_t *error_pages; /* error_page */
428 ngx_http_try_file_t *try_files; /* try_files */
430 ngx_path_t *client_body_temp_path; /* client_body_temp_path */
432 ngx_open_file_cache_t *open_file_cache;
433 time_t open_file_cache_valid;
434 ngx_uint_t open_file_cache_min_uses;
435 ngx_flag_t open_file_cache_errors;
436 ngx_flag_t open_file_cache_events;
438 ngx_log_t *error_log;
440 ngx_uint_t types_hash_max_size;
441 ngx_uint_t types_hash_bucket_size;
443 ngx_queue_t *locations;
445 #if 0
446 ngx_http_core_loc_conf_t *prev_location;
447 #endif
451 typedef struct {
452 ngx_queue_t queue;
453 ngx_http_core_loc_conf_t *exact;
454 ngx_http_core_loc_conf_t *inclusive;
455 ngx_str_t *name;
456 u_char *file_name;
457 ngx_uint_t line;
458 ngx_queue_t list;
459 } ngx_http_location_queue_t;
462 struct ngx_http_location_tree_node_s {
463 ngx_http_location_tree_node_t *left;
464 ngx_http_location_tree_node_t *right;
465 ngx_http_location_tree_node_t *tree;
467 ngx_http_core_loc_conf_t *exact;
468 ngx_http_core_loc_conf_t *inclusive;
470 u_char auto_redirect;
471 u_char len;
472 u_char name[1];
476 void ngx_http_core_run_phases(ngx_http_request_t *r);
477 ngx_int_t ngx_http_core_generic_phase(ngx_http_request_t *r,
478 ngx_http_phase_handler_t *ph);
479 ngx_int_t ngx_http_core_rewrite_phase(ngx_http_request_t *r,
480 ngx_http_phase_handler_t *ph);
481 ngx_int_t ngx_http_core_find_config_phase(ngx_http_request_t *r,
482 ngx_http_phase_handler_t *ph);
483 ngx_int_t ngx_http_core_post_rewrite_phase(ngx_http_request_t *r,
484 ngx_http_phase_handler_t *ph);
485 ngx_int_t ngx_http_core_access_phase(ngx_http_request_t *r,
486 ngx_http_phase_handler_t *ph);
487 ngx_int_t ngx_http_core_post_access_phase(ngx_http_request_t *r,
488 ngx_http_phase_handler_t *ph);
489 ngx_int_t ngx_http_core_try_files_phase(ngx_http_request_t *r,
490 ngx_http_phase_handler_t *ph);
491 ngx_int_t ngx_http_core_content_phase(ngx_http_request_t *r,
492 ngx_http_phase_handler_t *ph);
495 void *ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash);
496 ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r);
497 void ngx_http_set_exten(ngx_http_request_t *r);
498 ngx_int_t ngx_http_set_etag(ngx_http_request_t *r);
499 ngx_int_t ngx_http_send_response(ngx_http_request_t *r, ngx_uint_t status,
500 ngx_str_t *ct, ngx_http_complex_value_t *cv);
501 u_char *ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *name,
502 size_t *root_length, size_t reserved);
503 ngx_int_t ngx_http_auth_basic_user(ngx_http_request_t *r);
504 #if (NGX_HTTP_GZIP)
505 ngx_int_t ngx_http_gzip_ok(ngx_http_request_t *r);
506 #endif
509 ngx_int_t ngx_http_subrequest(ngx_http_request_t *r,
510 ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **sr,
511 ngx_http_post_subrequest_t *psr, ngx_uint_t flags);
512 ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r,
513 ngx_str_t *uri, ngx_str_t *args);
514 ngx_int_t ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name);
517 ngx_http_cleanup_t *ngx_http_cleanup_add(ngx_http_request_t *r, size_t size);
520 typedef ngx_int_t (*ngx_http_output_header_filter_pt)(ngx_http_request_t *r);
521 typedef ngx_int_t (*ngx_http_output_body_filter_pt)
522 (ngx_http_request_t *r, ngx_chain_t *chain);
525 ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *chain);
526 ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *chain);
529 ngx_int_t ngx_http_set_disable_symlinks(ngx_http_request_t *r,
530 ngx_http_core_loc_conf_t *clcf, ngx_str_t *path, ngx_open_file_info_t *of);
532 ngx_int_t ngx_http_get_forwarded_addr(ngx_http_request_t *r, ngx_addr_t *addr,
533 ngx_array_t *headers, ngx_str_t *value, ngx_array_t *proxies,
534 int recursive);
537 extern ngx_module_t ngx_http_core_module;
539 extern ngx_uint_t ngx_http_max_module;
541 extern ngx_str_t ngx_http_core_get_method;
544 #define ngx_http_clear_content_length(r) \
546 r->headers_out.content_length_n = -1; \
547 if (r->headers_out.content_length) { \
548 r->headers_out.content_length->hash = 0; \
549 r->headers_out.content_length = NULL; \
552 #define ngx_http_clear_accept_ranges(r) \
554 r->allow_ranges = 0; \
555 if (r->headers_out.accept_ranges) { \
556 r->headers_out.accept_ranges->hash = 0; \
557 r->headers_out.accept_ranges = NULL; \
560 #define ngx_http_clear_last_modified(r) \
562 r->headers_out.last_modified_time = -1; \
563 if (r->headers_out.last_modified) { \
564 r->headers_out.last_modified->hash = 0; \
565 r->headers_out.last_modified = NULL; \
568 #define ngx_http_clear_location(r) \
570 if (r->headers_out.location) { \
571 r->headers_out.location->hash = 0; \
572 r->headers_out.location = NULL; \
575 #define ngx_http_clear_etag(r) \
577 if (r->headers_out.etag) { \
578 r->headers_out.etag->hash = 0; \
579 r->headers_out.etag = NULL; \
583 #endif /* _NGX_HTTP_CORE_H_INCLUDED_ */