Mercurial > hg > nginx-quic
annotate src/http/ngx_http_script.c @ 8523:0c5e84096d99
Core: added the ngx_rbtree_data() macro.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Mon, 21 Jun 2021 09:42:43 +0300 |
parents | 3ab8e1e2f0f7 |
children | d26db4f82d7d |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
99
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
99
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
99
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
99
diff
changeset
|
6 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 #include <ngx_http.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
13 static ngx_int_t ngx_http_script_init_arrays(ngx_http_script_compile_t *sc); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
14 static ngx_int_t ngx_http_script_done(ngx_http_script_compile_t *sc); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
15 static ngx_int_t ngx_http_script_add_copy_code(ngx_http_script_compile_t *sc, |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
16 ngx_str_t *value, ngx_uint_t last); |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
17 static ngx_int_t ngx_http_script_add_var_code(ngx_http_script_compile_t *sc, |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
18 ngx_str_t *name); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
19 static ngx_int_t ngx_http_script_add_args_code(ngx_http_script_compile_t *sc); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
20 #if (NGX_PCRE) |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
21 static ngx_int_t ngx_http_script_add_capture_code(ngx_http_script_compile_t *sc, |
6474 | 22 ngx_uint_t n); |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
23 #endif |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
24 static ngx_int_t |
6474 | 25 ngx_http_script_add_full_name_code(ngx_http_script_compile_t *sc); |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
26 static size_t ngx_http_script_full_name_len_code(ngx_http_script_engine_t *e); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
27 static void ngx_http_script_full_name_code(ngx_http_script_engine_t *e); |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
28 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
29 |
509 | 30 #define ngx_http_script_exit (u_char *) &ngx_http_script_exit_code |
31 | |
32 static uintptr_t ngx_http_script_exit_code = (uintptr_t) NULL; | |
33 | |
34 | |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
35 void |
2609
ad99a49cd313
rename ngx_http_scrip_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2608
diff
changeset
|
36 ngx_http_script_flush_complex_value(ngx_http_request_t *r, |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
37 ngx_http_complex_value_t *val) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
38 { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
39 ngx_uint_t *index; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
40 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
41 index = val->flushes; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
42 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
43 if (index) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
44 while (*index != (ngx_uint_t) -1) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
45 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
46 if (r->variables[*index].no_cacheable) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
47 r->variables[*index].valid = 0; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
48 r->variables[*index].not_found = 0; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
49 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
50 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
51 index++; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
52 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
53 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
54 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
55 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
56 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
57 ngx_int_t |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
58 ngx_http_complex_value(ngx_http_request_t *r, ngx_http_complex_value_t *val, |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
59 ngx_str_t *value) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
60 { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
61 size_t len; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
62 ngx_http_script_code_pt code; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
63 ngx_http_script_len_code_pt lcode; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
64 ngx_http_script_engine_t e; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
65 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
66 if (val->lengths == NULL) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
67 *value = val->value; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
68 return NGX_OK; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
69 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
70 |
2609
ad99a49cd313
rename ngx_http_scrip_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2608
diff
changeset
|
71 ngx_http_script_flush_complex_value(r, val); |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
72 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
73 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
74 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
75 e.ip = val->lengths; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
76 e.request = r; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
77 e.flushed = 1; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
78 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
79 len = 0; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
80 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
81 while (*(uintptr_t *) e.ip) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
82 lcode = *(ngx_http_script_len_code_pt *) e.ip; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
83 len += lcode(&e); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
84 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
85 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
86 value->len = len; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
87 value->data = ngx_pnalloc(r->pool, len); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
88 if (value->data == NULL) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
89 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
90 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
91 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
92 e.ip = val->values; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
93 e.pos = value->data; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
94 e.buf = *value; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
95 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
96 while (*(uintptr_t *) e.ip) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
97 code = *(ngx_http_script_code_pt *) e.ip; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
98 code((ngx_http_script_engine_t *) &e); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
99 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
100 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
101 *value = e.buf; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
102 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
103 return NGX_OK; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
104 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
105 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
106 |
7503
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
107 size_t |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
108 ngx_http_complex_value_size(ngx_http_request_t *r, |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
109 ngx_http_complex_value_t *val, size_t default_value) |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
110 { |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
111 size_t size; |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
112 ngx_str_t value; |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
113 |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
114 if (val == NULL) { |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
115 return default_value; |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
116 } |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
117 |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
118 if (val->lengths == NULL) { |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
119 return val->u.size; |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
120 } |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
121 |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
122 if (ngx_http_complex_value(r, val, &value) != NGX_OK) { |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
123 return default_value; |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
124 } |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
125 |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
126 size = ngx_parse_size(&value); |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
127 |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
128 if (size == (size_t) NGX_ERROR) { |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
129 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
130 "invalid size \"%V\"", &value); |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
131 return default_value; |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
132 } |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
133 |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
134 return size; |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
135 } |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
136 |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
137 |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
138 ngx_int_t |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
139 ngx_http_compile_complex_value(ngx_http_compile_complex_value_t *ccv) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
140 { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
141 ngx_str_t *v; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
142 ngx_uint_t i, n, nv, nc; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
143 ngx_array_t flushes, lengths, values, *pf, *pl, *pv; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
144 ngx_http_script_compile_t sc; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
145 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
146 v = ccv->value; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
147 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
148 nv = 0; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
149 nc = 0; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
150 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
151 for (i = 0; i < v->len; i++) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
152 if (v->data[i] == '$') { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
153 if (v->data[i + 1] >= '1' && v->data[i + 1] <= '9') { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
154 nc++; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
155 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
156 } else { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
157 nv++; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
158 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
159 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
160 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
161 |
4947
4251e72b8bb4
Allow the complex value to be defined as an empty string.
Ruslan Ermilov <ru@nginx.com>
parents:
4617
diff
changeset
|
162 if ((v->len == 0 || v->data[0] != '$') |
4251e72b8bb4
Allow the complex value to be defined as an empty string.
Ruslan Ermilov <ru@nginx.com>
parents:
4617
diff
changeset
|
163 && (ccv->conf_prefix || ccv->root_prefix)) |
4251e72b8bb4
Allow the complex value to be defined as an empty string.
Ruslan Ermilov <ru@nginx.com>
parents:
4617
diff
changeset
|
164 { |
5330
314c3d7cc3a5
Backed out f1a91825730a and 7094bd12c1ff.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5317
diff
changeset
|
165 if (ngx_conf_full_name(ccv->cf->cycle, v, ccv->conf_prefix) != NGX_OK) { |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
166 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
167 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
168 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
169 ccv->conf_prefix = 0; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
170 ccv->root_prefix = 0; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
171 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
172 |
2608
2f4a3a4dfd34
fix plain text values using relative path in ngx_http_complex_value(),
Igor Sysoev <igor@sysoev.ru>
parents:
2587
diff
changeset
|
173 ccv->complex_value->value = *v; |
2f4a3a4dfd34
fix plain text values using relative path in ngx_http_complex_value(),
Igor Sysoev <igor@sysoev.ru>
parents:
2587
diff
changeset
|
174 ccv->complex_value->flushes = NULL; |
2f4a3a4dfd34
fix plain text values using relative path in ngx_http_complex_value(),
Igor Sysoev <igor@sysoev.ru>
parents:
2587
diff
changeset
|
175 ccv->complex_value->lengths = NULL; |
2f4a3a4dfd34
fix plain text values using relative path in ngx_http_complex_value(),
Igor Sysoev <igor@sysoev.ru>
parents:
2587
diff
changeset
|
176 ccv->complex_value->values = NULL; |
2f4a3a4dfd34
fix plain text values using relative path in ngx_http_complex_value(),
Igor Sysoev <igor@sysoev.ru>
parents:
2587
diff
changeset
|
177 |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
178 if (nv == 0 && nc == 0) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
179 return NGX_OK; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
180 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
181 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
182 n = nv + 1; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
183 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
184 if (ngx_array_init(&flushes, ccv->cf->pool, n, sizeof(ngx_uint_t)) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
185 != NGX_OK) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
186 { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
187 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
188 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
189 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
190 n = nv * (2 * sizeof(ngx_http_script_copy_code_t) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
191 + sizeof(ngx_http_script_var_code_t)) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
192 + sizeof(uintptr_t); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
193 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
194 if (ngx_array_init(&lengths, ccv->cf->pool, n, 1) != NGX_OK) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
195 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
196 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
197 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
198 n = (nv * (2 * sizeof(ngx_http_script_copy_code_t) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
199 + sizeof(ngx_http_script_var_code_t)) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
200 + sizeof(uintptr_t) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
201 + v->len |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
202 + sizeof(uintptr_t) - 1) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
203 & ~(sizeof(uintptr_t) - 1); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
204 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
205 if (ngx_array_init(&values, ccv->cf->pool, n, 1) != NGX_OK) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
206 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
207 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
208 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
209 pf = &flushes; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
210 pl = &lengths; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
211 pv = &values; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
212 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
213 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
214 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
215 sc.cf = ccv->cf; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
216 sc.source = v; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
217 sc.flushes = &pf; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
218 sc.lengths = &pl; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
219 sc.values = &pv; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
220 sc.complete_lengths = 1; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
221 sc.complete_values = 1; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
222 sc.zero = ccv->zero; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
223 sc.conf_prefix = ccv->conf_prefix; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
224 sc.root_prefix = ccv->root_prefix; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
225 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
226 if (ngx_http_script_compile(&sc) != NGX_OK) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
227 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
228 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
229 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
230 if (flushes.nelts) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
231 ccv->complex_value->flushes = flushes.elts; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
232 ccv->complex_value->flushes[flushes.nelts] = (ngx_uint_t) -1; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
233 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
234 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
235 ccv->complex_value->lengths = lengths.elts; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
236 ccv->complex_value->values = values.elts; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
237 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
238 return NGX_OK; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
239 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
240 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
241 |
3756
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
242 char * |
3761 | 243 ngx_http_set_complex_value_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
3756
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
244 { |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
245 char *p = conf; |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
246 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
247 ngx_str_t *value; |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
248 ngx_http_complex_value_t **cv; |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
249 ngx_http_compile_complex_value_t ccv; |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
250 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
251 cv = (ngx_http_complex_value_t **) (p + cmd->offset); |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
252 |
8452
bdd4d89370a7
Changed complex value slots to use NGX_CONF_UNSET_PTR.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7604
diff
changeset
|
253 if (*cv != NGX_CONF_UNSET_PTR && *cv != NULL) { |
6940
39ff6939266e
Unified error messages about duplicate directives.
Ruslan Ermilov <ru@nginx.com>
parents:
6861
diff
changeset
|
254 return "is duplicate"; |
3756
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
255 } |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
256 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
257 *cv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t)); |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
258 if (*cv == NULL) { |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
259 return NGX_CONF_ERROR; |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
260 } |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
261 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
262 value = cf->args->elts; |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
263 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
264 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
265 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
266 ccv.cf = cf; |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
267 ccv.value = &value[1]; |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
268 ccv.complex_value = *cv; |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
269 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
270 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
271 return NGX_CONF_ERROR; |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
272 } |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
273 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
274 return NGX_CONF_OK; |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
275 } |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
276 |
7224d008faaf
new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents:
3691
diff
changeset
|
277 |
7503
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
278 char * |
8454
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
279 ngx_http_set_complex_value_zero_slot(ngx_conf_t *cf, ngx_command_t *cmd, |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
280 void *conf) |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
281 { |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
282 char *p = conf; |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
283 |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
284 ngx_str_t *value; |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
285 ngx_http_complex_value_t **cv; |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
286 ngx_http_compile_complex_value_t ccv; |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
287 |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
288 cv = (ngx_http_complex_value_t **) (p + cmd->offset); |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
289 |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
290 if (*cv != NGX_CONF_UNSET_PTR) { |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
291 return "is duplicate"; |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
292 } |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
293 |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
294 *cv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t)); |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
295 if (*cv == NULL) { |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
296 return NGX_CONF_ERROR; |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
297 } |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
298 |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
299 value = cf->args->elts; |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
300 |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
301 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
302 |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
303 ccv.cf = cf; |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
304 ccv.value = &value[1]; |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
305 ccv.complex_value = *cv; |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
306 ccv.zero = 1; |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
307 |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
308 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
309 return NGX_CONF_ERROR; |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
310 } |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
311 |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
312 return NGX_CONF_OK; |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
313 } |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
314 |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
315 |
3ab8e1e2f0f7
Upstream: variables support in certificates.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8452
diff
changeset
|
316 char * |
7503
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
317 ngx_http_set_complex_value_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
318 void *conf) |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
319 { |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
320 char *p = conf; |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
321 |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
322 char *rv; |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
323 ngx_http_complex_value_t *cv; |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
324 |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
325 rv = ngx_http_set_complex_value_slot(cf, cmd, conf); |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
326 |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
327 if (rv != NGX_CONF_OK) { |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
328 return rv; |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
329 } |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
330 |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
331 cv = *(ngx_http_complex_value_t **) (p + cmd->offset); |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
332 |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
333 if (cv->lengths) { |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
334 return NGX_CONF_OK; |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
335 } |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
336 |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
337 cv->u.size = ngx_parse_size(&cv->value); |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
338 if (cv->u.size == (size_t) NGX_ERROR) { |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
339 return "invalid value"; |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
340 } |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
341 |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
342 return NGX_CONF_OK; |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
343 } |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
344 |
b82162b8496a
Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents:
7439
diff
changeset
|
345 |
3691
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
346 ngx_int_t |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
347 ngx_http_test_predicates(ngx_http_request_t *r, ngx_array_t *predicates) |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
348 { |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
349 ngx_str_t val; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
350 ngx_uint_t i; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
351 ngx_http_complex_value_t *cv; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
352 |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
353 if (predicates == NULL) { |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
354 return NGX_OK; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
355 } |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
356 |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
357 cv = predicates->elts; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
358 |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
359 for (i = 0; i < predicates->nelts; i++) { |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
360 if (ngx_http_complex_value(r, &cv[i], &val) != NGX_OK) { |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
361 return NGX_ERROR; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
362 } |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
363 |
3893
5581586480e9
values starting with '0' were incorrectly assumed to be false
Igor Sysoev <igor@sysoev.ru>
parents:
3887
diff
changeset
|
364 if (val.len && (val.len != 1 || val.data[0] != '0')) { |
3691
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
365 return NGX_DECLINED; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
366 } |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
367 } |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
368 |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
369 return NGX_OK; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
370 } |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
371 |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
372 |
7439
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
373 ngx_int_t |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
374 ngx_http_test_required_predicates(ngx_http_request_t *r, |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
375 ngx_array_t *predicates) |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
376 { |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
377 ngx_str_t val; |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
378 ngx_uint_t i; |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
379 ngx_http_complex_value_t *cv; |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
380 |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
381 if (predicates == NULL) { |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
382 return NGX_OK; |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
383 } |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
384 |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
385 cv = predicates->elts; |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
386 |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
387 for (i = 0; i < predicates->nelts; i++) { |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
388 if (ngx_http_complex_value(r, &cv[i], &val) != NGX_OK) { |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
389 return NGX_ERROR; |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
390 } |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
391 |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
392 if (val.len == 0 || (val.len == 1 && val.data[0] == '0')) { |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
393 return NGX_DECLINED; |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
394 } |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
395 } |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
396 |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
397 return NGX_OK; |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
398 } |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
399 |
5efc23d83bc2
Added the ngx_http_test_required_predicates() function.
Vladimir Homutov <vl@nginx.com>
parents:
7271
diff
changeset
|
400 |
3691
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
401 char * |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
402 ngx_http_set_predicate_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
403 { |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
404 char *p = conf; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
405 |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
406 ngx_str_t *value; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
407 ngx_uint_t i; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
408 ngx_array_t **a; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
409 ngx_http_complex_value_t *cv; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
410 ngx_http_compile_complex_value_t ccv; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
411 |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
412 a = (ngx_array_t **) (p + cmd->offset); |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
413 |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
414 if (*a == NGX_CONF_UNSET_PTR) { |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
415 *a = ngx_array_create(cf->pool, 1, sizeof(ngx_http_complex_value_t)); |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
416 if (*a == NULL) { |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
417 return NGX_CONF_ERROR; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
418 } |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
419 } |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
420 |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
421 value = cf->args->elts; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
422 |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
423 for (i = 1; i < cf->args->nelts; i++) { |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
424 cv = ngx_array_push(*a); |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
425 if (cv == NULL) { |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
426 return NGX_CONF_ERROR; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
427 } |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
428 |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
429 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
430 |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
431 ccv.cf = cf; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
432 ccv.value = &value[i]; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
433 ccv.complex_value = cv; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
434 |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
435 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
436 return NGX_CONF_ERROR; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
437 } |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
438 } |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
439 |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
440 return NGX_CONF_OK; |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
441 } |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
442 |
55f95e91daed
ngx_http_test_predicates(), ngx_http_set_predicate_slot()
Igor Sysoev <igor@sysoev.ru>
parents:
3633
diff
changeset
|
443 |
509 | 444 ngx_uint_t |
445 ngx_http_script_variables_count(ngx_str_t *value) | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
446 { |
509 | 447 ngx_uint_t i, n; |
507 | 448 |
509 | 449 for (n = 0, i = 0; i < value->len; i++) { |
450 if (value->data[i] == '$') { | |
451 n++; | |
452 } | |
507 | 453 } |
454 | |
509 | 455 return n; |
456 } | |
457 | |
458 | |
459 ngx_int_t | |
460 ngx_http_script_compile(ngx_http_script_compile_t *sc) | |
461 { | |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
462 u_char ch; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
463 ngx_str_t name; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
464 ngx_uint_t i, bracket; |
573 | 465 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
466 if (ngx_http_script_init_arrays(sc) != NGX_OK) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
467 return NGX_ERROR; |
509 | 468 } |
469 | |
470 for (i = 0; i < sc->source->len; /* void */ ) { | |
471 | |
472 name.len = 0; | |
473 | |
474 if (sc->source->data[i] == '$') { | |
475 | |
476 if (++i == sc->source->len) { | |
477 goto invalid_variable; | |
478 } | |
479 | |
6644
af642539cd53
Fixed regex captures handling without PCRE.
Vladimir Homutov <vl@nginx.com>
parents:
6480
diff
changeset
|
480 if (sc->source->data[i] >= '1' && sc->source->data[i] <= '9') { |
2547
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
481 #if (NGX_PCRE) |
6644
af642539cd53
Fixed regex captures handling without PCRE.
Vladimir Homutov <vl@nginx.com>
parents:
6480
diff
changeset
|
482 ngx_uint_t n; |
509 | 483 |
641 | 484 n = sc->source->data[i] - '0'; |
485 | |
6861
e4590dfd97ff
Win32: support 64-bit compilation with MSVC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6644
diff
changeset
|
486 if (sc->captures_mask & ((ngx_uint_t) 1 << n)) { |
641 | 487 sc->dup_capture = 1; |
488 } | |
489 | |
6861
e4590dfd97ff
Win32: support 64-bit compilation with MSVC.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6644
diff
changeset
|
490 sc->captures_mask |= (ngx_uint_t) 1 << n; |
641 | 491 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
492 if (ngx_http_script_add_capture_code(sc, n) != NGX_OK) { |
509 | 493 return NGX_ERROR; |
494 } | |
495 | |
496 i++; | |
497 | |
498 continue; | |
6644
af642539cd53
Fixed regex captures handling without PCRE.
Vladimir Homutov <vl@nginx.com>
parents:
6480
diff
changeset
|
499 #else |
af642539cd53
Fixed regex captures handling without PCRE.
Vladimir Homutov <vl@nginx.com>
parents:
6480
diff
changeset
|
500 ngx_conf_log_error(NGX_LOG_EMERG, sc->cf, 0, |
af642539cd53
Fixed regex captures handling without PCRE.
Vladimir Homutov <vl@nginx.com>
parents:
6480
diff
changeset
|
501 "using variable \"$%c\" requires " |
af642539cd53
Fixed regex captures handling without PCRE.
Vladimir Homutov <vl@nginx.com>
parents:
6480
diff
changeset
|
502 "PCRE library", sc->source->data[i]); |
af642539cd53
Fixed regex captures handling without PCRE.
Vladimir Homutov <vl@nginx.com>
parents:
6480
diff
changeset
|
503 return NGX_ERROR; |
af642539cd53
Fixed regex captures handling without PCRE.
Vladimir Homutov <vl@nginx.com>
parents:
6480
diff
changeset
|
504 #endif |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
505 } |
2547
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
506 |
509 | 507 if (sc->source->data[i] == '{') { |
508 bracket = 1; | |
509 | |
510 if (++i == sc->source->len) { | |
511 goto invalid_variable; | |
512 } | |
513 | |
514 name.data = &sc->source->data[i]; | |
515 | |
516 } else { | |
517 bracket = 0; | |
518 name.data = &sc->source->data[i]; | |
519 } | |
520 | |
521 for ( /* void */ ; i < sc->source->len; i++, name.len++) { | |
522 ch = sc->source->data[i]; | |
507 | 523 |
509 | 524 if (ch == '}' && bracket) { |
525 i++; | |
526 bracket = 0; | |
527 break; | |
528 } | |
529 | |
530 if ((ch >= 'A' && ch <= 'Z') | |
531 || (ch >= 'a' && ch <= 'z') | |
532 || (ch >= '0' && ch <= '9') | |
533 || ch == '_') | |
534 { | |
535 continue; | |
536 } | |
537 | |
538 break; | |
539 } | |
540 | |
541 if (bracket) { | |
542 ngx_conf_log_error(NGX_LOG_EMERG, sc->cf, 0, | |
543 "the closing bracket in \"%V\" " | |
544 "variable is missing", &name); | |
507 | 545 return NGX_ERROR; |
546 } | |
547 | |
509 | 548 if (name.len == 0) { |
549 goto invalid_variable; | |
550 } | |
507 | 551 |
509 | 552 sc->variables++; |
507 | 553 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
554 if (ngx_http_script_add_var_code(sc, &name) != NGX_OK) { |
507 | 555 return NGX_ERROR; |
556 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
557 |
509 | 558 continue; |
559 } | |
507 | 560 |
509 | 561 if (sc->source->data[i] == '?' && sc->compile_args) { |
562 sc->args = 1; | |
563 sc->compile_args = 0; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
564 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
565 if (ngx_http_script_add_args_code(sc) != NGX_OK) { |
1891
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
566 return NGX_ERROR; |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
567 } |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
568 |
509 | 569 i++; |
570 | |
507 | 571 continue; |
572 } | |
573 | |
509 | 574 name.data = &sc->source->data[i]; |
575 | |
2498
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
576 while (i < sc->source->len) { |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
577 |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
578 if (sc->source->data[i] == '$') { |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
579 break; |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
580 } |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
581 |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
582 if (sc->source->data[i] == '?') { |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
583 |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
584 sc->args = 1; |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
585 |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
586 if (sc->compile_args) { |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
587 break; |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
588 } |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
589 } |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
590 |
509 | 591 i++; |
592 name.len++; | |
593 } | |
594 | |
595 sc->size += name.len; | |
596 | |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
597 if (ngx_http_script_add_copy_code(sc, &name, (i == sc->source->len)) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
598 != NGX_OK) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
599 { |
509 | 600 return NGX_ERROR; |
601 } | |
507 | 602 } |
603 | |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
604 return ngx_http_script_done(sc); |
509 | 605 |
606 invalid_variable: | |
607 | |
608 ngx_conf_log_error(NGX_LOG_EMERG, sc->cf, 0, "invalid variable name"); | |
609 | |
610 return NGX_ERROR; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
611 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
612 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
613 |
623 | 614 u_char * |
615 ngx_http_script_run(ngx_http_request_t *r, ngx_str_t *value, | |
616 void *code_lengths, size_t len, void *code_values) | |
617 { | |
1152
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
618 ngx_uint_t i; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
619 ngx_http_script_code_pt code; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
620 ngx_http_script_len_code_pt lcode; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
621 ngx_http_script_engine_t e; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
622 ngx_http_core_main_conf_t *cmcf; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
623 |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
624 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
625 |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
626 for (i = 0; i < cmcf->variables.nelts; i++) { |
1565 | 627 if (r->variables[i].no_cacheable) { |
1152
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
628 r->variables[i].valid = 0; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
629 r->variables[i].not_found = 0; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
630 } |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
631 } |
623 | 632 |
633 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); | |
634 | |
635 e.ip = code_lengths; | |
636 e.request = r; | |
637 e.flushed = 1; | |
638 | |
639 while (*(uintptr_t *) e.ip) { | |
640 lcode = *(ngx_http_script_len_code_pt *) e.ip; | |
641 len += lcode(&e); | |
642 } | |
643 | |
644 | |
645 value->len = len; | |
2049 | 646 value->data = ngx_pnalloc(r->pool, len); |
623 | 647 if (value->data == NULL) { |
648 return NULL; | |
649 } | |
650 | |
651 e.ip = code_values; | |
652 e.pos = value->data; | |
653 | |
654 while (*(uintptr_t *) e.ip) { | |
655 code = *(ngx_http_script_code_pt *) e.ip; | |
656 code((ngx_http_script_engine_t *) &e); | |
657 } | |
658 | |
659 return e.pos; | |
660 } | |
661 | |
662 | |
573 | 663 void |
1565 | 664 ngx_http_script_flush_no_cacheable_variables(ngx_http_request_t *r, |
573 | 665 ngx_array_t *indices) |
666 { | |
667 ngx_uint_t n, *index; | |
668 | |
669 if (indices) { | |
670 index = indices->elts; | |
671 for (n = 0; n < indices->nelts; n++) { | |
1565 | 672 if (r->variables[index[n]].no_cacheable) { |
573 | 673 r->variables[index[n]].valid = 0; |
674 r->variables[index[n]].not_found = 0; | |
675 } | |
676 } | |
677 } | |
678 } | |
679 | |
680 | |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
681 static ngx_int_t |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
682 ngx_http_script_init_arrays(ngx_http_script_compile_t *sc) |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
683 { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
684 ngx_uint_t n; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
685 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
686 if (sc->flushes && *sc->flushes == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
687 n = sc->variables ? sc->variables : 1; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
688 *sc->flushes = ngx_array_create(sc->cf->pool, n, sizeof(ngx_uint_t)); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
689 if (*sc->flushes == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
690 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
691 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
692 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
693 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
694 if (*sc->lengths == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
695 n = sc->variables * (2 * sizeof(ngx_http_script_copy_code_t) |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
696 + sizeof(ngx_http_script_var_code_t)) |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
697 + sizeof(uintptr_t); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
698 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
699 *sc->lengths = ngx_array_create(sc->cf->pool, n, 1); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
700 if (*sc->lengths == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
701 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
702 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
703 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
704 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
705 if (*sc->values == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
706 n = (sc->variables * (2 * sizeof(ngx_http_script_copy_code_t) |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
707 + sizeof(ngx_http_script_var_code_t)) |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
708 + sizeof(uintptr_t) |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
709 + sc->source->len |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
710 + sizeof(uintptr_t) - 1) |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
711 & ~(sizeof(uintptr_t) - 1); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
712 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
713 *sc->values = ngx_array_create(sc->cf->pool, n, 1); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
714 if (*sc->values == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
715 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
716 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
717 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
718 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
719 sc->variables = 0; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
720 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
721 return NGX_OK; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
722 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
723 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
724 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
725 static ngx_int_t |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
726 ngx_http_script_done(ngx_http_script_compile_t *sc) |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
727 { |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
728 ngx_str_t zero; |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
729 uintptr_t *code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
730 |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
731 if (sc->zero) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
732 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
733 zero.len = 1; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
734 zero.data = (u_char *) "\0"; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
735 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
736 if (ngx_http_script_add_copy_code(sc, &zero, 0) != NGX_OK) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
737 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
738 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
739 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
740 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
741 if (sc->conf_prefix || sc->root_prefix) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
742 if (ngx_http_script_add_full_name_code(sc) != NGX_OK) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
743 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
744 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
745 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
746 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
747 if (sc->complete_lengths) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
748 code = ngx_http_script_add_code(*sc->lengths, sizeof(uintptr_t), NULL); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
749 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
750 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
751 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
752 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
753 *code = (uintptr_t) NULL; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
754 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
755 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
756 if (sc->complete_values) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
757 code = ngx_http_script_add_code(*sc->values, sizeof(uintptr_t), |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
758 &sc->main); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
759 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
760 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
761 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
762 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
763 *code = (uintptr_t) NULL; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
764 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
765 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
766 return NGX_OK; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
767 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
768 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
769 |
509 | 770 void * |
507 | 771 ngx_http_script_start_code(ngx_pool_t *pool, ngx_array_t **codes, size_t size) |
479 | 772 { |
507 | 773 if (*codes == NULL) { |
774 *codes = ngx_array_create(pool, 256, 1); | |
775 if (*codes == NULL) { | |
776 return NULL; | |
777 } | |
778 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
779 |
507 | 780 return ngx_array_push_n(*codes, size); |
781 } | |
782 | |
509 | 783 |
784 void * | |
785 ngx_http_script_add_code(ngx_array_t *codes, size_t size, void *code) | |
786 { | |
787 u_char *elts, **p; | |
788 void *new; | |
789 | |
790 elts = codes->elts; | |
791 | |
792 new = ngx_array_push_n(codes, size); | |
793 if (new == NULL) { | |
2911 | 794 return NULL; |
509 | 795 } |
796 | |
797 if (code) { | |
798 if (elts != codes->elts) { | |
799 p = code; | |
800 *p += (u_char *) codes->elts - elts; | |
801 } | |
802 } | |
803 | |
804 return new; | |
805 } | |
507 | 806 |
479 | 807 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
808 static ngx_int_t |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
809 ngx_http_script_add_copy_code(ngx_http_script_compile_t *sc, ngx_str_t *value, |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
810 ngx_uint_t last) |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
811 { |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
812 u_char *p; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
813 size_t size, len, zero; |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
814 ngx_http_script_copy_code_t *code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
815 |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
816 zero = (sc->zero && last); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
817 len = value->len + zero; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
818 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
819 code = ngx_http_script_add_code(*sc->lengths, |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
820 sizeof(ngx_http_script_copy_code_t), NULL); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
821 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
822 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
823 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
824 |
7271
9e25a5380a21
Silenced -Wcast-function-type warnings (closes #1546).
Sergey Kandaurov <pluknet@nginx.com>
parents:
6948
diff
changeset
|
825 code->code = (ngx_http_script_code_pt) (void *) |
9e25a5380a21
Silenced -Wcast-function-type warnings (closes #1546).
Sergey Kandaurov <pluknet@nginx.com>
parents:
6948
diff
changeset
|
826 ngx_http_script_copy_len_code; |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
827 code->len = len; |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
828 |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
829 size = (sizeof(ngx_http_script_copy_code_t) + len + sizeof(uintptr_t) - 1) |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
830 & ~(sizeof(uintptr_t) - 1); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
831 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
832 code = ngx_http_script_add_code(*sc->values, size, &sc->main); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
833 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
834 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
835 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
836 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
837 code->code = ngx_http_script_copy_code; |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
838 code->len = len; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
839 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
840 p = ngx_cpymem((u_char *) code + sizeof(ngx_http_script_copy_code_t), |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
841 value->data, value->len); |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
842 |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
843 if (zero) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
844 *p = '\0'; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
845 sc->zero = 0; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
846 } |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
847 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
848 return NGX_OK; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
849 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
850 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
851 |
507 | 852 size_t |
509 | 853 ngx_http_script_copy_len_code(ngx_http_script_engine_t *e) |
507 | 854 { |
855 ngx_http_script_copy_code_t *code; | |
479 | 856 |
509 | 857 code = (ngx_http_script_copy_code_t *) e->ip; |
507 | 858 |
509 | 859 e->ip += sizeof(ngx_http_script_copy_code_t); |
507 | 860 |
861 return code->len; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
862 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
863 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
864 |
507 | 865 void |
509 | 866 ngx_http_script_copy_code(ngx_http_script_engine_t *e) |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
867 { |
2393 | 868 u_char *p; |
507 | 869 ngx_http_script_copy_code_t *code; |
870 | |
509 | 871 code = (ngx_http_script_copy_code_t *) e->ip; |
872 | |
2393 | 873 p = e->pos; |
874 | |
509 | 875 if (!e->skip) { |
2393 | 876 e->pos = ngx_copy(p, e->ip + sizeof(ngx_http_script_copy_code_t), |
573 | 877 code->len); |
509 | 878 } |
507 | 879 |
509 | 880 e->ip += sizeof(ngx_http_script_copy_code_t) |
881 + ((code->len + sizeof(uintptr_t) - 1) & ~(sizeof(uintptr_t) - 1)); | |
507 | 882 |
2393 | 883 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, |
884 "http script copy: \"%*s\"", e->pos - p, p); | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
885 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
886 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
887 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
888 static ngx_int_t |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
889 ngx_http_script_add_var_code(ngx_http_script_compile_t *sc, ngx_str_t *name) |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
890 { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
891 ngx_int_t index, *p; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
892 ngx_http_script_var_code_t *code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
893 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
894 index = ngx_http_get_variable_index(sc->cf, name); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
895 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
896 if (index == NGX_ERROR) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
897 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
898 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
899 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
900 if (sc->flushes) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
901 p = ngx_array_push(*sc->flushes); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
902 if (p == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
903 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
904 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
905 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
906 *p = index; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
907 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
908 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
909 code = ngx_http_script_add_code(*sc->lengths, |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
910 sizeof(ngx_http_script_var_code_t), NULL); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
911 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
912 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
913 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
914 |
7271
9e25a5380a21
Silenced -Wcast-function-type warnings (closes #1546).
Sergey Kandaurov <pluknet@nginx.com>
parents:
6948
diff
changeset
|
915 code->code = (ngx_http_script_code_pt) (void *) |
9e25a5380a21
Silenced -Wcast-function-type warnings (closes #1546).
Sergey Kandaurov <pluknet@nginx.com>
parents:
6948
diff
changeset
|
916 ngx_http_script_copy_var_len_code; |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
917 code->index = (uintptr_t) index; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
918 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
919 code = ngx_http_script_add_code(*sc->values, |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
920 sizeof(ngx_http_script_var_code_t), |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
921 &sc->main); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
922 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
923 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
924 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
925 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
926 code->code = ngx_http_script_copy_var_code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
927 code->index = (uintptr_t) index; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
928 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
929 return NGX_OK; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
930 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
931 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
932 |
507 | 933 size_t |
509 | 934 ngx_http_script_copy_var_len_code(ngx_http_script_engine_t *e) |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
935 { |
507 | 936 ngx_http_variable_value_t *value; |
937 ngx_http_script_var_code_t *code; | |
938 | |
509 | 939 code = (ngx_http_script_var_code_t *) e->ip; |
507 | 940 |
509 | 941 e->ip += sizeof(ngx_http_script_var_code_t); |
507 | 942 |
573 | 943 if (e->flushed) { |
944 value = ngx_http_get_indexed_variable(e->request, code->index); | |
507 | 945 |
573 | 946 } else { |
947 value = ngx_http_get_flushed_variable(e->request, code->index); | |
948 } | |
949 | |
950 if (value && !value->not_found) { | |
951 return value->len; | |
507 | 952 } |
953 | |
553 | 954 return 0; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
955 } |
479 | 956 |
957 | |
507 | 958 void |
509 | 959 ngx_http_script_copy_var_code(ngx_http_script_engine_t *e) |
479 | 960 { |
2393 | 961 u_char *p; |
507 | 962 ngx_http_variable_value_t *value; |
963 ngx_http_script_var_code_t *code; | |
964 | |
509 | 965 code = (ngx_http_script_var_code_t *) e->ip; |
966 | |
967 e->ip += sizeof(ngx_http_script_var_code_t); | |
968 | |
969 if (!e->skip) { | |
573 | 970 |
971 if (e->flushed) { | |
972 value = ngx_http_get_indexed_variable(e->request, code->index); | |
509 | 973 |
573 | 974 } else { |
975 value = ngx_http_get_flushed_variable(e->request, code->index); | |
976 } | |
977 | |
978 if (value && !value->not_found) { | |
2393 | 979 p = e->pos; |
980 e->pos = ngx_copy(p, value->data, value->len); | |
509 | 981 |
2393 | 982 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, |
845
eb5cf273e5d2
debug log should not be under rewrite_log control
Igor Sysoev <igor@sysoev.ru>
parents:
730
diff
changeset
|
983 e->request->connection->log, 0, |
2393 | 984 "http script var: \"%*s\"", e->pos - p, p); |
509 | 985 } |
986 } | |
987 } | |
988 | |
989 | |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
990 static ngx_int_t |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
991 ngx_http_script_add_args_code(ngx_http_script_compile_t *sc) |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
992 { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
993 uintptr_t *code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
994 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
995 code = ngx_http_script_add_code(*sc->lengths, sizeof(uintptr_t), NULL); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
996 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
997 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
998 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
999 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1000 *code = (uintptr_t) ngx_http_script_mark_args_code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1001 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1002 code = ngx_http_script_add_code(*sc->values, sizeof(uintptr_t), &sc->main); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1003 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1004 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1005 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1006 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1007 *code = (uintptr_t) ngx_http_script_start_args_code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1008 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1009 return NGX_OK; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1010 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1011 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1012 |
509 | 1013 size_t |
1891
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
1014 ngx_http_script_mark_args_code(ngx_http_script_engine_t *e) |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
1015 { |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
1016 e->is_args = 1; |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
1017 e->ip += sizeof(uintptr_t); |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
1018 |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
1019 return 1; |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
1020 } |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
1021 |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
1022 |
509 | 1023 void |
1024 ngx_http_script_start_args_code(ngx_http_script_engine_t *e) | |
1025 { | |
1026 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1027 "http script args"); | |
577 | 1028 |
2225
207827f7bf71
escape a query string characters taken from URI while rewrite
Igor Sysoev <igor@sysoev.ru>
parents:
2133
diff
changeset
|
1029 e->is_args = 1; |
509 | 1030 e->args = e->pos; |
1031 e->ip += sizeof(uintptr_t); | |
1032 } | |
1033 | |
1034 | |
517 | 1035 #if (NGX_PCRE) |
1036 | |
509 | 1037 void |
1038 ngx_http_script_regex_start_code(ngx_http_script_engine_t *e) | |
1039 { | |
1040 size_t len; | |
1041 ngx_int_t rc; | |
1042 ngx_uint_t n; | |
1043 ngx_http_request_t *r; | |
1044 ngx_http_script_engine_t le; | |
1045 ngx_http_script_len_code_pt lcode; | |
1046 ngx_http_script_regex_code_t *code; | |
1047 | |
1048 code = (ngx_http_script_regex_code_t *) e->ip; | |
1049 | |
1050 r = e->request; | |
1051 | |
1052 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1053 "http script regex: \"%V\"", &code->name); | |
1054 | |
1055 if (code->uri) { | |
515 | 1056 e->line = r->uri; |
509 | 1057 } else { |
1058 e->sp--; | |
573 | 1059 e->line.len = e->sp->len; |
1060 e->line.data = e->sp->data; | |
509 | 1061 } |
507 | 1062 |
3325 | 1063 rc = ngx_http_regex_exec(r, code->regex, &e->line); |
2547
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1064 |
3325 | 1065 if (rc == NGX_DECLINED) { |
2397 | 1066 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) { |
509 | 1067 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, |
515 | 1068 "\"%V\" does not match \"%V\"", |
1069 &code->name, &e->line); | |
509 | 1070 } |
1071 | |
2547
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1072 r->ncaptures = 0; |
515 | 1073 |
509 | 1074 if (code->test) { |
631 | 1075 if (code->negative_test) { |
1076 e->sp->len = 1; | |
1077 e->sp->data = (u_char *) "1"; | |
1078 | |
1079 } else { | |
1080 e->sp->len = 0; | |
1081 e->sp->data = (u_char *) ""; | |
1082 } | |
1083 | |
509 | 1084 e->sp++; |
1085 | |
1086 e->ip += sizeof(ngx_http_script_regex_code_t); | |
1087 return; | |
1088 } | |
1089 | |
1090 e->ip += code->next; | |
1091 return; | |
1092 } | |
1093 | |
3325 | 1094 if (rc == NGX_ERROR) { |
509 | 1095 e->ip = ngx_http_script_exit; |
1096 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1097 return; | |
1098 } | |
1099 | |
2397 | 1100 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) { |
509 | 1101 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, |
515 | 1102 "\"%V\" matches \"%V\"", &code->name, &e->line); |
509 | 1103 } |
1104 | |
1105 if (code->test) { | |
631 | 1106 if (code->negative_test) { |
1107 e->sp->len = 0; | |
1108 e->sp->data = (u_char *) ""; | |
1109 | |
1110 } else { | |
1111 e->sp->len = 1; | |
1112 e->sp->data = (u_char *) "1"; | |
1113 } | |
1114 | |
509 | 1115 e->sp++; |
1116 | |
1117 e->ip += sizeof(ngx_http_script_regex_code_t); | |
1118 return; | |
1119 } | |
1120 | |
1121 if (code->status) { | |
1122 e->status = code->status; | |
507 | 1123 |
509 | 1124 if (!code->redirect) { |
1125 e->ip = ngx_http_script_exit; | |
1126 return; | |
1127 } | |
1128 } | |
1129 | |
1130 if (code->uri) { | |
1131 r->internal = 1; | |
1132 r->valid_unparsed_uri = 0; | |
1133 | |
1134 if (code->break_cycle) { | |
1135 r->valid_location = 0; | |
527 | 1136 r->uri_changed = 0; |
509 | 1137 |
1138 } else { | |
1139 r->uri_changed = 1; | |
1140 } | |
1141 } | |
1142 | |
1143 if (code->lengths == NULL) { | |
1144 e->buf.len = code->size; | |
1145 | |
1146 if (code->uri) { | |
3344
1aed55182ea2
fix captures in "rewrite", the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3325
diff
changeset
|
1147 if (r->ncaptures && (r->quoted_uri || r->plus_in_uri)) { |
509 | 1148 e->buf.len += 2 * ngx_escape_uri(NULL, r->uri.data, r->uri.len, |
1149 NGX_ESCAPE_ARGS); | |
1150 } | |
1151 } | |
1152 | |
3344
1aed55182ea2
fix captures in "rewrite", the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3325
diff
changeset
|
1153 for (n = 2; n < r->ncaptures; n += 2) { |
1aed55182ea2
fix captures in "rewrite", the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3325
diff
changeset
|
1154 e->buf.len += r->captures[n + 1] - r->captures[n]; |
509 | 1155 } |
1156 | |
1157 } else { | |
1158 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); | |
1159 | |
1160 le.ip = code->lengths->elts; | |
679 | 1161 le.line = e->line; |
509 | 1162 le.request = r; |
679 | 1163 le.quote = code->redirect; |
509 | 1164 |
1891
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
1165 len = 0; |
509 | 1166 |
1167 while (*(uintptr_t *) le.ip) { | |
1168 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
1169 len += lcode(&le); | |
1170 } | |
1171 | |
1172 e->buf.len = len; | |
1173 } | |
1174 | |
515 | 1175 if (code->add_args && r->args.len) { |
509 | 1176 e->buf.len += r->args.len + 1; |
1177 } | |
1178 | |
2049 | 1179 e->buf.data = ngx_pnalloc(r->pool, e->buf.len); |
509 | 1180 if (e->buf.data == NULL) { |
1181 e->ip = ngx_http_script_exit; | |
1182 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
507 | 1183 return; |
1184 } | |
1185 | |
509 | 1186 e->quote = code->redirect; |
1187 | |
1188 e->pos = e->buf.data; | |
1189 | |
1190 e->ip += sizeof(ngx_http_script_regex_code_t); | |
1191 } | |
1192 | |
1193 | |
1194 void | |
1195 ngx_http_script_regex_end_code(ngx_http_script_engine_t *e) | |
1196 { | |
577 | 1197 u_char *dst, *src; |
509 | 1198 ngx_http_request_t *r; |
1199 ngx_http_script_regex_end_code_t *code; | |
1200 | |
1201 code = (ngx_http_script_regex_end_code_t *) e->ip; | |
1202 | |
1203 r = e->request; | |
1204 | |
1205 e->quote = 0; | |
1206 | |
1207 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1208 "http script regex end"); | |
1209 | |
1210 if (code->redirect) { | |
1211 | |
577 | 1212 dst = e->buf.data; |
1213 src = e->buf.data; | |
1214 | |
1593 | 1215 ngx_unescape_uri(&dst, &src, e->pos - e->buf.data, |
1216 NGX_UNESCAPE_REDIRECT); | |
577 | 1217 |
1218 if (src < e->pos) { | |
3887
e7798b5e990a
use memmove() in appropriate places
Igor Sysoev <igor@sysoev.ru>
parents:
3761
diff
changeset
|
1219 dst = ngx_movemem(dst, src, e->pos - src); |
577 | 1220 } |
1221 | |
1222 e->pos = dst; | |
1223 | |
1224 if (code->add_args && r->args.len) { | |
509 | 1225 *e->pos++ = (u_char) (code->args ? '&' : '?'); |
573 | 1226 e->pos = ngx_copy(e->pos, r->args.data, r->args.len); |
509 | 1227 } |
1228 | |
1229 e->buf.len = e->pos - e->buf.data; | |
1230 | |
2397 | 1231 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) { |
509 | 1232 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, |
1233 "rewritten redirect: \"%V\"", &e->buf); | |
1234 } | |
1235 | |
4206
1a94a56a4e5d
Clear old Location header (if any) while adding a new one.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3904
diff
changeset
|
1236 ngx_http_clear_location(r); |
1a94a56a4e5d
Clear old Location header (if any) while adding a new one.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3904
diff
changeset
|
1237 |
509 | 1238 r->headers_out.location = ngx_list_push(&r->headers_out.headers); |
1239 if (r->headers_out.location == NULL) { | |
1240 e->ip = ngx_http_script_exit; | |
1241 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1242 return; | |
1243 } | |
1244 | |
577 | 1245 r->headers_out.location->hash = 1; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3344
diff
changeset
|
1246 ngx_str_set(&r->headers_out.location->key, "Location"); |
509 | 1247 r->headers_out.location->value = e->buf; |
1248 | |
1249 e->ip += sizeof(ngx_http_script_regex_end_code_t); | |
1250 return; | |
1251 } | |
1252 | |
577 | 1253 if (e->args) { |
509 | 1254 e->buf.len = e->args - e->buf.data; |
1255 | |
1256 if (code->add_args && r->args.len) { | |
1257 *e->pos++ = '&'; | |
573 | 1258 e->pos = ngx_copy(e->pos, r->args.data, r->args.len); |
509 | 1259 } |
1260 | |
1261 r->args.len = e->pos - e->args; | |
1262 r->args.data = e->args; | |
1263 | |
1264 e->args = NULL; | |
1265 | |
1266 } else { | |
1267 e->buf.len = e->pos - e->buf.data; | |
673 | 1268 |
1269 if (!code->add_args) { | |
1270 r->args.len = 0; | |
1271 } | |
509 | 1272 } |
1273 | |
2397 | 1274 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) { |
509 | 1275 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, |
1276 "rewritten data: \"%V\", args: \"%V\"", | |
1277 &e->buf, &r->args); | |
1278 } | |
1279 | |
1280 if (code->uri) { | |
1281 r->uri = e->buf; | |
1282 | |
535 | 1283 if (r->uri.len == 0) { |
1284 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1285 "the rewritten URI has a zero length"); | |
1286 e->ip = ngx_http_script_exit; | |
1287 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1288 return; | |
1289 } | |
1290 | |
2979
b941147f2b2e
ngx_http_set_exten() is always successful since 0.3.46
Igor Sysoev <igor@sysoev.ru>
parents:
2911
diff
changeset
|
1291 ngx_http_set_exten(r); |
509 | 1292 } |
1293 | |
1294 e->ip += sizeof(ngx_http_script_regex_end_code_t); | |
1295 } | |
1296 | |
2547
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1297 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1298 static ngx_int_t |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1299 ngx_http_script_add_capture_code(ngx_http_script_compile_t *sc, ngx_uint_t n) |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1300 { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1301 ngx_http_script_copy_capture_code_t *code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1302 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1303 code = ngx_http_script_add_code(*sc->lengths, |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1304 sizeof(ngx_http_script_copy_capture_code_t), |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1305 NULL); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1306 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1307 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1308 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1309 |
7271
9e25a5380a21
Silenced -Wcast-function-type warnings (closes #1546).
Sergey Kandaurov <pluknet@nginx.com>
parents:
6948
diff
changeset
|
1310 code->code = (ngx_http_script_code_pt) (void *) |
9e25a5380a21
Silenced -Wcast-function-type warnings (closes #1546).
Sergey Kandaurov <pluknet@nginx.com>
parents:
6948
diff
changeset
|
1311 ngx_http_script_copy_capture_len_code; |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1312 code->n = 2 * n; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1313 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1314 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1315 code = ngx_http_script_add_code(*sc->values, |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1316 sizeof(ngx_http_script_copy_capture_code_t), |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1317 &sc->main); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1318 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1319 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1320 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1321 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1322 code->code = ngx_http_script_copy_capture_code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1323 code->n = 2 * n; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1324 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1325 if (sc->ncaptures < n) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1326 sc->ncaptures = n; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1327 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1328 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1329 return NGX_OK; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1330 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1331 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1332 |
2547
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1333 size_t |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1334 ngx_http_script_copy_capture_len_code(ngx_http_script_engine_t *e) |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1335 { |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1336 int *cap; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1337 u_char *p; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1338 ngx_uint_t n; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1339 ngx_http_request_t *r; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1340 ngx_http_script_copy_capture_code_t *code; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1341 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1342 r = e->request; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1343 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1344 code = (ngx_http_script_copy_capture_code_t *) e->ip; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1345 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1346 e->ip += sizeof(ngx_http_script_copy_capture_code_t); |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1347 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1348 n = code->n; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1349 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1350 if (n < r->ncaptures) { |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1351 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1352 cap = r->captures; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1353 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1354 if ((e->is_args || e->quote) |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1355 && (e->request->quoted_uri || e->request->plus_in_uri)) |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1356 { |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1357 p = r->captures_data; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1358 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1359 return cap[n + 1] - cap[n] |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1360 + 2 * ngx_escape_uri(NULL, &p[cap[n]], cap[n + 1] - cap[n], |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1361 NGX_ESCAPE_ARGS); |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1362 } else { |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1363 return cap[n + 1] - cap[n]; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1364 } |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1365 } |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1366 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1367 return 0; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1368 } |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1369 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1370 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1371 void |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1372 ngx_http_script_copy_capture_code(ngx_http_script_engine_t *e) |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1373 { |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1374 int *cap; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1375 u_char *p, *pos; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1376 ngx_uint_t n; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1377 ngx_http_request_t *r; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1378 ngx_http_script_copy_capture_code_t *code; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1379 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1380 r = e->request; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1381 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1382 code = (ngx_http_script_copy_capture_code_t *) e->ip; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1383 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1384 e->ip += sizeof(ngx_http_script_copy_capture_code_t); |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1385 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1386 n = code->n; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1387 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1388 pos = e->pos; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1389 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1390 if (n < r->ncaptures) { |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1391 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1392 cap = r->captures; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1393 p = r->captures_data; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1394 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1395 if ((e->is_args || e->quote) |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1396 && (e->request->quoted_uri || e->request->plus_in_uri)) |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1397 { |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1398 e->pos = (u_char *) ngx_escape_uri(pos, &p[cap[n]], |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1399 cap[n + 1] - cap[n], |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1400 NGX_ESCAPE_ARGS); |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1401 } else { |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1402 e->pos = ngx_copy(pos, &p[cap[n]], cap[n + 1] - cap[n]); |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1403 } |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1404 } |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1405 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1406 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1407 "http script capture: \"%*s\"", e->pos - pos, pos); |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1408 } |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1409 |
517 | 1410 #endif |
1411 | |
509 | 1412 |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1413 static ngx_int_t |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1414 ngx_http_script_add_full_name_code(ngx_http_script_compile_t *sc) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1415 { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1416 ngx_http_script_full_name_code_t *code; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1417 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1418 code = ngx_http_script_add_code(*sc->lengths, |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1419 sizeof(ngx_http_script_full_name_code_t), |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1420 NULL); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1421 if (code == NULL) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1422 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1423 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1424 |
7271
9e25a5380a21
Silenced -Wcast-function-type warnings (closes #1546).
Sergey Kandaurov <pluknet@nginx.com>
parents:
6948
diff
changeset
|
1425 code->code = (ngx_http_script_code_pt) (void *) |
9e25a5380a21
Silenced -Wcast-function-type warnings (closes #1546).
Sergey Kandaurov <pluknet@nginx.com>
parents:
6948
diff
changeset
|
1426 ngx_http_script_full_name_len_code; |
2758 | 1427 code->conf_prefix = sc->conf_prefix; |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1428 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1429 code = ngx_http_script_add_code(*sc->values, |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1430 sizeof(ngx_http_script_full_name_code_t), |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1431 &sc->main); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1432 if (code == NULL) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1433 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1434 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1435 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1436 code->code = ngx_http_script_full_name_code; |
2758 | 1437 code->conf_prefix = sc->conf_prefix; |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1438 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1439 return NGX_OK; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1440 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1441 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1442 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1443 static size_t |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1444 ngx_http_script_full_name_len_code(ngx_http_script_engine_t *e) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1445 { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1446 ngx_http_script_full_name_code_t *code; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1447 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1448 code = (ngx_http_script_full_name_code_t *) e->ip; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1449 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1450 e->ip += sizeof(ngx_http_script_full_name_code_t); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1451 |
2758 | 1452 return code->conf_prefix ? ngx_cycle->conf_prefix.len: |
1453 ngx_cycle->prefix.len; | |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1454 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1455 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1456 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1457 static void |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1458 ngx_http_script_full_name_code(ngx_http_script_engine_t *e) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1459 { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1460 ngx_http_script_full_name_code_t *code; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1461 |
5331
e04083b79335
Style improved after 12dd27b74117.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5330
diff
changeset
|
1462 ngx_str_t value, *prefix; |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1463 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1464 code = (ngx_http_script_full_name_code_t *) e->ip; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1465 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1466 value.data = e->buf.data; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1467 value.len = e->pos - e->buf.data; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1468 |
5331
e04083b79335
Style improved after 12dd27b74117.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5330
diff
changeset
|
1469 prefix = code->conf_prefix ? (ngx_str_t *) &ngx_cycle->conf_prefix: |
e04083b79335
Style improved after 12dd27b74117.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5330
diff
changeset
|
1470 (ngx_str_t *) &ngx_cycle->prefix; |
e04083b79335
Style improved after 12dd27b74117.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5330
diff
changeset
|
1471 |
e04083b79335
Style improved after 12dd27b74117.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5330
diff
changeset
|
1472 if (ngx_get_full_name(e->request->pool, prefix, &value) != NGX_OK) { |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1473 e->ip = ngx_http_script_exit; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1474 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1475 return; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1476 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1477 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1478 e->buf = value; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1479 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1480 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1481 "http script fullname: \"%V\"", &value); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1482 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1483 e->ip += sizeof(ngx_http_script_full_name_code_t); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1484 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1485 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1486 |
509 | 1487 void |
1488 ngx_http_script_return_code(ngx_http_script_engine_t *e) | |
577 | 1489 { |
509 | 1490 ngx_http_script_return_code_t *code; |
577 | 1491 |
509 | 1492 code = (ngx_http_script_return_code_t *) e->ip; |
1493 | |
3633 | 1494 if (code->status < NGX_HTTP_BAD_REQUEST |
1495 || code->text.value.len | |
1496 || code->text.lengths) | |
1497 { | |
1498 e->status = ngx_http_send_response(e->request, code->status, NULL, | |
1499 &code->text); | |
1500 } else { | |
1501 e->status = code->status; | |
653 | 1502 } |
1503 | |
3633 | 1504 e->ip = ngx_http_script_exit; |
479 | 1505 } |
509 | 1506 |
1507 | |
1508 void | |
527 | 1509 ngx_http_script_break_code(ngx_http_script_engine_t *e) |
1510 { | |
7604
7aa20af4ac00
Rewrite: fixed segfault with rewritten URI and "alias".
Ruslan Ermilov <ru@nginx.com>
parents:
7503
diff
changeset
|
1511 ngx_http_request_t *r; |
7aa20af4ac00
Rewrite: fixed segfault with rewritten URI and "alias".
Ruslan Ermilov <ru@nginx.com>
parents:
7503
diff
changeset
|
1512 |
7aa20af4ac00
Rewrite: fixed segfault with rewritten URI and "alias".
Ruslan Ermilov <ru@nginx.com>
parents:
7503
diff
changeset
|
1513 r = e->request; |
7aa20af4ac00
Rewrite: fixed segfault with rewritten URI and "alias".
Ruslan Ermilov <ru@nginx.com>
parents:
7503
diff
changeset
|
1514 |
7aa20af4ac00
Rewrite: fixed segfault with rewritten URI and "alias".
Ruslan Ermilov <ru@nginx.com>
parents:
7503
diff
changeset
|
1515 if (r->uri_changed) { |
7aa20af4ac00
Rewrite: fixed segfault with rewritten URI and "alias".
Ruslan Ermilov <ru@nginx.com>
parents:
7503
diff
changeset
|
1516 r->valid_location = 0; |
7aa20af4ac00
Rewrite: fixed segfault with rewritten URI and "alias".
Ruslan Ermilov <ru@nginx.com>
parents:
7503
diff
changeset
|
1517 r->uri_changed = 0; |
7aa20af4ac00
Rewrite: fixed segfault with rewritten URI and "alias".
Ruslan Ermilov <ru@nginx.com>
parents:
7503
diff
changeset
|
1518 } |
527 | 1519 |
1520 e->ip = ngx_http_script_exit; | |
1521 } | |
1522 | |
1523 | |
1524 void | |
509 | 1525 ngx_http_script_if_code(ngx_http_script_engine_t *e) |
1526 { | |
1527 ngx_http_script_if_code_t *code; | |
1528 | |
1529 code = (ngx_http_script_if_code_t *) e->ip; | |
1530 | |
1531 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1532 "http script if"); | |
1533 | |
1534 e->sp--; | |
1535 | |
5426 | 1536 if (e->sp->len && (e->sp->len != 1 || e->sp->data[0] != '0')) { |
509 | 1537 if (code->loc_conf) { |
1538 e->request->loc_conf = code->loc_conf; | |
535 | 1539 ngx_http_update_location_config(e->request); |
509 | 1540 } |
1541 | |
1542 e->ip += sizeof(ngx_http_script_if_code_t); | |
1543 return; | |
1544 } | |
1545 | |
1546 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
577 | 1547 "http script if: false"); |
509 | 1548 |
1549 e->ip += code->next; | |
1550 } | |
1551 | |
1552 | |
1553 void | |
577 | 1554 ngx_http_script_equal_code(ngx_http_script_engine_t *e) |
1555 { | |
1556 ngx_http_variable_value_t *val, *res; | |
1557 | |
1558 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1559 "http script equal"); | |
1560 | |
1561 e->sp--; | |
1562 val = e->sp; | |
1563 res = e->sp - 1; | |
1564 | |
1565 e->ip += sizeof(uintptr_t); | |
1566 | |
2393 | 1567 if (val->len == res->len |
1568 && ngx_strncmp(val->data, res->data, res->len) == 0) | |
577 | 1569 { |
1570 *res = ngx_http_variable_true_value; | |
1571 return; | |
1572 } | |
1573 | |
1574 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1575 "http script equal: no"); | |
1576 | |
1577 *res = ngx_http_variable_null_value; | |
1578 } | |
1579 | |
1580 | |
1581 void | |
1582 ngx_http_script_not_equal_code(ngx_http_script_engine_t *e) | |
1583 { | |
1584 ngx_http_variable_value_t *val, *res; | |
1585 | |
1586 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1587 "http script not equal"); | |
1588 | |
1589 e->sp--; | |
1590 val = e->sp; | |
1591 res = e->sp - 1; | |
1592 | |
1593 e->ip += sizeof(uintptr_t); | |
1594 | |
2393 | 1595 if (val->len == res->len |
1596 && ngx_strncmp(val->data, res->data, res->len) == 0) | |
577 | 1597 { |
1598 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1599 "http script not equal: no"); | |
1600 | |
1601 *res = ngx_http_variable_null_value; | |
1602 return; | |
1603 } | |
1604 | |
1605 *res = ngx_http_variable_true_value; | |
1606 } | |
1607 | |
1608 | |
1609 void | |
631 | 1610 ngx_http_script_file_code(ngx_http_script_engine_t *e) |
1611 { | |
1454 | 1612 ngx_str_t path; |
1613 ngx_http_request_t *r; | |
1614 ngx_open_file_info_t of; | |
1615 ngx_http_core_loc_conf_t *clcf; | |
631 | 1616 ngx_http_variable_value_t *value; |
1617 ngx_http_script_file_code_t *code; | |
1618 | |
1619 value = e->sp - 1; | |
1620 | |
1621 code = (ngx_http_script_file_code_t *) e->ip; | |
1622 e->ip += sizeof(ngx_http_script_file_code_t); | |
1623 | |
1454 | 1624 path.len = value->len - 1; |
1625 path.data = value->data; | |
1626 | |
1627 r = e->request; | |
1628 | |
1629 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
6480 | 1630 "http script file op %p \"%V\"", (void *) code->op, &path); |
1454 | 1631 |
1632 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
631 | 1633 |
2068
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
1634 ngx_memzero(&of, sizeof(ngx_open_file_info_t)); |
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
1635 |
3178 | 1636 of.read_ahead = clcf->read_ahead; |
2129 | 1637 of.directio = clcf->directio; |
1767
c42431762903
open_file_cache_retest > open_file_cache_valid
Igor Sysoev <igor@sysoev.ru>
parents:
1593
diff
changeset
|
1638 of.valid = clcf->open_file_cache_valid; |
1772 | 1639 of.min_uses = clcf->open_file_cache_min_uses; |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2609
diff
changeset
|
1640 of.test_only = 1; |
1454 | 1641 of.errors = clcf->open_file_cache_errors; |
1457 | 1642 of.events = clcf->open_file_cache_events; |
4494
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
1643 |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
1644 if (ngx_http_set_disable_symlinks(r, clcf, &path, &of) != NGX_OK) { |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
1645 e->ip = ngx_http_script_exit; |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
1646 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
1647 return; |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
1648 } |
631 | 1649 |
1454 | 1650 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) |
1799 | 1651 != NGX_OK) |
1454 | 1652 { |
6948
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6940
diff
changeset
|
1653 if (of.err == 0) { |
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6940
diff
changeset
|
1654 e->ip = ngx_http_script_exit; |
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6940
diff
changeset
|
1655 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; |
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6940
diff
changeset
|
1656 return; |
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6940
diff
changeset
|
1657 } |
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6940
diff
changeset
|
1658 |
3160
a7637c2c1157
low ENAMETOOLONG logging level
Igor Sysoev <igor@sysoev.ru>
parents:
2979
diff
changeset
|
1659 if (of.err != NGX_ENOENT |
a7637c2c1157
low ENAMETOOLONG logging level
Igor Sysoev <igor@sysoev.ru>
parents:
2979
diff
changeset
|
1660 && of.err != NGX_ENOTDIR |
a7637c2c1157
low ENAMETOOLONG logging level
Igor Sysoev <igor@sysoev.ru>
parents:
2979
diff
changeset
|
1661 && of.err != NGX_ENAMETOOLONG) |
a7637c2c1157
low ENAMETOOLONG logging level
Igor Sysoev <igor@sysoev.ru>
parents:
2979
diff
changeset
|
1662 { |
1454 | 1663 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err, |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2609
diff
changeset
|
1664 "%s \"%s\" failed", of.failed, value->data); |
631 | 1665 } |
1666 | |
1667 switch (code->op) { | |
671 | 1668 |
631 | 1669 case ngx_http_script_file_plain: |
669 | 1670 case ngx_http_script_file_dir: |
1671 case ngx_http_script_file_exists: | |
1672 case ngx_http_script_file_exec: | |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1673 goto false_value; |
671 | 1674 |
631 | 1675 case ngx_http_script_file_not_plain: |
669 | 1676 case ngx_http_script_file_not_dir: |
671 | 1677 case ngx_http_script_file_not_exists: |
669 | 1678 case ngx_http_script_file_not_exec: |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1679 goto true_value; |
631 | 1680 } |
1681 | |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1682 goto false_value; |
631 | 1683 } |
1684 | |
1685 switch (code->op) { | |
1686 case ngx_http_script_file_plain: | |
1454 | 1687 if (of.is_file) { |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1688 goto true_value; |
631 | 1689 } |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1690 goto false_value; |
631 | 1691 |
1692 case ngx_http_script_file_not_plain: | |
1454 | 1693 if (of.is_file) { |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1694 goto false_value; |
631 | 1695 } |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1696 goto true_value; |
669 | 1697 |
1698 case ngx_http_script_file_dir: | |
1454 | 1699 if (of.is_dir) { |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1700 goto true_value; |
669 | 1701 } |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1702 goto false_value; |
669 | 1703 |
1704 case ngx_http_script_file_not_dir: | |
1454 | 1705 if (of.is_dir) { |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1706 goto false_value; |
669 | 1707 } |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1708 goto true_value; |
669 | 1709 |
1710 case ngx_http_script_file_exists: | |
1454 | 1711 if (of.is_file || of.is_dir || of.is_link) { |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1712 goto true_value; |
669 | 1713 } |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1714 goto false_value; |
669 | 1715 |
1716 case ngx_http_script_file_not_exists: | |
1454 | 1717 if (of.is_file || of.is_dir || of.is_link) { |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1718 goto false_value; |
669 | 1719 } |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1720 goto true_value; |
669 | 1721 |
1722 case ngx_http_script_file_exec: | |
1454 | 1723 if (of.is_exec) { |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1724 goto true_value; |
669 | 1725 } |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1726 goto false_value; |
669 | 1727 |
1728 case ngx_http_script_file_not_exec: | |
1454 | 1729 if (of.is_exec) { |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1730 goto false_value; |
669 | 1731 } |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1732 goto true_value; |
631 | 1733 } |
1734 | |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1735 false_value: |
631 | 1736 |
1454 | 1737 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
631 | 1738 "http script file op false"); |
1739 | |
1740 *value = ngx_http_variable_null_value; | |
1741 return; | |
1742 | |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1743 true_value: |
631 | 1744 |
1745 *value = ngx_http_variable_true_value; | |
1746 return; | |
1747 } | |
1748 | |
1749 | |
1750 void | |
515 | 1751 ngx_http_script_complex_value_code(ngx_http_script_engine_t *e) |
1752 { | |
1753 size_t len; | |
1754 ngx_http_script_engine_t le; | |
1755 ngx_http_script_len_code_pt lcode; | |
1756 ngx_http_script_complex_value_code_t *code; | |
1757 | |
1758 code = (ngx_http_script_complex_value_code_t *) e->ip; | |
1759 | |
1760 e->ip += sizeof(ngx_http_script_complex_value_code_t); | |
1761 | |
1762 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1763 "http script complex value"); | |
1764 | |
1765 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); | |
1766 | |
1767 le.ip = code->lengths->elts; | |
655 | 1768 le.line = e->line; |
515 | 1769 le.request = e->request; |
655 | 1770 le.quote = e->quote; |
515 | 1771 |
1772 for (len = 0; *(uintptr_t *) le.ip; len += lcode(&le)) { | |
1773 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
1774 } | |
1775 | |
1776 e->buf.len = len; | |
2049 | 1777 e->buf.data = ngx_pnalloc(e->request->pool, len); |
515 | 1778 if (e->buf.data == NULL) { |
1779 e->ip = ngx_http_script_exit; | |
1780 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1781 return; | |
1782 } | |
1783 | |
1784 e->pos = e->buf.data; | |
1785 | |
577 | 1786 e->sp->len = e->buf.len; |
573 | 1787 e->sp->data = e->buf.data; |
515 | 1788 e->sp++; |
1789 } | |
1790 | |
1791 | |
1792 void | |
509 | 1793 ngx_http_script_value_code(ngx_http_script_engine_t *e) |
1794 { | |
1795 ngx_http_script_value_code_t *code; | |
1796 | |
1797 code = (ngx_http_script_value_code_t *) e->ip; | |
1798 | |
1799 e->ip += sizeof(ngx_http_script_value_code_t); | |
1800 | |
573 | 1801 e->sp->len = code->text_len; |
1802 e->sp->data = (u_char *) code->text_data; | |
577 | 1803 |
1804 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1561 | 1805 "http script value: \"%v\"", e->sp); |
577 | 1806 |
509 | 1807 e->sp++; |
1808 } | |
1809 | |
1810 | |
1811 void | |
1812 ngx_http_script_set_var_code(ngx_http_script_engine_t *e) | |
1813 { | |
1814 ngx_http_request_t *r; | |
1815 ngx_http_script_var_code_t *code; | |
1816 | |
1817 code = (ngx_http_script_var_code_t *) e->ip; | |
1818 | |
1819 e->ip += sizeof(ngx_http_script_var_code_t); | |
1820 | |
1821 r = e->request; | |
1822 | |
1823 e->sp--; | |
1824 | |
573 | 1825 r->variables[code->index].len = e->sp->len; |
1826 r->variables[code->index].valid = 1; | |
1565 | 1827 r->variables[code->index].no_cacheable = 0; |
573 | 1828 r->variables[code->index].not_found = 0; |
1829 r->variables[code->index].data = e->sp->data; | |
2393 | 1830 |
1831 #if (NGX_DEBUG) | |
1832 { | |
1833 ngx_http_variable_t *v; | |
1834 ngx_http_core_main_conf_t *cmcf; | |
1835 | |
1836 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
1837 | |
1838 v = cmcf->variables.elts; | |
1839 | |
1840 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1841 "http script set $%V", &v[code->index].name); | |
1842 } | |
1843 #endif | |
509 | 1844 } |
1845 | |
1846 | |
1847 void | |
637 | 1848 ngx_http_script_var_set_handler_code(ngx_http_script_engine_t *e) |
1849 { | |
1850 ngx_http_script_var_handler_code_t *code; | |
1851 | |
1852 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1853 "http script set var handler"); | |
1854 | |
1855 code = (ngx_http_script_var_handler_code_t *) e->ip; | |
1856 | |
1857 e->ip += sizeof(ngx_http_script_var_handler_code_t); | |
1858 | |
1859 e->sp--; | |
1860 | |
1861 code->handler(e->request, e->sp, code->data); | |
1862 } | |
1863 | |
1864 | |
1865 void | |
509 | 1866 ngx_http_script_var_code(ngx_http_script_engine_t *e) |
1867 { | |
1868 ngx_http_variable_value_t *value; | |
1869 ngx_http_script_var_code_t *code; | |
1870 | |
1871 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1872 "http script var"); | |
1873 | |
1874 code = (ngx_http_script_var_code_t *) e->ip; | |
1875 | |
1876 e->ip += sizeof(ngx_http_script_var_code_t); | |
1877 | |
573 | 1878 value = ngx_http_get_flushed_variable(e->request, code->index); |
509 | 1879 |
573 | 1880 if (value && !value->not_found) { |
1881 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1406
03341711f9a2
use %v for ngx_variable_value_t in ngx_sprintf(),
Igor Sysoev <igor@sysoev.ru>
parents:
1152
diff
changeset
|
1882 "http script var: \"%v\"", value); |
573 | 1883 |
553 | 1884 *e->sp = *value; |
509 | 1885 e->sp++; |
1886 | |
1887 return; | |
1888 } | |
1889 | |
577 | 1890 *e->sp = ngx_http_variable_null_value; |
509 | 1891 e->sp++; |
1892 } | |
1893 | |
1894 | |
1895 void | |
1896 ngx_http_script_nop_code(ngx_http_script_engine_t *e) | |
1897 { | |
1898 e->ip += sizeof(uintptr_t); | |
1899 } |