summaryrefslogtreecommitdiffhomepage
path: root/src/http/modules
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2005-03-04 14:06:57 +0000
committerIgor Sysoev <igor@sysoev.ru>2005-03-04 14:06:57 +0000
commit8184d1b3a72c31e7e6492fc189d687ce85548279 (patch)
tree34e977c47f852d35117464b3cd5e82253fb4fa04 /src/http/modules
parent7ad4a94eee3e17e073d6e8b638b7bd0a2209d2df (diff)
downloadnginx-release-0.1.24.tar.gz
nginx-release-0.1.24.tar.bz2
nginx-0.1.24-RELEASE importrelease-0.1.24
*) Feature: the ngx_http_ssi_filter_module supports the QUERY_STRING and DOCUMENT_URI variables. *) Bugfix: the ngx_http_autoindex_module may some times return the 404 response for existent directory, if this directory was used in "alias" directive. *) Bugfix: the ngx_http_ssi_filter_module ran incorrectly for large responses. *) Bugfix: the lack of the "Referer" header line was always accounted as valid referrer.
Diffstat (limited to 'src/http/modules')
-rw-r--r--src/http/modules/ngx_http_access_handler.c2
-rw-r--r--src/http/modules/ngx_http_autoindex_handler.c37
-rw-r--r--src/http/modules/ngx_http_charset_filter.c4
-rw-r--r--src/http/modules/ngx_http_fastcgi_handler.c4
-rw-r--r--src/http/modules/ngx_http_headers_filter.c2
-rw-r--r--src/http/modules/ngx_http_index_handler.c2
-rw-r--r--src/http/modules/ngx_http_range_filter.c6
-rw-r--r--src/http/modules/ngx_http_rewrite_handler.c26
-rw-r--r--src/http/modules/ngx_http_ssi_filter.c278
-rw-r--r--src/http/modules/ngx_http_static_handler.c2
-rw-r--r--src/http/modules/ngx_http_userid_filter.c113
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_upstream.c4
12 files changed, 284 insertions, 196 deletions
diff --git a/src/http/modules/ngx_http_access_handler.c b/src/http/modules/ngx_http_access_handler.c
index 832f9c2ed..285570f23 100644
--- a/src/http/modules/ngx_http_access_handler.c
+++ b/src/http/modules/ngx_http_access_handler.c
@@ -127,7 +127,7 @@ static char *ngx_http_access_rule(ngx_conf_t *cf, ngx_command_t *cmd,
ngx_http_access_rule_t *rule;
if (alcf->rules == NULL) {
- alcf->rules = ngx_create_array(cf->pool, 5,
+ alcf->rules = ngx_create_array(cf->pool, 4,
sizeof(ngx_http_access_rule_t));
if (alcf->rules == NULL) {
return NGX_CONF_ERROR;
diff --git a/src/http/modules/ngx_http_autoindex_handler.c b/src/http/modules/ngx_http_autoindex_handler.c
index f7878c9b9..8976ad546 100644
--- a/src/http/modules/ngx_http_autoindex_handler.c
+++ b/src/http/modules/ngx_http_autoindex_handler.c
@@ -40,12 +40,12 @@ typedef struct {
static int ngx_http_autoindex_cmp_entries(const void *one, const void *two);
-static ngx_int_t ngx_http_autoindex_error(ngx_http_request_t *r, ngx_dir_t *dir,
- u_char *name);
+static ngx_int_t ngx_http_autoindex_error(ngx_http_request_t *r,
+ ngx_dir_t *dir, u_char *name);
static ngx_int_t ngx_http_autoindex_init(ngx_cycle_t *cycle);
static void *ngx_http_autoindex_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_autoindex_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child);
+ void *parent, void *child);
static ngx_command_t ngx_http_autoindex_commands[] = {
@@ -81,7 +81,7 @@ ngx_module_t ngx_http_autoindex_module = {
ngx_http_autoindex_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_autoindex_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
@@ -103,7 +103,8 @@ static u_char tail[] =
;
-static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_autoindex_handler(ngx_http_request_t *r)
{
u_char *last;
size_t len;
@@ -146,7 +147,7 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r)
if (clcf->alias) {
dname.data = ngx_palloc(pool, clcf->root.len + r->uri.len
- + NGX_DIR_MASK_LEN
+ + NGX_DIR_MASK_LEN + 1
- clcf->name.len);
if (dname.data == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
@@ -154,7 +155,7 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r)
last = ngx_cpymem(dname.data, clcf->root.data, clcf->root.len);
last = ngx_cpystrn(last, r->uri.data + clcf->name.len,
- r->uri.len - clcf->name.len);
+ r->uri.len - clcf->name.len + 1);
} else {
dname.data = ngx_palloc(pool, clcf->root.len + r->uri.len
@@ -165,7 +166,6 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r)
last = ngx_cpymem(dname.data, clcf->root.data, clcf->root.len);
last = ngx_cpystrn(last, r->uri.data, r->uri.len);
-
}
dname.len = last - dname.data;
@@ -445,7 +445,8 @@ static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r)
}
-static int ngx_http_autoindex_cmp_entries(const void *one, const void *two)
+static int
+ngx_http_autoindex_cmp_entries(const void *one, const void *two)
{
ngx_http_autoindex_entry_t *first = (ngx_http_autoindex_entry_t *) one;
ngx_http_autoindex_entry_t *second = (ngx_http_autoindex_entry_t *) two;
@@ -466,8 +467,8 @@ static int ngx_http_autoindex_cmp_entries(const void *one, const void *two)
#if 0
-static ngx_buf_t *ngx_http_autoindex_alloc(ngx_http_autoindex_ctx_t *ctx,
- size_t size)
+static ngx_buf_t *
+ngx_http_autoindex_alloc(ngx_http_autoindex_ctx_t *ctx, size_t size)
{
ngx_chain_t *cl;
@@ -500,8 +501,8 @@ static ngx_buf_t *ngx_http_autoindex_alloc(ngx_http_autoindex_ctx_t *ctx,
#endif
-static ngx_int_t ngx_http_autoindex_error(ngx_http_request_t *r, ngx_dir_t *dir,
- u_char *name)
+static ngx_int_t
+ngx_http_autoindex_error(ngx_http_request_t *r, ngx_dir_t *dir, u_char *name)
{
if (ngx_close_dir(dir) == NGX_ERROR) {
ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno,
@@ -512,7 +513,8 @@ static ngx_int_t ngx_http_autoindex_error(ngx_http_request_t *r, ngx_dir_t *dir,
}
-static ngx_int_t ngx_http_autoindex_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_autoindex_init(ngx_cycle_t *cycle)
{
ngx_http_handler_pt *h;
ngx_http_core_main_conf_t *cmcf;
@@ -530,7 +532,8 @@ static ngx_int_t ngx_http_autoindex_init(ngx_cycle_t *cycle)
}
-static void *ngx_http_autoindex_create_loc_conf(ngx_conf_t *cf)
+static void *
+ngx_http_autoindex_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_autoindex_loc_conf_t *conf;
@@ -545,8 +548,8 @@ static void *ngx_http_autoindex_create_loc_conf(ngx_conf_t *cf)
}
-static char *ngx_http_autoindex_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child)
+static char *
+ngx_http_autoindex_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_autoindex_loc_conf_t *prev = parent;
ngx_http_autoindex_loc_conf_t *conf = child;
diff --git a/src/http/modules/ngx_http_charset_filter.c b/src/http/modules/ngx_http_charset_filter.c
index 0aea91e2f..cbd0fca75 100644
--- a/src/http/modules/ngx_http_charset_filter.c
+++ b/src/http/modules/ngx_http_charset_filter.c
@@ -456,10 +456,10 @@ static void *ngx_http_charset_create_main_conf(ngx_conf_t *cf)
return NGX_CONF_ERROR;
}
- ngx_init_array(mcf->charsets, cf->pool, 5, sizeof(ngx_http_charset_t),
+ ngx_init_array(mcf->charsets, cf->pool, 2, sizeof(ngx_http_charset_t),
NGX_CONF_ERROR);
- ngx_init_array(mcf->tables, cf->pool, 10, sizeof(ngx_http_charset_tables_t),
+ ngx_init_array(mcf->tables, cf->pool, 4, sizeof(ngx_http_charset_tables_t),
NGX_CONF_ERROR);
return mcf;
diff --git a/src/http/modules/ngx_http_fastcgi_handler.c b/src/http/modules/ngx_http_fastcgi_handler.c
index d6130794a..5b384b86e 100644
--- a/src/http/modules/ngx_http_fastcgi_handler.c
+++ b/src/http/modules/ngx_http_fastcgi_handler.c
@@ -599,7 +599,7 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
for (i = 0; i < flcf->vars->nelts; i++) {
- if (!(value = ngx_http_get_variable(r, vindex[i]))) {
+ if (!(value = ngx_http_get_indexed_variable(r, vindex[i]))) {
continue;
}
@@ -998,7 +998,7 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
if (flcf->vars) {
for (i = 0; i < flcf->vars->nelts; i++) {
- if (!(value = ngx_http_get_variable(r, vindex[i]))) {
+ if (!(value = ngx_http_get_indexed_variable(r, vindex[i]))) {
continue;
}
diff --git a/src/http/modules/ngx_http_headers_filter.c b/src/http/modules/ngx_http_headers_filter.c
index ab334148e..39b35837b 100644
--- a/src/http/modules/ngx_http_headers_filter.c
+++ b/src/http/modules/ngx_http_headers_filter.c
@@ -59,7 +59,7 @@ ngx_module_t ngx_http_headers_filter_module = {
ngx_http_headers_filter_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_headers_filter_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c
index 1c7d0dfad..4e3755766 100644
--- a/src/http/modules/ngx_http_index_handler.c
+++ b/src/http/modules/ngx_http_index_handler.c
@@ -86,7 +86,7 @@ ngx_module_t ngx_http_index_module = {
ngx_http_index_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_index_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c
index 0049af6cb..03f274560 100644
--- a/src/http/modules/ngx_http_range_filter.c
+++ b/src/http/modules/ngx_http_range_filter.c
@@ -73,7 +73,7 @@ ngx_module_t ngx_http_range_header_filter_module = {
NULL, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_range_header_filter_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
@@ -97,7 +97,7 @@ ngx_module_t ngx_http_range_body_filter_module = {
NULL, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_range_body_filter_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
@@ -144,7 +144,7 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
return ngx_http_next_header_filter(r);
}
- if (ngx_array_init(&r->headers_out.ranges, r->pool, 5,
+ if (ngx_array_init(&r->headers_out.ranges, r->pool, 2,
sizeof(ngx_http_range_t)) == NGX_ERROR)
{
return NGX_ERROR;
diff --git a/src/http/modules/ngx_http_rewrite_handler.c b/src/http/modules/ngx_http_rewrite_handler.c
index d3c721fda..3080bd6f4 100644
--- a/src/http/modules/ngx_http_rewrite_handler.c
+++ b/src/http/modules/ngx_http_rewrite_handler.c
@@ -540,7 +540,7 @@ ngx_http_rewrite_var_code(ngx_http_rewrite_engine_t *e)
e->ip += sizeof(ngx_http_rewrite_var_code_t);
- if (!(value = ngx_http_get_variable(e->request, code->index))) {
+ if (!(value = ngx_http_get_indexed_variable(e->request, code->index))) {
*e->sp = (uintptr_t) 0;
return;
}
@@ -698,6 +698,10 @@ ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_value(conf->no_referer, prev->no_referer, 0);
}
+ if (conf->no_referer == NGX_CONF_UNSET) {
+ conf->no_referer = 0;
+ }
+
if (conf->codes == NULL) {
return NGX_CONF_OK;
}
@@ -1025,12 +1029,12 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
char *rv;
u_char *elts;
ngx_str_t *value;
+ ngx_int_t index;
ngx_uint_t i;
ngx_conf_t save;
ngx_http_rewrite_code_pt *code;
ngx_http_module_t *module;
ngx_http_conf_ctx_t *ctx, *pctx;
- ngx_http_variable_t *var;
ngx_http_core_loc_conf_t *clcf, *pclcf, **clcfp;
ngx_http_core_main_conf_t *cmcf;
ngx_http_rewrite_if_code_t *if_code;
@@ -1119,23 +1123,11 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
*code = ngx_http_rewrite_invalid_referer_code;
} else {
-
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
- var = cmcf->variables.elts;
- for (i = 0; i < cmcf->variables.nelts; i++) {
- if (var[i].name.len != value[1].len) {
- continue;
- }
-
- if (ngx_strncasecmp(var[i].name.data, value[1].data,
- var[i].name.len) == 0)
- {
- break;
- }
- }
+ index = ngx_http_get_variable_index(cmcf, &value[1]);
- if (i == cmcf->variables.nelts) {
+ if (index == -1) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"unknown variable name \"%V\"", &value[1]);
return NGX_CONF_ERROR;
@@ -1148,7 +1140,7 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
var_code->code = ngx_http_rewrite_var_code;
- var_code->index = var[i].index;
+ var_code->index = index;
}
if_code = ngx_array_push_n(lcf->codes, sizeof(ngx_http_rewrite_if_code_t));
diff --git a/src/http/modules/ngx_http_ssi_filter.c b/src/http/modules/ngx_http_ssi_filter.c
index f4b9737eb..ca877ac94 100644
--- a/src/http/modules/ngx_http_ssi_filter.c
+++ b/src/http/modules/ngx_http_ssi_filter.c
@@ -41,6 +41,8 @@ typedef struct {
ngx_chain_t *in;
ngx_chain_t *out;
ngx_chain_t **last_out;
+ ngx_chain_t *busy;
+ ngx_chain_t *free;
ngx_uint_t state;
ngx_uint_t saved_state;
@@ -158,7 +160,7 @@ ngx_module_t ngx_http_ssi_filter_module = {
ngx_http_ssi_filter_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_ssi_filter_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
@@ -212,7 +214,8 @@ ngx_http_ssi_header_filter(ngx_http_request_t *r)
}
- if (!(ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_ssi_ctx_t)))) {
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_ssi_ctx_t));
+ if (ctx == NULL) {
return NGX_ERROR;
}
@@ -262,7 +265,7 @@ ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module);
- if (ctx == NULL || (in == NULL && ctx->in == NULL)) {
+ if (ctx == NULL || (in == NULL && ctx->in == NULL && ctx->busy == NULL)) {
return ngx_http_next_body_filter(r, in);
}
@@ -279,19 +282,21 @@ ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http ssi filter");
- b = NULL;
+ while (ctx->in || ctx->buf) {
- while (ctx->in) {
-
- ctx->buf = ctx->in->buf;
- ctx->in = ctx->in->next;
- ctx->pos = ctx->buf->pos;
+ if (ctx->buf == NULL ){
+ ctx->buf = ctx->in->buf;
+ ctx->in = ctx->in->next;
+ ctx->pos = ctx->buf->pos;
+ }
if (ctx->state == ssi_start_state) {
ctx->copy_start = ctx->pos;
ctx->copy_end = ctx->pos;
}
+ b = NULL;
+
while (ctx->pos < ctx->buf->last) {
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
@@ -313,32 +318,60 @@ ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
"saved: %d", ctx->saved);
if (ctx->saved) {
- if (!(b = ngx_calloc_buf(r->pool))) {
- return NGX_ERROR;
+
+ if (ctx->free) {
+ cl = ctx->free;
+ ctx->free = ctx->free->next;
+ b = cl->buf;
+ ngx_memzero(b, sizeof(ngx_buf_t));
+
+ } else {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl->buf = b;
}
b->memory = 1;
b->pos = ngx_http_ssi_string;
b->last = ngx_http_ssi_string + ctx->saved;
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
- return NGX_ERROR;
- }
-
- cl->buf = b;
*ctx->last_out = cl;
ctx->last_out = &cl->next;
ctx->saved = 0;
}
- if (!(b = ngx_calloc_buf(r->pool))) {
- return NGX_ERROR;
+ if (ctx->free) {
+ cl = ctx->free;
+ ctx->free = ctx->free->next;
+ b = cl->buf;
+
+ } else {
+ b = ngx_alloc_buf(r->pool);
+ if (b == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl->buf = b;
}
ngx_memcpy(b, ctx->buf, sizeof(ngx_buf_t));
b->last_buf = 0;
+ b->recycled = 0;
b->pos = ctx->copy_start;
b->last = ctx->copy_end;
@@ -353,11 +386,6 @@ ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
}
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
- return NGX_ERROR;
- }
-
- cl->buf = b;
cl->next = NULL;
*ctx->last_out = cl;
ctx->last_out = &cl->next;
@@ -461,14 +489,30 @@ ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
/* rc == NGX_HTTP_SSI_ERROR */
-ssi_error:
+ ssi_error:
if (conf->silent_errors) {
continue;
}
- if (!(b = ngx_calloc_buf(r->pool))) {
- return NGX_ERROR;
+ if (ctx->free) {
+ cl = ctx->free;
+ ctx->free = ctx->free->next;
+ b = cl->buf;
+ ngx_memzero(b, sizeof(ngx_buf_t));
+
+ } else {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl->buf = b;
}
b->memory = 1;
@@ -476,11 +520,6 @@ ssi_error:
b->last = ngx_http_ssi_error_string
+ sizeof(ngx_http_ssi_error_string) - 1;
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
- return NGX_ERROR;
- }
-
- cl->buf = b;
cl->next = NULL;
*ctx->last_out = cl;
ctx->last_out = &cl->next;
@@ -488,24 +527,85 @@ ssi_error:
continue;
}
- ctx->buf->pos = ctx->buf->last;
+ if (ctx->buf->recycled || ctx->buf->last_buf) {
+ if (b == NULL) {
+
+ if (ctx->free) {
+ cl = ctx->free;
+ ctx->free = ctx->free->next;
+ b = cl->buf;
+ ngx_memzero(b, sizeof(ngx_buf_t));
+
+ } else {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl->buf = b;
+ }
+
+ cl->next = NULL;
+ *ctx->last_out = cl;
+ ctx->last_out = &cl->next;
+ }
- if (b && ctx->buf->last_buf) {
- b->last_buf = 1;
+ b->last_buf = ctx->buf->last_buf;
+ b->flush = ctx->buf->recycled;
+ b->shadow = ctx->buf;
}
+ ctx->buf = NULL;
+
ctx->saved = ctx->looked;
}
- if (ctx->out == NULL) {
+ if (ctx->out == NULL && ctx->busy == NULL) {
return NGX_OK;
}
rc = ngx_http_next_body_filter(r, ctx->out);
+ if (ctx->busy == NULL) {
+ ctx->busy = ctx->out;
+
+ } else {
+ for (cl = ctx->busy; cl->next; cl = cl->next) { /* void */ }
+ cl->next = ctx->out;
+ }
+
ctx->out = NULL;
ctx->last_out = &ctx->out;
+ while (ctx->busy) {
+
+ b = ctx->busy->buf;
+
+ if (ngx_buf_size(b) != 0) {
+ break;
+ }
+
+#if (NGX_HAVE_WRITE_ZEROCOPY)
+ if (b->zerocopy_busy) {
+ break;
+ }
+#endif
+
+ if (b->shadow) {
+ b->shadow->pos = b->shadow->last;
+ }
+
+ cl = ctx->busy;
+ ctx->busy = cl->next;
+ cl->next = ctx->free;
+ ctx->free = cl;
+ }
+
return rc;
}
@@ -530,16 +630,20 @@ ngx_http_ssi_parse(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx)
/* the tight loop */
- for ( /* void */ ; p < last; ch = *(++p)) {
- if (ch != '<') {
- continue;
+ for ( ;; ) {
+ if (ch == '<') {
+ copy_end = p;
+ looked = 1;
+ state = ssi_tag_state;
+
+ goto tag_started;
}
- copy_end = p;
- looked = 1;
- state = ssi_tag_state;
+ if (++p == last) {
+ break;
+ }
- goto tag_started;
+ ch = *p;
}
ctx->pos = p;
@@ -552,7 +656,8 @@ ngx_http_ssi_parse(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx)
return NGX_AGAIN;
-tag_started:
+ tag_started:
+
continue;
}
@@ -715,7 +820,8 @@ tag_started:
break;
default:
- if (!(ctx->param = ngx_array_push(&ctx->params))) {
+ ctx->param = ngx_array_push(&ctx->params);
+ if (ctx->param == NULL) {
return NGX_ERROR;
}
@@ -1041,80 +1147,45 @@ static ngx_int_t
ngx_http_ssi_echo(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
ngx_str_t **params)
{
- u_char ch;
- ngx_uint_t i, n;
- ngx_buf_t *b;
- ngx_str_t *var, *value;
- ngx_chain_t *cl;
- ngx_list_part_t *part;
- ngx_table_elt_t *header;
+ ngx_buf_t *b;
+ ngx_str_t *var, *value;
+ ngx_chain_t *cl;
+ ngx_http_variable_value_t *v;
var = params[NGX_HTTP_SSI_ECHO_VAR];
value = NULL;
- if (var->len > 5 && ngx_strncmp(var->data, "HTTP_", 5) == 0) {
+ v = ngx_http_get_variable(r, var);
- part = &r->headers_in.headers.part;
- header = part->elts;
-
- for (i = 0; /* void */ ; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- header = part->elts;
- i = 0;
- }
-
- for (n = 0; n + 5 < var->len && n < header[i].key.len; n++)
- {
- ch = header[i].key.data[n];
-
- if (ch >= 'a' && ch <= 'z') {
- ch &= ~0x20;
+ if (v == NULL) {
+ return NGX_HTTP_SSI_ERROR;
+ }
- } else if (ch == '-') {
- ch = '_';
- }
+ if (v == NGX_HTTP_VARIABLE_NOT_FOUND) {
+ value = params[NGX_HTTP_SSI_ECHO_DEFAULT];
- if (var->data[n + 5] != ch) {
- break;
- }
- }
+ if (value == NULL) {
+ value = &ngx_http_ssi_none;
- if (n + 5 == var->len) {
- value = &header[i].value;
- break;
- }
+ } else if (value->len == 0) {
+ return NGX_OK;
}
- } else if (var->len == sizeof("REMOTE_ADDR") - 1
- && ngx_strncmp(var->data, "REMOTE_ADDR",
- sizeof("REMOTE_ADDR") - 1) == 0)
- {
- value = &r->connection->addr_text;
- }
-
+ } else {
+ value = &v->text;
- if (value == NULL) {
- value = params[NGX_HTTP_SSI_ECHO_DEFAULT];
- }
-
- if (value == NULL) {
- value = &ngx_http_ssi_none;
-
- } else if (value->len == 0) {
- return NGX_OK;
+ if (value->len == 0) {
+ return NGX_OK;
+ }
}
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_HTTP_SSI_ERROR;
}
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
return NGX_HTTP_SSI_ERROR;
}
@@ -1136,7 +1207,8 @@ ngx_http_ssi_create_conf(ngx_conf_t *cf)
{
ngx_http_ssi_conf_t *conf;
- if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssi_conf_t)))) {
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssi_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c
index 1ff45da60..4f0f96dc0 100644
--- a/src/http/modules/ngx_http_static_handler.c
+++ b/src/http/modules/ngx_http_static_handler.c
@@ -59,7 +59,7 @@ ngx_module_t ngx_http_static_module = {
ngx_http_static_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_static_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
diff --git a/src/http/modules/ngx_http_userid_filter.c b/src/http/modules/ngx_http_userid_filter.c
index aee161b53..ea49f928b 100644
--- a/src/http/modules/ngx_http_userid_filter.c
+++ b/src/http/modules/ngx_http_userid_filter.c
@@ -38,30 +38,29 @@ typedef struct {
static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r,
- ngx_http_userid_ctx_t *ctx,
- ngx_http_userid_conf_t *conf);
+ ngx_http_userid_ctx_t *ctx, ngx_http_userid_conf_t *conf);
static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
- ngx_http_userid_ctx_t *ctx,
- ngx_http_userid_conf_t *conf);
+ ngx_http_userid_ctx_t *ctx, ngx_http_userid_conf_t *conf);
static size_t ngx_http_userid_log_uid_got_getlen(ngx_http_request_t *r,
- uintptr_t data);
+ uintptr_t data);
static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf,
- ngx_http_log_op_t *op);
+ ngx_http_log_op_t *op);
static size_t ngx_http_userid_log_uid_set_getlen(ngx_http_request_t *r,
- uintptr_t data);
+ uintptr_t data);
static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf,
- ngx_http_log_op_t *op);
+ ngx_http_log_op_t *op);
static ngx_int_t ngx_http_userid_add_log_formats(ngx_conf_t *cf);
static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle);
static void *ngx_http_userid_create_conf(ngx_conf_t *cf);
static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent,
- void *child);
-char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data);
-char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data);
-char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
-char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data);
+ void *child);
+static char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data);
+static char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data);
+static char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd,
+ void *conf);
+static char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data);
static uint32_t sequencer_v1 = 1;
@@ -141,7 +140,7 @@ static ngx_command_t ngx_http_userid_commands[] = {
offsetof(ngx_http_userid_conf_t, p3p),
&ngx_http_userid_p3p_p },
- ngx_null_command
+ ngx_null_command
};
@@ -180,7 +179,8 @@ static ngx_http_log_op_name_t ngx_http_userid_log_fmt_ops[] = {
};
-static ngx_int_t ngx_http_userid_filter(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_userid_filter(ngx_http_request_t *r)
{
ngx_int_t rc;
ngx_http_userid_ctx_t *ctx;
@@ -192,8 +192,14 @@ static ngx_int_t ngx_http_userid_filter(ngx_http_request_t *r)
return ngx_http_next_header_filter(r);
}
- ngx_http_create_ctx(r, ctx, ngx_http_userid_filter_module,
- sizeof(ngx_http_userid_ctx_t), NGX_ERROR);
+
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_userid_ctx_t));
+ if (ctx == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_http_set_ctx(r, ctx, ngx_http_userid_filter_module);
+
rc = ngx_http_userid_get_uid(r, ctx, conf);
@@ -215,9 +221,9 @@ static ngx_int_t ngx_http_userid_filter(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r,
- ngx_http_userid_ctx_t *ctx,
- ngx_http_userid_conf_t *conf)
+static ngx_int_t
+ngx_http_userid_get_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
+ ngx_http_userid_conf_t *conf)
{
u_char *start, *last, *end;
ngx_uint_t i;
@@ -299,9 +305,9 @@ static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r,
}
-static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
- ngx_http_userid_ctx_t *ctx,
- ngx_http_userid_conf_t *conf)
+static ngx_int_t
+ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
+ ngx_http_userid_conf_t *conf)
{
u_char *cookie, *p;
size_t len;
@@ -363,7 +369,8 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
len += conf->domain.len;
}
- if (!(cookie = ngx_palloc(r->pool, len))) {
+ cookie = ngx_palloc(r->pool, len);
+ if (cookie == NULL) {
return NGX_ERROR;
}
@@ -392,7 +399,8 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
p = ngx_cpymem(p, conf->path.data, conf->path.len);
- if (!(set_cookie = ngx_list_push(&r->headers_out.headers))) {
+ set_cookie = ngx_list_push(&r->headers_out.headers);
+ if (set_cookie == NULL) {
return NGX_ERROR;
}
@@ -408,7 +416,8 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
return NGX_OK;
}
- if (!(p3p = ngx_list_push(&r->headers_out.headers))) {
+ p3p = ngx_list_push(&r->headers_out.headers);
+ if (p3p == NULL) {
return NGX_ERROR;
}
@@ -420,8 +429,8 @@ static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
}
-static size_t ngx_http_userid_log_uid_got_getlen(ngx_http_request_t *r,
- uintptr_t data)
+static size_t
+ngx_http_userid_log_uid_got_getlen(ngx_http_request_t *r, uintptr_t data)
{
ngx_http_userid_ctx_t *ctx;
ngx_http_userid_conf_t *conf;
@@ -438,8 +447,9 @@ static size_t ngx_http_userid_log_uid_got_getlen(ngx_http_request_t *r,
}
-static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf,
- ngx_http_log_op_t *op)
+static u_char *
+ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf,
+ ngx_http_log_op_t *op)
{
ngx_http_userid_ctx_t *ctx;
ngx_http_userid_conf_t *conf;
@@ -463,8 +473,8 @@ static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf,
}
-static size_t ngx_http_userid_log_uid_set_getlen(ngx_http_request_t *r,
- uintptr_t data)
+static size_t
+ngx_http_userid_log_uid_set_getlen(ngx_http_request_t *r, uintptr_t data)
{
ngx_http_userid_ctx_t *ctx;
ngx_http_userid_conf_t *conf;
@@ -481,8 +491,9 @@ static size_t ngx_http_userid_log_uid_set_getlen(ngx_http_request_t *r,
}
-static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf,
- ngx_http_log_op_t *op)
+static u_char *
+ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf,
+ ngx_http_log_op_t *op)
{
ngx_http_userid_ctx_t *ctx;
ngx_http_userid_conf_t *conf;
@@ -506,7 +517,8 @@ static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf,
}
-static ngx_int_t ngx_http_userid_add_log_formats(ngx_conf_t *cf)
+static ngx_int_t
+ngx_http_userid_add_log_formats(ngx_conf_t *cf)
{
ngx_http_log_op_name_t *op;
@@ -525,7 +537,8 @@ static ngx_int_t ngx_http_userid_add_log_formats(ngx_conf_t *cf)
}
-static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_userid_init(ngx_cycle_t *cycle)
{
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_userid_filter;
@@ -534,11 +547,13 @@ static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle)
}
-static void *ngx_http_userid_create_conf(ngx_conf_t *cf)
+static void *
+ngx_http_userid_create_conf(ngx_conf_t *cf)
{
ngx_http_userid_conf_t *conf;
- if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_userid_conf_t)))) {
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_userid_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -563,8 +578,8 @@ static void *ngx_http_userid_create_conf(ngx_conf_t *cf)
}
-static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent,
- void *child)
+static char *
+ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_userid_conf_t *prev = parent;
ngx_http_userid_conf_t *conf = child;
@@ -583,7 +598,8 @@ static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent,
}
-char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data)
+static char *
+ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data)
{
ngx_str_t *domain = data;
@@ -596,7 +612,8 @@ char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data)
return NGX_CONF_OK;
}
- if (!(new = ngx_palloc(cf->pool, sizeof("; domain=") - 1 + domain->len))) {
+ new = ngx_palloc(cf->pool, sizeof("; domain=") - 1 + domain->len);
+ if (new == NULL) {
return NGX_CONF_ERROR;
}
@@ -610,13 +627,15 @@ char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data)
}
-char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data)
+static char *
+ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data)
{
ngx_str_t *path = data;
u_char *p, *new;
- if (!(new = ngx_palloc(cf->pool, sizeof("; path=") - 1 + path->len))) {
+ new = ngx_palloc(cf->pool, sizeof("; path=") - 1 + path->len);
+ if (new == NULL) {
return NGX_CONF_ERROR;
}
@@ -630,7 +649,8 @@ char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data)
}
-char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+static char *
+ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_userid_conf_t *ucf = conf;
@@ -665,7 +685,8 @@ char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
-char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data)
+static char *
+ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data)
{
ngx_str_t *p3p = data;
diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c
index e35433b08..061ab9f0e 100644
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -190,7 +190,7 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
for (i = 0; i < p->lcf->x_vars->nelts; i++) {
- if (!(value = ngx_http_get_variable(r, index[i]))) {
+ if (!(value = ngx_http_get_indexed_variable(r, index[i]))) {
continue;
}
@@ -379,7 +379,7 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
if (p->lcf->x_vars) {
for (i = 0; i < p->lcf->x_vars->nelts; i++) {
- if (!(value = ngx_http_get_variable(r, index[i]))) {
+ if (!(value = ngx_http_get_indexed_variable(r, index[i]))) {
continue;
}