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