Mercurial > hg > nginx-vendor-current
comparison src/http/ngx_http_script.c @ 430:dac47e9ef0d5 NGINX_0_7_27
nginx 0.7.27
*) Feature: the "try_files" directive.
*) Feature: variables support in the "fastcgi_pass" directive.
*) Feature: now the $geo variable may get an address from a
variable.
Thanks to Andrei Nigmatulin.
*) Feature: now a location's modifier may be used without space before
name.
*) Feature: the $upstream_response_length variable.
*) Bugfix: now a "add_header" directive does not add an empty value.
*) Bugfix: if zero length static file was requested, then nginx just
closed connection; the bug had appeared in 0.7.25.
*) Bugfix: a MOVE method could not move file in non-existent directory.
*) Bugfix: a segmentation fault occurred in worker process, if no one
named location was defined in server, but some one was used in an
error_page directive.
Thanks to Sergey Bochenkov.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 15 Dec 2008 00:00:00 +0300 |
parents | a094317ba307 |
children | 33394d1255b0 |
comparison
equal
deleted
inserted
replaced
429:3b8e9d1bc9bb | 430:dac47e9ef0d5 |
---|---|
428 | 428 |
429 | 429 |
430 void | 430 void |
431 ngx_http_script_copy_code(ngx_http_script_engine_t *e) | 431 ngx_http_script_copy_code(ngx_http_script_engine_t *e) |
432 { | 432 { |
433 u_char *p; | |
433 ngx_http_script_copy_code_t *code; | 434 ngx_http_script_copy_code_t *code; |
434 | 435 |
435 code = (ngx_http_script_copy_code_t *) e->ip; | 436 code = (ngx_http_script_copy_code_t *) e->ip; |
436 | 437 |
438 p = e->pos; | |
439 | |
437 if (!e->skip) { | 440 if (!e->skip) { |
438 e->pos = ngx_copy(e->pos, e->ip + sizeof(ngx_http_script_copy_code_t), | 441 e->pos = ngx_copy(p, e->ip + sizeof(ngx_http_script_copy_code_t), |
439 code->len); | 442 code->len); |
440 } | 443 } |
441 | 444 |
442 e->ip += sizeof(ngx_http_script_copy_code_t) | 445 e->ip += sizeof(ngx_http_script_copy_code_t) |
443 + ((code->len + sizeof(uintptr_t) - 1) & ~(sizeof(uintptr_t) - 1)); | 446 + ((code->len + sizeof(uintptr_t) - 1) & ~(sizeof(uintptr_t) - 1)); |
444 | 447 |
445 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | 448 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, |
446 "http script copy: \"%V\"", &e->buf); | 449 "http script copy: \"%*s\"", e->pos - p, p); |
447 } | 450 } |
448 | 451 |
449 | 452 |
450 size_t | 453 size_t |
451 ngx_http_script_copy_var_len_code(ngx_http_script_engine_t *e) | 454 ngx_http_script_copy_var_len_code(ngx_http_script_engine_t *e) |
473 | 476 |
474 | 477 |
475 void | 478 void |
476 ngx_http_script_copy_var_code(ngx_http_script_engine_t *e) | 479 ngx_http_script_copy_var_code(ngx_http_script_engine_t *e) |
477 { | 480 { |
481 u_char *p; | |
478 ngx_http_variable_value_t *value; | 482 ngx_http_variable_value_t *value; |
479 ngx_http_script_var_code_t *code; | 483 ngx_http_script_var_code_t *code; |
480 | 484 |
481 code = (ngx_http_script_var_code_t *) e->ip; | 485 code = (ngx_http_script_var_code_t *) e->ip; |
482 | 486 |
490 } else { | 494 } else { |
491 value = ngx_http_get_flushed_variable(e->request, code->index); | 495 value = ngx_http_get_flushed_variable(e->request, code->index); |
492 } | 496 } |
493 | 497 |
494 if (value && !value->not_found) { | 498 if (value && !value->not_found) { |
495 e->pos = ngx_copy(e->pos, value->data, value->len); | 499 p = e->pos; |
496 | 500 e->pos = ngx_copy(p, value->data, value->len); |
497 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, | 501 |
502 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, | |
498 e->request->connection->log, 0, | 503 e->request->connection->log, 0, |
499 "http script var: \"%V\"", &e->buf); | 504 "http script var: \"%*s\"", e->pos - p, p); |
500 } | 505 } |
501 } | 506 } |
502 } | 507 } |
503 | 508 |
504 | 509 |
530 | 535 |
531 | 536 |
532 void | 537 void |
533 ngx_http_script_copy_capture_code(ngx_http_script_engine_t *e) | 538 ngx_http_script_copy_capture_code(ngx_http_script_engine_t *e) |
534 { | 539 { |
540 u_char *p; | |
535 ngx_http_script_copy_capture_code_t *code; | 541 ngx_http_script_copy_capture_code_t *code; |
536 | 542 |
537 code = (ngx_http_script_copy_capture_code_t *) e->ip; | 543 code = (ngx_http_script_copy_capture_code_t *) e->ip; |
538 | 544 |
539 e->ip += sizeof(ngx_http_script_copy_capture_code_t); | 545 e->ip += sizeof(ngx_http_script_copy_capture_code_t); |
546 | |
547 p = e->pos; | |
540 | 548 |
541 if (code->n < e->ncaptures) { | 549 if (code->n < e->ncaptures) { |
542 if ((e->is_args || e->quote) | 550 if ((e->is_args || e->quote) |
543 && (e->request->quoted_uri || e->request->plus_in_uri)) | 551 && (e->request->quoted_uri || e->request->plus_in_uri)) |
544 { | 552 { |
545 e->pos = (u_char *) ngx_escape_uri(e->pos, | 553 e->pos = (u_char *) ngx_escape_uri(p, |
546 &e->line.data[e->captures[code->n]], | 554 &e->line.data[e->captures[code->n]], |
547 e->captures[code->n + 1] - e->captures[code->n], | 555 e->captures[code->n + 1] - e->captures[code->n], |
548 NGX_ESCAPE_ARGS); | 556 NGX_ESCAPE_ARGS); |
549 } else { | 557 } else { |
550 e->pos = ngx_copy(e->pos, | 558 e->pos = ngx_copy(p, |
551 &e->line.data[e->captures[code->n]], | 559 &e->line.data[e->captures[code->n]], |
552 e->captures[code->n + 1] - e->captures[code->n]); | 560 e->captures[code->n + 1] - e->captures[code->n]); |
553 } | 561 } |
554 } | 562 } |
555 | 563 |
556 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | 564 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, |
557 "http script capture: \"%V\"", &e->buf); | 565 "http script capture: \"%*s\"", e->pos - p, p); |
558 } | 566 } |
559 | 567 |
560 | 568 |
561 size_t | 569 size_t |
562 ngx_http_script_mark_args_code(ngx_http_script_engine_t *e) | 570 ngx_http_script_mark_args_code(ngx_http_script_engine_t *e) |
610 } | 618 } |
611 | 619 |
612 rc = ngx_regex_exec(code->regex, &e->line, e->captures, code->ncaptures); | 620 rc = ngx_regex_exec(code->regex, &e->line, e->captures, code->ncaptures); |
613 | 621 |
614 if (rc == NGX_REGEX_NO_MATCHED) { | 622 if (rc == NGX_REGEX_NO_MATCHED) { |
615 if (e->log) { | 623 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) { |
616 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | 624 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, |
617 "\"%V\" does not match \"%V\"", | 625 "\"%V\" does not match \"%V\"", |
618 &code->name, &e->line); | 626 &code->name, &e->line); |
619 } | 627 } |
620 | 628 |
648 e->ip = ngx_http_script_exit; | 656 e->ip = ngx_http_script_exit; |
649 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | 657 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; |
650 return; | 658 return; |
651 } | 659 } |
652 | 660 |
653 if (e->log) { | 661 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) { |
654 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | 662 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, |
655 "\"%V\" matches \"%V\"", &code->name, &e->line); | 663 "\"%V\" matches \"%V\"", &code->name, &e->line); |
656 } | 664 } |
657 | 665 |
658 e->ncaptures = code->ncaptures; | 666 e->ncaptures = code->ncaptures; |
784 e->pos = ngx_copy(e->pos, r->args.data, r->args.len); | 792 e->pos = ngx_copy(e->pos, r->args.data, r->args.len); |
785 } | 793 } |
786 | 794 |
787 e->buf.len = e->pos - e->buf.data; | 795 e->buf.len = e->pos - e->buf.data; |
788 | 796 |
789 if (e->log) { | 797 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) { |
790 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | 798 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, |
791 "rewritten redirect: \"%V\"", &e->buf); | 799 "rewritten redirect: \"%V\"", &e->buf); |
792 } | 800 } |
793 | 801 |
794 r->headers_out.location = ngx_list_push(&r->headers_out.headers); | 802 r->headers_out.location = ngx_list_push(&r->headers_out.headers); |
826 if (!code->add_args) { | 834 if (!code->add_args) { |
827 r->args.len = 0; | 835 r->args.len = 0; |
828 } | 836 } |
829 } | 837 } |
830 | 838 |
831 if (e->log) { | 839 if (e->log || (r->connection->log->log_level & NGX_LOG_DEBUG_HTTP)) { |
832 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | 840 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, |
833 "rewritten data: \"%V\", args: \"%V\"", | 841 "rewritten data: \"%V\", args: \"%V\"", |
834 &e->buf, &r->args); | 842 &e->buf, &r->args); |
835 } | 843 } |
836 | 844 |
926 val = e->sp; | 934 val = e->sp; |
927 res = e->sp - 1; | 935 res = e->sp - 1; |
928 | 936 |
929 e->ip += sizeof(uintptr_t); | 937 e->ip += sizeof(uintptr_t); |
930 | 938 |
931 if (val->len == res->len && ngx_strncmp(val->data, res->data, res->len) | 939 if (val->len == res->len |
932 == 0) | 940 && ngx_strncmp(val->data, res->data, res->len) == 0) |
933 { | 941 { |
934 *res = ngx_http_variable_true_value; | 942 *res = ngx_http_variable_true_value; |
935 return; | 943 return; |
936 } | 944 } |
937 | 945 |
954 val = e->sp; | 962 val = e->sp; |
955 res = e->sp - 1; | 963 res = e->sp - 1; |
956 | 964 |
957 e->ip += sizeof(uintptr_t); | 965 e->ip += sizeof(uintptr_t); |
958 | 966 |
959 if (val->len == res->len && ngx_strncmp(val->data, res->data, res->len) | 967 if (val->len == res->len |
960 == 0) | 968 && ngx_strncmp(val->data, res->data, res->len) == 0) |
961 { | 969 { |
962 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | 970 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, |
963 "http script not equal: no"); | 971 "http script not equal: no"); |
964 | 972 |
965 *res = ngx_http_variable_null_value; | 973 *res = ngx_http_variable_null_value; |
1161 ngx_http_script_set_var_code(ngx_http_script_engine_t *e) | 1169 ngx_http_script_set_var_code(ngx_http_script_engine_t *e) |
1162 { | 1170 { |
1163 ngx_http_request_t *r; | 1171 ngx_http_request_t *r; |
1164 ngx_http_script_var_code_t *code; | 1172 ngx_http_script_var_code_t *code; |
1165 | 1173 |
1166 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1167 "http script set var"); | |
1168 | |
1169 code = (ngx_http_script_var_code_t *) e->ip; | 1174 code = (ngx_http_script_var_code_t *) e->ip; |
1170 | 1175 |
1171 e->ip += sizeof(ngx_http_script_var_code_t); | 1176 e->ip += sizeof(ngx_http_script_var_code_t); |
1172 | 1177 |
1173 r = e->request; | 1178 r = e->request; |
1177 r->variables[code->index].len = e->sp->len; | 1182 r->variables[code->index].len = e->sp->len; |
1178 r->variables[code->index].valid = 1; | 1183 r->variables[code->index].valid = 1; |
1179 r->variables[code->index].no_cacheable = 0; | 1184 r->variables[code->index].no_cacheable = 0; |
1180 r->variables[code->index].not_found = 0; | 1185 r->variables[code->index].not_found = 0; |
1181 r->variables[code->index].data = e->sp->data; | 1186 r->variables[code->index].data = e->sp->data; |
1187 | |
1188 #if (NGX_DEBUG) | |
1189 { | |
1190 ngx_http_variable_t *v; | |
1191 ngx_http_core_main_conf_t *cmcf; | |
1192 | |
1193 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
1194 | |
1195 v = cmcf->variables.elts; | |
1196 | |
1197 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1198 "http script set $%V", &v[code->index].name); | |
1199 } | |
1200 #endif | |
1182 } | 1201 } |
1183 | 1202 |
1184 | 1203 |
1185 void | 1204 void |
1186 ngx_http_script_var_set_handler_code(ngx_http_script_engine_t *e) | 1205 ngx_http_script_var_set_handler_code(ngx_http_script_engine_t *e) |