Mercurial > hg > nginx
comparison src/http/modules/ngx_http_sub_filter_module.c @ 6756:521f5aa6e8fb stable-1.10
Sub filter: introduced the ngx_http_sub_match() function.
No functional changes.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Sat, 02 Jul 2016 15:59:52 +0300 |
parents | f01ab2dbcfdc |
children | f379b32e4733 |
comparison
equal
deleted
inserted
replaced
6755:e2f13011343e | 6756:521f5aa6e8fb |
---|---|
82 | 82 |
83 static ngx_int_t ngx_http_sub_output(ngx_http_request_t *r, | 83 static ngx_int_t ngx_http_sub_output(ngx_http_request_t *r, |
84 ngx_http_sub_ctx_t *ctx); | 84 ngx_http_sub_ctx_t *ctx); |
85 static ngx_int_t ngx_http_sub_parse(ngx_http_request_t *r, | 85 static ngx_int_t ngx_http_sub_parse(ngx_http_request_t *r, |
86 ngx_http_sub_ctx_t *ctx); | 86 ngx_http_sub_ctx_t *ctx); |
87 static ngx_int_t ngx_http_sub_match(ngx_http_sub_ctx_t *ctx, ngx_int_t start, | |
88 ngx_str_t *m); | |
87 | 89 |
88 static char * ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd, | 90 static char * ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd, |
89 void *conf); | 91 void *conf); |
90 static void *ngx_http_sub_create_conf(ngx_conf_t *cf); | 92 static void *ngx_http_sub_create_conf(ngx_conf_t *cf); |
91 static char *ngx_http_sub_merge_conf(ngx_conf_t *cf, | 93 static char *ngx_http_sub_merge_conf(ngx_conf_t *cf, |
590 | 592 |
591 | 593 |
592 static ngx_int_t | 594 static ngx_int_t |
593 ngx_http_sub_parse(ngx_http_request_t *r, ngx_http_sub_ctx_t *ctx) | 595 ngx_http_sub_parse(ngx_http_request_t *r, ngx_http_sub_ctx_t *ctx) |
594 { | 596 { |
595 u_char *p, *last, *pat, *pat_end, c; | 597 u_char *p, c; |
596 ngx_str_t *m; | 598 ngx_str_t *m; |
597 ngx_int_t offset, start, next, end, len, rc; | 599 ngx_int_t offset, start, next, end, len, rc; |
598 ngx_uint_t shift, i, j; | 600 ngx_uint_t shift, i, j; |
599 ngx_http_sub_match_t *match; | 601 ngx_http_sub_match_t *match; |
600 ngx_http_sub_tables_t *tables; | 602 ngx_http_sub_tables_t *tables; |
639 goto next; | 641 goto next; |
640 } | 642 } |
641 | 643 |
642 m = &match[i].match; | 644 m = &match[i].match; |
643 | 645 |
644 pat = m->data; | 646 rc = ngx_http_sub_match(ctx, start, m); |
645 pat_end = m->data + m->len; | 647 |
646 | 648 if (rc == NGX_DECLINED) { |
647 if (start >= 0) { | 649 goto next; |
648 p = ctx->pos + start; | |
649 | |
650 } else { | |
651 last = ctx->looked.data + ctx->looked.len; | |
652 p = last + start; | |
653 | |
654 while (p < last && pat < pat_end) { | |
655 if (ngx_tolower(*p) != *pat) { | |
656 goto next; | |
657 } | |
658 | |
659 p++; | |
660 pat++; | |
661 } | |
662 | |
663 p = ctx->pos; | |
664 } | |
665 | |
666 while (p < ctx->buf->last && pat < pat_end) { | |
667 if (ngx_tolower(*p) != *pat) { | |
668 goto next; | |
669 } | |
670 | |
671 p++; | |
672 pat++; | |
673 } | 650 } |
674 | 651 |
675 ctx->index = i; | 652 ctx->index = i; |
676 | 653 |
677 if (pat != pat_end) { | 654 if (rc == NGX_AGAIN) { |
678 /* partial match */ | |
679 goto again; | 655 goto again; |
680 } | 656 } |
681 | 657 |
682 ctx->offset = offset + (ngx_int_t) m->len; | 658 ctx->offset = offset + (ngx_int_t) m->len; |
683 next = start + (ngx_int_t) m->len; | 659 next = start + (ngx_int_t) m->len; |
726 | 702 |
727 ctx->pos += end; | 703 ctx->pos += end; |
728 ctx->offset -= end; | 704 ctx->offset -= end; |
729 | 705 |
730 return rc; | 706 return rc; |
707 } | |
708 | |
709 | |
710 static ngx_int_t | |
711 ngx_http_sub_match(ngx_http_sub_ctx_t *ctx, ngx_int_t start, ngx_str_t *m) | |
712 { | |
713 u_char *p, *last, *pat, *pat_end; | |
714 | |
715 pat = m->data; | |
716 pat_end = m->data + m->len; | |
717 | |
718 if (start >= 0) { | |
719 p = ctx->pos + start; | |
720 | |
721 } else { | |
722 last = ctx->looked.data + ctx->looked.len; | |
723 p = last + start; | |
724 | |
725 while (p < last && pat < pat_end) { | |
726 if (ngx_tolower(*p) != *pat) { | |
727 return NGX_DECLINED; | |
728 } | |
729 | |
730 p++; | |
731 pat++; | |
732 } | |
733 | |
734 p = ctx->pos; | |
735 } | |
736 | |
737 while (p < ctx->buf->last && pat < pat_end) { | |
738 if (ngx_tolower(*p) != *pat) { | |
739 return NGX_DECLINED; | |
740 } | |
741 | |
742 p++; | |
743 pat++; | |
744 } | |
745 | |
746 if (pat != pat_end) { | |
747 /* partial match */ | |
748 return NGX_AGAIN; | |
749 } | |
750 | |
751 return NGX_OK; | |
731 } | 752 } |
732 | 753 |
733 | 754 |
734 static char * | 755 static char * |
735 ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 756 ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |