Mercurial > hg > nginx
annotate src/http/ngx_http_script.c @ 3672:4f021d4ceb88
fix building by owc12: GetLongPathName() is available since Win2K only
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 05 Jul 2010 12:47:35 +0000 |
parents | 187783310b65 |
children | 55f95e91daed |
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 |
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
|
4 */ |
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 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_http.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
12 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
|
13 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
|
14 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
|
15 ngx_str_t *value, ngx_uint_t last); |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
16 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
|
17 ngx_str_t *name); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
18 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
|
19 #if (NGX_PCRE) |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
20 static ngx_int_t ngx_http_script_add_capture_code(ngx_http_script_compile_t *sc, |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
21 ngx_uint_t n); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
22 #endif |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
23 static ngx_int_t |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
24 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
|
25 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
|
26 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
|
27 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
28 |
509 | 29 #define ngx_http_script_exit (u_char *) &ngx_http_script_exit_code |
30 | |
31 static uintptr_t ngx_http_script_exit_code = (uintptr_t) NULL; | |
32 | |
33 | |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
34 void |
2609
ad99a49cd313
rename ngx_http_scrip_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2608
diff
changeset
|
35 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
|
36 ngx_http_complex_value_t *val) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
37 { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
38 ngx_uint_t *index; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
39 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
40 index = val->flushes; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
41 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
42 if (index) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
43 while (*index != (ngx_uint_t) -1) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
44 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
45 if (r->variables[*index].no_cacheable) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
46 r->variables[*index].valid = 0; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
47 r->variables[*index].not_found = 0; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
48 } |
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 index++; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
51 } |
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 ngx_int_t |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
57 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
|
58 ngx_str_t *value) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
59 { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
60 size_t len; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
61 ngx_http_script_code_pt code; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
62 ngx_http_script_len_code_pt lcode; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
63 ngx_http_script_engine_t e; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
64 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
65 if (val->lengths == NULL) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
66 *value = val->value; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
67 return NGX_OK; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
68 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
69 |
2609
ad99a49cd313
rename ngx_http_scrip_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2608
diff
changeset
|
70 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
|
71 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
72 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
|
73 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
74 e.ip = val->lengths; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
75 e.request = r; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
76 e.flushed = 1; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
77 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
78 len = 0; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
79 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
80 while (*(uintptr_t *) e.ip) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
81 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
|
82 len += lcode(&e); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
83 } |
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 value->len = len; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
86 value->data = ngx_pnalloc(r->pool, len); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
87 if (value->data == NULL) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
88 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
89 } |
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 e.ip = val->values; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
92 e.pos = value->data; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
93 e.buf = *value; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
94 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
95 while (*(uintptr_t *) e.ip) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
96 code = *(ngx_http_script_code_pt *) e.ip; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
97 code((ngx_http_script_engine_t *) &e); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
98 } |
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 *value = e.buf; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
101 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
102 return NGX_OK; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
103 } |
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 ngx_int_t |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
107 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
|
108 { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
109 ngx_str_t *v; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
110 ngx_uint_t i, n, nv, nc; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
111 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
|
112 ngx_http_script_compile_t sc; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
113 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
114 v = ccv->value; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
115 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
116 if (v->len == 0) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
117 ngx_conf_log_error(NGX_LOG_EMERG, ccv->cf, 0, "empty parameter"); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
118 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
119 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
120 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
121 nv = 0; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
122 nc = 0; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
123 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
124 for (i = 0; i < v->len; i++) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
125 if (v->data[i] == '$') { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
126 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
|
127 nc++; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
128 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
129 } else { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
130 nv++; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
131 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
132 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
133 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
134 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
135 if (v->data[0] != '$' && (ccv->conf_prefix || ccv->root_prefix)) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
136 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
137 if (ngx_conf_full_name(ccv->cf->cycle, v, ccv->conf_prefix) != NGX_OK) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
138 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
139 } |
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 ccv->conf_prefix = 0; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
142 ccv->root_prefix = 0; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
143 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
144 |
2608
2f4a3a4dfd34
fix plain text values using relative path in ngx_http_complex_value(),
Igor Sysoev <igor@sysoev.ru>
parents:
2587
diff
changeset
|
145 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
|
146 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
|
147 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
|
148 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
|
149 |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
150 if (nv == 0 && nc == 0) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
151 return NGX_OK; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
152 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
153 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
154 n = nv + 1; |
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 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
|
157 != NGX_OK) |
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 return NGX_ERROR; |
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 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
162 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
|
163 + sizeof(ngx_http_script_var_code_t)) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
164 + sizeof(uintptr_t); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
165 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
166 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
|
167 return NGX_ERROR; |
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 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
170 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
|
171 + sizeof(ngx_http_script_var_code_t)) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
172 + sizeof(uintptr_t) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
173 + v->len |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
174 + sizeof(uintptr_t) - 1) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
175 & ~(sizeof(uintptr_t) - 1); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
176 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
177 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
|
178 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
179 } |
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 pf = &flushes; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
182 pl = &lengths; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
183 pv = &values; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
184 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
185 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
|
186 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
187 sc.cf = ccv->cf; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
188 sc.source = v; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
189 sc.flushes = &pf; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
190 sc.lengths = &pl; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
191 sc.values = &pv; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
192 sc.complete_lengths = 1; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
193 sc.complete_values = 1; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
194 sc.zero = ccv->zero; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
195 sc.conf_prefix = ccv->conf_prefix; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
196 sc.root_prefix = ccv->root_prefix; |
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 if (ngx_http_script_compile(&sc) != NGX_OK) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
199 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
200 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
201 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
202 if (flushes.nelts) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
203 ccv->complex_value->flushes = flushes.elts; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
204 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
|
205 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
206 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
207 ccv->complex_value->lengths = lengths.elts; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
208 ccv->complex_value->values = values.elts; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
209 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
210 return NGX_OK; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
211 } |
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 |
509 | 214 ngx_uint_t |
215 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
|
216 { |
509 | 217 ngx_uint_t i, n; |
507 | 218 |
509 | 219 for (n = 0, i = 0; i < value->len; i++) { |
220 if (value->data[i] == '$') { | |
221 n++; | |
222 } | |
507 | 223 } |
224 | |
509 | 225 return n; |
226 } | |
227 | |
228 | |
229 ngx_int_t | |
230 ngx_http_script_compile(ngx_http_script_compile_t *sc) | |
231 { | |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
232 u_char ch; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
233 ngx_str_t name; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
234 ngx_uint_t i, bracket; |
573 | 235 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
236 if (ngx_http_script_init_arrays(sc) != NGX_OK) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
237 return NGX_ERROR; |
509 | 238 } |
239 | |
240 for (i = 0; i < sc->source->len; /* void */ ) { | |
241 | |
242 name.len = 0; | |
243 | |
244 if (sc->source->data[i] == '$') { | |
245 | |
246 if (++i == sc->source->len) { | |
247 goto invalid_variable; | |
248 } | |
249 | |
2547
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
250 #if (NGX_PCRE) |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
251 { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
252 ngx_uint_t n; |
2547
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
253 |
509 | 254 if (sc->source->data[i] >= '1' && sc->source->data[i] <= '9') { |
255 | |
641 | 256 n = sc->source->data[i] - '0'; |
257 | |
258 if (sc->captures_mask & (1 << n)) { | |
259 sc->dup_capture = 1; | |
260 } | |
261 | |
262 sc->captures_mask |= 1 << n; | |
263 | |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
264 if (ngx_http_script_add_capture_code(sc, n) != NGX_OK) { |
509 | 265 return NGX_ERROR; |
266 } | |
267 | |
268 i++; | |
269 | |
270 continue; | |
271 } | |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
272 } |
2547
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
273 #endif |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
274 |
509 | 275 if (sc->source->data[i] == '{') { |
276 bracket = 1; | |
277 | |
278 if (++i == sc->source->len) { | |
279 goto invalid_variable; | |
280 } | |
281 | |
282 name.data = &sc->source->data[i]; | |
283 | |
284 } else { | |
285 bracket = 0; | |
286 name.data = &sc->source->data[i]; | |
287 } | |
288 | |
289 for ( /* void */ ; i < sc->source->len; i++, name.len++) { | |
290 ch = sc->source->data[i]; | |
507 | 291 |
509 | 292 if (ch == '}' && bracket) { |
293 i++; | |
294 bracket = 0; | |
295 break; | |
296 } | |
297 | |
298 if ((ch >= 'A' && ch <= 'Z') | |
299 || (ch >= 'a' && ch <= 'z') | |
300 || (ch >= '0' && ch <= '9') | |
301 || ch == '_') | |
302 { | |
303 continue; | |
304 } | |
305 | |
306 break; | |
307 } | |
308 | |
309 if (bracket) { | |
310 ngx_conf_log_error(NGX_LOG_EMERG, sc->cf, 0, | |
311 "the closing bracket in \"%V\" " | |
312 "variable is missing", &name); | |
507 | 313 return NGX_ERROR; |
314 } | |
315 | |
509 | 316 if (name.len == 0) { |
317 goto invalid_variable; | |
318 } | |
507 | 319 |
509 | 320 sc->variables++; |
507 | 321 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
322 if (ngx_http_script_add_var_code(sc, &name) != NGX_OK) { |
507 | 323 return NGX_ERROR; |
324 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
325 |
509 | 326 continue; |
327 } | |
507 | 328 |
509 | 329 if (sc->source->data[i] == '?' && sc->compile_args) { |
330 sc->args = 1; | |
331 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
|
332 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
333 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
|
334 return NGX_ERROR; |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
335 } |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
336 |
509 | 337 i++; |
338 | |
507 | 339 continue; |
340 } | |
341 | |
509 | 342 name.data = &sc->source->data[i]; |
343 | |
2498
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
344 while (i < sc->source->len) { |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
345 |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
346 if (sc->source->data[i] == '$') { |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
347 break; |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
348 } |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
349 |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
350 if (sc->source->data[i] == '?') { |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
351 |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
352 sc->args = 1; |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
353 |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
354 if (sc->compile_args) { |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
355 break; |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
356 } |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
357 } |
d3357bf23a5e
fix /?new=arg?old=arg redirect case
Igor Sysoev <igor@sysoev.ru>
parents:
2397
diff
changeset
|
358 |
509 | 359 i++; |
360 name.len++; | |
361 } | |
362 | |
363 sc->size += name.len; | |
364 | |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
365 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
|
366 != NGX_OK) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
367 { |
509 | 368 return NGX_ERROR; |
369 } | |
507 | 370 } |
371 | |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
372 return ngx_http_script_done(sc); |
509 | 373 |
374 invalid_variable: | |
375 | |
376 ngx_conf_log_error(NGX_LOG_EMERG, sc->cf, 0, "invalid variable name"); | |
377 | |
378 return NGX_ERROR; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
379 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
380 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
381 |
623 | 382 u_char * |
383 ngx_http_script_run(ngx_http_request_t *r, ngx_str_t *value, | |
384 void *code_lengths, size_t len, void *code_values) | |
385 { | |
1152
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
386 ngx_uint_t i; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
387 ngx_http_script_code_pt code; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
388 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
|
389 ngx_http_script_engine_t e; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
390 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
|
391 |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
392 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
|
393 |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
394 for (i = 0; i < cmcf->variables.nelts; i++) { |
1565 | 395 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
|
396 r->variables[i].valid = 0; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
397 r->variables[i].not_found = 0; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
398 } |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
399 } |
623 | 400 |
401 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); | |
402 | |
403 e.ip = code_lengths; | |
404 e.request = r; | |
405 e.flushed = 1; | |
406 | |
407 while (*(uintptr_t *) e.ip) { | |
408 lcode = *(ngx_http_script_len_code_pt *) e.ip; | |
409 len += lcode(&e); | |
410 } | |
411 | |
412 | |
413 value->len = len; | |
2049 | 414 value->data = ngx_pnalloc(r->pool, len); |
623 | 415 if (value->data == NULL) { |
416 return NULL; | |
417 } | |
418 | |
419 e.ip = code_values; | |
420 e.pos = value->data; | |
421 | |
422 while (*(uintptr_t *) e.ip) { | |
423 code = *(ngx_http_script_code_pt *) e.ip; | |
424 code((ngx_http_script_engine_t *) &e); | |
425 } | |
426 | |
427 return e.pos; | |
428 } | |
429 | |
430 | |
573 | 431 void |
1565 | 432 ngx_http_script_flush_no_cacheable_variables(ngx_http_request_t *r, |
573 | 433 ngx_array_t *indices) |
434 { | |
435 ngx_uint_t n, *index; | |
436 | |
437 if (indices) { | |
438 index = indices->elts; | |
439 for (n = 0; n < indices->nelts; n++) { | |
1565 | 440 if (r->variables[index[n]].no_cacheable) { |
573 | 441 r->variables[index[n]].valid = 0; |
442 r->variables[index[n]].not_found = 0; | |
443 } | |
444 } | |
445 } | |
446 } | |
447 | |
448 | |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
449 static ngx_int_t |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
450 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
|
451 { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
452 ngx_uint_t n; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
453 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
454 if (sc->flushes && *sc->flushes == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
455 n = sc->variables ? sc->variables : 1; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
456 *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
|
457 if (*sc->flushes == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
458 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
459 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
460 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
461 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
462 if (*sc->lengths == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
463 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
|
464 + sizeof(ngx_http_script_var_code_t)) |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
465 + sizeof(uintptr_t); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
466 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
467 *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
|
468 if (*sc->lengths == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
469 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
470 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
471 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
472 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
473 if (*sc->values == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
474 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
|
475 + sizeof(ngx_http_script_var_code_t)) |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
476 + sizeof(uintptr_t) |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
477 + sc->source->len |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
478 + sizeof(uintptr_t) - 1) |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
479 & ~(sizeof(uintptr_t) - 1); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
480 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
481 *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
|
482 if (*sc->values == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
483 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
484 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
485 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
486 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
487 sc->variables = 0; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
488 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
489 return NGX_OK; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
490 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
491 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
492 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
493 static ngx_int_t |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
494 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
|
495 { |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
496 ngx_str_t zero; |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
497 uintptr_t *code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
498 |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
499 if (sc->zero) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
500 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
501 zero.len = 1; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
502 zero.data = (u_char *) "\0"; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
503 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
504 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
|
505 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
506 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
507 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
508 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
509 if (sc->conf_prefix || sc->root_prefix) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
510 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
|
511 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
512 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
513 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
514 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
515 if (sc->complete_lengths) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
516 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
|
517 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
518 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
519 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
520 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
521 *code = (uintptr_t) NULL; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
522 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
523 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
524 if (sc->complete_values) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
525 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
|
526 &sc->main); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
527 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
528 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
529 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
530 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
531 *code = (uintptr_t) NULL; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
532 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
533 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
534 return NGX_OK; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
535 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
536 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
537 |
509 | 538 void * |
507 | 539 ngx_http_script_start_code(ngx_pool_t *pool, ngx_array_t **codes, size_t size) |
479 | 540 { |
507 | 541 if (*codes == NULL) { |
542 *codes = ngx_array_create(pool, 256, 1); | |
543 if (*codes == NULL) { | |
544 return NULL; | |
545 } | |
546 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
547 |
507 | 548 return ngx_array_push_n(*codes, size); |
549 } | |
550 | |
509 | 551 |
552 void * | |
553 ngx_http_script_add_code(ngx_array_t *codes, size_t size, void *code) | |
554 { | |
555 u_char *elts, **p; | |
556 void *new; | |
557 | |
558 elts = codes->elts; | |
559 | |
560 new = ngx_array_push_n(codes, size); | |
561 if (new == NULL) { | |
2911 | 562 return NULL; |
509 | 563 } |
564 | |
565 if (code) { | |
566 if (elts != codes->elts) { | |
567 p = code; | |
568 *p += (u_char *) codes->elts - elts; | |
569 } | |
570 } | |
571 | |
572 return new; | |
573 } | |
507 | 574 |
479 | 575 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
576 static ngx_int_t |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
577 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
|
578 ngx_uint_t last) |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
579 { |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
580 u_char *p; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
581 size_t size, len, zero; |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
582 ngx_http_script_copy_code_t *code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
583 |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
584 zero = (sc->zero && last); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
585 len = value->len + zero; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
586 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
587 code = ngx_http_script_add_code(*sc->lengths, |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
588 sizeof(ngx_http_script_copy_code_t), NULL); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
589 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
590 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
591 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
592 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
593 code->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
594 code->len = len; |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
595 |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
596 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
|
597 & ~(sizeof(uintptr_t) - 1); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
598 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
599 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
|
600 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
601 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
602 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
603 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
604 code->code = ngx_http_script_copy_code; |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
605 code->len = len; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
606 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
607 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
|
608 value->data, value->len); |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
609 |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
610 if (zero) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
611 *p = '\0'; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
612 sc->zero = 0; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
613 } |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
614 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
615 return NGX_OK; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
616 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
617 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
618 |
507 | 619 size_t |
509 | 620 ngx_http_script_copy_len_code(ngx_http_script_engine_t *e) |
507 | 621 { |
622 ngx_http_script_copy_code_t *code; | |
479 | 623 |
509 | 624 code = (ngx_http_script_copy_code_t *) e->ip; |
507 | 625 |
509 | 626 e->ip += sizeof(ngx_http_script_copy_code_t); |
507 | 627 |
628 return code->len; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
629 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
630 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
631 |
507 | 632 void |
509 | 633 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
|
634 { |
2393 | 635 u_char *p; |
507 | 636 ngx_http_script_copy_code_t *code; |
637 | |
509 | 638 code = (ngx_http_script_copy_code_t *) e->ip; |
639 | |
2393 | 640 p = e->pos; |
641 | |
509 | 642 if (!e->skip) { |
2393 | 643 e->pos = ngx_copy(p, e->ip + sizeof(ngx_http_script_copy_code_t), |
573 | 644 code->len); |
509 | 645 } |
507 | 646 |
509 | 647 e->ip += sizeof(ngx_http_script_copy_code_t) |
648 + ((code->len + sizeof(uintptr_t) - 1) & ~(sizeof(uintptr_t) - 1)); | |
507 | 649 |
2393 | 650 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, |
651 "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
|
652 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
653 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
654 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
655 static ngx_int_t |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
656 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
|
657 { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
658 ngx_int_t index, *p; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
659 ngx_http_script_var_code_t *code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
660 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
661 index = ngx_http_get_variable_index(sc->cf, name); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
662 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
663 if (index == NGX_ERROR) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
664 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
665 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
666 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
667 if (sc->flushes) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
668 p = ngx_array_push(*sc->flushes); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
669 if (p == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
670 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
671 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
672 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
673 *p = index; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
674 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
675 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
676 code = ngx_http_script_add_code(*sc->lengths, |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
677 sizeof(ngx_http_script_var_code_t), NULL); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
678 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
679 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
680 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
681 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
682 code->code = (ngx_http_script_code_pt) ngx_http_script_copy_var_len_code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
683 code->index = (uintptr_t) index; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
684 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
685 code = ngx_http_script_add_code(*sc->values, |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
686 sizeof(ngx_http_script_var_code_t), |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
687 &sc->main); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
688 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
689 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
690 } |
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 code->code = ngx_http_script_copy_var_code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
693 code->index = (uintptr_t) index; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
694 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
695 return NGX_OK; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
696 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
697 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
698 |
507 | 699 size_t |
509 | 700 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
|
701 { |
507 | 702 ngx_http_variable_value_t *value; |
703 ngx_http_script_var_code_t *code; | |
704 | |
509 | 705 code = (ngx_http_script_var_code_t *) e->ip; |
507 | 706 |
509 | 707 e->ip += sizeof(ngx_http_script_var_code_t); |
507 | 708 |
573 | 709 if (e->flushed) { |
710 value = ngx_http_get_indexed_variable(e->request, code->index); | |
507 | 711 |
573 | 712 } else { |
713 value = ngx_http_get_flushed_variable(e->request, code->index); | |
714 } | |
715 | |
716 if (value && !value->not_found) { | |
717 return value->len; | |
507 | 718 } |
719 | |
553 | 720 return 0; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
721 } |
479 | 722 |
723 | |
507 | 724 void |
509 | 725 ngx_http_script_copy_var_code(ngx_http_script_engine_t *e) |
479 | 726 { |
2393 | 727 u_char *p; |
507 | 728 ngx_http_variable_value_t *value; |
729 ngx_http_script_var_code_t *code; | |
730 | |
509 | 731 code = (ngx_http_script_var_code_t *) e->ip; |
732 | |
733 e->ip += sizeof(ngx_http_script_var_code_t); | |
734 | |
735 if (!e->skip) { | |
573 | 736 |
737 if (e->flushed) { | |
738 value = ngx_http_get_indexed_variable(e->request, code->index); | |
509 | 739 |
573 | 740 } else { |
741 value = ngx_http_get_flushed_variable(e->request, code->index); | |
742 } | |
743 | |
744 if (value && !value->not_found) { | |
2393 | 745 p = e->pos; |
746 e->pos = ngx_copy(p, value->data, value->len); | |
509 | 747 |
2393 | 748 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
|
749 e->request->connection->log, 0, |
2393 | 750 "http script var: \"%*s\"", e->pos - p, p); |
509 | 751 } |
752 } | |
753 } | |
754 | |
755 | |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
756 static ngx_int_t |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
757 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
|
758 { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
759 uintptr_t *code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
760 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
761 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
|
762 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
763 return NGX_ERROR; |
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 *code = (uintptr_t) ngx_http_script_mark_args_code; |
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 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
|
769 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
770 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
771 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
772 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
773 *code = (uintptr_t) ngx_http_script_start_args_code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
774 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
775 return NGX_OK; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
776 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
777 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
778 |
509 | 779 size_t |
1891
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
780 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
|
781 { |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
782 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
|
783 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
|
784 |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
785 return 1; |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
786 } |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
787 |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
788 |
509 | 789 void |
790 ngx_http_script_start_args_code(ngx_http_script_engine_t *e) | |
791 { | |
792 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
793 "http script args"); | |
577 | 794 |
2225
207827f7bf71
escape a query string characters taken from URI while rewrite
Igor Sysoev <igor@sysoev.ru>
parents:
2133
diff
changeset
|
795 e->is_args = 1; |
509 | 796 e->args = e->pos; |
797 e->ip += sizeof(uintptr_t); | |
798 } | |
799 | |
800 | |
517 | 801 #if (NGX_PCRE) |
802 | |
509 | 803 void |
804 ngx_http_script_regex_start_code(ngx_http_script_engine_t *e) | |
805 { | |
806 size_t len; | |
807 ngx_int_t rc; | |
808 ngx_uint_t n; | |
809 ngx_http_request_t *r; | |
810 ngx_http_script_engine_t le; | |
811 ngx_http_script_len_code_pt lcode; | |
812 ngx_http_script_regex_code_t *code; | |
813 | |
814 code = (ngx_http_script_regex_code_t *) e->ip; | |
815 | |
816 r = e->request; | |
817 | |
818 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
819 "http script regex: \"%V\"", &code->name); | |
820 | |
821 if (code->uri) { | |
515 | 822 e->line = r->uri; |
509 | 823 } else { |
824 e->sp--; | |
573 | 825 e->line.len = e->sp->len; |
826 e->line.data = e->sp->data; | |
509 | 827 } |
507 | 828 |
3325 | 829 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
|
830 |
3325 | 831 if (rc == NGX_DECLINED) { |
2397 | 832 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) { |
509 | 833 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, |
515 | 834 "\"%V\" does not match \"%V\"", |
835 &code->name, &e->line); | |
509 | 836 } |
837 | |
2547
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
838 r->ncaptures = 0; |
515 | 839 |
509 | 840 if (code->test) { |
631 | 841 if (code->negative_test) { |
842 e->sp->len = 1; | |
843 e->sp->data = (u_char *) "1"; | |
844 | |
845 } else { | |
846 e->sp->len = 0; | |
847 e->sp->data = (u_char *) ""; | |
848 } | |
849 | |
509 | 850 e->sp++; |
851 | |
852 e->ip += sizeof(ngx_http_script_regex_code_t); | |
853 return; | |
854 } | |
855 | |
856 e->ip += code->next; | |
857 return; | |
858 } | |
859 | |
3325 | 860 if (rc == NGX_ERROR) { |
509 | 861 e->ip = ngx_http_script_exit; |
862 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
863 return; | |
864 } | |
865 | |
2397 | 866 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) { |
509 | 867 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, |
515 | 868 "\"%V\" matches \"%V\"", &code->name, &e->line); |
509 | 869 } |
870 | |
871 if (code->test) { | |
631 | 872 if (code->negative_test) { |
873 e->sp->len = 0; | |
874 e->sp->data = (u_char *) ""; | |
875 | |
876 } else { | |
877 e->sp->len = 1; | |
878 e->sp->data = (u_char *) "1"; | |
879 } | |
880 | |
509 | 881 e->sp++; |
882 | |
883 e->ip += sizeof(ngx_http_script_regex_code_t); | |
884 return; | |
885 } | |
886 | |
887 if (code->status) { | |
888 e->status = code->status; | |
507 | 889 |
509 | 890 if (!code->redirect) { |
891 e->ip = ngx_http_script_exit; | |
892 return; | |
893 } | |
894 } | |
895 | |
896 if (code->uri) { | |
897 r->internal = 1; | |
898 r->valid_unparsed_uri = 0; | |
899 | |
900 if (code->break_cycle) { | |
901 r->valid_location = 0; | |
527 | 902 r->uri_changed = 0; |
509 | 903 |
904 } else { | |
905 r->uri_changed = 1; | |
906 } | |
907 } | |
908 | |
909 if (code->lengths == NULL) { | |
910 e->buf.len = code->size; | |
911 | |
912 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
|
913 if (r->ncaptures && (r->quoted_uri || r->plus_in_uri)) { |
509 | 914 e->buf.len += 2 * ngx_escape_uri(NULL, r->uri.data, r->uri.len, |
915 NGX_ESCAPE_ARGS); | |
916 } | |
917 } | |
918 | |
3344
1aed55182ea2
fix captures in "rewrite", the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3325
diff
changeset
|
919 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
|
920 e->buf.len += r->captures[n + 1] - r->captures[n]; |
509 | 921 } |
922 | |
923 } else { | |
924 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); | |
925 | |
926 le.ip = code->lengths->elts; | |
679 | 927 le.line = e->line; |
509 | 928 le.request = r; |
679 | 929 le.quote = code->redirect; |
509 | 930 |
1891
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
931 len = 0; |
509 | 932 |
933 while (*(uintptr_t *) le.ip) { | |
934 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
935 len += lcode(&le); | |
936 } | |
937 | |
938 e->buf.len = len; | |
1891
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
939 e->is_args = le.is_args; |
509 | 940 } |
941 | |
515 | 942 if (code->add_args && r->args.len) { |
509 | 943 e->buf.len += r->args.len + 1; |
944 } | |
945 | |
2049 | 946 e->buf.data = ngx_pnalloc(r->pool, e->buf.len); |
509 | 947 if (e->buf.data == NULL) { |
948 e->ip = ngx_http_script_exit; | |
949 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
507 | 950 return; |
951 } | |
952 | |
509 | 953 e->quote = code->redirect; |
954 | |
955 e->pos = e->buf.data; | |
956 | |
957 e->ip += sizeof(ngx_http_script_regex_code_t); | |
958 } | |
959 | |
960 | |
961 void | |
962 ngx_http_script_regex_end_code(ngx_http_script_engine_t *e) | |
963 { | |
577 | 964 u_char *dst, *src; |
509 | 965 ngx_http_request_t *r; |
966 ngx_http_script_regex_end_code_t *code; | |
967 | |
968 code = (ngx_http_script_regex_end_code_t *) e->ip; | |
969 | |
970 r = e->request; | |
971 | |
972 e->quote = 0; | |
973 | |
974 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
975 "http script regex end"); | |
976 | |
977 if (code->redirect) { | |
978 | |
577 | 979 dst = e->buf.data; |
980 src = e->buf.data; | |
981 | |
1593 | 982 ngx_unescape_uri(&dst, &src, e->pos - e->buf.data, |
983 NGX_UNESCAPE_REDIRECT); | |
577 | 984 |
985 if (src < e->pos) { | |
986 dst = ngx_copy(dst, src, e->pos - src); | |
987 } | |
988 | |
989 e->pos = dst; | |
990 | |
991 if (code->add_args && r->args.len) { | |
509 | 992 *e->pos++ = (u_char) (code->args ? '&' : '?'); |
573 | 993 e->pos = ngx_copy(e->pos, r->args.data, r->args.len); |
509 | 994 } |
995 | |
996 e->buf.len = e->pos - e->buf.data; | |
997 | |
2397 | 998 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) { |
509 | 999 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, |
1000 "rewritten redirect: \"%V\"", &e->buf); | |
1001 } | |
1002 | |
1003 r->headers_out.location = ngx_list_push(&r->headers_out.headers); | |
1004 if (r->headers_out.location == NULL) { | |
1005 e->ip = ngx_http_script_exit; | |
1006 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1007 return; | |
1008 } | |
1009 | |
577 | 1010 r->headers_out.location->hash = 1; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3344
diff
changeset
|
1011 ngx_str_set(&r->headers_out.location->key, "Location"); |
509 | 1012 r->headers_out.location->value = e->buf; |
1013 | |
1014 e->ip += sizeof(ngx_http_script_regex_end_code_t); | |
1015 return; | |
1016 } | |
1017 | |
577 | 1018 if (e->args) { |
509 | 1019 e->buf.len = e->args - e->buf.data; |
1020 | |
1021 if (code->add_args && r->args.len) { | |
1022 *e->pos++ = '&'; | |
573 | 1023 e->pos = ngx_copy(e->pos, r->args.data, r->args.len); |
509 | 1024 } |
1025 | |
1026 r->args.len = e->pos - e->args; | |
1027 r->args.data = e->args; | |
1028 | |
1029 e->args = NULL; | |
1030 | |
1031 } else { | |
1032 e->buf.len = e->pos - e->buf.data; | |
673 | 1033 |
1034 if (!code->add_args) { | |
1035 r->args.len = 0; | |
1036 } | |
509 | 1037 } |
1038 | |
2397 | 1039 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) { |
509 | 1040 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, |
1041 "rewritten data: \"%V\", args: \"%V\"", | |
1042 &e->buf, &r->args); | |
1043 } | |
1044 | |
1045 if (code->uri) { | |
1046 r->uri = e->buf; | |
1047 | |
535 | 1048 if (r->uri.len == 0) { |
1049 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1050 "the rewritten URI has a zero length"); | |
1051 e->ip = ngx_http_script_exit; | |
1052 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1053 return; | |
1054 } | |
1055 | |
2979
b941147f2b2e
ngx_http_set_exten() is always successful since 0.3.46
Igor Sysoev <igor@sysoev.ru>
parents:
2911
diff
changeset
|
1056 ngx_http_set_exten(r); |
509 | 1057 } |
1058 | |
1059 e->ip += sizeof(ngx_http_script_regex_end_code_t); | |
1060 } | |
1061 | |
2547
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1062 |
2577
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1063 static ngx_int_t |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1064 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
|
1065 { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1066 ngx_http_script_copy_capture_code_t *code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1067 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1068 code = ngx_http_script_add_code(*sc->lengths, |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1069 sizeof(ngx_http_script_copy_capture_code_t), |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1070 NULL); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1071 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1072 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1073 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1074 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1075 code->code = (ngx_http_script_code_pt) |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1076 ngx_http_script_copy_capture_len_code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1077 code->n = 2 * n; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1078 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1079 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1080 code = ngx_http_script_add_code(*sc->values, |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1081 sizeof(ngx_http_script_copy_capture_code_t), |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1082 &sc->main); |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1083 if (code == NULL) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1084 return NGX_ERROR; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1085 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1086 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1087 code->code = ngx_http_script_copy_capture_code; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1088 code->n = 2 * n; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1089 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1090 if (sc->ncaptures < n) { |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1091 sc->ncaptures = n; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1092 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1093 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1094 return NGX_OK; |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1095 } |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1096 |
2dcbcfc1a8d1
split ngx_http_script_compile()
Igor Sysoev <igor@sysoev.ru>
parents:
2547
diff
changeset
|
1097 |
2547
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1098 size_t |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1099 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
|
1100 { |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1101 int *cap; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1102 u_char *p; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1103 ngx_uint_t n; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1104 ngx_http_request_t *r; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1105 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
|
1106 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1107 r = e->request; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1108 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1109 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
|
1110 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1111 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
|
1112 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1113 n = code->n; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1114 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1115 if (n < r->ncaptures) { |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1116 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1117 cap = r->captures; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1118 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1119 if ((e->is_args || e->quote) |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1120 && (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
|
1121 { |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1122 p = r->captures_data; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1123 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1124 return cap[n + 1] - cap[n] |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1125 + 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
|
1126 NGX_ESCAPE_ARGS); |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1127 } else { |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1128 return cap[n + 1] - cap[n]; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1129 } |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1130 } |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1131 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1132 return 0; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1133 } |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1134 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1135 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1136 void |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1137 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
|
1138 { |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1139 int *cap; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1140 u_char *p, *pos; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1141 ngx_uint_t n; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1142 ngx_http_request_t *r; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1143 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
|
1144 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1145 r = e->request; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1146 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1147 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
|
1148 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1149 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
|
1150 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1151 n = code->n; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1152 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1153 pos = e->pos; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1154 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1155 if (n < r->ncaptures) { |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1156 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1157 cap = r->captures; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1158 p = r->captures_data; |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1159 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1160 if ((e->is_args || e->quote) |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1161 && (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
|
1162 { |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1163 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
|
1164 cap[n + 1] - cap[n], |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1165 NGX_ESCAPE_ARGS); |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1166 } else { |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1167 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
|
1168 } |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1169 } |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1170 |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1171 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
|
1172 "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
|
1173 } |
912ce4113f21
now regex captures are per-request entities
Igor Sysoev <igor@sysoev.ru>
parents:
2498
diff
changeset
|
1174 |
517 | 1175 #endif |
1176 | |
509 | 1177 |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1178 static ngx_int_t |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1179 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
|
1180 { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1181 ngx_http_script_full_name_code_t *code; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1182 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1183 code = ngx_http_script_add_code(*sc->lengths, |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1184 sizeof(ngx_http_script_full_name_code_t), |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1185 NULL); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1186 if (code == NULL) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1187 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1188 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1189 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1190 code->code = (ngx_http_script_code_pt) ngx_http_script_full_name_len_code; |
2758 | 1191 code->conf_prefix = sc->conf_prefix; |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1192 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1193 code = ngx_http_script_add_code(*sc->values, |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1194 sizeof(ngx_http_script_full_name_code_t), |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1195 &sc->main); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1196 if (code == NULL) { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1197 return NGX_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1198 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1199 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1200 code->code = ngx_http_script_full_name_code; |
2758 | 1201 code->conf_prefix = sc->conf_prefix; |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1202 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1203 return NGX_OK; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1204 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1205 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1206 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1207 static size_t |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1208 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
|
1209 { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1210 ngx_http_script_full_name_code_t *code; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1211 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1212 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
|
1213 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1214 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
|
1215 |
2758 | 1216 return code->conf_prefix ? ngx_cycle->conf_prefix.len: |
1217 ngx_cycle->prefix.len; | |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1218 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1219 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1220 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1221 static void |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1222 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
|
1223 { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1224 ngx_http_script_full_name_code_t *code; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1225 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1226 ngx_str_t value; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1227 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1228 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
|
1229 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1230 value.data = e->buf.data; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1231 value.len = e->pos - e->buf.data; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1232 |
2758 | 1233 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, &value, code->conf_prefix) |
2587
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1234 != NGX_OK) |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1235 { |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1236 e->ip = ngx_http_script_exit; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1237 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1238 return; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1239 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1240 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1241 e->buf = value; |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1242 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1243 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
|
1244 "http script fullname: \"%V\"", &value); |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1245 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1246 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
|
1247 } |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1248 |
8afc4df77ee8
ngx_http_script_flush_complex_value()
Igor Sysoev <igor@sysoev.ru>
parents:
2577
diff
changeset
|
1249 |
509 | 1250 void |
1251 ngx_http_script_return_code(ngx_http_script_engine_t *e) | |
577 | 1252 { |
509 | 1253 ngx_http_script_return_code_t *code; |
577 | 1254 |
509 | 1255 code = (ngx_http_script_return_code_t *) e->ip; |
1256 | |
3633 | 1257 if (code->status < NGX_HTTP_BAD_REQUEST |
1258 || code->text.value.len | |
1259 || code->text.lengths) | |
1260 { | |
1261 e->status = ngx_http_send_response(e->request, code->status, NULL, | |
1262 &code->text); | |
1263 } else { | |
1264 e->status = code->status; | |
653 | 1265 } |
1266 | |
3633 | 1267 e->ip = ngx_http_script_exit; |
479 | 1268 } |
509 | 1269 |
1270 | |
1271 void | |
527 | 1272 ngx_http_script_break_code(ngx_http_script_engine_t *e) |
1273 { | |
1274 e->request->uri_changed = 0; | |
1275 | |
1276 e->ip = ngx_http_script_exit; | |
1277 } | |
1278 | |
1279 | |
1280 void | |
509 | 1281 ngx_http_script_if_code(ngx_http_script_engine_t *e) |
1282 { | |
1283 ngx_http_script_if_code_t *code; | |
1284 | |
1285 code = (ngx_http_script_if_code_t *) e->ip; | |
1286 | |
1287 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1288 "http script if"); | |
1289 | |
1290 e->sp--; | |
1291 | |
573 | 1292 if (e->sp->len && e->sp->data[0] != '0') { |
509 | 1293 if (code->loc_conf) { |
1294 e->request->loc_conf = code->loc_conf; | |
535 | 1295 ngx_http_update_location_config(e->request); |
509 | 1296 } |
1297 | |
1298 e->ip += sizeof(ngx_http_script_if_code_t); | |
1299 return; | |
1300 } | |
1301 | |
1302 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
577 | 1303 "http script if: false"); |
509 | 1304 |
1305 e->ip += code->next; | |
1306 } | |
1307 | |
1308 | |
1309 void | |
577 | 1310 ngx_http_script_equal_code(ngx_http_script_engine_t *e) |
1311 { | |
1312 ngx_http_variable_value_t *val, *res; | |
1313 | |
1314 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1315 "http script equal"); | |
1316 | |
1317 e->sp--; | |
1318 val = e->sp; | |
1319 res = e->sp - 1; | |
1320 | |
1321 e->ip += sizeof(uintptr_t); | |
1322 | |
2393 | 1323 if (val->len == res->len |
1324 && ngx_strncmp(val->data, res->data, res->len) == 0) | |
577 | 1325 { |
1326 *res = ngx_http_variable_true_value; | |
1327 return; | |
1328 } | |
1329 | |
1330 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1331 "http script equal: no"); | |
1332 | |
1333 *res = ngx_http_variable_null_value; | |
1334 } | |
1335 | |
1336 | |
1337 void | |
1338 ngx_http_script_not_equal_code(ngx_http_script_engine_t *e) | |
1339 { | |
1340 ngx_http_variable_value_t *val, *res; | |
1341 | |
1342 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1343 "http script not equal"); | |
1344 | |
1345 e->sp--; | |
1346 val = e->sp; | |
1347 res = e->sp - 1; | |
1348 | |
1349 e->ip += sizeof(uintptr_t); | |
1350 | |
2393 | 1351 if (val->len == res->len |
1352 && ngx_strncmp(val->data, res->data, res->len) == 0) | |
577 | 1353 { |
1354 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1355 "http script not equal: no"); | |
1356 | |
1357 *res = ngx_http_variable_null_value; | |
1358 return; | |
1359 } | |
1360 | |
1361 *res = ngx_http_variable_true_value; | |
1362 } | |
1363 | |
1364 | |
1365 void | |
631 | 1366 ngx_http_script_file_code(ngx_http_script_engine_t *e) |
1367 { | |
1454 | 1368 ngx_str_t path; |
1369 ngx_http_request_t *r; | |
1370 ngx_open_file_info_t of; | |
1371 ngx_http_core_loc_conf_t *clcf; | |
631 | 1372 ngx_http_variable_value_t *value; |
1373 ngx_http_script_file_code_t *code; | |
1374 | |
1375 value = e->sp - 1; | |
1376 | |
1377 code = (ngx_http_script_file_code_t *) e->ip; | |
1378 e->ip += sizeof(ngx_http_script_file_code_t); | |
1379 | |
1454 | 1380 path.len = value->len - 1; |
1381 path.data = value->data; | |
1382 | |
1383 r = e->request; | |
1384 | |
1385 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1386 "http script file op %p \"%V\"", code->op, &path); | |
1387 | |
1388 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
631 | 1389 |
2068
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
1390 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
|
1391 |
3178 | 1392 of.read_ahead = clcf->read_ahead; |
2129 | 1393 of.directio = clcf->directio; |
1767
c42431762903
open_file_cache_retest > open_file_cache_valid
Igor Sysoev <igor@sysoev.ru>
parents:
1593
diff
changeset
|
1394 of.valid = clcf->open_file_cache_valid; |
1772 | 1395 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
|
1396 of.test_only = 1; |
1454 | 1397 of.errors = clcf->open_file_cache_errors; |
1457 | 1398 of.events = clcf->open_file_cache_events; |
631 | 1399 |
1454 | 1400 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) |
1799 | 1401 != NGX_OK) |
1454 | 1402 { |
3160
a7637c2c1157
low ENAMETOOLONG logging level
Igor Sysoev <igor@sysoev.ru>
parents:
2979
diff
changeset
|
1403 if (of.err != NGX_ENOENT |
a7637c2c1157
low ENAMETOOLONG logging level
Igor Sysoev <igor@sysoev.ru>
parents:
2979
diff
changeset
|
1404 && of.err != NGX_ENOTDIR |
a7637c2c1157
low ENAMETOOLONG logging level
Igor Sysoev <igor@sysoev.ru>
parents:
2979
diff
changeset
|
1405 && of.err != NGX_ENAMETOOLONG) |
a7637c2c1157
low ENAMETOOLONG logging level
Igor Sysoev <igor@sysoev.ru>
parents:
2979
diff
changeset
|
1406 { |
1454 | 1407 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
|
1408 "%s \"%s\" failed", of.failed, value->data); |
631 | 1409 } |
1410 | |
1411 switch (code->op) { | |
671 | 1412 |
631 | 1413 case ngx_http_script_file_plain: |
669 | 1414 case ngx_http_script_file_dir: |
1415 case ngx_http_script_file_exists: | |
1416 case ngx_http_script_file_exec: | |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1417 goto false_value; |
671 | 1418 |
631 | 1419 case ngx_http_script_file_not_plain: |
669 | 1420 case ngx_http_script_file_not_dir: |
671 | 1421 case ngx_http_script_file_not_exists: |
669 | 1422 case ngx_http_script_file_not_exec: |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1423 goto true_value; |
631 | 1424 } |
1425 | |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1426 goto false_value; |
631 | 1427 } |
1428 | |
1429 switch (code->op) { | |
1430 case ngx_http_script_file_plain: | |
1454 | 1431 if (of.is_file) { |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1432 goto true_value; |
631 | 1433 } |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1434 goto false_value; |
631 | 1435 |
1436 case ngx_http_script_file_not_plain: | |
1454 | 1437 if (of.is_file) { |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1438 goto false_value; |
631 | 1439 } |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1440 goto true_value; |
669 | 1441 |
1442 case ngx_http_script_file_dir: | |
1454 | 1443 if (of.is_dir) { |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1444 goto true_value; |
669 | 1445 } |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1446 goto false_value; |
669 | 1447 |
1448 case ngx_http_script_file_not_dir: | |
1454 | 1449 if (of.is_dir) { |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1450 goto false_value; |
669 | 1451 } |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1452 goto true_value; |
669 | 1453 |
1454 case ngx_http_script_file_exists: | |
1454 | 1455 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
|
1456 goto true_value; |
669 | 1457 } |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1458 goto false_value; |
669 | 1459 |
1460 case ngx_http_script_file_not_exists: | |
1454 | 1461 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
|
1462 goto false_value; |
669 | 1463 } |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1464 goto true_value; |
669 | 1465 |
1466 case ngx_http_script_file_exec: | |
1454 | 1467 if (of.is_exec) { |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1468 goto true_value; |
669 | 1469 } |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1470 goto false_value; |
669 | 1471 |
1472 case ngx_http_script_file_not_exec: | |
1454 | 1473 if (of.is_exec) { |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1474 goto false_value; |
669 | 1475 } |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1476 goto true_value; |
631 | 1477 } |
1478 | |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1479 false_value: |
631 | 1480 |
1454 | 1481 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
631 | 1482 "http script file op false"); |
1483 | |
1484 *value = ngx_http_variable_null_value; | |
1485 return; | |
1486 | |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
1487 true_value: |
631 | 1488 |
1489 *value = ngx_http_variable_true_value; | |
1490 return; | |
1491 } | |
1492 | |
1493 | |
1494 void | |
515 | 1495 ngx_http_script_complex_value_code(ngx_http_script_engine_t *e) |
1496 { | |
1497 size_t len; | |
1498 ngx_http_script_engine_t le; | |
1499 ngx_http_script_len_code_pt lcode; | |
1500 ngx_http_script_complex_value_code_t *code; | |
1501 | |
1502 code = (ngx_http_script_complex_value_code_t *) e->ip; | |
1503 | |
1504 e->ip += sizeof(ngx_http_script_complex_value_code_t); | |
1505 | |
1506 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1507 "http script complex value"); | |
1508 | |
1509 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); | |
1510 | |
1511 le.ip = code->lengths->elts; | |
655 | 1512 le.line = e->line; |
515 | 1513 le.request = e->request; |
655 | 1514 le.quote = e->quote; |
515 | 1515 |
1516 for (len = 0; *(uintptr_t *) le.ip; len += lcode(&le)) { | |
1517 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
1518 } | |
1519 | |
1520 e->buf.len = len; | |
2049 | 1521 e->buf.data = ngx_pnalloc(e->request->pool, len); |
515 | 1522 if (e->buf.data == NULL) { |
1523 e->ip = ngx_http_script_exit; | |
1524 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1525 return; | |
1526 } | |
1527 | |
1528 e->pos = e->buf.data; | |
1529 | |
577 | 1530 e->sp->len = e->buf.len; |
573 | 1531 e->sp->data = e->buf.data; |
515 | 1532 e->sp++; |
1533 } | |
1534 | |
1535 | |
1536 void | |
509 | 1537 ngx_http_script_value_code(ngx_http_script_engine_t *e) |
1538 { | |
1539 ngx_http_script_value_code_t *code; | |
1540 | |
1541 code = (ngx_http_script_value_code_t *) e->ip; | |
1542 | |
1543 e->ip += sizeof(ngx_http_script_value_code_t); | |
1544 | |
573 | 1545 e->sp->len = code->text_len; |
1546 e->sp->data = (u_char *) code->text_data; | |
577 | 1547 |
1548 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1561 | 1549 "http script value: \"%v\"", e->sp); |
577 | 1550 |
509 | 1551 e->sp++; |
1552 } | |
1553 | |
1554 | |
1555 void | |
1556 ngx_http_script_set_var_code(ngx_http_script_engine_t *e) | |
1557 { | |
1558 ngx_http_request_t *r; | |
1559 ngx_http_script_var_code_t *code; | |
1560 | |
1561 code = (ngx_http_script_var_code_t *) e->ip; | |
1562 | |
1563 e->ip += sizeof(ngx_http_script_var_code_t); | |
1564 | |
1565 r = e->request; | |
1566 | |
1567 e->sp--; | |
1568 | |
573 | 1569 r->variables[code->index].len = e->sp->len; |
1570 r->variables[code->index].valid = 1; | |
1565 | 1571 r->variables[code->index].no_cacheable = 0; |
573 | 1572 r->variables[code->index].not_found = 0; |
1573 r->variables[code->index].data = e->sp->data; | |
2393 | 1574 |
1575 #if (NGX_DEBUG) | |
1576 { | |
1577 ngx_http_variable_t *v; | |
1578 ngx_http_core_main_conf_t *cmcf; | |
1579 | |
1580 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
1581 | |
1582 v = cmcf->variables.elts; | |
1583 | |
1584 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1585 "http script set $%V", &v[code->index].name); | |
1586 } | |
1587 #endif | |
509 | 1588 } |
1589 | |
1590 | |
1591 void | |
637 | 1592 ngx_http_script_var_set_handler_code(ngx_http_script_engine_t *e) |
1593 { | |
1594 ngx_http_script_var_handler_code_t *code; | |
1595 | |
1596 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1597 "http script set var handler"); | |
1598 | |
1599 code = (ngx_http_script_var_handler_code_t *) e->ip; | |
1600 | |
1601 e->ip += sizeof(ngx_http_script_var_handler_code_t); | |
1602 | |
1603 e->sp--; | |
1604 | |
1605 code->handler(e->request, e->sp, code->data); | |
1606 } | |
1607 | |
1608 | |
1609 void | |
509 | 1610 ngx_http_script_var_code(ngx_http_script_engine_t *e) |
1611 { | |
1612 ngx_http_variable_value_t *value; | |
1613 ngx_http_script_var_code_t *code; | |
1614 | |
1615 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1616 "http script var"); | |
1617 | |
1618 code = (ngx_http_script_var_code_t *) e->ip; | |
1619 | |
1620 e->ip += sizeof(ngx_http_script_var_code_t); | |
1621 | |
573 | 1622 value = ngx_http_get_flushed_variable(e->request, code->index); |
509 | 1623 |
573 | 1624 if (value && !value->not_found) { |
1625 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
|
1626 "http script var: \"%v\"", value); |
573 | 1627 |
553 | 1628 *e->sp = *value; |
509 | 1629 e->sp++; |
1630 | |
1631 return; | |
1632 } | |
1633 | |
577 | 1634 *e->sp = ngx_http_variable_null_value; |
509 | 1635 e->sp++; |
1636 } | |
1637 | |
1638 | |
1639 void | |
1640 ngx_http_script_nop_code(ngx_http_script_engine_t *e) | |
1641 { | |
1642 e->ip += sizeof(uintptr_t); | |
1643 } |