mirror of
https://github.com/nginx/nginx.git
synced 2025-02-25 18:55:26 -06:00
Sub filter: introduced the ngx_http_sub_match() function.
No functional changes.
This commit is contained in:
parent
c60b61a290
commit
ec70155755
@ -84,6 +84,8 @@ static ngx_int_t ngx_http_sub_output(ngx_http_request_t *r,
|
|||||||
ngx_http_sub_ctx_t *ctx);
|
ngx_http_sub_ctx_t *ctx);
|
||||||
static ngx_int_t ngx_http_sub_parse(ngx_http_request_t *r,
|
static ngx_int_t ngx_http_sub_parse(ngx_http_request_t *r,
|
||||||
ngx_http_sub_ctx_t *ctx);
|
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,
|
static char * ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||||
void *conf);
|
void *conf);
|
||||||
@ -592,7 +594,7 @@ ngx_http_sub_output(ngx_http_request_t *r, ngx_http_sub_ctx_t *ctx)
|
|||||||
static ngx_int_t
|
static ngx_int_t
|
||||||
ngx_http_sub_parse(ngx_http_request_t *r, ngx_http_sub_ctx_t *ctx)
|
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_str_t *m;
|
||||||
ngx_int_t offset, start, next, end, len, rc;
|
ngx_int_t offset, start, next, end, len, rc;
|
||||||
ngx_uint_t shift, i, j;
|
ngx_uint_t shift, i, j;
|
||||||
@ -641,41 +643,15 @@ ngx_http_sub_parse(ngx_http_request_t *r, ngx_http_sub_ctx_t *ctx)
|
|||||||
|
|
||||||
m = &match[i].match;
|
m = &match[i].match;
|
||||||
|
|
||||||
pat = m->data;
|
rc = ngx_http_sub_match(ctx, start, m);
|
||||||
pat_end = m->data + m->len;
|
|
||||||
|
|
||||||
if (start >= 0) {
|
if (rc == NGX_DECLINED) {
|
||||||
p = ctx->pos + start;
|
goto next;
|
||||||
|
|
||||||
} else {
|
|
||||||
last = ctx->looked.data + ctx->looked.len;
|
|
||||||
p = last + start;
|
|
||||||
|
|
||||||
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++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->index = i;
|
ctx->index = i;
|
||||||
|
|
||||||
if (pat != pat_end) {
|
if (rc == NGX_AGAIN) {
|
||||||
/* partial match */
|
|
||||||
goto 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 *
|
static char *
|
||||||
ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user