Mercurial > hg > nginx-quic
comparison src/http/modules/ngx_http_rewrite_module.c @ 631:5d2b8078c1c2 release-0.3.37
nginx-0.3.37-RELEASE import
*) Feature: the "limit_except" directive.
*) Feature: the "if" directive supports the "!~", "!~*", "-f", and
"!-f" operators.
*) Feature: the ngx_http_perl_module supports the $r->request_body
method.
*) Bugfix: in the ngx_http_addition_filter_module.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 07 Apr 2006 14:08:04 +0000 |
parents | 4d9ea73a627a |
children | 18268abd340c |
comparison
equal
deleted
inserted
replaced
630:375dab4fd227 | 631:5d2b8078c1c2 |
---|---|
576 if_code->code = ngx_http_script_if_code; | 576 if_code->code = ngx_http_script_if_code; |
577 | 577 |
578 elts = lcf->codes->elts; | 578 elts = lcf->codes->elts; |
579 | 579 |
580 | 580 |
581 /* the inside directives must compile to the same code array */ | 581 /* the inner directives must be compiled to the same code array */ |
582 | 582 |
583 nlcf = ctx->loc_conf[ngx_http_rewrite_module.ctx_index]; | 583 nlcf = ctx->loc_conf[ngx_http_rewrite_module.ctx_index]; |
584 nlcf->codes = lcf->codes; | 584 nlcf->codes = lcf->codes; |
585 | 585 |
586 | 586 |
627 | 627 |
628 | 628 |
629 static char * | 629 static char * |
630 ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf) | 630 ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf) |
631 { | 631 { |
632 u_char *p; | |
633 size_t len; | |
632 ngx_str_t *value, err; | 634 ngx_str_t *value, err; |
633 ngx_uint_t cur, last, n; | 635 ngx_uint_t cur, last, n; |
634 ngx_http_script_code_pt *code; | 636 ngx_http_script_code_pt *code; |
637 ngx_http_script_file_code_t *fop; | |
635 ngx_http_script_regex_code_t *regex; | 638 ngx_http_script_regex_code_t *regex; |
636 u_char errstr[NGX_MAX_CONF_ERRSTR]; | 639 u_char errstr[NGX_MAX_CONF_ERRSTR]; |
637 | 640 |
638 value = cf->args->elts; | 641 value = cf->args->elts; |
639 last = cf->args->nelts - 1; | 642 last = cf->args->nelts - 1; |
665 } else { | 668 } else { |
666 value[last].len--; | 669 value[last].len--; |
667 value[last].data[value[last].len] = '\0'; | 670 value[last].data[value[last].len] = '\0'; |
668 } | 671 } |
669 | 672 |
670 if (value[cur].len > 1 && value[cur].data[0] == '$') { | 673 len = value[cur].len; |
674 p = value[cur].data; | |
675 | |
676 if (len > 1 && p[0] == '$') { | |
671 | 677 |
672 if (cur != last && cur + 2 != last) { | 678 if (cur != last && cur + 2 != last) { |
673 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 679 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
674 "invalid condition \"%V\"", &value[cur]); | 680 "invalid condition \"%V\"", &value[cur]); |
675 return NGX_CONF_ERROR; | 681 return NGX_CONF_ERROR; |
676 } | 682 } |
677 | 683 |
678 if (ngx_http_rewrite_variable(cf, lcf, &value[cur]) != NGX_CONF_OK) { | 684 if (ngx_http_rewrite_variable(cf, lcf, &value[cur]) != NGX_CONF_OK) { |
679 return NGX_CONF_ERROR; | 685 return NGX_CONF_ERROR; |
683 return NGX_CONF_OK; | 689 return NGX_CONF_OK; |
684 } | 690 } |
685 | 691 |
686 cur++; | 692 cur++; |
687 | 693 |
688 if (value[cur].len == 1 && value[cur].data[0] == '=') { | 694 len = value[cur].len; |
695 p = value[cur].data; | |
696 | |
697 if (len == 1 && p[0] == '=') { | |
689 | 698 |
690 if (ngx_http_rewrite_value(cf, lcf, &value[last]) != NGX_CONF_OK) { | 699 if (ngx_http_rewrite_value(cf, lcf, &value[last]) != NGX_CONF_OK) { |
691 return NGX_CONF_ERROR; | 700 return NGX_CONF_ERROR; |
692 } | 701 } |
693 | 702 |
700 *code = ngx_http_script_equal_code; | 709 *code = ngx_http_script_equal_code; |
701 | 710 |
702 return NGX_CONF_OK; | 711 return NGX_CONF_OK; |
703 } | 712 } |
704 | 713 |
705 if (value[cur].len == 2 | 714 if (len == 2 && p[0] == '!' && p[1] == '=') { |
706 && value[cur].data[0] == '!' && value[cur].data[1] == '=') | 715 |
707 { | |
708 if (ngx_http_rewrite_value(cf, lcf, &value[last]) != NGX_CONF_OK) { | 716 if (ngx_http_rewrite_value(cf, lcf, &value[last]) != NGX_CONF_OK) { |
709 return NGX_CONF_ERROR; | 717 return NGX_CONF_ERROR; |
710 } | 718 } |
711 | 719 |
712 code = ngx_http_script_start_code(cf->pool, &lcf->codes, | 720 code = ngx_http_script_start_code(cf->pool, &lcf->codes, |
717 | 725 |
718 *code = ngx_http_script_not_equal_code; | 726 *code = ngx_http_script_not_equal_code; |
719 return NGX_CONF_OK; | 727 return NGX_CONF_OK; |
720 } | 728 } |
721 | 729 |
722 if ((value[cur].len == 1 && value[cur].data[0] == '~') | 730 if ((len == 1 && p[0] == '~') |
723 || (value[cur].len == 2 | 731 || (len == 2 && p[0] == '~' && p[1] == '*') |
724 && value[cur].data[0] == '~' && value[cur].data[1] == '*')) | 732 || (len == 2 && p[0] == '!' && p[1] == '~') |
733 || (len == 3 && p[0] == '!' && p[1] == '~' && p[2] == '*')) | |
725 { | 734 { |
726 regex = ngx_http_script_start_code(cf->pool, &lcf->codes, | 735 regex = ngx_http_script_start_code(cf->pool, &lcf->codes, |
727 sizeof(ngx_http_script_regex_code_t)); | 736 sizeof(ngx_http_script_regex_code_t)); |
728 if (regex == NULL) { | 737 if (regex == NULL) { |
729 return NGX_CONF_ERROR; | 738 return NGX_CONF_ERROR; |
733 | 742 |
734 err.len = NGX_MAX_CONF_ERRSTR; | 743 err.len = NGX_MAX_CONF_ERRSTR; |
735 err.data = errstr; | 744 err.data = errstr; |
736 | 745 |
737 regex->regex = ngx_regex_compile(&value[last], | 746 regex->regex = ngx_regex_compile(&value[last], |
738 (value[cur].len == 2) ? NGX_REGEX_CASELESS : 0, | 747 (p[len - 1] == '*') ? NGX_REGEX_CASELESS : 0, |
739 cf->pool, &err); | 748 cf->pool, &err); |
740 | 749 |
741 if (regex->regex == NULL) { | 750 if (regex->regex == NULL) { |
742 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data); | 751 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data); |
743 return NGX_CONF_ERROR; | 752 return NGX_CONF_ERROR; |
744 } | 753 } |
745 | 754 |
746 regex->code = ngx_http_script_regex_start_code; | 755 regex->code = ngx_http_script_regex_start_code; |
747 regex->next = sizeof(ngx_http_script_regex_code_t); | 756 regex->next = sizeof(ngx_http_script_regex_code_t); |
748 regex->test = 1; | 757 regex->test = 1; |
758 if (p[0] == '!') { | |
759 regex->negative_test = 1; | |
760 } | |
749 regex->name = value[last]; | 761 regex->name = value[last]; |
750 | 762 |
751 n = ngx_regex_capture_count(regex->regex); | 763 n = ngx_regex_capture_count(regex->regex); |
752 | 764 |
753 if (n) { | 765 if (n) { |
761 return NGX_CONF_OK; | 773 return NGX_CONF_OK; |
762 } | 774 } |
763 | 775 |
764 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 776 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
765 "unexpected \"%V\" in condition", &value[cur]); | 777 "unexpected \"%V\" in condition", &value[cur]); |
778 return NGX_CONF_ERROR; | |
779 | |
780 } else if ((len == 2 && p[0] == '-') | |
781 || (len == 3 && p[0] == '!' && p[1] == '-')) | |
782 { | |
783 if (cur + 1 != last) { | |
784 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
785 "invalid condition \"%V\"", &value[cur]); | |
786 return NGX_CONF_ERROR; | |
787 } | |
788 | |
789 value[last].data[value[last].len] = '\0'; | |
790 value[last].len++; | |
791 | |
792 if (ngx_http_rewrite_value(cf, lcf, &value[last]) != NGX_CONF_OK) { | |
793 return NGX_CONF_ERROR; | |
794 } | |
795 | |
796 fop = ngx_http_script_start_code(cf->pool, &lcf->codes, | |
797 sizeof(ngx_http_script_file_code_t)); | |
798 if (fop == NULL) { | |
799 return NGX_CONF_ERROR; | |
800 } | |
801 | |
802 fop->code = ngx_http_script_file_code; | |
803 | |
804 if (p[1] == 'f') { | |
805 fop->op = ngx_http_script_file_plain; | |
806 return NGX_CONF_OK; | |
807 } | |
808 | |
809 if (p[0] == '!') { | |
810 if (p[2] == 'f') { | |
811 fop->op = ngx_http_script_file_not_plain; | |
812 return NGX_CONF_OK; | |
813 } | |
814 } | |
815 | |
816 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
817 "invalid condition \"%V\"", &value[cur]); | |
766 return NGX_CONF_ERROR; | 818 return NGX_CONF_ERROR; |
767 } | 819 } |
768 | 820 |
769 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 821 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
770 "invalid condition \"%V\"", &value[cur]); | 822 "invalid condition \"%V\"", &value[cur]); |