Mercurial > hg > nginx-quic
annotate src/http/ngx_http_script.c @ 1271:2b3e6aede7da
add comment
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 06 Jul 2007 11:28:20 +0000 |
parents | a9715f8f17a5 |
children | 03341711f9a2 |
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 |
509 | 224 code = ngx_http_script_add_code(*sc->values, sizeof(uintptr_t), |
225 &sc->main); | |
226 if (code == NULL) { | |
507 | 227 return NGX_ERROR; |
228 } | |
229 | |
509 | 230 *code = (uintptr_t) ngx_http_script_start_args_code; |
231 | |
232 i++; | |
233 | |
507 | 234 continue; |
235 } | |
236 | |
509 | 237 name.data = &sc->source->data[i]; |
238 | |
239 while (i < sc->source->len | |
240 && sc->source->data[i] != '$' | |
241 && !(sc->source->data[i] == '?' && sc->compile_args)) | |
242 { | |
243 i++; | |
244 name.len++; | |
245 } | |
246 | |
247 sc->size += name.len; | |
248 | |
249 copy = ngx_http_script_add_code(*sc->lengths, | |
250 sizeof(ngx_http_script_copy_code_t), | |
251 NULL); | |
252 if (copy == NULL) { | |
507 | 253 return NGX_ERROR; |
254 } | |
509 | 255 |
256 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; | |
257 copy->len = name.len; | |
258 | |
259 size = (sizeof(ngx_http_script_copy_code_t) + name.len | |
260 + sizeof(uintptr_t) - 1) | |
261 & ~(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
|
262 |
509 | 263 copy = ngx_http_script_add_code(*sc->values, size, &sc->main); |
264 if (copy == NULL) { | |
265 return NGX_ERROR; | |
266 } | |
267 | |
268 copy->code = ngx_http_script_copy_code; | |
269 copy->len = name.len; | |
270 | |
271 ngx_memcpy((u_char *) copy + sizeof(ngx_http_script_copy_code_t), | |
272 name.data, name.len); | |
507 | 273 } |
274 | |
509 | 275 if (sc->complete_lengths) { |
276 code = ngx_http_script_add_code(*sc->lengths, sizeof(uintptr_t), NULL); | |
277 if (code == NULL) { | |
278 return NGX_ERROR; | |
279 } | |
507 | 280 |
509 | 281 *code = (uintptr_t) NULL; |
507 | 282 } |
283 | |
509 | 284 if (sc->complete_values) { |
285 code = ngx_http_script_add_code(*sc->values, sizeof(uintptr_t), | |
286 &sc->main); | |
287 if (code == NULL) { | |
288 return NGX_ERROR; | |
289 } | |
290 | |
291 *code = (uintptr_t) NULL; | |
292 } | |
507 | 293 |
294 return NGX_OK; | |
509 | 295 |
296 invalid_variable: | |
297 | |
298 ngx_conf_log_error(NGX_LOG_EMERG, sc->cf, 0, "invalid variable name"); | |
299 | |
300 return NGX_ERROR; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
301 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
302 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
303 |
623 | 304 u_char * |
305 ngx_http_script_run(ngx_http_request_t *r, ngx_str_t *value, | |
306 void *code_lengths, size_t len, void *code_values) | |
307 { | |
1152
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
308 ngx_uint_t i; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
309 ngx_http_script_code_pt code; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
310 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
|
311 ngx_http_script_engine_t e; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
312 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
|
313 |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
314 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
|
315 |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
316 for (i = 0; i < cmcf->variables.nelts; i++) { |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
317 if (r->variables[i].no_cachable) { |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
318 r->variables[i].valid = 0; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
319 r->variables[i].not_found = 0; |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
320 } |
a9715f8f17a5
flush nocachable variables before ngx_http_script_run()
Igor Sysoev <igor@sysoev.ru>
parents:
845
diff
changeset
|
321 } |
623 | 322 |
323 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); | |
324 | |
325 e.ip = code_lengths; | |
326 e.request = r; | |
327 e.flushed = 1; | |
328 | |
329 while (*(uintptr_t *) e.ip) { | |
330 lcode = *(ngx_http_script_len_code_pt *) e.ip; | |
331 len += lcode(&e); | |
332 } | |
333 | |
334 | |
335 value->len = len; | |
336 value->data = ngx_palloc(r->pool, len); | |
337 if (value->data == NULL) { | |
338 return NULL; | |
339 } | |
340 | |
341 e.ip = code_values; | |
342 e.pos = value->data; | |
343 | |
344 while (*(uintptr_t *) e.ip) { | |
345 code = *(ngx_http_script_code_pt *) e.ip; | |
346 code((ngx_http_script_engine_t *) &e); | |
347 } | |
348 | |
349 return e.pos; | |
350 } | |
351 | |
352 | |
573 | 353 void |
354 ngx_http_script_flush_no_cachable_variables(ngx_http_request_t *r, | |
355 ngx_array_t *indices) | |
356 { | |
357 ngx_uint_t n, *index; | |
358 | |
359 if (indices) { | |
360 index = indices->elts; | |
361 for (n = 0; n < indices->nelts; n++) { | |
362 if (r->variables[index[n]].no_cachable) { | |
363 r->variables[index[n]].valid = 0; | |
364 r->variables[index[n]].not_found = 0; | |
365 } | |
366 } | |
367 } | |
368 } | |
369 | |
370 | |
509 | 371 void * |
507 | 372 ngx_http_script_start_code(ngx_pool_t *pool, ngx_array_t **codes, size_t size) |
479 | 373 { |
507 | 374 if (*codes == NULL) { |
375 *codes = ngx_array_create(pool, 256, 1); | |
376 if (*codes == NULL) { | |
377 return NULL; | |
378 } | |
379 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
380 |
507 | 381 return ngx_array_push_n(*codes, size); |
382 } | |
383 | |
509 | 384 |
385 void * | |
386 ngx_http_script_add_code(ngx_array_t *codes, size_t size, void *code) | |
387 { | |
388 u_char *elts, **p; | |
389 void *new; | |
390 | |
391 elts = codes->elts; | |
392 | |
393 new = ngx_array_push_n(codes, size); | |
394 if (new == NULL) { | |
395 return NGX_CONF_ERROR; | |
396 } | |
397 | |
398 if (code) { | |
399 if (elts != codes->elts) { | |
400 p = code; | |
401 *p += (u_char *) codes->elts - elts; | |
402 } | |
403 } | |
404 | |
405 return new; | |
406 } | |
507 | 407 |
479 | 408 |
507 | 409 size_t |
509 | 410 ngx_http_script_copy_len_code(ngx_http_script_engine_t *e) |
507 | 411 { |
412 ngx_http_script_copy_code_t *code; | |
479 | 413 |
509 | 414 code = (ngx_http_script_copy_code_t *) e->ip; |
507 | 415 |
509 | 416 e->ip += sizeof(ngx_http_script_copy_code_t); |
507 | 417 |
418 return code->len; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
419 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
420 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
421 |
507 | 422 void |
509 | 423 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
|
424 { |
507 | 425 ngx_http_script_copy_code_t *code; |
426 | |
509 | 427 code = (ngx_http_script_copy_code_t *) e->ip; |
428 | |
429 if (!e->skip) { | |
573 | 430 e->pos = ngx_copy(e->pos, e->ip + sizeof(ngx_http_script_copy_code_t), |
431 code->len); | |
509 | 432 } |
507 | 433 |
509 | 434 e->ip += sizeof(ngx_http_script_copy_code_t) |
435 + ((code->len + sizeof(uintptr_t) - 1) & ~(sizeof(uintptr_t) - 1)); | |
507 | 436 |
845
eb5cf273e5d2
debug log should not be under rewrite_log control
Igor Sysoev <igor@sysoev.ru>
parents:
730
diff
changeset
|
437 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
|
438 "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
|
439 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
440 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
441 |
507 | 442 size_t |
509 | 443 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
|
444 { |
507 | 445 ngx_http_variable_value_t *value; |
446 ngx_http_script_var_code_t *code; | |
447 | |
509 | 448 code = (ngx_http_script_var_code_t *) e->ip; |
507 | 449 |
509 | 450 e->ip += sizeof(ngx_http_script_var_code_t); |
507 | 451 |
573 | 452 if (e->flushed) { |
453 value = ngx_http_get_indexed_variable(e->request, code->index); | |
507 | 454 |
573 | 455 } else { |
456 value = ngx_http_get_flushed_variable(e->request, code->index); | |
457 } | |
458 | |
459 if (value && !value->not_found) { | |
460 return value->len; | |
507 | 461 } |
462 | |
553 | 463 return 0; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
464 } |
479 | 465 |
466 | |
507 | 467 void |
509 | 468 ngx_http_script_copy_var_code(ngx_http_script_engine_t *e) |
479 | 469 { |
507 | 470 ngx_http_variable_value_t *value; |
471 ngx_http_script_var_code_t *code; | |
472 | |
509 | 473 code = (ngx_http_script_var_code_t *) e->ip; |
474 | |
475 e->ip += sizeof(ngx_http_script_var_code_t); | |
476 | |
477 if (!e->skip) { | |
573 | 478 |
479 if (e->flushed) { | |
480 value = ngx_http_get_indexed_variable(e->request, code->index); | |
509 | 481 |
573 | 482 } else { |
483 value = ngx_http_get_flushed_variable(e->request, code->index); | |
484 } | |
485 | |
486 if (value && !value->not_found) { | |
487 e->pos = ngx_copy(e->pos, value->data, value->len); | |
509 | 488 |
845
eb5cf273e5d2
debug log should not be under rewrite_log control
Igor Sysoev <igor@sysoev.ru>
parents:
730
diff
changeset
|
489 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
|
490 e->request->connection->log, 0, |
eb5cf273e5d2
debug log should not be under rewrite_log control
Igor Sysoev <igor@sysoev.ru>
parents:
730
diff
changeset
|
491 "http script var: \"%V\"", &e->buf); |
509 | 492 } |
493 } | |
494 } | |
495 | |
496 | |
497 size_t | |
498 ngx_http_script_copy_capture_len_code(ngx_http_script_engine_t *e) | |
499 { | |
500 ngx_http_script_copy_capture_code_t *code; | |
501 | |
502 code = (ngx_http_script_copy_capture_code_t *) e->ip; | |
503 | |
504 e->ip += sizeof(ngx_http_script_copy_capture_code_t); | |
505 | |
515 | 506 if (code->n < e->ncaptures) { |
507 if ((e->args || e->quote) | |
508 && (e->request->quoted_uri || e->request->plus_in_uri)) | |
509 { | |
510 return e->captures[code->n + 1] - e->captures[code->n] | |
655 | 511 + 2 * ngx_escape_uri(NULL, |
515 | 512 &e->line.data[e->captures[code->n]], |
509 | 513 e->captures[code->n + 1] - e->captures[code->n], |
514 NGX_ESCAPE_ARGS); | |
515 | 515 } else { |
516 return e->captures[code->n + 1] - e->captures[code->n]; | |
517 } | |
509 | 518 } |
515 | 519 |
520 return 0; | |
509 | 521 } |
522 | |
523 | |
524 void | |
525 ngx_http_script_copy_capture_code(ngx_http_script_engine_t *e) | |
526 { | |
527 ngx_http_script_copy_capture_code_t *code; | |
528 | |
529 code = (ngx_http_script_copy_capture_code_t *) e->ip; | |
530 | |
531 e->ip += sizeof(ngx_http_script_copy_capture_code_t); | |
507 | 532 |
515 | 533 if (code->n < e->ncaptures) { |
534 if ((e->args || e->quote) | |
535 && (e->request->quoted_uri || e->request->plus_in_uri)) | |
536 { | |
537 e->pos = (u_char *) ngx_escape_uri(e->pos, | |
538 &e->line.data[e->captures[code->n]], | |
509 | 539 e->captures[code->n + 1] - e->captures[code->n], |
540 NGX_ESCAPE_ARGS); | |
515 | 541 } else { |
573 | 542 e->pos = ngx_copy(e->pos, |
543 &e->line.data[e->captures[code->n]], | |
544 e->captures[code->n + 1] - e->captures[code->n]); | |
515 | 545 } |
509 | 546 } |
547 | |
548 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
549 "http script capture: \"%V\"", &e->buf); | |
550 } | |
551 | |
552 | |
553 void | |
554 ngx_http_script_start_args_code(ngx_http_script_engine_t *e) | |
555 { | |
556 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
557 "http script args"); | |
577 | 558 |
509 | 559 e->args = e->pos; |
560 e->ip += sizeof(uintptr_t); | |
561 } | |
562 | |
563 | |
517 | 564 |
565 #if (NGX_PCRE) | |
566 | |
509 | 567 void |
568 ngx_http_script_regex_start_code(ngx_http_script_engine_t *e) | |
569 { | |
570 size_t len; | |
571 ngx_int_t rc; | |
572 ngx_uint_t n; | |
573 ngx_http_request_t *r; | |
574 ngx_http_script_engine_t le; | |
575 ngx_http_script_len_code_pt lcode; | |
576 ngx_http_script_regex_code_t *code; | |
577 | |
578 code = (ngx_http_script_regex_code_t *) e->ip; | |
579 | |
580 r = e->request; | |
581 | |
582 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
583 "http script regex: \"%V\"", &code->name); | |
584 | |
585 if (code->uri) { | |
515 | 586 e->line = r->uri; |
509 | 587 } else { |
588 e->sp--; | |
573 | 589 e->line.len = e->sp->len; |
590 e->line.data = e->sp->data; | |
509 | 591 } |
507 | 592 |
515 | 593 rc = ngx_regex_exec(code->regex, &e->line, e->captures, code->ncaptures); |
509 | 594 |
595 if (rc == NGX_REGEX_NO_MATCHED) { | |
596 if (e->log) { | |
597 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | |
515 | 598 "\"%V\" does not match \"%V\"", |
599 &code->name, &e->line); | |
509 | 600 } |
601 | |
515 | 602 e->ncaptures = 0; |
603 | |
509 | 604 if (code->test) { |
631 | 605 if (code->negative_test) { |
606 e->sp->len = 1; | |
607 e->sp->data = (u_char *) "1"; | |
608 | |
609 } else { | |
610 e->sp->len = 0; | |
611 e->sp->data = (u_char *) ""; | |
612 } | |
613 | |
509 | 614 e->sp++; |
615 | |
616 e->ip += sizeof(ngx_http_script_regex_code_t); | |
617 return; | |
618 } | |
619 | |
620 e->ip += code->next; | |
621 return; | |
622 } | |
623 | |
624 if (rc < 0) { | |
625 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
626 ngx_regex_exec_n " failed: %d on \"%V\" using \"%V\"", | |
515 | 627 rc, &e->line, &code->name); |
509 | 628 |
629 e->ip = ngx_http_script_exit; | |
630 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
631 return; | |
632 } | |
633 | |
634 if (e->log) { | |
635 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | |
515 | 636 "\"%V\" matches \"%V\"", &code->name, &e->line); |
509 | 637 } |
638 | |
515 | 639 e->ncaptures = code->ncaptures; |
640 | |
509 | 641 if (code->test) { |
631 | 642 if (code->negative_test) { |
643 e->sp->len = 0; | |
644 e->sp->data = (u_char *) ""; | |
645 | |
646 } else { | |
647 e->sp->len = 1; | |
648 e->sp->data = (u_char *) "1"; | |
649 } | |
650 | |
509 | 651 e->sp++; |
652 | |
653 e->ip += sizeof(ngx_http_script_regex_code_t); | |
654 return; | |
655 } | |
656 | |
657 if (code->status) { | |
658 e->status = code->status; | |
507 | 659 |
509 | 660 if (!code->redirect) { |
661 e->ip = ngx_http_script_exit; | |
662 return; | |
663 } | |
664 } | |
665 | |
666 if (code->uri) { | |
667 r->internal = 1; | |
668 r->valid_unparsed_uri = 0; | |
669 | |
670 if (code->break_cycle) { | |
671 r->valid_location = 0; | |
527 | 672 r->uri_changed = 0; |
509 | 673 |
674 } else { | |
675 r->uri_changed = 1; | |
676 } | |
677 } | |
678 | |
679 if (code->lengths == NULL) { | |
680 e->buf.len = code->size; | |
681 | |
682 if (code->uri) { | |
683 if (rc && (r->quoted_uri || r->plus_in_uri)) { | |
684 e->buf.len += 2 * ngx_escape_uri(NULL, r->uri.data, r->uri.len, | |
685 NGX_ESCAPE_ARGS); | |
686 } | |
687 } | |
688 | |
689 for (n = 1; n < (ngx_uint_t) rc; n++) { | |
690 e->buf.len += e->captures[2 * n + 1] - e->captures[2 * n]; | |
691 } | |
692 | |
693 } else { | |
694 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); | |
695 | |
696 le.ip = code->lengths->elts; | |
679 | 697 le.line = e->line; |
509 | 698 le.request = r; |
699 le.captures = e->captures; | |
515 | 700 le.ncaptures = e->ncaptures; |
679 | 701 le.quote = code->redirect; |
509 | 702 |
703 len = 1; /* reserve 1 byte for possible "?" */ | |
704 | |
705 while (*(uintptr_t *) le.ip) { | |
706 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
707 len += lcode(&le); | |
708 } | |
709 | |
710 e->buf.len = len; | |
711 } | |
712 | |
515 | 713 if (code->add_args && r->args.len) { |
509 | 714 e->buf.len += r->args.len + 1; |
715 } | |
716 | |
717 e->buf.data = ngx_palloc(r->pool, e->buf.len); | |
718 if (e->buf.data == NULL) { | |
719 e->ip = ngx_http_script_exit; | |
720 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
507 | 721 return; |
722 } | |
723 | |
509 | 724 e->quote = code->redirect; |
725 | |
726 e->pos = e->buf.data; | |
727 | |
728 e->ip += sizeof(ngx_http_script_regex_code_t); | |
729 } | |
730 | |
731 | |
732 void | |
733 ngx_http_script_regex_end_code(ngx_http_script_engine_t *e) | |
734 { | |
577 | 735 u_char *dst, *src; |
509 | 736 ngx_http_request_t *r; |
737 ngx_http_script_regex_end_code_t *code; | |
738 | |
739 code = (ngx_http_script_regex_end_code_t *) e->ip; | |
740 | |
741 r = e->request; | |
742 | |
743 e->quote = 0; | |
744 | |
745 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
746 "http script regex end"); | |
747 | |
748 if (code->redirect) { | |
749 | |
577 | 750 dst = e->buf.data; |
751 src = e->buf.data; | |
752 | |
601 | 753 ngx_unescape_uri(&dst, &src, e->pos - e->buf.data, NGX_UNESCAPE_URI); |
577 | 754 |
755 if (src < e->pos) { | |
756 dst = ngx_copy(dst, src, e->pos - src); | |
757 } | |
758 | |
759 e->pos = dst; | |
760 | |
761 if (code->add_args && r->args.len) { | |
509 | 762 *e->pos++ = (u_char) (code->args ? '&' : '?'); |
573 | 763 e->pos = ngx_copy(e->pos, r->args.data, r->args.len); |
509 | 764 } |
765 | |
766 e->buf.len = e->pos - e->buf.data; | |
767 | |
768 if (e->log) { | |
769 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | |
770 "rewritten redirect: \"%V\"", &e->buf); | |
771 } | |
772 | |
773 r->headers_out.location = ngx_list_push(&r->headers_out.headers); | |
774 if (r->headers_out.location == NULL) { | |
775 e->ip = ngx_http_script_exit; | |
776 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
777 return; | |
778 } | |
779 | |
577 | 780 r->headers_out.location->hash = 1; |
509 | 781 r->headers_out.location->key.len = sizeof("Location") - 1; |
782 r->headers_out.location->key.data = (u_char *) "Location"; | |
783 r->headers_out.location->value = e->buf; | |
784 | |
785 e->ip += sizeof(ngx_http_script_regex_end_code_t); | |
786 return; | |
787 } | |
788 | |
577 | 789 if (e->args) { |
509 | 790 e->buf.len = e->args - e->buf.data; |
791 | |
792 if (code->add_args && r->args.len) { | |
793 *e->pos++ = '&'; | |
573 | 794 e->pos = ngx_copy(e->pos, r->args.data, r->args.len); |
509 | 795 } |
796 | |
797 r->args.len = e->pos - e->args; | |
798 r->args.data = e->args; | |
799 | |
800 e->args = NULL; | |
801 | |
802 } else { | |
803 e->buf.len = e->pos - e->buf.data; | |
673 | 804 |
805 if (!code->add_args) { | |
806 r->args.len = 0; | |
807 } | |
509 | 808 } |
809 | |
810 if (e->log) { | |
811 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | |
812 "rewritten data: \"%V\", args: \"%V\"", | |
813 &e->buf, &r->args); | |
814 } | |
815 | |
816 if (code->uri) { | |
817 r->uri = e->buf; | |
818 | |
535 | 819 if (r->uri.len == 0) { |
820 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
821 "the rewritten URI has a zero length"); | |
822 e->ip = ngx_http_script_exit; | |
823 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
824 return; | |
825 } | |
826 | |
509 | 827 if (ngx_http_set_exten(r) != NGX_OK) { |
828 e->ip = ngx_http_script_exit; | |
829 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
830 return; | |
831 } | |
832 } | |
833 | |
834 e->ip += sizeof(ngx_http_script_regex_end_code_t); | |
835 } | |
836 | |
517 | 837 #endif |
838 | |
509 | 839 |
840 void | |
841 ngx_http_script_return_code(ngx_http_script_engine_t *e) | |
577 | 842 { |
509 | 843 ngx_http_script_return_code_t *code; |
577 | 844 |
509 | 845 code = (ngx_http_script_return_code_t *) e->ip; |
846 | |
847 e->status = code->status; | |
848 | |
653 | 849 if (code->status == NGX_HTTP_NO_CONTENT) { |
850 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
|
851 e->request->zero_body = 1; |
653 | 852 } |
853 | |
509 | 854 e->ip += sizeof(ngx_http_script_return_code_t) - sizeof(uintptr_t); |
479 | 855 } |
509 | 856 |
857 | |
858 void | |
527 | 859 ngx_http_script_break_code(ngx_http_script_engine_t *e) |
860 { | |
861 e->request->uri_changed = 0; | |
862 | |
863 e->ip = ngx_http_script_exit; | |
864 } | |
865 | |
866 | |
867 void | |
509 | 868 ngx_http_script_if_code(ngx_http_script_engine_t *e) |
869 { | |
870 ngx_http_script_if_code_t *code; | |
871 | |
872 code = (ngx_http_script_if_code_t *) e->ip; | |
873 | |
874 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
875 "http script if"); | |
876 | |
877 e->sp--; | |
878 | |
573 | 879 if (e->sp->len && e->sp->data[0] != '0') { |
509 | 880 if (code->loc_conf) { |
881 e->request->loc_conf = code->loc_conf; | |
535 | 882 ngx_http_update_location_config(e->request); |
509 | 883 } |
884 | |
885 e->ip += sizeof(ngx_http_script_if_code_t); | |
886 return; | |
887 } | |
888 | |
889 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
577 | 890 "http script if: false"); |
509 | 891 |
892 e->ip += code->next; | |
893 } | |
894 | |
895 | |
896 void | |
577 | 897 ngx_http_script_equal_code(ngx_http_script_engine_t *e) |
898 { | |
899 ngx_http_variable_value_t *val, *res; | |
900 | |
901 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
902 "http script equal"); | |
903 | |
904 e->sp--; | |
905 val = e->sp; | |
906 res = e->sp - 1; | |
907 | |
908 e->ip += sizeof(uintptr_t); | |
909 | |
910 if (val->len == res->len && ngx_strncmp(val->data, res->data, res->len) | |
911 == 0) | |
912 { | |
913 *res = ngx_http_variable_true_value; | |
914 return; | |
915 } | |
916 | |
917 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
918 "http script equal: no"); | |
919 | |
920 *res = ngx_http_variable_null_value; | |
921 } | |
922 | |
923 | |
924 void | |
925 ngx_http_script_not_equal_code(ngx_http_script_engine_t *e) | |
926 { | |
927 ngx_http_variable_value_t *val, *res; | |
928 | |
929 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
930 "http script not equal"); | |
931 | |
932 e->sp--; | |
933 val = e->sp; | |
934 res = e->sp - 1; | |
935 | |
936 e->ip += sizeof(uintptr_t); | |
937 | |
938 if (val->len == res->len && ngx_strncmp(val->data, res->data, res->len) | |
939 == 0) | |
940 { | |
941 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
942 "http script not equal: no"); | |
943 | |
944 *res = ngx_http_variable_null_value; | |
945 return; | |
946 } | |
947 | |
948 *res = ngx_http_variable_true_value; | |
949 } | |
950 | |
951 | |
952 void | |
631 | 953 ngx_http_script_file_code(ngx_http_script_engine_t *e) |
954 { | |
955 ngx_err_t err; | |
956 ngx_file_info_t fi; | |
957 ngx_http_variable_value_t *value; | |
958 ngx_http_script_file_code_t *code; | |
959 | |
960 value = e->sp - 1; | |
961 | |
962 code = (ngx_http_script_file_code_t *) e->ip; | |
963 e->ip += sizeof(ngx_http_script_file_code_t); | |
964 | |
965 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
966 "http script file op %p", code->op); | |
967 | |
968 if (ngx_file_info(value->data, &fi) == -1) { | |
969 err = ngx_errno; | |
970 | |
971 if (err != NGX_ENOENT && err != NGX_ENOTDIR) { | |
972 ngx_log_error(NGX_LOG_CRIT, e->request->connection->log, err, | |
973 ngx_file_info_n " \"%s\" failed", value->data); | |
974 } | |
975 | |
976 switch (code->op) { | |
671 | 977 |
631 | 978 case ngx_http_script_file_plain: |
669 | 979 case ngx_http_script_file_dir: |
980 case ngx_http_script_file_exists: | |
981 case ngx_http_script_file_exec: | |
631 | 982 goto false; |
671 | 983 |
631 | 984 case ngx_http_script_file_not_plain: |
669 | 985 case ngx_http_script_file_not_dir: |
671 | 986 case ngx_http_script_file_not_exists: |
669 | 987 case ngx_http_script_file_not_exec: |
631 | 988 goto true; |
989 } | |
990 | |
991 goto false; | |
992 } | |
993 | |
994 switch (code->op) { | |
995 case ngx_http_script_file_plain: | |
996 if (ngx_is_file(&fi)) { | |
997 goto true; | |
998 } | |
999 goto false; | |
1000 | |
1001 case ngx_http_script_file_not_plain: | |
1002 if (ngx_is_file(&fi)) { | |
1003 goto false; | |
1004 } | |
1005 goto true; | |
669 | 1006 |
1007 case ngx_http_script_file_dir: | |
1008 if (ngx_is_dir(&fi)) { | |
1009 goto true; | |
1010 } | |
1011 goto false; | |
1012 | |
1013 case ngx_http_script_file_not_dir: | |
1014 if (ngx_is_dir(&fi)) { | |
1015 goto false; | |
1016 } | |
1017 goto true; | |
1018 | |
1019 case ngx_http_script_file_exists: | |
1020 if (ngx_is_file(&fi) || ngx_is_dir(&fi) || ngx_is_link(&fi)) { | |
1021 goto true; | |
1022 } | |
1023 goto false; | |
1024 | |
1025 case ngx_http_script_file_not_exists: | |
1026 if (ngx_is_file(&fi) || ngx_is_dir(&fi) || ngx_is_link(&fi)) { | |
1027 goto false; | |
1028 } | |
1029 goto true; | |
1030 | |
1031 #if (NGX_WIN32) | |
1032 | |
1033 case ngx_http_script_file_exec: | |
1034 goto false; | |
1035 | |
1036 case ngx_http_script_file_not_exec: | |
1037 goto true; | |
1038 | |
1039 #else | |
1040 | |
1041 case ngx_http_script_file_exec: | |
1042 if (ngx_is_exec(&fi)) { | |
1043 goto true; | |
1044 } | |
1045 goto false; | |
1046 | |
1047 case ngx_http_script_file_not_exec: | |
1048 if (ngx_is_exec(&fi)) { | |
1049 goto false; | |
1050 } | |
1051 goto true; | |
1052 | |
1053 #endif | |
631 | 1054 } |
1055 | |
1056 false: | |
1057 | |
1058 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1059 "http script file op false"); | |
1060 | |
1061 *value = ngx_http_variable_null_value; | |
1062 return; | |
1063 | |
1064 true: | |
1065 | |
1066 *value = ngx_http_variable_true_value; | |
1067 return; | |
1068 } | |
1069 | |
1070 | |
1071 void | |
515 | 1072 ngx_http_script_complex_value_code(ngx_http_script_engine_t *e) |
1073 { | |
1074 size_t len; | |
1075 ngx_http_script_engine_t le; | |
1076 ngx_http_script_len_code_pt lcode; | |
1077 ngx_http_script_complex_value_code_t *code; | |
1078 | |
1079 code = (ngx_http_script_complex_value_code_t *) e->ip; | |
1080 | |
1081 e->ip += sizeof(ngx_http_script_complex_value_code_t); | |
1082 | |
1083 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1084 "http script complex value"); | |
1085 | |
1086 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); | |
1087 | |
1088 le.ip = code->lengths->elts; | |
655 | 1089 le.line = e->line; |
515 | 1090 le.request = e->request; |
1091 le.captures = e->captures; | |
1092 le.ncaptures = e->ncaptures; | |
655 | 1093 le.quote = e->quote; |
515 | 1094 |
1095 for (len = 0; *(uintptr_t *) le.ip; len += lcode(&le)) { | |
1096 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
1097 } | |
1098 | |
1099 e->buf.len = len; | |
1100 e->buf.data = ngx_palloc(e->request->pool, len); | |
1101 if (e->buf.data == NULL) { | |
1102 e->ip = ngx_http_script_exit; | |
1103 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1104 return; | |
1105 } | |
1106 | |
1107 e->pos = e->buf.data; | |
1108 | |
577 | 1109 e->sp->len = e->buf.len; |
573 | 1110 e->sp->data = e->buf.data; |
515 | 1111 e->sp++; |
1112 } | |
1113 | |
1114 | |
1115 void | |
509 | 1116 ngx_http_script_value_code(ngx_http_script_engine_t *e) |
1117 { | |
1118 ngx_http_script_value_code_t *code; | |
1119 | |
1120 code = (ngx_http_script_value_code_t *) e->ip; | |
1121 | |
1122 e->ip += sizeof(ngx_http_script_value_code_t); | |
1123 | |
573 | 1124 e->sp->len = code->text_len; |
1125 e->sp->data = (u_char *) code->text_data; | |
577 | 1126 |
1127 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1128 "http script value: \"%V\"", e->sp); | |
1129 | |
509 | 1130 e->sp++; |
1131 } | |
1132 | |
1133 | |
1134 void | |
1135 ngx_http_script_set_var_code(ngx_http_script_engine_t *e) | |
1136 { | |
1137 ngx_http_request_t *r; | |
1138 ngx_http_script_var_code_t *code; | |
1139 | |
1140 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1141 "http script set var"); | |
1142 | |
1143 code = (ngx_http_script_var_code_t *) e->ip; | |
1144 | |
1145 e->ip += sizeof(ngx_http_script_var_code_t); | |
1146 | |
1147 r = e->request; | |
1148 | |
1149 e->sp--; | |
1150 | |
573 | 1151 r->variables[code->index].len = e->sp->len; |
1152 r->variables[code->index].valid = 1; | |
1153 r->variables[code->index].no_cachable = 0; | |
1154 r->variables[code->index].not_found = 0; | |
1155 r->variables[code->index].data = e->sp->data; | |
509 | 1156 } |
1157 | |
1158 | |
1159 void | |
637 | 1160 ngx_http_script_var_set_handler_code(ngx_http_script_engine_t *e) |
1161 { | |
1162 ngx_http_script_var_handler_code_t *code; | |
1163 | |
1164 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1165 "http script set var handler"); | |
1166 | |
1167 code = (ngx_http_script_var_handler_code_t *) e->ip; | |
1168 | |
1169 e->ip += sizeof(ngx_http_script_var_handler_code_t); | |
1170 | |
1171 e->sp--; | |
1172 | |
1173 code->handler(e->request, e->sp, code->data); | |
1174 } | |
1175 | |
1176 | |
1177 void | |
509 | 1178 ngx_http_script_var_code(ngx_http_script_engine_t *e) |
1179 { | |
1180 ngx_http_variable_value_t *value; | |
1181 ngx_http_script_var_code_t *code; | |
1182 | |
1183 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1184 "http script var"); | |
1185 | |
1186 code = (ngx_http_script_var_code_t *) e->ip; | |
1187 | |
1188 e->ip += sizeof(ngx_http_script_var_code_t); | |
1189 | |
573 | 1190 value = ngx_http_get_flushed_variable(e->request, code->index); |
509 | 1191 |
573 | 1192 if (value && !value->not_found) { |
1193 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1194 "http script var: \"%V\"", value); | |
1195 | |
553 | 1196 *e->sp = *value; |
509 | 1197 e->sp++; |
1198 | |
1199 return; | |
1200 } | |
1201 | |
577 | 1202 *e->sp = ngx_http_variable_null_value; |
509 | 1203 e->sp++; |
1204 } | |
1205 | |
1206 | |
1207 void | |
1208 ngx_http_script_nop_code(ngx_http_script_engine_t *e) | |
1209 { | |
1210 e->ip += sizeof(uintptr_t); | |
1211 } |