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/http
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2005-03-19 15:38:37 +0300
committerIgor Sysoev <igor@sysoev.ru>2005-03-19 15:38:37 +0300
commitc15717285d2157a603bb1b130b26d7baa549be7e (patch)
tree56dc8346b22bb2660eecd3bc086d263ac6d67326 /src/http
parente12fbfe82a176cd386cdcecfeabf43ac8fd870a4 (diff)
nginx-0.1.25-RELEASE importrelease-0.1.25
*) Bugfix: nginx did run on Linux parisc. *) Feature: nginx now does not start under FreeBSD if the sysctl kern.ipc.somaxconn value is too big. *) Bugfix: if a request was internally redirected by the ngx_http_index_module module to the ngx_http_proxy_module or ngx_http_fastcgi_module modules, then the index file was not closed after request completion. *) Feature: the "proxy_pass" can be used in location with regular expression. *) Feature: the ngx_http_rewrite_filter_module module supports the condition like "if ($HTTP_USER_AGENT ~ MSIE)". *) Bugfix: nginx started too slow if the large number of addresses and text values were used in the "geo" directive. *) Change: a variable name must be declared as "$name" in the "geo" directive. The previous variant without "$" is still supported, but will be removed soon. *) Feature: the "%{VARIABLE}v" logging parameter. *) Feature: the "set $name value" directive. *) Bugfix: gcc 4.0 compatibility. *) Feature: the --with-openssl-opt=OPTIONS autoconfiguration directive.
Diffstat (limited to 'src/http')
-rw-r--r--src/http/modules/ngx_http_access_module.c (renamed from src/http/modules/ngx_http_access_handler.c)31
-rw-r--r--src/http/modules/ngx_http_autoindex_module.c (renamed from src/http/modules/ngx_http_autoindex_handler.c)23
-rw-r--r--src/http/modules/ngx_http_charset_filter_module.c (renamed from src/http/modules/ngx_http_charset_filter.c)93
-rw-r--r--src/http/modules/ngx_http_chunked_filter_module.c (renamed from src/http/modules/ngx_http_chunked_filter.c)24
-rw-r--r--src/http/modules/ngx_http_fastcgi_module.c (renamed from src/http/modules/ngx_http_fastcgi_handler.c)94
-rw-r--r--src/http/modules/ngx_http_geo_module.c48
-rw-r--r--src/http/modules/ngx_http_gzip_filter_module.c (renamed from src/http/modules/ngx_http_gzip_filter.c)70
-rw-r--r--src/http/modules/ngx_http_headers_filter_module.c (renamed from src/http/modules/ngx_http_headers_filter.c)29
-rw-r--r--src/http/modules/ngx_http_index_module.c (renamed from src/http/modules/ngx_http_index_handler.c)51
-rw-r--r--src/http/modules/ngx_http_not_modified_filter_module.c (renamed from src/http/modules/ngx_http_not_modified_filter.c)0
-rw-r--r--src/http/modules/ngx_http_range_filter_module.c (renamed from src/http/modules/ngx_http_range_filter.c)52
-rw-r--r--src/http/modules/ngx_http_rewrite_module.c (renamed from src/http/modules/ngx_http_rewrite_handler.c)560
-rw-r--r--src/http/modules/ngx_http_ssi_filter_module.c (renamed from src/http/modules/ngx_http_ssi_filter.c)18
-rw-r--r--src/http/modules/ngx_http_ssl_module.c24
-rw-r--r--src/http/modules/ngx_http_ssl_module.h2
-rw-r--r--src/http/modules/ngx_http_static_module.c (renamed from src/http/modules/ngx_http_static_handler.c)40
-rw-r--r--src/http/modules/ngx_http_status_module.c (renamed from src/http/modules/ngx_http_status_handler.c)0
-rw-r--r--src/http/modules/ngx_http_stub_status_module.c3
-rw-r--r--src/http/modules/ngx_http_userid_filter_module.c (renamed from src/http/modules/ngx_http_userid_filter.c)4
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.c42
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_header.c9
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_upstream.c79
-rw-r--r--src/http/ngx_http.c89
-rw-r--r--src/http/ngx_http.h13
-rw-r--r--src/http/ngx_http_busy_lock.c6
-rw-r--r--src/http/ngx_http_config.h10
-rw-r--r--src/http/ngx_http_copy_filter_module.c (renamed from src/http/ngx_http_copy_filter.c)44
-rw-r--r--src/http/ngx_http_core_module.c73
-rw-r--r--src/http/ngx_http_header_filter_module.c (renamed from src/http/ngx_http_header_filter.c)15
-rw-r--r--src/http/ngx_http_log_module.c (renamed from src/http/ngx_http_log_handler.c)143
-rw-r--r--src/http/ngx_http_log_module.h (renamed from src/http/ngx_http_log_handler.h)15
-rw-r--r--src/http/ngx_http_parse.c3
-rw-r--r--src/http/ngx_http_parse_time.c6
-rw-r--r--src/http/ngx_http_request.c136
-rw-r--r--src/http/ngx_http_request.h321
-rw-r--r--src/http/ngx_http_request_body.c54
-rw-r--r--src/http/ngx_http_special_response.c55
-rw-r--r--src/http/ngx_http_upstream.c17
-rw-r--r--src/http/ngx_http_variables.c235
-rw-r--r--src/http/ngx_http_variables.h30
-rw-r--r--src/http/ngx_http_write_filter_module.c (renamed from src/http/ngx_http_write_filter.c)24
41 files changed, 1730 insertions, 855 deletions
diff --git a/src/http/modules/ngx_http_access_handler.c b/src/http/modules/ngx_http_access_module.c
index 285570f23..685d15d57 100644
--- a/src/http/modules/ngx_http_access_handler.c
+++ b/src/http/modules/ngx_http_access_module.c
@@ -25,10 +25,10 @@ typedef struct {
static ngx_int_t ngx_http_access_handler(ngx_http_request_t *r);
static char *ngx_http_access_rule(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
+ void *conf);
static void *ngx_http_access_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_access_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child);
+ void *parent, void *child);
static ngx_int_t ngx_http_access_init(ngx_cycle_t *cycle);
@@ -77,7 +77,8 @@ ngx_module_t ngx_http_access_module = {
};
-static ngx_int_t ngx_http_access_handler(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_access_handler(ngx_http_request_t *r)
{
ngx_uint_t i;
struct sockaddr_in *sin;
@@ -117,8 +118,8 @@ static ngx_int_t ngx_http_access_handler(ngx_http_request_t *r)
}
-static char *ngx_http_access_rule(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+static char *
+ngx_http_access_rule(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_access_loc_conf_t *alcf = conf;
@@ -127,14 +128,15 @@ 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, 4,
+ alcf->rules = ngx_array_create(cf->pool, 4,
sizeof(ngx_http_access_rule_t));
if (alcf->rules == NULL) {
return NGX_CONF_ERROR;
}
}
- if (!(rule = ngx_push_array(alcf->rules))) {
+ rule = ngx_array_push(alcf->rules);
+ if (rule == NULL) {
return NGX_CONF_ERROR;
}
@@ -170,11 +172,13 @@ static char *ngx_http_access_rule(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static void *ngx_http_access_create_loc_conf(ngx_conf_t *cf)
+static void *
+ngx_http_access_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_access_loc_conf_t *conf;
- if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_access_loc_conf_t)))) {
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_access_loc_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -182,8 +186,8 @@ static void *ngx_http_access_create_loc_conf(ngx_conf_t *cf)
}
-static char *ngx_http_access_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child)
+static char *
+ngx_http_access_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_access_loc_conf_t *prev = parent;
ngx_http_access_loc_conf_t *conf = child;
@@ -196,14 +200,15 @@ static char *ngx_http_access_merge_loc_conf(ngx_conf_t *cf,
}
-static ngx_int_t ngx_http_access_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_access_init(ngx_cycle_t *cycle)
{
ngx_http_handler_pt *h;
ngx_http_core_main_conf_t *cmcf;
cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
- h = ngx_push_array(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers);
+ h = ngx_array_push(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers);
if (h == NULL) {
return NGX_ERROR;
}
diff --git a/src/http/modules/ngx_http_autoindex_handler.c b/src/http/modules/ngx_http_autoindex_module.c
index 8976ad546..a7b998678 100644
--- a/src/http/modules/ngx_http_autoindex_handler.c
+++ b/src/http/modules/ngx_http_autoindex_module.c
@@ -218,10 +218,7 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
if (ngx_read_dir(&dir) == NGX_ERROR) {
err = ngx_errno;
- if (err == NGX_ENOMOREFILES) {
- rc = NGX_OK;
-
- } else {
+ if (err != NGX_ENOMOREFILES) {
ngx_log_error(NGX_LOG_CRIT, r->connection->log, err,
ngx_read_dir_n " \"%s\" failed", dname.data);
return ngx_http_autoindex_error(r, &dir, dname.data);
@@ -251,7 +248,8 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
if (dname.len + 1 + len > fname.len) {
fname.len = dname.len + 1 + len + 32;
- if (!(fname.data = ngx_palloc(pool, fname.len))) {
+ fname.data = ngx_palloc(pool, fname.len);
+ if (fname.data == NULL) {
return ngx_http_autoindex_error(r, &dir, dname.data);
}
@@ -280,7 +278,8 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
}
}
- if (!(entry = ngx_array_push(&entries))) {
+ entry = ngx_array_push(&entries);
+ if (entry == NULL) {
return ngx_http_autoindex_error(r, &dir, dname.data);
}
@@ -288,7 +287,8 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
entry->escape = 2 * ngx_escape_uri(NULL, ngx_de_name(&dir), len,
NGX_ESCAPE_HTML);
- if (!(entry->name.data = ngx_palloc(pool, len + entry->escape + 1))) {
+ entry->name.data = ngx_palloc(pool, len + entry->escape + 1);
+ if (entry->name.data == NULL) {
return ngx_http_autoindex_error(r, &dir, dname.data);
}
@@ -326,7 +326,8 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
+ 2;
}
- if (!(b = ngx_create_temp_buf(r->pool, len))) {
+ b = ngx_create_temp_buf(r->pool, len);
+ if (b == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -481,11 +482,13 @@ ngx_http_autoindex_alloc(ngx_http_autoindex_ctx_t *ctx, size_t size)
ctx->size += ctx->buf->last - ctx->buf->pos;
}
- if (!(ctx->buf = ngx_create_temp_buf(ctx->pool, ctx->alloc_size))) {
+ ctx->buf = ngx_create_temp_buf(ctx->pool, ctx->alloc_size);
+ if (ctx->buf == NULL) {
return NULL;
}
- if (!(cl = ngx_alloc_chain_link(ctx->pool))) {
+ cl = ngx_alloc_chain_link(ctx->pool);
+ if (cl == NULL) {
return NULL;
}
diff --git a/src/http/modules/ngx_http_charset_filter.c b/src/http/modules/ngx_http_charset_filter_module.c
index cbd0fca75..dad26ba91 100644
--- a/src/http/modules/ngx_http_charset_filter.c
+++ b/src/http/modules/ngx_http_charset_filter_module.c
@@ -48,11 +48,11 @@ typedef struct {
static ngx_uint_t ngx_charset_recode(ngx_buf_t *b, char *table);
static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
+ void *conf);
static char *ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf);
static char *ngx_http_set_charset_slot(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
+ void *conf);
static ngx_int_t ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name);
static ngx_int_t ngx_http_charset_filter_init(ngx_cycle_t *cycle);
@@ -61,7 +61,7 @@ static void *ngx_http_charset_create_main_conf(ngx_conf_t *cf);
static char *ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf);
static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child);
+ void *parent, void *child);
static ngx_command_t ngx_http_charset_filter_commands[] = {
@@ -133,7 +133,8 @@ static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
-static ngx_int_t ngx_http_charset_header_filter(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_charset_header_filter(ngx_http_request_t *r)
{
ngx_http_charset_t *charsets;
ngx_http_charset_ctx_t *ctx;
@@ -165,7 +166,7 @@ static ngx_int_t ngx_http_charset_header_filter(ngx_http_request_t *r)
}
if (r->headers_out.status == NGX_HTTP_MOVED_PERMANENTLY
- && r->headers_out.status == NGX_HTTP_MOVED_TEMPORARILY)
+ || r->headers_out.status == NGX_HTTP_MOVED_TEMPORARILY)
{
/*
* do not set charset for the redirect because NN 4.x uses this
@@ -187,8 +188,14 @@ static ngx_int_t ngx_http_charset_header_filter(ngx_http_request_t *r)
return ngx_http_next_header_filter(r);
}
- ngx_http_create_ctx(r, ctx, ngx_http_charset_filter_module,
- sizeof(ngx_http_charset_ctx_t), NGX_ERROR);
+
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_charset_ctx_t));
+ if (ctx == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_http_set_ctx(r, ctx, ngx_http_charset_filter_module);
+
r->filter_need_in_memory = 1;
@@ -196,8 +203,8 @@ static ngx_int_t ngx_http_charset_header_filter(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_charset_body_filter(ngx_http_request_t *r,
- ngx_chain_t *in)
+static ngx_int_t
+ngx_http_charset_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
char *table;
ngx_chain_t *cl;
@@ -226,7 +233,8 @@ static ngx_int_t ngx_http_charset_body_filter(ngx_http_request_t *r,
}
-static ngx_uint_t ngx_charset_recode(ngx_buf_t *b, char *table)
+static ngx_uint_t
+ngx_charset_recode(ngx_buf_t *b, char *table)
{
u_char *p;
ngx_uint_t change;
@@ -254,8 +262,8 @@ static ngx_uint_t ngx_charset_recode(ngx_buf_t *b, char *table)
}
-static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+static char *
+ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_charset_main_conf_t *mcf = conf;
@@ -297,18 +305,21 @@ static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd,
}
}
- if (!(table = ngx_push_array(&mcf->tables))) {
+ table = ngx_array_push(&mcf->tables);
+ if (table == NULL) {
return NGX_CONF_ERROR;
}
table->src = src;
table->dst = dst;
- if (!(table->src2dst = ngx_palloc(cf->pool, 256))) {
+ table->src2dst = ngx_palloc(cf->pool, 256);
+ if (table->src2dst == NULL) {
return NGX_CONF_ERROR;
}
- if (!(table->dst2src = ngx_palloc(cf->pool, 256))) {
+ table->dst2src = ngx_palloc(cf->pool, 256);
+ if (table->dst2src == NULL) {
return NGX_CONF_ERROR;
}
@@ -326,14 +337,17 @@ static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd,
cf->ctx = table;
cf->handler = ngx_charset_map;
cf->handler_conf = conf;
+
rv = ngx_conf_parse(cf, NULL);
+
*cf = pvcf;
return rv;
}
-static char *ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
+static char *
+ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
{
ngx_int_t src, dst;
ngx_str_t *value;
@@ -369,8 +383,8 @@ static char *ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
}
-static char *ngx_http_set_charset_slot(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+static char *
+ngx_http_set_charset_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
@@ -404,7 +418,8 @@ static char *ngx_http_set_charset_slot(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static ngx_int_t ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name)
+static ngx_int_t
+ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name)
{
ngx_uint_t i;
ngx_http_charset_t *c;
@@ -424,7 +439,8 @@ static ngx_int_t ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name)
return i;
}
- if (!(c = ngx_push_array(charsets))) {
+ c = ngx_array_push(charsets);
+ if (c == NULL) {
return NGX_ERROR;
}
@@ -436,7 +452,8 @@ static ngx_int_t ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name)
}
-static ngx_int_t ngx_http_charset_filter_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_charset_filter_init(ngx_cycle_t *cycle)
{
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_charset_header_filter;
@@ -448,25 +465,34 @@ static ngx_int_t ngx_http_charset_filter_init(ngx_cycle_t *cycle)
}
-static void *ngx_http_charset_create_main_conf(ngx_conf_t *cf)
+static void *
+ngx_http_charset_create_main_conf(ngx_conf_t *cf)
{
ngx_http_charset_main_conf_t *mcf;
- if (!(mcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_main_conf_t)))) {
+ mcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_main_conf_t));
+ if (mcf == NULL) {
return NGX_CONF_ERROR;
}
- ngx_init_array(mcf->charsets, cf->pool, 2, sizeof(ngx_http_charset_t),
- NGX_CONF_ERROR);
+ if (ngx_array_init(&mcf->charsets, cf->pool, 2, sizeof(ngx_http_charset_t))
+ == NGX_ERROR)
+ {
+ return NGX_CONF_ERROR;
+ }
- ngx_init_array(mcf->tables, cf->pool, 4, sizeof(ngx_http_charset_tables_t),
- NGX_CONF_ERROR);
+ if (ngx_array_init(&mcf->tables, cf->pool, 4,
+ sizeof(ngx_http_charset_tables_t)) == NGX_ERROR)
+ {
+ return NGX_CONF_ERROR;
+ }
return mcf;
}
-static char *ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf)
+static char *
+ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf)
{
ngx_http_charset_main_conf_t *mcf = conf;
@@ -484,7 +510,6 @@ static char *ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf)
charset[i].tables = ngx_pcalloc(cf->pool,
sizeof(char *) * mcf->charsets.nelts);
-
if (charset[i].tables == NULL) {
return NGX_CONF_ERROR;
}
@@ -527,11 +552,13 @@ static char *ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf)
}
-static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf)
+static void *
+ngx_http_charset_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_charset_loc_conf_t *lcf;
- if (!(lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_loc_conf_t)))) {
+ lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_loc_conf_t));
+ if (lcf == NULL) {
return NGX_CONF_ERROR;
}
@@ -544,8 +571,8 @@ static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf)
}
-static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child)
+static char *
+ngx_http_charset_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_charset_loc_conf_t *prev = parent;
ngx_http_charset_loc_conf_t *conf = child;
diff --git a/src/http/modules/ngx_http_chunked_filter.c b/src/http/modules/ngx_http_chunked_filter_module.c
index 5145ff67f..b742dbb7c 100644
--- a/src/http/modules/ngx_http_chunked_filter.c
+++ b/src/http/modules/ngx_http_chunked_filter_module.c
@@ -40,7 +40,8 @@ static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
-static ngx_int_t ngx_http_chunked_header_filter(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_chunked_header_filter(ngx_http_request_t *r)
{
if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED) {
return ngx_http_next_header_filter(r);
@@ -59,8 +60,8 @@ static ngx_int_t ngx_http_chunked_header_filter(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r,
- ngx_chain_t *in)
+static ngx_int_t
+ngx_http_chunked_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
u_char *chunk;
off_t size;
@@ -85,7 +86,8 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r,
if (cl->buf->flush || ngx_buf_in_memory(cl->buf) || cl->buf->in_file) {
- if (!(tl = ngx_alloc_chain_link(r->pool))) {
+ tl = ngx_alloc_chain_link(r->pool);
+ if (tl == NULL) {
return NGX_ERROR;
}
@@ -102,10 +104,13 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r,
}
if (size) {
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
+ /* the "0000000000000000" is 64-bit hexadimal string */
+
chunk = ngx_palloc(r->pool, sizeof("0000000000000000" CRLF) - 1);
if (chunk == NULL) {
return NGX_ERROR;
@@ -119,7 +124,8 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r,
}
if (cl->buf->last_buf) {
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -144,7 +150,8 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r,
return ngx_http_next_body_filter(r, out.next);
}
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -161,7 +168,8 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r,
}
-static ngx_int_t ngx_http_chunked_filter_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_chunked_filter_init(ngx_cycle_t *cycle)
{
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_chunked_header_filter;
diff --git a/src/http/modules/ngx_http_fastcgi_handler.c b/src/http/modules/ngx_http_fastcgi_module.c
index 5b384b86e..a5f9a02c8 100644
--- a/src/http/modules/ngx_http_fastcgi_handler.c
+++ b/src/http/modules/ngx_http_fastcgi_module.c
@@ -377,7 +377,8 @@ ngx_http_fastcgi_handler(ngx_http_request_t *r)
flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
- if (!(u = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_t)))) {
+ u = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_t));
+ if (u == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -492,25 +493,24 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
index = (r->uri.data[r->uri.len - 1] == '/') ? flcf->index.len : 0;
len += 1 + ((flcf->root.len + r->uri.len + index > 127) ? 4 : 1)
- + sizeof("PATH_TRANSLATED") - 1
- + flcf->root.len + r->uri.len + index;
+ + sizeof("PATH_TRANSLATED") - 1 + flcf->root.len + r->uri.len + index;
if (r->args.len) {
len += 1 + ((r->args.len > 127) ? 4 : 1) + sizeof("QUERY_STRING") - 1
- + r->args.len;
+ + r->args.len;
}
if (r->headers_in.content_length_n > 0) {
len += 1 + ((r->headers_in.content_length->value.len > 127) ? 4 : 1)
- + sizeof("CONTENT_LENGTH") - 1
- + r->headers_in.content_length->value.len;
+ + sizeof("CONTENT_LENGTH") - 1
+ + r->headers_in.content_length->value.len;
}
if (r->headers_in.content_type) {
len += 1 + ((r->headers_in.content_type->value.len > 127) ? 4 : 1)
- + sizeof("CONTENT_TYPE") - 1
- + r->headers_in.content_type->value.len;
+ + sizeof("CONTENT_TYPE") - 1
+ + r->headers_in.content_type->value.len;
}
@@ -520,24 +520,24 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
if (flcf->params & NGX_HTTP_FASTCGI_REQUEST_URI) {
len += 1 + ((r->unparsed_uri.len > 127) ? 4 : 1)
- + sizeof("REQUEST_URI") - 1 + r->unparsed_uri.len;
+ + sizeof("REQUEST_URI") - 1 + r->unparsed_uri.len;
}
if (flcf->params & NGX_HTTP_FASTCGI_DOCUMENT_ROOT) {
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
len += 1 + ((clcf->root.len > 127) ? 4 : 1)
- + sizeof("DOCUMENT_ROOT") - 1 + clcf->root.len;
+ + sizeof("DOCUMENT_ROOT") - 1 + clcf->root.len;
}
if (flcf->params & NGX_HTTP_FASTCGI_SCRIPT_FILENAME) {
len += 1 + ((flcf->root.len + r->uri.len + index > 127) ? 4 : 1)
- + sizeof("SCRIPT_FILENAME") - 1
- + flcf->root.len + r->uri.len + index;
+ + sizeof("SCRIPT_FILENAME") - 1
+ + flcf->root.len + r->uri.len + index;
}
if (flcf->params & NGX_HTTP_FASTCGI_SCRIPT_NAME) {
len += 1 + ((r->uri.len + index > 127) ? 4 : 1)
- + sizeof("SCRIPT_NAME") - 1 + r->uri.len + index ;
+ + sizeof("SCRIPT_NAME") - 1 + r->uri.len + index ;
}
if (flcf->params & NGX_HTTP_FASTCGI_REMOTE_ADDR) {
@@ -579,7 +579,7 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
&& r->http_protocol.len)
{
len += 1 + ((r->http_protocol.len > 127) ? 4 : 1)
- + sizeof("SERVER_PROTOCOL") - 1 + r->http_protocol.len;
+ + sizeof("SERVER_PROTOCOL") - 1 + r->http_protocol.len;
}
if (flcf->params & NGX_HTTP_FASTCGI_SERVER_SOFTWARE) {
@@ -599,7 +599,8 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
for (i = 0; i < flcf->vars->nelts; i++) {
- if (!(value = ngx_http_get_indexed_variable(r, vindex[i]))) {
+ value = ngx_http_get_indexed_variable(r, vindex[i]);
+ if (value == NULL) {
continue;
}
@@ -626,8 +627,8 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
}
len += ((header[i].key.len > 127) ? 4 : 1)
- + ((header[i].value.len > 127) ? 4 : 1)
- + 5 + header[i].key.len + header[i].value.len;
+ + ((header[i].value.len > 127) ? 4 : 1)
+ + 5 + header[i].key.len + header[i].value.len;
}
@@ -652,11 +653,13 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
+ sizeof(ngx_http_fastcgi_header_t); /* NGX_HTTP_FASTCGI_STDIN */
- if (!(b = ngx_create_temp_buf(r->pool, size))) {
+ b = ngx_create_temp_buf(r->pool, size);
+ if (b == NULL) {
return NGX_ERROR;
}
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
return NGX_ERROR;
}
@@ -998,7 +1001,8 @@ 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_indexed_variable(r, vindex[i]))) {
+ value = ngx_http_get_indexed_variable(r, vindex[i]);
+ if (value == NULL) {
continue;
}
@@ -1115,7 +1119,8 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
next = 0;
do {
- if (!(b = ngx_alloc_buf(r->pool))) {
+ b = ngx_alloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -1158,7 +1163,8 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
h->padding_length = (u_char) padding;
h->reserved = 0;
- if (!(cl->next = ngx_alloc_chain_link(r->pool))) {
+ cl->next = ngx_alloc_chain_link(r->pool);
+ if (cl->next == NULL) {
return NGX_ERROR;
}
@@ -1179,7 +1185,8 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
h = (ngx_http_fastcgi_header_t *) b->last;
b->last += sizeof(ngx_http_fastcgi_header_t);
- if (!(cl->next = ngx_alloc_chain_link(r->pool))) {
+ cl->next = ngx_alloc_chain_link(r->pool);
+ if (cl->next == NULL) {
return NGX_ERROR;
}
@@ -1248,7 +1255,8 @@ static ngx_int_t ngx_http_fastcgi_process_header(ngx_http_request_t *r)
f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
if (f == NULL) {
- if (!(f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t)))) {
+ f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t));
+ if (f == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -1413,7 +1421,8 @@ static ngx_int_t ngx_http_fastcgi_process_header(ngx_http_request_t *r)
/* a header line has been parsed successfully */
- if (!(h = ngx_list_push(&f->upstream->headers_in.headers))) {
+ h = ngx_list_push(&f->upstream->headers_in.headers);
+ if (h == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -1580,7 +1589,8 @@ ngx_http_fastcgi_send_header(ngx_http_request_t *r)
/* copy some header pointers and set up r->headers_out */
- if (!(ho = ngx_list_push(&r->headers_out.headers))) {
+ ho = ngx_list_push(&r->headers_out.headers);
+ if (ho == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -1733,7 +1743,8 @@ ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
p->free = p->free->next;
} else {
- if (!(b = ngx_alloc_buf(p->pool))) {
+ b = ngx_alloc_buf(p->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
}
@@ -1750,18 +1761,26 @@ ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
*prev = b;
prev = &b->shadow;
- if (!(cl = ngx_alloc_chain_link(p->pool))) {
+ cl = ngx_alloc_chain_link(p->pool);
+ if (cl == NULL) {
return NGX_ERROR;
}
cl->buf = b;
cl->next = NULL;
+ if (p->in) {
+ *p->last_in = cl;
+ } else {
+ p->in = cl;
+ }
+ p->last_in = &cl->next;
+
+
/* STUB */ b->num = buf->num;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "input buf #%d", b->num);
- ngx_chain_add_link(p->in, p->last_in, cl);
if (f->pos + f->length < f->last) {
@@ -1820,11 +1839,8 @@ ngx_http_fastcgi_process_record(ngx_http_request_t *r,
ngx_http_fastcgi_ctx_t *f)
{
u_char ch, *p;
- ngx_http_upstream_t *u;
ngx_http_fastcgi_state_e state;
- u = r->upstream;
-
state = f->state;
for (p = f->pos; p < f->last; p++) {
@@ -1968,7 +1984,8 @@ ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
unix_upstream.name = value[1];
unix_upstream.url = value[1];
- if (!(lcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream))) {
+ lcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream);
+ if (lcf->peers == NULL) {
return NGX_CONF_ERROR;
}
@@ -1986,7 +2003,8 @@ ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
inet_upstream.name = value[1];
inet_upstream.url = value[1];
- if (!(lcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream))) {
+ lcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream);
+ if (lcf->peers == NULL) {
return NGX_CONF_ERROR;
}
}
@@ -1996,7 +2014,7 @@ ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
clcf->handler = ngx_http_fastcgi_handler;
#if (NGX_PCRE)
- lcf->location = clcf->regex ? &ngx_http_fastcgi_uri: &clcf->name;
+ lcf->location = clcf->regex ? &ngx_http_fastcgi_uri : &clcf->name;
#else
lcf->location = &clcf->name;
#endif
@@ -2035,7 +2053,8 @@ ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
for (i = 0; i < cmcf->variables.nelts; i++) {
if (ngx_strcasecmp(var[i].name.data, value[1].data) == 0) {
- if (!(index = ngx_array_push(lcf->vars))) {
+ index = ngx_array_push(lcf->vars);
+ if (index == NULL) {
return NGX_CONF_ERROR;
}
@@ -2084,7 +2103,8 @@ ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_fastcgi_loc_conf_t *conf;
- if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_fastcgi_loc_conf_t)))) {
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_fastcgi_loc_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/ngx_http_geo_module.c b/src/http/modules/ngx_http_geo_module.c
index 0d8267d8e..865f82551 100644
--- a/src/http/modules/ngx_http_geo_module.c
+++ b/src/http/modules/ngx_http_geo_module.c
@@ -64,9 +64,9 @@ static ngx_http_variable_value_t ngx_http_geo_null_value =
/* AF_INET only */
static ngx_http_variable_value_t *
-ngx_http_geo_variable(ngx_http_request_t *r, void *data)
+ngx_http_geo_variable(ngx_http_request_t *r, uintptr_t data)
{
- ngx_radix_tree_t *tree = data;
+ ngx_radix_tree_t *tree = (ngx_radix_tree_t *) data;
struct sockaddr_in *sin;
ngx_http_variable_value_t *var;
@@ -90,33 +90,46 @@ static char *
ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *rv;
- ngx_str_t *value;
+ ngx_str_t *value, name;
ngx_conf_t save;
ngx_pool_t *pool;
ngx_radix_tree_t *tree;
ngx_http_geo_conf_t geo;
ngx_http_variable_t *var;
- if (!(var = ngx_http_add_variable(cf))) {
- return NGX_CONF_ERROR;
+ value = cf->args->elts;
+
+ name = value[1];
+
+ if (name.data[0] != '$') {
+ ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
+ "\"%V\" variable name should start with '$'",
+ &value[1]);
+ } else {
+ name.len--;
+ name.data++;
}
- if (!(tree = ngx_radix_tree_create(cf->pool, -1))) {
+ var = ngx_http_add_variable(cf, &name, 1);
+ if (var == NULL) {
return NGX_CONF_ERROR;
}
- value = cf->args->elts;
+ tree = ngx_radix_tree_create(cf->pool, -1);
+ if (tree == NULL) {
+ return NGX_CONF_ERROR;
+ }
- var->name = value[1];
var->handler = ngx_http_geo_variable;
- var->data = tree;
+ var->data = (uintptr_t) tree;
/*
* create the temporary pool of a huge initial size
* to process quickly a large number of geo lines
*/
- if (!(pool = ngx_create_pool(512 * 1024, cf->log))) {
+ pool = ngx_create_pool(512 * 1024, cf->log);
+ if (pool == NULL) {
return NGX_CONF_ERROR;
}
@@ -212,7 +225,12 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
if (n == NGX_ERROR) {
for (i = 0; i < geo->values.nelts; i++) {
- if (ngx_strcmp(value[1].data, v[i]->text.data) == 0) {
+ if (v[i]->text.len != value[1].len) {
+ continue;
+ }
+
+ if (ngx_strncmp(value[1].data, v[i]->text.data, value[1].len) == 0)
+ {
var = v[i];
break;
}
@@ -227,20 +245,22 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
}
}
- if (i == geo->values.nelts) {
+ if (var == NULL) {
var = ngx_palloc(geo->pool, sizeof(ngx_http_variable_value_t));
if (var == NULL) {
return NGX_CONF_ERROR;
}
var->text.len = value[1].len;
- if (!(var->text.data = ngx_pstrdup(geo->pool, &value[1]))) {
+ var->text.data = ngx_pstrdup(geo->pool, &value[1]);
+ if (var->text.data == NULL) {
return NGX_CONF_ERROR;
}
var->value = (n == NGX_ERROR) ? 0 : n;
- if (!(v = ngx_array_push(&geo->values))) {
+ v = ngx_array_push(&geo->values);
+ if (v == NULL) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter_module.c
index eec6a134d..4a4da7f58 100644
--- a/src/http/modules/ngx_http_gzip_filter.c
+++ b/src/http/modules/ngx_http_gzip_filter_module.c
@@ -331,9 +331,14 @@ ngx_http_gzip_header_filter(ngx_http_request_t *r)
return ngx_http_next_header_filter(r);
}
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_gzip_ctx_t));
+ if (ctx == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_http_set_ctx(r, ctx, ngx_http_gzip_filter_module);
+
- ngx_http_create_ctx(r, ctx, ngx_http_gzip_filter_module,
- sizeof(ngx_http_gzip_ctx_t), NGX_ERROR);
ctx->request = r;
r->headers_out.content_encoding = ngx_list_push(&r->headers_out.headers);
@@ -445,7 +450,7 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ngx_int_t last;
struct gztrailer *trailer;
ngx_buf_t *b;
- ngx_chain_t *cl;
+ ngx_chain_t *cl, out;
ngx_http_gzip_ctx_t *ctx;
ngx_http_gzip_conf_t *conf;
@@ -485,7 +490,8 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ctx->allocated = 8192 + (1 << (wbits + 2)) + (1 << (memlevel + 9));
- if (!(ctx->preallocated = ngx_palloc(r->pool, ctx->allocated))) {
+ ctx->preallocated = ngx_palloc(r->pool, ctx->allocated);
+ if (ctx->preallocated == NULL) {
return NGX_ERROR;
}
@@ -505,7 +511,8 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
return NGX_ERROR;
}
- if (!(b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)))) {
+ b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
+ if (b == NULL) {
ngx_http_gzip_error(ctx);
return NGX_ERROR;
}
@@ -514,12 +521,8 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
b->pos = gzheader;
b->last = b->pos + 10;
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
- ngx_http_gzip_error(ctx);
- return NGX_ERROR;
- }
- cl->buf = b;
- cl->next = NULL;
+ out.buf = b;
+ out.next = NULL;
/*
* We pass the gzheader to the next filter now to avoid its linking
@@ -528,7 +531,7 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
* to the ctx->busy chain would be flushed by ngx_http_write_filter().
*/
- if (ngx_http_next_body_filter(r, cl) == NGX_ERROR) {
+ if (ngx_http_next_body_filter(r, &out) == NGX_ERROR) {
ngx_http_gzip_error(ctx);
return NGX_ERROR;
}
@@ -673,10 +676,12 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
/* zlib wants to output some more gzipped data */
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
ngx_http_gzip_error(ctx);
return NGX_ERROR;
}
+
cl->buf = ctx->out_buf;
cl->next = NULL;
*ctx->last_out = cl;
@@ -694,10 +699,12 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ctx->out_buf->flush = 0;
ctx->flush = Z_NO_FLUSH;
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
ngx_http_gzip_error(ctx);
return NGX_ERROR;
}
+
cl->buf = ctx->out_buf;
cl->next = NULL;
*ctx->last_out = cl;
@@ -722,10 +729,12 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ngx_pfree(r->pool, ctx->preallocated);
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
ngx_http_gzip_error(ctx);
return NGX_ERROR;
}
+
cl->buf = ctx->out_buf;
cl->next = NULL;
*ctx->last_out = cl;
@@ -737,17 +746,20 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ctx->out_buf->last_buf = 1;
} else {
- if (!(b = ngx_create_temp_buf(r->pool, 8))) {
+ b = ngx_create_temp_buf(r->pool, 8);
+ if (b == NULL) {
ngx_http_gzip_error(ctx);
return NGX_ERROR;
}
b->last_buf = 1;
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
ngx_http_gzip_error(ctx);
return NGX_ERROR;
}
+
cl->buf = b;
cl->next = NULL;
*ctx->last_out = cl;
@@ -782,10 +794,13 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
if (conf->no_buffer && ctx->in == NULL) {
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
+
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
ngx_http_gzip_error(ctx);
return NGX_ERROR;
}
+
cl->buf = ctx->out_buf;
cl->next = NULL;
*ctx->last_out = cl;
@@ -816,7 +831,7 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
ngx_chain_update_chains(&ctx->free, &ctx->busy, &ctx->out,
- (ngx_buf_tag_t) &ngx_http_gzip_filter_module);
+ (ngx_buf_tag_t) &ngx_http_gzip_filter_module);
ctx->last_out = &ctx->out;
if (ctx->done) {
@@ -969,7 +984,8 @@ ngx_http_gzip_create_conf(ngx_conf_t *cf)
{
ngx_http_gzip_conf_t *conf;
- if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_gzip_conf_t)))) {
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_gzip_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -1027,7 +1043,8 @@ ngx_http_gzip_merge_conf(ngx_conf_t *cf, void *parent, void *child)
return NGX_CONF_ERROR;
}
- if (!(type = ngx_array_push(conf->types))) {
+ type = ngx_array_push(conf->types);
+ if (type == NULL) {
return NGX_CONF_ERROR;
}
@@ -1055,12 +1072,13 @@ ngx_http_gzip_set_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (gcf->types == NULL) {
gcf->types = ngx_array_create(cf->pool, 4,
- sizeof(ngx_http_gzip_type_t));
+ sizeof(ngx_http_gzip_type_t));
if (gcf->types == NULL) {
return NGX_CONF_ERROR;
}
- if (!(type = ngx_array_push(gcf->types))) {
+ type = ngx_array_push(gcf->types);
+ if (type == NULL) {
return NGX_CONF_ERROR;
}
@@ -1077,13 +1095,15 @@ ngx_http_gzip_set_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
continue;
}
- if (!(type = ngx_array_push(gcf->types))) {
+ type = ngx_array_push(gcf->types);
+ if (type == NULL) {
return NGX_CONF_ERROR;
}
type->name.len = value[i].len;
- if (!(type->name.data = ngx_palloc(cf->pool, type->name.len + 1))) {
+ type->name.data = ngx_palloc(cf->pool, type->name.len + 1);
+ if (type->name.data == NULL) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/ngx_http_headers_filter.c b/src/http/modules/ngx_http_headers_filter_module.c
index 39b35837b..793cefd48 100644
--- a/src/http/modules/ngx_http_headers_filter.c
+++ b/src/http/modules/ngx_http_headers_filter_module.c
@@ -23,7 +23,8 @@ static ngx_int_t ngx_http_headers_filter_init(ngx_cycle_t *cycle);
static void *ngx_http_headers_create_conf(ngx_conf_t *cf);
static char *ngx_http_headers_merge_conf(ngx_conf_t *cf,
void *parent, void *child);
-char *ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
+static char *ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd,
+ void *conf);
static ngx_command_t ngx_http_headers_filter_commands[] = {
@@ -66,7 +67,8 @@ ngx_module_t ngx_http_headers_filter_module = {
static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
-static ngx_int_t ngx_http_headers_filter(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_headers_filter(ngx_http_request_t *r)
{
size_t len;
ngx_table_elt_t *expires, *cc;
@@ -80,13 +82,15 @@ static ngx_int_t ngx_http_headers_filter(ngx_http_request_t *r)
if (conf->expires != NGX_HTTP_EXPIRES_OFF) {
- if (!(expires = ngx_list_push(&r->headers_out.headers))) {
+ expires = ngx_list_push(&r->headers_out.headers);
+ if (expires == NULL) {
return NGX_ERROR;
}
r->headers_out.expires = expires;
- if (!(cc = ngx_list_push(&r->headers_out.headers))) {
+ cc = ngx_list_push(&r->headers_out.headers);
+ if (cc == NULL) {
return NGX_ERROR;
}
@@ -147,7 +151,8 @@ static ngx_int_t ngx_http_headers_filter(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_headers_filter_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_headers_filter_init(ngx_cycle_t *cycle)
{
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_headers_filter;
@@ -156,11 +161,13 @@ static ngx_int_t ngx_http_headers_filter_init(ngx_cycle_t *cycle)
}
-static void *ngx_http_headers_create_conf(ngx_conf_t *cf)
+static void *
+ngx_http_headers_create_conf(ngx_conf_t *cf)
{
ngx_http_headers_conf_t *conf;
- if (!(conf = ngx_palloc(cf->pool, sizeof(ngx_http_headers_conf_t)))) {
+ conf = ngx_palloc(cf->pool, sizeof(ngx_http_headers_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -170,8 +177,8 @@ static void *ngx_http_headers_create_conf(ngx_conf_t *cf)
}
-static char *ngx_http_headers_merge_conf(ngx_conf_t *cf,
- void *parent, void *child)
+static char *
+ngx_http_headers_merge_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_headers_conf_t *prev = parent;
ngx_http_headers_conf_t *conf = child;
@@ -185,7 +192,8 @@ static char *ngx_http_headers_merge_conf(ngx_conf_t *cf,
}
-char *ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+static char *
+ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_headers_conf_t *hcf = conf;
@@ -223,6 +231,7 @@ char *ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
hcf->expires = ngx_parse_time(&value[1], 1);
+
if (hcf->expires == NGX_ERROR) {
return "invalid value";
}
diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_module.c
index 4e3755766..373c31552 100644
--- a/src/http/modules/ngx_http_index_handler.c
+++ b/src/http/modules/ngx_http_index_module.c
@@ -93,10 +93,10 @@ ngx_module_t ngx_http_index_module = {
/*
* Try to open the first index file before the test of the directory existence
* because the valid requests should be many more than invalid ones.
- * If open() failed then stat() should be more quickly because some data
+ * If open() would fail, then stat() should be more quickly because some data
* is already cached in the kernel.
- * Besides Win32 has ERROR_PATH_NOT_FOUND (NGX_ENOTDIR).
- * Unix has ENOTDIR error, although it less helpfull - it shows only
+ * Besides, Win32 has ERROR_PATH_NOT_FOUND (NGX_ENOTDIR).
+ * Unix has ENOTDIR error, although it less helpfull - it points only
* that path contains the usual file in place of the directory.
*/
@@ -137,9 +137,13 @@ static ngx_int_t ngx_http_index_handler(ngx_http_request_t *r)
ctx = ngx_http_get_module_ctx(r, ngx_http_index_module);
if (ctx == NULL) {
- ngx_http_create_ctx(r, ctx, ngx_http_index_module,
- sizeof(ngx_http_index_ctx_t),
- NGX_HTTP_INTERNAL_SERVER_ERROR);
+
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_index_ctx_t));
+ if (ctx == NULL) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ ngx_http_set_ctx(r, ctx, ngx_http_index_module);
#if (NGX_HTTP_CACHE)
@@ -417,7 +421,7 @@ static ngx_int_t ngx_http_index_init(ngx_cycle_t *cycle)
cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
- h = ngx_push_array(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
+ h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
if (h == NULL) {
return NGX_ERROR;
}
@@ -432,11 +436,17 @@ static void *ngx_http_index_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_index_loc_conf_t *conf;
- ngx_test_null(conf, ngx_palloc(cf->pool, sizeof(ngx_http_index_loc_conf_t)),
- NGX_CONF_ERROR);
+ conf = ngx_palloc(cf->pool, sizeof(ngx_http_index_loc_conf_t));
+ if (conf == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ if (ngx_array_init(&conf->indices, cf->pool, 2, sizeof(ngx_str_t))
+ == NGX_ERROR)
+ {
+ return NGX_CONF_ERROR;
+ }
- ngx_init_array(conf->indices, cf->pool, 3, sizeof(ngx_str_t),
- NGX_CONF_ERROR);
conf->max_index_len = 0;
conf->index_cache = NULL;
@@ -461,7 +471,11 @@ static char *ngx_http_index_merge_loc_conf(ngx_conf_t *cf,
return NGX_CONF_OK;
}
- ngx_test_null(index, ngx_push_array(&conf->indices), NGX_CONF_ERROR);
+ index = ngx_array_push(&conf->indices);
+ if (index == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
index->len = sizeof(NGX_HTTP_DEFAULT_INDEX) - 1;
index->data = (u_char *) NGX_HTTP_DEFAULT_INDEX;
conf->max_index_len = sizeof(NGX_HTTP_DEFAULT_INDEX);
@@ -475,8 +489,11 @@ static char *ngx_http_index_merge_loc_conf(ngx_conf_t *cf,
prev_index = prev->indices.elts;
for (i = 0; i < prev->indices.nelts; i++) {
- ngx_test_null(index, ngx_push_array(&conf->indices),
- NGX_CONF_ERROR);
+ index = ngx_array_push(&conf->indices);
+ if (index == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
index->len = prev_index[i].len;
index->data = prev_index[i].data;
}
@@ -524,7 +541,11 @@ static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd,
return NGX_CONF_ERROR;
}
- ngx_test_null(index, ngx_push_array(&ilcf->indices), NGX_CONF_ERROR);
+ index = ngx_array_push(&ilcf->indices);
+ if (index == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
index->len = value[i].len;
index->data = value[i].data;
diff --git a/src/http/modules/ngx_http_not_modified_filter.c b/src/http/modules/ngx_http_not_modified_filter_module.c
index 24ea58d90..24ea58d90 100644
--- a/src/http/modules/ngx_http_not_modified_filter.c
+++ b/src/http/modules/ngx_http_not_modified_filter_module.c
diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter_module.c
index 03f274560..84381c930 100644
--- a/src/http/modules/ngx_http_range_filter.c
+++ b/src/http/modules/ngx_http_range_filter_module.c
@@ -186,7 +186,8 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
while (*p == ' ') { p++; }
if (*p == ',' || *p == '\0') {
- if (!(range = ngx_array_push(&r->headers_out.ranges))) {
+ range = ngx_array_push(&r->headers_out.ranges);
+ if (range == NULL) {
return NGX_ERROR;
}
@@ -231,7 +232,8 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
break;
}
- if (!(range = ngx_array_push(&r->headers_out.ranges))) {
+ range = ngx_array_push(&r->headers_out.ranges);
+ if (range == NULL) {
return NGX_ERROR;
}
@@ -260,7 +262,8 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
r->headers_out.status = rc;
r->headers_out.ranges.nelts = 0;
- if (!(content_range = ngx_list_push(&r->headers_out.headers))) {
+ content_range = ngx_list_push(&r->headers_out.headers);
+ if (content_range == NULL) {
return NGX_ERROR;
}
@@ -269,9 +272,8 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
content_range->key.len = sizeof("Content-Range") - 1;
content_range->key.data = (u_char *) "Content-Range";
- content_range->value.data =
- ngx_palloc(r->pool, sizeof("bytes */") - 1 + NGX_OFF_T_LEN);
-
+ content_range->value.data = ngx_palloc(r->pool,
+ sizeof("bytes */") - 1 + NGX_OFF_T_LEN);
if (content_range->value.data == NULL) {
return NGX_ERROR;
}
@@ -294,7 +296,8 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
if (r->headers_out.ranges.nelts == 1) {
- if (!(content_range = ngx_list_push(&r->headers_out.headers))) {
+ content_range = ngx_list_push(&r->headers_out.headers);
+ if (content_range == NULL) {
return NGX_ERROR;
}
@@ -325,8 +328,12 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
/* TODO: what if no content_type ?? */
- ngx_http_create_ctx(r, ctx, ngx_http_range_body_filter_module,
- sizeof(ngx_http_range_filter_ctx_t), NGX_ERROR);
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_range_filter_ctx_t));
+ if (ctx == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_http_set_ctx(r, ctx, ngx_http_range_body_filter_module);
len = sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN
@@ -338,7 +345,8 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
len += sizeof("; charset=") - 1 + r->headers_out.charset.len;
}
- if (!(ctx->boundary_header.data = ngx_palloc(r->pool, len))) {
+ ctx->boundary_header.data = ngx_palloc(r->pool, len);
+ if (ctx->boundary_header.data == NULL) {
return NGX_ERROR;
}
@@ -466,7 +474,8 @@ ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
* "Content-Range: bytes "
*/
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -474,7 +483,8 @@ ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
b->pos = ctx->boundary_header.data;
b->last = ctx->boundary_header.data + ctx->boundary_header.len;
- if (!(hcl = ngx_alloc_chain_link(r->pool))) {
+ hcl = ngx_alloc_chain_link(r->pool);
+ if (hcl == NULL) {
return NGX_ERROR;
}
@@ -483,7 +493,8 @@ ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
/* "SSSS-EEEE/TTTT" CRLF CRLF */
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -491,7 +502,8 @@ ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
b->pos = range[i].content_range.data;
b->last = range[i].content_range.data + range[i].content_range.len;
- if (!(rcl = ngx_alloc_chain_link(r->pool))) {
+ rcl = ngx_alloc_chain_link(r->pool);
+ if (rcl == NULL) {
return NGX_ERROR;
}
@@ -500,7 +512,8 @@ ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
/* the range data */
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -509,7 +522,8 @@ ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
b->file_last = range[i].end;
b->file = in->buf->file;
- if (!(dcl = ngx_alloc_chain_link(r->pool))) {
+ dcl = ngx_alloc_chain_link(r->pool);
+ if (dcl == NULL) {
return NGX_ERROR;
}
@@ -523,7 +537,8 @@ ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
/* the last boundary CRLF "--0123456789--" CRLF */
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -540,7 +555,8 @@ ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
*b->last++ = '-'; *b->last++ = '-';
*b->last++ = CR; *b->last++ = LF;
- if (!(hcl = ngx_alloc_chain_link(r->pool))) {
+ hcl = ngx_alloc_chain_link(r->pool);
+ if (hcl == NULL) {
return NGX_ERROR;
}
diff --git a/src/http/modules/ngx_http_rewrite_handler.c b/src/http/modules/ngx_http_rewrite_module.c
index 3080bd6f4..d0313a01f 100644
--- a/src/http/modules/ngx_http_rewrite_handler.c
+++ b/src/http/modules/ngx_http_rewrite_module.c
@@ -21,6 +21,12 @@ typedef struct {
typedef struct {
+ ngx_str_t *name;
+ ngx_http_variable_value_t *value;
+} ngx_http_rewrite_variable_t;
+
+
+typedef struct {
ngx_array_t *codes; /* uintptr_t */
ngx_array_t *referers; /* ngx_http_rewrite_referer_t */
@@ -41,6 +47,7 @@ typedef struct {
uintptr_t status;
uintptr_t next;
+ uintptr_t test:1;
uintptr_t uri:1;
/* add the r->args to the new arguments */
@@ -92,13 +99,21 @@ typedef struct {
typedef struct {
ngx_http_rewrite_code_pt code;
+ uintptr_t value;
+ uintptr_t text_len;
+ uintptr_t text_data;
+} ngx_http_rewrite_value_code_t;
+
+
+typedef struct {
+ ngx_http_rewrite_code_pt code;
uintptr_t index;
} ngx_http_rewrite_var_code_t;
struct ngx_http_rewrite_engine_s {
u_char *ip;
- uintptr_t *sp;
+ ngx_http_variable_value_t *sp;
ngx_str_t buf;
ngx_str_t *line;
@@ -128,8 +143,14 @@ static char *ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static char *ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
+static char * ngx_http_rewrite_if_condition(ngx_conf_t *cf,
+ ngx_http_rewrite_loc_conf_t *lcf);
+static char *ngx_http_rewrite_variable(ngx_conf_t *cf,
+ ngx_http_rewrite_loc_conf_t *lcf, ngx_str_t *value);
static char *ngx_http_rewrite_valid_referers(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);
+static char * ngx_http_rewrite_set(ngx_conf_t *cf, ngx_command_t *cmd,
+ void *conf);
static void *ngx_http_rewrite_start_code(ngx_pool_t *pool,
ngx_array_t **codes, size_t size);
static void *ngx_http_rewrite_add_code(ngx_array_t *codes, size_t size,
@@ -168,6 +189,14 @@ static ngx_command_t ngx_http_rewrite_commands[] = {
0,
NULL },
+ { ngx_string("set"),
+ NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
+ |NGX_CONF_TAKE2,
+ ngx_http_rewrite_set,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ 0,
+ NULL },
+
{ ngx_string("rewrite_log"),
NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|NGX_CONF_TAKE1,
@@ -208,6 +237,9 @@ ngx_module_t ngx_http_rewrite_module = {
uintptr_t ngx_http_rewrite_exit_code = (uintptr_t) NULL;
+static ngx_http_variable_value_t ngx_http_rewrite_null_value =
+ { 0, ngx_string("") };
+
static ngx_int_t
ngx_http_rewrite_handler(ngx_http_request_t *r)
@@ -222,11 +254,13 @@ ngx_http_rewrite_handler(ngx_http_request_t *r)
return NGX_DECLINED;
}
- if (!(e = ngx_palloc(r->pool, sizeof(ngx_http_rewrite_engine_t)))) {
+ e = ngx_palloc(r->pool, sizeof(ngx_http_rewrite_engine_t));
+ if (e == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
- e->sp = ngx_palloc(r->pool, cf->stack_size * sizeof(ngx_int_t));
+ e->sp = ngx_palloc(r->pool,
+ cf->stack_size * sizeof(ngx_http_variable_value_t));
if (e->sp == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -274,12 +308,13 @@ ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e)
r = e->request;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http rewrite start: \"%V\"", &code->name);
+ "http rewrite regex: \"%V\"", &code->name);
if (code->uri) {
e->line = &r->uri;
} else {
- e->line = *(ngx_str_t **) e->sp--;
+ e->sp--;
+ e->line = &e->sp->text;
}
rc = ngx_regex_exec(code->regex, e->line, e->captures, code->ncaptures);
@@ -290,6 +325,16 @@ ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e)
"\"%V\" does not match \"%V\"", &code->name, e->line);
}
+ if (code->test) {
+ e->sp->value = 0;
+ e->sp->text.len = 0;
+ e->sp->text.data = (u_char *) "";
+ e->sp++;
+
+ e->ip += sizeof(ngx_http_rewrite_regex_code_t);
+ return;
+ }
+
e->ip += code->next;
return;
}
@@ -309,6 +354,16 @@ ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e)
"\"%V\" matches \"%V\"", &code->name, e->line);
}
+ if (code->test) {
+ e->sp->value = 1;
+ e->sp->text.len = 1;
+ e->sp->text.data = (u_char *) "1";
+ e->sp++;
+
+ e->ip += sizeof(ngx_http_rewrite_regex_code_t);
+ return;
+ }
+
if (code->status) {
e->status = code->status;
@@ -339,7 +394,8 @@ ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e)
e->buf.len += r->args.len + 1;
}
- if (!(e->buf.data = ngx_palloc(r->pool, e->buf.len))) {
+ e->buf.data = ngx_palloc(r->pool, e->buf.len);
+ if (e->buf.data == NULL) {
e->ip = ngx_http_rewrite_exit;
e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
return;
@@ -366,7 +422,7 @@ ngx_http_rewrite_regex_end_code(ngx_http_rewrite_engine_t *e)
e->quote = 0;
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http rewrite end");
+ "http rewrite regex end");
if (e->args) {
e->buf.len = e->args - e->buf.data;
@@ -414,7 +470,8 @@ ngx_http_rewrite_regex_end_code(ngx_http_rewrite_engine_t *e)
ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
"rewritten redirect: \"%V\"", &e->buf);
- if (!(r->headers_out.location = ngx_list_push(&r->headers_out.headers))) {
+ r->headers_out.location = ngx_list_push(&r->headers_out.headers);
+ if (r->headers_out.location == NULL) {
e->ip = ngx_http_rewrite_exit;
e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
return;
@@ -468,7 +525,7 @@ ngx_http_rewrite_copy_code(ngx_http_rewrite_engine_t *e)
code->len);
e->ip += sizeof(ngx_http_rewrite_copy_code_t)
- + ((code->len + sizeof(uintptr_t) - 1) & ~(sizeof(uintptr_t) - 1));
+ + ((code->len + sizeof(uintptr_t) - 1) & ~(sizeof(uintptr_t) - 1));
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
"http rewrite copy: \"%V\"", &e->buf);
@@ -509,7 +566,9 @@ ngx_http_rewrite_if_code(ngx_http_rewrite_engine_t *e)
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
"http rewrite if");
- if (*e->sp--) {
+ e->sp--;
+
+ if (e->sp->value) {
if (code->loc_conf) {
e->request->loc_conf = code->loc_conf;
}
@@ -526,6 +585,69 @@ ngx_http_rewrite_if_code(ngx_http_rewrite_engine_t *e)
static void
+ngx_http_rewrite_value_code(ngx_http_rewrite_engine_t *e)
+{
+ ngx_http_rewrite_value_code_t *code;
+
+ code = (ngx_http_rewrite_value_code_t *) e->ip;
+
+ e->ip += sizeof(ngx_http_rewrite_value_code_t);
+
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
+ "http rewrite value");
+
+ e->sp->value = (ngx_uint_t) code->value;
+ e->sp->text.len = (size_t) code->text_len;
+ e->sp->text.data = (u_char *) code->text_data;
+ e->sp++;
+}
+
+
+static void
+ngx_http_rewrite_set_var_code(ngx_http_rewrite_engine_t *e)
+{
+ ngx_http_request_t *r;
+ ngx_http_variable_value_t *value;
+ ngx_http_core_main_conf_t *cmcf;
+ ngx_http_rewrite_var_code_t *code;
+
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
+ "http rewrite set var");
+
+ code = (ngx_http_rewrite_var_code_t *) e->ip;
+
+ e->ip += sizeof(ngx_http_rewrite_var_code_t);
+
+ r = e->request;
+
+ if (r->variables == NULL) {
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
+
+ r->variables = ngx_pcalloc(r->pool, cmcf->variables.nelts
+ * sizeof(ngx_http_variable_value_t *));
+ if (r->variables == NULL) {
+ e->ip = ngx_http_rewrite_exit;
+ e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
+ return;
+ }
+ }
+
+ value = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
+ if (value == NULL) {
+ e->ip = ngx_http_rewrite_exit;
+ e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
+ return;
+ }
+
+ e->sp--;
+
+ *value = *e->sp;
+
+ r->variables[code->index] = value;
+}
+
+
+static void
ngx_http_rewrite_var_code(ngx_http_rewrite_engine_t *e)
{
ngx_http_variable_value_t *value;
@@ -536,19 +658,24 @@ ngx_http_rewrite_var_code(ngx_http_rewrite_engine_t *e)
code = (ngx_http_rewrite_var_code_t *) e->ip;
- e->sp++;
-
e->ip += sizeof(ngx_http_rewrite_var_code_t);
- if (!(value = ngx_http_get_indexed_variable(e->request, code->index))) {
- *e->sp = (uintptr_t) 0;
+ value = ngx_http_get_indexed_variable(e->request, code->index);
+
+ if (value == NULL || value == NGX_HTTP_VARIABLE_NOT_FOUND) {
+ e->sp->value = 0;
+ e->sp->text.len = 0;
+ e->sp->text.data = (u_char *) "";
+ e->sp++;
+
return;
}
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
- "http rewrite var: %p", value->value);
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
+ "http rewrite var: %ui, \"%V\"", value->value, &value->text);
- *e->sp = value->value;
+ *e->sp = *value;
+ e->sp++;
}
@@ -569,20 +696,31 @@ ngx_http_rewrite_invalid_referer_code(ngx_http_rewrite_engine_t *e)
cf = ngx_http_get_module_loc_conf(r, ngx_http_rewrite_module);
- e->sp++;
e->ip += sizeof(uintptr_t);
if (cf->referers == NULL) {
- *e->sp = (uintptr_t) 0;
+ e->sp->value = 0;
+ e->sp->text.len = 0;
+ e->sp->text.data = (u_char *) "";
+ e->sp++;
+
return;
}
if (r->headers_in.referer == NULL) {
if (cf->no_referer) {
- *e->sp = (uintptr_t) 0;
+ e->sp->value = 0;
+ e->sp->text.len = 0;
+ e->sp->text.data = (u_char *) "";
+ e->sp++;
+
return;
} else {
- *e->sp = (uintptr_t) 1;
+ e->sp->value = 1;
+ e->sp->text.len = 1;
+ e->sp->text.data = (u_char *) "1";
+ e->sp++;
+
return;
}
}
@@ -593,7 +731,11 @@ ngx_http_rewrite_invalid_referer_code(ngx_http_rewrite_engine_t *e)
if (len < sizeof("http://i.ru") - 1
|| (ngx_strncasecmp(ref, "http://", 7) != 0))
{
- *e->sp = (uintptr_t) 1;
+ e->sp->value = 1;
+ e->sp->text.len = 1;
+ e->sp->text.data = (u_char *) "1";
+ e->sp++;
+
return;
}
@@ -620,7 +762,11 @@ ngx_http_rewrite_invalid_referer_code(ngx_http_rewrite_engine_t *e)
if (ngx_strncmp(&ref[n], refs[i].name.data,
refs[i].name.len) == 0)
{
- *e->sp = (uintptr_t) 0;
+ e->sp->value = 0;
+ e->sp->text.len = 0;
+ e->sp->text.data = (u_char *) "";
+ e->sp++;
+
return;
}
}
@@ -628,13 +774,20 @@ ngx_http_rewrite_invalid_referer_code(ngx_http_rewrite_engine_t *e)
} else {
if (ngx_strncasecmp(refs[i].name.data, ref, refs[i].name.len) == 0)
{
- *e->sp = (uintptr_t) 0;
+ e->sp->value = 0;
+ e->sp->text.len = 0;
+ e->sp->text.data = (u_char *) "";
+ e->sp++;
+
return;
}
}
}
- *e->sp = (uintptr_t) 1;
+ e->sp->value = 1;
+ e->sp->text.len = 1;
+ e->sp->text.data = (u_char *) "1";
+ e->sp++;
}
@@ -645,6 +798,29 @@ ngx_http_rewrite_nop_code(ngx_http_rewrite_engine_t *e)
}
+static ngx_http_variable_value_t *
+ngx_http_rewrite_var(ngx_http_request_t *r, uintptr_t data)
+{
+ ngx_http_variable_t *var;
+ ngx_http_core_main_conf_t *cmcf;
+
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
+
+ var = cmcf->variables.elts;
+
+ /*
+ * the ngx_http_rewrite_module sets variables directly in r->variables,
+ * and they should be handle by ngx_http_get_indexed_variable(),
+ * so the handler is called only if the variable is not initialized
+ */
+
+ ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
+ "using uninitialized \"%V\" variable", &var[data].name);
+
+ return &ngx_http_rewrite_null_value;
+}
+
+
static ngx_int_t
ngx_http_rewrite_init(ngx_cycle_t *cycle)
{
@@ -653,7 +829,7 @@ ngx_http_rewrite_init(ngx_cycle_t *cycle)
cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
- h = ngx_push_array(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers);
+ h = ngx_array_push(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers);
if (h == NULL) {
return NGX_ERROR;
}
@@ -669,7 +845,8 @@ ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_rewrite_loc_conf_t *conf;
- if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_rewrite_loc_conf_t)))) {
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_rewrite_loc_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -724,30 +901,53 @@ ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
conf->max_captures = regex->ncaptures;
}
code = (uintptr_t *) ((u_char *) code + regex->next);
+ continue;
}
if (*code == (uintptr_t) &ngx_http_rewrite_if_code) {
code += sizeof(ngx_http_rewrite_if_code_t) / sizeof(uintptr_t);
+ continue;
}
if (*code == (uintptr_t) &ngx_http_rewrite_return_code) {
code += sizeof(ngx_http_rewrite_return_code_t) / sizeof(uintptr_t);
+ continue;
+ }
+
+ if (*code == (uintptr_t) &ngx_http_rewrite_set_var_code) {
+ code += sizeof(ngx_http_rewrite_var_code_t) / sizeof(uintptr_t);
+ continue;
}
if (*code == (uintptr_t) &ngx_http_rewrite_var_code) {
code += sizeof(ngx_http_rewrite_var_code_t) / sizeof(uintptr_t);
+ continue;
+ }
+
+ if (*code == (uintptr_t) &ngx_http_rewrite_value_code) {
+ code += sizeof(ngx_http_rewrite_value_code_t) / sizeof(uintptr_t);
+ continue;
}
if (*code == (uintptr_t) &ngx_http_rewrite_invalid_referer_code) {
code++;
+ continue;
}
if (*code == (uintptr_t) &ngx_http_rewrite_nop_code) {
code++;
+ continue;
}
+
+#if (NGX_DEBUG)
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "unknown rewrite code: %p", *code);
+ return NGX_CONF_ERROR;
+#endif
}
- if (!(code = ngx_array_push_n(conf->codes, sizeof(uintptr_t)))) {
+ code = ngx_array_push_n(conf->codes, sizeof(uintptr_t));
+ if (code == NULL) {
return NGX_CONF_ERROR;
}
@@ -765,7 +965,8 @@ ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
u_char *data;
size_t len, size;
ngx_str_t *value, err;
- ngx_uint_t i, n, last;
+ ngx_int_t n;
+ ngx_uint_t i, last;
ngx_http_rewrite_code_pt *code;
ngx_http_rewrite_copy_code_t *copy;
ngx_http_rewrite_regex_code_t *regex;
@@ -797,6 +998,7 @@ ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
regex->size = 0;
regex->ncaptures = 0;
regex->status = 0;
+ regex->test = 0;
regex->uri = 1;
regex->args = 1;
regex->redirect = 0;
@@ -946,7 +1148,14 @@ ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
n = ngx_regex_capture_count(regex->regex);
- if (regex->ncaptures > n) {
+ if (n < 0) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ ngx_regex_capture_count_n " failed for "
+ "pattern \"%V\"", &value[1]);
+ return NGX_CONF_ERROR;
+ }
+
+ if (regex->ncaptures > (ngx_uint_t) n) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"pattern \"%V\" has less captures "
"than referrenced in substitution \"%V\"",
@@ -954,8 +1163,8 @@ ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}
- if (regex->ncaptures < n) {
- regex->ncaptures = n;
+ if (regex->ncaptures < (ngx_uint_t) n) {
+ regex->ncaptures = (ngx_uint_t) n;
}
if (regex->ncaptures) {
@@ -1028,20 +1237,16 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
void *mconf;
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_core_loc_conf_t *clcf, *pclcf, **clcfp;
- ngx_http_core_main_conf_t *cmcf;
ngx_http_rewrite_if_code_t *if_code;
- ngx_http_rewrite_var_code_t *var_code;
ngx_http_rewrite_loc_conf_t *nlcf;
- if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) {
+ ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
+ if (ctx == NULL) {
return NGX_CONF_ERROR;
}
@@ -1063,7 +1268,8 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (module->create_loc_conf) {
- if (!(mconf = module->create_loc_conf(cf))) {
+ mconf = module->create_loc_conf(cf);
+ if (mconf == NULL) {
return NGX_CONF_ERROR;
}
@@ -1086,63 +1292,18 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
}
- if (!(clcfp = ngx_push_array(&pclcf->locations))) {
+ clcfp = ngx_array_push(&pclcf->locations);
+ if (clcfp == NULL) {
return NGX_CONF_ERROR;
}
*clcfp = clcf;
- /* STUB: "if ($var)" */
-
- value = cf->args->elts;
-
- if (value[1].len < 2
- || value[1].data[0] != '('
- || value[1].data[1] != '$'
- || value[1].data[value[1].len - 1] != ')')
- {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid condition \"%V\"", &value[1]);
+ if (ngx_http_rewrite_if_condition(cf, lcf) != NGX_CONF_OK) {
return NGX_CONF_ERROR;
}
- value[1].len -= 3;
- value[1].data += 2;
-
- if (value[1].len == sizeof("invalid_referer") - 1
- && ngx_strncmp(value[1].data, "invalid_referer",
- sizeof("invalid_referer") - 1) == 0)
- {
- code = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
- sizeof(ngx_http_rewrite_code_pt));
- if (code == NULL) {
- return NGX_CONF_ERROR;
- }
-
- *code = ngx_http_rewrite_invalid_referer_code;
-
- } else {
- cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
-
- index = ngx_http_get_variable_index(cmcf, &value[1]);
-
- if (index == -1) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "unknown variable name \"%V\"", &value[1]);
- return NGX_CONF_ERROR;
- }
-
- var_code = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
- sizeof(ngx_http_rewrite_var_code_t));
- if (var_code == NULL) {
- return NGX_CONF_ERROR;
- }
-
- var_code->code = ngx_http_rewrite_var_code;
- var_code->index = index;
- }
-
if_code = ngx_array_push_n(lcf->codes, sizeof(ngx_http_rewrite_if_code_t));
if (if_code == NULL) {
return NULL;
@@ -1193,6 +1354,156 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
static char *
+ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
+{
+ ngx_str_t *value, err;
+ ngx_uint_t cur, last;
+ ngx_http_rewrite_regex_code_t *regex;
+ u_char errstr[NGX_MAX_CONF_ERRSTR];
+
+ value = cf->args->elts;
+ last = cf->args->nelts - 1;
+
+ if (value[1].len < 1 || value[1].data[0] != '(') {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid condition \"%V\"", &value[1]);
+ return NGX_CONF_ERROR;
+ }
+
+ if (value[1].len == 1) {
+ cur = 2;
+
+ } else {
+ cur = 1;
+ value[1].len--;
+ value[1].data++;
+ }
+
+ if (value[last].len < 1 || value[last].data[value[last].len - 1] != ')') {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid condition \"%V\"", &value[last]);
+ return NGX_CONF_ERROR;
+ }
+
+ if (value[last].len == 1) {
+ last--;
+
+ } else {
+ value[last].len--;
+ value[last].data[value[last].len] = '\0';
+ }
+
+ if (value[cur].len > 1 && value[cur].data[0] == '$') {
+
+ if (cur != last && cur + 2 != last) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid condition \"%V\"", &value[cur]);
+ return NGX_CONF_ERROR;
+ }
+
+ if (ngx_http_rewrite_variable(cf, lcf, &value[cur])!= NGX_CONF_OK) {
+ return NGX_CONF_ERROR;
+ }
+
+ if (cur == last) {
+ return NGX_CONF_OK;
+ }
+
+ cur++;
+
+ if ((value[cur].len == 1 && value[cur].data[0] != '~')
+ || (value[cur].len == 2
+ && value[cur].data[0] != '~' && value[cur].data[1] != '*'))
+ {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "unexpected \"%V\" in condition", &value[cur]);
+ return NGX_CONF_ERROR;
+ }
+
+ regex = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
+ sizeof(ngx_http_rewrite_regex_code_t));
+ if (regex == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ err.len = NGX_MAX_CONF_ERRSTR;
+ err.data = errstr;
+
+ regex->regex = ngx_regex_compile(&value[last],
+ (value[cur].len == 2) ? NGX_REGEX_CASELESS : 0,
+ cf->pool, &err);
+
+ if (regex->regex == NULL) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
+ return NGX_CONF_ERROR;
+ }
+
+ regex->code = ngx_http_rewrite_regex_start_code;
+ regex->size = 0;
+ regex->ncaptures = 0;
+ regex->status = 0;
+ regex->next = sizeof(ngx_http_rewrite_regex_code_t);
+ regex->test = 1;
+ regex->uri = 0;
+ regex->args = 0;
+ regex->redirect = 0;
+ regex->name = value[last];
+
+ return NGX_CONF_OK;
+ }
+
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid condition \"%V\"", &value[cur]);
+
+ return NGX_CONF_ERROR;
+}
+
+
+static char *
+ngx_http_rewrite_variable(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf,
+ ngx_str_t *value)
+{
+ ngx_http_variable_t *var;
+ ngx_http_rewrite_code_pt *code;
+ ngx_http_rewrite_var_code_t *var_code;
+
+ value->len--;
+ value->data++;
+
+ if (value->len == sizeof("invalid_referer") - 1
+ && ngx_strncmp(value->data, "invalid_referer",
+ sizeof("invalid_referer") - 1) == 0)
+ {
+ code = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
+ sizeof(ngx_http_rewrite_code_pt));
+ if (code == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ *code = ngx_http_rewrite_invalid_referer_code;
+
+ } else {
+ var = ngx_http_add_variable(cf, value, 0);
+
+ if (var == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ var_code = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
+ sizeof(ngx_http_rewrite_var_code_t));
+ if (var_code == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ var_code->code = ngx_http_rewrite_var_code;
+ var_code->index = var->index;
+ }
+
+ return NGX_CONF_OK;
+}
+
+
+static char *
ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_rewrite_loc_conf_t *lcf = conf;
@@ -1234,7 +1545,8 @@ ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
continue;
}
- if (!(ref = ngx_array_push(lcf->referers))) {
+ ref = ngx_array_push(lcf->referers);
+ if (ref == NULL) {
return NGX_CONF_ERROR;
}
@@ -1261,12 +1573,14 @@ ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
sn = cscf->server_names.elts;
for (i = 0; i < cscf->server_names.nelts; i++) {
- if (!(ref = ngx_array_push(lcf->referers))) {
+ ref = ngx_array_push(lcf->referers);
+ if (ref == NULL) {
return NGX_CONF_ERROR;
}
ref->name.len = sn[i].name.len + 1;
- if (!(ref->name.data = ngx_palloc(cf->pool, ref->name.len))) {
+ ref->name.data = ngx_palloc(cf->pool, ref->name.len);
+ if (ref->name.data == NULL) {
return NGX_CONF_ERROR;
}
@@ -1279,11 +1593,72 @@ ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
+static char *
+ngx_http_rewrite_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+ ngx_http_rewrite_loc_conf_t *lcf = conf;
+
+ ngx_int_t n;
+ ngx_str_t *value;
+ ngx_http_variable_t *v;
+ ngx_http_rewrite_var_code_t *var;
+ ngx_http_rewrite_value_code_t *val;
+
+ value = cf->args->elts;
+
+ if (value[1].data[0] != '$') {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid variable name \"%V\"", &value[1]);
+ return NGX_CONF_ERROR;
+ }
+
+ value[1].len--;
+ value[1].data++;
+
+ v = ngx_http_add_variable(cf, &value[1], 1);
+ if (v == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ v->handler = ngx_http_rewrite_var;
+ v->data = v->index;
+
+ val = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
+ sizeof(ngx_http_rewrite_value_code_t));
+ if (val == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ n = ngx_atoi(value[2].data, value[2].len);
+
+ if (n == NGX_ERROR) {
+ n = 0;
+ }
+
+ val->code = ngx_http_rewrite_value_code;
+ val->value = (uintptr_t) n;
+ val->text_len = (uintptr_t) value[2].len;
+ val->text_data = (uintptr_t) value[2].data;
+
+ var = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
+ sizeof(ngx_http_rewrite_var_code_t));
+ if (var == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ var->code = ngx_http_rewrite_set_var_code;
+ var->index = (uintptr_t) v->index;
+
+ return NGX_CONF_OK;
+}
+
+
static void *
ngx_http_rewrite_start_code(ngx_pool_t *pool, ngx_array_t **codes, size_t size)
{
if (*codes == NULL) {
- if (!(*codes = ngx_array_create(pool, 256, 1))) {
+ *codes = ngx_array_create(pool, 256, 1);
+ if (*codes == NULL) {
return NULL;
}
}
@@ -1300,7 +1675,8 @@ ngx_http_rewrite_add_code(ngx_array_t *codes, size_t size, void *code)
elts = codes->elts;
- if (!(new = ngx_array_push_n(codes, size))) {
+ new = ngx_array_push_n(codes, size);
+ if (new == NULL) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/ngx_http_ssi_filter.c b/src/http/modules/ngx_http_ssi_filter_module.c
index ca877ac94..a351747b5 100644
--- a/src/http/modules/ngx_http_ssi_filter.c
+++ b/src/http/modules/ngx_http_ssi_filter_module.c
@@ -98,8 +98,6 @@ typedef enum {
} ngx_http_ssi_state_e;
-static ngx_int_t ngx_http_ssi_error(ngx_http_request_t *r,
- ngx_http_ssi_ctx_t *ctx);
static ngx_int_t ngx_http_ssi_parse(ngx_http_request_t *r,
ngx_http_ssi_ctx_t *ctx);
@@ -1147,21 +1145,25 @@ static ngx_int_t
ngx_http_ssi_echo(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
ngx_str_t **params)
{
+ ngx_uint_t i;
ngx_buf_t *b;
ngx_str_t *var, *value;
ngx_chain_t *cl;
- ngx_http_variable_value_t *v;
+ ngx_http_variable_value_t *vv;
var = params[NGX_HTTP_SSI_ECHO_VAR];
- value = NULL;
- v = ngx_http_get_variable(r, var);
+ for (i = 0; i < var->len; i++) {
+ var->data[i] = ngx_toupper(var->data[i]);
+ }
+
+ vv = ngx_http_get_variable(r, var);
- if (v == NULL) {
+ if (vv == NULL) {
return NGX_HTTP_SSI_ERROR;
}
- if (v == NGX_HTTP_VARIABLE_NOT_FOUND) {
+ if (vv == NGX_HTTP_VARIABLE_NOT_FOUND) {
value = params[NGX_HTTP_SSI_ECHO_DEFAULT];
if (value == NULL) {
@@ -1172,7 +1174,7 @@ ngx_http_ssi_echo(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
}
} else {
- value = &v->text;
+ value = &vv->text;
if (value->len == 0) {
return NGX_OK;
diff --git a/src/http/modules/ngx_http_ssl_module.c b/src/http/modules/ngx_http_ssl_module.c
index 883e44fbc..1c4128ca1 100644
--- a/src/http/modules/ngx_http_ssl_module.c
+++ b/src/http/modules/ngx_http_ssl_module.c
@@ -19,7 +19,7 @@ static void *ngx_http_ssl_create_main_conf(ngx_conf_t *cf);
static char *ngx_http_ssl_init_main_conf(ngx_conf_t *cf, void *conf);
static void *ngx_http_ssl_create_srv_conf(ngx_conf_t *cf);
static char *ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf,
- void *parent, void *child);
+ void *parent, void *child);
static ngx_command_t ngx_http_ssl_commands[] = {
@@ -87,11 +87,13 @@ ngx_module_t ngx_http_ssl_module = {
};
-static void *ngx_http_ssl_create_main_conf(ngx_conf_t *cf)
+static void *
+ngx_http_ssl_create_main_conf(ngx_conf_t *cf)
{
ngx_http_ssl_main_conf_t *mcf;
- if (!(mcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssl_main_conf_t)))) {
+ mcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssl_main_conf_t));
+ if (mcf == NULL) {
return NGX_CONF_ERROR;
}
@@ -106,7 +108,8 @@ static void *ngx_http_ssl_create_main_conf(ngx_conf_t *cf)
}
-static char *ngx_http_ssl_init_main_conf(ngx_conf_t *cf, void *conf)
+static char *
+ngx_http_ssl_init_main_conf(ngx_conf_t *cf, void *conf)
{
ngx_http_ssl_main_conf_t *mcf = conf;
@@ -137,11 +140,13 @@ static char *ngx_http_ssl_init_main_conf(ngx_conf_t *cf, void *conf)
}
-static void *ngx_http_ssl_create_srv_conf(ngx_conf_t *cf)
+static void *
+ngx_http_ssl_create_srv_conf(ngx_conf_t *cf)
{
ngx_http_ssl_srv_conf_t *scf;
- if (!(scf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssl_srv_conf_t)))) {
+ scf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssl_srv_conf_t));
+ if (scf == NULL) {
return NGX_CONF_ERROR;
}
@@ -162,8 +167,8 @@ static void *ngx_http_ssl_create_srv_conf(ngx_conf_t *cf)
}
-static char *ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf,
- void *parent, void *child)
+static char *
+ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_ssl_srv_conf_t *prev = parent;
ngx_http_ssl_srv_conf_t *conf = child;
@@ -226,7 +231,8 @@ static char *ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf,
#if 0
-static ngx_int_t ngx_http_ssl_init_process(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_ssl_init_process(ngx_cycle_t *cycle)
{
ngx_uint_t i;
ngx_http_ssl_srv_conf_t *sscf;
diff --git a/src/http/modules/ngx_http_ssl_module.h b/src/http/modules/ngx_http_ssl_module.h
index 87166877f..bf6036634 100644
--- a/src/http/modules/ngx_http_ssl_module.h
+++ b/src/http/modules/ngx_http_ssl_module.h
@@ -32,7 +32,7 @@ typedef struct {
ngx_int_t ngx_http_ssl_read(ngx_http_request_t *r, u_char *buf, size_t size);
ngx_int_t ngx_http_ssl_shutdown(ngx_http_request_t *r);
ngx_chain_t *ngx_http_ssl_write(ngx_connection_t *c, ngx_chain_t *in,
- off_t limit);
+ off_t limit);
void ngx_http_ssl_close_connection(SSL *ssl, ngx_log_t *log);
diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_module.c
index 4f0f96dc0..c2c45828f 100644
--- a/src/http/modules/ngx_http_static_handler.c
+++ b/src/http/modules/ngx_http_static_module.c
@@ -75,10 +75,13 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
ngx_buf_t *b;
ngx_chain_t out;
ngx_file_info_t fi;
- ngx_http_cleanup_t *file_cleanup, *redirect_cleanup;
+ ngx_http_cleanup_t *file_cleanup;
+#if (NGX_HTTP_CACHE)
+ ngx_http_cleanup_t *redirect_cleanup;
+#endif
ngx_http_core_loc_conf_t *clcf;
- ngx_http_static_loc_conf_t *slcf;
#if (NGX_HTTP_CACHE)
+ ngx_http_static_loc_conf_t *slcf;
uint32_t file_crc, redirect_crc;
ngx_http_cache_t *file, *redirect;
#endif
@@ -176,14 +179,18 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
/* allocate cleanups */
- if (!(file_cleanup = ngx_push_array(&r->cleanup))) {
+ file_cleanup = ngx_array_push(&r->cleanup);
+ if (file_cleanup == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
file_cleanup->valid = 0;
+#if (NGX_HTTP_CACHE)
+
slcf = ngx_http_get_module_loc_conf(r, ngx_http_static_module);
if (slcf->redirect_cache) {
- if (!(redirect_cleanup = ngx_push_array(&r->cleanup))) {
+ redirect_cleanup = ngx_array_push(&r->cleanup);
+ if (redirect_cleanup == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
redirect_cleanup->valid = 0;
@@ -192,8 +199,6 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
redirect_cleanup = NULL;
}
-#if (NGX_HTTP_CACHE)
-
/* look up an open files cache */
if (clcf->open_files) {
@@ -232,9 +237,9 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
* should keep more popular redirects in cache.
*/
- if (!(r->headers_out.location =
- ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
- {
+ r->headers_out.location = ngx_http_add_header(&r->headers_out,
+ ngx_http_headers_out);
+ if (r->headers_out.location == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -283,9 +288,9 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
"HTTP DIR: \"%s\"", name.data);
- if (!(r->headers_out.location =
- ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
- {
+ r->headers_out.location = ngx_http_add_header(&r->headers_out,
+ ngx_http_headers_out);
+ if (r->headers_out.location == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -506,11 +511,13 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
if (!r->header_only) {
/* we need to allocate all before the header would be sent */
- if (!(b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)))) {
+ b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
+ if (b == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
- if (!(b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)))) {
+ b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
+ if (b->file == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -547,7 +554,8 @@ static void *ngx_http_static_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_static_loc_conf_t *conf;
- if (!(conf = ngx_palloc(cf->pool, sizeof(ngx_http_static_loc_conf_t)))) {
+ conf = ngx_palloc(cf->pool, sizeof(ngx_http_static_loc_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -578,7 +586,7 @@ static ngx_int_t ngx_http_static_init(ngx_cycle_t *cycle)
cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
- h = ngx_push_array(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
+ h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
if (h == NULL) {
return NGX_ERROR;
}
diff --git a/src/http/modules/ngx_http_status_handler.c b/src/http/modules/ngx_http_status_module.c
index ce49ae426..ce49ae426 100644
--- a/src/http/modules/ngx_http_status_handler.c
+++ b/src/http/modules/ngx_http_status_module.c
diff --git a/src/http/modules/ngx_http_stub_status_module.c b/src/http/modules/ngx_http_stub_status_module.c
index 7eeef5986..1a01bcea8 100644
--- a/src/http/modules/ngx_http_stub_status_module.c
+++ b/src/http/modules/ngx_http_stub_status_module.c
@@ -88,7 +88,8 @@ static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r)
+ 6 + 3 * NGX_ATOMIC_T_LEN
+ sizeof("Reading: Writing: Waiting: \n") + 3 * NGX_ATOMIC_T_LEN;
- if (!(b = ngx_create_temp_buf(r->pool, size))) {
+ b = ngx_create_temp_buf(r->pool, size);
+ if (b == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
diff --git a/src/http/modules/ngx_http_userid_filter.c b/src/http/modules/ngx_http_userid_filter_module.c
index ea49f928b..62d40ac34 100644
--- a/src/http/modules/ngx_http_userid_filter.c
+++ b/src/http/modules/ngx_http_userid_filter_module.c
@@ -618,7 +618,7 @@ ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data)
}
p = ngx_cpymem(new, "; domain=", sizeof("; domain=") - 1);
- p = ngx_cpymem(p, domain->data, domain->len);
+ ngx_memcpy(p, domain->data, domain->len);
domain->len += sizeof("; domain=") - 1;
domain->data = new;
@@ -640,7 +640,7 @@ ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data)
}
p = ngx_cpymem(new, "; path=", sizeof("; path=") - 1);
- p = ngx_cpymem(p, path->data, path->len);
+ ngx_memcpy(p, path->data, path->len);
path->len += sizeof("; path=") - 1;
path->data = new;
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index d213d6929..edad22cdf 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -11,7 +11,9 @@
static ngx_int_t ngx_http_proxy_handler(ngx_http_request_t *r);
+#if 0
static ngx_int_t ngx_http_proxy_cache_get(ngx_http_proxy_ctx_t *p);
+#endif
static size_t ngx_http_proxy_log_proxy_state_getlen(ngx_http_request_t *r,
uintptr_t data);
@@ -33,8 +35,6 @@ static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf,
static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
-static char *ngx_http_proxy_parse_upstream(ngx_str_t *url,
- ngx_http_proxy_upstream_conf_t *u);
static char *ngx_http_proxy_set_x_var(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
@@ -362,13 +362,20 @@ static ngx_str_t cache_reasons[] = {
};
+static ngx_str_t ngx_http_proxy_uri = ngx_string("/");
+
+
static ngx_int_t ngx_http_proxy_handler(ngx_http_request_t *r)
{
ngx_http_proxy_ctx_t *p;
- ngx_http_create_ctx(r, p, ngx_http_proxy_module,
- sizeof(ngx_http_proxy_ctx_t),
- NGX_HTTP_INTERNAL_SERVER_ERROR);
+ p = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_ctx_t));
+ if (p == NULL) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ ngx_http_set_ctx(r, p, ngx_http_proxy_module);
+
p->lcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
p->request = r;
@@ -382,7 +389,8 @@ static ngx_int_t ngx_http_proxy_handler(ngx_http_request_t *r)
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
- if (!(p->state = ngx_array_push(&p->states))) {
+ p->state = ngx_array_push(&p->states);
+ if (p->state == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -439,7 +447,8 @@ static ngx_int_t ngx_http_proxy_cache_get(ngx_http_proxy_ctx_t *p)
u = p->lcf->upstream;
ctx.key.len = u->url.len + r->uri.len - u->location->len + r->args.len;
- if (!(ctx.key.data = ngx_palloc(r->pool, ctx.key.len))) {
+ ctx.key.data = ngx_palloc(r->pool, ctx.key.len);
+ if (ctx.key.data == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -1072,7 +1081,8 @@ static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_proxy_loc_conf_t *conf;
- if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_loc_conf_t)))) {
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_loc_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -1332,7 +1342,8 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
unix_upstream.url.data = url->data + 7;
unix_upstream.uri_part = 1;
- if (!(lcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream))) {
+ lcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream);
+ if (lcf->peers == NULL) {
return NGX_CONF_ERROR;
}
@@ -1359,7 +1370,8 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
inet_upstream.default_port_value = 80;
inet_upstream.uri_part = 1;
- if (!(lcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream))) {
+ lcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream);
+ if (lcf->peers == NULL) {
return NGX_CONF_ERROR;
}
@@ -1372,9 +1384,14 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
- lcf->upstream->location = &clcf->name;
clcf->handler = ngx_http_proxy_handler;
+#if (NGX_PCRE)
+ lcf->upstream->location = clcf->regex ? &ngx_http_proxy_uri : &clcf->name;
+#else
+ lcf->upstream->location = &clcf->name;
+#endif
+
if (clcf->name.data[clcf->name.len - 1] == '/') {
clcf->auto_redirect = 1;
}
@@ -1409,7 +1426,8 @@ static char *ngx_http_proxy_set_x_var(ngx_conf_t *cf, ngx_command_t *cmd,
for (i = 0; i < cmcf->variables.nelts; i++) {
if (ngx_strcasecmp(var[i].name.data, value[1].data) == 0) {
- if (!(index = ngx_array_push(lcf->x_vars))) {
+ index = ngx_array_push(lcf->x_vars);
+ if (index == NULL) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/proxy/ngx_http_proxy_header.c b/src/http/modules/proxy/ngx_http_proxy_header.c
index 78ae6530f..a46ff9e2a 100644
--- a/src/http/modules/proxy/ngx_http_proxy_header.c
+++ b/src/http/modules/proxy/ngx_http_proxy_header.c
@@ -87,7 +87,8 @@ int ngx_http_proxy_copy_header(ngx_http_proxy_ctx_t *p,
/* copy some header pointers and set up r->headers_out */
- if (!(ho = ngx_list_push(&r->headers_out.headers))) {
+ ho = ngx_list_push(&r->headers_out.headers);
+ if (ho == NULL) {
return NGX_ERROR;
}
@@ -162,7 +163,8 @@ static int ngx_http_proxy_rewrite_location_header(ngx_http_proxy_ctx_t *p,
r = p->request;
uc = p->lcf->upstream;
- if (!(location = ngx_list_push(&r->headers_out.headers))) {
+ location = ngx_list_push(&r->headers_out.headers);
+ if (location == NULL) {
return NGX_ERROR;
}
@@ -189,7 +191,8 @@ static int ngx_http_proxy_rewrite_location_header(ngx_http_proxy_ctx_t *p,
location->value.len = uc->location->len
+ (loc->value.len - uc->url.len) + 1;
- if (!(location->value.data = ngx_palloc(r->pool, location->value.len))) {
+ location->value.data = ngx_palloc(r->pool, location->value.len);
+ if (location->value.data == NULL) {
return NGX_ERROR;
}
diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c
index 061ab9f0e..45dc04d70 100644
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -58,7 +58,8 @@ int ngx_http_proxy_request_upstream(ngx_http_proxy_ctx_t *p)
r = p->request;
- if (!(u = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_upstream_t)))) {
+ u = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_upstream_t));
+ if (u == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -85,7 +86,7 @@ int ngx_http_proxy_request_upstream(ngx_http_proxy_ctx_t *p)
static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
{
- size_t len;
+ size_t len, loc_len;
ngx_uint_t i, escape, *index;
ngx_buf_t *b;
ngx_chain_t *chain;
@@ -94,6 +95,7 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
ngx_http_request_t *r;
ngx_http_variable_t *var;
ngx_http_variable_value_t *value;
+ ngx_http_core_loc_conf_t *clcf;
ngx_http_core_main_conf_t *cmcf;
ngx_http_proxy_upstream_conf_t *uc;
@@ -112,16 +114,23 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
len = r->method_name.len;
}
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
+#if (NGX_PCRE)
+ loc_len = (clcf->regex) ? 1 : clcf->name.len;
+#else
+ loc_len = clcf->name.len;
+#endif
+
if (r->quoted_uri) {
- escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len,
- r->uri.len - uc->location->len,
- NGX_ESCAPE_URI);
+ escape = 2 * ngx_escape_uri(NULL, r->uri.data + loc_len,
+ r->uri.len - loc_len, NGX_ESCAPE_URI);
} else {
escape = 0;
}
len += uc->uri.len
- + r->uri.len - uc->location->len + escape
+ + r->uri.len - loc_len + escape
+ sizeof("?") - 1 + r->args.len
+ sizeof(http_version) - 1
+ sizeof(connection_close_header) - 1
@@ -190,7 +199,8 @@ 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_indexed_variable(r, index[i]))) {
+ value = ngx_http_get_indexed_variable(r, index[i]);
+ if (value == NULL) {
continue;
}
@@ -233,11 +243,13 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
len++;
#endif
- if (!(b = ngx_create_temp_buf(r->pool, len))) {
+ b = ngx_create_temp_buf(r->pool, len);
+ if (b == NULL) {
return NULL;
}
- if (!(chain = ngx_alloc_chain_link(r->pool))) {
+ chain = ngx_alloc_chain_link(r->pool);
+ if (chain == NULL) {
return NULL;
}
@@ -258,14 +270,13 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
b->last = ngx_cpymem(b->last, uc->uri.data, uc->uri.len);
if (escape) {
- ngx_escape_uri(b->last, r->uri.data + uc->location->len,
- r->uri.len - uc->location->len, NGX_ESCAPE_URI);
- b->last += r->uri.len - uc->location->len + escape;
+ ngx_escape_uri(b->last, r->uri.data + loc_len,
+ r->uri.len - loc_len, NGX_ESCAPE_URI);
+ b->last += r->uri.len - loc_len + escape;
} else {
- b->last = ngx_cpymem(b->last,
- r->uri.data + uc->location->len,
- r->uri.len - uc->location->len);
+ b->last = ngx_cpymem(b->last, r->uri.data + loc_len,
+ r->uri.len - loc_len);
}
if (r->args.len > 0) {
@@ -379,7 +390,8 @@ 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_indexed_variable(r, index[i]))) {
+ value = ngx_http_get_indexed_variable(r, index[i]);
+ if (value == NULL) {
continue;
}
@@ -506,7 +518,8 @@ static void ngx_http_proxy_init_upstream(ngx_http_request_t *r)
}
- if (!(cl = ngx_http_proxy_create_request(p))) {
+ cl = ngx_http_proxy_create_request(p);
+ if (cl == NULL) {
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
@@ -517,7 +530,8 @@ static void ngx_http_proxy_init_upstream(ngx_http_request_t *r)
r->request_body->bufs = cl;
- if (!(ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_log_ctx_t)))) {
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_log_ctx_t));
+ if (ctx == NULL) {
ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
@@ -531,7 +545,8 @@ static void ngx_http_proxy_init_upstream(ngx_http_request_t *r)
r->connection->log->handler = ngx_http_proxy_log_error;
p->action = "connecting to upstream";
- if (!(output = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t)))) {
+ output = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t));
+ if (output == NULL) {
ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
@@ -544,7 +559,8 @@ static void ngx_http_proxy_init_upstream(ngx_http_request_t *r)
output->tag = (ngx_buf_tag_t) &ngx_http_proxy_module;
output->output_filter = ngx_chain_writer;
- if (!(writer = ngx_palloc(r->pool, sizeof(ngx_chain_writer_ctx_t)))) {
+ writer = ngx_palloc(r->pool, sizeof(ngx_chain_writer_ctx_t));
+ if (writer == NULL) {
ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
@@ -603,7 +619,8 @@ static void ngx_http_proxy_reinit_upstream(ngx_http_proxy_ctx_t *p)
state = p->state->cache_state;
- if (!(p->state = ngx_push_array(&p->states))) {
+ p->state = ngx_array_push(&p->states);
+ if (p->state == NULL) {
ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
@@ -775,7 +792,8 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p)
if (r->request_body->buf) {
if (r->request_body->temp_file) {
- if (!(output->free = ngx_alloc_chain_link(r->pool))) {
+ output->free = ngx_alloc_chain_link(r->pool);
+ if (output->free == NULL) {
ngx_http_proxy_finalize_request(p,
NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
@@ -1005,7 +1023,7 @@ static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev)
rc = ngx_http_proxy_parse_status_line(p);
if (rc == NGX_AGAIN) {
- if (p->header_in->pos == p->header_in->last) {
+ if (p->header_in->pos == p->header_in->end) {
ngx_log_error(NGX_LOG_ERR, rev->log, 0,
"upstream sent too long status line");
ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_INVALID_HEADER);
@@ -1158,7 +1176,8 @@ static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev)
/* a header line has been parsed successfully */
- if (!(h = ngx_list_push(&p->upstream->headers_in.headers))) {
+ h = ngx_list_push(&p->upstream->headers_in.headers);
+ if (h == NULL) {
ngx_http_proxy_finalize_request(p,
NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
@@ -1315,6 +1334,11 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
rc = ngx_http_send_header(r);
+ if (rc == NGX_ERROR || rc > NGX_OK) {
+ ngx_http_proxy_finalize_request(p, rc);
+ return;
+ }
+
p->header_sent = 1;
if (p->cache && p->cache->ctx.file.fd != NGX_INVALID_FILE) {
@@ -1361,7 +1385,8 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
ep->cachable = p->cachable;
- if (!(ep->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)))) {
+ ep->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
+ if (ep->temp_file == NULL) {
ngx_http_proxy_finalize_request(p, 0);
return;
}
@@ -1381,7 +1406,8 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
ep->max_temp_file_size = p->lcf->max_temp_file_size;
ep->temp_file_write_size = p->lcf->temp_file_write_size;
- if (!(ep->preread_bufs = ngx_alloc_chain_link(r->pool))) {
+ ep->preread_bufs = ngx_alloc_chain_link(r->pool);
+ if (ep->preread_bufs == NULL) {
ngx_http_proxy_finalize_request(p, 0);
return;
}
@@ -1467,7 +1493,6 @@ static void ngx_http_proxy_process_body(ngx_event_t *ev)
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0,
"http proxy process upstream");
p = c->data;
- r = p->request;
p->action = "reading upstream body";
}
diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c
index f9c926091..e4c8f2e9c 100644
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -92,7 +92,8 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
/* the main http context */
- if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) {
+ ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
+ if (ctx == NULL) {
return NGX_CONF_ERROR;
}
@@ -162,19 +163,22 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
if (module->create_main_conf) {
- if (!(ctx->main_conf[mi] = module->create_main_conf(cf))) {
+ ctx->main_conf[mi] = module->create_main_conf(cf);
+ if (ctx->main_conf[mi] == NULL) {
return NGX_CONF_ERROR;
}
}
if (module->create_srv_conf) {
- if (!(ctx->srv_conf[mi] = module->create_srv_conf(cf))) {
+ ctx->srv_conf[mi] = module->create_srv_conf(cf);
+ if (ctx->srv_conf[mi] == NULL) {
return NGX_CONF_ERROR;
}
}
if (module->create_loc_conf) {
- if (!(ctx->loc_conf[mi] = module->create_loc_conf(cf))) {
+ ctx->loc_conf[mi] = module->create_loc_conf(cf);
+ if (ctx->loc_conf[mi] == NULL) {
return NGX_CONF_ERROR;
}
}
@@ -261,13 +265,14 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
/* we needed http{}'s cf->ctx while the merging configuration */
+
*cf = pcf;
/* init lists of the handlers */
if (ngx_array_init(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers,
- cf->pool, 1, sizeof(ngx_http_handler_pt)) == NGX_ERROR)
+ cf->pool, 1, sizeof(ngx_http_handler_pt)) != NGX_OK)
{
return NGX_CONF_ERROR;
}
@@ -278,14 +283,14 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
/* the special find config phase for a single handler */
if (ngx_array_init(&cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].handlers,
- cf->pool, 1, sizeof(ngx_http_handler_pt)) == NGX_ERROR)
+ cf->pool, 1, sizeof(ngx_http_handler_pt)) != NGX_OK)
{
return NGX_CONF_ERROR;
}
cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].type = NGX_OK;
- h = ngx_push_array(&cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].handlers);
+ h = ngx_array_push(&cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].handlers);
if (h == NULL) {
return NGX_CONF_ERROR;
}
@@ -294,7 +299,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (ngx_array_init(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers,
- cf->pool, 1, sizeof(ngx_http_handler_pt)) == NGX_ERROR)
+ cf->pool, 1, sizeof(ngx_http_handler_pt)) != NGX_OK)
{
return NGX_CONF_ERROR;
}
@@ -303,7 +308,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (ngx_array_init(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers,
- cf->pool, 4, sizeof(ngx_http_handler_pt)) == NGX_ERROR)
+ cf->pool, 4, sizeof(ngx_http_handler_pt)) != NGX_OK)
{
return NGX_CONF_ERROR;
}
@@ -317,7 +322,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
*/
if (ngx_array_init(&in_ports, cf->pool, 10, sizeof(ngx_http_in_port_t))
- == NGX_ERROR)
+ != NGX_OK)
{
return NGX_CONF_ERROR;
}
@@ -354,7 +359,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
/* the address is already in the address list */
if (ngx_http_add_names(cf, &in_addr[a], cscfp[s])
- == NGX_ERROR)
+ != NGX_OK)
{
return NGX_CONF_ERROR;
}
@@ -386,7 +391,8 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
/* the INADDR_ANY is always the last address */
- if (!(inaddr = ngx_array_push(&in_port[p].addrs))) {
+ inaddr = ngx_array_push(&in_port[p].addrs);
+ if (inaddr == NULL) {
return NGX_CONF_ERROR;
}
@@ -407,7 +413,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
in_addr[a].core_srv_conf = cscfp[s];
if (ngx_http_add_names(cf, &in_addr[a], cscfp[s])
- == NGX_ERROR)
+ != NGX_OK)
{
return NGX_CONF_ERROR;
}
@@ -426,7 +432,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
*/
if (ngx_http_add_address(cf, &in_port[p], &lscf[l],
- cscfp[s]) == NGX_ERROR)
+ cscfp[s]) != NGX_OK)
{
return NGX_CONF_ERROR;
}
@@ -438,14 +444,16 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
/* add the port to the in_port list */
- if (!(in_port = ngx_array_push(&in_ports))) {
+ in_port = ngx_array_push(&in_ports);
+ if (in_port == NULL) {
return NGX_CONF_ERROR;
}
in_port->port = lscf[l].port;
in_port->addrs.elts = NULL;
- if (!(in_port->port_text.data = ngx_palloc(cf->pool, 7))) {
+ in_port->port_text.data = ngx_palloc(cf->pool, 7);
+ if (in_port->port_text.data == NULL) {
return NGX_CONF_ERROR;
}
@@ -454,7 +462,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
- in_port->port_text.data;
if (ngx_http_add_address(cf, in_port, &lscf[l], cscfp[s])
- == NGX_ERROR)
+ != NGX_OK)
{
return NGX_CONF_ERROR;
}
@@ -484,7 +492,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
for (n = 0; n < in_addr[a].names.nelts; n++) {
if (in_addr[a].core_srv_conf != name[n].core_srv_conf
|| name[n].core_srv_conf->restrict_host_names
- != NGX_HTTP_RESTRICT_HOST_OFF)
+ != NGX_HTTP_RESTRICT_HOST_OFF)
{
virtual_names = 1;
break;
@@ -496,7 +504,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
for (n = 0; n < in_addr[a].wildcards.nelts; n++) {
if (in_addr[a].core_srv_conf != name[n].core_srv_conf
|| name[n].core_srv_conf->restrict_host_names
- != NGX_HTTP_RESTRICT_HOST_OFF)
+ != NGX_HTTP_RESTRICT_HOST_OFF)
{
virtual_names = 1;
break;
@@ -532,7 +540,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
for (n = 0; n < cmcf->server_names_hash; n++) {
if (ngx_array_init(&in_addr[a].hash[n], cf->pool, 5,
- sizeof(ngx_http_server_name_t)) == NGX_ERROR)
+ sizeof(ngx_http_server_name_t)) != NGX_OK)
{
return NGX_CONF_ERROR;
}
@@ -544,7 +552,8 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
name[s].name.len,
cmcf->server_names_hash);
- if (!(s_name = ngx_array_push(&in_addr[a].hash[key]))) {
+ s_name = ngx_array_push(&in_addr[a].hash[key]);
+ if (s_name == NULL) {
return NGX_CONF_ERROR;
}
@@ -575,13 +584,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
ls->backlog = -1;
-#if 0
-#if 0
- ls->nonblocking = 1;
-#else
- ls->nonblocking = 0;
-#endif
-#endif
+
ls->addr_ntop = 1;
ls->handler = ngx_http_init_connection;
@@ -612,19 +615,21 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
* the separate ngx_http_in_port_t for the all bindings
*/
- ngx_test_null(inport,
- ngx_palloc(cf->pool,
- sizeof(ngx_http_in_port_t)),
- NGX_CONF_ERROR);
+ inport = ngx_palloc(cf->pool, sizeof(ngx_http_in_port_t));
+ if (inport == NULL) {
+ return NGX_CONF_ERROR;
+ }
inport->port = in_port[p].port;
inport->port_text = in_port[p].port_text;
/* init list of the addresses ... */
- ngx_init_array(inport->addrs, cf->pool, 1,
- sizeof(ngx_http_in_addr_t),
- NGX_CONF_ERROR);
+ if (ngx_array_init(&inport->addrs, cf->pool, 1,
+ sizeof(ngx_http_in_addr_t)) != NGX_OK)
+ {
+ return NGX_CONF_ERROR;
+ }
/* ... and set up it with the first address */
@@ -636,7 +641,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
/* prepare for the next cycle */
in_port[p].addrs.elts = (char *) in_port[p].addrs.elts
- + in_port[p].addrs.size;
+ + in_port[p].addrs.size;
in_port[p].addrs.nelts--;
in_addr = (ngx_http_in_addr_t *) in_port[p].addrs.elts;
@@ -705,13 +710,14 @@ ngx_http_add_address(ngx_conf_t *cf, ngx_http_in_port_t *in_port,
if (in_port->addrs.elts == NULL) {
if (ngx_array_init(&in_port->addrs, cf->pool, 10,
- sizeof(ngx_http_in_addr_t)) == NGX_ERROR)
+ sizeof(ngx_http_in_addr_t)) != NGX_OK)
{
return NGX_ERROR;
}
}
- if (!(in_addr = ngx_array_push(&in_port->addrs))) {
+ in_addr = ngx_array_push(&in_port->addrs);
+ if (in_addr == NULL) {
return NGX_ERROR;
}
@@ -750,7 +756,7 @@ ngx_http_add_names(ngx_conf_t *cf, ngx_http_in_addr_t *in_addr,
if (in_addr->names.elts == NULL) {
if (ngx_array_init(&in_addr->names, cf->pool, 10,
- sizeof(ngx_http_server_name_t)) == NGX_ERROR)
+ sizeof(ngx_http_server_name_t)) != NGX_OK)
{
return NGX_ERROR;
}
@@ -758,7 +764,7 @@ ngx_http_add_names(ngx_conf_t *cf, ngx_http_in_addr_t *in_addr,
if (in_addr->wildcards.elts == NULL) {
if (ngx_array_init(&in_addr->wildcards, cf->pool, 10,
- sizeof(ngx_http_server_name_t)) == NGX_ERROR)
+ sizeof(ngx_http_server_name_t)) != NGX_OK)
{
return NGX_ERROR;
}
@@ -785,7 +791,8 @@ ngx_http_add_names(ngx_conf_t *cf, ngx_http_in_addr_t *in_addr,
array = &in_addr->names;
}
- if (!(name = ngx_array_push(array))) {
+ name = ngx_array_push(array);
+ if (name == NULL) {
return NGX_ERROR;
}
diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h
index 6f19af1c8..2d4158f1a 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -16,6 +16,8 @@ typedef struct ngx_http_request_s ngx_http_request_t;
typedef struct ngx_http_log_ctx_s ngx_http_log_ctx_t;
typedef struct ngx_http_cleanup_s ngx_http_cleanup_t;
typedef struct ngx_http_in_addr_s ngx_http_in_addr_t;
+typedef struct ngx_http_variable_value_s ngx_http_variable_value_t;
+
#if (NGX_HTTP_CACHE)
#include <ngx_http_cache.h>
@@ -27,7 +29,7 @@ typedef struct ngx_http_in_addr_s ngx_http_in_addr_t;
#include <ngx_http_request.h>
#include <ngx_http_config.h>
#include <ngx_http_busy_lock.h>
-#include <ngx_http_log_handler.h>
+#include <ngx_http_log_module.h>
#include <ngx_http_core_module.h>
#include <ngx_http_variables.h>
@@ -46,16 +48,7 @@ struct ngx_http_log_ctx_s {
#define ngx_http_get_module_err_ctx(r, module) \
((r)->err_ctx ? (r)->err_ctx[module.ctx_index] : (r)->ctx[module.ctx_index])
-/* STUB */
-#define ngx_http_create_ctx(r, cx, module, size, error) \
- do { \
- ngx_test_null(cx, ngx_pcalloc(r->pool, size), error); \
- r->ctx[module.ctx_index] = cx; \
- } while (0)
-/**/
-
#define ngx_http_set_ctx(r, c, module) r->ctx[module.ctx_index] = c;
-
#define ngx_http_delete_ctx(r, module) r->ctx[module.ctx_index] = NULL;
diff --git a/src/http/ngx_http_busy_lock.c b/src/http/ngx_http_busy_lock.c
index 2b3ee105d..fe04390a1 100644
--- a/src/http/ngx_http_busy_lock.c
+++ b/src/http/ngx_http_busy_lock.c
@@ -205,13 +205,15 @@ char *ngx_http_set_busy_lock_slot(ngx_conf_t *cf, ngx_command_t *cmd,
}
/* ngx_calloc_shared() */
- if (!(bl = ngx_pcalloc(cf->pool, sizeof(ngx_http_busy_lock_t)))) {
+ bl = ngx_pcalloc(cf->pool, sizeof(ngx_http_busy_lock_t));
+ if (bl == NULL) {
return NGX_CONF_ERROR;
}
*blp = bl;
/* ngx_calloc_shared() */
- if (!(bl->mutex = ngx_pcalloc(cf->pool, sizeof(ngx_event_mutex_t)))) {
+ bl->mutex = ngx_pcalloc(cf->pool, sizeof(ngx_event_mutex_t));
+ if (bl->mutex == NULL) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/ngx_http_config.h b/src/http/ngx_http_config.h
index 0bf63385c..581556fe4 100644
--- a/src/http/ngx_http_config.h
+++ b/src/http/ngx_http_config.h
@@ -59,15 +59,15 @@ typedef struct {
*/
#define ngx_http_conf_get_module_main_conf(cf, module) \
- ((ngx_http_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index]
+ ((ngx_http_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index]
#define ngx_http_conf_get_module_srv_conf(cf, module) \
- ((ngx_http_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index]
+ ((ngx_http_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index]
#define ngx_http_conf_get_module_loc_conf(cf, module) \
- ((ngx_http_conf_ctx_t *) cf->ctx)->loc_conf[module.ctx_index]
+ ((ngx_http_conf_ctx_t *) cf->ctx)->loc_conf[module.ctx_index]
#define ngx_http_cycle_get_module_main_conf(cycle, module) \
- ((ngx_http_conf_ctx_t *) \
- cycle->conf_ctx[ngx_http_module.index])->main_conf[module.ctx_index]
+ ((ngx_http_conf_ctx_t *) \
+ cycle->conf_ctx[ngx_http_module.index])->main_conf[module.ctx_index]
diff --git a/src/http/ngx_http_copy_filter.c b/src/http/ngx_http_copy_filter_module.c
index 10c574f4a..4e8943844 100644
--- a/src/http/ngx_http_copy_filter.c
+++ b/src/http/ngx_http_copy_filter_module.c
@@ -16,20 +16,20 @@ typedef struct {
static void *ngx_http_copy_filter_create_conf(ngx_conf_t *cf);
static char *ngx_http_copy_filter_merge_conf(ngx_conf_t *cf,
- void *parent, void *child);
+ void *parent, void *child);
static ngx_int_t ngx_http_copy_filter_init(ngx_cycle_t *cycle);
static ngx_command_t ngx_http_copy_filter_commands[] = {
- {ngx_string("output_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_copy_filter_conf_t, bufs),
- NULL},
+ { ngx_string("output_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_copy_filter_conf_t, bufs),
+ NULL },
- ngx_null_command
+ ngx_null_command
};
@@ -60,7 +60,8 @@ ngx_module_t ngx_http_copy_filter_module = {
static ngx_http_output_body_filter_pt ngx_http_next_filter;
-ngx_int_t ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
+static ngx_int_t
+ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
ngx_output_chain_ctx_t *ctx;
ngx_http_copy_filter_conf_t *conf;
@@ -76,8 +77,12 @@ ngx_int_t ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
conf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
ngx_http_copy_filter_module);
- ngx_http_create_ctx(r, ctx, ngx_http_copy_filter_module,
- sizeof(ngx_output_chain_ctx_t), NGX_ERROR);
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t));
+ if (ctx == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_http_set_ctx(r, ctx, ngx_http_copy_filter_module);
ctx->sendfile = r->connection->sendfile;
ctx->need_in_memory = r->filter_need_in_memory;
@@ -96,13 +101,15 @@ ngx_int_t ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
-static void *ngx_http_copy_filter_create_conf(ngx_conf_t *cf)
+static void *
+ngx_http_copy_filter_create_conf(ngx_conf_t *cf)
{
ngx_http_copy_filter_conf_t *conf;
- ngx_test_null(conf,
- ngx_palloc(cf->pool, sizeof(ngx_http_copy_filter_conf_t)),
- NULL);
+ conf = ngx_palloc(cf->pool, sizeof(ngx_http_copy_filter_conf_t));
+ if (conf == NULL) {
+ return NULL;
+ }
conf->bufs.num = 0;
@@ -110,8 +117,8 @@ static void *ngx_http_copy_filter_create_conf(ngx_conf_t *cf)
}
-static char *ngx_http_copy_filter_merge_conf(ngx_conf_t *cf,
- void *parent, void *child)
+static char *
+ngx_http_copy_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_copy_filter_conf_t *prev = parent;
ngx_http_copy_filter_conf_t *conf = child;
@@ -122,7 +129,8 @@ static char *ngx_http_copy_filter_merge_conf(ngx_conf_t *cf,
}
-static ngx_int_t ngx_http_copy_filter_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_copy_filter_init(ngx_cycle_t *cycle)
{
ngx_http_next_filter = ngx_http_top_body_filter;
ngx_http_top_body_filter = ngx_http_copy_filter;
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index c773d8ff4..620d2e9e5 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -785,7 +785,8 @@ ngx_http_set_content_type(ngx_http_request_t *r)
}
if (i < r->exten.len) {
- if (!(p = ngx_palloc(r->pool, r->exten.len))) {
+ p = ngx_palloc(r->pool, r->exten.len);
+ if (p == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -897,7 +898,8 @@ ngx_http_set_exten(ngx_http_request_t *r)
r->exten.len = r->uri.len - i - 1;
if (r->exten.len > 0) {
- if (!(r->exten.data = ngx_palloc(r->pool, r->exten.len + 1))) {
+ r->exten.data = ngx_palloc(r->pool, r->exten.len + 1);
+ if (r->exten.data == NULL) {
return NGX_ERROR;
}
@@ -997,7 +999,8 @@ ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
ngx_http_core_srv_conf_t *cscf, **cscfp;
ngx_http_core_main_conf_t *cmcf;
- if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) {
+ ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
+ if (ctx == NULL) {
return NGX_CONF_ERROR;
}
@@ -1026,7 +1029,8 @@ ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
module = ngx_modules[m]->ctx;
if (module->create_srv_conf) {
- if (!(mconf = module->create_srv_conf(cf))) {
+ mconf = module->create_srv_conf(cf);
+ if (mconf == NULL) {
return NGX_CONF_ERROR;
}
@@ -1034,7 +1038,8 @@ ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
}
if (module->create_loc_conf) {
- if (!(mconf = module->create_loc_conf(cf))) {
+ mconf = module->create_loc_conf(cf);
+ if (mconf == NULL) {
return NGX_CONF_ERROR;
}
@@ -1051,7 +1056,8 @@ ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
- if (!(cscfp = ngx_array_push(&cmcf->servers))) {
+ cscfp = ngx_array_push(&cmcf->servers);
+ if (cscfp == NULL) {
return NGX_CONF_ERROR;
}
@@ -1095,7 +1101,8 @@ ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
u_char errstr[NGX_MAX_CONF_ERRSTR];
#endif
- if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) {
+ ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
+ if (ctx == NULL) {
return NGX_CONF_ERROR;
}
@@ -1181,7 +1188,9 @@ ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
if (pclcf->name.len == 0) {
cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
- if (!(clcfp = ngx_array_push(&cscf->locations))) {
+
+ clcfp = ngx_array_push(&cscf->locations);
+ if (clcfp == NULL) {
return NGX_CONF_ERROR;
}
@@ -1214,11 +1223,15 @@ ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
}
if (pclcf->locations.elts == NULL) {
- ngx_init_array(pclcf->locations, cf->pool, 4, sizeof(void *),
- NGX_CONF_ERROR);
+ if (ngx_array_init(&pclcf->locations, cf->pool, 4, sizeof(void *))
+ != NGX_OK)
+ {
+ return NGX_CONF_ERROR;
+ }
}
- if (!(clcfp = ngx_push_array(&pclcf->locations))) {
+ clcfp = ngx_array_push(&pclcf->locations);
+ if (clcfp == NULL) {
return NGX_CONF_ERROR;
}
}
@@ -1347,7 +1360,8 @@ ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
for (i = 1; i < cf->args->nelts; i++) {
ngx_http_types_hash_key(key, value[i]);
- if (!(type = ngx_array_push(&lcf->types[key]))) {
+ type = ngx_array_push(&lcf->types[key]);
+ if (type == NULL) {
return NGX_CONF_ERROR;
}
@@ -1364,7 +1378,8 @@ ngx_http_core_create_main_conf(ngx_conf_t *cf)
{
ngx_http_core_main_conf_t *cmcf;
- if (!(cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t)))) {
+ cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t));
+ if (cmcf == NULL) {
return NGX_CONF_ERROR;
}
@@ -1403,7 +1418,8 @@ ngx_http_core_create_srv_conf(ngx_conf_t *cf)
{
ngx_http_core_srv_conf_t *cscf;
- if (!(cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t)))) {
+ cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t));
+ if (cscf == NULL) {
return NGX_CONF_ERROR;
}
@@ -1455,7 +1471,8 @@ ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
/* TODO: it does not merge, it inits only */
if (conf->listen.nelts == 0) {
- if (!(ls = ngx_array_push(&conf->listen))) {
+ ls = ngx_array_push(&conf->listen);
+ if (ls == NULL) {
return NGX_CONF_ERROR;
}
@@ -1470,11 +1487,13 @@ ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
}
if (conf->server_names.nelts == 0) {
- if (!(sn = ngx_array_push(&conf->server_names))) {
+ sn = ngx_array_push(&conf->server_names);
+ if (sn == NULL) {
return NGX_CONF_ERROR;
}
- if (!(sn->name.data = ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN))) {
+ sn->name.data = ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN);
+ if (sn->name.data == NULL) {
return NGX_CONF_ERROR;
}
@@ -1528,7 +1547,8 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_core_loc_conf_t *lcf;
- if (!(lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)))) {
+ lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t));
+ if (lcf == NULL) {
return NGX_CONF_ERROR;
}
@@ -1618,7 +1638,8 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
ngx_http_types_hash_key(key,
ngx_http_core_default_types[i].exten);
- if (!(type = ngx_array_push(&conf->types[key]))) {
+ type = ngx_array_push(&conf->types[key]);
+ if (type == NULL) {
return NGX_CONF_ERROR;
}
@@ -1700,7 +1721,8 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
* add resolved name to server names ???
*/
- if (!(ls = ngx_array_push(&scf->listen))) {
+ ls = ngx_array_push(&scf->listen);
+ if (ls == NULL) {
return NGX_CONF_ERROR;
}
@@ -1796,7 +1818,8 @@ ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}
- if (!(sn = ngx_array_push(&scf->server_names))) {
+ sn = ngx_array_push(&scf->server_names);
+ if (sn == NULL) {
return NGX_CONF_ERROR;
}
@@ -1908,7 +1931,8 @@ ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
for (i = 1; i < cf->args->nelts - n; i++) {
- if (!(err = ngx_array_push(lcf->error_pages))) {
+ err = ngx_array_push(lcf->error_pages);
+ if (err == NULL) {
return NGX_CONF_ERROR;
}
@@ -1981,7 +2005,8 @@ ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_core_loc_conf_t *lcf = conf;
- if (!(lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args))) {
+ lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args);
+ if (lcf->err_log == NULL) {
return NGX_CONF_ERROR;
}
@@ -2021,5 +2046,5 @@ ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
static ngx_int_t
ngx_http_core_init(ngx_cycle_t *cycle)
{
- return ngx_http_core_variables_init(cycle);
+ return ngx_http_variables_init(cycle);
}
diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter_module.c
index 65d8dee0a..b9dd88d5d 100644
--- a/src/http/ngx_http_header_filter.c
+++ b/src/http/ngx_http_header_filter_module.c
@@ -145,7 +145,7 @@ ngx_http_header_filter(ngx_http_request_t *r)
size_t len;
ngx_uint_t status, i;
ngx_buf_t *b;
- ngx_chain_t *ln;
+ ngx_chain_t out;
ngx_list_part_t *part;
ngx_table_elt_t *header;
ngx_http_core_loc_conf_t *clcf;
@@ -311,7 +311,8 @@ ngx_http_header_filter(ngx_http_request_t *r)
+ sizeof(CRLF) - 1;
}
- if (!(b = ngx_create_temp_buf(r->pool, len))) {
+ b = ngx_create_temp_buf(r->pool, len);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -461,14 +462,10 @@ ngx_http_header_filter(ngx_http_request_t *r)
b->last_buf = 1;
}
- if (!(ln = ngx_alloc_chain_link(r->pool))) {
- return NGX_ERROR;
- }
-
- ln->buf = b;
- ln->next = NULL;
+ out.buf = b;
+ out.next = NULL;
- return ngx_http_write_filter(r, ln);
+ return ngx_http_write_filter(r, &out);
}
diff --git a/src/http/ngx_http_log_handler.c b/src/http/ngx_http_log_module.c
index 4cb4af703..d19cae7d4 100644
--- a/src/http/ngx_http_log_handler.c
+++ b/src/http/ngx_http_log_module.c
@@ -36,8 +36,8 @@ static size_t ngx_http_log_request_getlen(ngx_http_request_t *r,
static u_char *ngx_http_log_request(ngx_http_request_t *r, u_char *buf,
ngx_http_log_op_t *op);
-static ngx_int_t ngx_http_log_header_in_compile(ngx_http_log_op_t *op,
- ngx_str_t *value);
+static ngx_int_t ngx_http_log_header_in_compile(ngx_conf_t *cf,
+ ngx_http_log_op_t *op, ngx_str_t *value);
static size_t ngx_http_log_header_in_getlen(ngx_http_request_t *r,
uintptr_t data);
static u_char *ngx_http_log_header_in(ngx_http_request_t *r, u_char *buf,
@@ -47,8 +47,8 @@ static size_t ngx_http_log_unknown_header_in_getlen(ngx_http_request_t *r,
static u_char *ngx_http_log_unknown_header_in(ngx_http_request_t *r,
u_char *buf, ngx_http_log_op_t *op);
-static ngx_int_t ngx_http_log_header_out_compile(ngx_http_log_op_t *op,
- ngx_str_t *value);
+static ngx_int_t ngx_http_log_header_out_compile(ngx_conf_t *cf,
+ ngx_http_log_op_t *op, ngx_str_t *value);
static size_t ngx_http_log_header_out_getlen(ngx_http_request_t *r,
uintptr_t data);
static u_char *ngx_http_log_header_out(ngx_http_request_t *r, u_char *buf,
@@ -66,6 +66,14 @@ static u_char *ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r,
static ngx_table_elt_t *ngx_http_log_unknown_header(ngx_list_t *headers,
ngx_str_t *value);
+static ngx_int_t ngx_http_log_variable_compile(ngx_conf_t *cf,
+ ngx_http_log_op_t *op, ngx_str_t *value);
+static size_t ngx_http_log_variable_getlen(ngx_http_request_t *r,
+ uintptr_t data);
+static u_char *ngx_http_log_variable(ngx_http_request_t *r, u_char *buf,
+ ngx_http_log_op_t *op);
+
+
static ngx_int_t ngx_http_log_set_formats(ngx_conf_t *cf);
static void *ngx_http_log_create_main_conf(ngx_conf_t *cf);
static void *ngx_http_log_create_loc_conf(ngx_conf_t *cf);
@@ -75,8 +83,6 @@ static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
-static ngx_int_t ngx_http_log_parse_format(ngx_conf_t *cf, ngx_array_t *ops,
- ngx_str_t *line);
static ngx_command_t ngx_http_log_commands[] = {
@@ -152,13 +158,12 @@ ngx_http_log_op_name_t ngx_http_log_fmt_ops[] = {
ngx_http_log_request_getlen,
ngx_http_log_request },
- { ngx_string("i"), 0, ngx_http_log_header_in_compile,
- ngx_http_log_header_in_getlen,
+ { ngx_string("i"), 0, ngx_http_log_header_in_compile, NULL,
ngx_http_log_header_in },
-
- { ngx_string("o"), 0, ngx_http_log_header_out_compile,
- ngx_http_log_header_out_getlen,
+ { ngx_string("o"), 0, ngx_http_log_header_out_compile, NULL,
ngx_http_log_header_out },
+ { ngx_string("v"), 0, ngx_http_log_variable_compile, NULL,
+ ngx_http_log_variable },
{ ngx_null_string, 0, NULL, NULL, NULL }
};
@@ -206,7 +211,8 @@ ngx_http_log_handler(ngx_http_request_t *r)
len++;
#endif
- if (!(line = ngx_palloc(r->pool, len))) {
+ line = ngx_palloc(r->pool, len);
+ if (line == NULL) {
return NGX_ERROR;
}
@@ -372,7 +378,8 @@ ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf,
static ngx_int_t
-ngx_http_log_header_in_compile(ngx_http_log_op_t *op, ngx_str_t *value)
+ngx_http_log_header_in_compile(ngx_conf_t *cf, ngx_http_log_op_t *op,
+ ngx_str_t *value)
{
ngx_uint_t i;
@@ -385,7 +392,7 @@ ngx_http_log_header_in_compile(ngx_http_log_op_t *op, ngx_str_t *value)
}
if (ngx_strncasecmp(ngx_http_headers_in[i].name.data, value->data,
- value->len) == 0)
+ value->len) == 0)
{
op->getlen = ngx_http_log_header_in_getlen;
op->run = ngx_http_log_header_in;
@@ -471,7 +478,8 @@ ngx_http_log_unknown_header_in(ngx_http_request_t *r, u_char *buf,
static ngx_int_t
-ngx_http_log_header_out_compile(ngx_http_log_op_t *op, ngx_str_t *value)
+ngx_http_log_header_out_compile(ngx_conf_t *cf, ngx_http_log_op_t *op,
+ ngx_str_t *value)
{
ngx_uint_t i;
@@ -721,6 +729,68 @@ ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r, u_char *buf,
}
+static ngx_int_t
+ngx_http_log_variable_compile(ngx_conf_t *cf, ngx_http_log_op_t *op,
+ ngx_str_t *value)
+{
+ ngx_uint_t i;
+ ngx_http_variable_t *var;
+
+ for (i = 0; i < value->len; i++) {
+ value->data[i] = ngx_toupper(value->data[i]);
+ }
+
+ var = ngx_http_add_variable(cf, value, 0);
+ if (var == NULL) {
+ return NGX_ERROR;
+ }
+
+ op->len = 0;
+ op->getlen = ngx_http_log_variable_getlen;
+ op->run = ngx_http_log_variable;
+ op->data = var->index;
+
+ return NGX_OK;
+}
+
+
+static size_t
+ngx_http_log_variable_getlen(ngx_http_request_t *r, uintptr_t data)
+{
+ ngx_http_variable_value_t *value;
+
+ value = ngx_http_get_indexed_variable(r, data);
+
+ if (value == NULL
+ || value == NGX_HTTP_VARIABLE_NOT_FOUND
+ || value->text.len == 0)
+ {
+ return 1;
+ }
+
+ return value->text.len;
+}
+
+
+static u_char *
+ngx_http_log_variable(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op)
+{
+ ngx_http_variable_value_t *value;
+
+ value = ngx_http_get_indexed_variable(r, op->data);
+
+ if (value == NULL
+ || value == NGX_HTTP_VARIABLE_NOT_FOUND
+ || value->text.len == 0)
+ {
+ *buf = '-';
+ return buf + 1;
+ }
+
+ return ngx_cpymem(buf, value->text.data, value->text.len);
+}
+
+
static ngx_int_t
ngx_http_log_set_formats(ngx_conf_t *cf)
{
@@ -741,7 +811,8 @@ ngx_http_log_create_main_conf(ngx_conf_t *cf)
char *rc;
ngx_str_t *value;
- if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_main_conf_t)))) {
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_main_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -753,18 +824,21 @@ ngx_http_log_create_main_conf(ngx_conf_t *cf)
cf->args->nelts = 0;
- if (!(value = ngx_array_push(cf->args))) {
+ value = ngx_array_push(cf->args);
+ if (value == NULL) {
return NGX_CONF_ERROR;
}
- if (!(value = ngx_array_push(cf->args))) {
+ value = ngx_array_push(cf->args);
+ if (value == NULL) {
return NGX_CONF_ERROR;
}
value->len = sizeof("combined") - 1;
value->data = (u_char *) "combined";
- if (!(value = ngx_array_push(cf->args))) {
+ value = ngx_array_push(cf->args);
+ if (value == NULL) {
return NGX_CONF_ERROR;
}
@@ -784,7 +858,8 @@ ngx_http_log_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_log_loc_conf_t *conf;
- if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_loc_conf_t)))) {
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_loc_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -823,7 +898,8 @@ ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
return NGX_CONF_ERROR;
}
- if (!(log = ngx_array_push(conf->logs))) {
+ log = ngx_array_push(conf->logs);
+ if (log == NULL) {
return NGX_CONF_ERROR;
}
@@ -871,11 +947,13 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module);
- if (!(log = ngx_array_push(llcf->logs))) {
+ log = ngx_array_push(llcf->logs);
+ if (log == NULL) {
return NGX_CONF_ERROR;
}
- if (!(log->file = ngx_conf_open_file(cf->cycle, &value[1]))) {
+ log->file = ngx_conf_open_file(cf->cycle, &value[1]);
+ if (log->file == NULL) {
return NGX_CONF_ERROR;
}
@@ -927,19 +1005,21 @@ ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
}
- if (!(fmt = ngx_push_array(&lmcf->formats))) {
+ fmt = ngx_array_push(&lmcf->formats);
+ if (fmt == NULL) {
return NGX_CONF_ERROR;
}
fmt->name = value[1];
- if (!(fmt->ops = ngx_array_create(cf->pool, 20, sizeof(ngx_http_log_op_t))))
- {
+ fmt->ops = ngx_array_create(cf->pool, 20, sizeof(ngx_http_log_op_t));
+ if (fmt->ops == NULL) {
return NGX_CONF_ERROR;
}
invalid = 0;
data = NULL;
+ arg.data = NULL;
for (s = 2; s < cf->args->nelts && !invalid; s++) {
@@ -947,7 +1027,8 @@ ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
while (i < value[s].len) {
- if (!(op = ngx_push_array(fmt->ops))) {
+ op = ngx_array_push(fmt->ops);
+ if (op == NULL) {
return NGX_CONF_ERROR;
}
@@ -1032,12 +1113,13 @@ ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}
- if (!(a = ngx_palloc(cf->pool, sizeof(ngx_str_t)))) {
+ a = ngx_palloc(cf->pool, sizeof(ngx_str_t));
+ if (a == NULL) {
return NGX_CONF_ERROR;
}
*a = arg;
- if (name->compile(op, a) == NGX_ERROR) {
+ if (name->compile(cf, op, a) == NGX_ERROR) {
return NGX_CONF_ERROR;
}
@@ -1076,7 +1158,8 @@ ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
} else {
op->run = ngx_http_log_copy_long;
- if (!(p = ngx_palloc(cf->pool, len))) {
+ p = ngx_palloc(cf->pool, len);
+ if (p == NULL) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/ngx_http_log_handler.h b/src/http/ngx_http_log_module.h
index 4472ed982..c414bc4ac 100644
--- a/src/http/ngx_http_log_handler.h
+++ b/src/http/ngx_http_log_module.h
@@ -4,8 +4,8 @@
*/
-#ifndef _NGX_HTTP_LOG_HANDLER_H_INCLUDED_
-#define _NGX_HTTP_LOG_HANDLER_H_INCLUDED_
+#ifndef _NGX_HTTP_LOG_MODULE_H_INCLUDED_
+#define _NGX_HTTP_LOG_MODULE_H_INCLUDED_
#include <ngx_config.h>
@@ -16,13 +16,14 @@
typedef struct ngx_http_log_op_s ngx_http_log_op_t;
typedef u_char *(*ngx_http_log_op_run_pt) (ngx_http_request_t *r, u_char *buf,
- ngx_http_log_op_t *op);
+ ngx_http_log_op_t *op);
typedef size_t (*ngx_http_log_op_getlen_pt) (ngx_http_request_t *r,
- uintptr_t data);
+ uintptr_t data);
+
+typedef ngx_int_t (*ngx_http_log_op_compile_pt) (ngx_conf_t *cf,
+ ngx_http_log_op_t *op, ngx_str_t *value);
-typedef ngx_int_t (*ngx_http_log_op_compile_pt) (ngx_http_log_op_t *op,
- ngx_str_t *value);
struct ngx_http_log_op_s {
size_t len;
@@ -67,4 +68,4 @@ typedef struct {
extern ngx_http_log_op_name_t ngx_http_log_fmt_ops[];
-#endif /* _NGX_HTTP_LOG_HANDLER_H_INCLUDED_ */
+#endif /* _NGX_HTTP_LOG_MODULE_H_INCLUDED_ */
diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c
index ca84d1627..a7d8fe37f 100644
--- a/src/http/ngx_http_parse.c
+++ b/src/http/ngx_http_parse.c
@@ -461,7 +461,6 @@ ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
default:
return NGX_HTTP_PARSE_INVALID_REQUEST;
}
- break;
}
}
@@ -646,7 +645,6 @@ ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b)
default:
return NGX_HTTP_PARSE_INVALID_HEADER;
}
- break;
/* end of header */
case sw_header_almost_done:
@@ -656,7 +654,6 @@ ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b)
default:
return NGX_HTTP_PARSE_INVALID_HEADER;
}
- break;
}
}
diff --git a/src/http/ngx_http_parse_time.c b/src/http/ngx_http_parse_time.c
index da9797177..549873762 100644
--- a/src/http/ngx_http_parse_time.c
+++ b/src/http/ngx_http_parse_time.c
@@ -229,10 +229,14 @@ time_t ngx_http_parse_time(u_char *value, size_t len)
return NGX_ERROR;
}
- if (sizeof(time_t) <= 4 && year >= 2038) {
+#if (NGX_TIME_T_SIZE <= 4)
+
+ if (year >= 2038) {
return NGX_ERROR;
}
+#endif
+
/*
* shift new year to March 1 and start months from 1 (not 0),
* it is needed for Gauss's formula
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index d41cb8d40..3876e39e7 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -18,7 +18,7 @@ static void ngx_http_process_request_line(ngx_event_t *rev);
static void ngx_http_process_request_headers(ngx_event_t *rev);
static ssize_t ngx_http_read_request_header(ngx_http_request_t *r);
static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r,
- ngx_uint_t request_line);
+ ngx_uint_t request_line);
static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r);
static ngx_int_t ngx_http_find_virtual_server(ngx_http_request_t *r);
@@ -34,7 +34,7 @@ static void ngx_http_set_lingering_close(ngx_http_request_t *r);
static void ngx_http_lingering_close_handler(ngx_event_t *ev);
static void ngx_http_client_error(ngx_http_request_t *r,
- int client_error, int error);
+ int client_error, int error);
static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len);
@@ -100,19 +100,22 @@ ngx_http_header_t ngx_http_headers_in[] = {
#if 0
-static void ngx_http_dummy(ngx_event_t *wev)
+static void
+ngx_http_dummy(ngx_event_t *wev)
{
return;
}
#endif
-void ngx_http_init_connection(ngx_connection_t *c)
+void
+ngx_http_init_connection(ngx_connection_t *c)
{
ngx_event_t *rev;
ngx_http_log_ctx_t *ctx;
- if (!(ctx = ngx_palloc(c->pool, sizeof(ngx_http_log_ctx_t)))) {
+ ctx = ngx_palloc(c->pool, sizeof(ngx_http_log_ctx_t));
+ if (ctx == NULL) {
ngx_http_close_connection(c);
return;
}
@@ -186,7 +189,8 @@ void ngx_http_init_connection(ngx_connection_t *c)
}
-static void ngx_http_init_request(ngx_event_t *rev)
+static
+void ngx_http_init_request(ngx_event_t *rev)
{
ngx_uint_t i;
socklen_t len;
@@ -225,7 +229,8 @@ static void ngx_http_init_request(ngx_event_t *rev)
#endif
} else {
- if (!(hc = ngx_pcalloc(c->pool, sizeof(ngx_http_connection_t)))) {
+ hc = ngx_pcalloc(c->pool, sizeof(ngx_http_connection_t));
+ if (hc == NULL) {
#if (NGX_STAT_STUB)
ngx_atomic_dec(ngx_stat_reading);
@@ -248,7 +253,8 @@ static void ngx_http_init_request(ngx_event_t *rev)
}
} else {
- if (!(r = ngx_pcalloc(c->pool, sizeof(ngx_http_request_t)))) {
+ r = ngx_pcalloc(c->pool, sizeof(ngx_http_request_t));
+ if (r == NULL) {
#if (NGX_STAT_STUB)
ngx_atomic_dec(ngx_stat_reading);
@@ -388,7 +394,8 @@ static void ngx_http_init_request(ngx_event_t *rev)
r->header_in = c->buffer;
}
- if (!(r->pool = ngx_create_pool(cscf->request_pool_size, c->log))) {
+ r->pool = ngx_create_pool(cscf->request_pool_size, c->log);
+ if (r->pool == NULL) {
ngx_http_close_connection(c);
return;
}
@@ -444,7 +451,8 @@ static void ngx_http_init_request(ngx_event_t *rev)
#if (NGX_HTTP_SSL)
-static void ngx_http_ssl_handshake(ngx_event_t *rev)
+static void
+ngx_http_ssl_handshake(ngx_event_t *rev)
{
u_char buf[1];
ssize_t n;
@@ -504,7 +512,8 @@ static void ngx_http_ssl_handshake(ngx_event_t *rev)
#endif
-static void ngx_http_process_request_line(ngx_event_t *rev)
+static void
+ngx_http_process_request_line(ngx_event_t *rev)
{
ssize_t n;
ngx_int_t rc, rv;
@@ -554,7 +563,8 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
if (r->complex_uri || r->quoted_uri) {
- if (!(r->uri.data = ngx_palloc(r->pool, r->uri.len + 1))) {
+ r->uri.data = ngx_palloc(r->pool, r->uri.len + 1);
+ if (r->uri.data == NULL) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
ngx_http_close_connection(c);
return;
@@ -707,7 +717,8 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
}
-static void ngx_http_process_request_headers(ngx_event_t *rev)
+static void
+ngx_http_process_request_headers(ngx_event_t *rev)
{
ssize_t n;
ngx_int_t rc, rv, i;
@@ -764,7 +775,8 @@ static void ngx_http_process_request_headers(ngx_event_t *rev)
r->headers_n++;
- if (!(h = ngx_list_push(&r->headers_in.headers))) {
+ h = ngx_list_push(&r->headers_in.headers);
+ if (h == NULL) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
ngx_http_close_connection(c);
return;
@@ -781,7 +793,8 @@ static void ngx_http_process_request_headers(ngx_event_t *rev)
if (h->key.len == sizeof("Cookie") - 1
&& ngx_strcasecmp(h->key.data, "Cookie") == 0)
{
- if (!(cookie = ngx_array_push(&r->headers_in.cookies))) {
+ cookie = ngx_array_push(&r->headers_in.cookies);
+ if (cookie == NULL) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
ngx_http_close_connection(c);
return;
@@ -879,7 +892,8 @@ static void ngx_http_process_request_headers(ngx_event_t *rev)
}
-static ssize_t ngx_http_read_request_header(ngx_http_request_t *r)
+static ssize_t
+ngx_http_read_request_header(ngx_http_request_t *r)
{
ssize_t n;
ngx_event_t *rev;
@@ -933,8 +947,9 @@ static ssize_t ngx_http_read_request_header(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r,
- ngx_uint_t request_line)
+static ngx_int_t
+ngx_http_alloc_large_header_buffer(ngx_http_request_t *r,
+ ngx_uint_t request_line)
{
u_char *old, *new;
ngx_buf_t *b;
@@ -1076,7 +1091,8 @@ static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r,
}
-static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_process_request_header(ngx_http_request_t *r)
{
u_char *ua, *user_agent, ch;
size_t len;
@@ -1106,7 +1122,7 @@ static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r)
if (r->headers_in.content_length) {
r->headers_in.content_length_n =
- ngx_atoi(r->headers_in.content_length->value.data,
+ ngx_atosz(r->headers_in.content_length->value.data,
r->headers_in.content_length->value.len);
if (r->headers_in.content_length_n == NGX_ERROR) {
@@ -1137,7 +1153,7 @@ static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r)
if (r->headers_in.keep_alive) {
r->headers_in.keep_alive_n =
- ngx_atoi(r->headers_in.keep_alive->value.data,
+ ngx_atotm(r->headers_in.keep_alive->value.data,
r->headers_in.keep_alive->value.len);
}
}
@@ -1191,7 +1207,8 @@ static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_find_virtual_server(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_find_virtual_server(ngx_http_request_t *r)
{
ngx_int_t rc;
ngx_uint_t i, n, key, found;
@@ -1297,7 +1314,8 @@ static ngx_int_t ngx_http_find_virtual_server(ngx_http_request_t *r)
}
-void ngx_http_finalize_request(ngx_http_request_t *r, int rc)
+void
+ngx_http_finalize_request(ngx_http_request_t *r, int rc)
{
ngx_http_core_loc_conf_t *clcf;
@@ -1380,7 +1398,8 @@ void ngx_http_finalize_request(ngx_http_request_t *r, int rc)
}
-static void ngx_http_set_write_handler(ngx_http_request_t *r)
+static void
+ngx_http_set_write_handler(ngx_http_request_t *r)
{
ngx_event_t *wev;
ngx_http_core_loc_conf_t *clcf;
@@ -1409,7 +1428,8 @@ static void ngx_http_set_write_handler(ngx_http_request_t *r)
}
-void ngx_http_writer(ngx_event_t *wev)
+void
+ngx_http_writer(ngx_event_t *wev)
{
int rc;
ngx_connection_t *c;
@@ -1486,7 +1506,8 @@ void ngx_http_writer(ngx_event_t *wev)
}
-static void ngx_http_block_read(ngx_event_t *rev)
+static void
+ngx_http_block_read(ngx_event_t *rev)
{
ngx_connection_t *c;
ngx_http_request_t *r;
@@ -1506,7 +1527,8 @@ static void ngx_http_block_read(ngx_event_t *rev)
}
-ngx_int_t ngx_http_discard_body(ngx_http_request_t *r)
+ngx_int_t
+ngx_http_discard_body(ngx_http_request_t *r)
{
ssize_t size;
ngx_event_t *rev;
@@ -1546,7 +1568,8 @@ ngx_int_t ngx_http_discard_body(ngx_http_request_t *r)
}
-static void ngx_http_read_discarded_body_event(ngx_event_t *rev)
+static void
+ngx_http_read_discarded_body_event(ngx_event_t *rev)
{
ngx_int_t rc;
ngx_connection_t *c;
@@ -1572,7 +1595,8 @@ static void ngx_http_read_discarded_body_event(ngx_event_t *rev)
}
-static ngx_int_t ngx_http_read_discarded_body(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_read_discarded_body(ngx_http_request_t *r)
{
ssize_t size, n;
u_char buffer[NGX_HTTP_DISCARD_BUFFER_SIZE];
@@ -1615,7 +1639,8 @@ static ngx_int_t ngx_http_read_discarded_body(ngx_http_request_t *r)
}
-static void ngx_http_set_keepalive(ngx_http_request_t *r)
+static void
+ngx_http_set_keepalive(ngx_http_request_t *r)
{
int tcp_nodelay;
ngx_int_t i;
@@ -1776,7 +1801,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
c->log->action = "keepalive";
if (c->tcp_nopush == NGX_TCP_NOPUSH_SET) {
- if (ngx_tcp_push(c->fd) == NGX_ERROR) {
+ if (ngx_tcp_push(c->fd) == -1) {
ngx_connection_error(c, ngx_socket_errno, ngx_tcp_push_n " failed");
ngx_http_close_connection(c);
return;
@@ -1818,13 +1843,13 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
}
-static void ngx_http_keepalive_handler(ngx_event_t *rev)
+static void
+ngx_http_keepalive_handler(ngx_event_t *rev)
{
- size_t size;
- ssize_t n;
- ngx_buf_t *b;
- ngx_connection_t *c;
- ngx_http_connection_t *hc;
+ size_t size;
+ ssize_t n;
+ ngx_buf_t *b;
+ ngx_connection_t *c;
c = rev->data;
@@ -1855,7 +1880,6 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev)
#endif
- hc = c->data;
b = c->buffer;
size = b->end - b->start;
@@ -1867,7 +1891,8 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev)
* to keep the buffer size.
*/
- if (!(b->pos = ngx_palloc(c->pool, size))) {
+ b->pos = ngx_palloc(c->pool, size);
+ if (b->pos == NULL) {
ngx_http_close_connection(c);
return;
}
@@ -1919,7 +1944,8 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev)
}
-static void ngx_http_set_lingering_close(ngx_http_request_t *r)
+static void
+ngx_http_set_lingering_close(ngx_http_request_t *r)
{
ngx_event_t *rev, *wev;
ngx_connection_t *c;
@@ -1977,7 +2003,8 @@ static void ngx_http_set_lingering_close(ngx_http_request_t *r)
}
-static void ngx_http_lingering_close_handler(ngx_event_t *rev)
+static void
+ngx_http_lingering_close_handler(ngx_event_t *rev)
{
ssize_t n;
ngx_msec_t timer;
@@ -2036,7 +2063,8 @@ static void ngx_http_lingering_close_handler(ngx_event_t *rev)
}
-void ngx_http_empty_handler(ngx_event_t *wev)
+void
+ngx_http_empty_handler(ngx_event_t *wev)
{
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0, "http empty handler");
@@ -2044,12 +2072,14 @@ void ngx_http_empty_handler(ngx_event_t *wev)
}
-ngx_int_t ngx_http_send_last(ngx_http_request_t *r)
+ngx_int_t
+ngx_http_send_last(ngx_http_request_t *r)
{
ngx_buf_t *b;
ngx_chain_t out;
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -2061,7 +2091,8 @@ ngx_int_t ngx_http_send_last(ngx_http_request_t *r)
}
-void ngx_http_close_request(ngx_http_request_t *r, int error)
+void
+ngx_http_close_request(ngx_http_request_t *r, int error)
{
ngx_uint_t i;
ngx_log_t *log;
@@ -2171,7 +2202,8 @@ void ngx_http_close_request(ngx_http_request_t *r, int error)
#if (NGX_HTTP_SSL)
-void ngx_ssl_close_handler(ngx_event_t *ev)
+void
+ngx_ssl_close_handler(ngx_event_t *ev)
{
ngx_connection_t *c;
@@ -2189,7 +2221,8 @@ void ngx_ssl_close_handler(ngx_event_t *ev)
#endif
-void ngx_http_close_connection(ngx_connection_t *c)
+void
+ngx_http_close_connection(ngx_connection_t *c)
{
ngx_pool_t *pool;
@@ -2216,12 +2249,12 @@ void ngx_http_close_connection(ngx_connection_t *c)
ngx_close_connection(c);
- ngx_destroy_pool(c->pool);
+ ngx_destroy_pool(pool);
}
-static void ngx_http_client_error(ngx_http_request_t *r,
- int client_error, int error)
+static void
+ngx_http_client_error(ngx_http_request_t *r, int client_error, int error)
{
u_char *p;
ngx_http_log_ctx_t *ctx;
@@ -2315,7 +2348,8 @@ static void ngx_http_client_error(ngx_http_request_t *r,
}
-static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len)
+static u_char *
+ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len)
{
u_char *p;
ngx_http_log_ctx_t *ctx;
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index 0e7e1054c..413af2fab 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -119,91 +119,91 @@ typedef enum {
typedef struct {
- ngx_str_t name;
- ngx_uint_t offset;
+ ngx_str_t name;
+ ngx_uint_t offset;
} ngx_http_header_t;
typedef struct {
- ngx_list_t headers;
+ ngx_list_t headers;
- ngx_table_elt_t *host;
- ngx_table_elt_t *connection;
- ngx_table_elt_t *if_modified_since;
- ngx_table_elt_t *user_agent;
- ngx_table_elt_t *referer;
- ngx_table_elt_t *content_length;
- ngx_table_elt_t *content_type;
+ ngx_table_elt_t *host;
+ ngx_table_elt_t *connection;
+ ngx_table_elt_t *if_modified_since;
+ ngx_table_elt_t *user_agent;
+ ngx_table_elt_t *referer;
+ ngx_table_elt_t *content_length;
+ ngx_table_elt_t *content_type;
- ngx_table_elt_t *range;
+ ngx_table_elt_t *range;
#if (NGX_HTTP_GZIP)
- ngx_table_elt_t *accept_encoding;
- ngx_table_elt_t *via;
+ ngx_table_elt_t *accept_encoding;
+ ngx_table_elt_t *via;
#endif
- ngx_table_elt_t *authorization;
+ ngx_table_elt_t *authorization;
- ngx_table_elt_t *keep_alive;
+ ngx_table_elt_t *keep_alive;
#if (NGX_HTTP_PROXY)
- ngx_table_elt_t *x_forwarded_for;
- ngx_table_elt_t *x_real_ip;
- ngx_table_elt_t *x_url;
+ ngx_table_elt_t *x_forwarded_for;
+ ngx_table_elt_t *x_real_ip;
+ ngx_table_elt_t *x_url;
#endif
#if (NGX_HTTP_HEADERS)
- ngx_table_elt_t *accept;
- ngx_table_elt_t *accept_language;
+ ngx_table_elt_t *accept;
+ ngx_table_elt_t *accept_language;
#endif
- ngx_array_t cookies;
+ ngx_array_t cookies;
- size_t host_name_len;
- ssize_t content_length_n;
- size_t connection_type;
- ssize_t keep_alive_n;
+ size_t host_name_len;
+ ssize_t content_length_n;
+ time_t keep_alive_n;
- unsigned msie:1;
- unsigned msie4:1;
- unsigned opera:1;
- unsigned gecko:1;
- unsigned konqueror:1;
+ unsigned connection_type:2;
+ unsigned msie:1;
+ unsigned msie4:1;
+ unsigned opera:1;
+ unsigned gecko:1;
+ unsigned konqueror:1;
} ngx_http_headers_in_t;
typedef struct {
- off_t start;
- off_t end;
- ngx_str_t content_range;
+ off_t start;
+ off_t end;
+ ngx_str_t content_range;
} ngx_http_range_t;
typedef struct {
- ngx_list_t headers;
-
- ngx_uint_t status;
- ngx_str_t status_line;
-
- ngx_table_elt_t *server;
- ngx_table_elt_t *date;
- ngx_table_elt_t *content_type;
- ngx_table_elt_t *content_length;
- ngx_table_elt_t *content_encoding;
- ngx_table_elt_t *location;
- ngx_table_elt_t *last_modified;
- ngx_table_elt_t *content_range;
- ngx_table_elt_t *accept_ranges;
- ngx_table_elt_t *expires;
- ngx_table_elt_t *cache_control;
- ngx_table_elt_t *etag;
-
- ngx_str_t charset;
- ngx_array_t ranges;
-
- off_t content_length_n;
- time_t date_time;
- time_t last_modified_time;
+ ngx_list_t headers;
+
+ ngx_uint_t status;
+ ngx_str_t status_line;
+
+ ngx_table_elt_t *server;
+ ngx_table_elt_t *date;
+ ngx_table_elt_t *content_type;
+ ngx_table_elt_t *content_length;
+ ngx_table_elt_t *content_encoding;
+ ngx_table_elt_t *location;
+ ngx_table_elt_t *last_modified;
+ ngx_table_elt_t *content_range;
+ ngx_table_elt_t *accept_ranges;
+ ngx_table_elt_t *expires;
+ ngx_table_elt_t *cache_control;
+ ngx_table_elt_t *etag;
+
+ ngx_str_t charset;
+ ngx_array_t ranges;
+
+ off_t content_length_n;
+ time_t date_time;
+ time_t last_modified_time;
} ngx_http_headers_out_t;
@@ -221,172 +221,171 @@ typedef struct {
struct ngx_http_cleanup_s {
union {
struct {
- ngx_fd_t fd;
- u_char *name;
+ ngx_fd_t fd;
+ u_char *name;
} file;
struct {
- ngx_http_cache_hash_t *hash;
- ngx_http_cache_entry_t *cache;
+ ngx_http_cache_hash_t *hash;
+ ngx_http_cache_entry_t *cache;
} cache;
} data;
- unsigned valid:1;
- unsigned cache:1;
+ unsigned valid:1;
+ unsigned cache:1;
};
typedef struct {
- ngx_http_request_t *request;
+ ngx_http_request_t *request;
- ngx_buf_t **busy;
- ngx_int_t nbusy;
+ ngx_buf_t **busy;
+ ngx_int_t nbusy;
- ngx_buf_t **free;
- ngx_int_t nfree;
+ ngx_buf_t **free;
+ ngx_int_t nfree;
- ngx_uint_t pipeline; /* unsigned pipeline:1; */
+ ngx_uint_t pipeline; /* unsigned pipeline:1; */
} ngx_http_connection_t;
typedef ngx_int_t (*ngx_http_handler_pt)(ngx_http_request_t *r);
struct ngx_http_request_s {
- uint32_t signature; /* "HTTP" */
+ uint32_t signature; /* "HTTP" */
- ngx_connection_t *connection;
+ ngx_connection_t *connection;
- void **ctx;
- void **main_conf;
- void **srv_conf;
- void **loc_conf;
+ void **ctx;
+ void **main_conf;
+ void **srv_conf;
+ void **loc_conf;
- ngx_http_cache_t *cache;
+ ngx_http_cache_t *cache;
- ngx_http_upstream_t *upstream;
+ ngx_http_upstream_t *upstream;
- ngx_file_t file;
+ ngx_file_t file;
- ngx_pool_t *pool;
- ngx_buf_t *header_in;
+ ngx_pool_t *pool;
+ ngx_buf_t *header_in;
- ngx_http_headers_in_t headers_in;
- ngx_http_headers_out_t headers_out;
+ ngx_http_headers_in_t headers_in;
+ ngx_http_headers_out_t headers_out;
- ngx_http_request_body_t *request_body;
+ ngx_http_request_body_t *request_body;
- time_t lingering_time;
- time_t start_time;
+ time_t lingering_time;
+ time_t start_time;
- ngx_uint_t method;
- ngx_uint_t http_version;
- ngx_uint_t http_major;
- ngx_uint_t http_minor;
+ ngx_uint_t method;
+ ngx_uint_t http_version;
+ ngx_uint_t http_major;
+ ngx_uint_t http_minor;
+
+ ngx_str_t request_line;
+ ngx_str_t uri;
+ ngx_str_t args;
+ ngx_str_t exten;
+ ngx_str_t unparsed_uri;
- ngx_str_t request_line;
- ngx_str_t uri;
- ngx_str_t args;
- ngx_str_t exten;
- ngx_str_t unparsed_uri;
+ ngx_str_t method_name;
+ ngx_str_t http_protocol;
+
+ ngx_http_request_t *main;
- ngx_str_t method_name;
- ngx_str_t http_protocol;
+ uint32_t in_addr;
+ ngx_uint_t port;
+ ngx_str_t *port_text; /* ":80" */
+ ngx_str_t server_name;
+ ngx_http_in_addr_t *virtual_names;
- ngx_http_request_t *main;
+ ngx_uint_t phase;
+ ngx_int_t phase_handler;
+ ngx_http_handler_pt content_handler;
- uint32_t in_addr;
- ngx_uint_t port;
- ngx_str_t *port_text; /* ":80" */
- ngx_str_t server_name;
- ngx_http_in_addr_t *virtual_names;
+ ngx_http_variable_value_t **variables;
- ngx_uint_t phase;
- ngx_int_t phase_handler;
- ngx_http_handler_pt content_handler;
-
- ngx_uint_t nvariables;
- void **variables;
-
- ngx_array_t cleanup;
+ ngx_array_t cleanup;
/* used to learn the Apache compatible response length without a header */
- size_t header_size;
+ size_t header_size;
- size_t request_length;
+ size_t request_length;
- u_char *discarded_buffer;
- void **err_ctx;
- ngx_uint_t err_status;
+ u_char *discarded_buffer;
+ void **err_ctx;
+ ngx_uint_t err_status;
- ngx_http_connection_t *http_connection;
+ ngx_http_connection_t *http_connection;
- unsigned http_state:4;
+ unsigned http_state:4;
/* URI with "/." and on Win32 with "//" */
- unsigned complex_uri:1;
+ unsigned complex_uri:1;
/* URI with "%" */
- unsigned quoted_uri:1;
+ unsigned quoted_uri:1;
/* URI with "+" */
- unsigned plus_in_uri:1;
+ unsigned plus_in_uri:1;
/* URI with "\0" or "%00" */
- unsigned zero_in_uri:1;
+ unsigned zero_in_uri:1;
- unsigned uri_changed:1;
- unsigned uri_changes:4;
+ unsigned uri_changed:1;
+ unsigned uri_changes:4;
- unsigned low_case_exten:1;
- unsigned header_timeout_set:1;
+ unsigned low_case_exten:1;
+ unsigned header_timeout_set:1;
- unsigned proxy:1;
- unsigned bypass_cache:1;
- unsigned no_cache:1;
+ unsigned proxy:1;
+ unsigned bypass_cache:1;
+ unsigned no_cache:1;
#if 0
- unsigned cachable:1;
+ unsigned cachable:1;
#endif
- unsigned pipeline:1;
+ unsigned pipeline:1;
- unsigned plain_http:1;
- unsigned chunked:1;
- unsigned header_only:1;
- unsigned keepalive:1;
- unsigned lingering_close:1;
- unsigned closed:1;
+ unsigned plain_http:1;
+ unsigned chunked:1;
+ unsigned header_only:1;
+ unsigned keepalive:1;
+ unsigned lingering_close:1;
+ unsigned closed:1;
- unsigned filter_need_in_memory:1;
- unsigned filter_ssi_need_in_memory:1;
- unsigned filter_need_temporary:1;
- unsigned filter_allow_ranges:1;
+ unsigned filter_need_in_memory:1;
+ unsigned filter_ssi_need_in_memory:1;
+ unsigned filter_need_temporary:1;
+ unsigned filter_allow_ranges:1;
#if (NGX_STAT_STUB)
- unsigned stat_reading:1;
- unsigned stat_writing:1;
+ unsigned stat_reading:1;
+ unsigned stat_writing:1;
#endif
- ngx_uint_t headers_n;
+ ngx_uint_t headers_n;
/* used to parse HTTP headers */
- ngx_uint_t state;
- u_char *uri_start;
- u_char *uri_end;
- u_char *uri_ext;
- u_char *args_start;
- u_char *request_start;
- u_char *request_end;
- u_char *method_end;
- u_char *schema_start;
- u_char *schema_end;
- u_char *host_start;
- u_char *host_end;
- u_char *port_start;
- u_char *port_end;
- u_char *header_name_start;
- u_char *header_name_end;
- u_char *header_start;
- u_char *header_end;
+ ngx_uint_t state;
+ u_char *uri_start;
+ u_char *uri_end;
+ u_char *uri_ext;
+ u_char *args_start;
+ u_char *request_start;
+ u_char *request_end;
+ u_char *method_end;
+ u_char *schema_start;
+ u_char *schema_end;
+ u_char *host_start;
+ u_char *host_end;
+ u_char *port_start;
+ u_char *port_end;
+ u_char *header_name_start;
+ u_char *header_name_end;
+ u_char *header_start;
+ u_char *header_end;
};
diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c
index 59f72208d..eeffd8afd 100644
--- a/src/http/ngx_http_request_body.c
+++ b/src/http/ngx_http_request_body.c
@@ -12,7 +12,7 @@
static void ngx_http_read_client_request_body_handler(ngx_event_t *rev);
static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r,
- ngx_connection_t *c);
+ ngx_connection_t *c);
/*
* on completion ngx_http_read_client_request_body() adds to
@@ -21,22 +21,35 @@ static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r,
* *) one memory or file buf that contains the rest of the body
*/
-ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r,
- ngx_http_client_body_handler_pt post_handler)
+ngx_int_t
+ngx_http_read_client_request_body(ngx_http_request_t *r,
+ ngx_http_client_body_handler_pt post_handler)
{
ssize_t size;
ngx_buf_t *b;
ngx_chain_t *cl;
+ ngx_connection_t *c;
ngx_http_request_body_t *rb;
ngx_http_core_loc_conf_t *clcf;
- if (!(rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t)))) {
+ rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t));
+ if (rb == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
r->request_body = rb;
+ /* STUB */
+ if (r->file.fd != NGX_INVALID_FILE) {
+ if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) {
+ ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno,
+ ngx_close_file_n " \"%V\" failed", &r->file.name);
+ }
+ r->file.fd = NGX_INVALID_FILE;
+ }
+ /**/
+
if (r->headers_in.content_length_n <= 0) {
post_handler(r);
return NGX_OK;
@@ -58,7 +71,8 @@ ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r,
/* there is the pre-read part of the request body */
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -66,7 +80,8 @@ ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r,
b->start = b->pos = r->header_in->pos;
b->end = b->last = r->header_in->last;
- if (!(rb->bufs = ngx_alloc_chain_link(r->pool))) {
+ rb->bufs = ngx_alloc_chain_link(r->pool);
+ if (rb->bufs == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -103,11 +118,13 @@ ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r,
size = clcf->client_body_buffer_size;
}
- if (!(rb->buf = ngx_create_temp_buf(r->pool, size))) {
+ rb->buf = ngx_create_temp_buf(r->pool, size);
+ if (rb->buf == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -121,14 +138,16 @@ ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r,
rb->bufs = cl;
}
- r->connection->read->event_handler =
- ngx_http_read_client_request_body_handler;
+ c = r->connection;
- return ngx_http_do_read_client_request_body(r, r->connection);
+ c->read->event_handler = ngx_http_read_client_request_body_handler;
+
+ return ngx_http_do_read_client_request_body(r, c);
}
-static void ngx_http_read_client_request_body_handler(ngx_event_t *rev)
+static void
+ngx_http_read_client_request_body_handler(ngx_event_t *rev)
{
ngx_int_t rc;
ngx_connection_t *c;
@@ -150,8 +169,9 @@ static void ngx_http_read_client_request_body_handler(ngx_event_t *rev)
}
-static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r,
- ngx_connection_t *c)
+static ngx_int_t
+ngx_http_do_read_client_request_body(ngx_http_request_t *r,
+ ngx_connection_t *c)
{
size_t size;
ssize_t n;
@@ -169,7 +189,8 @@ static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r,
if (rb->buf->last == rb->buf->end) {
if (rb->temp_file == NULL) {
- if (!(tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)))) {
+ tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
+ if (tf == NULL) {
return NGX_ERROR;
}
@@ -268,7 +289,8 @@ static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r,
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c
index 572ad0a9b..44da5f388 100644
--- a/src/http/ngx_http_special_response.c
+++ b/src/http/ngx_http_special_response.c
@@ -17,7 +17,7 @@ static u_char error_tail[] =
;
-static u_char msie_stub[] =
+static u_char ngx_http_msie_stub[] =
"<!-- The padding to disable MSIE's friendly error page -->" CRLF
"<!-- The padding to disable MSIE's friendly error page -->" CRLF
"<!-- The padding to disable MSIE's friendly error page -->" CRLF
@@ -234,9 +234,9 @@ ngx_int_t
ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
{
ngx_int_t rc;
- ngx_uint_t err, i, msie_padding;
+ ngx_uint_t i, err, msie_padding;
ngx_buf_t *b;
- ngx_chain_t *out, **ll, *cl;
+ ngx_chain_t *out, *cl;
ngx_http_err_page_t *err_page;
ngx_http_core_loc_conf_t *clcf;
@@ -327,7 +327,7 @@ ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
&& error >= NGX_HTTP_BAD_REQUEST
&& error != NGX_HTTP_REQUEST_URI_TOO_LARGE)
{
- r->headers_out.content_length_n += sizeof(msie_stub) - 1;
+ r->headers_out.content_length_n += sizeof(ngx_http_msie_stub) - 1;
msie_padding = 1;
}
@@ -360,43 +360,64 @@ ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
return NGX_OK;
}
- out = NULL;
- ll = NULL;
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
+
b->memory = 1;
b->pos = error_pages[err].data;
b->last = error_pages[err].data + error_pages[err].len;
- ngx_alloc_link_and_set_buf(cl, b, r->pool, NGX_ERROR);
- ngx_chain_add_link(out, ll, cl);
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl->buf = b;
+ out = cl;
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
+
b->memory = 1;
b->pos = error_tail;
b->last = error_tail + sizeof(error_tail) - 1;
- ngx_alloc_link_and_set_buf(cl, b, r->pool, NGX_ERROR);
- ngx_chain_add_link(out, ll, cl);
+ cl->next = ngx_alloc_chain_link(r->pool);
+ if (cl->next == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl = cl->next;
+ cl->buf = b;
if (msie_padding) {
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
+
b->memory = 1;
- b->pos = msie_stub;
- b->last = msie_stub + sizeof(msie_stub) - 1;
+ b->pos = ngx_http_msie_stub;
+ b->last = ngx_http_msie_stub + sizeof(ngx_http_msie_stub) - 1;
+
+ cl->next = ngx_alloc_chain_link(r->pool);
+ if (cl->next == NULL) {
+ return NGX_ERROR;
+ }
- ngx_alloc_link_and_set_buf(cl, b, r->pool, NGX_ERROR);
- ngx_chain_add_link(out, ll, cl);
+ cl = cl->next;
+ cl->buf = b;
}
b->last_buf = 1;
+ cl->next = NULL;
+
return ngx_http_output_filter(r, out);
}
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index 5b8312130..3076df7de 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -129,13 +129,14 @@ ngx_http_upstream_init(ngx_http_request_t *r)
u->writer.pool = r->pool;
if (ngx_array_init(&u->states, r->pool, u->peer.peers->number,
- sizeof(ngx_http_upstream_state_t)) == NGX_ERROR)
+ sizeof(ngx_http_upstream_state_t)) != NGX_OK)
{
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
- if (!(u->state = ngx_push_array(&u->states))) {
+ u->state = ngx_array_push(&u->states);
+ if (u->state == NULL) {
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
@@ -317,7 +318,8 @@ ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
if (r->request_body->buf) {
if (r->request_body->temp_file) {
- if (!(u->output.free = ngx_alloc_chain_link(r->pool))) {
+ u->output.free = ngx_alloc_chain_link(r->pool);
+ if (u->output.free == NULL) {
ngx_http_upstream_finalize_request(r, u,
NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
@@ -392,7 +394,8 @@ ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u)
/* add one more state */
- if (!(u->state = ngx_push_array(&u->states))) {
+ u->state = ngx_array_push(&u->states);
+ if (u->state == NULL) {
ngx_http_upstream_finalize_request(r, u,
NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
@@ -739,7 +742,8 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
p->cachable = u->cachable;
- if (!(p->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)))) {
+ p->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
+ if (p->temp_file == NULL) {
ngx_http_upstream_finalize_request(r, u, 0);
return;
}
@@ -759,7 +763,8 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
p->max_temp_file_size = u->conf->max_temp_file_size;
p->temp_file_write_size = u->conf->temp_file_write_size;
- if (!(p->preread_bufs = ngx_alloc_chain_link(r->pool))) {
+ p->preread_bufs = ngx_alloc_chain_link(r->pool);
+ if (p->preread_bufs == NULL) {
ngx_http_upstream_finalize_request(r, u, 0);
return;
}
diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c
index e65f38858..154ee1352 100644
--- a/src/http/ngx_http_variables.c
+++ b/src/http/ngx_http_variables.c
@@ -25,7 +25,7 @@
static ngx_http_variable_value_t *
ngx_http_variable_header(ngx_http_request_t *r, uintptr_t data);
static ngx_http_variable_value_t *
- ngx_http_variable_unknown_header(ngx_http_request_t *r, ngx_str_t *var);
+ ngx_http_variable_unknown_header(ngx_http_request_t *r, uintptr_t data);
static ngx_http_variable_value_t *
ngx_http_variable_remote_addr(ngx_http_request_t *r, uintptr_t data);
static ngx_http_variable_value_t *
@@ -69,39 +69,71 @@ static ngx_http_core_variable_t ngx_http_core_variables[] = {
ngx_http_variable_t *
-ngx_http_add_variable(ngx_conf_t *cf)
+ngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name, ngx_uint_t set)
{
- ngx_http_variable_t *var;
+ ngx_uint_t i;
+ ngx_http_variable_t *v;
ngx_http_core_main_conf_t *cmcf;
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
- if (cmcf->variables.elts == NULL) {
+ v = cmcf->variables.elts;
+
+ if (v == NULL) {
if (ngx_array_init(&cmcf->variables, cf->pool, 4,
sizeof(ngx_http_variable_t)) == NGX_ERROR)
{
return NULL;
}
+
+ } else {
+ for (i = 0; i < cmcf->variables.nelts; i++) {
+ if (name->len != v[i].name.len
+ || ngx_strncasecmp(name->data, v[i].name.data, name->len) != 0)
+ {
+ continue;
+ }
+
+ if (set && v[i].handler) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "the duplicate \"%V\" variable", name);
+ return NULL;
+ }
+
+ return &v[i];
+ }
}
- if (!(var = ngx_array_push(&cmcf->variables))) {
+ v = ngx_array_push(&cmcf->variables);
+ if (v == NULL) {
return NULL;
}
- var->index = cmcf->variables.nelts - 1;
+ v->name.len = name->len;
+ v->name.data = ngx_palloc(cf->pool, name->len);
+ if (v->name.data == NULL) {
+ return NULL;
+ }
+
+ for (i = 0; i < name->len; i++) {
+ v->name.data[i] = ngx_toupper(name->data[i]);
+ }
- return var;
+ v->index = cmcf->variables.nelts - 1;
+ v->handler = NULL;
+ v->data = 0;
+
+ return v;
}
ngx_http_variable_value_t *
ngx_http_get_indexed_variable(ngx_http_request_t *r, ngx_uint_t index)
{
- ngx_http_variable_t *var;
+ ngx_http_variable_t *v;
+ ngx_http_variable_value_t *vv;
ngx_http_core_main_conf_t *cmcf;
- /* TODO: cached variables */
-
cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
if (cmcf->variables.elts == NULL || cmcf->variables.nelts <= index) {
@@ -110,70 +142,70 @@ ngx_http_get_indexed_variable(ngx_http_request_t *r, ngx_uint_t index)
return NULL;
}
- var = cmcf->variables.elts;
-
- return var[index].handler(r, var[index].data);
-}
-
+ if (r->variables && r->variables[index]) {
+ return r->variables[index];
+ }
-ngx_int_t
-ngx_http_get_variable_index(ngx_http_core_main_conf_t *cmcf, ngx_str_t *name)
-{
- ngx_uint_t i;
- ngx_http_variable_t *var;
+ v = cmcf->variables.elts;
- var = cmcf->variables.elts;
- for (i = 0; i < cmcf->variables.nelts; i++) {
- if (var[i].name.len != name->len) {
- continue;
- }
+ vv = v[index].handler(r, v[index].data);
- if (ngx_strncasecmp(var[i].name.data, name->data, name->len) == 0) {
- return var[i].index;
+ if (r->variables == NULL) {
+ r->variables = ngx_pcalloc(r->pool, cmcf->variables.nelts
+ * sizeof(ngx_http_variable_value_t *));
+ if (r->variables == NULL) {
+ return NULL;
}
}
- return -1;
+ r->variables[index] = vv;
+
+ return vv;
}
ngx_http_variable_value_t *
ngx_http_get_variable(ngx_http_request_t *r, ngx_str_t *name)
{
- ngx_int_t index;
ngx_uint_t i, key;
- ngx_http_core_variable_t *var;
+ ngx_http_variable_t *v;
+ ngx_http_core_variable_t *cv;
ngx_http_core_main_conf_t *cmcf;
cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
- index = ngx_http_get_variable_index(cmcf, name);
+ v = cmcf->variables.elts;
+ for (i = 0; i < cmcf->variables.nelts; i++) {
+ if (v[i].name.len != name->len) {
+ continue;
+ }
- if (index != -1) {
- return ngx_http_get_indexed_variable(r, index);
+ if (ngx_strncmp(v[i].name.data, name->data, name->len) == 0) {
+ return ngx_http_get_indexed_variable(r, v[i].index);
+ }
}
ngx_http_vars_hash_key(key, name);
- var = ngx_http_core_variables_hash[key].elts;
+ cv = ngx_http_core_variables_hash[key].elts;
for (i = 0; i < ngx_http_core_variables_hash[key].nelts; i++) {
-
- if (var[i].name.len != name->len
- || ngx_strncasecmp(var[i].name.data, name->data, name->len) != 0)
- {
+ if (cv[i].name.len != name->len) {
continue;
}
- return var[i].handler(r, var[i].data);
+ if (ngx_strncmp(cv[i].name.data, name->data, name->len) == 0) {
+ return cv[i].handler(r, cv[i].data);
+ }
}
- if (ngx_strncasecmp(name->data, "HTTP_", 5) != 0) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "unknown \"%V\" variable", name);
- return NGX_HTTP_VARIABLE_NOT_FOUND;
+ if (ngx_strncmp(name->data, "HTTP_", 5) == 0) {
+ return ngx_http_variable_unknown_header(r, (uintptr_t) name);
}
- return ngx_http_variable_unknown_header(r, name);
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "unknown \"%V\" variable", name);
+
+ return NGX_HTTP_VARIABLE_NOT_FOUND;
}
@@ -181,7 +213,7 @@ static ngx_http_variable_value_t *
ngx_http_variable_header(ngx_http_request_t *r, uintptr_t data)
{
ngx_table_elt_t *h;
- ngx_http_variable_value_t *v;
+ ngx_http_variable_value_t *vv;
h = *(ngx_table_elt_t **) ((char *) &r->headers_in + data);
@@ -189,25 +221,28 @@ ngx_http_variable_header(ngx_http_request_t *r, uintptr_t data)
return NGX_HTTP_VARIABLE_NOT_FOUND;
}
- if (!(v = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)))) {
+ vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
+ if (vv == NULL) {
return NULL;
}
- v->value = 0;
- v->text = h->value;
+ vv->value = 0;
+ vv->text = h->value;
- return v;
+ return vv;
}
static ngx_http_variable_value_t *
-ngx_http_variable_unknown_header(ngx_http_request_t *r, ngx_str_t *var)
+ngx_http_variable_unknown_header(ngx_http_request_t *r, uintptr_t data)
{
+ ngx_str_t *var = (ngx_str_t *) data;
+
u_char ch;
ngx_uint_t i, n;
ngx_list_part_t *part;
ngx_table_elt_t *header;
- ngx_http_variable_value_t *v;
+ ngx_http_variable_value_t *vv;
part = &r->headers_in.headers.part;
header = part->elts;
@@ -241,13 +276,14 @@ ngx_http_variable_unknown_header(ngx_http_request_t *r, ngx_str_t *var)
}
if (n + 5 == var->len) {
- if (!(v = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)))) {
+ vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
+ if (vv == NULL) {
return NULL;
}
- v->value = 0;
- v->text = header[i].value;
- return v;
+ vv->value = 0;
+ vv->text = header[i].value;
+ return vv;
}
}
@@ -258,56 +294,61 @@ ngx_http_variable_unknown_header(ngx_http_request_t *r, ngx_str_t *var)
static ngx_http_variable_value_t *
ngx_http_variable_remote_addr(ngx_http_request_t *r, uintptr_t data)
{
- ngx_http_variable_value_t *v;
+ ngx_http_variable_value_t *vv;
- if (!(v = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)))) {
+ vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
+ if (vv == NULL) {
return NULL;
}
- v->value = 0;
- v->text = r->connection->addr_text;
+ vv->value = 0;
+ vv->text = r->connection->addr_text;
- return v;
+ return vv;
}
static ngx_http_variable_value_t *
ngx_http_variable_uri(ngx_http_request_t *r, uintptr_t data)
{
- ngx_http_variable_value_t *v;
+ ngx_http_variable_value_t *vv;
- if (!(v = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)))) {
+ vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
+ if (vv == NULL) {
return NULL;
}
- v->value = 0;
- v->text = r->uri;
+ vv->value = 0;
+ vv->text = r->uri;
- return v;
+ return vv;
}
static ngx_http_variable_value_t *
ngx_http_variable_query_string(ngx_http_request_t *r, uintptr_t data)
{
- ngx_http_variable_value_t *v;
+ ngx_http_variable_value_t *vv;
- if (!(v = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)))) {
+ vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
+ if (vv == NULL) {
return NULL;
}
- v->value = 0;
- v->text = r->args;
+ vv->value = 0;
+ vv->text = r->args;
- return v;
+ return vv;
}
ngx_int_t
-ngx_http_core_variables_init(ngx_cycle_t *cycle)
+ngx_http_variables_init(ngx_cycle_t *cycle)
{
- ngx_uint_t i, key;
- ngx_http_core_variable_t *var, *v;
+ ngx_uint_t i, j, key;
+ ngx_http_variable_t *v;
+ ngx_http_core_variable_t *cv, *vp;
+ ngx_http_core_main_conf_t *cmcf;
ngx_http_core_variables_hash = ngx_palloc(cycle->pool,
NGX_HTTP_VARS_HASH_PRIME
@@ -324,14 +365,54 @@ ngx_http_core_variables_init(ngx_cycle_t *cycle)
}
}
- for (var = ngx_http_core_variables; var->name.len; var++) {
- ngx_http_vars_hash_key(key, &var->name);
+ for (cv = ngx_http_core_variables; cv->name.len; cv++) {
+ ngx_http_vars_hash_key(key, &cv->name);
- if (!(v = ngx_array_push(&ngx_http_core_variables_hash[key]))) {
+ vp = ngx_array_push(&ngx_http_core_variables_hash[key]);
+ if (vp == NULL) {
return NGX_ERROR;
}
- *v = *var;
+ *vp = *cv;
+ }
+
+
+ cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
+
+ v = cmcf->variables.elts;
+ for (i = 0; i < cmcf->variables.nelts; i++) {
+
+ if (v[i].handler) {
+ continue;
+ }
+
+ ngx_http_vars_hash_key(key, &v[i].name);
+
+ cv = ngx_http_core_variables_hash[key].elts;
+ for (j = 0; j < ngx_http_core_variables_hash[key].nelts; j++) {
+ if (cv[j].name.len != v[i].name.len) {
+ continue;
+ }
+
+ if (ngx_strncmp(cv[j].name.data, v[i].name.data, v[i].name.len)
+ == 0)
+ {
+ v[i].handler = cv[j].handler;
+ v[i].data = cv[j].data;
+ continue;
+ }
+ }
+
+ if (ngx_strncmp(v[i].name.data, "HTTP_", 5) == 0) {
+ v[i].handler = ngx_http_variable_unknown_header;
+ v[i].data = (uintptr_t) &v[i].name;
+ continue;
+ }
+
+ ngx_log_error(NGX_LOG_ERR, cycle->log, 0,
+ "unknown \"%V\" variable", &v[i].name);
+
+ return NGX_ERROR;
}
return NGX_OK;
diff --git a/src/http/ngx_http_variables.h b/src/http/ngx_http_variables.h
index c7ccdc12e..bf80386cb 100644
--- a/src/http/ngx_http_variables.h
+++ b/src/http/ngx_http_variables.h
@@ -17,45 +17,41 @@
#define NGX_HTTP_VARIABLE_NOT_FOUND (ngx_http_variable_value_t *) -1
-typedef struct {
+struct ngx_http_variable_value_s {
ngx_uint_t value;
ngx_str_t text;
-} ngx_http_variable_value_t;
-
+};
typedef struct ngx_http_variable_s ngx_http_variable_t;
typedef ngx_http_variable_value_t *
- (*ngx_http_get_variable_pt) (ngx_http_request_t *r, void *var);
+ (*ngx_http_get_variable_pt) (ngx_http_request_t *r, uintptr_t data);
struct ngx_http_variable_s {
- ngx_str_t name;
- ngx_uint_t index;
- ngx_http_get_variable_pt handler;
- void *data;
- ngx_uint_t uses;
+ ngx_str_t name;
+ ngx_uint_t index;
+ ngx_http_get_variable_pt handler;
+ uintptr_t data;
};
-typedef ngx_http_variable_value_t *
- (*ngx_http_get_core_variable_pt) (ngx_http_request_t *r, uintptr_t data);
-
typedef struct {
- ngx_str_t name;
- ngx_http_get_core_variable_pt handler;
- uintptr_t data;
+ ngx_str_t name;
+ ngx_http_get_variable_pt handler;
+ uintptr_t data;
} ngx_http_core_variable_t;
-ngx_http_variable_t *ngx_http_add_variable(ngx_conf_t *cf);
+ngx_http_variable_t *ngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name,
+ ngx_uint_t set);
ngx_int_t ngx_http_get_variable_index(ngx_http_core_main_conf_t *cmcf,
ngx_str_t *name);
ngx_http_variable_value_t *ngx_http_get_indexed_variable(ngx_http_request_t *r,
ngx_uint_t index);
ngx_http_variable_value_t *ngx_http_get_variable(ngx_http_request_t *r,
ngx_str_t *name);
-ngx_int_t ngx_http_core_variables_init(ngx_cycle_t *cycle);
+ngx_int_t ngx_http_variables_init(ngx_cycle_t *cycle);
#endif /* _NGX_HTTP_VARIABLES_H_INCLUDED_ */
diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter_module.c
index 12699096e..8883907ae 100644
--- a/src/http/ngx_http_write_filter.c
+++ b/src/http/ngx_http_write_filter_module.c
@@ -42,7 +42,8 @@ ngx_module_t ngx_http_write_filter_module = {
};
-ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
+ngx_int_t
+ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
off_t size, sent;
ngx_uint_t last, flush;
@@ -55,8 +56,13 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
ngx_http_write_filter_module);
if (ctx == NULL) {
- ngx_http_create_ctx(r, ctx, ngx_http_write_filter_module,
- sizeof(ngx_http_write_filter_ctx_t), NGX_ERROR);
+
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_write_filter_ctx_t));
+ if (ctx == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_http_set_ctx(r, ctx, ngx_http_write_filter_module);
}
size = 0;
@@ -112,7 +118,8 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
/* add the new chain to the existent one */
for (ln = in; ln; ln = ln->next) {
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
return NGX_ERROR;
}
@@ -190,7 +197,11 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
if (flush) {
- while ((ctx->out = ctx->out->next)) { /* void */ }
+ do {
+ ctx->out = ctx->out->next;
+ }
+ while (ctx->out);
+
return NGX_OK;
}
@@ -230,7 +241,8 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
-static ngx_int_t ngx_http_write_filter_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_write_filter_init(ngx_cycle_t *cycle)
{
ngx_http_top_body_filter = ngx_http_write_filter;