Mercurial > hg > nginx
comparison src/http/ngx_http_script.c @ 515:417a087c9c4d release-0.1.32
nginx-0.1.32-RELEASE import
*) Bugfix: the arguments were omitted in the redirects, issued by the
"rewrite" directive; the bug had appeared in 0.1.29.
*) Feature: the "if" directive supports the captures in regular
expressions.
*) Feature: the "set" directive supports the variables and the captures
of regular expressions.
*) Feature: the "X-Accel-Redirect" response header line is supported in
proxy and FastCGI mode.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 19 May 2005 13:25:22 +0000 |
parents | 9b8c906f6e63 |
children | dadfa78d2270 |
comparison
equal
deleted
inserted
replaced
514:88d593732655 | 515:417a087c9c4d |
---|---|
403 | 403 |
404 code = (ngx_http_script_copy_capture_code_t *) e->ip; | 404 code = (ngx_http_script_copy_capture_code_t *) e->ip; |
405 | 405 |
406 e->ip += sizeof(ngx_http_script_copy_capture_code_t); | 406 e->ip += sizeof(ngx_http_script_copy_capture_code_t); |
407 | 407 |
408 if ((e->args || e->quote) | 408 if (code->n < e->ncaptures) { |
409 && (e->request->quoted_uri || e->request->plus_in_uri)) | 409 if ((e->args || e->quote) |
410 { | 410 && (e->request->quoted_uri || e->request->plus_in_uri)) |
411 return e->captures[code->n + 1] - e->captures[code->n] | 411 { |
412 + ngx_escape_uri(NULL, | 412 return e->captures[code->n + 1] - e->captures[code->n] |
413 &e->line->data[e->captures[code->n]], | 413 + ngx_escape_uri(NULL, |
414 &e->line.data[e->captures[code->n]], | |
414 e->captures[code->n + 1] - e->captures[code->n], | 415 e->captures[code->n + 1] - e->captures[code->n], |
415 NGX_ESCAPE_ARGS); | 416 NGX_ESCAPE_ARGS); |
416 } else { | 417 } else { |
417 return e->captures[code->n + 1] - e->captures[code->n]; | 418 return e->captures[code->n + 1] - e->captures[code->n]; |
418 } | 419 } |
420 } | |
421 | |
422 return 0; | |
419 } | 423 } |
420 | 424 |
421 | 425 |
422 void | 426 void |
423 ngx_http_script_copy_capture_code(ngx_http_script_engine_t *e) | 427 ngx_http_script_copy_capture_code(ngx_http_script_engine_t *e) |
426 | 430 |
427 code = (ngx_http_script_copy_capture_code_t *) e->ip; | 431 code = (ngx_http_script_copy_capture_code_t *) e->ip; |
428 | 432 |
429 e->ip += sizeof(ngx_http_script_copy_capture_code_t); | 433 e->ip += sizeof(ngx_http_script_copy_capture_code_t); |
430 | 434 |
431 if ((e->args || e->quote) | 435 if (code->n < e->ncaptures) { |
432 && (e->request->quoted_uri || e->request->plus_in_uri)) | 436 if ((e->args || e->quote) |
433 { | 437 && (e->request->quoted_uri || e->request->plus_in_uri)) |
434 e->pos = (u_char *) ngx_escape_uri(e->pos, | 438 { |
435 &e->line->data[e->captures[code->n]], | 439 e->pos = (u_char *) ngx_escape_uri(e->pos, |
440 &e->line.data[e->captures[code->n]], | |
436 e->captures[code->n + 1] - e->captures[code->n], | 441 e->captures[code->n + 1] - e->captures[code->n], |
437 NGX_ESCAPE_ARGS); | 442 NGX_ESCAPE_ARGS); |
438 } else { | 443 } else { |
439 e->pos = ngx_cpymem(e->pos, | 444 e->pos = ngx_cpymem(e->pos, |
440 &e->line->data[e->captures[code->n]], | 445 &e->line.data[e->captures[code->n]], |
441 e->captures[code->n + 1] - e->captures[code->n]); | 446 e->captures[code->n + 1] - e->captures[code->n]); |
447 } | |
442 } | 448 } |
443 | 449 |
444 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | 450 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, |
445 "http script capture: \"%V\"", &e->buf); | 451 "http script capture: \"%V\"", &e->buf); |
446 } | 452 } |
474 | 480 |
475 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 481 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
476 "http script regex: \"%V\"", &code->name); | 482 "http script regex: \"%V\"", &code->name); |
477 | 483 |
478 if (code->uri) { | 484 if (code->uri) { |
479 e->line = &r->uri; | 485 e->line = r->uri; |
480 } else { | 486 } else { |
481 e->sp--; | 487 e->sp--; |
482 e->line = &e->sp->text; | 488 e->line = e->sp->text; |
483 } | 489 } |
484 | 490 |
485 rc = ngx_regex_exec(code->regex, e->line, e->captures, code->ncaptures); | 491 rc = ngx_regex_exec(code->regex, &e->line, e->captures, code->ncaptures); |
486 | 492 |
487 if (rc == NGX_REGEX_NO_MATCHED) { | 493 if (rc == NGX_REGEX_NO_MATCHED) { |
488 if (e->log) { | 494 if (e->log) { |
489 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | 495 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, |
490 "\"%V\" does not match \"%V\"", &code->name, e->line); | 496 "\"%V\" does not match \"%V\"", |
491 } | 497 &code->name, &e->line); |
498 } | |
499 | |
500 e->ncaptures = 0; | |
492 | 501 |
493 if (code->test) { | 502 if (code->test) { |
494 e->sp->value = 0; | 503 e->sp->value = 0; |
495 e->sp->text.len = 0; | 504 e->sp->text.len = 0; |
496 e->sp->text.data = (u_char *) ""; | 505 e->sp->text.data = (u_char *) ""; |
505 } | 514 } |
506 | 515 |
507 if (rc < 0) { | 516 if (rc < 0) { |
508 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | 517 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
509 ngx_regex_exec_n " failed: %d on \"%V\" using \"%V\"", | 518 ngx_regex_exec_n " failed: %d on \"%V\" using \"%V\"", |
510 rc, e->line, &code->name); | 519 rc, &e->line, &code->name); |
511 | 520 |
512 e->ip = ngx_http_script_exit; | 521 e->ip = ngx_http_script_exit; |
513 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | 522 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; |
514 return; | 523 return; |
515 } | 524 } |
516 | 525 |
517 if (e->log) { | 526 if (e->log) { |
518 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | 527 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, |
519 "\"%V\" matches \"%V\"", &code->name, e->line); | 528 "\"%V\" matches \"%V\"", &code->name, &e->line); |
520 } | 529 } |
530 | |
531 e->ncaptures = code->ncaptures; | |
521 | 532 |
522 if (code->test) { | 533 if (code->test) { |
523 e->sp->value = 1; | 534 e->sp->value = 1; |
524 e->sp->text.len = 1; | 535 e->sp->text.len = 1; |
525 e->sp->text.data = (u_char *) "1"; | 536 e->sp->text.data = (u_char *) "1"; |
568 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); | 579 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); |
569 | 580 |
570 le.ip = code->lengths->elts; | 581 le.ip = code->lengths->elts; |
571 le.request = r; | 582 le.request = r; |
572 le.captures = e->captures; | 583 le.captures = e->captures; |
584 le.ncaptures = e->ncaptures; | |
573 | 585 |
574 len = 1; /* reserve 1 byte for possible "?" */ | 586 len = 1; /* reserve 1 byte for possible "?" */ |
575 | 587 |
576 while (*(uintptr_t *) le.ip) { | 588 while (*(uintptr_t *) le.ip) { |
577 lcode = *(ngx_http_script_len_code_pt *) le.ip; | 589 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
579 } | 591 } |
580 | 592 |
581 e->buf.len = len; | 593 e->buf.len = len; |
582 } | 594 } |
583 | 595 |
584 if (code->args && code->add_args && r->args.len) { | 596 if (code->add_args && r->args.len) { |
585 e->buf.len += r->args.len + 1; | 597 e->buf.len += r->args.len + 1; |
586 } | 598 } |
587 | 599 |
588 e->buf.data = ngx_palloc(r->pool, e->buf.len); | 600 e->buf.data = ngx_palloc(r->pool, e->buf.len); |
589 if (e->buf.data == NULL) { | 601 if (e->buf.data == NULL) { |
718 | 730 |
719 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | 731 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, |
720 "http script if false"); | 732 "http script if false"); |
721 | 733 |
722 e->ip += code->next; | 734 e->ip += code->next; |
735 } | |
736 | |
737 | |
738 void | |
739 ngx_http_script_complex_value_code(ngx_http_script_engine_t *e) | |
740 { | |
741 size_t len; | |
742 ngx_http_script_engine_t le; | |
743 ngx_http_script_len_code_pt lcode; | |
744 ngx_http_script_complex_value_code_t *code; | |
745 | |
746 code = (ngx_http_script_complex_value_code_t *) e->ip; | |
747 | |
748 e->ip += sizeof(ngx_http_script_complex_value_code_t); | |
749 | |
750 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, | |
751 "http script complex value"); | |
752 | |
753 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); | |
754 | |
755 le.ip = code->lengths->elts; | |
756 le.request = e->request; | |
757 le.captures = e->captures; | |
758 le.ncaptures = e->ncaptures; | |
759 | |
760 for (len = 0; *(uintptr_t *) le.ip; len += lcode(&le)) { | |
761 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
762 } | |
763 | |
764 e->buf.len = len; | |
765 e->buf.data = ngx_palloc(e->request->pool, len); | |
766 if (e->buf.data == NULL) { | |
767 e->ip = ngx_http_script_exit; | |
768 e->status = NGX_HTTP_INTERNAL_SERVER_ERROR; | |
769 return; | |
770 } | |
771 | |
772 e->pos = e->buf.data; | |
773 | |
774 e->sp->value = 0; | |
775 e->sp->text = e->buf; | |
776 e->sp++; | |
723 } | 777 } |
724 | 778 |
725 | 779 |
726 void | 780 void |
727 ngx_http_script_value_code(ngx_http_script_engine_t *e) | 781 ngx_http_script_value_code(ngx_http_script_engine_t *e) |