3 * Copyright (C) Igor Sysoev
7 #include <ngx_config.h>
12 #define ngx_http_script_exit (u_char *) &ngx_http_script_exit_code
14 static uintptr_t ngx_http_script_exit_code = (uintptr_t) NULL;
18 ngx_http_script_variables_count(ngx_str_t *value)
22 for (n = 0, i = 0; i < value->len; i++) {
23 if (value->data[i] == '$') {
33 ngx_http_script_compile(ngx_http_script_compile_t *sc)
40 ngx_uint_t i, n, bracket;
41 ngx_http_script_var_code_t *var_code;
42 ngx_http_script_copy_code_t *copy;
44 ngx_http_script_copy_capture_code_t *copy_capture;
47 if (sc->flushes && *sc->flushes == NULL) {
48 n = sc->variables ? sc->variables : 1;
49 *sc->flushes = ngx_array_create(sc->cf->pool, n, sizeof(ngx_uint_t));
50 if (*sc->flushes == NULL) {
56 if (*sc->lengths == NULL) {
57 n = sc->variables * (2 * sizeof(ngx_http_script_copy_code_t)
58 + sizeof(ngx_http_script_var_code_t))
61 *sc->lengths = ngx_array_create(sc->cf->pool, n, 1);
62 if (*sc->lengths == NULL) {
68 if (*sc->values == NULL) {
69 n = (sc->variables * (2 * sizeof(ngx_http_script_copy_code_t)
70 + sizeof(ngx_http_script_var_code_t))
73 + sizeof(uintptr_t) - 1)
74 & ~(sizeof(uintptr_t) - 1);
76 *sc->values = ngx_array_create(sc->cf->pool, n, 1);
77 if (*sc->values == NULL) {
84 for (i = 0; i < sc->source->len; /* void */ ) {
88 if (sc->source->data[i] == '$') {
90 if (++i == sc->source->len) {
91 goto invalid_variable;
96 /* NGX_HTTP_MAX_CAPTURES is 9 */
98 if (sc->source->data[i] >= '1' && sc->source->data[i] <= '9') {
100 n = sc->source->data[i] - '0';
102 if (sc->captures_mask & (1 << n)) {
106 sc->captures_mask |= 1 << n;
108 copy_capture = ngx_http_script_add_code(*sc->lengths,
109 sizeof(ngx_http_script_copy_capture_code_t),
111 if (copy_capture == NULL) {
115 copy_capture->code = (ngx_http_script_code_pt)
116 ngx_http_script_copy_capture_len_code;
117 copy_capture->n = 2 * n;
120 copy_capture = ngx_http_script_add_code(*sc->values,
121 sizeof(ngx_http_script_copy_capture_code_t),
123 if (copy_capture == NULL) {
127 copy_capture->code = ngx_http_script_copy_capture_code;
128 copy_capture->n = 2 * n;
130 if (sc->ncaptures < n) {
141 if (sc->source->data[i] == '{') {
144 if (++i == sc->source->len) {
145 goto invalid_variable;
148 name.data = &sc->source->data[i];
152 name.data = &sc->source->data[i];
155 for ( /* void */ ; i < sc->source->len; i++, name.len++) {
156 ch = sc->source->data[i];
158 if (ch == '}' && bracket) {
164 if ((ch >= 'A' && ch <= 'Z')
165 || (ch >= 'a' && ch <= 'z')
166 || (ch >= '0' && ch <= '9')
176 ngx_conf_log_error(NGX_LOG_EMERG, sc->cf, 0,
177 "the closing bracket in \"%V\" "
178 "variable is missing", &name);
183 goto invalid_variable;
188 index = ngx_http_get_variable_index(sc->cf, &name);
190 if (index == NGX_ERROR) {
195 p = ngx_array_push(*sc->flushes);
203 var_code = ngx_http_script_add_code(*sc->lengths,
204 sizeof(ngx_http_script_var_code_t),
206 if (var_code == NULL) {
210 var_code->code = (ngx_http_script_code_pt)
211 ngx_http_script_copy_var_len_code;
212 var_code->index = (uintptr_t) index;
215 var_code = ngx_http_script_add_code(*sc->values,
216 sizeof(ngx_http_script_var_code_t),
218 if (var_code == NULL) {
222 var_code->code = ngx_http_script_copy_var_code;
223 var_code->index = (uintptr_t) index;
228 if (sc->source->data[i] == '?' && sc->compile_args) {
230 sc->compile_args = 0;
232 code = ngx_http_script_add_code(*sc->lengths, sizeof(uintptr_t),
238 *code = (uintptr_t) ngx_http_script_mark_args_code;
240 code = ngx_http_script_add_code(*sc->values, sizeof(uintptr_t),
246 *code = (uintptr_t) ngx_http_script_start_args_code;
253 name.data = &sc->source->data[i];
255 while (i < sc->source->len) {
257 if (sc->source->data[i] == '$') {
261 if (sc->source->data[i] == '?') {
265 if (sc->compile_args) {
274 sc->size += name.len;
276 copy = ngx_http_script_add_code(*sc->lengths,
277 sizeof(ngx_http_script_copy_code_t),
283 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
284 copy->len = name.len;
286 size = (sizeof(ngx_http_script_copy_code_t) + name.len
287 + sizeof(uintptr_t) - 1)
288 & ~(sizeof(uintptr_t) - 1);
290 copy = ngx_http_script_add_code(*sc->values, size, &sc->main);
295 copy->code = ngx_http_script_copy_code;
296 copy->len = name.len;
298 ngx_memcpy((u_char *) copy + sizeof(ngx_http_script_copy_code_t),
299 name.data, name.len);
302 if (sc->complete_lengths) {
303 code = ngx_http_script_add_code(*sc->lengths, sizeof(uintptr_t), NULL);
308 *code = (uintptr_t) NULL;
311 if (sc->complete_values) {
312 code = ngx_http_script_add_code(*sc->values, sizeof(uintptr_t),
318 *code = (uintptr_t) NULL;
325 ngx_conf_log_error(NGX_LOG_EMERG, sc->cf, 0, "invalid variable name");
332 ngx_http_script_run(ngx_http_request_t *r, ngx_str_t *value,
333 void *code_lengths, size_t len, void *code_values)
336 ngx_http_script_code_pt code;
337 ngx_http_script_len_code_pt lcode;
338 ngx_http_script_engine_t e;
339 ngx_http_core_main_conf_t *cmcf;
341 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
343 for (i = 0; i < cmcf->variables.nelts; i++) {
344 if (r->variables[i].no_cacheable) {
345 r->variables[i].valid = 0;
346 r->variables[i].not_found = 0;
350 ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
356 while (*(uintptr_t *) e.ip) {
357 lcode = *(ngx_http_script_len_code_pt *) e.ip;
363 value->data = ngx_pnalloc(r->pool, len);
364 if (value->data == NULL) {
371 while (*(uintptr_t *) e.ip) {
372 code = *(ngx_http_script_code_pt *) e.ip;
373 code((ngx_http_script_engine_t *) &e);
381 ngx_http_script_flush_no_cacheable_variables(ngx_http_request_t *r,
382 ngx_array_t *indices)
384 ngx_uint_t n, *index;
387 index = indices->elts;
388 for (n = 0; n < indices->nelts; n++) {
389 if (r->variables[index[n]].no_cacheable) {
390 r->variables[index[n]].valid = 0;
391 r->variables[index[n]].not_found = 0;
399 ngx_http_script_start_code(ngx_pool_t *pool, ngx_array_t **codes, size_t size)
401 if (*codes == NULL) {
402 *codes = ngx_array_create(pool, 256, 1);
403 if (*codes == NULL) {
408 return ngx_array_push_n(*codes, size);
413 ngx_http_script_add_code(ngx_array_t *codes, size_t size, void *code)
420 new = ngx_array_push_n(codes, size);
422 return NGX_CONF_ERROR;
426 if (elts != codes->elts) {
428 *p += (u_char *) codes->elts - elts;
437 ngx_http_script_copy_len_code(ngx_http_script_engine_t *e)
439 ngx_http_script_copy_code_t *code;
441 code = (ngx_http_script_copy_code_t *) e->ip;
443 e->ip += sizeof(ngx_http_script_copy_code_t);
450 ngx_http_script_copy_code(ngx_http_script_engine_t *e)
453 ngx_http_script_copy_code_t *code;
455 code = (ngx_http_script_copy_code_t *) e->ip;
460 e->pos = ngx_copy(p, e->ip + sizeof(ngx_http_script_copy_code_t),
464 e->ip += sizeof(ngx_http_script_copy_code_t)
465 + ((code->len + sizeof(uintptr_t) - 1) & ~(sizeof(uintptr_t) - 1));
467 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
468 "http script copy: \"%*s\"", e->pos - p, p);
473 ngx_http_script_copy_var_len_code(ngx_http_script_engine_t *e)
475 ngx_http_variable_value_t *value;
476 ngx_http_script_var_code_t *code;
478 code = (ngx_http_script_var_code_t *) e->ip;
480 e->ip += sizeof(ngx_http_script_var_code_t);
483 value = ngx_http_get_indexed_variable(e->request, code->index);
486 value = ngx_http_get_flushed_variable(e->request, code->index);
489 if (value && !value->not_found) {
498 ngx_http_script_copy_var_code(ngx_http_script_engine_t *e)
501 ngx_http_variable_value_t *value;
502 ngx_http_script_var_code_t *code;
504 code = (ngx_http_script_var_code_t *) e->ip;
506 e->ip += sizeof(ngx_http_script_var_code_t);
511 value = ngx_http_get_indexed_variable(e->request, code->index);
514 value = ngx_http_get_flushed_variable(e->request, code->index);
517 if (value && !value->not_found) {
519 e->pos = ngx_copy(p, value->data, value->len);
521 ngx_log_debug2(NGX_LOG_DEBUG_HTTP,
522 e->request->connection->log, 0,
523 "http script var: \"%*s\"", e->pos - p, p);
530 ngx_http_script_mark_args_code(ngx_http_script_engine_t *e)
533 e->ip += sizeof(uintptr_t);
540 ngx_http_script_start_args_code(ngx_http_script_engine_t *e)
542 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
547 e->ip += sizeof(uintptr_t);
554 ngx_http_script_regex_start_code(ngx_http_script_engine_t *e)
559 ngx_http_request_t *r;
560 ngx_http_script_engine_t le;
561 ngx_http_script_len_code_pt lcode;
562 ngx_http_script_regex_code_t *code;
564 code = (ngx_http_script_regex_code_t *) e->ip;
568 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
569 "http script regex: \"%V\"", &code->name);
575 e->line.len = e->sp->len;
576 e->line.data = e->sp->data;
579 if (code->ncaptures && r->captures == NULL) {
581 r->captures = ngx_palloc(r->pool,
582 (NGX_HTTP_MAX_CAPTURES + 1) * 3 * sizeof(int));
583 if (r->captures == NULL) {
584 e->ip = ngx_http_script_exit;
585 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
590 rc = ngx_regex_exec(code->regex, &e->line, r->captures, code->ncaptures);
592 if (rc == NGX_REGEX_NO_MATCHED) {
593 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) {
594 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
595 "\"%V\" does not match \"%V\"",
596 &code->name, &e->line);
602 if (code->negative_test) {
604 e->sp->data = (u_char *) "1";
608 e->sp->data = (u_char *) "";
613 e->ip += sizeof(ngx_http_script_regex_code_t);
622 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
623 ngx_regex_exec_n " failed: %d on \"%V\" using \"%V\"",
624 rc, &e->line, &code->name);
626 e->ip = ngx_http_script_exit;
627 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
631 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) {
632 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
633 "\"%V\" matches \"%V\"", &code->name, &e->line);
636 r->ncaptures = code->ncaptures;
637 r->captures_data = e->line.data;
640 if (code->negative_test) {
642 e->sp->data = (u_char *) "";
646 e->sp->data = (u_char *) "1";
651 e->ip += sizeof(ngx_http_script_regex_code_t);
656 e->status = code->status;
658 if (!code->redirect) {
659 e->ip = ngx_http_script_exit;
666 r->valid_unparsed_uri = 0;
668 if (code->break_cycle) {
669 r->valid_location = 0;
677 if (code->lengths == NULL) {
678 e->buf.len = code->size;
681 if (rc && (r->quoted_uri || r->plus_in_uri)) {
682 e->buf.len += 2 * ngx_escape_uri(NULL, r->uri.data, r->uri.len,
687 for (n = 1; n < (ngx_uint_t) rc; n++) {
688 e->buf.len += r->captures[2 * n + 1] - r->captures[2 * n];
692 ngx_memzero(&le, sizeof(ngx_http_script_engine_t));
694 le.ip = code->lengths->elts;
697 le.quote = code->redirect;
701 while (*(uintptr_t *) le.ip) {
702 lcode = *(ngx_http_script_len_code_pt *) le.ip;
707 e->is_args = le.is_args;
710 if (code->add_args && r->args.len) {
711 e->buf.len += r->args.len + 1;
714 e->buf.data = ngx_pnalloc(r->pool, e->buf.len);
715 if (e->buf.data == NULL) {
716 e->ip = ngx_http_script_exit;
717 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
721 e->quote = code->redirect;
723 e->pos = e->buf.data;
725 e->ip += sizeof(ngx_http_script_regex_code_t);
730 ngx_http_script_regex_end_code(ngx_http_script_engine_t *e)
733 ngx_http_request_t *r;
734 ngx_http_script_regex_end_code_t *code;
736 code = (ngx_http_script_regex_end_code_t *) e->ip;
742 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
743 "http script regex end");
745 if (code->redirect) {
750 ngx_unescape_uri(&dst, &src, e->pos - e->buf.data,
751 NGX_UNESCAPE_REDIRECT);
754 dst = ngx_copy(dst, src, e->pos - src);
759 if (code->add_args && r->args.len) {
760 *e->pos++ = (u_char) (code->args ? '&' : '?');
761 e->pos = ngx_copy(e->pos, r->args.data, r->args.len);
764 e->buf.len = e->pos - e->buf.data;
766 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) {
767 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
768 "rewritten redirect: \"%V\"", &e->buf);
771 r->headers_out.location = ngx_list_push(&r->headers_out.headers);
772 if (r->headers_out.location == NULL) {
773 e->ip = ngx_http_script_exit;
774 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
778 r->headers_out.location->hash = 1;
779 r->headers_out.location->key.len = sizeof("Location") - 1;
780 r->headers_out.location->key.data = (u_char *) "Location";
781 r->headers_out.location->value = e->buf;
783 e->ip += sizeof(ngx_http_script_regex_end_code_t);
788 e->buf.len = e->args - e->buf.data;
790 if (code->add_args && r->args.len) {
792 e->pos = ngx_copy(e->pos, r->args.data, r->args.len);
795 r->args.len = e->pos - e->args;
796 r->args.data = e->args;
801 e->buf.len = e->pos - e->buf.data;
803 if (!code->add_args) {
808 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) {
809 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
810 "rewritten data: \"%V\", args: \"%V\"",
817 if (r->uri.len == 0) {
818 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
819 "the rewritten URI has a zero length");
820 e->ip = ngx_http_script_exit;
821 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
825 if (ngx_http_set_exten(r) != NGX_OK) {
826 e->ip = ngx_http_script_exit;
827 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
832 e->ip += sizeof(ngx_http_script_regex_end_code_t);
837 ngx_http_script_copy_capture_len_code(ngx_http_script_engine_t *e)
842 ngx_http_request_t *r;
843 ngx_http_script_copy_capture_code_t *code;
847 code = (ngx_http_script_copy_capture_code_t *) e->ip;
849 e->ip += sizeof(ngx_http_script_copy_capture_code_t);
853 if (n < r->ncaptures) {
857 if ((e->is_args || e->quote)
858 && (e->request->quoted_uri || e->request->plus_in_uri))
860 p = r->captures_data;
862 return cap[n + 1] - cap[n]
863 + 2 * ngx_escape_uri(NULL, &p[cap[n]], cap[n + 1] - cap[n],
866 return cap[n + 1] - cap[n];
875 ngx_http_script_copy_capture_code(ngx_http_script_engine_t *e)
880 ngx_http_request_t *r;
881 ngx_http_script_copy_capture_code_t *code;
885 code = (ngx_http_script_copy_capture_code_t *) e->ip;
887 e->ip += sizeof(ngx_http_script_copy_capture_code_t);
893 if (n < r->ncaptures) {
896 p = r->captures_data;
898 if ((e->is_args || e->quote)
899 && (e->request->quoted_uri || e->request->plus_in_uri))
901 e->pos = (u_char *) ngx_escape_uri(pos, &p[cap[n]],
905 e->pos = ngx_copy(pos, &p[cap[n]], cap[n + 1] - cap[n]);
909 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
910 "http script capture: \"%*s\"", e->pos - pos, pos);
917 ngx_http_script_return_code(ngx_http_script_engine_t *e)
919 ngx_http_script_return_code_t *code;
921 code = (ngx_http_script_return_code_t *) e->ip;
923 e->status = code->status;
925 if (code->status == NGX_HTTP_NO_CONTENT) {
926 e->request->header_only = 1;
927 e->request->zero_body = 1;
930 e->ip += sizeof(ngx_http_script_return_code_t) - sizeof(uintptr_t);
935 ngx_http_script_break_code(ngx_http_script_engine_t *e)
937 e->request->uri_changed = 0;
939 e->ip = ngx_http_script_exit;
944 ngx_http_script_if_code(ngx_http_script_engine_t *e)
946 ngx_http_script_if_code_t *code;
948 code = (ngx_http_script_if_code_t *) e->ip;
950 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
955 if (e->sp->len && e->sp->data[0] != '0') {
956 if (code->loc_conf) {
957 e->request->loc_conf = code->loc_conf;
958 ngx_http_update_location_config(e->request);
961 e->ip += sizeof(ngx_http_script_if_code_t);
965 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
966 "http script if: false");
973 ngx_http_script_equal_code(ngx_http_script_engine_t *e)
975 ngx_http_variable_value_t *val, *res;
977 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
978 "http script equal");
984 e->ip += sizeof(uintptr_t);
986 if (val->len == res->len
987 && ngx_strncmp(val->data, res->data, res->len) == 0)
989 *res = ngx_http_variable_true_value;
993 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
994 "http script equal: no");
996 *res = ngx_http_variable_null_value;
1001 ngx_http_script_not_equal_code(ngx_http_script_engine_t *e)
1003 ngx_http_variable_value_t *val, *res;
1005 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
1006 "http script not equal");
1012 e->ip += sizeof(uintptr_t);
1014 if (val->len == res->len
1015 && ngx_strncmp(val->data, res->data, res->len) == 0)
1017 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
1018 "http script not equal: no");
1020 *res = ngx_http_variable_null_value;
1024 *res = ngx_http_variable_true_value;
1029 ngx_http_script_file_code(ngx_http_script_engine_t *e)
1032 ngx_http_request_t *r;
1033 ngx_open_file_info_t of;
1034 ngx_http_core_loc_conf_t *clcf;
1035 ngx_http_variable_value_t *value;
1036 ngx_http_script_file_code_t *code;
1040 code = (ngx_http_script_file_code_t *) e->ip;
1041 e->ip += sizeof(ngx_http_script_file_code_t);
1043 path.len = value->len - 1;
1044 path.data = value->data;
1048 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1049 "http script file op %p \"%V\"", code->op, &path);
1051 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1053 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
1055 of.directio = clcf->directio;
1056 of.valid = clcf->open_file_cache_valid;
1057 of.min_uses = clcf->open_file_cache_min_uses;
1058 of.errors = clcf->open_file_cache_errors;
1059 of.events = clcf->open_file_cache_events;
1061 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
1064 if (of.err != NGX_ENOENT && of.err != NGX_ENOTDIR) {
1065 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
1066 ngx_file_info_n " \"%s\" failed", value->data);
1071 case ngx_http_script_file_plain:
1072 case ngx_http_script_file_dir:
1073 case ngx_http_script_file_exists:
1074 case ngx_http_script_file_exec:
1077 case ngx_http_script_file_not_plain:
1078 case ngx_http_script_file_not_dir:
1079 case ngx_http_script_file_not_exists:
1080 case ngx_http_script_file_not_exec:
1088 case ngx_http_script_file_plain:
1094 case ngx_http_script_file_not_plain:
1100 case ngx_http_script_file_dir:
1106 case ngx_http_script_file_not_dir:
1112 case ngx_http_script_file_exists:
1113 if (of.is_file || of.is_dir || of.is_link) {
1118 case ngx_http_script_file_not_exists:
1119 if (of.is_file || of.is_dir || of.is_link) {
1124 case ngx_http_script_file_exec:
1130 case ngx_http_script_file_not_exec:
1139 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1140 "http script file op false");
1142 *value = ngx_http_variable_null_value;
1147 *value = ngx_http_variable_true_value;
1153 ngx_http_script_complex_value_code(ngx_http_script_engine_t *e)
1156 ngx_http_script_engine_t le;
1157 ngx_http_script_len_code_pt lcode;
1158 ngx_http_script_complex_value_code_t *code;
1160 code = (ngx_http_script_complex_value_code_t *) e->ip;
1162 e->ip += sizeof(ngx_http_script_complex_value_code_t);
1164 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
1165 "http script complex value");
1167 ngx_memzero(&le, sizeof(ngx_http_script_engine_t));
1169 le.ip = code->lengths->elts;
1171 le.request = e->request;
1172 le.quote = e->quote;
1174 for (len = 0; *(uintptr_t *) le.ip; len += lcode(&le)) {
1175 lcode = *(ngx_http_script_len_code_pt *) le.ip;
1179 e->buf.data = ngx_pnalloc(e->request->pool, len);
1180 if (e->buf.data == NULL) {
1181 e->ip = ngx_http_script_exit;
1182 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
1186 e->pos = e->buf.data;
1188 e->sp->len = e->buf.len;
1189 e->sp->data = e->buf.data;
1195 ngx_http_script_value_code(ngx_http_script_engine_t *e)
1197 ngx_http_script_value_code_t *code;
1199 code = (ngx_http_script_value_code_t *) e->ip;
1201 e->ip += sizeof(ngx_http_script_value_code_t);
1203 e->sp->len = code->text_len;
1204 e->sp->data = (u_char *) code->text_data;
1206 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
1207 "http script value: \"%v\"", e->sp);
1214 ngx_http_script_set_var_code(ngx_http_script_engine_t *e)
1216 ngx_http_request_t *r;
1217 ngx_http_script_var_code_t *code;
1219 code = (ngx_http_script_var_code_t *) e->ip;
1221 e->ip += sizeof(ngx_http_script_var_code_t);
1227 r->variables[code->index].len = e->sp->len;
1228 r->variables[code->index].valid = 1;
1229 r->variables[code->index].no_cacheable = 0;
1230 r->variables[code->index].not_found = 0;
1231 r->variables[code->index].data = e->sp->data;
1235 ngx_http_variable_t *v;
1236 ngx_http_core_main_conf_t *cmcf;
1238 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
1240 v = cmcf->variables.elts;
1242 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
1243 "http script set $%V", &v[code->index].name);
1250 ngx_http_script_var_set_handler_code(ngx_http_script_engine_t *e)
1252 ngx_http_script_var_handler_code_t *code;
1254 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
1255 "http script set var handler");
1257 code = (ngx_http_script_var_handler_code_t *) e->ip;
1259 e->ip += sizeof(ngx_http_script_var_handler_code_t);
1263 code->handler(e->request, e->sp, code->data);
1268 ngx_http_script_var_code(ngx_http_script_engine_t *e)
1270 ngx_http_variable_value_t *value;
1271 ngx_http_script_var_code_t *code;
1273 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
1276 code = (ngx_http_script_var_code_t *) e->ip;
1278 e->ip += sizeof(ngx_http_script_var_code_t);
1280 value = ngx_http_get_flushed_variable(e->request, code->index);
1282 if (value && !value->not_found) {
1283 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
1284 "http script var: \"%v\"", value);
1292 *e->sp = ngx_http_variable_null_value;
1298 ngx_http_script_nop_code(ngx_http_script_engine_t *e)
1300 e->ip += sizeof(uintptr_t);