diff options
author | Igor Sysoev <igor@sysoev.ru> | 2005-03-19 15:38:37 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2005-03-19 15:38:37 +0300 |
commit | c15717285d2157a603bb1b130b26d7baa549be7e (patch) | |
tree | 56dc8346b22bb2660eecd3bc086d263ac6d67326 /src/core | |
parent | e12fbfe82a176cd386cdcecfeabf43ac8fd870a4 (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/core')
-rw-r--r-- | src/core/nginx.c | 43 | ||||
-rw-r--r-- | src/core/nginx.h | 2 | ||||
-rw-r--r-- | src/core/ngx_array.c | 12 | ||||
-rw-r--r-- | src/core/ngx_array.h | 17 | ||||
-rw-r--r-- | src/core/ngx_buf.c | 21 | ||||
-rw-r--r-- | src/core/ngx_buf.h | 18 | ||||
-rw-r--r-- | src/core/ngx_conf_file.c | 323 | ||||
-rw-r--r-- | src/core/ngx_connection.c | 7 | ||||
-rw-r--r-- | src/core/ngx_cycle.c | 23 | ||||
-rw-r--r-- | src/core/ngx_file.c | 9 | ||||
-rw-r--r-- | src/core/ngx_file.h | 3 | ||||
-rw-r--r-- | src/core/ngx_garbage_collector.c | 3 | ||||
-rw-r--r-- | src/core/ngx_inet.c | 22 | ||||
-rw-r--r-- | src/core/ngx_list.c | 6 | ||||
-rw-r--r-- | src/core/ngx_list.h | 8 | ||||
-rw-r--r-- | src/core/ngx_log.c | 6 | ||||
-rw-r--r-- | src/core/ngx_output_chain.c | 17 | ||||
-rw-r--r-- | src/core/ngx_palloc.c | 33 | ||||
-rw-r--r-- | src/core/ngx_palloc.h | 2 | ||||
-rw-r--r-- | src/core/ngx_radix_tree.c | 12 | ||||
-rw-r--r-- | src/core/ngx_regex.c | 8 | ||||
-rw-r--r-- | src/core/ngx_regex.h | 5 | ||||
-rw-r--r-- | src/core/ngx_string.c | 81 | ||||
-rw-r--r-- | src/core/ngx_string.h | 4 | ||||
-rw-r--r-- | src/core/ngx_times.c | 23 | ||||
-rw-r--r-- | src/core/ngx_unix_domain.c | 6 |
26 files changed, 425 insertions, 289 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c index d6ee9f652..e2a35dc67 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -141,7 +141,8 @@ main(int argc, char *const *argv) ngx_pid = ngx_getpid(); - if (!(log = ngx_log_init())) { + log = ngx_log_init(); + if (log == NULL) { return 1; } @@ -155,7 +156,8 @@ main(int argc, char *const *argv) 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 @@ main(int argc, char *const *argv) 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 @@ ngx_add_inherited_sockets(ngx_cycle_t *cycle) 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 @@ ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv) 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_getopt(ngx_cycle_t *cycle, int argc, char *const *argv) static ngx_int_t ngx_save_argv(ngx_cycle_t *cycle, int argc, char *const *argv) { - size_t len; - ngx_int_t i; +#if (NGX_FREEBSD) ngx_os_argv = (char **) argv; - ngx_argc = argc; - -#if (NGX_FREEBSD) - ngx_argv = (char **) argv; #else + size_t len; + ngx_int_t i; + + ngx_os_argv = (char **) argv; + ngx_argc = argc; - 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_module_create_conf(ngx_cycle_t *cycle) { 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 @@ ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf) 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 5f76b9b01..54afca93a 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 82d5d1db8..b6167afc4 100644 --- a/src/core/ngx_array.c +++ b/src/core/ngx_array.c @@ -12,11 +12,13 @@ ngx_array_t *ngx_array_create(ngx_pool_t *p, ngx_uint_t n, size_t size) { 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 @@ void *ngx_array_push(ngx_array_t *a) } 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 @@ void *ngx_array_push_n(ngx_array_t *a, ngx_uint_t n) 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 d90cf76f0..5f97451aa 100644 --- a/src/core/ngx_array.h +++ b/src/core/ngx_array.h @@ -27,10 +27,11 @@ void *ngx_array_push(ngx_array_t *a); 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 @@ static ngx_inline ngx_int_t ngx_array_init(ngx_array_t *array, ngx_pool_t *pool, } -/* 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 97c94a363..2f0356ffd 100644 --- a/src/core/ngx_buf.c +++ b/src/core/ngx_buf.c @@ -13,11 +13,13 @@ ngx_create_temp_buf(ngx_pool_t *pool, size_t size) { 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_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs) 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 @@ ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs) 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 @@ ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in) } 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 d672cf485..721b9c2df 100644 --- a/src/core/ngx_buf.h +++ b/src/core/ngx_buf.h @@ -119,27 +119,9 @@ ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs); #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 437d7a283..653ff48b3 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 @@ static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf); 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 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) } 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,210 +130,204 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) 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; } + + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "%s in %s:%d", + rv, cf->conf_file->file.name.data, + cf->conf_file->line); + rc = NGX_ERROR; + break; } - name = (ngx_str_t *) cf->args->elts; - found = 0; - for (m = 0; rc != NGX_ERROR && !found && ngx_modules[m]; m++) { + rc = ngx_conf_handler(cf, rc); - /* look up the directive in the appropriate modules */ + if (rc == NGX_ERROR) { + break; + } + } - 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; - } + if (filename) { + cf->conf_file = prev; - while (cmd->name.len) { - if (name->len == cmd->name.len - && ngx_strcmp(name->data, cmd->name.data) == 0) - { + if (ngx_close_file(fd) == NGX_FILE_ERROR) { + ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, + ngx_close_file_n " %s failed", + cf->conf_file->file.name.data); + return NGX_CONF_ERROR; + } + } - found = 1; + if (rc == NGX_ERROR) { + return NGX_CONF_ERROR; + } - /* 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; - } + return NGX_CONF_OK; +} - 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; - } +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; - /* is the directive's argument count right ? */ + name = cf->args->elts; - if (cmd->type & NGX_CONF_ANY) { - valid = 1; + for (i = 0; ngx_modules[i]; i++) { - } else if (cmd->type & NGX_CONF_FLAG) { + /* look up the directive in the appropriate modules */ - if (cf->args->nelts == 2) { - valid = 1; - } else { - valid = 0; - } + if (ngx_modules[i]->type != NGX_CONF_MODULE + && ngx_modules[i]->type != cf->module_type) + { + continue; + } - } else if (cmd->type & NGX_CONF_1MORE) { + cmd = ngx_modules[i]->commands; + if (cmd == NULL) { + continue; + } - if (cf->args->nelts > 1) { - valid = 1; - } else { - valid = 0; - } + while (cmd->name.len) { - } else if (cmd->type & NGX_CONF_2MORE) { + if (name->len == cmd->name.len + && ngx_strcmp(name->data, cmd->name.data) == 0) + { + /* is the directive's location right ? */ - if (cf->args->nelts > 2) { - valid = 1; - } else { - valid = 0; - } + 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; + } - } else if (cf->args->nelts <= 10 - && (cmd->type - & argument_number[cf->args->nelts - 1])) - { - valid = 1; + 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; } - 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; + } else if (cmd->type & NGX_CONF_1MORE) { + + if (cf->args->nelts > 1) { + valid = 1; + } else { + valid = 0; } - /* set up the directive's configuration context */ + } else if (cmd->type & NGX_CONF_2MORE) { - conf = NULL; + if (cf->args->nelts > 2) { + valid = 1; + } else { + valid = 0; + } - if (cmd->type & NGX_DIRECT_CONF) { - conf = ((void **) cf->ctx)[ngx_modules[m]->index]; + } else if (cf->args->nelts <= 10 + && (cmd->type + & argument_number[cf->args->nelts - 1])) + { + valid = 1; + + } else { + valid = 0; + } - } else if (cmd->type & NGX_MAIN_CONF) { - conf = &(((void **) cf->ctx)[ngx_modules[m]->index]); + 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; + } - } else if (cf->ctx) { - confp = *(void **) ((char *) cf->ctx + cmd->conf); + /* set up the directive's configuration context */ - if (confp) { - conf = confp[ngx_modules[m]->ctx_index]; - } - } + conf = NULL; - rv = cmd->set(cf, cmd, conf); + if (cmd->type & NGX_DIRECT_CONF) { + conf = ((void **) cf->ctx)[ngx_modules[i]->index]; - if (rv == NGX_CONF_OK) { - break; + } else if (cmd->type & NGX_MAIN_CONF) { + conf = &(((void **) cf->ctx)[ngx_modules[i]->index]); - } else if (rv == NGX_CONF_ERROR) { - rc = NGX_ERROR; - break; + } else if (cf->ctx) { + confp = *(void **) ((char *) cf->ctx + cmd->conf); - } 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; + if (confp) { + conf = confp[ngx_modules[i]->ctx_index]; } } - cmd++; - } - } + rv = cmd->set(cf, cmd, conf); - 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); + if (rv == NGX_CONF_OK) { + return NGX_OK; + } - rc = NGX_ERROR; - break; - } + if (rv == NGX_CONF_ERROR) { + return NGX_ERROR; + } - if (rc == NGX_ERROR) { - break; - } - } + 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); - if (filename) { - cf->conf_file = prev; + return NGX_ERROR; + } - if (ngx_close_file(fd) == NGX_FILE_ERROR) { - ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, - ngx_close_file_n " %s failed", - cf->conf_file->file.name.data); - return NGX_CONF_ERROR; + cmd++; } } - if (rc == NGX_ERROR) { - return NGX_CONF_ERROR; - } + 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_CONF_OK; + return NGX_ERROR; } @@ -523,11 +517,13 @@ static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf) } 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 @@ ngx_int_t ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name) 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 @@ ngx_int_t ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name) /* 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 @@ ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name) } } - 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 e8f06fdfd..4268157bd 100644 --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c @@ -20,13 +20,15 @@ ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf, 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 @@ ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf, 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 ad9049e4e..51864e3f7 100644 --- a/src/core/ngx_cycle.c +++ b/src/core/ngx_cycle.c @@ -54,15 +54,18 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) 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 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) 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 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) } - 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 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) 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_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) 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_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle) 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_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle) { 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 561f080fd..6fe04e70d 100644 --- a/src/core/ngx_file.c +++ b/src/core/ngx_file.c @@ -43,7 +43,8 @@ ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path, ngx_pool_t *pool, 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 @@ ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 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 @@ ngx_add_path(ngx_conf_t *cf, ngx_path_t **slot) } } - 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 c9063c5b4..2bda85886 100644 --- a/src/core/ngx_file.h +++ b/src/core/ngx_file.h @@ -70,7 +70,8 @@ char *ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); #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 ba7d7336f..07a3f7fc5 100644 --- a/src/core/ngx_garbage_collector.c +++ b/src/core/ngx_garbage_collector.c @@ -77,7 +77,8 @@ ngx_int_t ngx_collect_garbage(ngx_gc_t *ctx, ngx_str_t *dname, ngx_int_t level) 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 a30ff035b..6cad053b7 100644 --- a/src/core/ngx_inet.c +++ b/src/core/ngx_inet.c @@ -244,7 +244,8 @@ ngx_peers_t *ngx_inet_upstream_parse(ngx_conf_t *cf, ngx_inet_upstream_t *u) 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 @@ ngx_peers_t *ngx_inet_upstream_parse(ngx_conf_t *cf, ngx_inet_upstream_t *u) 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 @@ ngx_peers_t *ngx_inet_upstream_parse(ngx_conf_t *cf, ngx_inet_upstream_t *u) peers = ngx_pcalloc(cf->pool, sizeof(ngx_peers_t) + sizeof(ngx_peer_t) * (i - 1)); - if (peers == NULL) { return NULL; } @@ -307,7 +308,8 @@ ngx_peers_t *ngx_inet_upstream_parse(ngx_conf_t *cf, ngx_inet_upstream_t *u) 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 @@ ngx_peers_t *ngx_inet_upstream_parse(ngx_conf_t *cf, ngx_inet_upstream_t *u) 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 @@ ngx_peers_t *ngx_inet_upstream_parse(ngx_conf_t *cf, ngx_inet_upstream_t *u) /* 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 @@ ngx_peers_t *ngx_inet_upstream_parse(ngx_conf_t *cf, ngx_inet_upstream_t *u) 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 236eff4f9..c082afa37 100644 --- a/src/core/ngx_list.c +++ b/src/core/ngx_list.c @@ -19,11 +19,13 @@ void *ngx_list_push(ngx_list_t *l) /* 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 2dd8ab37a..c030cf293 100644 --- a/src/core/ngx_list.h +++ b/src/core/ngx_list.h @@ -30,10 +30,12 @@ typedef struct { } 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 5d937f226..adccd5e33 100644 --- a/src/core/ngx_log.c +++ b/src/core/ngx_log.c @@ -253,11 +253,13 @@ ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args) 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 5f6970f80..313557d8e 100644 --- a/src/core/ngx_output_chain.c +++ b/src/core/ngx_output_chain.c @@ -155,7 +155,8 @@ ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in) } } - 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 @@ ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in) 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 @@ ngx_output_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, 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 @@ ngx_output_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, && 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_chain_writer(void *data, ngx_chain_t *in) 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 fc6f36e83..8faf9a77e 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 @@ ngx_pool_t *ngx_create_pool(size_t size, ngx_log_t *log) } -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_destroy_pool(ngx_pool_t *pool) } -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 @@ void *ngx_palloc(ngx_pool_t *pool, size_t size) /* 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 @@ void *ngx_palloc(ngx_pool_t *pool, size_t size) } 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 @@ void *ngx_palloc(ngx_pool_t *pool, size_t size) } #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 @@ void *ngx_palloc(ngx_pool_t *pool, size_t size) } -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 @@ ngx_int_t ngx_pfree(ngx_pool_t *pool, void *p) } -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 @@ void *ngx_pcalloc(ngx_pool_t *pool, size_t size) #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 71be7424e..b31008288 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 f8deb21f0..f82a5e5b7 100644 --- a/src/core/ngx_radix_tree.c +++ b/src/core/ngx_radix_tree.c @@ -17,7 +17,8 @@ ngx_radix_tree_create(ngx_pool_t *pool, ngx_int_t preallocate) 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 @@ ngx_radix_tree_create(ngx_pool_t *pool, ngx_int_t preallocate) 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 @@ ngx_radix32tree_insert(ngx_radix_tree_t *tree, uint32_t key, uint32_t mask, } while (bit & mask) { - if (!(next = ngx_radix_alloc(tree))) { + next = ngx_radix_alloc(tree); + if (next == NULL) { return NGX_ERROR; } @@ -266,7 +269,8 @@ ngx_radix_alloc(ngx_radix_tree_t *tree) } 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 bb719a52f..12579946b 100644 --- a/src/core/ngx_regex.c +++ b/src/core/ngx_regex.c @@ -79,7 +79,7 @@ ngx_regex_t *ngx_regex_compile(ngx_str_t *pattern, ngx_int_t options, } -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 @@ ngx_uint_t ngx_regex_capture_count(ngx_regex_t *re) 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 ff07fc7fb..7eefdbe49 100644 --- a/src/core/ngx_regex.h +++ b/src/core/ngx_regex.h @@ -23,11 +23,12 @@ typedef pcre ngx_regex_t; 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 fdb59fd9a..a1f593f96 100644 --- a/src/core/ngx_string.c +++ b/src/core/ngx_string.c @@ -34,7 +34,8 @@ ngx_pstrdup(ngx_pool_t *pool, ngx_str_t *src) { 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 @@ ngx_atoi(u_char *line, size_t n) } +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 52bac6a09..25b06b3f6 100644 --- a/src/core/ngx_string.h +++ b/src/core/ngx_string.h @@ -23,6 +23,7 @@ typedef struct { #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_rstrncmp(u_char *s1, u_char *s2, size_t n); 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 42932892e..e4fa69d7f 100644 --- a/src/core/ngx_times.c +++ b/src/core/ngx_times.c @@ -70,8 +70,8 @@ static char *week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; 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 @@ void ngx_time_init(void) #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 @@ ngx_int_t ngx_time_mutex_init(ngx_log_t *log) #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 @@ void ngx_time_update(time_t s) } -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_time(u_char *buf, time_t t) } -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 @@ u_char *ngx_http_cookie_time(u_char *buf, time_t t) } -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 436777f8f..3df83bb3e 100644 --- a/src/core/ngx_unix_domain.c +++ b/src/core/ngx_unix_domain.c @@ -59,11 +59,13 @@ ngx_peers_t *ngx_unix_upstream_parse(ngx_conf_t *cf, /* 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; } |