Mercurial > hg > nginx
comparison src/http/ngx_http_script.c @ 2393:fbff569bf456
fix debug logging
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 10 Dec 2008 14:48:04 +0000 |
parents | 207827f7bf71 |
children | da6f70bb41f0 |
comparison
equal
deleted
inserted
replaced
2392:3530e5bd4826 | 2393:fbff569bf456 |
---|---|
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) |
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 |
797 #if (NGX_DEBUG) | |
798 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | |
799 "rewritten redirect: \"%V\"", &e->buf); | |
800 #else | |
789 if (e->log) { | 801 if (e->log) { |
790 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | 802 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, |
791 "rewritten redirect: \"%V\"", &e->buf); | 803 "rewritten redirect: \"%V\"", &e->buf); |
792 } | 804 } |
805 #endif | |
793 | 806 |
794 r->headers_out.location = ngx_list_push(&r->headers_out.headers); | 807 r->headers_out.location = ngx_list_push(&r->headers_out.headers); |
795 if (r->headers_out.location == NULL) { | 808 if (r->headers_out.location == NULL) { |
796 e->ip = ngx_http_script_exit; | 809 e->ip = ngx_http_script_exit; |
797 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | 810 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; |
826 if (!code->add_args) { | 839 if (!code->add_args) { |
827 r->args.len = 0; | 840 r->args.len = 0; |
828 } | 841 } |
829 } | 842 } |
830 | 843 |
844 #if (NGX_DEBUG) | |
845 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | |
846 "rewritten data: \"%V\", args: \"%V\"", &e->buf, &r->args); | |
847 #else | |
831 if (e->log) { | 848 if (e->log) { |
832 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | 849 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, |
833 "rewritten data: \"%V\", args: \"%V\"", | 850 "rewritten data: \"%V\", args: \"%V\"", |
834 &e->buf, &r->args); | 851 &e->buf, &r->args); |
835 } | 852 } |
853 #endif | |
836 | 854 |
837 if (code->uri) { | 855 if (code->uri) { |
838 r->uri = e->buf; | 856 r->uri = e->buf; |
839 | 857 |
840 if (r->uri.len == 0) { | 858 if (r->uri.len == 0) { |
926 val = e->sp; | 944 val = e->sp; |
927 res = e->sp - 1; | 945 res = e->sp - 1; |
928 | 946 |
929 e->ip += sizeof(uintptr_t); | 947 e->ip += sizeof(uintptr_t); |
930 | 948 |
931 if (val->len == res->len && ngx_strncmp(val->data, res->data, res->len) | 949 if (val->len == res->len |
932 == 0) | 950 && ngx_strncmp(val->data, res->data, res->len) == 0) |
933 { | 951 { |
934 *res = ngx_http_variable_true_value; | 952 *res = ngx_http_variable_true_value; |
935 return; | 953 return; |
936 } | 954 } |
937 | 955 |
954 val = e->sp; | 972 val = e->sp; |
955 res = e->sp - 1; | 973 res = e->sp - 1; |
956 | 974 |
957 e->ip += sizeof(uintptr_t); | 975 e->ip += sizeof(uintptr_t); |
958 | 976 |
959 if (val->len == res->len && ngx_strncmp(val->data, res->data, res->len) | 977 if (val->len == res->len |
960 == 0) | 978 && ngx_strncmp(val->data, res->data, res->len) == 0) |
961 { | 979 { |
962 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | 980 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, |
963 "http script not equal: no"); | 981 "http script not equal: no"); |
964 | 982 |
965 *res = ngx_http_variable_null_value; | 983 *res = ngx_http_variable_null_value; |
1161 ngx_http_script_set_var_code(ngx_http_script_engine_t *e) | 1179 ngx_http_script_set_var_code(ngx_http_script_engine_t *e) |
1162 { | 1180 { |
1163 ngx_http_request_t *r; | 1181 ngx_http_request_t *r; |
1164 ngx_http_script_var_code_t *code; | 1182 ngx_http_script_var_code_t *code; |
1165 | 1183 |
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; | 1184 code = (ngx_http_script_var_code_t *) e->ip; |
1170 | 1185 |
1171 e->ip += sizeof(ngx_http_script_var_code_t); | 1186 e->ip += sizeof(ngx_http_script_var_code_t); |
1172 | 1187 |
1173 r = e->request; | 1188 r = e->request; |
1177 r->variables[code->index].len = e->sp->len; | 1192 r->variables[code->index].len = e->sp->len; |
1178 r->variables[code->index].valid = 1; | 1193 r->variables[code->index].valid = 1; |
1179 r->variables[code->index].no_cacheable = 0; | 1194 r->variables[code->index].no_cacheable = 0; |
1180 r->variables[code->index].not_found = 0; | 1195 r->variables[code->index].not_found = 0; |
1181 r->variables[code->index].data = e->sp->data; | 1196 r->variables[code->index].data = e->sp->data; |
1197 | |
1198 #if (NGX_DEBUG) | |
1199 { | |
1200 ngx_http_variable_t *v; | |
1201 ngx_http_core_main_conf_t *cmcf; | |
1202 | |
1203 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
1204 | |
1205 v = cmcf->variables.elts; | |
1206 | |
1207 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
1208 "http script set $%V", &v[code->index].name); | |
1209 } | |
1210 #endif | |
1182 } | 1211 } |
1183 | 1212 |
1184 | 1213 |
1185 void | 1214 void |
1186 ngx_http_script_var_set_handler_code(ngx_http_script_engine_t *e) | 1215 ngx_http_script_var_set_handler_code(ngx_http_script_engine_t *e) |