# HG changeset patch # User Igor Sysoev # Date 1060147851 0 # Node ID 885ffb8cc32abadbf49095ce0553caf0988896a1 # Parent 842a78cebbb7327272025128178ada44af3e40a3 nginx-0.0.1-2003-08-06-09:30:51 import diff --git a/src/http/modules/ngx_http_ssi_filter.c b/src/http/modules/ngx_http_ssi_filter.c --- a/src/http/modules/ngx_http_ssi_filter.c +++ b/src/http/modules/ngx_http_ssi_filter.c @@ -1,306 +1,79 @@ #include #include -#include -#include #include -#include + + +typedef struct { +} ngx_http_ssi_filter_ctx_t; -static ngx_command_t ngx_http_ssi_filter_commands[]; +static int ngx_http_ssi_filter_init(ngx_cycle_t *cycle); -static void *ngx_http_ssi_filter_create_conf(ngx_pool_t *pool); + +static ngx_http_module_t ngx_http_ssi_filter_module_ctx = { + NULL, /* create main configuration */ + NULL, /* init main configuration */ -ngx_http_module_t ngx_http_ssi_filter_module = { - NGX_HTTP_MODULE, - NULL, /* create server config */ - ngx_http_ssi_filter_create_conf, /* create location config */ - ngx_http_ssi_filter_commands, /* module directives */ - NULL, /* init module */ - NULL /* init output body filter */ -}; + NULL, /* create server configuration */ + NULL, /* merge server configuration */ + + NULL, /* create location configuration */ + NULL, /* merge location configuration */ +}; -static ngx_command_t ngx_http_ssi_filter_commands[] = { - - {"ssi", ngx_conf_set_flag_slot, - offsetof(ngx_http_ssi_filter_conf_t, on), - NGX_HTTP_LOC_CONF, NGX_CONF_FLAG, - "enable ssi filter"}, - - {NULL} - +ngx_module_t ngx_http_ssi_filter_module = { + NGX_MODULE, + &ngx_http_ssi_filter_module_ctx, /* module context */ + NULL, /* module directives */ + NGX_HTTP_MODULE, /* module type */ + ngx_http_ssi_filter_init, /* init module */ + NULL /* init child */ }; -int ngx_http_ssi_filter(ngx_http_request_t *r, ngx_chain_t *in) -{ - ngx_chain_t *ch, **prev, *chain; - 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, 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; - } - - ch = in; - 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; - } - } -} - +static int (*next_header_filter) (ngx_http_request_t *r); +static int (*next_body_filter) (ngx_http_request_t *r, ngx_chain_t *ch); -static int ngx_http_ssi_find_start(ngx_http_request_t *r, - ngx_http_ssi_filter_ctx_t *ctx, - ngx_chain_t *ch) +static int ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in) { - 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_find_command(ngx_http_request_t *r, - ngx_http_ssi_filter_ctx_t *ctx, - ngx_chain_t *ch) -{ - ngx_http_ssi_parse_command(r, ctx, ch->hunk); } -static char ssi_start[] = "