blob: 1918397fb005588f3278131c6724df90bdedee65 [file] [log] [blame]
Igor Sysoev7578ec92003-06-02 15:24:30 +00001
Igor Sysoevd90282d2004-09-28 08:34:51 +00002/*
Igor Sysoevff8da912004-09-29 16:00:49 +00003 * Copyright (C) Igor Sysoev
Igor Sysoevd90282d2004-09-28 08:34:51 +00004 */
5
6
Igor Sysoev7578ec92003-06-02 15:24:30 +00007#include <ngx_config.h>
8#include <ngx_core.h>
9#include <ngx_http.h>
10
11
Igor Sysoev899b44e2005-05-12 14:58:06 +000012#define ngx_http_script_exit (u_char *) &ngx_http_script_exit_code
13
14static uintptr_t ngx_http_script_exit_code = (uintptr_t) NULL;
15
16
17ngx_uint_t
18ngx_http_script_variables_count(ngx_str_t *value)
Igor Sysoev7578ec92003-06-02 15:24:30 +000019{
Igor Sysoev899b44e2005-05-12 14:58:06 +000020 ngx_uint_t i, n;
Igor Sysoev02025fd2005-01-18 13:03:58 +000021
Igor Sysoev899b44e2005-05-12 14:58:06 +000022 for (n = 0, i = 0; i < value->len; i++) {
23 if (value->data[i] == '$') {
24 n++;
25 }
Igor Sysoev02f742b2005-04-08 15:18:55 +000026 }
Igor Sysoev02025fd2005-01-18 13:03:58 +000027
Igor Sysoev899b44e2005-05-12 14:58:06 +000028 return n;
29}
30
31
32ngx_int_t
33ngx_http_script_compile(ngx_http_script_compile_t *sc)
34{
35 u_char ch;
36 size_t size;
Igor Sysoev09c684b2005-11-09 17:25:55 +000037 ngx_int_t index, *p;
Igor Sysoev899b44e2005-05-12 14:58:06 +000038 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
Igor Sysoev09c684b2005-11-09 17:25:55 +000045 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
Igor Sysoev899b44e2005-05-12 14:58:06 +000054 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) {
Igor Sysoev02f742b2005-04-08 15:18:55 +000061 return NGX_ERROR;
62 }
63 }
Igor Sysoev02025fd2005-01-18 13:03:58 +000064
Igor Sysoev899b44e2005-05-12 14:58:06 +000065
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) {
Igor Sysoev02f742b2005-04-08 15:18:55 +000076 return NGX_ERROR;
77 }
78 }
79
Igor Sysoev899b44e2005-05-12 14:58:06 +000080 sc->variables = 0;
Igor Sysoev02f742b2005-04-08 15:18:55 +000081
Igor Sysoev899b44e2005-05-12 14:58:06 +000082 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
Igor Sysoev7f7846d2006-04-26 09:52:47 +000094 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
Igor Sysoev899b44e2005-05-12 14:58:06 +0000102 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;
Igor Sysoev7f7846d2006-04-26 09:52:47 +0000111 copy_capture->n = 2 * n;
112
Igor Sysoev899b44e2005-05-12 14:58:06 +0000113
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;
Igor Sysoev7f7846d2006-04-26 09:52:47 +0000122 copy_capture->n = 2 * n;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000123
Igor Sysoev7f7846d2006-04-26 09:52:47 +0000124 if (sc->ncaptures < n) {
125 sc->ncaptures = n;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000126 }
127
Igor Sysoev899b44e2005-05-12 14:58:06 +0000128 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];
149
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);
Igor Sysoev02f742b2005-04-08 15:18:55 +0000171 return NGX_ERROR;
172 }
173
Igor Sysoev899b44e2005-05-12 14:58:06 +0000174 if (name.len == 0) {
175 goto invalid_variable;
176 }
Igor Sysoev02f742b2005-04-08 15:18:55 +0000177
Igor Sysoev899b44e2005-05-12 14:58:06 +0000178 sc->variables++;
Igor Sysoev02f742b2005-04-08 15:18:55 +0000179
Igor Sysoev899b44e2005-05-12 14:58:06 +0000180 index = ngx_http_get_variable_index(sc->cf, &name);
181
182 if (index == NGX_ERROR) {
Igor Sysoev02f742b2005-04-08 15:18:55 +0000183 return NGX_ERROR;
184 }
185
Igor Sysoev09c684b2005-11-09 17:25:55 +0000186 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
Igor Sysoev899b44e2005-05-12 14:58:06 +0000195 var_code = ngx_http_script_add_code(*sc->lengths,
196 sizeof(ngx_http_script_var_code_t),
197 NULL);
Igor Sysoev02f742b2005-04-08 15:18:55 +0000198 if (var_code == NULL) {
199 return NGX_ERROR;
200 }
201
202 var_code->code = (ngx_http_script_code_pt)
Igor Sysoev899b44e2005-05-12 14:58:06 +0000203 ngx_http_script_copy_var_len_code;
204 var_code->index = (uintptr_t) index;
Igor Sysoev02f742b2005-04-08 15:18:55 +0000205
206
Igor Sysoev899b44e2005-05-12 14:58:06 +0000207 var_code = ngx_http_script_add_code(*sc->values,
208 sizeof(ngx_http_script_var_code_t),
209 &sc->main);
Igor Sysoev02f742b2005-04-08 15:18:55 +0000210 if (var_code == NULL) {
211 return NGX_ERROR;
212 }
213
Igor Sysoev899b44e2005-05-12 14:58:06 +0000214 var_code->code = ngx_http_script_copy_var_code;
215 var_code->index = (uintptr_t) index;
Igor Sysoev02f742b2005-04-08 15:18:55 +0000216
217 continue;
218 }
219
Igor Sysoev899b44e2005-05-12 14:58:06 +0000220 if (sc->source->data[i] == '?' && sc->compile_args) {
221 sc->args = 1;
222 sc->compile_args = 0;
223
224 code = ngx_http_script_add_code(*sc->values, sizeof(uintptr_t),
225 &sc->main);
226 if (code == NULL) {
227 return NGX_ERROR;
228 }
229
230 *code = (uintptr_t) ngx_http_script_start_args_code;
231
232 i++;
233
234 continue;
235 }
236
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) {
Igor Sysoev02f742b2005-04-08 15:18:55 +0000253 return NGX_ERROR;
254 }
Igor Sysoev899b44e2005-05-12 14:58:06 +0000255
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);
262
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);
Igor Sysoev02f742b2005-04-08 15:18:55 +0000273 }
274
Igor Sysoev899b44e2005-05-12 14:58:06 +0000275 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 }
280
281 *code = (uintptr_t) NULL;
Igor Sysoev02f742b2005-04-08 15:18:55 +0000282 }
283
Igor Sysoev899b44e2005-05-12 14:58:06 +0000284 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 }
Igor Sysoev02f742b2005-04-08 15:18:55 +0000290
Igor Sysoev899b44e2005-05-12 14:58:06 +0000291 *code = (uintptr_t) NULL;
Igor Sysoev02f742b2005-04-08 15:18:55 +0000292 }
293
Igor Sysoev02f742b2005-04-08 15:18:55 +0000294 return NGX_OK;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000295
296invalid_variable:
297
298 ngx_conf_log_error(NGX_LOG_EMERG, sc->cf, 0, "invalid variable name");
299
300 return NGX_ERROR;
Igor Sysoev7578ec92003-06-02 15:24:30 +0000301}
302
303
Igor Sysoev8fea8852006-03-15 09:53:04 +0000304u_char *
305ngx_http_script_run(ngx_http_request_t *r, ngx_str_t *value,
306 void *code_lengths, size_t len, void *code_values)
307{
308 ngx_http_script_code_pt code;
309 ngx_http_script_len_code_pt lcode;
310 ngx_http_script_engine_t e;
311
312 ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
313
314 e.ip = code_lengths;
315 e.request = r;
316 e.flushed = 1;
317
318 while (*(uintptr_t *) e.ip) {
319 lcode = *(ngx_http_script_len_code_pt *) e.ip;
320 len += lcode(&e);
321 }
322
323
324 value->len = len;
325 value->data = ngx_palloc(r->pool, len);
326 if (value->data == NULL) {
327 return NULL;
328 }
329
330 e.ip = code_values;
331 e.pos = value->data;
332
333 while (*(uintptr_t *) e.ip) {
334 code = *(ngx_http_script_code_pt *) e.ip;
335 code((ngx_http_script_engine_t *) &e);
336 }
337
338 return e.pos;
339}
340
341
Igor Sysoev09c684b2005-11-09 17:25:55 +0000342void
343ngx_http_script_flush_no_cachable_variables(ngx_http_request_t *r,
344 ngx_array_t *indices)
345{
346 ngx_uint_t n, *index;
347
348 if (indices) {
349 index = indices->elts;
350 for (n = 0; n < indices->nelts; n++) {
351 if (r->variables[index[n]].no_cachable) {
352 r->variables[index[n]].valid = 0;
353 r->variables[index[n]].not_found = 0;
354 }
355 }
356 }
357}
358
359
Igor Sysoev899b44e2005-05-12 14:58:06 +0000360void *
Igor Sysoev02f742b2005-04-08 15:18:55 +0000361ngx_http_script_start_code(ngx_pool_t *pool, ngx_array_t **codes, size_t size)
Igor Sysoev7578ec92003-06-02 15:24:30 +0000362{
Igor Sysoev02f742b2005-04-08 15:18:55 +0000363 if (*codes == NULL) {
364 *codes = ngx_array_create(pool, 256, 1);
365 if (*codes == NULL) {
366 return NULL;
367 }
368 }
Igor Sysoev7578ec92003-06-02 15:24:30 +0000369
Igor Sysoev02f742b2005-04-08 15:18:55 +0000370 return ngx_array_push_n(*codes, size);
371}
Igor Sysoev7578ec92003-06-02 15:24:30 +0000372
Igor Sysoev899b44e2005-05-12 14:58:06 +0000373
374void *
375ngx_http_script_add_code(ngx_array_t *codes, size_t size, void *code)
376{
377 u_char *elts, **p;
378 void *new;
379
380 elts = codes->elts;
381
382 new = ngx_array_push_n(codes, size);
383 if (new == NULL) {
384 return NGX_CONF_ERROR;
385 }
386
387 if (code) {
388 if (elts != codes->elts) {
389 p = code;
390 *p += (u_char *) codes->elts - elts;
391 }
392 }
393
394 return new;
395}
Igor Sysoev02025fd2005-01-18 13:03:58 +0000396
Igor Sysoev02f742b2005-04-08 15:18:55 +0000397
398size_t
Igor Sysoev899b44e2005-05-12 14:58:06 +0000399ngx_http_script_copy_len_code(ngx_http_script_engine_t *e)
Igor Sysoev02f742b2005-04-08 15:18:55 +0000400{
401 ngx_http_script_copy_code_t *code;
402
Igor Sysoev899b44e2005-05-12 14:58:06 +0000403 code = (ngx_http_script_copy_code_t *) e->ip;
Igor Sysoev02f742b2005-04-08 15:18:55 +0000404
Igor Sysoev899b44e2005-05-12 14:58:06 +0000405 e->ip += sizeof(ngx_http_script_copy_code_t);
Igor Sysoev02f742b2005-04-08 15:18:55 +0000406
407 return code->len;
Igor Sysoev7578ec92003-06-02 15:24:30 +0000408}
409
410
Igor Sysoev02f742b2005-04-08 15:18:55 +0000411void
Igor Sysoev899b44e2005-05-12 14:58:06 +0000412ngx_http_script_copy_code(ngx_http_script_engine_t *e)
Igor Sysoev7578ec92003-06-02 15:24:30 +0000413{
Igor Sysoev02f742b2005-04-08 15:18:55 +0000414 ngx_http_script_copy_code_t *code;
415
Igor Sysoev899b44e2005-05-12 14:58:06 +0000416 code = (ngx_http_script_copy_code_t *) e->ip;
Igor Sysoev02f742b2005-04-08 15:18:55 +0000417
Igor Sysoev899b44e2005-05-12 14:58:06 +0000418 if (!e->skip) {
Igor Sysoev09c684b2005-11-09 17:25:55 +0000419 e->pos = ngx_copy(e->pos, e->ip + sizeof(ngx_http_script_copy_code_t),
420 code->len);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000421 }
Igor Sysoev02f742b2005-04-08 15:18:55 +0000422
Igor Sysoev899b44e2005-05-12 14:58:06 +0000423 e->ip += sizeof(ngx_http_script_copy_code_t)
424 + ((code->len + sizeof(uintptr_t) - 1) & ~(sizeof(uintptr_t) - 1));
425
426 if (e->log) {
427 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
428 "http script copy: \"%V\"", &e->buf);
429 }
Igor Sysoev7578ec92003-06-02 15:24:30 +0000430}
431
432
Igor Sysoev02f742b2005-04-08 15:18:55 +0000433size_t
Igor Sysoev899b44e2005-05-12 14:58:06 +0000434ngx_http_script_copy_var_len_code(ngx_http_script_engine_t *e)
Igor Sysoev7578ec92003-06-02 15:24:30 +0000435{
Igor Sysoev02f742b2005-04-08 15:18:55 +0000436 ngx_http_variable_value_t *value;
437 ngx_http_script_var_code_t *code;
438
Igor Sysoev899b44e2005-05-12 14:58:06 +0000439 code = (ngx_http_script_var_code_t *) e->ip;
Igor Sysoev02f742b2005-04-08 15:18:55 +0000440
Igor Sysoev899b44e2005-05-12 14:58:06 +0000441 e->ip += sizeof(ngx_http_script_var_code_t);
Igor Sysoev02f742b2005-04-08 15:18:55 +0000442
Igor Sysoev09c684b2005-11-09 17:25:55 +0000443 if (e->flushed) {
444 value = ngx_http_get_indexed_variable(e->request, code->index);
Igor Sysoev02f742b2005-04-08 15:18:55 +0000445
Igor Sysoev09c684b2005-11-09 17:25:55 +0000446 } else {
447 value = ngx_http_get_flushed_variable(e->request, code->index);
448 }
449
450 if (value && !value->not_found) {
451 return value->len;
Igor Sysoev02f742b2005-04-08 15:18:55 +0000452 }
453
Igor Sysoevf6e1fe32005-10-04 10:38:53 +0000454 return 0;
Igor Sysoev7578ec92003-06-02 15:24:30 +0000455}
456
457
Igor Sysoev02f742b2005-04-08 15:18:55 +0000458void
Igor Sysoev899b44e2005-05-12 14:58:06 +0000459ngx_http_script_copy_var_code(ngx_http_script_engine_t *e)
Igor Sysoev7578ec92003-06-02 15:24:30 +0000460{
Igor Sysoev02f742b2005-04-08 15:18:55 +0000461 ngx_http_variable_value_t *value;
462 ngx_http_script_var_code_t *code;
463
Igor Sysoev899b44e2005-05-12 14:58:06 +0000464 code = (ngx_http_script_var_code_t *) e->ip;
Igor Sysoev02f742b2005-04-08 15:18:55 +0000465
Igor Sysoev899b44e2005-05-12 14:58:06 +0000466 e->ip += sizeof(ngx_http_script_var_code_t);
Igor Sysoev02f742b2005-04-08 15:18:55 +0000467
Igor Sysoev899b44e2005-05-12 14:58:06 +0000468 if (!e->skip) {
Igor Sysoev02f742b2005-04-08 15:18:55 +0000469
Igor Sysoev09c684b2005-11-09 17:25:55 +0000470 if (e->flushed) {
471 value = ngx_http_get_indexed_variable(e->request, code->index);
472
473 } else {
474 value = ngx_http_get_flushed_variable(e->request, code->index);
475 }
476
477 if (value && !value->not_found) {
478 e->pos = ngx_copy(e->pos, value->data, value->len);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000479
Igor Sysoevf6e1fe32005-10-04 10:38:53 +0000480 if (e->log) {
481 ngx_log_debug1(NGX_LOG_DEBUG_HTTP,
482 e->request->connection->log, 0,
483 "http script var: \"%V\"", &e->buf);
484 }
Igor Sysoev899b44e2005-05-12 14:58:06 +0000485 }
486 }
487}
488
489
490size_t
491ngx_http_script_copy_capture_len_code(ngx_http_script_engine_t *e)
492{
493 ngx_http_script_copy_capture_code_t *code;
494
495 code = (ngx_http_script_copy_capture_code_t *) e->ip;
496
497 e->ip += sizeof(ngx_http_script_copy_capture_code_t);
498
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000499 if (code->n < e->ncaptures) {
500 if ((e->args || e->quote)
501 && (e->request->quoted_uri || e->request->plus_in_uri))
502 {
503 return e->captures[code->n + 1] - e->captures[code->n]
Igor Sysoevaf3b7ea2006-05-31 14:11:45 +0000504 + 2 * ngx_escape_uri(NULL,
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000505 &e->line.data[e->captures[code->n]],
Igor Sysoev899b44e2005-05-12 14:58:06 +0000506 e->captures[code->n + 1] - e->captures[code->n],
507 NGX_ESCAPE_ARGS);
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000508 } else {
509 return e->captures[code->n + 1] - e->captures[code->n];
510 }
Igor Sysoev899b44e2005-05-12 14:58:06 +0000511 }
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000512
513 return 0;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000514}
515
516
517void
518ngx_http_script_copy_capture_code(ngx_http_script_engine_t *e)
519{
520 ngx_http_script_copy_capture_code_t *code;
521
522 code = (ngx_http_script_copy_capture_code_t *) e->ip;
523
524 e->ip += sizeof(ngx_http_script_copy_capture_code_t);
525
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000526 if (code->n < e->ncaptures) {
527 if ((e->args || e->quote)
528 && (e->request->quoted_uri || e->request->plus_in_uri))
529 {
530 e->pos = (u_char *) ngx_escape_uri(e->pos,
531 &e->line.data[e->captures[code->n]],
Igor Sysoev899b44e2005-05-12 14:58:06 +0000532 e->captures[code->n + 1] - e->captures[code->n],
533 NGX_ESCAPE_ARGS);
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000534 } else {
Igor Sysoev09c684b2005-11-09 17:25:55 +0000535 e->pos = ngx_copy(e->pos,
536 &e->line.data[e->captures[code->n]],
537 e->captures[code->n + 1] - e->captures[code->n]);
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000538 }
Igor Sysoev899b44e2005-05-12 14:58:06 +0000539 }
540
541 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
542 "http script capture: \"%V\"", &e->buf);
543}
544
545
546void
547ngx_http_script_start_args_code(ngx_http_script_engine_t *e)
548{
549 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
550 "http script args");
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000551
Igor Sysoev899b44e2005-05-12 14:58:06 +0000552 e->args = e->pos;
553 e->ip += sizeof(uintptr_t);
554}
555
556
Igor Sysoev4959ec42005-05-23 12:07:45 +0000557
558#if (NGX_PCRE)
559
Igor Sysoev899b44e2005-05-12 14:58:06 +0000560void
561ngx_http_script_regex_start_code(ngx_http_script_engine_t *e)
562{
563 size_t len;
564 ngx_int_t rc;
565 ngx_uint_t n;
566 ngx_http_request_t *r;
567 ngx_http_script_engine_t le;
568 ngx_http_script_len_code_pt lcode;
569 ngx_http_script_regex_code_t *code;
570
571 code = (ngx_http_script_regex_code_t *) e->ip;
572
573 r = e->request;
574
575 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
576 "http script regex: \"%V\"", &code->name);
577
578 if (code->uri) {
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000579 e->line = r->uri;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000580 } else {
581 e->sp--;
Igor Sysoev09c684b2005-11-09 17:25:55 +0000582 e->line.len = e->sp->len;
583 e->line.data = e->sp->data;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000584 }
585
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000586 rc = ngx_regex_exec(code->regex, &e->line, e->captures, code->ncaptures);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000587
588 if (rc == NGX_REGEX_NO_MATCHED) {
589 if (e->log) {
590 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000591 "\"%V\" does not match \"%V\"",
592 &code->name, &e->line);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000593 }
594
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000595 e->ncaptures = 0;
596
Igor Sysoev899b44e2005-05-12 14:58:06 +0000597 if (code->test) {
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000598 if (code->negative_test) {
599 e->sp->len = 1;
600 e->sp->data = (u_char *) "1";
601
602 } else {
603 e->sp->len = 0;
604 e->sp->data = (u_char *) "";
605 }
606
Igor Sysoev899b44e2005-05-12 14:58:06 +0000607 e->sp++;
608
609 e->ip += sizeof(ngx_http_script_regex_code_t);
610 return;
611 }
612
613 e->ip += code->next;
Igor Sysoev02f742b2005-04-08 15:18:55 +0000614 return;
615 }
616
Igor Sysoev899b44e2005-05-12 14:58:06 +0000617 if (rc < 0) {
618 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
619 ngx_regex_exec_n " failed: %d on \"%V\" using \"%V\"",
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000620 rc, &e->line, &code->name);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000621
622 e->ip = ngx_http_script_exit;
623 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
624 return;
625 }
626
627 if (e->log) {
628 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000629 "\"%V\" matches \"%V\"", &code->name, &e->line);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000630 }
631
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000632 e->ncaptures = code->ncaptures;
633
Igor Sysoev899b44e2005-05-12 14:58:06 +0000634 if (code->test) {
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000635 if (code->negative_test) {
636 e->sp->len = 0;
637 e->sp->data = (u_char *) "";
638
639 } else {
640 e->sp->len = 1;
641 e->sp->data = (u_char *) "1";
642 }
643
Igor Sysoev899b44e2005-05-12 14:58:06 +0000644 e->sp++;
645
646 e->ip += sizeof(ngx_http_script_regex_code_t);
647 return;
648 }
649
650 if (code->status) {
651 e->status = code->status;
652
653 if (!code->redirect) {
654 e->ip = ngx_http_script_exit;
655 return;
656 }
657 }
658
659 if (code->uri) {
660 r->internal = 1;
661 r->valid_unparsed_uri = 0;
662
663 if (code->break_cycle) {
664 r->valid_location = 0;
Igor Sysoev5192b362005-07-08 14:34:20 +0000665 r->uri_changed = 0;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000666
667 } else {
668 r->uri_changed = 1;
669 }
670 }
671
672 if (code->lengths == NULL) {
673 e->buf.len = code->size;
674
675 if (code->uri) {
676 if (rc && (r->quoted_uri || r->plus_in_uri)) {
677 e->buf.len += 2 * ngx_escape_uri(NULL, r->uri.data, r->uri.len,
678 NGX_ESCAPE_ARGS);
679 }
680 }
681
682 for (n = 1; n < (ngx_uint_t) rc; n++) {
683 e->buf.len += e->captures[2 * n + 1] - e->captures[2 * n];
684 }
685
686 } else {
687 ngx_memzero(&le, sizeof(ngx_http_script_engine_t));
688
689 le.ip = code->lengths->elts;
690 le.request = r;
691 le.captures = e->captures;
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000692 le.ncaptures = e->ncaptures;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000693
694 len = 1; /* reserve 1 byte for possible "?" */
695
696 while (*(uintptr_t *) le.ip) {
697 lcode = *(ngx_http_script_len_code_pt *) le.ip;
698 len += lcode(&le);
699 }
700
701 e->buf.len = len;
702 }
703
Igor Sysoeve31e90b2005-05-19 13:25:22 +0000704 if (code->add_args && r->args.len) {
Igor Sysoev899b44e2005-05-12 14:58:06 +0000705 e->buf.len += r->args.len + 1;
706 }
707
708 e->buf.data = ngx_palloc(r->pool, e->buf.len);
709 if (e->buf.data == NULL) {
710 e->ip = ngx_http_script_exit;
711 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
712 return;
713 }
714
715 e->quote = code->redirect;
716
717 e->pos = e->buf.data;
718
719 e->ip += sizeof(ngx_http_script_regex_code_t);
720}
721
722
723void
724ngx_http_script_regex_end_code(ngx_http_script_engine_t *e)
725{
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000726 u_char *dst, *src;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000727 ngx_http_request_t *r;
728 ngx_http_script_regex_end_code_t *code;
729
730 code = (ngx_http_script_regex_end_code_t *) e->ip;
731
732 r = e->request;
733
734 e->quote = 0;
735
736 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
737 "http script regex end");
738
739 if (code->redirect) {
740
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000741 dst = e->buf.data;
742 src = e->buf.data;
743
Igor Sysoevae33d012006-01-17 20:04:32 +0000744 ngx_unescape_uri(&dst, &src, e->pos - e->buf.data, NGX_UNESCAPE_URI);
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000745
746 if (src < e->pos) {
747 dst = ngx_copy(dst, src, e->pos - src);
748 }
749
750 e->pos = dst;
751
752 if (code->add_args && r->args.len) {
Igor Sysoev899b44e2005-05-12 14:58:06 +0000753 *e->pos++ = (u_char) (code->args ? '&' : '?');
Igor Sysoev09c684b2005-11-09 17:25:55 +0000754 e->pos = ngx_copy(e->pos, r->args.data, r->args.len);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000755 }
756
757 e->buf.len = e->pos - e->buf.data;
758
759 if (e->log) {
760 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
761 "rewritten redirect: \"%V\"", &e->buf);
762 }
763
764 r->headers_out.location = ngx_list_push(&r->headers_out.headers);
765 if (r->headers_out.location == NULL) {
766 e->ip = ngx_http_script_exit;
767 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
768 return;
769 }
770
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000771 r->headers_out.location->hash = 1;
Igor Sysoev899b44e2005-05-12 14:58:06 +0000772 r->headers_out.location->key.len = sizeof("Location") - 1;
773 r->headers_out.location->key.data = (u_char *) "Location";
774 r->headers_out.location->value = e->buf;
775
776 e->ip += sizeof(ngx_http_script_regex_end_code_t);
777 return;
778 }
779
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000780 if (e->args) {
Igor Sysoev899b44e2005-05-12 14:58:06 +0000781 e->buf.len = e->args - e->buf.data;
782
783 if (code->add_args && r->args.len) {
784 *e->pos++ = '&';
Igor Sysoev09c684b2005-11-09 17:25:55 +0000785 e->pos = ngx_copy(e->pos, r->args.data, r->args.len);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000786 }
787
788 r->args.len = e->pos - e->args;
789 r->args.data = e->args;
790
791 e->args = NULL;
792
793 } else {
794 e->buf.len = e->pos - e->buf.data;
795 }
796
797 if (e->log) {
798 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
799 "rewritten data: \"%V\", args: \"%V\"",
800 &e->buf, &r->args);
801 }
802
803 if (code->uri) {
804 r->uri = e->buf;
805
Igor Sysoevb85fd592005-08-23 15:36:54 +0000806 if (r->uri.len == 0) {
807 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
808 "the rewritten URI has a zero length");
809 e->ip = ngx_http_script_exit;
810 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
811 return;
812 }
813
Igor Sysoev899b44e2005-05-12 14:58:06 +0000814 if (ngx_http_set_exten(r) != NGX_OK) {
815 e->ip = ngx_http_script_exit;
816 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
817 return;
818 }
819 }
820
821 e->ip += sizeof(ngx_http_script_regex_end_code_t);
822}
823
Igor Sysoev4959ec42005-05-23 12:07:45 +0000824#endif
825
Igor Sysoev899b44e2005-05-12 14:58:06 +0000826
827void
828ngx_http_script_return_code(ngx_http_script_engine_t *e)
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000829{
Igor Sysoev899b44e2005-05-12 14:58:06 +0000830 ngx_http_script_return_code_t *code;
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000831
Igor Sysoev899b44e2005-05-12 14:58:06 +0000832 code = (ngx_http_script_return_code_t *) e->ip;
833
834 e->status = code->status;
835
Igor Sysoevafd7ec52006-05-29 17:28:12 +0000836 if (code->status == NGX_HTTP_NO_CONTENT) {
837 e->request->header_only = 1;
838 }
839
Igor Sysoev899b44e2005-05-12 14:58:06 +0000840 e->ip += sizeof(ngx_http_script_return_code_t) - sizeof(uintptr_t);
841}
842
843
844void
Igor Sysoev5192b362005-07-08 14:34:20 +0000845ngx_http_script_break_code(ngx_http_script_engine_t *e)
846{
847 e->request->uri_changed = 0;
848
849 e->ip = ngx_http_script_exit;
850}
851
852
853void
Igor Sysoev899b44e2005-05-12 14:58:06 +0000854ngx_http_script_if_code(ngx_http_script_engine_t *e)
855{
856 ngx_http_script_if_code_t *code;
857
858 code = (ngx_http_script_if_code_t *) e->ip;
859
860 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
861 "http script if");
862
863 e->sp--;
864
Igor Sysoev09c684b2005-11-09 17:25:55 +0000865 if (e->sp->len && e->sp->data[0] != '0') {
Igor Sysoev899b44e2005-05-12 14:58:06 +0000866 if (code->loc_conf) {
867 e->request->loc_conf = code->loc_conf;
Igor Sysoevb85fd592005-08-23 15:36:54 +0000868 ngx_http_update_location_config(e->request);
Igor Sysoev899b44e2005-05-12 14:58:06 +0000869 }
870
871 e->ip += sizeof(ngx_http_script_if_code_t);
872 return;
873 }
874
875 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000876 "http script if: false");
Igor Sysoev899b44e2005-05-12 14:58:06 +0000877
878 e->ip += code->next;
879}
880
881
882void
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +0000883ngx_http_script_equal_code(ngx_http_script_engine_t *e)
884{
885 ngx_http_variable_value_t *val, *res;
886
887 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
888 "http script equal");
889
890 e->sp--;
891 val = e->sp;
892 res = e->sp - 1;
893
894 e->ip += sizeof(uintptr_t);
895
896 if (val->len == res->len && ngx_strncmp(val->data, res->data, res->len)
897 == 0)
898 {
899 *res = ngx_http_variable_true_value;
900 return;
901 }
902
903 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
904 "http script equal: no");
905
906 *res = ngx_http_variable_null_value;
907}
908
909
910void
911ngx_http_script_not_equal_code(ngx_http_script_engine_t *e)
912{
913 ngx_http_variable_value_t *val, *res;
914
915 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
916 "http script not equal");
917
918 e->sp--;
919 val = e->sp;
920 res = e->sp - 1;
921
922 e->ip += sizeof(uintptr_t);
923
924 if (val->len == res->len && ngx_strncmp(val->data, res->data, res->len)
925 == 0)
926 {
927 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
928 "http script not equal: no");
929
930 *res = ngx_http_variable_null_value;
931 return;
932 }
933
934 *res = ngx_http_variable_true_value;
935}
936
937
938void
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000939ngx_http_script_file_code(ngx_http_script_engine_t *e)
940{
941 ngx_err_t err;
942 ngx_file_info_t fi;
943 ngx_http_variable_value_t *value;
944 ngx_http_script_file_code_t *code;
945
946 value = e->sp - 1;
947
948 code = (ngx_http_script_file_code_t *) e->ip;
949 e->ip += sizeof(ngx_http_script_file_code_t);
950
951 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
952 "http script file op %p", code->op);
953
954 if (ngx_file_info(value->data, &fi) == -1) {
955 err = ngx_errno;
956
957 if (err != NGX_ENOENT && err != NGX_ENOTDIR) {
958 ngx_log_error(NGX_LOG_CRIT, e->request->connection->log, err,
959 ngx_file_info_n " \"%s\" failed", value->data);
960 }
961
962 switch (code->op) {
Igor Sysoevc55a1042006-08-09 19:59:45 +0000963
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000964 case ngx_http_script_file_plain:
Igor Sysoevb71c6902006-08-04 16:04:04 +0000965 case ngx_http_script_file_dir:
966 case ngx_http_script_file_exists:
967 case ngx_http_script_file_exec:
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000968 goto false;
Igor Sysoevc55a1042006-08-09 19:59:45 +0000969
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000970 case ngx_http_script_file_not_plain:
Igor Sysoevb71c6902006-08-04 16:04:04 +0000971 case ngx_http_script_file_not_dir:
Igor Sysoevc55a1042006-08-09 19:59:45 +0000972 case ngx_http_script_file_not_exists:
Igor Sysoevb71c6902006-08-04 16:04:04 +0000973 case ngx_http_script_file_not_exec:
Igor Sysoev94e32ce2006-04-07 14:08:04 +0000974 goto true;
975 }
976
977 goto false;
978 }
979
980 switch (code->op) {
981 case ngx_http_script_file_plain:
982 if (ngx_is_file(&fi)) {
983 goto true;
984 }
985 goto false;
986
987 case ngx_http_script_file_not_plain:
988 if (ngx_is_file(&fi)) {
989 goto false;
990 }
991 goto true;
Igor Sysoevb71c6902006-08-04 16:04:04 +0000992
993 case ngx_http_script_file_dir:
994 if (ngx_is_dir(&fi)) {
995 goto true;
996 }
997 goto false;
998
999 case ngx_http_script_file_not_dir:
1000 if (ngx_is_dir(&fi)) {
1001 goto false;
1002 }
1003 goto true;
1004
1005 case ngx_http_script_file_exists:
1006 if (ngx_is_file(&fi) || ngx_is_dir(&fi) || ngx_is_link(&fi)) {
1007 goto true;
1008 }
1009 goto false;
1010
1011 case ngx_http_script_file_not_exists:
1012 if (ngx_is_file(&fi) || ngx_is_dir(&fi) || ngx_is_link(&fi)) {
1013 goto false;
1014 }
1015 goto true;
1016
1017#if (NGX_WIN32)
1018
1019 case ngx_http_script_file_exec:
1020 goto false;
1021
1022 case ngx_http_script_file_not_exec:
1023 goto true;
1024
1025#else
1026
1027 case ngx_http_script_file_exec:
1028 if (ngx_is_exec(&fi)) {
1029 goto true;
1030 }
1031 goto false;
1032
1033 case ngx_http_script_file_not_exec:
1034 if (ngx_is_exec(&fi)) {
1035 goto false;
1036 }
1037 goto true;
1038
1039#endif
Igor Sysoev94e32ce2006-04-07 14:08:04 +00001040 }
1041
1042false:
1043
1044 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
1045 "http script file op false");
1046
1047 *value = ngx_http_variable_null_value;
1048 return;
1049
1050true:
1051
1052 *value = ngx_http_variable_true_value;
1053 return;
1054}
1055
1056
1057void
Igor Sysoeve31e90b2005-05-19 13:25:22 +00001058ngx_http_script_complex_value_code(ngx_http_script_engine_t *e)
1059{
1060 size_t len;
1061 ngx_http_script_engine_t le;
1062 ngx_http_script_len_code_pt lcode;
1063 ngx_http_script_complex_value_code_t *code;
1064
1065 code = (ngx_http_script_complex_value_code_t *) e->ip;
1066
1067 e->ip += sizeof(ngx_http_script_complex_value_code_t);
1068
1069 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
1070 "http script complex value");
1071
1072 ngx_memzero(&le, sizeof(ngx_http_script_engine_t));
1073
1074 le.ip = code->lengths->elts;
Igor Sysoevaf3b7ea2006-05-31 14:11:45 +00001075 le.line = e->line;
Igor Sysoeve31e90b2005-05-19 13:25:22 +00001076 le.request = e->request;
1077 le.captures = e->captures;
1078 le.ncaptures = e->ncaptures;
Igor Sysoevaf3b7ea2006-05-31 14:11:45 +00001079 le.quote = e->quote;
Igor Sysoeve31e90b2005-05-19 13:25:22 +00001080
1081 for (len = 0; *(uintptr_t *) le.ip; len += lcode(&le)) {
1082 lcode = *(ngx_http_script_len_code_pt *) le.ip;
1083 }
1084
1085 e->buf.len = len;
1086 e->buf.data = ngx_palloc(e->request->pool, len);
1087 if (e->buf.data == NULL) {
1088 e->ip = ngx_http_script_exit;
1089 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
1090 return;
1091 }
1092
1093 e->pos = e->buf.data;
1094
Igor Sysoev09c684b2005-11-09 17:25:55 +00001095 e->sp->len = e->buf.len;
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001096 e->sp->data = e->buf.data;
Igor Sysoeve31e90b2005-05-19 13:25:22 +00001097 e->sp++;
1098}
1099
1100
1101void
Igor Sysoev899b44e2005-05-12 14:58:06 +00001102ngx_http_script_value_code(ngx_http_script_engine_t *e)
1103{
1104 ngx_http_script_value_code_t *code;
1105
1106 code = (ngx_http_script_value_code_t *) e->ip;
1107
1108 e->ip += sizeof(ngx_http_script_value_code_t);
1109
Igor Sysoev09c684b2005-11-09 17:25:55 +00001110 e->sp->len = code->text_len;
1111 e->sp->data = (u_char *) code->text_data;
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001112
1113 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
1114 "http script value: \"%V\"", e->sp);
1115
Igor Sysoev899b44e2005-05-12 14:58:06 +00001116 e->sp++;
1117}
1118
1119
1120void
1121ngx_http_script_set_var_code(ngx_http_script_engine_t *e)
1122{
1123 ngx_http_request_t *r;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001124 ngx_http_script_var_code_t *code;
1125
1126 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
1127 "http script set var");
1128
1129 code = (ngx_http_script_var_code_t *) e->ip;
1130
1131 e->ip += sizeof(ngx_http_script_var_code_t);
1132
1133 r = e->request;
1134
Igor Sysoev899b44e2005-05-12 14:58:06 +00001135 e->sp--;
1136
Igor Sysoev09c684b2005-11-09 17:25:55 +00001137 r->variables[code->index].len = e->sp->len;
1138 r->variables[code->index].valid = 1;
1139 r->variables[code->index].no_cachable = 0;
1140 r->variables[code->index].not_found = 0;
1141 r->variables[code->index].data = e->sp->data;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001142}
1143
1144
1145void
Igor Sysoev7bdb7202006-04-19 15:30:56 +00001146ngx_http_script_var_set_handler_code(ngx_http_script_engine_t *e)
1147{
1148 ngx_http_script_var_handler_code_t *code;
1149
1150 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
1151 "http script set var handler");
1152
1153 code = (ngx_http_script_var_handler_code_t *) e->ip;
1154
1155 e->ip += sizeof(ngx_http_script_var_handler_code_t);
1156
1157 e->sp--;
1158
1159 code->handler(e->request, e->sp, code->data);
1160}
1161
1162
1163void
Igor Sysoev899b44e2005-05-12 14:58:06 +00001164ngx_http_script_var_code(ngx_http_script_engine_t *e)
1165{
1166 ngx_http_variable_value_t *value;
1167 ngx_http_script_var_code_t *code;
1168
1169 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
1170 "http script var");
1171
1172 code = (ngx_http_script_var_code_t *) e->ip;
1173
1174 e->ip += sizeof(ngx_http_script_var_code_t);
1175
Igor Sysoev09c684b2005-11-09 17:25:55 +00001176 value = ngx_http_get_flushed_variable(e->request, code->index);
Igor Sysoev899b44e2005-05-12 14:58:06 +00001177
Igor Sysoev09c684b2005-11-09 17:25:55 +00001178 if (value && !value->not_found) {
1179 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
1180 "http script var: \"%V\"", value);
1181
Igor Sysoevf6e1fe32005-10-04 10:38:53 +00001182 *e->sp = *value;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001183 e->sp++;
1184
1185 return;
1186 }
1187
Igor Sysoev0e5dc5c2005-11-15 13:30:52 +00001188 *e->sp = ngx_http_variable_null_value;
Igor Sysoev899b44e2005-05-12 14:58:06 +00001189 e->sp++;
1190}
1191
1192
1193void
1194ngx_http_script_nop_code(ngx_http_script_engine_t *e)
1195{
1196 e->ip += sizeof(uintptr_t);
Igor Sysoev7578ec92003-06-02 15:24:30 +00001197}