blob: 46592ab01553402718a1a1dca2cffa879c6098ed [file] [log] [blame]
Igor Sysoevd90282d2004-09-28 08:34:51 +00001
2/*
Igor Sysoevff8da912004-09-29 16:00:49 +00003 * Copyright (C) Igor Sysoev
Maxim Konovalovf8d59e32012-01-18 15:07:43 +00004 * Copyright (C) Nginx, Inc.
Igor Sysoevd90282d2004-09-28 08:34:51 +00005 */
6
7
Igor Sysoev7578ec92003-06-02 15:24:30 +00008#ifndef _NGX_HTTP_SCRIPT_H_INCLUDED_
9#define _NGX_HTTP_SCRIPT_H_INCLUDED_
10
11
Igor Sysoev02025fd2005-01-18 13:03:58 +000012#include <ngx_config.h>
13#include <ngx_core.h>
14#include <ngx_http.h>
15
16
Igor Sysoev02f742b2005-04-08 15:18:55 +000017typedef struct {
Igor Sysoev09c684b2005-11-09 17:25:55 +000018 u_char *ip;
19 u_char *pos;
20 ngx_http_variable_value_t *sp;
Igor Sysoev899b44e2005-05-12 14:58:06 +000021
Igor Sysoev09c684b2005-11-09 17:25:55 +000022 ngx_str_t buf;
23 ngx_str_t line;
Igor Sysoev899b44e2005-05-12 14:58:06 +000024
25 /* the start of the rewritten arguments */
Igor Sysoev09c684b2005-11-09 17:25:55 +000026 u_char *args;
Igor Sysoev899b44e2005-05-12 14:58:06 +000027
Igor Sysoev09c684b2005-11-09 17:25:55 +000028 unsigned flushed:1;
29 unsigned skip:1;
30 unsigned quote:1;
Igor Sysoev04610ea2008-02-12 18:05:32 +000031 unsigned is_args:1;
Igor Sysoev09c684b2005-11-09 17:25:55 +000032 unsigned log:1;
Igor Sysoev899b44e2005-05-12 14:58:06 +000033
Igor Sysoev09c684b2005-11-09 17:25:55 +000034 ngx_int_t status;
35 ngx_http_request_t *request;
Igor Sysoev02f742b2005-04-08 15:18:55 +000036} ngx_http_script_engine_t;
37
38
Igor Sysoev899b44e2005-05-12 14:58:06 +000039typedef struct {
Igor Sysoev09c684b2005-11-09 17:25:55 +000040 ngx_conf_t *cf;
41 ngx_str_t *source;
Igor Sysoev02f742b2005-04-08 15:18:55 +000042
Igor Sysoev09c684b2005-11-09 17:25:55 +000043 ngx_array_t **flushes;
44 ngx_array_t **lengths;
45 ngx_array_t **values;
Igor Sysoev899b44e2005-05-12 14:58:06 +000046
Igor Sysoev09c684b2005-11-09 17:25:55 +000047 ngx_uint_t variables;
48 ngx_uint_t ncaptures;
Igor Sysoev7f7846d2006-04-26 09:52:47 +000049 ngx_uint_t captures_mask;
Igor Sysoev09c684b2005-11-09 17:25:55 +000050 ngx_uint_t size;
Igor Sysoev899b44e2005-05-12 14:58:06 +000051
Igor Sysoev09c684b2005-11-09 17:25:55 +000052 void *main;
Igor Sysoev899b44e2005-05-12 14:58:06 +000053
Igor Sysoev09c684b2005-11-09 17:25:55 +000054 unsigned compile_args:1;
Igor Sysoev09c684b2005-11-09 17:25:55 +000055 unsigned complete_lengths:1;
56 unsigned complete_values:1;
Igor Sysoev8508c102009-03-22 09:36:51 +000057 unsigned zero:1;
58 unsigned conf_prefix:1;
59 unsigned root_prefix:1;
Igor Sysoev09c684b2005-11-09 17:25:55 +000060
Igor Sysoev8508c102009-03-22 09:36:51 +000061 unsigned dup_capture:1;
Igor Sysoev09c684b2005-11-09 17:25:55 +000062 unsigned args:1;
Igor Sysoev899b44e2005-05-12 14:58:06 +000063} ngx_http_script_compile_t;
64
65
Igor Sysoev8508c102009-03-22 09:36:51 +000066typedef struct {
67 ngx_str_t value;
68 ngx_uint_t *flushes;
69 void *lengths;
70 void *values;
71} ngx_http_complex_value_t;
72
73
74typedef struct {
75 ngx_conf_t *cf;
76 ngx_str_t *value;
77 ngx_http_complex_value_t *complex_value;
78
79 unsigned zero:1;
80 unsigned conf_prefix:1;
81 unsigned root_prefix:1;
82} ngx_http_compile_complex_value_t;
83
84
Igor Sysoev899b44e2005-05-12 14:58:06 +000085typedef void (*ngx_http_script_code_pt) (ngx_http_script_engine_t *e);
86typedef size_t (*ngx_http_script_len_code_pt) (ngx_http_script_engine_t *e);
Igor Sysoev02f742b2005-04-08 15:18:55 +000087
88
89typedef struct {
Igor Sysoev8508c102009-03-22 09:36:51 +000090 ngx_http_script_code_pt code;
91 uintptr_t len;
Igor Sysoev02f742b2005-04-08 15:18:55 +000092} ngx_http_script_copy_code_t;
93
94
95typedef struct {
Igor Sysoev8508c102009-03-22 09:36:51 +000096 ngx_http_script_code_pt code;
97 uintptr_t index;
Igor Sysoev02f742b2005-04-08 15:18:55 +000098} ngx_http_script_var_code_t;
99
100
Igor Sysoev899b44e2005-05-12 14:58:06 +0000101typedef struct {
Igor Sysoev8508c102009-03-22 09:36:51 +0000102 ngx_http_script_code_pt code;
103 ngx_http_set_variable_pt handler;
104 uintptr_t data;
Igor Sysoev7bdb7202006-04-19 15:30:56 +0000105} ngx_http_script_var_handler_code_t;
106
107
108typedef struct {
Igor Sysoev8508c102009-03-22 09:36:51 +0000109 ngx_http_script_code_pt code;
110 uintptr_t n;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000111} ngx_http_script_copy_capture_code_t;
Igor Sysoev02f742b2005-04-08 15:18:55 +0000112
113
Igor Sysoev4959ec42005-05-23 12:07:45 +0000114#if (NGX_PCRE)
115
Igor Sysoev899b44e2005-05-12 14:58:06 +0000116typedef struct {
Igor Sysoev8508c102009-03-22 09:36:51 +0000117 ngx_http_script_code_pt code;
Igor Sysoevc05f20e2009-11-16 12:19:02 +0000118 ngx_http_regex_t *regex;
Igor Sysoev8508c102009-03-22 09:36:51 +0000119 ngx_array_t *lengths;
120 uintptr_t size;
Igor Sysoev8508c102009-03-22 09:36:51 +0000121 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;
Igor Sysoev5ef370d2009-04-27 11:32:33 +0000156 uintptr_t conf_prefix;
Igor Sysoev8508c102009-03-22 09:36:51 +0000157} ngx_http_script_full_name_code_t;
158
159
160typedef struct {
161 ngx_http_script_code_pt code;
162 uintptr_t status;
Igor Sysoev4c1b0772010-06-18 15:15:20 +0000163 ngx_http_complex_value_t text;
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 Sysoev766f3a92009-03-27 14:59:47 +0000206void ngx_http_script_flush_complex_value(ngx_http_request_t *r,
Igor Sysoev8508c102009-03-22 09:36:51 +0000207 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);
Igor Sysoev9a626482010-09-13 12:44:43 +0000211char *ngx_http_set_complex_value_slot(ngx_conf_t *cf, ngx_command_t *cmd,
Igor Sysoev94e9aaa2010-09-02 14:37:16 +0000212 void *conf);
213
Igor Sysoev8508c102009-03-22 09:36:51 +0000214
Igor Sysoev7fc29052010-07-14 11:13:59 +0000215ngx_int_t ngx_http_test_predicates(ngx_http_request_t *r,
216 ngx_array_t *predicates);
217char *ngx_http_set_predicate_slot(ngx_conf_t *cf, ngx_command_t *cmd,
218 void *conf);
219
Igor Sysoev899b44e2005-05-12 14:58:06 +0000220ngx_uint_t ngx_http_script_variables_count(ngx_str_t *value);
221ngx_int_t ngx_http_script_compile(ngx_http_script_compile_t *sc);
Igor Sysoev8fea8852006-03-15 09:53:04 +0000222u_char *ngx_http_script_run(ngx_http_request_t *r, ngx_str_t *value,
223 void *code_lengths, size_t reserved, void *code_values);
Igor Sysoev2d3f3f62007-10-14 18:56:15 +0000224void ngx_http_script_flush_no_cacheable_variables(ngx_http_request_t *r,
Igor Sysoev09c684b2005-11-09 17:25:55 +0000225 ngx_array_t *indices);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000226
227void *ngx_http_script_start_code(ngx_pool_t *pool, ngx_array_t **codes,
Igor Sysoev02f742b2005-04-08 15:18:55 +0000228 size_t size);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000229void *ngx_http_script_add_code(ngx_array_t *codes, size_t size, void *code);
Igor Sysoev02f742b2005-04-08 15:18:55 +0000230
Igor Sysoev899b44e2005-05-12 14:58:06 +0000231size_t ngx_http_script_copy_len_code(ngx_http_script_engine_t *e);
232void ngx_http_script_copy_code(ngx_http_script_engine_t *e);
233size_t ngx_http_script_copy_var_len_code(ngx_http_script_engine_t *e);
234void ngx_http_script_copy_var_code(ngx_http_script_engine_t *e);
235size_t ngx_http_script_copy_capture_len_code(ngx_http_script_engine_t *e);
236void ngx_http_script_copy_capture_code(ngx_http_script_engine_t *e);
Igor Sysoev04610ea2008-02-12 18:05:32 +0000237size_t ngx_http_script_mark_args_code(ngx_http_script_engine_t *e);
Igor Sysoev4959ec42005-05-23 12:07:45 +0000238void ngx_http_script_start_args_code(ngx_http_script_engine_t *e);
239#if (NGX_PCRE)
Igor Sysoev899b44e2005-05-12 14:58:06 +0000240void ngx_http_script_regex_start_code(ngx_http_script_engine_t *e);
241void ngx_http_script_regex_end_code(ngx_http_script_engine_t *e);
Igor Sysoev4959ec42005-05-23 12:07:45 +0000242#endif
Igor Sysoev899b44e2005-05-12 14:58:06 +0000243void ngx_http_script_return_code(ngx_http_script_engine_t *e);
Igor Sysoev5192b362005-07-08 14:34:20 +0000244void ngx_http_script_break_code(ngx_http_script_engine_t *e);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000245void ngx_http_script_if_code(ngx_http_script_engine_t *e);
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000246void ngx_http_script_equal_code(ngx_http_script_engine_t *e);
247void ngx_http_script_not_equal_code(ngx_http_script_engine_t *e);
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000248void ngx_http_script_file_code(ngx_http_script_engine_t *e);
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000249void ngx_http_script_complex_value_code(ngx_http_script_engine_t *e);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000250void ngx_http_script_value_code(ngx_http_script_engine_t *e);
251void ngx_http_script_set_var_code(ngx_http_script_engine_t *e);
Igor Sysoev7bdb7202006-04-19 15:30:56 +0000252void ngx_http_script_var_set_handler_code(ngx_http_script_engine_t *e);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000253void ngx_http_script_var_code(ngx_http_script_engine_t *e);
254void ngx_http_script_nop_code(ngx_http_script_engine_t *e);
Igor Sysoev7578ec92003-06-02 15:24:30 +0000255
256
257#endif /* _NGX_HTTP_SCRIPT_H_INCLUDED_ */