blob: 7f36ce54750019e94686d26515a8a3eee8e629aa [file] [log] [blame]
Igor Sysoevd90282d2004-09-28 08:34:51 +00001
2/*
Igor Sysoevff8da912004-09-29 16:00:49 +00003 * Copyright (C) Igor Sysoev
Igor Sysoevd90282d2004-09-28 08:34:51 +00004 */
5
6
Igor Sysoev7578ec92003-06-02 15:24:30 +00007#ifndef _NGX_HTTP_SCRIPT_H_INCLUDED_
8#define _NGX_HTTP_SCRIPT_H_INCLUDED_
9
10
Igor Sysoev02025fd2005-01-18 13:03:58 +000011#include <ngx_config.h>
12#include <ngx_core.h>
13#include <ngx_http.h>
14
15
Igor Sysoev02f742b2005-04-08 15:18:55 +000016typedef struct {
Igor Sysoev09c684b2005-11-09 17:25:55 +000017 u_char *ip;
18 u_char *pos;
19 ngx_http_variable_value_t *sp;
Igor Sysoev899b44e2005-05-12 14:58:06 +000020
Igor Sysoev09c684b2005-11-09 17:25:55 +000021 ngx_str_t buf;
22 ngx_str_t line;
Igor Sysoev899b44e2005-05-12 14:58:06 +000023
24 /* the start of the rewritten arguments */
Igor Sysoev09c684b2005-11-09 17:25:55 +000025 u_char *args;
Igor Sysoev899b44e2005-05-12 14:58:06 +000026
Igor Sysoev09c684b2005-11-09 17:25:55 +000027 unsigned flushed:1;
28 unsigned skip:1;
29 unsigned quote:1;
Igor Sysoev04610ea2008-02-12 18:05:32 +000030 unsigned is_args:1;
Igor Sysoev09c684b2005-11-09 17:25:55 +000031 unsigned log:1;
Igor Sysoev899b44e2005-05-12 14:58:06 +000032
Igor Sysoev09c684b2005-11-09 17:25:55 +000033 ngx_int_t status;
34 ngx_http_request_t *request;
Igor Sysoev02f742b2005-04-08 15:18:55 +000035} ngx_http_script_engine_t;
36
37
Igor Sysoev899b44e2005-05-12 14:58:06 +000038typedef struct {
Igor Sysoev09c684b2005-11-09 17:25:55 +000039 ngx_conf_t *cf;
40 ngx_str_t *source;
Igor Sysoev02f742b2005-04-08 15:18:55 +000041
Igor Sysoev09c684b2005-11-09 17:25:55 +000042 ngx_array_t **flushes;
43 ngx_array_t **lengths;
44 ngx_array_t **values;
Igor Sysoev899b44e2005-05-12 14:58:06 +000045
Igor Sysoev09c684b2005-11-09 17:25:55 +000046 ngx_uint_t variables;
47 ngx_uint_t ncaptures;
Igor Sysoev7f7846d2006-04-26 09:52:47 +000048 ngx_uint_t captures_mask;
Igor Sysoev09c684b2005-11-09 17:25:55 +000049 ngx_uint_t size;
Igor Sysoev899b44e2005-05-12 14:58:06 +000050
Igor Sysoev09c684b2005-11-09 17:25:55 +000051 void *main;
Igor Sysoev899b44e2005-05-12 14:58:06 +000052
Igor Sysoev09c684b2005-11-09 17:25:55 +000053 unsigned compile_args:1;
Igor Sysoev09c684b2005-11-09 17:25:55 +000054 unsigned complete_lengths:1;
55 unsigned complete_values:1;
Igor Sysoev8508c102009-03-22 09:36:51 +000056 unsigned zero:1;
57 unsigned conf_prefix:1;
58 unsigned root_prefix:1;
Igor Sysoev09c684b2005-11-09 17:25:55 +000059
Igor Sysoev8508c102009-03-22 09:36:51 +000060 unsigned dup_capture:1;
Igor Sysoev09c684b2005-11-09 17:25:55 +000061 unsigned args:1;
Igor Sysoev899b44e2005-05-12 14:58:06 +000062} ngx_http_script_compile_t;
63
64
Igor Sysoev8508c102009-03-22 09:36:51 +000065typedef struct {
66 ngx_str_t value;
67 ngx_uint_t *flushes;
68 void *lengths;
69 void *values;
70} ngx_http_complex_value_t;
71
72
73typedef struct {
74 ngx_conf_t *cf;
75 ngx_str_t *value;
76 ngx_http_complex_value_t *complex_value;
77
78 unsigned zero:1;
79 unsigned conf_prefix:1;
80 unsigned root_prefix:1;
81} ngx_http_compile_complex_value_t;
82
83
Igor Sysoev899b44e2005-05-12 14:58:06 +000084typedef void (*ngx_http_script_code_pt) (ngx_http_script_engine_t *e);
85typedef size_t (*ngx_http_script_len_code_pt) (ngx_http_script_engine_t *e);
Igor Sysoev02f742b2005-04-08 15:18:55 +000086
87
88typedef struct {
Igor Sysoev8508c102009-03-22 09:36:51 +000089 ngx_http_script_code_pt code;
90 uintptr_t len;
Igor Sysoev02f742b2005-04-08 15:18:55 +000091} ngx_http_script_copy_code_t;
92
93
94typedef struct {
Igor Sysoev8508c102009-03-22 09:36:51 +000095 ngx_http_script_code_pt code;
96 uintptr_t index;
Igor Sysoev02f742b2005-04-08 15:18:55 +000097} ngx_http_script_var_code_t;
98
99
Igor Sysoev899b44e2005-05-12 14:58:06 +0000100typedef struct {
Igor Sysoev8508c102009-03-22 09:36:51 +0000101 ngx_http_script_code_pt code;
102 ngx_http_set_variable_pt handler;
103 uintptr_t data;
Igor Sysoev7bdb7202006-04-19 15:30:56 +0000104} ngx_http_script_var_handler_code_t;
105
106
107typedef struct {
Igor Sysoev8508c102009-03-22 09:36:51 +0000108 ngx_http_script_code_pt code;
109 uintptr_t n;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000110} ngx_http_script_copy_capture_code_t;
Igor Sysoev02f742b2005-04-08 15:18:55 +0000111
112
Igor Sysoev4959ec42005-05-23 12:07:45 +0000113#if (NGX_PCRE)
114
Igor Sysoev899b44e2005-05-12 14:58:06 +0000115typedef struct {
Igor Sysoev8508c102009-03-22 09:36:51 +0000116 ngx_http_script_code_pt code;
117 ngx_regex_t *regex;
118 ngx_array_t *lengths;
119 uintptr_t size;
120 uintptr_t ncaptures;
121 uintptr_t status;
122 uintptr_t next;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000123
Igor Sysoev8508c102009-03-22 09:36:51 +0000124 uintptr_t test:1;
125 uintptr_t negative_test:1;
126 uintptr_t uri:1;
127 uintptr_t args:1;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000128
129 /* add the r->args to the new arguments */
Igor Sysoev8508c102009-03-22 09:36:51 +0000130 uintptr_t add_args:1;
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000131
Igor Sysoev8508c102009-03-22 09:36:51 +0000132 uintptr_t redirect:1;
133 uintptr_t break_cycle:1;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000134
Igor Sysoev8508c102009-03-22 09:36:51 +0000135 ngx_str_t name;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000136} ngx_http_script_regex_code_t;
137
138
139typedef struct {
Igor Sysoev8508c102009-03-22 09:36:51 +0000140 ngx_http_script_code_pt code;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000141
Igor Sysoev8508c102009-03-22 09:36:51 +0000142 uintptr_t uri:1;
143 uintptr_t args:1;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000144
145 /* add the r->args to the new arguments */
Igor Sysoev8508c102009-03-22 09:36:51 +0000146 uintptr_t add_args:1;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000147
Igor Sysoev8508c102009-03-22 09:36:51 +0000148 uintptr_t redirect:1;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000149} ngx_http_script_regex_end_code_t;
150
Igor Sysoev4959ec42005-05-23 12:07:45 +0000151#endif
152
Igor Sysoev899b44e2005-05-12 14:58:06 +0000153
154typedef struct {
Igor Sysoev8508c102009-03-22 09:36:51 +0000155 ngx_http_script_code_pt code;
156 uintptr_t prefix;
157} ngx_http_script_full_name_code_t;
158
159
160typedef struct {
161 ngx_http_script_code_pt code;
162 uintptr_t status;
163 uintptr_t null;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000164} ngx_http_script_return_code_t;
165
166
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000167typedef enum {
168 ngx_http_script_file_plain = 0,
Igor Sysoevb71c6902006-08-04 16:04:04 +0000169 ngx_http_script_file_not_plain,
170 ngx_http_script_file_dir,
171 ngx_http_script_file_not_dir,
172 ngx_http_script_file_exists,
173 ngx_http_script_file_not_exists,
174 ngx_http_script_file_exec,
175 ngx_http_script_file_not_exec
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000176} ngx_http_script_file_op_e;
177
178
179typedef struct {
Igor Sysoev8508c102009-03-22 09:36:51 +0000180 ngx_http_script_code_pt code;
181 uintptr_t op;
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000182} ngx_http_script_file_code_t;
183
184
Igor Sysoev899b44e2005-05-12 14:58:06 +0000185typedef struct {
Igor Sysoev8508c102009-03-22 09:36:51 +0000186 ngx_http_script_code_pt code;
187 uintptr_t next;
188 void **loc_conf;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000189} ngx_http_script_if_code_t;
190
191
192typedef struct {
Igor Sysoev8508c102009-03-22 09:36:51 +0000193 ngx_http_script_code_pt code;
194 ngx_array_t *lengths;
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000195} ngx_http_script_complex_value_code_t;
196
197
198typedef struct {
Igor Sysoev8508c102009-03-22 09:36:51 +0000199 ngx_http_script_code_pt code;
200 uintptr_t value;
201 uintptr_t text_len;
202 uintptr_t text_data;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000203} ngx_http_script_value_code_t;
204
205
Igor Sysoev8508c102009-03-22 09:36:51 +0000206void ngx_http_scrip_flush_complex_value(ngx_http_request_t *r,
207 ngx_http_complex_value_t *val);
208ngx_int_t ngx_http_complex_value(ngx_http_request_t *r,
209 ngx_http_complex_value_t *val, ngx_str_t *value);
210ngx_int_t ngx_http_compile_complex_value(ngx_http_compile_complex_value_t *ccv);
211
Igor Sysoev899b44e2005-05-12 14:58:06 +0000212ngx_uint_t ngx_http_script_variables_count(ngx_str_t *value);
213ngx_int_t ngx_http_script_compile(ngx_http_script_compile_t *sc);
Igor Sysoev8fea8852006-03-15 09:53:04 +0000214u_char *ngx_http_script_run(ngx_http_request_t *r, ngx_str_t *value,
215 void *code_lengths, size_t reserved, void *code_values);
Igor Sysoev2d3f3f62007-10-14 18:56:15 +0000216void ngx_http_script_flush_no_cacheable_variables(ngx_http_request_t *r,
Igor Sysoev09c684b2005-11-09 17:25:55 +0000217 ngx_array_t *indices);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000218
219void *ngx_http_script_start_code(ngx_pool_t *pool, ngx_array_t **codes,
Igor Sysoev02f742b2005-04-08 15:18:55 +0000220 size_t size);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000221void *ngx_http_script_add_code(ngx_array_t *codes, size_t size, void *code);
Igor Sysoev02f742b2005-04-08 15:18:55 +0000222
Igor Sysoev899b44e2005-05-12 14:58:06 +0000223size_t ngx_http_script_copy_len_code(ngx_http_script_engine_t *e);
224void ngx_http_script_copy_code(ngx_http_script_engine_t *e);
225size_t ngx_http_script_copy_var_len_code(ngx_http_script_engine_t *e);
226void ngx_http_script_copy_var_code(ngx_http_script_engine_t *e);
227size_t ngx_http_script_copy_capture_len_code(ngx_http_script_engine_t *e);
228void ngx_http_script_copy_capture_code(ngx_http_script_engine_t *e);
Igor Sysoev04610ea2008-02-12 18:05:32 +0000229size_t ngx_http_script_mark_args_code(ngx_http_script_engine_t *e);
Igor Sysoev4959ec42005-05-23 12:07:45 +0000230void ngx_http_script_start_args_code(ngx_http_script_engine_t *e);
231#if (NGX_PCRE)
Igor Sysoev899b44e2005-05-12 14:58:06 +0000232void ngx_http_script_regex_start_code(ngx_http_script_engine_t *e);
233void ngx_http_script_regex_end_code(ngx_http_script_engine_t *e);
Igor Sysoev4959ec42005-05-23 12:07:45 +0000234#endif
Igor Sysoev899b44e2005-05-12 14:58:06 +0000235void ngx_http_script_return_code(ngx_http_script_engine_t *e);
Igor Sysoev5192b362005-07-08 14:34:20 +0000236void ngx_http_script_break_code(ngx_http_script_engine_t *e);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000237void ngx_http_script_if_code(ngx_http_script_engine_t *e);
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000238void ngx_http_script_equal_code(ngx_http_script_engine_t *e);
239void ngx_http_script_not_equal_code(ngx_http_script_engine_t *e);
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000240void ngx_http_script_file_code(ngx_http_script_engine_t *e);
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000241void ngx_http_script_complex_value_code(ngx_http_script_engine_t *e);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000242void ngx_http_script_value_code(ngx_http_script_engine_t *e);
243void ngx_http_script_set_var_code(ngx_http_script_engine_t *e);
Igor Sysoev7bdb7202006-04-19 15:30:56 +0000244void ngx_http_script_var_set_handler_code(ngx_http_script_engine_t *e);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000245void ngx_http_script_var_code(ngx_http_script_engine_t *e);
246void ngx_http_script_nop_code(ngx_http_script_engine_t *e);
Igor Sysoev7578ec92003-06-02 15:24:30 +0000247
248
249#endif /* _NGX_HTTP_SCRIPT_H_INCLUDED_ */