diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/nginx.c | 44 | ||||
-rw-r--r-- | src/core/ngx_conf_file.c | 79 | ||||
-rw-r--r-- | src/core/ngx_conf_file.h | 7 | ||||
-rw-r--r-- | src/core/ngx_core.h | 2 | ||||
-rw-r--r-- | src/core/ngx_string.h | 2 |
5 files changed, 79 insertions, 55 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c index e1894f4cf..820d6e3f4 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -1,30 +1,16 @@ -#include <nginx.h> #include <ngx_config.h> - #include <ngx_core.h> -#include <ngx_connection.h> -#include <ngx_os_init.h> -#include <ngx_server.h> -#include <ngx_listen.h> -#include <ngx_conf_file.h> -/* STUB */ -#include <ngx_http.h> -/* */ +#include <ngx_listen.h> +#include <nginx.h> -static void ngx_set_signals(ngx_log_t *log); -static void ngx_open_listening_sockets(ngx_log_t *log); -/* STUB */ -int ngx_max_conn = 512; -u_int ngx_sendfile_flags; +static int ngx_open_listening_sockets(ngx_log_t *log); -ngx_server_t ngx_server; -/* */ ngx_log_t ngx_log; ngx_pool_t *ngx_pool; @@ -34,8 +20,8 @@ void ****ngx_conf_ctx; ngx_os_io_t ngx_io; -int ngx_max_module; -void *ctx_conf; +int ngx_max_module; +void *ctx_conf; int ngx_connection_counter; @@ -109,7 +95,9 @@ int main(int argc, char *const *argv) } } - ngx_open_listening_sockets(&ngx_log); + if (ngx_open_listening_sockets(&ngx_log) == NGX_ERROR) { + return 1; + } /* TODO: daemon, once only */ @@ -127,7 +115,7 @@ int main(int argc, char *const *argv) } -static void ngx_open_listening_sockets(ngx_log_t *log) +static int ngx_open_listening_sockets(ngx_log_t *log) { int times, failed, reuseaddr, i; ngx_err_t err; @@ -161,7 +149,7 @@ static void ngx_open_listening_sockets(ngx_log_t *log) if (s == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, ngx_socket_n " %s falied", ls[i].addr_text.data); - exit(1); + return NGX_ERROR; } if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, @@ -169,7 +157,7 @@ static void ngx_open_listening_sockets(ngx_log_t *log) ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, "setsockopt(SO_REUSEADDR) %s failed", ls[i].addr_text.data); - exit(1); + return NGX_ERROR; } /* TODO: close on exit */ @@ -179,7 +167,7 @@ static void ngx_open_listening_sockets(ngx_log_t *log) ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, ngx_nonblocking_n " %s failed", ls[i].addr_text.data); - exit(1); + return NGX_ERROR; } } @@ -189,7 +177,7 @@ static void ngx_open_listening_sockets(ngx_log_t *log) "bind() to %s failed", ls[i].addr_text.data); if (err != NGX_EADDRINUSE) - exit(1); + return NGX_ERROR; if (ngx_close_socket(s) == -1) ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, @@ -203,7 +191,7 @@ static void ngx_open_listening_sockets(ngx_log_t *log) if (listen(s, ls[i].backlog) == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, "listen() to %s failed", ls[i].addr_text.data); - exit(1); + return NGX_ERROR; } /* TODO: deferred accept */ @@ -222,6 +210,8 @@ static void ngx_open_listening_sockets(ngx_log_t *log) if (failed) { ngx_log_error(NGX_LOG_EMERG, log, 0, "can not bind(), exiting"); - exit(1); + return NGX_ERROR; } + + return NGX_OK; } diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c index 527cbdfe0..54d4f387b 100644 --- a/src/core/ngx_conf_file.c +++ b/src/core/ngx_conf_file.c @@ -20,7 +20,7 @@ static int ngx_conf_read_token(ngx_conf_t *cf); char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) { - int m, rc, found; + int m, rc, found, valid; char *rv; void *conf, **confp; ngx_str_t *name; @@ -139,15 +139,33 @@ ngx_log_debug(cf->log, "command '%s'" _ cmd->name.data); /* is the directive's argument count right ? */ - if (!(cmd->type & NGX_CONF_ANY) - && ((cmd->type & NGX_CONF_FLAG && cf->args->nelts != 2) - || (!(cmd->type & NGX_CONF_FLAG) - && !(cmd->type - & argument_number[cf->args->nelts - 1]) - ) - ) - ) - { + if (cmd->type & argument_number[cf->args->nelts - 1]) { + valid = 1; + + } else if (cmd->type & NGX_CONF_ANY1) { + + if (cf->args->nelts != 1) { + valid = 1; + } else { + valid = 0; + } + + } else if (cmd->type & NGX_CONF_FLAG) { + + if (cf->args->nelts == 2) { + valid = 1; + } else { + valid = 0; + } + + } else if (cmd->type & NGX_CONF_ANY) { + 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", @@ -441,10 +459,12 @@ ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data); char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { + char *p = conf; + int flag; ngx_str_t *value; - if (*(int *) (conf + cmd->offset) != NGX_CONF_UNSET) { + if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) { return "is duplicate"; } @@ -457,10 +477,13 @@ char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) flag = 0; } else { - return "must be \"on\" or \"off\""; + ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1, + "invalid value \"%s\", it must be \"on\" or \"off\"", + value[1].data); + return ngx_conf_errstr; } - *(int *) (conf + cmd->offset) = flag; + *(int *) (p + cmd->offset) = flag; return NGX_CONF_OK; } @@ -468,9 +491,11 @@ char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) char *ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { + char *p = conf; + ngx_str_t *field, *value; - field = (ngx_str_t *) (conf + cmd->offset); + field = (ngx_str_t *) (p + cmd->offset); if (field->data) { return "is duplicate"; @@ -487,10 +512,12 @@ char *ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { + char *p = conf; + int num, len; ngx_str_t *value; - if (*(int *) (conf + cmd->offset) != NGX_CONF_UNSET) { + if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) { return "is duplicate"; } @@ -500,10 +527,10 @@ char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) num = ngx_atoi(value[1].data, len); if (num == NGX_ERROR) { - return "invalid value"; + return "invalid number"; } - *(int *) (conf + cmd->offset) = num; + *(int *) (p + cmd->offset) = num; return NGX_CONF_OK; } @@ -511,11 +538,13 @@ char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { + char *p = conf; + int size, len, scale; char last; ngx_str_t *value; - if (*(int *) (conf + cmd->offset) != NGX_CONF_UNSET) { + if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) { return "is duplicate"; } @@ -548,7 +577,7 @@ char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) size *= scale; - *(int *) (conf + cmd->offset) = size; + *(int *) (p + cmd->offset) = size; return NGX_CONF_OK; } @@ -556,12 +585,14 @@ char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { + char *p = conf; + int size, total, len, scale; u_int max, i; char last, *start; ngx_str_t *value; - if (*(int *) (conf + cmd->offset) != NGX_CONF_UNSET) { + if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) { return "is duplicate"; } @@ -643,7 +674,7 @@ char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) start = &value[1].data[i + 1]; } - *(int *) (conf + cmd->offset) = total; + *(int *) (p + cmd->offset) = total; return NGX_CONF_OK; } @@ -651,12 +682,14 @@ char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) char *ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { + char *p = conf; + int size, total, len, scale; u_int max, i; char last, *start; ngx_str_t *value; - if (*(int *) (conf + cmd->offset) != NGX_CONF_UNSET) { + if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) { return "is duplicate"; } @@ -750,7 +783,7 @@ char *ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) start = &value[1].data[i + 1]; } - *(int *) (conf + cmd->offset) = total; + *(int *) (p + cmd->offset) = total; return NGX_CONF_OK; } diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h index 3624d5df0..b3f1d6304 100644 --- a/src/core/ngx_conf_file.h +++ b/src/core/ngx_conf_file.h @@ -24,8 +24,9 @@ #define NGX_CONF_TAKE2 0x00000004 #define NGX_CONF_ARGS_NUMBER 0x0000ffff #define NGX_CONF_ANY 0x00010000 -#define NGX_CONF_BLOCK 0x00020000 -#define NGX_CONF_FLAG 0x00040000 +#define NGX_CONF_ANY1 0x00020000 +#define NGX_CONF_BLOCK 0x00040000 +#define NGX_CONF_FLAG 0x00080000 #define NGX_MAIN_CONF 0x01000000 @@ -83,7 +84,7 @@ typedef struct { typedef char *(*ngx_conf_handler_pt)(ngx_conf_t *cf, - ngx_command_t *dummy, char *conf); + ngx_command_t *dummy, void *conf); struct ngx_conf_s { diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h index aabbbc7f7..e8b311700 100644 --- a/src/core/ngx_core.h +++ b/src/core/ngx_core.h @@ -43,7 +43,7 @@ typedef struct ngx_event_s ngx_event_t; -#define NGX_MAXHOSTNAMELEN 32 +#define NGX_MAXHOSTNAMELEN 64 /* #define NGX_MAXHOSTNAMELEN MAXHOSTNAMELEN */ diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h index 9f72f17b0..daf5f00b7 100644 --- a/src/core/ngx_string.h +++ b/src/core/ngx_string.h @@ -46,7 +46,7 @@ typedef struct { #endif #define ngx_memcpy(dst, src, n) memcpy(dst, src, n) -#define ngx_cpymem(dst, src, n) memcpy(dst, src, n) + n +#define ngx_cpymem(dst, src, n) ((char *) memcpy(dst, src, n)) + n char *ngx_cpystrn(char *dst, char *src, size_t n); int ngx_rstrncmp(char *s1, char *s2, size_t n); |