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