Mercurial > hg > nginx
changeset 43:53cd05892261
nginx-0.0.1-2002-12-27-19:22:50 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 27 Dec 2002 16:22:50 +0000 |
parents | cd035a94e0b6 |
children | 0e81ac0bb3e2 |
files | src/core/nginx.c src/core/ngx_conf_file.c src/core/ngx_conf_file.h src/core/ngx_config_file.c src/core/ngx_config_file.h src/core/ngx_modules.c src/http/modules/ngx_http_index_handler.c src/http/ngx_http.h src/http/ngx_http_config.c src/http/ngx_http_core.c src/http/ngx_http_header_filter.c src/http/ngx_http_output_filter.c src/http/ngx_http_output_filter.h src/http/ngx_http_write_filter.c |
diffstat | 14 files changed, 551 insertions(+), 519 deletions(-) [+] |
line wrap: on
line diff
--- a/src/core/nginx.c Fri Dec 27 07:27:47 2002 +0000 +++ b/src/core/nginx.c Fri Dec 27 16:22:50 2002 +0000 @@ -2,6 +2,7 @@ #include <nginx.h> #include <ngx_config.h> + #include <ngx_string.h> #include <ngx_errno.h> #include <ngx_time.h> @@ -12,6 +13,7 @@ #include <ngx_server.h> #include <ngx_connection.h> #include <ngx_listen.h> +#include <ngx_conf_file.h> /* STUB */ #include <ngx_http.h> @@ -62,6 +64,7 @@ ngx_create_array(ngx_pool, 10, sizeof(ngx_str_t)), 1); conf.pool = ngx_pool; conf.log = &ngx_log; + conf.type = NGX_CORE_MODULE_TYPE; conf_file.len = sizeof("nginx.conf") - 1; conf_file.data = "nginx.conf";
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/core/ngx_conf_file.c Fri Dec 27 16:22:50 2002 +0000 @@ -0,0 +1,427 @@ + +#include <ngx_config.h> +#include <ngx_core.h> +#include <ngx_conf_file.h> + + +static int argument_number[] = { + NGX_CONF_NOARGS, + NGX_CONF_TAKE1, + NGX_CONF_TAKE2 +}; + +static int ngx_conf_read_token(ngx_conf_t *cf); + + +int ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) +{ + int rc, i; + char *error; + ngx_str_t *name; + ngx_fd_t fd; + ngx_conf_file_t *prev; + ngx_command_t *cmd; + + if (filename) { + + fd = ngx_open_file(filename->data, NGX_FILE_RDONLY); + if (fd == NGX_INVALID_FILE) { + ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, + "ngx_conf_file: " + ngx_open_file_n " %s failed", filename->data); + return NGX_ERROR; + } + + prev = cf->conf_file; + ngx_test_null(cf->conf_file, + ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)), + NGX_ERROR); + + if (ngx_stat_fd(fd, &cf->conf_file->file.info) == -1) { + ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, + "ngx_conf_file: " + ngx_stat_fd_n " %s failed", filename->data); + } + + ngx_test_null(cf->conf_file->hunk, + ngx_create_temp_hunk(cf->pool, 1024, 0, 0), + NGX_ERROR); + + cf->conf_file->file.fd = fd; + cf->conf_file->file.name.len = filename->len; + cf->conf_file->file.name.data = filename->data; + cf->conf_file->file.log = cf->log;; + cf->conf_file->line = 1; + } + + for ( ;; ) { + rc = ngx_conf_read_token(cf); + + /* NGX_OK, NGX_ERROR, NGX_CONF_FILE_DONE, NGX_CONF_BLOCK_DONE */ + + if (rc == NGX_ERROR || rc == NGX_CONF_FILE_DONE) { + return rc; + } + + if (cf->handler) { + + if ((*cf->handler)(cf) == NGX_ERROR) { + return NGX_ERROR; + } + + continue; + } + + name = (ngx_str_t *) cf->args->elts; + + for (i = 0; ngx_modules[i]; i++) { + if (ngx_modules[i]->type != NULL + && ngx_modules[i]->type != cf->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) + { + +ngx_log_debug(cf->log, "command '%s'" _ cmd->name.data); + + cmd->set(cf, cmd, NULL); + } + + cmd++; + } + } + +#if 0 + cmd = ngx_conf_find_token(cf); + if (cmd == NULL) { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "unknown directive \"%s\" in %s:%d", + cf->name, cf->file->name, cf->file->line); + return NGX_ERROR; + } + + if (cmd->type & argument_number[cf->args->nelts - 1]) { + error = cmd->set(cf, cmd->offset, cf->args); + + if (error) { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "%s in directive \"%s\" in %s:%d", + error, cf->name, cf->file->name, cf->file->line); + return NGX_ERROR; + } + } +#endif + +#if 0 + if (cmd->type == NGX_CONF_CONTAINER) { + ngx_conf_parse(cf, cmd->container, NULL); + + } else if (cmd->type == NGX_CONF_FLAG) { + + if (cf->args->nelts != 1) { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "invalid number of arguments " + "in directive \"%s\" in %s:%d", + cf->name, cf->file->name, cf->file->line); + return NGX_ERROR; + } + + if (ngx_strcasecmp(cf->args->elts[0], "on") == 0) { + flag = 1; + + } else if (ngx_strcasecmp(cf->args->elts[0], "off") == 0) { + flag = 0; + + } else { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "invalid flag in directive \"%s\" in %s:%d", + cf->name, cf->file->name, cf->file->line); + return NGX_ERROR; + } + + rv = cmd->set(cf, cmd->offset, flag); + if (rv) { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "%s in directive \"%s\" in %s:%d", + rv, cf->name, cf->file->name, cf->file->line); + return NGX_ERROR; + } + + } else if (cmd->type & argument_number[args->nelts]) { + rv = cmd->set(cf, cmd->offset, cf->args); + if (rv) { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "%s in directive \"%s\" in %s:%d", + rv, cf->name, cf->file->name, cf->file->line); + return NGX_ERROR; + } + + } else { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "invalid number of arguments " + "in directive \"%s\" in %s:%d", + cf->name, cf->file->name, cf->file->line); + return NGX_ERROR; + } +#endif + } + + if (filename) { + cf->conf_file = prev; + + if (ngx_close_file(fd) == NGX_FILE_ERROR) { + ngx_log_error(NGX_LOG_ERR, cf->log, ngx_errno, + ngx_close_file_n " %s failed", + cf->conf_file->file.name.data); + return NGX_ERROR; + } + } + + return NGX_OK; +} + + +static int ngx_conf_read_token(ngx_conf_t *cf) +{ + char *start, ch, *src, *dst; + 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; + + found = 0; + need_space = 0; + last_space = 1; + sharp_comment = 0; + quoted = s_quoted = d_quoted = 0; + + cf->args->nelts = 0; + h = cf->conf_file->hunk; + start = h->pos.mem; + +ngx_log_debug(cf->log, "TOKEN START"); + + for ( ;; ) { + + if (h->pos.mem >= h->last.mem) { + if (cf->conf_file->file.offset + >= ngx_file_size(cf->conf_file->file.info)) { + return NGX_CONF_FILE_DONE; + } + + if (h->pos.mem - start) { + ngx_memcpy(h->start, start, h->pos.mem - start); + } + + n = ngx_read_file(&cf->conf_file->file, + h->start + (h->pos.mem - start), + h->end - (h->start + (h->pos.mem - start)), + cf->conf_file->file.offset); + + if (n == NGX_ERROR) { + return NGX_ERROR; + } + + h->pos.mem = h->start + (h->pos.mem - start); + start = h->start; + h->last.mem = h->pos.mem + n; + } + + ch = *h->pos.mem++; + +#if 0 +ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _ + last_space _ need_space _ + quoted _ s_quoted _ d_quoted _ ch); +#endif + + if (ch == LF) { + cf->conf_file->line++; + + if (sharp_comment) { + sharp_comment = 0; + } + } + + if (sharp_comment) { + continue; + } + + if (quoted) { + quoted = 0; + continue; + } + + if (need_space) { + if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) { + last_space = 1; + need_space = 0; + continue; + } + + if (ch == ';' || ch == '{') { + return NGX_OK; + } + + return NGX_ERROR; + } + + if (last_space) { + if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) { + continue; + } + + start = h->pos.mem - 1; + + switch (ch) { + + 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; + continue; + + case '"': + start++; + d_quoted = 1; + last_space = 0; + continue; + + case '\'': + start++; + s_quoted = 1; + last_space = 0; + continue; + + default: + last_space = 0; + } + + } else { + if (ch == '\\') { + quoted = 1; + continue; + } + + if (d_quoted) { + if (ch == '"') { + d_quoted = 0; + need_space = 1; + found = 1; + } + + } else if (s_quoted) { + if (ch == '\'') { + s_quoted = 0; + need_space = 1; + found = 1; + } + + } else if (ch == ' ' || ch == '\t' || ch == CR || ch == LF + || ch == ';' || ch == '{') { + last_space = 1; + found = 1; + } + + if (found) { + ngx_test_null(word, ngx_push_array(cf->args), NGX_ERROR); + ngx_test_null(word->data, + ngx_palloc(cf->pool, h->pos.mem - start + 1), + NGX_ERROR); + + for (dst = word->data, src = start, len = 0; + src < h->pos.mem - 1; + len++) + { + if (*src == '\\') { + src++; + } + *dst++ = *src++; + } + *dst = '\0'; + word->len = len; + +ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data); + + if (ch == ';' || ch == '{') { + return NGX_OK; + } + + found = 0; + } + } + } +} + + +char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) +{ + int size; + ngx_str_t *value; + + value = (ngx_str_t *) cf->args->elts; + + size = atoi(value[1].data); + if (size < 0) { + return "value must be greater or equal to zero"; + } + + *(int *) (conf + cmd->offset) = size; + + return NULL; +} + + +char *ngx_conf_set_time_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) +{ + int size; + ngx_str_t *value; + + value = (ngx_str_t *) cf->args->elts; + + size = atoi(value[1].data); + if (size < 0) { + return "value must be greater or equal to zero"; + } + + *(int *) (conf + cmd->offset) = size; + + return NULL; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/core/ngx_conf_file.h Fri Dec 27 16:22:50 2002 +0000 @@ -0,0 +1,87 @@ +#ifndef _NGX_HTTP_CONF_FILE_H_INCLUDED_ +#define _NGX_HTTP_CONF_FILE_H_INCLUDED_ + + +#include <ngx_config.h> +#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 +#define NGX_CONF_ARGS_NUMBER 0x0ffff +#define NGX_CONF_ANY 0x10000 +#define NGX_CONF_BLOCK 0x20000 + + +#define NGX_CONF_UNSET -1 + + +#define NGX_CONF_ERROR (char *) -1 + +#define NGX_CONF_BLOCK_DONE 1 +#define NGX_CONF_FILE_DONE 2 + + +#define NGX_CORE_MODULE_TYPE 0x45524f43 /* "CORE" */ + + +typedef struct ngx_conf_s ngx_conf_t; + + +typedef struct ngx_command_s ngx_command_t; +struct ngx_command_s { + ngx_str_t name; + int type; + char *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, char *conf); + int conf; + int offset; +}; + + +typedef struct { + void *ctx; + ngx_command_t *commands; + int type; + int (*init_module)(ngx_pool_t *p); +} ngx_module_t; + + +typedef struct { + ngx_file_t file; + ngx_hunk_t *hunk; + int line; +} ngx_conf_file_t; + + +struct ngx_conf_s { + char *name; + ngx_array_t *args; + + ngx_pool_t *pool; + ngx_conf_file_t *conf_file; + ngx_log_t *log; + + void *ctx; + int type; + int (*handler)(ngx_conf_t *cf); +}; + + +int ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename); + + +char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf); +char *ngx_conf_set_time_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf); + + +extern ngx_module_t *ngx_modules[]; + + +#endif _NGX_HTTP_CONF_FILE_H_INCLUDED_
--- a/src/core/ngx_config_file.c Fri Dec 27 07:27:47 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,423 +0,0 @@ - -#include <ngx_config.h> -#include <ngx_core.h> -#include <ngx_config_file.h> - - -static int argument_number[] = { - NGX_CONF_NOARGS, - NGX_CONF_TAKE1, - NGX_CONF_TAKE2 -}; - -static int ngx_conf_read_token(ngx_conf_t *cf); - - -int ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) -{ - int rc, i; - char *error; - ngx_str_t *name; - ngx_fd_t fd; - ngx_conf_file_t *prev; - ngx_command_t *cmd; - - if (filename) { - - fd = ngx_open_file(filename->data, NGX_FILE_RDONLY); - if (fd == NGX_INVALID_FILE) { - ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, - "ngx_conf_file: " - ngx_open_file_n " %s failed", filename->data); - return NGX_ERROR; - } - - prev = cf->conf_file; - ngx_test_null(cf->conf_file, - ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)), - NGX_ERROR); - - if (ngx_stat_fd(fd, &cf->conf_file->file.info) == -1) { - ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, - "ngx_conf_file: " - ngx_stat_fd_n " %s failed", filename->data); - } - - ngx_test_null(cf->conf_file->hunk, - ngx_create_temp_hunk(cf->pool, 1024, 0, 0), - NGX_ERROR); - - cf->conf_file->file.fd = fd; - cf->conf_file->file.name.len = filename->len; - cf->conf_file->file.name.data = filename->data; - cf->conf_file->file.log = cf->log;; - cf->conf_file->line = 1; - } - - for ( ;; ) { - rc = ngx_conf_read_token(cf); - - /* NGX_OK, NGX_ERROR, NGX_CONF_FILE_DONE, NGX_CONF_BLOCK_DONE */ - - if (rc == NGX_ERROR || rc == NGX_CONF_FILE_DONE) { - return rc; - } - - if (cf->handler) { - - if ((*cf->handler)(cf) == NGX_ERROR) { - return NGX_ERROR; - } - - continue; - } - - name = (ngx_str_t *) cf->args->elts; - - for (i = 0; ngx_modules[i]; i++) { - if (cf->type != ngx_modules[i]->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) - { -ngx_log_debug(cf->log, "command '%s'" _ cmd->name.data); - cmd->set(cf, cmd, NULL); - } - - cmd++; - } - } - -#if 0 - cmd = ngx_conf_find_token(cf); - if (cmd == NULL) { - ngx_log_error(NGX_LOG_EMERG, cf->log, 0, - "unknown directive \"%s\" in %s:%d", - cf->name, cf->file->name, cf->file->line); - return NGX_ERROR; - } - - if (cmd->type & argument_number[cf->args->nelts - 1]) { - error = cmd->set(cf, cmd->offset, cf->args); - - if (error) { - ngx_log_error(NGX_LOG_EMERG, cf->log, 0, - "%s in directive \"%s\" in %s:%d", - error, cf->name, cf->file->name, cf->file->line); - return NGX_ERROR; - } - } -#endif - -#if 0 - if (cmd->type == NGX_CONF_CONTAINER) { - ngx_conf_parse(cf, cmd->container, NULL); - - } else if (cmd->type == NGX_CONF_FLAG) { - - if (cf->args->nelts != 1) { - ngx_log_error(NGX_LOG_EMERG, cf->log, 0, - "invalid number of arguments " - "in directive \"%s\" in %s:%d", - cf->name, cf->file->name, cf->file->line); - return NGX_ERROR; - } - - if (ngx_strcasecmp(cf->args->elts[0], "on") == 0) { - flag = 1; - - } else if (ngx_strcasecmp(cf->args->elts[0], "off") == 0) { - flag = 0; - - } else { - ngx_log_error(NGX_LOG_EMERG, cf->log, 0, - "invalid flag in directive \"%s\" in %s:%d", - cf->name, cf->file->name, cf->file->line); - return NGX_ERROR; - } - - rv = cmd->set(cf, cmd->offset, flag); - if (rv) { - ngx_log_error(NGX_LOG_EMERG, cf->log, 0, - "%s in directive \"%s\" in %s:%d", - rv, cf->name, cf->file->name, cf->file->line); - return NGX_ERROR; - } - - } else if (cmd->type & argument_number[args->nelts]) { - rv = cmd->set(cf, cmd->offset, cf->args); - if (rv) { - ngx_log_error(NGX_LOG_EMERG, cf->log, 0, - "%s in directive \"%s\" in %s:%d", - rv, cf->name, cf->file->name, cf->file->line); - return NGX_ERROR; - } - - } else { - ngx_log_error(NGX_LOG_EMERG, cf->log, 0, - "invalid number of arguments " - "in directive \"%s\" in %s:%d", - cf->name, cf->file->name, cf->file->line); - return NGX_ERROR; - } -#endif - } - - if (filename) { - cf->conf_file = prev; - - if (ngx_close_file(fd) == NGX_FILE_ERROR) { - ngx_log_error(NGX_LOG_ERR, cf->log, ngx_errno, - ngx_close_file_n " %s failed", - cf->conf_file->file.name.data); - return NGX_ERROR; - } - } - - return NGX_OK; -} - - -static int ngx_conf_read_token(ngx_conf_t *cf) -{ - char *start, ch, *src, *dst; - 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; - - found = 0; - need_space = 0; - last_space = 1; - sharp_comment = 0; - quoted = s_quoted = d_quoted = 0; - - cf->args->nelts = 0; - h = cf->conf_file->hunk; - start = h->pos.mem; - -ngx_log_debug(cf->log, "TOKEN START"); - - for ( ;; ) { - - if (h->pos.mem >= h->last.mem) { - if (cf->conf_file->file.offset - >= ngx_file_size(cf->conf_file->file.info)) { - return NGX_CONF_FILE_DONE; - } - - if (h->pos.mem - start) { - ngx_memcpy(h->start, start, h->pos.mem - start); - } - - n = ngx_read_file(&cf->conf_file->file, - h->start + (h->pos.mem - start), - h->end - (h->start + (h->pos.mem - start)), - cf->conf_file->file.offset); - - if (n == NGX_ERROR) { - return NGX_ERROR; - } - - h->pos.mem = h->start + (h->pos.mem - start); - start = h->start; - h->last.mem = h->pos.mem + n; - } - - ch = *h->pos.mem++; - -#if 0 -ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _ - last_space _ need_space _ - quoted _ s_quoted _ d_quoted _ ch); -#endif - - if (ch == LF) { - cf->conf_file->line++; - - if (sharp_comment) { - sharp_comment = 0; - } - } - - if (sharp_comment) { - continue; - } - - if (quoted) { - quoted = 0; - continue; - } - - if (need_space) { - if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) { - last_space = 1; - need_space = 0; - continue; - } - - if (ch == ';' || ch == '{') { - return NGX_OK; - } - - return NGX_ERROR; - } - - if (last_space) { - if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) { - continue; - } - - start = h->pos.mem - 1; - - switch (ch) { - - 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; - continue; - - case '"': - start++; - d_quoted = 1; - last_space = 0; - continue; - - case '\'': - start++; - s_quoted = 1; - last_space = 0; - continue; - - default: - last_space = 0; - } - - } else { - if (ch == '\\') { - quoted = 1; - continue; - } - - if (d_quoted) { - if (ch == '"') { - d_quoted = 0; - need_space = 1; - found = 1; - } - - } else if (s_quoted) { - if (ch == '\'') { - s_quoted = 0; - need_space = 1; - found = 1; - } - - } else if (ch == ' ' || ch == '\t' || ch == CR || ch == LF - || ch == ';' || ch == '{') { - last_space = 1; - found = 1; - } - - if (found) { - ngx_test_null(word, ngx_push_array(cf->args), NGX_ERROR); - ngx_test_null(word->data, - ngx_palloc(cf->pool, h->pos.mem - start + 1), - NGX_ERROR); - - for (dst = word->data, src = start, len = 0; - src < h->pos.mem - 1; - len++) - { - if (*src == '\\') { - src++; - } - *dst++ = *src++; - } - *dst = '\0'; - word->len = len; - -ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data); - - if (ch == ';' || ch == '{') { - return NGX_OK; - } - - found = 0; - } - } - } -} - - -char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) -{ - int size; - ngx_str_t *value; - - value = (ngx_str_t *) cf->args->elts; - - size = atoi(value[1].data); - if (size < 0) { - return "value must be greater or equal to zero"; - } - - *(int *) (conf + cmd->offset) = size; - - return NULL; -} - - -char *ngx_conf_set_time_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) -{ - int size; - ngx_str_t *value; - - value = (ngx_str_t *) cf->args->elts; - - size = atoi(value[1].data); - if (size < 0) { - return "value must be greater or equal to zero"; - } - - *(int *) (conf + cmd->offset) = size; - - return NULL; -}
--- a/src/core/ngx_config_file.h Fri Dec 27 07:27:47 2002 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -#ifndef _NGX_HTTP_CONFIG_FILE_H_INCLUDED_ -#define _NGX_HTTP_CONFIG_FILE_H_INCLUDED_ - - -#include <ngx_config.h> -#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 - -#define NGX_CONF_ANY 0x10000 -#define NGX_CONF_BLOCK 0x20000 - -#define NGX_CONF_UNSET -1 - - -#define NGX_CONF_BLOCK_DONE 1 -#define NGX_CONF_FILE_DONE 2 - - -#define NGX_CONF_ERROR (char *) -1 - -typedef struct ngx_conf_s ngx_conf_t; - - -typedef struct ngx_command_s ngx_command_t; -struct ngx_command_s { - ngx_str_t name; - int type; - char *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, char *conf); - int conf; - int offset; -}; - - -typedef struct { - void *ctx; - ngx_command_t *commands; - int type; - int (*init_module)(ngx_pool_t *p); -} ngx_module_t; - - -typedef struct { - ngx_file_t file; - ngx_hunk_t *hunk; - int line; -} ngx_conf_file_t; - - -struct ngx_conf_s { - char *name; - ngx_array_t *args; - - ngx_pool_t *pool; - ngx_conf_file_t *conf_file; - ngx_log_t *log; - - void *ctx; - int type; - int (*handler)(ngx_conf_t *cf); -}; - - -int ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename); - - -char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf); -char *ngx_conf_set_time_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf); - - -extern ngx_module_t *ngx_modules[]; - - -#endif _NGX_HTTP_CONFIG_FILE_H_INCLUDED_
--- a/src/core/ngx_modules.c Fri Dec 27 07:27:47 2002 +0000 +++ b/src/core/ngx_modules.c Fri Dec 27 16:22:50 2002 +0000 @@ -1,7 +1,7 @@ #include <ngx_config.h> -#include <ngx_config_file.h> +#include <ngx_conf_file.h> extern ngx_module_t ngx_http_header_filter_module;
--- a/src/http/modules/ngx_http_index_handler.c Fri Dec 27 07:27:47 2002 +0000 +++ b/src/http/modules/ngx_http_index_handler.c Fri Dec 27 16:22:50 2002 +0000 @@ -1,10 +1,12 @@ #include <ngx_config.h> + #include <ngx_core.h> #include <ngx_errno.h> #include <ngx_string.h> #include <ngx_files.h> -#include <ngx_config_file.h> +#include <ngx_conf_file.h> + #include <ngx_http.h> #include <ngx_http_config.h> #include <ngx_http_index_handler.h>
--- a/src/http/ngx_http.h Fri Dec 27 07:27:47 2002 +0000 +++ b/src/http/ngx_http.h Fri Dec 27 16:22:50 2002 +0000 @@ -3,13 +3,14 @@ #include <ngx_config.h> + #include <ngx_types.h> #include <ngx_string.h> #include <ngx_table.h> #include <ngx_hunk.h> #include <ngx_files.h> #include <ngx_connection.h> -#include <ngx_config_file.h> +#include <ngx_conf_file.h> #define NGX_HTTP_VERSION_10 1000
--- a/src/http/ngx_http_config.c Fri Dec 27 07:27:47 2002 +0000 +++ b/src/http/ngx_http_config.c Fri Dec 27 16:22:50 2002 +0000 @@ -1,7 +1,13 @@ + +/* TODO: + ngx_http_conf_ctx_t ctx; on stack or in pool ? */ + #include <ngx_config.h> + #include <ngx_core.h> -#include <ngx_config_file.h> +#include <ngx_conf_file.h> + #include <ngx_http.h> #include <ngx_http_core.h> #include <ngx_http_config.h> @@ -38,10 +44,11 @@ ngx_module_t ngx_http_module = { NULL, /* module context */ ngx_http_commands, /* module directives */ - 0, /* module type */ + NGX_CORE_MODULE_TYPE, /* module type */ NULL /* init module */ }; + static ngx_command_t ngx_http_core_commands[] = { {ngx_string("server"), @@ -83,7 +90,7 @@ { int i; ngx_http_module_t *module; - ngx_http_conf_ctx_t *ctx; + ngx_http_conf_ctx_t ctx; for (i = 0; ngx_modules[i]; i++) { if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) { @@ -98,9 +105,9 @@ ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), NGX_CONF_ERROR); - ctx->srv_conf = NULL; - ctx->loc_conf = null_loc_conf; - ctx->locations = NULL; + ctx.srv_conf = NULL; + ctx.loc_conf = null_loc_conf; + ctx.locations = NULL; for (i = 0; ngx_modules[i]; i++) { if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) { @@ -116,7 +123,7 @@ } } - cf->ctx = ctx; + cf->ctx = &ctx; cf->type = NGX_HTTP_MODULE_TYPE; return ngx_conf_parse(cf, NULL); }
--- a/src/http/ngx_http_core.c Fri Dec 27 07:27:47 2002 +0000 +++ b/src/http/ngx_http_core.c Fri Dec 27 16:22:50 2002 +0000 @@ -1,7 +1,9 @@ #include <ngx_config.h> + #include <ngx_core.h> -#include <ngx_config_file.h> +#include <ngx_conf_file.h> + #include <ngx_http.h> #include <ngx_http_core.h> #include <ngx_http_config.h>
--- a/src/http/ngx_http_header_filter.c Fri Dec 27 07:27:47 2002 +0000 +++ b/src/http/ngx_http_header_filter.c Fri Dec 27 16:22:50 2002 +0000 @@ -2,11 +2,13 @@ #include <nginx.h> #include <ngx_config.h> + #include <ngx_core.h> #include <ngx_string.h> #include <ngx_table.h> #include <ngx_hunk.h> -#include <ngx_config_file.h> +#include <ngx_conf_file.h> + #include <ngx_http.h> #include <ngx_http_write_filter.h>
--- a/src/http/ngx_http_output_filter.c Fri Dec 27 07:27:47 2002 +0000 +++ b/src/http/ngx_http_output_filter.c Fri Dec 27 16:22:50 2002 +0000 @@ -1,10 +1,12 @@ #include <ngx_config.h> + #include <ngx_core.h> #include <ngx_files.h> #include <ngx_string.h> #include <ngx_hunk.h> -#include <ngx_config_file.h> +#include <ngx_conf_file.h> + #include <ngx_http.h> #include <ngx_http_config.h> #include <ngx_http_output_filter.h>
--- a/src/http/ngx_http_output_filter.h Fri Dec 27 07:27:47 2002 +0000 +++ b/src/http/ngx_http_output_filter.h Fri Dec 27 16:22:50 2002 +0000 @@ -3,6 +3,7 @@ #include <ngx_hunk.h> +#include <ngx_conf_file.h> #include <ngx_http.h>
--- a/src/http/ngx_http_write_filter.c Fri Dec 27 07:27:47 2002 +0000 +++ b/src/http/ngx_http_write_filter.c Fri Dec 27 16:22:50 2002 +0000 @@ -1,8 +1,12 @@ #include <ngx_config.h> + #include <ngx_core.h> #include <ngx_hunk.h> +#include <ngx_conf_file.h> + #include <ngx_event_write.h> + #include <ngx_http.h> #include <ngx_http_config.h> #include <ngx_http_write_filter.h>