Mercurial > hg > nginx
diff src/core/ngx_config_file.c @ 40:d5d4f3bba6f0
nginx-0.0.1-2002-12-26-10:24:21 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 26 Dec 2002 07:24:21 +0000 |
parents | 9fe40e51d4a3 |
children | 59e7c7f30d49 |
line wrap: on
line diff
--- 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_s 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_s 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_s 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 ' 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 ' 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'" _ } } -#endif + +static ngx_command_t *ngx_conf_find_token(ngx_conf_t *cf) +{ + int i; + ngx_command_t *cmd; -char *ngx_conf_set_size_slot(char *conf, int offset, char *value) -{ - int size; + 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++; + } - size = atoi(value); - if (size < 0) + } +} + + +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 + offset) = size; + *(int *) (conf + cf->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; - size = atoi(value); - if (size < 0) + 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 + offset) = size; + return NULL; }