From 170efb2b7d36e85db017e9daa25a0422aee8ce8a Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Thu, 26 Sep 2002 16:50:29 +0000 Subject: nginx-0.0.1-2002-09-26-20:50:29 import --- src/http/modules/ngx_http_ssi_filter.c | 274 ++++++++++++++++++++------------- 1 file changed, 166 insertions(+), 108 deletions(-) (limited to 'src/http/modules') diff --git a/src/http/modules/ngx_http_ssi_filter.c b/src/http/modules/ngx_http_ssi_filter.c index 4a94a2367..55194aaf4 100644 --- a/src/http/modules/ngx_http_ssi_filter.c +++ b/src/http/modules/ngx_http_ssi_filter.c @@ -39,172 +39,230 @@ int ngx_http_ssi_filter(ngx_http_request_t *r, ngx_chain_t *in) ngx_http_ssi_filter_ctx_t *ctx; ngx_http_ssi_filter_conf_t *conf; + if (in == NULL) + return next_filter; + ctx = (ngx_http_ssi_filter_ctx_t *) - ngx_get_module_ctx(r->main ? r->main : r, - ngx_http_ssi_filter_module); + ngx_get_module_ctx(r, ngx_http_ssi_filter_module); if (ctx == NULL) { ngx_http_create_ctx(r, ctx, ngx_http_ssi_filter_module, sizeof(ngx_http_ssi_filter_ctx_t)); ctx->state = &ssi_start; + ctx->handler = ngx_http_ssi_find_start; } - state = ctx->state; - length = ctx->length; - ch = in; - p = ch->hunk->pos.mem; + ctx->start = ctx->pos = ch->hunk->pos.mem; + + for ( ;; ) { + if (ctx->handler(r, ctx, ch) == NGX_ERROR) + return NGX_ERROR; + + if (ctx->pos + ctx->length == ch->hunk->last.mem) { + ch = ch->next; + if (ch == NULL) + break; + + ctx->start = ctx->pos = ch->hunk->pos.mem; + } + } +} + + - rc = ngx_http_ssi_parse(r, ctx, in); - if (rc == NGX_SSI_FOUND) { +static int ngx_http_ssi_find_start(ngx_http_request_t *r, + ngx_http_ssi_filter_ctx_t *ctx, + ngx_chain_t *ch) +{ + ngx_http_ssi_parse(r, ctx, ch->hunk); + + if (ctx->state == ssi_command_state + || (ctx->length > 0 && ch->next == NULL) + || ctx->hunk_with_ssi) + { + ngx_test_null(h, ngx_palloc(r->pool, sizeof(ngx_hunk_t)), NGX_ERROR); +#if !(HAVE_OFFSET_EQUAL_PTR) + h->pos.file = h->last.file = 0; +#endif + h->pre_start = h->start = h->pos.mem = ctx->start; + h->post_end = h->end = h->last.mem = ctx->pos; + h->type = NGX_HUNK_TEMP; + h->tag = 0; + h->file = NULL; + + ngx_add_hunk_to_chain(ctx->last, h, r->pool, NGX_ERROR); + + ngx_test_null(ssi_hunk, ngx_push_array(ctx->ssi_hunks), NGX_ERROR); + ssi_hunk->ssi_hunk = h; + ssi_hunk->hunk = ch->hunk; + ssi_hunk->pos = NULL; } + if (ctx->state == ssi_command_state) + ctx->handler = ngx_http_ssi_find_command; + } + + return NGX_OK; } -static int ngx_http_ssi_parse(ngx_http_request_t *r, - ngx_http_ssi_filter_ctx_t *ctx, ngx_chain_t *in) +static int ngx_http_ssi_find_command(ngx_http_request_t *r, + ngx_http_ssi_filter_ctx_t *ctx, + ngx_chain_t *ch) { - state = ctx->state; - length = ctx->length; + ngx_http_ssi_parse_command(r, ctx, ch->hunk); +} + + +static char ssi_start[] = "