diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/ngx_conf_file.c | 30 | ||||
-rw-r--r-- | src/core/ngx_conf_file.h | 12 | ||||
-rw-r--r-- | src/core/ngx_file.c | 41 | ||||
-rw-r--r-- | src/core/ngx_file.h | 19 | ||||
-rw-r--r-- | src/core/ngx_hunk.c | 20 | ||||
-rw-r--r-- | src/core/ngx_hunk.h | 21 | ||||
-rw-r--r-- | src/core/ngx_listen.c | 44 | ||||
-rw-r--r-- | src/core/ngx_listen.h | 54 | ||||
-rw-r--r-- | src/core/ngx_write_chain.c | 50 |
9 files changed, 113 insertions, 178 deletions
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c index c26aa1774..70da2dcbe 100644 --- a/src/core/ngx_conf_file.c +++ b/src/core/ngx_conf_file.c @@ -6,10 +6,20 @@ #define MAX_CONF_ERRSTR 256 +/* Ten fixed arguments */ + static int argument_number[] = { NGX_CONF_NOARGS, NGX_CONF_TAKE1, - NGX_CONF_TAKE2 + NGX_CONF_TAKE2, + NGX_CONF_TAKE3, + NGX_CONF_TAKE4, + NGX_CONF_TAKE5, + NGX_CONF_TAKE6, + NGX_CONF_TAKE7, + NGX_CONF_TAKE8, + NGX_CONF_TAKE9, + NGX_CONF_TAKE10 }; static int ngx_conf_read_token(ngx_conf_t *cf); @@ -146,26 +156,29 @@ ngx_log_debug(cf->log, "command '%s'" _ cmd->name.data); /* is the directive's argument count right ? */ - if (cmd->type & argument_number[cf->args->nelts - 1]) { + if (cmd->type & NGX_CONF_ANY) { valid = 1; - } else if (cmd->type & NGX_CONF_1MORE) { + } else if (cmd->type & NGX_CONF_FLAG) { - if (cf->args->nelts != 1) { + if (cf->args->nelts == 2) { valid = 1; } else { valid = 0; } - } else if (cmd->type & NGX_CONF_FLAG) { + } else if (cmd->type & NGX_CONF_1MORE) { - if (cf->args->nelts == 2) { + if (cf->args->nelts != 1) { valid = 1; } else { valid = 0; } - } else if (cmd->type & NGX_CONF_ANY) { + } else if (cf->args->nelts <= 10 + && (cmd->type + & argument_number[cf->args->nelts - 1])) + { valid = 1; } else { @@ -573,8 +586,7 @@ char *ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) value = (ngx_str_t *) cf->args->elts; - field->len = value[1].len; - field->data = value[1].data; + *field = value[1]; return NGX_CONF_OK; } diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h index 3164c6c92..66ca2a912 100644 --- a/src/core/ngx_conf_file.h +++ b/src/core/ngx_conf_file.h @@ -15,6 +15,18 @@ #define NGX_CONF_NOARGS 0x00000001 #define NGX_CONF_TAKE1 0x00000002 #define NGX_CONF_TAKE2 0x00000004 +#define NGX_CONF_TAKE3 0x00000008 +#define NGX_CONF_TAKE4 0x00000010 +#define NGX_CONF_TAKE5 0x00000020 +#define NGX_CONF_TAKE6 0x00000040 +#define NGX_CONF_TAKE7 0x00000080 +#define NGX_CONF_TAKE8 0x00000100 +#define NGX_CONF_TAKE9 0x00000200 +#define NGX_CONF_TAKE10 0x00000400 + +#define NGX_CONF_TAKE1234 (NGX_CONF_TAKE1|NGX_CONF_TAKE2|NGX_CONF_TAKE3 \ + |NGX_CONF_TAKE4) + #define NGX_CONF_ARGS_NUMBER 0x0000ffff #define NGX_CONF_ANY 0x00010000 #define NGX_CONF_1MORE 0x00020000 diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c index 455b785fd..538adff1d 100644 --- a/src/core/ngx_file.c +++ b/src/core/ngx_file.c @@ -164,3 +164,44 @@ int ngx_next_temp_number(int collision) return ngx_temp_number++; } + + +char *ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +{ + char *p = conf; + + int i, n; + ngx_str_t *value; + ngx_path_t *path, **pp; + + pp = (ngx_path_t **) (p + cmd->offset); + + if (*pp) { + return "is duplicate"; + } + + ngx_test_null(path, ngx_pcalloc(cf->pool, sizeof(ngx_path_t)), NULL); + + *pp = path; + + value = (ngx_str_t *) cf->args->elts; + + path->name = value[1]; + + path->len = 0; + + for (i = 0, n = 2; n < cf->args->nelts; i++, n++) { + path->level[i] = ngx_atoi(value[n].data, value[n].len); + if (path->level[i] == NGX_ERROR || path->level[i] == 0) { + return "invalid value"; + } + + path->len += path->level[i] + 1; + } + + while (i < 3) { + path->level[i++] = 0; + } + + return NULL; +} diff --git a/src/core/ngx_file.h b/src/core/ngx_file.h index 6f521c251..ef3f78327 100644 --- a/src/core/ngx_file.h +++ b/src/core/ngx_file.h @@ -34,5 +34,24 @@ int ngx_create_path(ngx_file_t *file, ngx_path_t *path); void ngx_init_temp_number(); int ngx_next_temp_number(int collision); +char *ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); + + +#define ngx_conf_merge_path_value(conf, prev, path, l1, l2, l3, pool) \ + if (conf == NULL) { \ + if (prev == NULL) { \ + ngx_test_null(conf, ngx_palloc(pool, sizeof(ngx_path_t)), NULL); \ + conf->name.len = sizeof(path) - 1; \ + conf->name.data = path; \ + conf->level[0] = l1; \ + conf->level[1] = l2; \ + conf->level[2] = l3; \ + conf->len = l1 + l2 + l3 + l1 ? 1:0 + l2 ? 1:0 + l3 ? 1:0; \ + } else { \ + conf = prev; \ + } \ + } + + #endif /* _NGX_FILE_H_INCLUDED_ */ diff --git a/src/core/ngx_hunk.c b/src/core/ngx_hunk.c index cd218307d..100bc62af 100644 --- a/src/core/ngx_hunk.c +++ b/src/core/ngx_hunk.c @@ -99,26 +99,26 @@ ngx_hunk_t *ngx_create_hunk_after(ngx_pool_t *pool, ngx_hunk_t *hunk, int size) } -int ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **ch, ngx_chain_t *in) +int ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in) { - ngx_chain_t *ce, **le; + ngx_chain_t *cl, **ll; - le = ch; + ll = chain; - for (ce = *ch; ce; ce = ce->next) { - le = &ce->next; + for (cl = *chain; cl; cl = cl->next) { + ll = &cl->next; } while (in) { - ngx_test_null(ce, ngx_alloc_chain_entry(pool), NGX_ERROR); + ngx_test_null(cl, ngx_alloc_chain_link(pool), NGX_ERROR); - ce->hunk = in->hunk; - *le = ce; - le = &ce->next; + cl->hunk = in->hunk; + *ll = cl; + ll = &cl->next; in = in->next; } - *le = NULL; + *ll = NULL; return NGX_OK; } diff --git a/src/core/ngx_hunk.h b/src/core/ngx_hunk.h index 940241be7..abbdcfe48 100644 --- a/src/core/ngx_hunk.h +++ b/src/core/ngx_hunk.h @@ -99,31 +99,30 @@ ngx_hunk_t *ngx_create_temp_hunk(ngx_pool_t *pool, int size, #define ngx_alloc_hunk(pool) ngx_palloc(pool, sizeof(ngx_hunk_t)) #define ngx_calloc_hunk(pool) ngx_pcalloc(pool, sizeof(ngx_hunk_t)) -#define ngx_alloc_chain_entry(pool) ngx_palloc(pool, sizeof(ngx_chain_t)) -#define ngx_add_hunk_to_chain(chain, h, pool, error) \ +#define ngx_alloc_chain_link(pool) ngx_palloc(pool, sizeof(ngx_chain_t)) + + +#define ngx_alloc_link_and_set_hunk(chain, h, pool, error) \ do { \ - ngx_test_null(chain, ngx_alloc_chain_entry(pool), error); \ + ngx_test_null(chain, ngx_alloc_chain_link(pool), error); \ chain->hunk = h; \ chain->next = NULL; \ } while (0); -#define ngx_alloc_ce_and_set_hunk ngx_add_hunk_to_chain - -#define ngx_chain_add_ce(chain, last, ce) \ +#define ngx_chain_add_link(chain, last, cl) \ if (chain) { \ - *last = ce; \ + *last = cl; \ } else { \ - chain = ce; \ + chain = cl; \ } \ - last = &ce->next + last = &cl->next -int ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **ch, ngx_chain_t *in); +int ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in); void ngx_chain_update_chains(ngx_chain_t **free, ngx_chain_t **busy, ngx_chain_t **out, ngx_hunk_tag_t tag); - #endif /* _NGX_HUNK_H_INCLUDED_ */ diff --git a/src/core/ngx_listen.c b/src/core/ngx_listen.c deleted file mode 100644 index 873b18de0..000000000 --- a/src/core/ngx_listen.c +++ /dev/null @@ -1,44 +0,0 @@ - -#include <ngx_config.h> -#include <ngx_types.h> -#include <ngx_errno.h> -#include <ngx_log.h> -#include <ngx_listen.h> - -ngx_socket_t ngx_listen(struct sockaddr *addr, int backlog, - ngx_log_t *log, char *addr_text) -{ - ngx_socket_t s; - int reuseaddr = 1; -#if (WIN32) - unsigned long nb = 1; -#endif - - if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) - ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, "socket failed"); - - if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, - (const void *) &reuseaddr, sizeof(int)) == -1) - ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, - "ngx_listen: setsockopt (SO_REUSEADDR) failed"); - -#if (WIN32) - if (ioctlsocket(s, FIONBIO, &nb) == -1) - ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, - "ngx_listen: ioctlsocket (FIONBIO) failed"); -#else - if (fcntl(s, F_SETFL, O_NONBLOCK) == -1) - ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, - "ngx_listen: fcntl (O_NONBLOCK) failed"); -#endif - - if (bind(s, (struct sockaddr *) addr, sizeof(struct sockaddr_in)) == -1) - ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, - "ngx_listen: bind to %s failed", addr_text); - - if (listen(s, backlog) == -1) - ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, - "ngx_listen: listen to %s failed", addr_text); - - return s; -} diff --git a/src/core/ngx_listen.h b/src/core/ngx_listen.h deleted file mode 100644 index 1824ef17c..000000000 --- a/src/core/ngx_listen.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef _NGX_LISTEN_H_INCLUDED_ -#define _NGX_LISTEN_H_INCLUDED_ - - -#include <ngx_config.h> -#include <ngx_log.h> -#include <ngx_types.h> -#include <ngx_socket.h> -#include <ngx_connection.h> - -typedef struct { - ngx_socket_t fd; - - struct sockaddr *sockaddr; - socklen_t socklen; /* size of sockaddr */ - int addr; /* offset to address in sockaddr */ - int addr_text_max_len; - ngx_str_t addr_text; - - int family; - int type; - int protocol; - int flags; /* Winsock2 flags */ - - void (*handler)(ngx_connection_t *c); /* handler of accepted - connection */ - void *ctx; /* ngx_http_conf_ctx_t, for example */ - void *servers; /* array of ngx_http_in_addr_t, for example */ - - ngx_log_t *log; - int pool_size; - - int backlog; - time_t post_accept_timeout; /* should be here because - of the deferred accept */ - - unsigned bound:1; /* already bound */ - unsigned inherited:1; /* inherited from previous process */ - unsigned nonblocking_accept:1; - unsigned nonblocking:1; -#if 0 - unsigned overlapped:1; /* Winsock2 overlapped */ -#endif - unsigned shared:1; /* shared between threads or processes */ -#if (HAVE_DEFERRED_ACCEPT) - unsigned deferred_accept:1; -#endif -} ngx_listen_t; - - -extern ngx_array_t ngx_listening_sockets; - - -#endif /* _NGX_LISTEN_H_INCLUDED_ */ diff --git a/src/core/ngx_write_chain.c b/src/core/ngx_write_chain.c deleted file mode 100644 index 17af4039e..000000000 --- a/src/core/ngx_write_chain.c +++ /dev/null @@ -1,50 +0,0 @@ - -#include <ngx_config.h> - -#include <ngx_core.h> -#include <ngx_types.h> -#include <ngx_alloc.h> -#include <ngx_array.h> -#include <ngx_hunk.h> -#include <ngx_connection.h> - - -ngx_chain_t *(*ngx_write_chain_proc)(ngx_connection_t *c, ngx_chain_t *in); - - -ngx_chain_t *ngx_write_chain(ngx_connection_t *c, ngx_chain_t *in, off_t flush) -{ -#if (NGX_EVENT) - - return (*ngx_write_chain_proc)(c, in); - -#elif (NGX_EVENT_THREAD) - - off_t sent; - ngx_chain_t *rc; - - sent = flush - c->sent; - - do { - rc = (*ngx_write_chain_proc)(c, in); - - if (rc == NGX_CHAIN_ERROR && rc == NULL) { - return rc; - } - - } while (c->thread && flush > c->sent - sent); - -#else - - ngx_chain_t *rc; - - do { - - rc = (*ngx_write_chain_proc)(c, in); - - } while (rc != NGX_CHAIN_ERROR && rc != NULL); - - return rc; - -#endif -} |