Welcome! Log In Create A New Profile

Advanced

[nginx] Sub filter: introduced the ngx_http_sub_match() function.

Roman Arutyunyan
July 02, 2016 09:04AM
details: http://hg.nginx.org/nginx/rev/0e0adbbc8752
branches:
changeset: 6604:0e0adbbc8752
user: Roman Arutyunyan <arut@nginx.com>
date: Sat Jul 02 15:59:52 2016 +0300
description:
Sub filter: introduced the ngx_http_sub_match() function.

No functional changes.

diffstat:

src/http/modules/ngx_http_sub_filter_module.c | 83 ++++++++++++++++----------
1 files changed, 52 insertions(+), 31 deletions(-)

diffs (119 lines):

diff -r 9eefb38f0005 -r 0e0adbbc8752 src/http/modules/ngx_http_sub_filter_module.c
--- a/src/http/modules/ngx_http_sub_filter_module.c Thu Jun 30 18:57:39 2016 +0300
+++ b/src/http/modules/ngx_http_sub_filter_module.c Sat Jul 02 15:59:52 2016 +0300
@@ -84,6 +84,8 @@ static ngx_int_t ngx_http_sub_output(ngx
ngx_http_sub_ctx_t *ctx);
static ngx_int_t ngx_http_sub_parse(ngx_http_request_t *r,
ngx_http_sub_ctx_t *ctx);
+static ngx_int_t ngx_http_sub_match(ngx_http_sub_ctx_t *ctx, ngx_int_t start,
+ ngx_str_t *m);

static char * ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
@@ -592,7 +594,7 @@ ngx_http_sub_output(ngx_http_request_t *
static ngx_int_t
ngx_http_sub_parse(ngx_http_request_t *r, ngx_http_sub_ctx_t *ctx)
{
- u_char *p, *last, *pat, *pat_end, c;
+ u_char *p, c;
ngx_str_t *m;
ngx_int_t offset, start, next, end, len, rc;
ngx_uint_t shift, i, j;
@@ -641,41 +643,15 @@ ngx_http_sub_parse(ngx_http_request_t *r

m = &match[i].match;

- pat = m->data;
- pat_end = m->data + m->len;
-
- if (start >= 0) {
- p = ctx->pos + start;
-
- } else {
- last = ctx->looked.data + ctx->looked.len;
- p = last + start;
+ rc = ngx_http_sub_match(ctx, start, m);

- while (p < last && pat < pat_end) {
- if (ngx_tolower(*p) != *pat) {
- goto next;
- }
-
- p++;
- pat++;
- }
-
- p = ctx->pos;
- }
-
- while (p < ctx->buf->last && pat < pat_end) {
- if (ngx_tolower(*p) != *pat) {
- goto next;
- }
-
- p++;
- pat++;
+ if (rc == NGX_DECLINED) {
+ goto next;
}

ctx->index = i;

- if (pat != pat_end) {
- /* partial match */
+ if (rc == NGX_AGAIN) {
goto again;
}

@@ -731,6 +707,51 @@ done:
}


+static ngx_int_t
+ngx_http_sub_match(ngx_http_sub_ctx_t *ctx, ngx_int_t start, ngx_str_t *m)
+{
+ u_char *p, *last, *pat, *pat_end;
+
+ pat = m->data;
+ pat_end = m->data + m->len;
+
+ if (start >= 0) {
+ p = ctx->pos + start;
+
+ } else {
+ last = ctx->looked.data + ctx->looked.len;
+ p = last + start;
+
+ while (p < last && pat < pat_end) {
+ if (ngx_tolower(*p) != *pat) {
+ return NGX_DECLINED;
+ }
+
+ p++;
+ pat++;
+ }
+
+ p = ctx->pos;
+ }
+
+ while (p < ctx->buf->last && pat < pat_end) {
+ if (ngx_tolower(*p) != *pat) {
+ return NGX_DECLINED;
+ }
+
+ p++;
+ pat++;
+ }
+
+ if (pat != pat_end) {
+ /* partial match */
+ return NGX_AGAIN;
+ }
+
+ return NGX_OK;
+}
+
+
static char *
ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Sub filter: introduced the ngx_http_sub_match() function.

Roman Arutyunyan 299 July 02, 2016 09:04AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 218
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready