nginx-0.1.25-RELEASE import
*) 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.
diff --git a/src/core/nginx.c b/src/core/nginx.c
index d6ee9f6..e2a35dc 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -141,7 +141,8 @@
ngx_pid = ngx_getpid();
- if (!(log = ngx_log_init())) {
+ log = ngx_log_init();
+ if (log == NULL) {
return 1;
}
@@ -155,7 +156,8 @@
init_cycle.log = log;
ngx_cycle = &init_cycle;
- if (!(init_cycle.pool = ngx_create_pool(1024, log))) {
+ init_cycle.pool = ngx_create_pool(1024, log);
+ if (init_cycle.pool == NULL) {
return 1;
}
@@ -255,9 +257,9 @@
static ngx_int_t
ngx_add_inherited_sockets(ngx_cycle_t *cycle)
{
- u_char *p, *v, *inherited;
- ngx_socket_t s;
- ngx_listening_t *ls;
+ u_char *p, *v, *inherited;
+ ngx_int_t s;
+ ngx_listening_t *ls;
inherited = (u_char *) getenv(NGINX_VAR);
@@ -287,11 +289,12 @@
v = p + 1;
- if (!(ls = ngx_array_push(&cycle->listening))) {
+ ls = ngx_array_push(&cycle->listening);
+ if (ls == NULL) {
return NGX_ERROR;
}
- ls->fd = s;
+ ls->fd = (ngx_socket_t) s;
}
}
@@ -315,7 +318,7 @@
ctx.argv = argv;
var = ngx_alloc(sizeof(NGINX_VAR)
- + cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2,
+ + cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2,
cycle->log);
p = ngx_cpymem(var, NGINX_VAR "=", sizeof(NGINX_VAR));
@@ -411,27 +414,29 @@
static ngx_int_t
ngx_save_argv(ngx_cycle_t *cycle, int argc, char *const *argv)
{
+#if (NGX_FREEBSD)
+
+ ngx_os_argv = (char **) argv;
+ ngx_argc = argc;
+ ngx_argv = (char **) argv;
+
+#else
size_t len;
ngx_int_t i;
ngx_os_argv = (char **) argv;
-
ngx_argc = argc;
-#if (NGX_FREEBSD)
-
- ngx_argv = (char **) argv;
-
-#else
-
- if (!(ngx_argv = ngx_alloc((argc + 1) * sizeof(char *), cycle->log))) {
+ ngx_argv = ngx_alloc((argc + 1) * sizeof(char *), cycle->log);
+ if (ngx_argv == NULL) {
return NGX_ERROR;
}
for (i = 0; i < argc; i++) {
len = ngx_strlen(argv[i]) + 1;
- if (!(ngx_argv[i] = ngx_alloc(len, cycle->log))) {
+ ngx_argv[i] = ngx_alloc(len, cycle->log);
+ if (ngx_argv[i] == NULL) {
return NGX_ERROR;
}
@@ -451,7 +456,8 @@
{
ngx_core_conf_t *ccf;
- if (!(ccf = ngx_pcalloc(cycle->pool, sizeof(ngx_core_conf_t)))) {
+ ccf = ngx_pcalloc(cycle->pool, sizeof(ngx_core_conf_t));
+ if (ccf == NULL) {
return NULL;
}
@@ -534,7 +540,8 @@
ccf->newpid.len = ccf->pid.len + sizeof(NGX_NEWPID_EXT);
- if (!(ccf->newpid.data = ngx_palloc(cycle->pool, ccf->newpid.len))) {
+ ccf->newpid.data = ngx_palloc(cycle->pool, ccf->newpid.len);
+ if (ccf->newpid.data == NULL) {
return NGX_CONF_ERROR;
}
diff --git a/src/core/nginx.h b/src/core/nginx.h
index 5f76b9b..54afca9 100644
--- a/src/core/nginx.h
+++ b/src/core/nginx.h
@@ -8,7 +8,7 @@
#define _NGINX_H_INCLUDED_
-#define NGINX_VER "nginx/0.1.24"
+#define NGINX_VER "nginx/0.1.25"
#define NGINX_VAR "NGINX"
#define NGX_NEWPID_EXT ".newbin"
diff --git a/src/core/ngx_array.c b/src/core/ngx_array.c
index 82d5d1d..b6167af 100644
--- a/src/core/ngx_array.c
+++ b/src/core/ngx_array.c
@@ -12,11 +12,13 @@
{
ngx_array_t *a;
- if (!(a = ngx_palloc(p, sizeof(ngx_array_t)))) {
+ a = ngx_palloc(p, sizeof(ngx_array_t));
+ if (a == NULL) {
return NULL;
}
- if (!(a->elts = ngx_palloc(p, n * size))) {
+ a->elts = ngx_palloc(p, n * size);
+ if (a->elts == NULL) {
return NULL;
}
@@ -72,7 +74,8 @@
} else {
/* allocate a new array */
- if (!(new = ngx_palloc(p, 2 * size))) {
+ new = ngx_palloc(p, 2 * size);
+ if (new == NULL) {
return NULL;
}
@@ -120,7 +123,8 @@
nalloc = 2 * ((n >= a->nalloc) ? n : a->nalloc);
- if (!(new = ngx_palloc(p, nalloc * a->size))) {
+ new = ngx_palloc(p, nalloc * a->size);
+ if (new == NULL) {
return NULL;
}
diff --git a/src/core/ngx_array.h b/src/core/ngx_array.h
index d90cf76..5f97451 100644
--- a/src/core/ngx_array.h
+++ b/src/core/ngx_array.h
@@ -27,10 +27,11 @@
void *ngx_array_push_n(ngx_array_t *a, ngx_uint_t n);
-static ngx_inline ngx_int_t ngx_array_init(ngx_array_t *array, ngx_pool_t *pool,
- ngx_uint_t n, size_t size)
+static ngx_inline ngx_int_t
+ngx_array_init(ngx_array_t *array, ngx_pool_t *pool, ngx_uint_t n, size_t size)
{
- if (!(array->elts = ngx_palloc(pool, n * size))) {
+ array->elts = ngx_palloc(pool, n * size);
+ if (array->elts == NULL) {
return NGX_ERROR;
}
@@ -43,14 +44,4 @@
}
-/* STUB */
-#define ngx_init_array(a, p, n, s, rc) \
- ngx_test_null(a.elts, ngx_palloc(p, n * s), rc); \
- a.nelts = 0; a.size = s; a.nalloc = n; a.pool = p;
-
-#define ngx_create_array ngx_array_create
-#define ngx_push_array ngx_array_push
-/**/
-
-
#endif /* _NGX_ARRAY_H_INCLUDED_ */
diff --git a/src/core/ngx_buf.c b/src/core/ngx_buf.c
index 97c94a3..2f0356f 100644
--- a/src/core/ngx_buf.c
+++ b/src/core/ngx_buf.c
@@ -13,11 +13,13 @@
{
ngx_buf_t *b;
- if (!(b = ngx_calloc_buf(pool))) {
+ b = ngx_calloc_buf(pool);
+ if (b == NULL) {
return NULL;
}
- if (!(b->start = ngx_palloc(pool, size))) {
+ b->start = ngx_palloc(pool, size);
+ if (b->start == NULL) {
return NULL;
}
@@ -49,14 +51,17 @@
ngx_buf_t *b;
ngx_chain_t *chain, *cl, **ll;
- if (!(p = ngx_palloc(pool, bufs->num * bufs->size))) {
+ p = ngx_palloc(pool, bufs->num * bufs->size);
+ if (p == NULL) {
return NULL;
}
ll = &chain;
for (i = 0; i < bufs->num; i++) {
- if (!(b = ngx_calloc_buf(pool))) {
+
+ b = ngx_calloc_buf(pool);
+ if (b == NULL) {
return NULL;
}
@@ -79,7 +84,8 @@
p += bufs->size;
b->end = p;
- if (!(cl = ngx_alloc_chain_link(pool))) {
+ cl = ngx_alloc_chain_link(pool);
+ if (cl == NULL) {
return NULL;
}
@@ -106,7 +112,10 @@
}
while (in) {
- ngx_test_null(cl, ngx_alloc_chain_link(pool), NGX_ERROR);
+ cl = ngx_alloc_chain_link(pool);
+ if (cl == NULL) {
+ return NGX_ERROR;
+ }
cl->buf = in->buf;
*ll = cl;
diff --git a/src/core/ngx_buf.h b/src/core/ngx_buf.h
index d672cf4..721b9c2 100644
--- a/src/core/ngx_buf.h
+++ b/src/core/ngx_buf.h
@@ -119,27 +119,9 @@
#define ngx_alloc_buf(pool) ngx_palloc(pool, sizeof(ngx_buf_t))
#define ngx_calloc_buf(pool) ngx_pcalloc(pool, sizeof(ngx_buf_t))
-
#define ngx_alloc_chain_link(pool) ngx_palloc(pool, sizeof(ngx_chain_t))
-#define ngx_alloc_link_and_set_buf(chain, b, pool, error) \
- do { \
- ngx_test_null(chain, ngx_alloc_chain_link(pool), error); \
- chain->buf = b; \
- chain->next = NULL; \
- } while (0);
-
-
-#define ngx_chain_add_link(chain, last, cl) \
- if (chain) { \
- *last = cl; \
- } else { \
- chain = cl; \
- } \
- last = &cl->next
-
-
ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in);
ngx_int_t ngx_chain_writer(void *ctx, ngx_chain_t *in);
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index 437d7a2..653ff48 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -8,6 +8,7 @@
#include <ngx_core.h>
+static ngx_int_t ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last);
static char *ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
@@ -53,13 +54,10 @@
char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
{
- int m, rc, found, valid;
char *rv;
- void *conf, **confp;
ngx_fd_t fd;
- ngx_str_t *name;
+ ngx_int_t rc;
ngx_conf_file_t *prev;
- ngx_command_t *cmd;
#if (NGX_SUPPRESS_WARN)
fd = NGX_INVALID_FILE;
@@ -78,7 +76,9 @@
}
prev = cf->conf_file;
- if (!(cf->conf_file = ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)))) {
+
+ cf->conf_file = ngx_palloc(cf->pool, sizeof(ngx_conf_file_t));
+ if (cf->conf_file == NULL) {
return NGX_CONF_ERROR;
}
@@ -130,194 +130,30 @@
rv = (*cf->handler)(cf, NULL, cf->handler_conf);
if (rv == NGX_CONF_OK) {
continue;
+ }
- } else if (rv == NGX_CONF_ERROR) {
- rc = NGX_ERROR;
- break;
-
- } else {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "%s in %s:%d",
- rv,
- cf->conf_file->file.name.data,
- cf->conf_file->line);
+ if (rv == NGX_CONF_ERROR) {
rc = NGX_ERROR;
break;
}
- }
- name = (ngx_str_t *) cf->args->elts;
- found = 0;
-
- for (m = 0; rc != NGX_ERROR && !found && ngx_modules[m]; m++) {
-
- /* look up the directive in the appropriate modules */
-
- if (ngx_modules[m]->type != NGX_CONF_MODULE
- && ngx_modules[m]->type != cf->module_type)
- {
- continue;
- }
-
- cmd = ngx_modules[m]->commands;
- if (cmd == NULL) {
- continue;
- }
-
- while (cmd->name.len) {
- if (name->len == cmd->name.len
- && ngx_strcmp(name->data, cmd->name.data) == 0)
- {
-
- found = 1;
-
- /* is the directive's location right ? */
-
- if ((cmd->type & cf->cmd_type) == 0) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "directive \"%s\" in %s:%d "
- "is not allowed here",
- name->data,
- cf->conf_file->file.name.data,
- cf->conf_file->line);
- rc = NGX_ERROR;
- break;
- }
-
- if (!(cmd->type & NGX_CONF_BLOCK) && rc != NGX_OK)
- {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "directive \"%s\" in %s:%d "
- "is not terminated by \";\"",
- name->data,
- cf->conf_file->file.name.data,
- cf->conf_file->line);
- rc = NGX_ERROR;
- break;
- }
-
- if ((cmd->type & NGX_CONF_BLOCK)
- && rc != NGX_CONF_BLOCK_START)
- {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "directive \"%s\" in %s:%d "
- "has not the opening \"{\"",
- name->data,
- cf->conf_file->file.name.data,
- cf->conf_file->line);
- rc = NGX_ERROR;
- break;
- }
-
- /* is the directive's argument count right ? */
-
- if (cmd->type & NGX_CONF_ANY) {
- valid = 1;
-
- } else if (cmd->type & NGX_CONF_FLAG) {
-
- if (cf->args->nelts == 2) {
- valid = 1;
- } else {
- valid = 0;
- }
-
- } else if (cmd->type & NGX_CONF_1MORE) {
-
- if (cf->args->nelts > 1) {
- valid = 1;
- } else {
- valid = 0;
- }
-
- } else if (cmd->type & NGX_CONF_2MORE) {
-
- if (cf->args->nelts > 2) {
- valid = 1;
- } else {
- valid = 0;
- }
-
- } else if (cf->args->nelts <= 10
- && (cmd->type
- & argument_number[cf->args->nelts - 1]))
- {
- valid = 1;
-
- } else {
- valid = 0;
- }
-
- if (!valid) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "invalid number arguments in "
- "directive \"%s\" in %s:%d",
- name->data,
- cf->conf_file->file.name.data,
- cf->conf_file->line);
- rc = NGX_ERROR;
- break;
- }
-
- /* set up the directive's configuration context */
-
- conf = NULL;
-
- if (cmd->type & NGX_DIRECT_CONF) {
- conf = ((void **) cf->ctx)[ngx_modules[m]->index];
-
- } else if (cmd->type & NGX_MAIN_CONF) {
- conf = &(((void **) cf->ctx)[ngx_modules[m]->index]);
-
- } else if (cf->ctx) {
- confp = *(void **) ((char *) cf->ctx + cmd->conf);
-
- if (confp) {
- conf = confp[ngx_modules[m]->ctx_index];
- }
- }
-
- rv = cmd->set(cf, cmd, conf);
-
- if (rv == NGX_CONF_OK) {
- break;
-
- } else if (rv == NGX_CONF_ERROR) {
- rc = NGX_ERROR;
- break;
-
- } else {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "the \"%s\" directive %s in %s:%d",
- name->data, rv,
- cf->conf_file->file.name.data,
- cf->conf_file->line);
-
- rc = NGX_ERROR;
- break;
- }
- }
-
- cmd++;
- }
- }
-
- if (!found) {
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "unknown directive \"%s\" in %s:%d",
- name->data,
- cf->conf_file->file.name.data,
- cf->conf_file->line);
-
+ "%s in %s:%d",
+ rv, cf->conf_file->file.name.data,
+ cf->conf_file->line);
rc = NGX_ERROR;
break;
}
+
+ rc = ngx_conf_handler(cf, rc);
+
if (rc == NGX_ERROR) {
break;
}
}
+
if (filename) {
cf->conf_file = prev;
@@ -337,6 +173,164 @@
}
+static ngx_int_t ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last)
+{
+ char *rv;
+ void *conf, **confp;
+ ngx_uint_t i, valid;
+ ngx_str_t *name;
+ ngx_command_t *cmd;
+
+ name = cf->args->elts;
+
+ for (i = 0; ngx_modules[i]; i++) {
+
+ /* look up the directive in the appropriate modules */
+
+ if (ngx_modules[i]->type != NGX_CONF_MODULE
+ && ngx_modules[i]->type != cf->module_type)
+ {
+ continue;
+ }
+
+ cmd = ngx_modules[i]->commands;
+ if (cmd == NULL) {
+ continue;
+ }
+
+ while (cmd->name.len) {
+
+ if (name->len == cmd->name.len
+ && ngx_strcmp(name->data, cmd->name.data) == 0)
+ {
+ /* is the directive's location right ? */
+
+ if (!(cmd->type & cf->cmd_type)) {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "directive \"%s\" in %s:%d "
+ "is not allowed here",
+ name->data, cf->conf_file->file.name.data,
+ cf->conf_file->line);
+ return NGX_ERROR;
+ }
+
+ if (!(cmd->type & NGX_CONF_BLOCK) && last != NGX_OK) {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "directive \"%s\" in %s:%d "
+ "is not terminated by \";\"",
+ name->data, cf->conf_file->file.name.data,
+ cf->conf_file->line);
+ return NGX_ERROR;
+ }
+
+ if ((cmd->type & NGX_CONF_BLOCK)
+ && last != NGX_CONF_BLOCK_START)
+ {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "directive \"%s\" in %s:%d "
+ "has not the opening \"{\"",
+ name->data, cf->conf_file->file.name.data,
+ cf->conf_file->line);
+ return NGX_ERROR;
+ }
+
+ /* is the directive's argument count right ? */
+
+ if (cmd->type & NGX_CONF_ANY) {
+ valid = 1;
+
+ } else if (cmd->type & NGX_CONF_FLAG) {
+
+ if (cf->args->nelts == 2) {
+ valid = 1;
+ } else {
+ valid = 0;
+ }
+
+ } else if (cmd->type & NGX_CONF_1MORE) {
+
+ if (cf->args->nelts > 1) {
+ valid = 1;
+ } else {
+ valid = 0;
+ }
+
+ } else if (cmd->type & NGX_CONF_2MORE) {
+
+ if (cf->args->nelts > 2) {
+ valid = 1;
+ } else {
+ valid = 0;
+ }
+
+ } else if (cf->args->nelts <= 10
+ && (cmd->type
+ & argument_number[cf->args->nelts - 1]))
+ {
+ valid = 1;
+
+ } else {
+ valid = 0;
+ }
+
+ if (!valid) {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "invalid number arguments in "
+ "directive \"%s\" in %s:%d",
+ name->data, cf->conf_file->file.name.data,
+ cf->conf_file->line);
+ return NGX_ERROR;
+ }
+
+ /* set up the directive's configuration context */
+
+ conf = NULL;
+
+ if (cmd->type & NGX_DIRECT_CONF) {
+ conf = ((void **) cf->ctx)[ngx_modules[i]->index];
+
+ } else if (cmd->type & NGX_MAIN_CONF) {
+ conf = &(((void **) cf->ctx)[ngx_modules[i]->index]);
+
+ } else if (cf->ctx) {
+ confp = *(void **) ((char *) cf->ctx + cmd->conf);
+
+ if (confp) {
+ conf = confp[ngx_modules[i]->ctx_index];
+ }
+ }
+
+ rv = cmd->set(cf, cmd, conf);
+
+ if (rv == NGX_CONF_OK) {
+ return NGX_OK;
+ }
+
+ if (rv == NGX_CONF_ERROR) {
+ return NGX_ERROR;
+ }
+
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "the \"%s\" directive %s in %s:%d",
+ name->data, rv, cf->conf_file->file.name.data,
+ cf->conf_file->line);
+
+ return NGX_ERROR;
+ }
+
+ cmd++;
+ }
+ }
+
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "unknown directive \"%s\" in %s:%d",
+ name->data, cf->conf_file->file.name.data,
+ cf->conf_file->line);
+
+ return NGX_ERROR;
+}
+
+
static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf)
{
u_char *start, ch, *src, *dst;
@@ -523,11 +517,13 @@
}
if (found) {
- if (!(word = ngx_push_array(cf->args))) {
+ word = ngx_array_push(cf->args);
+ if (word == NULL) {
return NGX_ERROR;
}
- if (!(word->data = ngx_palloc(cf->pool, b->pos - start + 1))) {
+ word->data = ngx_palloc(cf->pool, b->pos - start + 1);
+ if (word->data == NULL) {
return NGX_ERROR;
}
@@ -623,7 +619,8 @@
name->len = cycle->root.len + old.len;
if (cycle->connections) {
- if (!(name->data = ngx_palloc(cycle->pool, name->len + 1))) {
+ name->data = ngx_palloc(cycle->pool, name->len + 1);
+ if (name->data == NULL) {
return NGX_ERROR;
}
@@ -631,7 +628,8 @@
/* the init_cycle */
- if (!(name->data = ngx_alloc(name->len + 1, cycle->log))) {
+ name->data = ngx_alloc(name->len + 1, cycle->log);
+ if (name->data == NULL) {
return NGX_ERROR;
}
}
@@ -686,7 +684,8 @@
}
}
- if (!(file = ngx_list_push(&cycle->open_files))) {
+ file = ngx_list_push(&cycle->open_files);
+ if (file == NULL) {
return NULL;
}
diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c
index e8f06fd..4268157 100644
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -20,13 +20,15 @@
ngx_listening_t *ls;
struct sockaddr_in *sin;
- if (!(ls = ngx_array_push(&cf->cycle->listening))) {
+ ls = ngx_array_push(&cf->cycle->listening);
+ if (ls == NULL) {
return NULL;
}
ngx_memzero(ls, sizeof(ngx_listening_t));
- if (!(sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)))) {
+ sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in));
+ if (sin == NULL) {
return NULL;
}
@@ -46,7 +48,6 @@
ls->addr_text.len = ngx_sprintf(ls->addr_text.data + len, ":%d", port)
- ls->addr_text.data;
-
ls->fd = (ngx_socket_t) -1;
ls->family = AF_INET;
ls->type = SOCK_STREAM;
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index ad9049e..51864e3 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -54,15 +54,18 @@
log = old_cycle->log;
- if (!(pool = ngx_create_pool(16 * 1024, log))) {
+ pool = ngx_create_pool(16 * 1024, log);
+ if (pool == NULL) {
return NULL;
}
pool->log = log;
- if (!(cycle = ngx_pcalloc(pool, sizeof(ngx_cycle_t)))) {
+ cycle = ngx_pcalloc(pool, sizeof(ngx_cycle_t));
+ if (cycle == NULL) {
ngx_destroy_pool(pool);
return NULL;
}
+
cycle->pool = pool;
cycle->log = log;
cycle->old_cycle = old_cycle;
@@ -72,10 +75,13 @@
n = old_cycle->pathes.nelts ? old_cycle->pathes.nelts : 10;
- if (!(cycle->pathes.elts = ngx_pcalloc(pool, n * sizeof(ngx_path_t *)))) {
+
+ cycle->pathes.elts = ngx_pcalloc(pool, n * sizeof(ngx_path_t *));
+ if (cycle->pathes.elts == NULL) {
ngx_destroy_pool(pool);
return NULL;
}
+
cycle->pathes.nelts = 0;
cycle->pathes.size = sizeof(ngx_path_t *);
cycle->pathes.nalloc = n;
@@ -100,7 +106,8 @@
}
- if (!(cycle->new_log = ngx_log_create_errlog(cycle, NULL))) {
+ cycle->new_log = ngx_log_create_errlog(cycle, NULL);
+ if (cycle->new_log == NULL) {
ngx_destroy_pool(pool);
return NULL;
}
@@ -109,11 +116,13 @@
n = old_cycle->listening.nelts ? old_cycle->listening.nelts : 10;
+
cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t));
if (cycle->listening.elts == NULL) {
ngx_destroy_pool(pool);
return NULL;
}
+
cycle->listening.nelts = 0;
cycle->listening.size = sizeof(ngx_listening_t);
cycle->listening.nalloc = n;
@@ -147,7 +156,7 @@
ngx_memzero(&conf, sizeof(ngx_conf_t));
/* STUB: init array ? */
- conf.args = ngx_create_array(pool, 10, sizeof(ngx_str_t));
+ conf.args = ngx_array_create(pool, 10, sizeof(ngx_str_t));
if (conf.args == NULL) {
ngx_destroy_pool(pool);
return NULL;
@@ -516,7 +525,7 @@
ngx_temp_pool->log = cycle->log;
- old = ngx_push_array(&ngx_old_cycles);
+ old = ngx_array_push(&ngx_old_cycles);
if (old == NULL) {
exit(1);
}
@@ -562,7 +571,7 @@
{
ngx_uint_t trunc;
size_t len;
- u_char *name, pid[NGX_INT64_LEN];
+ u_char pid[NGX_INT64_LEN];
ngx_file_t file;
ngx_core_conf_t *ccf, *old_ccf;
diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c
index 561f080..6fe04e7 100644
--- a/src/core/ngx_file.c
+++ b/src/core/ngx_file.c
@@ -43,7 +43,8 @@
file->name.len = path->name.len + 1 + path->len + NGX_ATOMIC_T_LEN;
- if (!(file->name.data = ngx_palloc(pool, file->name.len + 1))) {
+ file->name.data = ngx_palloc(pool, file->name.len + 1);
+ if (file->name.data == NULL) {
return NGX_ERROR;
}
@@ -203,7 +204,8 @@
return "is duplicate";
}
- if (!(path = ngx_pcalloc(cf->pool, sizeof(ngx_path_t)))) {
+ path = ngx_pcalloc(cf->pool, sizeof(ngx_path_t));
+ if (path == NULL) {
return NGX_CONF_ERROR;
}
@@ -292,7 +294,8 @@
}
}
- if (!(p = ngx_array_push(&cf->cycle->pathes))) {
+ p = ngx_array_push(&cf->cycle->pathes);
+ if (p == NULL) {
return NGX_ERROR;
}
diff --git a/src/core/ngx_file.h b/src/core/ngx_file.h
index c9063c5..2bda858 100644
--- a/src/core/ngx_file.h
+++ b/src/core/ngx_file.h
@@ -70,7 +70,8 @@
#define ngx_conf_merge_path_value(curr, prev, path, l1, l2, l3, clean, cf) \
if (curr == NULL) { \
if (prev == NULL) { \
- if (!(curr = ngx_palloc(cf->pool, sizeof(ngx_path_t)))) { \
+ curr = ngx_palloc(cf->pool, sizeof(ngx_path_t)); \
+ if (curr == NULL) { \
return NGX_CONF_ERROR; \
} \
\
diff --git a/src/core/ngx_garbage_collector.c b/src/core/ngx_garbage_collector.c
index ba7d733..07a3f7f 100644
--- a/src/core/ngx_garbage_collector.c
+++ b/src/core/ngx_garbage_collector.c
@@ -77,7 +77,8 @@
buf.len = dname->len + 1 + len + NGX_DIR_MASK_LEN;
- if (!(buf.data = ngx_alloc(buf.len + 1, ctx->log))) {
+ buf.data = ngx_alloc(buf.len + 1, ctx->log);
+ if (buf.data == NULL) {
return NGX_ABORT;
}
}
diff --git a/src/core/ngx_inet.c b/src/core/ngx_inet.c
index a30ff03..6cad053 100644
--- a/src/core/ngx_inet.c
+++ b/src/core/ngx_inet.c
@@ -244,7 +244,8 @@
u->port = u->default_port_value;
- if (!(u->port_text.data = ngx_palloc(cf->pool, sizeof("65536") - 1))) {
+ u->port_text.data = ngx_palloc(cf->pool, sizeof("65536") - 1);
+ if (u->port_text.data == NULL) {
return NULL;
}
@@ -271,7 +272,8 @@
u->port = htons(u->port);
- if (!(host = ngx_palloc(cf->pool, u->host.len + 1))) {
+ host = ngx_palloc(cf->pool, u->host.len + 1);
+ if (host == NULL) {
return NULL;
}
@@ -297,7 +299,6 @@
peers = ngx_pcalloc(cf->pool,
sizeof(ngx_peers_t) + sizeof(ngx_peer_t) * (i - 1));
-
if (peers == NULL) {
return NULL;
}
@@ -307,7 +308,8 @@
for (i = 0; h->h_addr_list[i] != NULL; i++) {
- if (!(sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)))) {
+ sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in));
+ if (sin == NULL) {
return NULL;
}
@@ -320,7 +322,8 @@
len = INET_ADDRSTRLEN - 1 + 1 + u->port_text.len;
- if (!(peers->peer[i].name.data = ngx_palloc(cf->pool, len))) {
+ peers->peer[i].name.data = ngx_palloc(cf->pool, len);
+ if (peers->peer[i].name.data == NULL) {
return NULL;
}
@@ -345,11 +348,13 @@
/* MP: ngx_shared_palloc() */
- if (!(peers = ngx_pcalloc(cf->pool, sizeof(ngx_peers_t)))) {
+ peers = ngx_pcalloc(cf->pool, sizeof(ngx_peers_t));
+ if (peers == NULL) {
return NULL;
}
- if (!(sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)))) {
+ sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in));
+ if (sin == NULL) {
return NULL;
}
@@ -366,7 +371,8 @@
peers->peer[0].name.len = len;
- if (!(peers->peer[0].name.data = ngx_palloc(cf->pool, len))) {
+ peers->peer[0].name.data = ngx_palloc(cf->pool, len);
+ if (peers->peer[0].name.data == NULL) {
return NULL;
}
diff --git a/src/core/ngx_list.c b/src/core/ngx_list.c
index 236eff4..c082afa 100644
--- a/src/core/ngx_list.c
+++ b/src/core/ngx_list.c
@@ -19,11 +19,13 @@
/* the last part is full, allocate a new list part */
- if (!(last = ngx_palloc(l->pool, sizeof(ngx_list_part_t)))) {
+ last = ngx_palloc(l->pool, sizeof(ngx_list_part_t));
+ if (last == NULL) {
return NULL;
}
- if (!(last->elts = ngx_palloc(l->pool, l->nalloc * l->size))) {
+ last->elts = ngx_palloc(l->pool, l->nalloc * l->size);
+ if (last->elts == NULL) {
return NULL;
}
diff --git a/src/core/ngx_list.h b/src/core/ngx_list.h
index 2dd8ab3..c030cf2 100644
--- a/src/core/ngx_list.h
+++ b/src/core/ngx_list.h
@@ -30,10 +30,12 @@
} ngx_list_t;
-static ngx_inline ngx_int_t ngx_list_init(ngx_list_t *list, ngx_pool_t *pool,
- ngx_uint_t n, size_t size)
+static ngx_inline
+ngx_int_t ngx_list_init(ngx_list_t *list, ngx_pool_t *pool, ngx_uint_t n,
+ size_t size)
{
- if (!(list->part.elts = ngx_palloc(pool, n * size))) {
+ list->part.elts = ngx_palloc(pool, n * size);
+ if (list->part.elts == NULL) {
return NGX_ERROR;
}
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index 5d937f2..adccd5e 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -253,11 +253,13 @@
name = NULL;
}
- if (!(log = ngx_pcalloc(cycle->pool, sizeof(ngx_log_t)))) {
+ log = ngx_pcalloc(cycle->pool, sizeof(ngx_log_t));
+ if (log == NULL) {
return NULL;
}
- if (!(log->file = ngx_conf_open_file(cycle, name))) {
+ log->file = ngx_conf_open_file(cycle, name);
+ if (log->file == NULL) {
return NULL;
}
diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c
index 5f6970f..313557d 100644
--- a/src/core/ngx_output_chain.c
+++ b/src/core/ngx_output_chain.c
@@ -155,7 +155,8 @@
}
}
- if (!(ctx->buf = ngx_create_temp_buf(ctx->pool, size))) {
+ ctx->buf = ngx_create_temp_buf(ctx->pool, size);
+ if (ctx->buf == NULL) {
return NGX_ERROR;
}
@@ -186,9 +187,11 @@
ctx->in = ctx->in->next;
}
- if (!(cl = ngx_alloc_chain_link(ctx->pool))) {
+ cl = ngx_alloc_chain_link(ctx->pool);
+ if (cl == NULL) {
return NGX_ERROR;
}
+
cl->buf = ctx->buf;
cl->next = NULL;
*last_out = cl;
@@ -269,7 +272,8 @@
while (in) {
- if (!(cl = ngx_alloc_chain_link(pool))) {
+ cl = ngx_alloc_chain_link(pool);
+ if (cl == NULL) {
return NGX_ERROR;
}
@@ -281,7 +285,8 @@
&& buf->file_pos < NGX_SENDFILE_LIMIT
&& buf->file_last > NGX_SENDFILE_LIMIT)
{
- if (!(b = ngx_calloc_buf(pool))) {
+ b = ngx_calloc_buf(pool);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -431,9 +436,11 @@
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0,
"chain writer buf size: %uz", ngx_buf_size(in->buf));
- if (!(cl = ngx_alloc_chain_link(ctx->pool))) {
+ cl = ngx_alloc_chain_link(ctx->pool);
+ if (cl == NULL) {
return NGX_ERROR;
}
+
cl->buf = in->buf;
cl->next = NULL;
*ctx->last = cl;
diff --git a/src/core/ngx_palloc.c b/src/core/ngx_palloc.c
index fc6f36e..8faf9a7 100644
--- a/src/core/ngx_palloc.c
+++ b/src/core/ngx_palloc.c
@@ -8,11 +8,13 @@
#include <ngx_core.h>
-ngx_pool_t *ngx_create_pool(size_t size, ngx_log_t *log)
+ngx_pool_t *
+ngx_create_pool(size_t size, ngx_log_t *log)
{
ngx_pool_t *p;
- if (!(p = ngx_alloc(size, log))) {
+ p = ngx_alloc(size, log);
+ if (p == NULL) {
return NULL;
}
@@ -26,7 +28,8 @@
}
-void ngx_destroy_pool(ngx_pool_t *pool)
+void
+ngx_destroy_pool(ngx_pool_t *pool)
{
ngx_pool_t *p, *n;
ngx_pool_large_t *l;
@@ -68,7 +71,8 @@
}
-void *ngx_palloc(ngx_pool_t *pool, size_t size)
+void *
+ngx_palloc(ngx_pool_t *pool, size_t size)
{
u_char *m;
ngx_pool_t *p, *n;
@@ -94,7 +98,8 @@
/* allocate a new pool block */
- if (!(n = ngx_create_pool((size_t) (p->end - (u_char *) p), p->log))) {
+ n = ngx_create_pool((size_t) (p->end - (u_char *) p), p->log);
+ if (n == NULL) {
return NULL;
}
@@ -125,7 +130,8 @@
}
if (large == NULL) {
- if (!(large = ngx_palloc(pool, sizeof(ngx_pool_large_t)))) {
+ large = ngx_palloc(pool, sizeof(ngx_pool_large_t));
+ if (large == NULL) {
return NULL;
}
@@ -133,11 +139,13 @@
}
#if 0
- if (!(p = ngx_memalign(ngx_pagesize, size, pool->log))) {
+ p = ngx_memalign(ngx_pagesize, size, pool->log);
+ if (p == NULL) {
return NULL;
}
#else
- if (!(p = ngx_alloc(size, pool->log))) {
+ p = ngx_alloc(size, pool->log);
+ if (p == NULL) {
return NULL;
}
#endif
@@ -155,7 +163,8 @@
}
-ngx_int_t ngx_pfree(ngx_pool_t *pool, void *p)
+ngx_int_t
+ngx_pfree(ngx_pool_t *pool, void *p)
{
ngx_pool_large_t *l;
@@ -174,7 +183,8 @@
}
-void *ngx_pcalloc(ngx_pool_t *pool, size_t size)
+void *
+ngx_pcalloc(ngx_pool_t *pool, size_t size)
{
void *p;
@@ -188,7 +198,8 @@
#if 0
-static void *ngx_get_cached_block(size_t size)
+static void *
+ngx_get_cached_block(size_t size)
{
void *p;
ngx_cached_block_slot_t *slot;
diff --git a/src/core/ngx_palloc.h b/src/core/ngx_palloc.h
index 71be742..b310082 100644
--- a/src/core/ngx_palloc.h
+++ b/src/core/ngx_palloc.h
@@ -21,8 +21,6 @@
#define NGX_DEFAULT_POOL_SIZE (16 * 1024)
-#define ngx_test_null(p, alloc, rc) if ((p = alloc) == NULL) { return rc; }
-
typedef struct ngx_pool_large_s ngx_pool_large_t;
diff --git a/src/core/ngx_radix_tree.c b/src/core/ngx_radix_tree.c
index f8deb21..f82a5e5 100644
--- a/src/core/ngx_radix_tree.c
+++ b/src/core/ngx_radix_tree.c
@@ -17,7 +17,8 @@
uint32_t key, mask, inc;
ngx_radix_tree_t *tree;
- if (!(tree = ngx_palloc(pool, sizeof(ngx_radix_tree_t)))) {
+ tree = ngx_palloc(pool, sizeof(ngx_radix_tree_t));
+ if (tree == NULL) {
return NULL;
}
@@ -26,7 +27,8 @@
tree->start = NULL;
tree->size = 0;
- if (!(tree->root = ngx_radix_alloc(tree))) {
+ tree->root = ngx_radix_alloc(tree);
+ if (tree->root == NULL) {
return NULL;
}
@@ -140,7 +142,8 @@
}
while (bit & mask) {
- if (!(next = ngx_radix_alloc(tree))) {
+ next = ngx_radix_alloc(tree);
+ if (next == NULL) {
return NGX_ERROR;
}
@@ -266,7 +269,8 @@
}
if (tree->size < sizeof(ngx_radix_node_t)) {
- if (!(tree->start = ngx_palloc(tree->pool, ngx_pagesize))) {
+ tree->start = ngx_palloc(tree->pool, ngx_pagesize);
+ if (tree->start == NULL) {
return NULL;
}
diff --git a/src/core/ngx_regex.c b/src/core/ngx_regex.c
index bb719a5..1257994 100644
--- a/src/core/ngx_regex.c
+++ b/src/core/ngx_regex.c
@@ -79,7 +79,7 @@
}
-ngx_uint_t ngx_regex_capture_count(ngx_regex_t *re)
+ngx_int_t ngx_regex_capture_count(ngx_regex_t *re)
{
int rc, n;
@@ -87,7 +87,11 @@
rc = pcre_fullinfo(re, NULL, PCRE_INFO_CAPTURECOUNT, &n);
- return (ngx_uint_t) n;
+ if (rc < 0) {
+ return (ngx_int_t) rc;
+ }
+
+ return (ngx_int_t) n;
}
diff --git a/src/core/ngx_regex.h b/src/core/ngx_regex.h
index ff07fc7..7eefdbe 100644
--- a/src/core/ngx_regex.h
+++ b/src/core/ngx_regex.h
@@ -23,11 +23,12 @@
void ngx_regex_init(void);
ngx_regex_t *ngx_regex_compile(ngx_str_t *pattern, ngx_int_t options,
ngx_pool_t *pool, ngx_str_t *err);
-ngx_uint_t ngx_regex_capture_count(ngx_regex_t *re);
+ngx_int_t ngx_regex_capture_count(ngx_regex_t *re);
ngx_int_t ngx_regex_exec(ngx_regex_t *re, ngx_str_t *s,
int *captures, ngx_int_t size);
-#define ngx_regex_exec_n "pcre_exec()"
+#define ngx_regex_exec_n "pcre_exec()"
+#define ngx_regex_capture_count_n "pcre_fullinfo()"
#endif /* _NGX_REGEX_H_INCLUDED_ */
diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c
index fdb59fd..a1f593f 100644
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -34,7 +34,8 @@
{
u_char *dst;
- if (!(dst = ngx_palloc(pool, src->len))) {
+ dst = ngx_palloc(pool, src->len);
+ if (dst == NULL) {
return NULL;
}
@@ -489,6 +490,84 @@
}
+ssize_t
+ngx_atosz(u_char *line, size_t n)
+{
+ ssize_t value;
+
+ if (n == 0) {
+ return NGX_ERROR;
+ }
+
+ for (value = 0; n--; line++) {
+ if (*line < '0' || *line > '9') {
+ return NGX_ERROR;
+ }
+
+ value = value * 10 + (*line - '0');
+ }
+
+ if (value < 0) {
+ return NGX_ERROR;
+
+ } else {
+ return value;
+ }
+}
+
+
+off_t
+ngx_atoof(u_char *line, size_t n)
+{
+ off_t value;
+
+ if (n == 0) {
+ return NGX_ERROR;
+ }
+
+ for (value = 0; n--; line++) {
+ if (*line < '0' || *line > '9') {
+ return NGX_ERROR;
+ }
+
+ value = value * 10 + (*line - '0');
+ }
+
+ if (value < 0) {
+ return NGX_ERROR;
+
+ } else {
+ return value;
+ }
+}
+
+
+time_t
+ngx_atotm(u_char *line, size_t n)
+{
+ time_t value;
+
+ if (n == 0) {
+ return NGX_ERROR;
+ }
+
+ for (value = 0; n--; line++) {
+ if (*line < '0' || *line > '9') {
+ return NGX_ERROR;
+ }
+
+ value = value * 10 + (*line - '0');
+ }
+
+ if (value < 0) {
+ return NGX_ERROR;
+
+ } else {
+ return value;
+ }
+}
+
+
ngx_int_t
ngx_hextoi(u_char *line, size_t n)
{
diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h
index 52bac6a..25b06b3 100644
--- a/src/core/ngx_string.h
+++ b/src/core/ngx_string.h
@@ -23,6 +23,7 @@
#define ngx_tolower(c) (u_char) ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c)
+#define ngx_toupper(c) (u_char) ((c >= 'a' && c <= 'z') ? (c & ~0x20) : c)
#if (NGX_WIN32)
@@ -81,6 +82,9 @@
ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n);
ngx_int_t ngx_atoi(u_char *line, size_t n);
+ssize_t ngx_atosz(u_char *line, size_t n);
+off_t ngx_atoof(u_char *line, size_t n);
+time_t ngx_atotm(u_char *line, size_t n);
ngx_int_t ngx_hextoi(u_char *line, size_t n);
void ngx_md5_text(u_char *text, u_char *md5);
diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c
index 4293289..e4fa69d 100644
--- a/src/core/ngx_times.c
+++ b/src/core/ngx_times.c
@@ -70,8 +70,8 @@
static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
-
-void ngx_time_init(void)
+void
+ngx_time_init(void)
{
struct timeval tv;
@@ -104,9 +104,12 @@
#if (NGX_THREADS)
-ngx_int_t ngx_time_mutex_init(ngx_log_t *log)
+ngx_int_t
+ngx_time_mutex_init(ngx_log_t *log)
{
- if (!(ngx_time_mutex = ngx_mutex_init(log, NGX_MUTEX_LIGHT))) {
+ ngx_time_mutex = ngx_mutex_init(log, NGX_MUTEX_LIGHT);
+
+ if (ngx_time_mutex == NULL) {
return NGX_ERROR;
}
@@ -116,7 +119,8 @@
#endif
-void ngx_time_update(time_t s)
+void
+ngx_time_update(time_t s)
{
u_char *p;
ngx_tm_t tm;
@@ -209,7 +213,8 @@
}
-u_char *ngx_http_time(u_char *buf, time_t t)
+u_char *
+ngx_http_time(u_char *buf, time_t t)
{
ngx_tm_t tm;
@@ -226,7 +231,8 @@
}
-u_char *ngx_http_cookie_time(u_char *buf, time_t t)
+u_char *
+ngx_http_cookie_time(u_char *buf, time_t t)
{
ngx_tm_t tm;
@@ -252,7 +258,8 @@
}
-void ngx_gmtime(time_t t, ngx_tm_t *tp)
+void
+ngx_gmtime(time_t t, ngx_tm_t *tp)
{
ngx_int_t sec, min, hour, mday, mon, year, wday, yday, days;
diff --git a/src/core/ngx_unix_domain.c b/src/core/ngx_unix_domain.c
index 436777f..3df83bb 100644
--- a/src/core/ngx_unix_domain.c
+++ b/src/core/ngx_unix_domain.c
@@ -59,11 +59,13 @@
/* MP: ngx_shared_palloc() */
- if (!(peers = ngx_pcalloc(cf->pool, sizeof(ngx_peers_t)))) {
+ peers = ngx_pcalloc(cf->pool, sizeof(ngx_peers_t));
+ if (peers == NULL) {
return NULL;
}
- if (!(sun = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_un)))) {
+ sun = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_un));
+ if (sun == NULL) {
return NULL;
}