diff --git a/auto/make b/auto/make index c210d7e2b..a44963e13 100644 --- a/auto/make +++ b/auto/make @@ -21,6 +21,11 @@ if [ $HTTP_GZIP = YES ]; then HTTP_SRCS="$HTTP_SRCS $HTTP_GZIP_SRCS" fi +if [ $HTTP_SSI = YES ]; then + HTTP_FILTER_MODULES="$HTTP_FILTER_MODULES $HTTP_SSI_FILTER_MODULE" + HTTP_SRCS="$HTTP_SRCS $HTTP_SSI_SRCS" +fi + if [ $HTTP_PROXY = YES ]; then HTTP_MODULES="$HTTP_MODULES $HTTP_PROXY_MODULE" HTTP_INCS="$HTTP_INCS $HTTP_PROXY_INCS" diff --git a/auto/options b/auto/options index 80302e419..3064a950d 100644 --- a/auto/options +++ b/auto/options @@ -11,6 +11,7 @@ POLL=YES HTTP_REWRITE=YES HTTP_GZIP=YES +HTTP_SSI=YES HTTP_PROXY=YES PCRE=NO @@ -42,6 +43,7 @@ do --without-poll_module) POLL=NO ;; --without-http_rewrite_module) HTTP_REWRITE=NO ;; + --without-http_ssi_module) HTTP_SSI=NO ;; --without-http_gzip_module) HTTP_GZIP=NO ;; --without-http_proxy_module) HTTP_PROXY=NO ;; diff --git a/auto/sources b/auto/sources index f6f8de794..b352effbb 100644 --- a/auto/sources +++ b/auto/sources @@ -206,6 +206,10 @@ HTTP_GZIP_UNIX_LIBS=-lz HTTP_GZIP_WIN_LIBS=zlib.lib +HTTP_SSI_FILTER_MODULE=ngx_http_ssi_filter_module +HTTP_SSI_SRCS=src/http/modules/ngx_http_ssi_filter.c + + HTTP_PROXY_MODULE=ngx_http_proxy_module HTTP_PROXY_INCS="-I src/http/modules/proxy" HTTP_PROXY_DEPS=src/http/modules/proxy/ngx_http_proxy_handler.h diff --git a/src/core/ngx_hunk.c b/src/core/ngx_hunk.c index d6aa0a40e..07c388499 100644 --- a/src/core/ngx_hunk.c +++ b/src/core/ngx_hunk.c @@ -98,15 +98,15 @@ int ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in) void ngx_chain_update_chains(ngx_chain_t **free, ngx_chain_t **busy, ngx_chain_t **out, ngx_hunk_tag_t tag) { - ngx_chain_t *te; + ngx_chain_t *tl; if (*busy == NULL) { *busy = *out; } else { - for (te = *busy; /* void */ ; te = te->next) { - if (te->next == NULL) { - te->next = *out; + for (tl = *busy; /* void */ ; tl = tl->next) { + if (tl->next == NULL) { + tl->next = *out; break; } } @@ -132,9 +132,9 @@ void ngx_chain_update_chains(ngx_chain_t **free, ngx_chain_t **busy, (*busy)->hunk->pos = (*busy)->hunk->last = (*busy)->hunk->start; - te = *busy; + tl = *busy; *busy = (*busy)->next; - te->next = *free; - *free = te; + tl->next = *free; + *free = tl; } } diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c index 09980eff3..c5e68c9a5 100644 --- a/src/http/modules/ngx_http_gzip_filter.c +++ b/src/http/modules/ngx_http_gzip_filter.c @@ -76,49 +76,49 @@ static ngx_conf_post_handler_pt ngx_http_gzip_set_hash_p = static ngx_command_t ngx_http_gzip_filter_commands[] = { - {ngx_string("gzip"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, - ngx_conf_set_flag_slot, - NGX_HTTP_LOC_CONF_OFFSET, - offsetof(ngx_http_gzip_conf_t, enable), - NULL}, + { ngx_string("gzip"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_gzip_conf_t, enable), + NULL}, - {ngx_string("gzip_buffers"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, - ngx_conf_set_bufs_slot, - NGX_HTTP_LOC_CONF_OFFSET, - offsetof(ngx_http_gzip_conf_t, bufs), - NULL}, + { ngx_string("gzip_buffers"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, + ngx_conf_set_bufs_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_gzip_conf_t, bufs), + NULL}, - {ngx_string("gzip_comp_level"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, - ngx_conf_set_num_slot, - NGX_HTTP_LOC_CONF_OFFSET, - offsetof(ngx_http_gzip_conf_t, level), - &ngx_http_gzip_comp_level_bounds}, + { ngx_string("gzip_comp_level"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, + ngx_conf_set_num_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_gzip_conf_t, level), + &ngx_http_gzip_comp_level_bounds}, - {ngx_string("gzip_window"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, - ngx_conf_set_size_slot, - NGX_HTTP_LOC_CONF_OFFSET, - offsetof(ngx_http_gzip_conf_t, wbits), - &ngx_http_gzip_set_window_p}, + { ngx_string("gzip_window"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, + ngx_conf_set_size_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_gzip_conf_t, wbits), + &ngx_http_gzip_set_window_p}, - {ngx_string("gzip_hash"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, - ngx_conf_set_size_slot, - NGX_HTTP_LOC_CONF_OFFSET, - offsetof(ngx_http_gzip_conf_t, memlevel), - &ngx_http_gzip_set_hash_p}, + { ngx_string("gzip_hash"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, + ngx_conf_set_size_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_gzip_conf_t, memlevel), + &ngx_http_gzip_set_hash_p}, - {ngx_string("gzip_no_buffer"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, - ngx_conf_set_flag_slot, - NGX_HTTP_LOC_CONF_OFFSET, - offsetof(ngx_http_gzip_conf_t, no_buffer), - NULL}, + { ngx_string("gzip_no_buffer"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_gzip_conf_t, no_buffer), + NULL}, - ngx_null_command + ngx_null_command }; diff --git a/src/http/modules/ngx_http_ssi_filter.c b/src/http/modules/ngx_http_ssi_filter.c index e00c35280..78bf60826 100644 --- a/src/http/modules/ngx_http_ssi_filter.c +++ b/src/http/modules/ngx_http_ssi_filter.c @@ -7,7 +7,7 @@ #define NGX_HTTP_SSI_COMMAND_LEN 31 #define NGX_HTTP_SSI_PARAM_LEN 31 -#define NGX_HTTP_SSI_DONE 1 +#define NGX_HTTP_SSI_COPY 1 #define NGX_HTTP_SSI_INVALID_COMMAND 2 #define NGX_HTTP_SSI_INVALID_PARAM 3 #define NGX_HTTP_SSI_INVALID_VALUE 4 @@ -15,173 +15,265 @@ typedef struct { - ngx_hunk_t *hunk; - ngx_table_elt_t *param; - ngx_str_t command; - ngx_array_t params; - int state; - int looked; - char *pos; - ngx_chain_t *incoming; - int new_hunk; - u_int value_len; + int enable; +} ngx_http_ssi_conf_t; + + +typedef struct { + ngx_hunk_t *buf; + + char *start; + char *last; + char *pos; + + ngx_table_elt_t *param; + ngx_str_t command; + ngx_array_t params; + int state; + + ngx_chain_t *in; + ngx_chain_t *current; + ngx_chain_t *out; + ngx_chain_t **last_out; + ngx_chain_t *busy; + + size_t prev; + + u_int value_len; } ngx_http_ssi_ctx_t; +static ngx_int_t ngx_http_ssi_parse(ngx_http_request_t *r, + ngx_http_ssi_ctx_t *ctx); +static void *ngx_http_ssi_create_conf(ngx_conf_t *cf); +static char *ngx_http_ssi_merge_conf(ngx_conf_t *cf, + void *parent, void *child); static int ngx_http_ssi_filter_init(ngx_cycle_t *cycle); + +static ngx_command_t ngx_http_ssi_filter_commands[] = { + + { ngx_string("ssi"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_ssi_conf_t, enable), + NULL }, + + ngx_null_command +}; + + static ngx_http_module_t ngx_http_ssi_filter_module_ctx = { + NULL, /* pre conf */ + NULL, /* create main configuration */ NULL, /* init main configuration */ NULL, /* create server configuration */ NULL, /* merge server configuration */ - NULL, /* create location configuration */ - NULL, /* merge location configuration */ + ngx_http_ssi_create_conf, /* create location configuration */ + ngx_http_ssi_merge_conf /* merge location configuration */ }; ngx_module_t ngx_http_ssi_filter_module = { NGX_MODULE, &ngx_http_ssi_filter_module_ctx, /* module context */ - NULL, /* module directives */ + ngx_http_ssi_filter_commands, /* module directives */ NGX_HTTP_MODULE, /* module type */ ngx_http_ssi_filter_init, /* init module */ NULL /* init child */ }; -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_next_header_filter) (ngx_http_request_t *r); +static int (*ngx_http_next_body_filter) (ngx_http_request_t *r, ngx_chain_t *in); static char comment_string[] = "