diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/nginx.c | 3 | ||||
-rw-r--r-- | src/core/ngx_config_file.c | 117 | ||||
-rw-r--r-- | src/core/ngx_config_file.h | 46 | ||||
-rw-r--r-- | src/core/ngx_modules.c | 23 | ||||
-rw-r--r-- | src/core/ngx_string.h | 5 |
5 files changed, 149 insertions, 45 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c index 3d2d4403f..bab1fa738 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -56,12 +56,13 @@ int main(int argc, char *const *argv) /* TODO: read config */ -#if 0 +#if 1 ngx_memzero(&conf, sizeof(ngx_conf_t)); ngx_test_null(conf.args, ngx_create_array(ngx_pool, 10, sizeof(ngx_str_t)), 1); conf.pool = ngx_pool; conf.log = &ngx_log; + conf.modules = ngx_http_modules; conf_file.len = sizeof("nginx.conf") - 1; conf_file.data = "nginx.conf"; diff --git a/src/core/ngx_config_file.c b/src/core/ngx_config_file.c index 0feb21c45..b1582d1d2 100644 --- a/src/core/ngx_config_file.c +++ b/src/core/ngx_config_file.c @@ -12,14 +12,18 @@ static int argument_number[] = { NGX_CONF_TAKE2 }; -#if 1 +static int ngx_conf_read_token(ngx_conf_t *cf); +static ngx_command_t *ngx_conf_find_token(ngx_conf_t *cf, + ngx_http_module_t **modules); + int ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) { - int rc; - char *error; - ngx_fd_t fd; + int rc; + char *error; + ngx_fd_t fd; ngx_conf_file_t *prev; + ngx_command_t *cmd; if (filename) { @@ -56,16 +60,12 @@ int ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) for ( ;; ) { rc = ngx_conf_read_token(cf); - /* ??? NGX_OK, NGX_ERROR, NGX_CONF_FILE_DONE, NGX_CONF_BLOCK_DONE */ + /* NGX_OK, NGX_ERROR, NGX_CONF_FILE_DONE, NGX_CONF_BLOCK_DONE */ - if (rc != NGX_OK) { + if (rc == NGX_ERROR || rc == NGX_CONF_FILE_DONE) { return rc; } - /* ???? - "listen address:port;" - "location /images/ {" */ - if (cf->handler) { if ((*cf->handler)(cf) == NGX_ERROR) { @@ -75,6 +75,8 @@ int ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) continue; } + cmd = ngx_conf_find_token(cf); + #if 0 cmd = ngx_conf_find_token(cf); if (cmd == NULL) { @@ -164,14 +166,13 @@ int ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) return NGX_OK; } -#endif - -#if 1 -int ngx_conf_read_token(ngx_conf_t *cf) +static int ngx_conf_read_token(ngx_conf_t *cf) { char *start, ch, *src, *dst; - int found, need_space, last_space, len, quoted, s_quoted, d_quoted; + int len; + int found, need_space, last_space, sharp_comment; + int quoted, s_quoted, d_quoted; ssize_t n; ngx_str_t *word; ngx_hunk_t *h; @@ -179,6 +180,7 @@ int ngx_conf_read_token(ngx_conf_t *cf) found = 0; need_space = 0; last_space = 1; + sharp_comment = 0; quoted = s_quoted = d_quoted = 0; cf->args->nelts = 0; @@ -192,7 +194,7 @@ ngx_log_debug(cf->log, "TOKEN START"); if (h->pos.mem >= h->last.mem) { if (cf->conf_file->file.offset >= ngx_file_size(cf->conf_file->file.info)) { - return NGX_FILE_DONE; + return NGX_CONF_FILE_DONE; } if (h->pos.mem - start) { @@ -223,6 +225,14 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _ if (ch == LF) { cf->conf_file->line++; + + if (sharp_comment) { + sharp_comment = 0; + } + } + + if (sharp_comment) { + continue; } if (quoted) { @@ -255,8 +265,31 @@ ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _ case ';': case '{': + if (cf->args->nelts == 0) { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "unexpected '%c' in %s:%d", + ch, cf->conf_file->file.name.data, + cf->conf_file->line); + return NGX_ERROR; + } + return NGX_OK; + case '}': + if (cf->args->nelts > 0) { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "unexpected '}' in %s:%d", + cf->conf_file->file.name.data, + cf->conf_file->line); + return NGX_ERROR; + } + + return NGX_CONF_BLOCK_DONE; + + case '#': + sharp_comment = 1; + continue; + case '\\': quoted = 1; last_space = 0; @@ -334,28 +367,60 @@ ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data); } } -#endif -char *ngx_conf_set_size_slot(char *conf, int offset, char *value) +static ngx_command_t *ngx_conf_find_token(ngx_conf_t *cf) { - int size; + int i; + ngx_command_t *cmd; - size = atoi(value); - if (size < 0) + for (i = 0; cf->modules[i]; i++) { + cmd = cf->modules[i]->commands; + if (cmd == NULL) { + continue; + } + + while (cmd->name) { + +ngx_log_debug(cf->log, "command '%s'" _ cmd->name); + + cmd++; + } + + } +} + + +char *ngx_conf_set_size_slot(ngx_conf_t *cf, char *conf) +{ + int size; + ngx_str_t *value; + + value = (ngx_str_t *) cf->args->elts; + + size = atoi(value.data); + if (size < 0) { return "value must be greater or equal to zero"; + } + + *(int *) (conf + cf->offset) = size; - *(int *) (conf + offset) = size; return NULL; } -char *ngx_conf_set_time_slot(char *conf, int offset, char *value) + +char *ngx_conf_set_time_slot(ngx_conf_t *cf, char *conf) { - int size; + int size; + ngx_str_t *value; + + value = (ngx_str_t *) cf->args->elts; - size = atoi(value); - if (size < 0) + size = atoi(value.data); + if (size < 0) { return "value must be greater or equal to zero"; + } *(int *) (conf + offset) = size; + return NULL; } diff --git a/src/core/ngx_config_file.h b/src/core/ngx_config_file.h index 7ba7621f8..a7eb47c1d 100644 --- a/src/core/ngx_config_file.h +++ b/src/core/ngx_config_file.h @@ -6,10 +6,12 @@ #include <ngx_files.h> #include <ngx_log.h> #include <ngx_file.h> +#include <ngx_string.h> #include <ngx_alloc.h> #include <ngx_hunk.h> #include <ngx_array.h> + #define NGX_CONF_NOARGS 1 #define NGX_CONF_TAKE1 2 #define NGX_CONF_TAKE2 4 @@ -19,8 +21,28 @@ #define NGX_CONF_UNSET -1 -#define NGX_BLOCK_DONE 1 -#define NGX_FILE_DONE 2 +#define NGX_CONF_BLOCK_DONE 1 +#define NGX_CONF_FILE_DONE 2 + + +typedef struct ngx_conf_s ngx_conf_t; + + +typedef struct { + ngx_str_t name; + char *(*set)(ngx_conf_t *cf); + int offset; + int zone; + int type; +} ngx_command_t; + + +typedef struct { + void *ctx; + ngx_command_t *commands; + int type; + int (*init_module)(ngx_pool_t *p); +} ngx_module_t; typedef struct { @@ -29,7 +51,7 @@ typedef struct { int line; } ngx_conf_file_t; -typedef struct ngx_conf_s ngx_conf_t; + struct ngx_conf_s { char *name; ngx_array_t *args; @@ -38,27 +60,17 @@ struct ngx_conf_s { ngx_conf_file_t *conf_file; ngx_log_t *log; + ngx_module_t *modules; + void *ctx; int (*handler)(ngx_conf_t *cf); }; - -typedef struct { - char *name; - char *(*set)(); - int offset; - int zone; - int type; - char *description; -} ngx_command_t; - - -int ngx_conf_read_token(ngx_conf_t *cf); +int ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename); -char *ngx_conf_set_size_slot(char *conf, int offset, char *value); -char *ngx_conf_set_time_slot(char *conf, int offset, char *value); +char *ngx_conf_set_size_slot(ngx_conf_t *cf); #endif _NGX_HTTP_CONFIG_FILE_H_INCLUDED_ diff --git a/src/core/ngx_modules.c b/src/core/ngx_modules.c new file mode 100644 index 000000000..5b814baf9 --- /dev/null +++ b/src/core/ngx_modules.c @@ -0,0 +1,23 @@ + +#include <ngx_http.h> + +extern ngx_http_module_t ngx_http_header_filter_module; + +extern ngx_http_module_t ngx_http_write_filter_module; +extern ngx_http_module_t ngx_http_output_filter_module; + +extern ngx_http_module_t ngx_http_core_module; +extern ngx_http_module_t ngx_http_index_module; + +ngx_http_module_t *ngx_http_modules[] = { + + &ngx_http_header_filter_module, + + &ngx_http_write_filter_module, + &ngx_http_output_filter_module, + + &ngx_http_index_module, + &ngx_http_core_module, + + NULL +}; diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h index ddfdaccee..3e28abb68 100644 --- a/src/core/ngx_string.h +++ b/src/core/ngx_string.h @@ -10,8 +10,11 @@ typedef struct { char *data; } ngx_str_t; -#if (WIN32) +#define ngx_string(str) { sizeof(str) - 1, str } + + +#if (WIN32) #define ngx_memzero ZeroMemory |