Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2003-08-06 09:30:51 +0400
committerIgor Sysoev <igor@sysoev.ru>2003-08-06 09:30:51 +0400
commit7f4003a76ad894ddc074c5b0dbbf89c699badef4 (patch)
tree22c4398dda89367a658a6d12014616c0c7945add /src
parent044105067d5ac2178c57b4f8f4ffa3c877381690 (diff)
nginx-0.0.1-2003-08-06-09:30:51 import
Diffstat (limited to 'src')
-rw-r--r--src/http/modules/ngx_http_ssi_filter.c309
1 files changed, 41 insertions, 268 deletions
diff --git a/src/http/modules/ngx_http_ssi_filter.c b/src/http/modules/ngx_http_ssi_filter.c
index 55194aaf4..9ef6b6ceb 100644
--- a/src/http/modules/ngx_http_ssi_filter.c
+++ b/src/http/modules/ngx_http_ssi_filter.c
@@ -1,306 +1,79 @@
#include <ngx_config.h>
#include <ngx_core.h>
-#include <ngx_hunk.h>
-#include <ngx_event_write.h>
#include <ngx_http.h>
-#include <ngx_http_config.h>
-static ngx_command_t ngx_http_ssi_filter_commands[];
+typedef struct {
+} ngx_http_ssi_filter_ctx_t;
-static void *ngx_http_ssi_filter_create_conf(ngx_pool_t *pool);
-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 */
-};
+static int ngx_http_ssi_filter_init(ngx_cycle_t *cycle);
+
+static ngx_http_module_t ngx_http_ssi_filter_module_ctx = {
+ NULL, /* create main configuration */
+ NULL, /* init main configuration */
-static ngx_command_t ngx_http_ssi_filter_commands[] = {
+ NULL, /* create server configuration */
+ NULL, /* merge server configuration */
- {"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, /* create location configuration */
+ NULL, /* merge location configuration */
+};
- {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;
+static int (*next_header_filter) (ngx_http_request_t *r);
+static int (*next_body_filter) (ngx_http_request_t *r, ngx_chain_t *ch);
- ctx->start = ctx->pos = ch->hunk->pos.mem;
- }
- }
-}
-
-
-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)
+static void ngx_http_ssi_parse()
{
- ngx_http_ssi_parse_command(r, ctx, ch->hunk);
-}
-
-
-static char ssi_start[] = "<!--#";
-
-static char ssi_include[] = "include";
-
-static ssi_parser_t ssi_pre_command_state[] = {
- { 1, (char *) ' ', ssi_pre_command_state, NULL },
-
- { 7, "include", ssi_command_state, ssi_include_state },
-
- { 4, "random", ssi_command_state, NULL },
- { 0, NULL, ssi_error_state }
-};
-
-static ssi_parser_t ssi_include_state[] = {
- { 1, (char *) ' ', ssi_include_state, NULL },
- { 7, "virtual", ssi_equal_state, offsetof(ssi_include_t, virtual) },
- { 0, NULL, ssi_error_state }
-};
-
-static ssi_parser_t ssi_equal_state[] = {
- { 1, (char *) ' ', ssi_equal_state, NULL },
- { 1, (char *) '=', ssi_param_state, NULL },
-};
-
-static char ssi_echo[] = "echo";
-
-static void ngx_http_ssi_parse(ngx_http_request_t *r,
- ngx_http_ssi_filter_ctx_t *ctx,
- ngx_hunk_t *hunk)
-
-
- for ( ;; ) {
-
- for (/* void */ ; p < ch->hunk->last.mem; p++) {
-
- switch (state) {
-
- case ssi_start_state:
-
- /* tight loop */
- while (p < ch->hunk->last.mem) {
- if (*p++ == '<') {
- state = ssi_comment_state;
- length = 1;
- break;
- }
- }
-
- /* fall through */
-
- case ssi_comment_state:
-
- if (*p == ssi_start[length]) {
- length++;
-
- } else {
- length = 0;
- flush = 1;
- state = ssi_start_state;
- }
-
- if (length < 6)
- continue;
-
- state = ssi_space_before_command_state;
-
- /* fall through */
-
- case ssi_space_before_command_state:
-
- if (*p == ' ' || *p == '\t' || *p == CR || *p == LF)
- continue;
-
- state = ssi_command_state;
-
- /* fall through */
-
- case ssi_choose_command_state:
-
- for (i = 0; ctx->name[i].len; i++) {
- if (*p == ctx->name[i].name[0]) {
- state = choos[i].state;
- }
+ for ( ) {
+ switch (state) {
+ case ssi_start_state:
+
+ /* tight loop */
+ while (p < h->last) {
+ if (*p++ == '<') {
+ state = ssi_comment_state;
+ length = 1;
+ break;
}
-
- case ssi_command_state:
- if (*p == ssi_include[n];
- n++;
-
- break;
-
- }
- }
-
- if (length == 6
- || (length > 0 && ch->next == NULL)
- || hunk_with_ssi) {
-
- if (ctx->saved > 0 && flush) {
- add saved
- ctx->saved = 0;
- }
-
- for (c = ctx->in; c != hunk; c = c->next) {
- ngx_add_hunk_to_chain(ctx->last, c->hunk,
- r->pool, NGX_ERROR);
- }
-
- add duped;
- push duped_hunk, hunk, NULL;
-
- n = length - (hunk->last.mem - pos);
- for (c = hunk; c; c->next) {
- if (n > c->hunk->last.mem - c->hunk->pos.mem) {
- n -= c->hunk->last.mem - c->hunk->pos.mem;
- push NULL, c->hunk, NULL;
- }
- }
-
- ctx->in = c;
}
- }
-
- } else {
- for (/* void */ ; p < ch->hunk->last.mem; p++) {
- if (*p == ' ' || *p == '\t' || *p == CR || *P == LF)
- continue;
+ /* fall through */
- ctx->state = ssi_command_state;
+ case ssi_comment_state:
break;
- }
-
- if (
}
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-static void *ngx_http_ssi_filter_create_conf(ngx_pool_t *pool)
+static int ngx_http_ssi_filter_init(ngx_cycle_t *cycle)
{
- ngx_http_ssi_filter_conf_t *conf;
-
- ngx_test_null(conf,
- ngx_palloc(pool, sizeof(ngx_http_ssi_filter_conf_t)),
- NULL);
+ next_header_filter = ngx_http_top_header_filter;
+ ngx_http_top_header_filter = ngx_http_ssi_header_filter;
- conf->buffer_output = NGX_CONF_UNSET;
+ next_body_filter = ngx_http_top_body_filter;
+ ngx_http_top_body_filter = ngx_http_ssi_body_filter;
- return conf;
+ return NGX_OK;
}