Mercurial > hg > nginx-quic
annotate src/http/ngx_http_script.c @ 2052:b4085596a7e6
fix "proxy_pass https://..." broken in r1427
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 20 Jun 2008 14:42:54 +0000 |
parents | 2a92804f4109 |
children | 67a29af877ed |
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 |
509 | 12 #define ngx_http_script_exit (u_char *) &ngx_http_script_exit_code |
13 | |
14 static uintptr_t ngx_http_script_exit_code = (uintptr_t) NULL; | |
15 | |
16 | |
17 ngx_uint_t | |
18 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
|
19 { |
509 | 20 ngx_uint_t i, n; |
507 | 21 |
509 | 22 for (n = 0, i = 0; i < value->len; i++) { |
23 if (value->data[i] == '$') { | |
24 n++; | |
25 } | |
507 | 26 } |
27 | |
509 | 28 return n; |
29 } | |
30 | |
31 | |
32 ngx_int_t | |
33 ngx_http_script_compile(ngx_http_script_compile_t *sc) | |
34 { | |
35 u_char ch; | |
36 size_t size; | |
573 | 37 ngx_int_t index, *p; |
509 | 38 ngx_str_t name; |
39 uintptr_t *code; | |
40 ngx_uint_t i, n, bracket; | |
41 ngx_http_script_var_code_t *var_code; | |
42 ngx_http_script_copy_code_t *copy; | |
43 ngx_http_script_copy_capture_code_t *copy_capture; | |
44 | |
573 | 45 if (sc->flushes && *sc->flushes == NULL) { |
46 n = sc->variables ? sc->variables : 1; | |
47 *sc->flushes = ngx_array_create(sc->cf->pool, n, sizeof(ngx_uint_t)); | |
48 if (*sc->flushes == NULL) { | |
49 return NGX_ERROR; | |
50 } | |
51 } | |
52 | |
53 | |
509 | 54 if (*sc->lengths == NULL) { |
55 n = sc->variables * (2 * sizeof(ngx_http_script_copy_code_t) | |
56 + sizeof(ngx_http_script_var_code_t)) | |
57 + sizeof(uintptr_t); | |
58 | |
59 *sc->lengths = ngx_array_create(sc->cf->pool, n, 1); | |
60 if (*sc->lengths == NULL) { | |
61 return NGX_ERROR; | |
62 } | |
63 } | |
64 | |
65 | |
66 if (*sc->values == NULL) { | |
67 n = (sc->variables * (2 * sizeof(ngx_http_script_copy_code_t) | |
68 + sizeof(ngx_http_script_var_code_t)) | |
69 + sizeof(uintptr_t) | |
70 + sc->source->len | |
71 + sizeof(uintptr_t) - 1) | |
72 & ~(sizeof(uintptr_t) - 1); | |
73 | |
74 *sc->values = ngx_array_create(sc->cf->pool, n, 1); | |
75 if (*sc->values == NULL) { | |
507 | 76 return NGX_ERROR; |
77 } | |
78 } | |
79 | |
509 | 80 sc->variables = 0; |
81 | |
82 for (i = 0; i < sc->source->len; /* void */ ) { | |
83 | |
84 name.len = 0; | |
85 | |
86 if (sc->source->data[i] == '$') { | |
87 | |
88 if (++i == sc->source->len) { | |
89 goto invalid_variable; | |
90 } | |
91 | |
92 if (sc->source->data[i] >= '1' && sc->source->data[i] <= '9') { | |
93 | |
641 | 94 n = sc->source->data[i] - '0'; |
95 | |
96 if (sc->captures_mask & (1 << n)) { | |
97 sc->dup_capture = 1; | |
98 } | |
99 | |
100 sc->captures_mask |= 1 << n; | |
101 | |
509 | 102 copy_capture = ngx_http_script_add_code(*sc->lengths, |
103 sizeof(ngx_http_script_copy_capture_code_t), | |
104 NULL); | |
105 if (copy_capture == NULL) { | |
106 return NGX_ERROR; | |
107 } | |
108 | |
109 copy_capture->code = (ngx_http_script_code_pt) | |
110 ngx_http_script_copy_capture_len_code; | |
641 | 111 copy_capture->n = 2 * n; |
112 | |
509 | 113 |
114 copy_capture = ngx_http_script_add_code(*sc->values, | |
115 sizeof(ngx_http_script_copy_capture_code_t), | |
116 &sc->main); | |
117 if (copy_capture == NULL) { | |
118 return NGX_ERROR; | |
119 } | |
120 | |
121 copy_capture->code = ngx_http_script_copy_capture_code; | |
641 | 122 copy_capture->n = 2 * n; |
509 | 123 |
641 | 124 if (sc->ncaptures < n) { |
125 sc->ncaptures = n; | |
509 | 126 } |
127 | |
128 i++; | |
129 | |
130 continue; | |
131 } | |
132 | |
133 if (sc->source->data[i] == '{') { | |
134 bracket = 1; | |
135 | |
136 if (++i == sc->source->len) { | |
137 goto invalid_variable; | |
138 } | |
139 | |
140 name.data = &sc->source->data[i]; | |
141 | |
142 } else { | |
143 bracket = 0; | |
144 name.data = &sc->source->data[i]; | |
145 } | |
146 | |
147 for ( /* void */ ; i < sc->source->len; i++, name.len++) { | |
148 ch = sc->source->data[i]; | |
507 | 149 |
509 | 150 if (ch == '}' && bracket) { |
151 i++; | |
152 bracket = 0; | |
153 break; | |
154 } | |
155 | |
156 if ((ch >= 'A' && ch <= 'Z') | |
157 || (ch >= 'a' && ch <= 'z') | |
158 || (ch >= '0' && ch <= '9') | |
159 || ch == '_') | |
160 { | |
161 continue; | |
162 } | |
163 | |
164 break; | |
165 } | |
166 | |
167 if (bracket) { | |
168 ngx_conf_log_error(NGX_LOG_EMERG, sc->cf, 0, | |
169 "the closing bracket in \"%V\" " | |
170 "variable is missing", &name); | |
507 | 171 return NGX_ERROR; |
172 } | |
173 | |
509 | 174 if (name.len == 0) { |
175 goto invalid_variable; | |
176 } | |
507 | 177 |
509 | 178 sc->variables++; |
507 | 179 |
509 | 180 index = ngx_http_get_variable_index(sc->cf, &name); |
181 | |
182 if (index == NGX_ERROR) { | |
507 | 183 return NGX_ERROR; |
184 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
185 |
573 | 186 if (sc->flushes) { |
187 p = ngx_array_push(*sc->flushes); | |
188 if (p == NULL) { | |
189 return NGX_ERROR; | |
190 } | |
191 | |
192 *p = index; | |
193 } | |
194 | |
509 | 195 var_code = ngx_http_script_add_code(*sc->lengths, |
196 sizeof(ngx_http_script_var_code_t), | |
197 NULL); | |
507 | 198 if (var_code == NULL) { |
199 return NGX_ERROR; | |
200 } | |
201 | |
202 var_code->code = (ngx_http_script_code_pt) | |
509 | 203 ngx_http_script_copy_var_len_code; |
204 var_code->index = (uintptr_t) index; | |
507 | 205 |
206 | |
509 | 207 var_code = ngx_http_script_add_code(*sc->values, |
208 sizeof(ngx_http_script_var_code_t), | |
209 &sc->main); | |
507 | 210 if (var_code == NULL) { |
211 return NGX_ERROR; | |
212 } | |
213 | |
509 | 214 var_code->code = ngx_http_script_copy_var_code; |
215 var_code->index = (uintptr_t) index; | |
216 | |
217 continue; | |
218 } | |
507 | 219 |
509 | 220 if (sc->source->data[i] == '?' && sc->compile_args) { |
221 sc->args = 1; | |
222 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
|
223 |
1891
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
224 code = ngx_http_script_add_code(*sc->lengths, sizeof(uintptr_t), |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
225 NULL); |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
226 if (code == NULL) { |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
227 return NGX_ERROR; |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
228 } |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
229 |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
230 *code = (uintptr_t) ngx_http_script_mark_args_code; |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
231 |
509 | 232 code = ngx_http_script_add_code(*sc->values, sizeof(uintptr_t), |
233 &sc->main); | |
234 if (code == NULL) { | |
507 | 235 return NGX_ERROR; |
236 } | |
237 | |
509 | 238 *code = (uintptr_t) ngx_http_script_start_args_code; |
239 | |
240 i++; | |
241 | |
507 | 242 continue; |
243 } | |
244 | |
509 | 245 name.data = &sc->source->data[i]; |
246 | |
247 while (i < sc->source->len | |
248 && sc->source->data[i] != '$' | |
249 && !(sc->source->data[i] == '?' && sc->compile_args)) | |
250 { | |
251 i++; | |
252 name.len++; | |
253 } | |
254 | |
255 sc->size += name.len; | |
256 | |
257 copy = ngx_http_script_add_code(*sc->lengths, | |
258 sizeof(ngx_http_script_copy_code_t), | |
259 NULL); | |
260 if (copy == NULL) { | |
507 | 261 return NGX_ERROR; |
262 } | |
509 | 263 |
264 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; | |
265 copy->len = name.len; | |
266 | |
267 size = (sizeof(ngx_http_script_copy_code_t) + name.len | |
268 + sizeof(uintptr_t) - 1) | |
269 & ~(sizeof(uintptr_t) - 1); | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
270 |
509 | 271 copy = ngx_http_script_add_code(*sc->values, size, &sc->main); |
272 if (copy == NULL) { | |
273 return NGX_ERROR; | |
274 } | |
275 | |
276 copy->code = ngx_http_script_copy_code; | |
277 copy->len = name.len; | |
278 | |
279 ngx_memcpy((u_char *) copy + sizeof(ngx_http_script_copy_code_t), | |
280 name.data, name.len); | |
507 | 281 } |
282 | |
509 | 283 if (sc->complete_lengths) { |
284 code = ngx_http_script_add_code(*sc->lengths, sizeof(uintptr_t), NULL); | |
285 if (code == NULL) { | |
286 return NGX_ERROR; | |
287 } | |
507 | 288 |
509 | 289 *code = (uintptr_t) NULL; |
507 | 290 } |
291 | |
509 | 292 if (sc->complete_values) { |
293 code = ngx_http_script_add_code(*sc->values, sizeof(uintptr_t), | |
294 &sc->main); | |
295 if (code == NULL) { | |
296 return NGX_ERROR; | |
297 } | |
298 | |
299 *code = (uintptr_t) NULL; | |
300 } | |
507 | 301 |
302 return NGX_OK; | |
509 | 303 |
304 invalid_variable: | |
305 | |
306 ngx_conf_log_error(NGX_LOG_EMERG, sc->cf, 0, "invalid variable name"); | |
307 | |
308 return NGX_ERROR; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
309 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
310 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
311 |
623 | 312 u_char * |
313 ngx_http_script_run(ngx_http_request_t *r, ngx_str_t *value, | |
314 void *code_lengths, size_t len, void *code_values) | |
315 { | |
1152
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
316 ngx_uint_t i; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
317 ngx_http_script_code_pt code; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
318 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
|
319 ngx_http_script_engine_t e; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
320 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
|
321 |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
322 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
|
323 |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
324 for (i = 0; i < cmcf->variables.nelts; i++) { |
1565 | 325 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
|
326 r->variables[i].valid = 0; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
327 r->variables[i].not_found = 0; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
328 } |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
329 } |
623 | 330 |
331 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); | |
332 | |
333 e.ip = code_lengths; | |
334 e.request = r; | |
335 e.flushed = 1; | |
336 | |
337 while (*(uintptr_t *) e.ip) { | |
338 lcode = *(ngx_http_script_len_code_pt *) e.ip; | |
339 len += lcode(&e); | |
340 } | |
341 | |
342 | |
343 value->len = len; | |
2049 | 344 value->data = ngx_pnalloc(r->pool, len); |
623 | 345 if (value->data == NULL) { |
346 return NULL; | |
347 } | |
348 | |
349 e.ip = code_values; | |
350 e.pos = value->data; | |
351 | |
352 while (*(uintptr_t *) e.ip) { | |
353 code = *(ngx_http_script_code_pt *) e.ip; | |
354 code((ngx_http_script_engine_t *) &e); | |
355 } | |
356 | |
357 return e.pos; | |
358 } | |
359 | |
360 | |
573 | 361 void |
1565 | 362 ngx_http_script_flush_no_cacheable_variables(ngx_http_request_t *r, |
573 | 363 ngx_array_t *indices) |
364 { | |
365 ngx_uint_t n, *index; | |
366 | |
367 if (indices) { | |
368 index = indices->elts; | |
369 for (n = 0; n < indices->nelts; n++) { | |
1565 | 370 if (r->variables[index[n]].no_cacheable) { |
573 | 371 r->variables[index[n]].valid = 0; |
372 r->variables[index[n]].not_found = 0; | |
373 } | |
374 } | |
375 } | |
376 } | |
377 | |
378 | |
509 | 379 void * |
507 | 380 ngx_http_script_start_code(ngx_pool_t *pool, ngx_array_t **codes, size_t size) |
479 | 381 { |
507 | 382 if (*codes == NULL) { |
383 *codes = ngx_array_create(pool, 256, 1); | |
384 if (*codes == NULL) { | |
385 return NULL; | |
386 } | |
387 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
388 |
507 | 389 return ngx_array_push_n(*codes, size); |
390 } | |
391 | |
509 | 392 |
393 void * | |
394 ngx_http_script_add_code(ngx_array_t *codes, size_t size, void *code) | |
395 { | |
396 u_char *elts, **p; | |
397 void *new; | |
398 | |
399 elts = codes->elts; | |
400 | |
401 new = ngx_array_push_n(codes, size); | |
402 if (new == NULL) { | |
403 return NGX_CONF_ERROR; | |
404 } | |
405 | |
406 if (code) { | |
407 if (elts != codes->elts) { | |
408 p = code; | |
409 *p += (u_char *) codes->elts - elts; | |
410 } | |
411 } | |
412 | |
413 return new; | |
414 } | |
507 | 415 |
479 | 416 |
507 | 417 size_t |
509 | 418 ngx_http_script_copy_len_code(ngx_http_script_engine_t *e) |
507 | 419 { |
420 ngx_http_script_copy_code_t *code; | |
479 | 421 |
509 | 422 code = (ngx_http_script_copy_code_t *) e->ip; |
507 | 423 |
509 | 424 e->ip += sizeof(ngx_http_script_copy_code_t); |
507 | 425 |
426 return code->len; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
427 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
428 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
429 |
507 | 430 void |
509 | 431 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
|
432 { |
507 | 433 ngx_http_script_copy_code_t *code; |
434 | |
509 | 435 code = (ngx_http_script_copy_code_t *) e->ip; |
436 | |
437 if (!e->skip) { | |
573 | 438 e->pos = ngx_copy(e->pos, e->ip + sizeof(ngx_http_script_copy_code_t), |
439 code->len); | |
509 | 440 } |
507 | 441 |
509 | 442 e->ip += sizeof(ngx_http_script_copy_code_t) |
443 + ((code->len + sizeof(uintptr_t) - 1) & ~(sizeof(uintptr_t) - 1)); | |
507 | 444 |
845
eb5cf273e5d2
debug log should not be under rewrite_log control
Igor Sysoev <igor@sysoev.ru>
parents:
730
diff
changeset
|
445 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, |
eb5cf273e5d2
debug log should not be under rewrite_log control
Igor Sysoev <igor@sysoev.ru>
parents:
730
diff
changeset
|
446 "http script copy: \"%V\"", &e->buf); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
447 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
448 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
449 |
507 | 450 size_t |
509 | 451 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
|
452 { |
507 | 453 ngx_http_variable_value_t *value; |
454 ngx_http_script_var_code_t *code; | |
455 | |
509 | 456 code = (ngx_http_script_var_code_t *) e->ip; |
507 | 457 |
509 | 458 e->ip += sizeof(ngx_http_script_var_code_t); |
507 | 459 |
573 | 460 if (e->flushed) { |
461 value = ngx_http_get_indexed_variable(e->request, code->index); | |
507 | 462 |
573 | 463 } else { |
464 value = ngx_http_get_flushed_variable(e->request, code->index); | |
465 } | |
466 | |
467 if (value && !value->not_found) { | |
468 return value->len; | |
507 | 469 } |
470 | |
553 | 471 return 0; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
472 } |
479 | 473 |
474 | |
507 | 475 void |
509 | 476 ngx_http_script_copy_var_code(ngx_http_script_engine_t *e) |
479 | 477 { |
507 | 478 ngx_http_variable_value_t *value; |
479 ngx_http_script_var_code_t *code; | |
480 | |
509 | 481 code = (ngx_http_script_var_code_t *) e->ip; |
482 | |
483 e->ip += sizeof(ngx_http_script_var_code_t); | |
484 | |
485 if (!e->skip) { | |
573 | 486 |
487 if (e->flushed) { | |
488 value = ngx_http_get_indexed_variable(e->request, code->index); | |
509 | 489 |
573 | 490 } else { |
491 value = ngx_http_get_flushed_variable(e->request, code->index); | |
492 } | |
493 | |
494 if (value && !value->not_found) { | |
495 e->pos = ngx_copy(e->pos, value->data, value->len); | |
509 | 496 |
845
eb5cf273e5d2
debug log should not be under rewrite_log control
Igor Sysoev <igor@sysoev.ru>
parents:
730
diff
changeset
|
497 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, |
eb5cf273e5d2
debug log should not be under rewrite_log control
Igor Sysoev <igor@sysoev.ru>
parents:
730
diff
changeset
|
498 e->request->connection->log, 0, |
eb5cf273e5d2
debug log should not be under rewrite_log control
Igor Sysoev <igor@sysoev.ru>
parents:
730
diff
changeset
|
499 "http script var: \"%V\"", &e->buf); |
509 | 500 } |
501 } | |
502 } | |
503 | |
504 | |
505 size_t | |
506 ngx_http_script_copy_capture_len_code(ngx_http_script_engine_t *e) | |
507 { | |
508 ngx_http_script_copy_capture_code_t *code; | |
509 | |
510 code = (ngx_http_script_copy_capture_code_t *) e->ip; | |
511 | |
512 e->ip += sizeof(ngx_http_script_copy_capture_code_t); | |
513 | |
515 | 514 if (code->n < e->ncaptures) { |
1891
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
515 if ((e->is_args || e->quote) |
515 | 516 && (e->request->quoted_uri || e->request->plus_in_uri)) |
517 { | |
518 return e->captures[code->n + 1] - e->captures[code->n] | |
655 | 519 + 2 * ngx_escape_uri(NULL, |
515 | 520 &e->line.data[e->captures[code->n]], |
509 | 521 e->captures[code->n + 1] - e->captures[code->n], |
522 NGX_ESCAPE_ARGS); | |
515 | 523 } else { |
524 return e->captures[code->n + 1] - e->captures[code->n]; | |
525 } | |
509 | 526 } |
515 | 527 |
528 return 0; | |
509 | 529 } |
530 | |
531 | |
532 void | |
533 ngx_http_script_copy_capture_code(ngx_http_script_engine_t *e) | |
534 { | |
535 ngx_http_script_copy_capture_code_t *code; | |
536 | |
537 code = (ngx_http_script_copy_capture_code_t *) e->ip; | |
538 | |
539 e->ip += sizeof(ngx_http_script_copy_capture_code_t); | |
507 | 540 |
515 | 541 if (code->n < e->ncaptures) { |
1891
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
542 if ((e->is_args || e->quote) |
515 | 543 && (e->request->quoted_uri || e->request->plus_in_uri)) |
544 { | |
545 e->pos = (u_char *) ngx_escape_uri(e->pos, | |
546 &e->line.data[e->captures[code->n]], | |
509 | 547 e->captures[code->n + 1] - e->captures[code->n], |
548 NGX_ESCAPE_ARGS); | |
515 | 549 } else { |
573 | 550 e->pos = ngx_copy(e->pos, |
551 &e->line.data[e->captures[code->n]], | |
552 e->captures[code->n + 1] - e->captures[code->n]); | |
515 | 553 } |
509 | 554 } |
555 | |
556 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
557 "http script capture: \"%V\"", &e->buf); | |
558 } | |
559 | |
560 | |
1891
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
561 size_t |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
562 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
|
563 { |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
564 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
|
565 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
|
566 |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
567 return 1; |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
568 } |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
569 |
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
570 |
509 | 571 void |
572 ngx_http_script_start_args_code(ngx_http_script_engine_t *e) | |
573 { | |
574 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
575 "http script args"); | |
577 | 576 |
509 | 577 e->args = e->pos; |
578 e->ip += sizeof(uintptr_t); | |
579 } | |
580 | |
581 | |
517 | 582 |
583 #if (NGX_PCRE) | |
584 | |
509 | 585 void |
586 ngx_http_script_regex_start_code(ngx_http_script_engine_t *e) | |
587 { | |
588 size_t len; | |
589 ngx_int_t rc; | |
590 ngx_uint_t n; | |
591 ngx_http_request_t *r; | |
592 ngx_http_script_engine_t le; | |
593 ngx_http_script_len_code_pt lcode; | |
594 ngx_http_script_regex_code_t *code; | |
595 | |
596 code = (ngx_http_script_regex_code_t *) e->ip; | |
597 | |
598 r = e->request; | |
599 | |
600 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
601 "http script regex: \"%V\"", &code->name); | |
602 | |
603 if (code->uri) { | |
515 | 604 e->line = r->uri; |
509 | 605 } else { |
606 e->sp--; | |
573 | 607 e->line.len = e->sp->len; |
608 e->line.data = e->sp->data; | |
509 | 609 } |
507 | 610 |
515 | 611 rc = ngx_regex_exec(code->regex, &e->line, e->captures, code->ncaptures); |
509 | 612 |
613 if (rc == NGX_REGEX_NO_MATCHED) { | |
614 if (e->log) { | |
615 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | |
515 | 616 "\"%V\" does not match \"%V\"", |
617 &code->name, &e->line); | |
509 | 618 } |
619 | |
515 | 620 e->ncaptures = 0; |
621 | |
509 | 622 if (code->test) { |
631 | 623 if (code->negative_test) { |
624 e->sp->len = 1; | |
625 e->sp->data = (u_char *) "1"; | |
626 | |
627 } else { | |
628 e->sp->len = 0; | |
629 e->sp->data = (u_char *) ""; | |
630 } | |
631 | |
509 | 632 e->sp++; |
633 | |
634 e->ip += sizeof(ngx_http_script_regex_code_t); | |
635 return; | |
636 } | |
637 | |
638 e->ip += code->next; | |
639 return; | |
640 } | |
641 | |
642 if (rc < 0) { | |
643 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
644 ngx_regex_exec_n " failed: %d on \"%V\" using \"%V\"", | |
515 | 645 rc, &e->line, &code->name); |
509 | 646 |
647 e->ip = ngx_http_script_exit; | |
648 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
649 return; | |
650 } | |
651 | |
652 if (e->log) { | |
653 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | |
515 | 654 "\"%V\" matches \"%V\"", &code->name, &e->line); |
509 | 655 } |
656 | |
515 | 657 e->ncaptures = code->ncaptures; |
658 | |
509 | 659 if (code->test) { |
631 | 660 if (code->negative_test) { |
661 e->sp->len = 0; | |
662 e->sp->data = (u_char *) ""; | |
663 | |
664 } else { | |
665 e->sp->len = 1; | |
666 e->sp->data = (u_char *) "1"; | |
667 } | |
668 | |
509 | 669 e->sp++; |
670 | |
671 e->ip += sizeof(ngx_http_script_regex_code_t); | |
672 return; | |
673 } | |
674 | |
675 if (code->status) { | |
676 e->status = code->status; | |
507 | 677 |
509 | 678 if (!code->redirect) { |
679 e->ip = ngx_http_script_exit; | |
680 return; | |
681 } | |
682 } | |
683 | |
684 if (code->uri) { | |
685 r->internal = 1; | |
686 r->valid_unparsed_uri = 0; | |
687 | |
688 if (code->break_cycle) { | |
689 r->valid_location = 0; | |
527 | 690 r->uri_changed = 0; |
509 | 691 |
692 } else { | |
693 r->uri_changed = 1; | |
694 } | |
695 } | |
696 | |
697 if (code->lengths == NULL) { | |
698 e->buf.len = code->size; | |
699 | |
700 if (code->uri) { | |
701 if (rc && (r->quoted_uri || r->plus_in_uri)) { | |
702 e->buf.len += 2 * ngx_escape_uri(NULL, r->uri.data, r->uri.len, | |
703 NGX_ESCAPE_ARGS); | |
704 } | |
705 } | |
706 | |
707 for (n = 1; n < (ngx_uint_t) rc; n++) { | |
708 e->buf.len += e->captures[2 * n + 1] - e->captures[2 * n]; | |
709 } | |
710 | |
711 } else { | |
712 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); | |
713 | |
714 le.ip = code->lengths->elts; | |
679 | 715 le.line = e->line; |
509 | 716 le.request = r; |
717 le.captures = e->captures; | |
515 | 718 le.ncaptures = e->ncaptures; |
679 | 719 le.quote = code->redirect; |
509 | 720 |
1891
782af1038115
length calculation did not take into account escaped symbols in arguments
Igor Sysoev <igor@sysoev.ru>
parents:
1799
diff
changeset
|
721 len = 0; |
509 | 722 |
723 while (*(uintptr_t *) le.ip) { | |
724 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
725 len += lcode(&le); | |
726 } | |
727 | |
728 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
|
729 e->is_args = le.is_args; |
509 | 730 } |
731 | |
515 | 732 if (code->add_args && r->args.len) { |
509 | 733 e->buf.len += r->args.len + 1; |
734 } | |
735 | |
2049 | 736 e->buf.data = ngx_pnalloc(r->pool, e->buf.len); |
509 | 737 if (e->buf.data == NULL) { |
738 e->ip = ngx_http_script_exit; | |
739 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
507 | 740 return; |
741 } | |
742 | |
509 | 743 e->quote = code->redirect; |
744 | |
745 e->pos = e->buf.data; | |
746 | |
747 e->ip += sizeof(ngx_http_script_regex_code_t); | |
748 } | |
749 | |
750 | |
751 void | |
752 ngx_http_script_regex_end_code(ngx_http_script_engine_t *e) | |
753 { | |
577 | 754 u_char *dst, *src; |
509 | 755 ngx_http_request_t *r; |
756 ngx_http_script_regex_end_code_t *code; | |
757 | |
758 code = (ngx_http_script_regex_end_code_t *) e->ip; | |
759 | |
760 r = e->request; | |
761 | |
762 e->quote = 0; | |
763 | |
764 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
765 "http script regex end"); | |
766 | |
767 if (code->redirect) { | |
768 | |
577 | 769 dst = e->buf.data; |
770 src = e->buf.data; | |
771 | |
1593 | 772 ngx_unescape_uri(&dst, &src, e->pos - e->buf.data, |
773 NGX_UNESCAPE_REDIRECT); | |
577 | 774 |
775 if (src < e->pos) { | |
776 dst = ngx_copy(dst, src, e->pos - src); | |
777 } | |
778 | |
779 e->pos = dst; | |
780 | |
781 if (code->add_args && r->args.len) { | |
509 | 782 *e->pos++ = (u_char) (code->args ? '&' : '?'); |
573 | 783 e->pos = ngx_copy(e->pos, r->args.data, r->args.len); |
509 | 784 } |
785 | |
786 e->buf.len = e->pos - e->buf.data; | |
787 | |
788 if (e->log) { | |
789 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | |
790 "rewritten redirect: \"%V\"", &e->buf); | |
791 } | |
792 | |
793 r->headers_out.location = ngx_list_push(&r->headers_out.headers); | |
794 if (r->headers_out.location == NULL) { | |
795 e->ip = ngx_http_script_exit; | |
796 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
797 return; | |
798 } | |
799 | |
577 | 800 r->headers_out.location->hash = 1; |
509 | 801 r->headers_out.location->key.len = sizeof("Location") - 1; |
802 r->headers_out.location->key.data = (u_char *) "Location"; | |
803 r->headers_out.location->value = e->buf; | |
804 | |
805 e->ip += sizeof(ngx_http_script_regex_end_code_t); | |
806 return; | |
807 } | |
808 | |
577 | 809 if (e->args) { |
509 | 810 e->buf.len = e->args - e->buf.data; |
811 | |
812 if (code->add_args && r->args.len) { | |
813 *e->pos++ = '&'; | |
573 | 814 e->pos = ngx_copy(e->pos, r->args.data, r->args.len); |
509 | 815 } |
816 | |
817 r->args.len = e->pos - e->args; | |
818 r->args.data = e->args; | |
819 | |
820 e->args = NULL; | |
821 | |
822 } else { | |
823 e->buf.len = e->pos - e->buf.data; | |
673 | 824 |
825 if (!code->add_args) { | |
826 r->args.len = 0; | |
827 } | |
509 | 828 } |
829 | |
830 if (e->log) { | |
831 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | |
832 "rewritten data: \"%V\", args: \"%V\"", | |
833 &e->buf, &r->args); | |
834 } | |
835 | |
836 if (code->uri) { | |
837 r->uri = e->buf; | |
838 | |
535 | 839 if (r->uri.len == 0) { |
840 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
841 "the rewritten URI has a zero length"); | |
842 e->ip = ngx_http_script_exit; | |
843 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
844 return; | |
845 } | |
846 | |
509 | 847 if (ngx_http_set_exten(r) != NGX_OK) { |
848 e->ip = ngx_http_script_exit; | |
849 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
850 return; | |
851 } | |
852 } | |
853 | |
854 e->ip += sizeof(ngx_http_script_regex_end_code_t); | |
855 } | |
856 | |
517 | 857 #endif |
858 | |
509 | 859 |
860 void | |
861 ngx_http_script_return_code(ngx_http_script_engine_t *e) | |
577 | 862 { |
509 | 863 ngx_http_script_return_code_t *code; |
577 | 864 |
509 | 865 code = (ngx_http_script_return_code_t *) e->ip; |
866 | |
867 e->status = code->status; | |
868 | |
653 | 869 if (code->status == NGX_HTTP_NO_CONTENT) { |
870 e->request->header_only = 1; | |
730
1be87cdd010f
set "Content-Length: 0" for errors handled by "return 204"
Igor Sysoev <igor@sysoev.ru>
parents:
679
diff
changeset
|
871 e->request->zero_body = 1; |
653 | 872 } |
873 | |
509 | 874 e->ip += sizeof(ngx_http_script_return_code_t) - sizeof(uintptr_t); |
479 | 875 } |
509 | 876 |
877 | |
878 void | |
527 | 879 ngx_http_script_break_code(ngx_http_script_engine_t *e) |
880 { | |
881 e->request->uri_changed = 0; | |
882 | |
883 e->ip = ngx_http_script_exit; | |
884 } | |
885 | |
886 | |
887 void | |
509 | 888 ngx_http_script_if_code(ngx_http_script_engine_t *e) |
889 { | |
890 ngx_http_script_if_code_t *code; | |
891 | |
892 code = (ngx_http_script_if_code_t *) e->ip; | |
893 | |
894 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
895 "http script if"); | |
896 | |
897 e->sp--; | |
898 | |
573 | 899 if (e->sp->len && e->sp->data[0] != '0') { |
509 | 900 if (code->loc_conf) { |
901 e->request->loc_conf = code->loc_conf; | |
535 | 902 ngx_http_update_location_config(e->request); |
509 | 903 } |
904 | |
905 e->ip += sizeof(ngx_http_script_if_code_t); | |
906 return; | |
907 } | |
908 | |
909 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
577 | 910 "http script if: false"); |
509 | 911 |
912 e->ip += code->next; | |
913 } | |
914 | |
915 | |
916 void | |
577 | 917 ngx_http_script_equal_code(ngx_http_script_engine_t *e) |
918 { | |
919 ngx_http_variable_value_t *val, *res; | |
920 | |
921 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
922 "http script equal"); | |
923 | |
924 e->sp--; | |
925 val = e->sp; | |
926 res = e->sp - 1; | |
927 | |
928 e->ip += sizeof(uintptr_t); | |
929 | |
930 if (val->len == res->len && ngx_strncmp(val->data, res->data, res->len) | |
931 == 0) | |
932 { | |
933 *res = ngx_http_variable_true_value; | |
934 return; | |
935 } | |
936 | |
937 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
938 "http script equal: no"); | |
939 | |
940 *res = ngx_http_variable_null_value; | |
941 } | |
942 | |
943 | |
944 void | |
945 ngx_http_script_not_equal_code(ngx_http_script_engine_t *e) | |
946 { | |
947 ngx_http_variable_value_t *val, *res; | |
948 | |
949 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
950 "http script not equal"); | |
951 | |
952 e->sp--; | |
953 val = e->sp; | |
954 res = e->sp - 1; | |
955 | |
956 e->ip += sizeof(uintptr_t); | |
957 | |
958 if (val->len == res->len && ngx_strncmp(val->data, res->data, res->len) | |
959 == 0) | |
960 { | |
961 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
962 "http script not equal: no"); | |
963 | |
964 *res = ngx_http_variable_null_value; | |
965 return; | |
966 } | |
967 | |
968 *res = ngx_http_variable_true_value; | |
969 } | |
970 | |
971 | |
972 void | |
631 | 973 ngx_http_script_file_code(ngx_http_script_engine_t *e) |
974 { | |
1454 | 975 ngx_str_t path; |
976 ngx_http_request_t *r; | |
977 ngx_open_file_info_t of; | |
978 ngx_http_core_loc_conf_t *clcf; | |
631 | 979 ngx_http_variable_value_t *value; |
980 ngx_http_script_file_code_t *code; | |
981 | |
982 value = e->sp - 1; | |
983 | |
984 code = (ngx_http_script_file_code_t *) e->ip; | |
985 e->ip += sizeof(ngx_http_script_file_code_t); | |
986 | |
1454 | 987 path.len = value->len - 1; |
988 path.data = value->data; | |
989 | |
990 r = e->request; | |
991 | |
992 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
993 "http script file op %p \"%V\"", code->op, &path); | |
994 | |
995 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
631 | 996 |
1454 | 997 of.test_dir = 0; |
1767
c42431762903
open_file_cache_retest > open_file_cache_valid
Igor Sysoev <igor@sysoev.ru>
parents:
1593
diff
changeset
|
998 of.valid = clcf->open_file_cache_valid; |
1772 | 999 of.min_uses = clcf->open_file_cache_min_uses; |
1454 | 1000 of.errors = clcf->open_file_cache_errors; |
1457 | 1001 of.events = clcf->open_file_cache_events; |
631 | 1002 |
1454 | 1003 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) |
1799 | 1004 != NGX_OK) |
1454 | 1005 { |
1006 if (of.err != NGX_ENOENT && of.err != NGX_ENOTDIR) { | |
1007 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err, | |
631 | 1008 ngx_file_info_n " \"%s\" failed", value->data); |
1009 } | |
1010 | |
1011 switch (code->op) { | |
671 | 1012 |
631 | 1013 case ngx_http_script_file_plain: |
669 | 1014 case ngx_http_script_file_dir: |
1015 case ngx_http_script_file_exists: | |
1016 case ngx_http_script_file_exec: | |
631 | 1017 goto false; |
671 | 1018 |
631 | 1019 case ngx_http_script_file_not_plain: |
669 | 1020 case ngx_http_script_file_not_dir: |
671 | 1021 case ngx_http_script_file_not_exists: |
669 | 1022 case ngx_http_script_file_not_exec: |
631 | 1023 goto true; |
1024 } | |
1025 | |
1026 goto false; | |
1027 } | |
1028 | |
1029 switch (code->op) { | |
1030 case ngx_http_script_file_plain: | |
1454 | 1031 if (of.is_file) { |
631 | 1032 goto true; |
1033 } | |
1034 goto false; | |
1035 | |
1036 case ngx_http_script_file_not_plain: | |
1454 | 1037 if (of.is_file) { |
631 | 1038 goto false; |
1039 } | |
1040 goto true; | |
669 | 1041 |
1042 case ngx_http_script_file_dir: | |
1454 | 1043 if (of.is_dir) { |
669 | 1044 goto true; |
1045 } | |
1046 goto false; | |
1047 | |
1048 case ngx_http_script_file_not_dir: | |
1454 | 1049 if (of.is_dir) { |
669 | 1050 goto false; |
1051 } | |
1052 goto true; | |
1053 | |
1054 case ngx_http_script_file_exists: | |
1454 | 1055 if (of.is_file || of.is_dir || of.is_link) { |
669 | 1056 goto true; |
1057 } | |
1058 goto false; | |
1059 | |
1060 case ngx_http_script_file_not_exists: | |
1454 | 1061 if (of.is_file || of.is_dir || of.is_link) { |
669 | 1062 goto false; |
1063 } | |
1064 goto true; | |
1065 | |
1066 case ngx_http_script_file_exec: | |
1454 | 1067 if (of.is_exec) { |
669 | 1068 goto true; |
1069 } | |
1070 goto false; | |
1071 | |
1072 case ngx_http_script_file_not_exec: | |
1454 | 1073 if (of.is_exec) { |
669 | 1074 goto false; |
1075 } | |
1076 goto true; | |
631 | 1077 } |
1078 | |
1079 false: | |
1080 | |
1454 | 1081 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
631 | 1082 "http script file op false"); |
1083 | |
1084 *value = ngx_http_variable_null_value; | |
1085 return; | |
1086 | |
1087 true: | |
1088 | |
1089 *value = ngx_http_variable_true_value; | |
1090 return; | |
1091 } | |
1092 | |
1093 | |
1094 void | |
515 | 1095 ngx_http_script_complex_value_code(ngx_http_script_engine_t *e) |
1096 { | |
1097 size_t len; | |
1098 ngx_http_script_engine_t le; | |
1099 ngx_http_script_len_code_pt lcode; | |
1100 ngx_http_script_complex_value_code_t *code; | |
1101 | |
1102 code = (ngx_http_script_complex_value_code_t *) e->ip; | |
1103 | |
1104 e->ip += sizeof(ngx_http_script_complex_value_code_t); | |
1105 | |
1106 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1107 "http script complex value"); | |
1108 | |
1109 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); | |
1110 | |
1111 le.ip = code->lengths->elts; | |
655 | 1112 le.line = e->line; |
515 | 1113 le.request = e->request; |
1114 le.captures = e->captures; | |
1115 le.ncaptures = e->ncaptures; | |
655 | 1116 le.quote = e->quote; |
515 | 1117 |
1118 for (len = 0; *(uintptr_t *) le.ip; len += lcode(&le)) { | |
1119 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
1120 } | |
1121 | |
1122 e->buf.len = len; | |
2049 | 1123 e->buf.data = ngx_pnalloc(e->request->pool, len); |
515 | 1124 if (e->buf.data == NULL) { |
1125 e->ip = ngx_http_script_exit; | |
1126 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1127 return; | |
1128 } | |
1129 | |
1130 e->pos = e->buf.data; | |
1131 | |
577 | 1132 e->sp->len = e->buf.len; |
573 | 1133 e->sp->data = e->buf.data; |
515 | 1134 e->sp++; |
1135 } | |
1136 | |
1137 | |
1138 void | |
509 | 1139 ngx_http_script_value_code(ngx_http_script_engine_t *e) |
1140 { | |
1141 ngx_http_script_value_code_t *code; | |
1142 | |
1143 code = (ngx_http_script_value_code_t *) e->ip; | |
1144 | |
1145 e->ip += sizeof(ngx_http_script_value_code_t); | |
1146 | |
573 | 1147 e->sp->len = code->text_len; |
1148 e->sp->data = (u_char *) code->text_data; | |
577 | 1149 |
1150 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1561 | 1151 "http script value: \"%v\"", e->sp); |
577 | 1152 |
509 | 1153 e->sp++; |
1154 } | |
1155 | |
1156 | |
1157 void | |
1158 ngx_http_script_set_var_code(ngx_http_script_engine_t *e) | |
1159 { | |
1160 ngx_http_request_t *r; | |
1161 ngx_http_script_var_code_t *code; | |
1162 | |
1163 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1164 "http script set var"); | |
1165 | |
1166 code = (ngx_http_script_var_code_t *) e->ip; | |
1167 | |
1168 e->ip += sizeof(ngx_http_script_var_code_t); | |
1169 | |
1170 r = e->request; | |
1171 | |
1172 e->sp--; | |
1173 | |
573 | 1174 r->variables[code->index].len = e->sp->len; |
1175 r->variables[code->index].valid = 1; | |
1565 | 1176 r->variables[code->index].no_cacheable = 0; |
573 | 1177 r->variables[code->index].not_found = 0; |
1178 r->variables[code->index].data = e->sp->data; | |
509 | 1179 } |
1180 | |
1181 | |
1182 void | |
637 | 1183 ngx_http_script_var_set_handler_code(ngx_http_script_engine_t *e) |
1184 { | |
1185 ngx_http_script_var_handler_code_t *code; | |
1186 | |
1187 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1188 "http script set var handler"); | |
1189 | |
1190 code = (ngx_http_script_var_handler_code_t *) e->ip; | |
1191 | |
1192 e->ip += sizeof(ngx_http_script_var_handler_code_t); | |
1193 | |
1194 e->sp--; | |
1195 | |
1196 code->handler(e->request, e->sp, code->data); | |
1197 } | |
1198 | |
1199 | |
1200 void | |
509 | 1201 ngx_http_script_var_code(ngx_http_script_engine_t *e) |
1202 { | |
1203 ngx_http_variable_value_t *value; | |
1204 ngx_http_script_var_code_t *code; | |
1205 | |
1206 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1207 "http script var"); | |
1208 | |
1209 code = (ngx_http_script_var_code_t *) e->ip; | |
1210 | |
1211 e->ip += sizeof(ngx_http_script_var_code_t); | |
1212 | |
573 | 1213 value = ngx_http_get_flushed_variable(e->request, code->index); |
509 | 1214 |
573 | 1215 if (value && !value->not_found) { |
1216 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
|
1217 "http script var: \"%v\"", value); |
573 | 1218 |
553 | 1219 *e->sp = *value; |
509 | 1220 e->sp++; |
1221 | |
1222 return; | |
1223 } | |
1224 | |
577 | 1225 *e->sp = ngx_http_variable_null_value; |
509 | 1226 e->sp++; |
1227 } | |
1228 | |
1229 | |
1230 void | |
1231 ngx_http_script_nop_code(ngx_http_script_engine_t *e) | |
1232 { | |
1233 e->ip += sizeof(uintptr_t); | |
1234 } |