2002-09-11 23:18:33 +08:00
|
|
|
|
|
|
|
#include <ngx_config.h>
|
2002-12-19 15:08:55 +08:00
|
|
|
#include <ngx_core.h>
|
2002-12-03 00:09:40 +08:00
|
|
|
|
|
|
|
|
2003-05-27 20:18:54 +08:00
|
|
|
|
2003-07-21 05:15:59 +08:00
|
|
|
#define MAX_CONF_ERRSTR 256
|
2003-05-27 20:18:54 +08:00
|
|
|
|
2003-10-23 00:38:26 +08:00
|
|
|
/* Ten fixed arguments */
|
|
|
|
|
2002-12-03 00:09:40 +08:00
|
|
|
static int argument_number[] = {
|
|
|
|
NGX_CONF_NOARGS,
|
|
|
|
NGX_CONF_TAKE1,
|
2003-10-23 00:38:26 +08:00
|
|
|
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
|
2002-12-03 00:09:40 +08:00
|
|
|
};
|
|
|
|
|
2002-12-26 15:24:21 +08:00
|
|
|
static int ngx_conf_read_token(ngx_conf_t *cf);
|
|
|
|
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2003-01-09 13:36:00 +08:00
|
|
|
char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
|
2002-12-03 00:09:40 +08:00
|
|
|
{
|
2003-05-30 22:27:59 +08:00
|
|
|
int m, rc, found, valid;
|
2003-01-09 13:36:00 +08:00
|
|
|
char *rv;
|
2003-05-20 00:39:14 +08:00
|
|
|
void *conf, **confp;
|
2002-12-27 00:26:23 +08:00
|
|
|
ngx_str_t *name;
|
2002-12-26 15:24:21 +08:00
|
|
|
ngx_fd_t fd;
|
2002-12-19 15:08:55 +08:00
|
|
|
ngx_conf_file_t *prev;
|
2002-12-26 15:24:21 +08:00
|
|
|
ngx_command_t *cmd;
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2003-07-07 14:11:50 +08:00
|
|
|
#if (NGX_SUPPRESS_WARN)
|
|
|
|
fd = NGX_INVALID_FILE;
|
|
|
|
prev = NULL;
|
|
|
|
#endif
|
|
|
|
|
2002-12-03 00:09:40 +08:00
|
|
|
if (filename) {
|
2002-12-19 15:08:55 +08:00
|
|
|
|
2003-05-16 23:27:48 +08:00
|
|
|
/* open configuration file */
|
|
|
|
|
2003-06-02 23:24:30 +08:00
|
|
|
fd = ngx_open_file(filename->data, NGX_FILE_RDONLY, NGX_FILE_OPEN);
|
2002-12-19 15:08:55 +08:00
|
|
|
if (fd == NGX_INVALID_FILE) {
|
|
|
|
ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
|
2002-12-23 14:29:22 +08:00
|
|
|
ngx_open_file_n " %s failed", filename->data);
|
2003-01-09 13:36:00 +08:00
|
|
|
return NGX_CONF_ERROR;
|
2002-12-19 15:08:55 +08:00
|
|
|
}
|
|
|
|
|
2002-12-23 14:29:22 +08:00
|
|
|
prev = cf->conf_file;
|
|
|
|
ngx_test_null(cf->conf_file,
|
|
|
|
ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)),
|
2003-01-09 13:36:00 +08:00
|
|
|
NGX_CONF_ERROR);
|
2002-12-19 15:08:55 +08:00
|
|
|
|
2002-12-23 14:29:22 +08:00
|
|
|
if (ngx_stat_fd(fd, &cf->conf_file->file.info) == -1) {
|
|
|
|
ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
|
|
|
|
ngx_stat_fd_n " %s failed", filename->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_test_null(cf->conf_file->hunk,
|
|
|
|
ngx_create_temp_hunk(cf->pool, 1024, 0, 0),
|
2003-01-09 13:36:00 +08:00
|
|
|
NGX_CONF_ERROR);
|
2002-12-23 14:29:22 +08:00
|
|
|
|
|
|
|
cf->conf_file->file.fd = fd;
|
|
|
|
cf->conf_file->file.name.len = filename->len;
|
|
|
|
cf->conf_file->file.name.data = filename->data;
|
2003-07-07 14:11:50 +08:00
|
|
|
cf->conf_file->file.offset = 0;
|
2002-12-23 14:29:22 +08:00
|
|
|
cf->conf_file->file.log = cf->log;;
|
|
|
|
cf->conf_file->line = 1;
|
2002-12-03 00:09:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for ( ;; ) {
|
|
|
|
rc = ngx_conf_read_token(cf);
|
|
|
|
|
2003-05-16 23:27:48 +08:00
|
|
|
/* ngx_conf_read_token() returns NGX_OK, NGX_ERROR,
|
|
|
|
NGX_CONF_FILE_DONE or NGX_CONF_BLOCK_DONE */
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2003-02-07 01:21:13 +08:00
|
|
|
#if 0
|
2003-01-09 13:36:00 +08:00
|
|
|
ngx_log_debug(cf->log, "token %d" _ rc);
|
2003-02-07 01:21:13 +08:00
|
|
|
#endif
|
2003-01-09 13:36:00 +08:00
|
|
|
|
|
|
|
if (rc == NGX_ERROR) {
|
2003-07-07 14:11:50 +08:00
|
|
|
break;
|
2003-01-09 13:36:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rc != NGX_OK) {
|
2003-07-07 14:11:50 +08:00
|
|
|
break;
|
2002-12-19 15:08:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cf->handler) {
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2003-05-16 23:27:48 +08:00
|
|
|
/* custom handler, i.e. used in http "types { ... }" directive */
|
|
|
|
|
2003-05-15 01:13:13 +08:00
|
|
|
rv = (*cf->handler)(cf, NULL, cf->handler_conf);
|
|
|
|
if (rv == NGX_CONF_OK) {
|
|
|
|
continue;
|
|
|
|
|
|
|
|
} else if (rv == NGX_CONF_ERROR) {
|
2003-07-07 14:11:50 +08:00
|
|
|
rc = NGX_ERROR;
|
|
|
|
break;
|
2002-12-19 15:08:55 +08:00
|
|
|
|
2003-05-15 01:13:13 +08:00
|
|
|
} else {
|
|
|
|
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
2003-05-15 23:42:53 +08:00
|
|
|
"%s in %s:%d",
|
|
|
|
rv,
|
2003-05-15 01:13:13 +08:00
|
|
|
cf->conf_file->file.name.data,
|
|
|
|
cf->conf_file->line);
|
2003-07-07 14:11:50 +08:00
|
|
|
rc = NGX_ERROR;
|
|
|
|
break;
|
2003-05-15 01:13:13 +08:00
|
|
|
}
|
2002-12-19 15:08:55 +08:00
|
|
|
}
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2002-12-27 00:26:23 +08:00
|
|
|
name = (ngx_str_t *) cf->args->elts;
|
2003-01-09 13:36:00 +08:00
|
|
|
found = 0;
|
2002-12-27 00:26:23 +08:00
|
|
|
|
2003-07-07 14:11:50 +08:00
|
|
|
for (m = 0; rc != NGX_ERROR && !found && ngx_modules[m]; m++) {
|
2003-05-16 23:27:48 +08:00
|
|
|
|
|
|
|
/* look up the directive in the appropriate modules */
|
|
|
|
|
2003-05-27 20:18:54 +08:00
|
|
|
if (ngx_modules[m]->type != NGX_CONF_MODULE
|
|
|
|
&& ngx_modules[m]->type != cf->module_type)
|
2002-12-28 00:22:50 +08:00
|
|
|
{
|
2002-12-27 00:26:23 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-05-27 20:18:54 +08:00
|
|
|
cmd = ngx_modules[m]->commands;
|
2002-12-27 00:26:23 +08:00
|
|
|
if (cmd == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (cmd->name.len) {
|
|
|
|
if (name->len == cmd->name.len
|
|
|
|
&& ngx_strcmp(name->data, cmd->name.data) == 0)
|
|
|
|
{
|
2002-12-28 00:22:50 +08:00
|
|
|
|
2003-07-18 22:44:05 +08:00
|
|
|
found = 1;
|
2003-02-07 01:21:13 +08:00
|
|
|
#if 0
|
2002-12-27 00:26:23 +08:00
|
|
|
ngx_log_debug(cf->log, "command '%s'" _ cmd->name.data);
|
2003-02-07 01:21:13 +08:00
|
|
|
#endif
|
2003-05-16 23:27:48 +08:00
|
|
|
/* is the directive's location right ? */
|
2002-12-28 00:22:50 +08:00
|
|
|
|
2003-05-15 01:13:13 +08:00
|
|
|
if ((cmd->type & cf->cmd_type) == 0) {
|
|
|
|
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
|
|
|
"directive \"%s\" in %s:%d "
|
|
|
|
"is not allowed here",
|
|
|
|
name->data,
|
|
|
|
cf->conf_file->file.name.data,
|
|
|
|
cf->conf_file->line);
|
2003-07-07 14:11:50 +08:00
|
|
|
rc = NGX_ERROR;
|
|
|
|
break;
|
2003-05-15 01:13:13 +08:00
|
|
|
}
|
|
|
|
|
2003-05-16 23:27:48 +08:00
|
|
|
/* is the directive's argument count right ? */
|
|
|
|
|
2003-10-23 00:38:26 +08:00
|
|
|
if (cmd->type & NGX_CONF_ANY) {
|
2003-05-30 22:27:59 +08:00
|
|
|
valid = 1;
|
|
|
|
|
2003-10-23 00:38:26 +08:00
|
|
|
} else if (cmd->type & NGX_CONF_FLAG) {
|
2003-05-30 22:27:59 +08:00
|
|
|
|
2003-10-23 00:38:26 +08:00
|
|
|
if (cf->args->nelts == 2) {
|
2003-05-30 22:27:59 +08:00
|
|
|
valid = 1;
|
|
|
|
} else {
|
|
|
|
valid = 0;
|
|
|
|
}
|
|
|
|
|
2003-10-23 00:38:26 +08:00
|
|
|
} else if (cmd->type & NGX_CONF_1MORE) {
|
2003-05-30 22:27:59 +08:00
|
|
|
|
2003-10-23 00:38:26 +08:00
|
|
|
if (cf->args->nelts != 1) {
|
2003-05-30 22:27:59 +08:00
|
|
|
valid = 1;
|
|
|
|
} else {
|
|
|
|
valid = 0;
|
|
|
|
}
|
|
|
|
|
2003-10-23 00:38:26 +08:00
|
|
|
} else if (cf->args->nelts <= 10
|
|
|
|
&& (cmd->type
|
|
|
|
& argument_number[cf->args->nelts - 1]))
|
|
|
|
{
|
2003-05-30 22:27:59 +08:00
|
|
|
valid = 1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
valid = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!valid) {
|
2003-01-09 13:36:00 +08:00
|
|
|
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
|
|
|
"invalid number arguments in "
|
|
|
|
"directive \"%s\" in %s:%d",
|
|
|
|
name->data,
|
|
|
|
cf->conf_file->file.name.data,
|
|
|
|
cf->conf_file->line);
|
2003-07-07 14:11:50 +08:00
|
|
|
rc = NGX_ERROR;
|
|
|
|
break;
|
2003-01-09 13:36:00 +08:00
|
|
|
}
|
2002-12-19 15:08:55 +08:00
|
|
|
|
2003-05-16 23:27:48 +08:00
|
|
|
/* set up the directive's configuration context */
|
|
|
|
|
2003-01-09 13:36:00 +08:00
|
|
|
conf = NULL;
|
2003-05-16 23:27:48 +08:00
|
|
|
|
2003-05-27 20:18:54 +08:00
|
|
|
if (cf->module_type == NGX_CORE_MODULE) {
|
|
|
|
conf = &(((void **) cf->ctx)[ngx_modules[m]->index]);
|
2003-05-16 23:27:48 +08:00
|
|
|
|
|
|
|
} else if (cf->ctx) {
|
2003-05-20 00:39:14 +08:00
|
|
|
confp = *(void **) ((char *) cf->ctx + cmd->conf);
|
2002-12-19 15:08:55 +08:00
|
|
|
|
2003-05-20 00:39:14 +08:00
|
|
|
if (confp) {
|
2003-05-27 20:18:54 +08:00
|
|
|
conf = confp[ngx_modules[m]->ctx_index];
|
2003-01-09 13:36:00 +08:00
|
|
|
}
|
|
|
|
}
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2003-01-09 13:36:00 +08:00
|
|
|
rv = cmd->set(cf, cmd, conf);
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2003-02-07 01:21:13 +08:00
|
|
|
#if 0
|
2003-01-09 13:36:00 +08:00
|
|
|
ngx_log_debug(cf->log, "rv: %d" _ rv);
|
2003-02-07 01:21:13 +08:00
|
|
|
#endif
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2003-01-09 13:36:00 +08:00
|
|
|
if (rv == NGX_CONF_OK) {
|
|
|
|
break;
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2003-01-09 13:36:00 +08:00
|
|
|
} else if (rv == NGX_CONF_ERROR) {
|
2003-07-07 14:11:50 +08:00
|
|
|
rc = NGX_ERROR;
|
|
|
|
break;
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2003-01-09 13:36:00 +08:00
|
|
|
} else {
|
2003-07-21 05:15:59 +08:00
|
|
|
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
|
|
|
"\"%s\" directive %s in %s:%d",
|
|
|
|
name->data, rv,
|
|
|
|
cf->conf_file->file.name.data,
|
|
|
|
cf->conf_file->line);
|
2003-03-04 14:33:48 +08:00
|
|
|
|
2003-07-07 14:11:50 +08:00
|
|
|
rc = NGX_ERROR;
|
|
|
|
break;
|
2003-01-09 13:36:00 +08:00
|
|
|
}
|
|
|
|
}
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2003-01-09 13:36:00 +08:00
|
|
|
cmd++;
|
2002-12-03 00:09:40 +08:00
|
|
|
}
|
2003-01-09 13:36:00 +08:00
|
|
|
}
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2003-01-09 13:36:00 +08:00
|
|
|
if (!found) {
|
2002-12-03 00:09:40 +08:00
|
|
|
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
2003-01-09 13:36:00 +08:00
|
|
|
"unknown directive \"%s\" in %s:%d",
|
|
|
|
name->data,
|
|
|
|
cf->conf_file->file.name.data,
|
|
|
|
cf->conf_file->line);
|
|
|
|
|
2003-07-07 14:11:50 +08:00
|
|
|
rc = NGX_ERROR;
|
|
|
|
break;
|
2002-12-03 00:09:40 +08:00
|
|
|
}
|
2003-07-18 22:44:05 +08:00
|
|
|
|
|
|
|
if (rc == NGX_ERROR) {
|
|
|
|
break;
|
|
|
|
}
|
2002-12-23 14:29:22 +08:00
|
|
|
}
|
2002-12-03 00:09:40 +08:00
|
|
|
|
|
|
|
if (filename) {
|
2002-12-23 14:29:22 +08:00
|
|
|
cf->conf_file = prev;
|
2002-12-19 15:08:55 +08:00
|
|
|
|
|
|
|
if (ngx_close_file(fd) == NGX_FILE_ERROR) {
|
2003-05-16 23:27:48 +08:00
|
|
|
ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
|
2002-12-23 14:29:22 +08:00
|
|
|
ngx_close_file_n " %s failed",
|
|
|
|
cf->conf_file->file.name.data);
|
2003-01-09 13:36:00 +08:00
|
|
|
return NGX_CONF_ERROR;
|
2002-12-19 15:08:55 +08:00
|
|
|
}
|
2002-12-03 00:09:40 +08:00
|
|
|
}
|
2002-12-19 15:08:55 +08:00
|
|
|
|
2003-07-07 14:11:50 +08:00
|
|
|
if (rc == NGX_ERROR) {
|
|
|
|
return NGX_CONF_ERROR;
|
|
|
|
}
|
|
|
|
|
2003-01-09 13:36:00 +08:00
|
|
|
return NGX_CONF_OK;
|
2002-12-23 14:29:22 +08:00
|
|
|
}
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2002-12-19 15:08:55 +08:00
|
|
|
|
2002-12-26 15:24:21 +08:00
|
|
|
static int ngx_conf_read_token(ngx_conf_t *cf)
|
2002-12-03 00:09:40 +08:00
|
|
|
{
|
2002-12-19 15:08:55 +08:00
|
|
|
char *start, ch, *src, *dst;
|
2002-12-26 15:24:21 +08:00
|
|
|
int len;
|
|
|
|
int found, need_space, last_space, sharp_comment;
|
|
|
|
int quoted, s_quoted, d_quoted;
|
2002-12-23 14:29:22 +08:00
|
|
|
ssize_t n;
|
|
|
|
ngx_str_t *word;
|
2002-12-19 15:08:55 +08:00
|
|
|
ngx_hunk_t *h;
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2002-12-23 14:29:22 +08:00
|
|
|
found = 0;
|
2002-12-03 00:09:40 +08:00
|
|
|
need_space = 0;
|
|
|
|
last_space = 1;
|
2002-12-26 15:24:21 +08:00
|
|
|
sharp_comment = 0;
|
2002-12-03 00:09:40 +08:00
|
|
|
quoted = s_quoted = d_quoted = 0;
|
|
|
|
|
|
|
|
cf->args->nelts = 0;
|
2002-12-19 15:08:55 +08:00
|
|
|
h = cf->conf_file->hunk;
|
2003-03-12 04:38:13 +08:00
|
|
|
start = h->pos;
|
2002-12-19 15:08:55 +08:00
|
|
|
|
2003-02-07 01:21:13 +08:00
|
|
|
#if 0
|
2002-12-23 14:29:22 +08:00
|
|
|
ngx_log_debug(cf->log, "TOKEN START");
|
2003-02-07 01:21:13 +08:00
|
|
|
#endif
|
2002-12-23 14:29:22 +08:00
|
|
|
|
2002-12-24 02:22:18 +08:00
|
|
|
for ( ;; ) {
|
2002-12-19 15:08:55 +08:00
|
|
|
|
2003-03-12 04:38:13 +08:00
|
|
|
if (h->pos >= h->last) {
|
2002-12-23 14:29:22 +08:00
|
|
|
if (cf->conf_file->file.offset
|
|
|
|
>= ngx_file_size(cf->conf_file->file.info)) {
|
2002-12-26 15:24:21 +08:00
|
|
|
return NGX_CONF_FILE_DONE;
|
2002-12-23 14:29:22 +08:00
|
|
|
}
|
|
|
|
|
2003-03-12 04:38:13 +08:00
|
|
|
if (h->pos - start) {
|
|
|
|
ngx_memcpy(h->start, start, h->pos - start);
|
2002-12-19 15:08:55 +08:00
|
|
|
}
|
|
|
|
|
2002-12-23 14:29:22 +08:00
|
|
|
n = ngx_read_file(&cf->conf_file->file,
|
2003-03-12 04:38:13 +08:00
|
|
|
h->start + (h->pos - start),
|
|
|
|
h->end - (h->start + (h->pos - start)),
|
2002-12-19 15:08:55 +08:00
|
|
|
cf->conf_file->file.offset);
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2002-12-19 15:08:55 +08:00
|
|
|
if (n == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2003-03-12 04:38:13 +08:00
|
|
|
h->pos = h->start + (h->pos - start);
|
2002-12-19 15:08:55 +08:00
|
|
|
start = h->start;
|
2003-03-12 04:38:13 +08:00
|
|
|
h->last = h->pos + n;
|
2002-12-19 15:08:55 +08:00
|
|
|
}
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2003-03-12 04:38:13 +08:00
|
|
|
ch = *h->pos++;
|
2002-12-23 14:29:22 +08:00
|
|
|
|
2002-12-24 02:22:18 +08:00
|
|
|
#if 0
|
2002-12-23 14:29:22 +08:00
|
|
|
ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _
|
|
|
|
last_space _ need_space _
|
|
|
|
quoted _ s_quoted _ d_quoted _ ch);
|
2002-12-24 02:22:18 +08:00
|
|
|
#endif
|
2002-12-19 15:08:55 +08:00
|
|
|
|
|
|
|
if (ch == LF) {
|
|
|
|
cf->conf_file->line++;
|
2002-12-26 15:24:21 +08:00
|
|
|
|
|
|
|
if (sharp_comment) {
|
|
|
|
sharp_comment = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sharp_comment) {
|
|
|
|
continue;
|
2002-12-19 15:08:55 +08:00
|
|
|
}
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2002-12-24 02:22:18 +08:00
|
|
|
if (quoted) {
|
|
|
|
quoted = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-12-23 14:29:22 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-12-19 15:08:55 +08:00
|
|
|
if (last_space) {
|
|
|
|
if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-03-12 04:38:13 +08:00
|
|
|
start = h->pos - 1;
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2002-12-23 14:29:22 +08:00
|
|
|
switch (ch) {
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2002-12-24 02:22:18 +08:00
|
|
|
case ';':
|
|
|
|
case '{':
|
2002-12-26 15:24:21 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-12-24 02:22:18 +08:00
|
|
|
return NGX_OK;
|
|
|
|
|
2002-12-26 15:24:21 +08:00
|
|
|
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;
|
|
|
|
|
2002-12-23 14:29:22 +08:00
|
|
|
case '\\':
|
|
|
|
quoted = 1;
|
|
|
|
last_space = 0;
|
2002-12-03 00:09:40 +08:00
|
|
|
continue;
|
|
|
|
|
2002-12-23 14:29:22 +08:00
|
|
|
case '"':
|
|
|
|
start++;
|
|
|
|
d_quoted = 1;
|
|
|
|
last_space = 0;
|
|
|
|
continue;
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2002-12-23 14:29:22 +08:00
|
|
|
case '\'':
|
|
|
|
start++;
|
|
|
|
s_quoted = 1;
|
|
|
|
last_space = 0;
|
2002-12-03 00:09:40 +08:00
|
|
|
continue;
|
2002-12-23 14:29:22 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
last_space = 0;
|
2002-12-03 00:09:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2002-12-23 14:29:22 +08:00
|
|
|
if (ch == '\\') {
|
|
|
|
quoted = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2002-12-23 14:29:22 +08:00
|
|
|
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) {
|
2002-12-19 15:08:55 +08:00
|
|
|
ngx_test_null(word, ngx_push_array(cf->args), NGX_ERROR);
|
2002-12-24 02:22:18 +08:00
|
|
|
ngx_test_null(word->data,
|
2003-03-12 04:38:13 +08:00
|
|
|
ngx_palloc(cf->pool, h->pos - start + 1),
|
2002-12-03 00:09:40 +08:00
|
|
|
NGX_ERROR);
|
|
|
|
|
2002-12-24 02:22:18 +08:00
|
|
|
for (dst = word->data, src = start, len = 0;
|
2003-03-12 04:38:13 +08:00
|
|
|
src < h->pos - 1;
|
2002-12-24 02:22:18 +08:00
|
|
|
len++)
|
2002-12-23 14:29:22 +08:00
|
|
|
{
|
|
|
|
if (*src == '\\') {
|
2002-12-03 00:09:40 +08:00
|
|
|
src++;
|
2002-12-23 14:29:22 +08:00
|
|
|
}
|
2002-12-03 00:09:40 +08:00
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
|
|
|
*dst = '\0';
|
2002-12-24 02:22:18 +08:00
|
|
|
word->len = len;
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2003-02-07 01:21:13 +08:00
|
|
|
#if 0
|
2002-12-23 14:29:22 +08:00
|
|
|
ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data);
|
2003-02-07 01:21:13 +08:00
|
|
|
#endif
|
2002-12-03 00:09:40 +08:00
|
|
|
|
2002-12-23 14:29:22 +08:00
|
|
|
if (ch == ';' || ch == '{') {
|
|
|
|
return NGX_OK;
|
2002-12-03 00:09:40 +08:00
|
|
|
}
|
|
|
|
|
2002-12-23 14:29:22 +08:00
|
|
|
found = 0;
|
2002-12-03 00:09:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-21 05:15:59 +08:00
|
|
|
ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
ngx_open_file_t *file;
|
|
|
|
|
|
|
|
if (name) {
|
|
|
|
file = cycle->open_files.elts;
|
|
|
|
for (i = 0; i < cycle->open_files.nelts; i++) {
|
|
|
|
if (name->len != file[i].name.len) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ngx_strcmp(name->data, file[i].name.data) == 0) {
|
|
|
|
return &file[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_test_null(file, ngx_push_array(&cycle->open_files), NULL);
|
|
|
|
file->fd = NGX_INVALID_FILE;
|
|
|
|
if (name) {
|
|
|
|
file->name = *name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-18 22:44:05 +08:00
|
|
|
void ngx_conf_log_error(int level, ngx_conf_t *cf, ngx_err_t err,
|
|
|
|
char *fmt, ...)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
char errstr[MAX_CONF_ERRSTR];
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
len = ngx_vsnprintf(errstr, sizeof(errstr) - 1, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
|
|
|
|
" (%d: ", err);
|
|
|
|
len += ngx_strerror_r(err, errstr + len, sizeof(errstr) - len - 1);
|
|
|
|
errstr[len++] = ')';
|
|
|
|
errstr[len++] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_log_error(level, cf->log, 0, "%s in %s:%d",
|
|
|
|
errstr, cf->conf_file->file.name.data, cf->conf_file->line);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-11 23:17:50 +08:00
|
|
|
char *ngx_conf_set_core_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
|
|
void *conf)
|
|
|
|
{
|
|
|
|
return ngx_conf_set_flag_slot(cf, cmd, *(void **)conf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-27 20:18:54 +08:00
|
|
|
char *ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
2003-03-04 14:33:48 +08:00
|
|
|
{
|
2003-05-30 22:27:59 +08:00
|
|
|
char *p = conf;
|
|
|
|
|
2003-03-04 14:33:48 +08:00
|
|
|
int flag;
|
|
|
|
ngx_str_t *value;
|
|
|
|
|
2003-05-30 22:27:59 +08:00
|
|
|
if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) {
|
2003-05-20 23:37:55 +08:00
|
|
|
return "is duplicate";
|
|
|
|
}
|
|
|
|
|
2003-03-04 14:33:48 +08:00
|
|
|
value = (ngx_str_t *) cf->args->elts;
|
|
|
|
|
|
|
|
if (ngx_strcasecmp(value[1].data, "on") == 0) {
|
|
|
|
flag = 1;
|
|
|
|
|
|
|
|
} else if (ngx_strcasecmp(value[1].data, "off") == 0) {
|
|
|
|
flag = 0;
|
|
|
|
|
|
|
|
} else {
|
2003-07-21 05:15:59 +08:00
|
|
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
|
|
"invalid value \"%s\" in \"%s\" directive, "
|
|
|
|
"it must be \"on\" or \"off\"",
|
|
|
|
value[1].data, cmd->name.data);
|
|
|
|
return NGX_CONF_ERROR;
|
2003-03-04 14:33:48 +08:00
|
|
|
}
|
|
|
|
|
2003-05-30 22:27:59 +08:00
|
|
|
*(int *) (p + cmd->offset) = flag;
|
2003-03-04 14:33:48 +08:00
|
|
|
|
|
|
|
return NGX_CONF_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-27 20:18:54 +08:00
|
|
|
char *ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
2003-01-09 13:36:00 +08:00
|
|
|
{
|
2003-05-30 22:27:59 +08:00
|
|
|
char *p = conf;
|
|
|
|
|
2003-01-09 13:36:00 +08:00
|
|
|
ngx_str_t *field, *value;
|
|
|
|
|
2003-05-30 22:27:59 +08:00
|
|
|
field = (ngx_str_t *) (p + cmd->offset);
|
2003-05-20 23:37:55 +08:00
|
|
|
|
2003-05-27 20:18:54 +08:00
|
|
|
if (field->data) {
|
2003-05-20 23:37:55 +08:00
|
|
|
return "is duplicate";
|
|
|
|
}
|
|
|
|
|
2003-01-09 13:36:00 +08:00
|
|
|
value = (ngx_str_t *) cf->args->elts;
|
|
|
|
|
2003-10-23 00:38:26 +08:00
|
|
|
*field = value[1];
|
2003-01-09 13:36:00 +08:00
|
|
|
|
|
|
|
return NGX_CONF_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-27 20:18:54 +08:00
|
|
|
char *ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
2003-05-16 23:27:48 +08:00
|
|
|
{
|
2003-05-30 22:27:59 +08:00
|
|
|
char *p = conf;
|
|
|
|
|
2003-05-16 23:27:48 +08:00
|
|
|
int num, len;
|
|
|
|
ngx_str_t *value;
|
|
|
|
|
2003-05-30 22:27:59 +08:00
|
|
|
if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) {
|
2003-05-20 23:37:55 +08:00
|
|
|
return "is duplicate";
|
|
|
|
}
|
|
|
|
|
2003-05-16 23:27:48 +08:00
|
|
|
value = (ngx_str_t *) cf->args->elts;
|
|
|
|
|
|
|
|
len = value[1].len;
|
|
|
|
|
|
|
|
num = ngx_atoi(value[1].data, len);
|
|
|
|
if (num == NGX_ERROR) {
|
2003-05-30 22:27:59 +08:00
|
|
|
return "invalid number";
|
2003-05-16 23:27:48 +08:00
|
|
|
}
|
|
|
|
|
2003-05-30 22:27:59 +08:00
|
|
|
*(int *) (p + cmd->offset) = num;
|
2003-05-16 23:27:48 +08:00
|
|
|
|
|
|
|
return NGX_CONF_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-27 20:18:54 +08:00
|
|
|
char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
2002-12-26 15:24:21 +08:00
|
|
|
{
|
2003-05-30 22:27:59 +08:00
|
|
|
char *p = conf;
|
|
|
|
|
2003-04-28 23:06:39 +08:00
|
|
|
int size, len, scale;
|
|
|
|
char last;
|
2002-12-26 15:24:21 +08:00
|
|
|
ngx_str_t *value;
|
|
|
|
|
2003-05-30 22:27:59 +08:00
|
|
|
if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) {
|
2003-05-20 23:37:55 +08:00
|
|
|
return "is duplicate";
|
|
|
|
}
|
|
|
|
|
2002-12-26 15:24:21 +08:00
|
|
|
value = (ngx_str_t *) cf->args->elts;
|
|
|
|
|
2003-04-28 23:06:39 +08:00
|
|
|
len = value[1].len;
|
|
|
|
last = value[1].data[len - 1];
|
|
|
|
|
2003-05-07 01:03:16 +08:00
|
|
|
switch (last) {
|
|
|
|
case 'K':
|
|
|
|
case 'k':
|
2003-04-28 23:06:39 +08:00
|
|
|
len--;
|
|
|
|
scale = 1024;
|
2003-05-07 01:03:16 +08:00
|
|
|
break;
|
2003-04-28 23:06:39 +08:00
|
|
|
|
2003-05-07 01:03:16 +08:00
|
|
|
case 'M':
|
|
|
|
case 'm':
|
2003-04-28 23:06:39 +08:00
|
|
|
len--;
|
|
|
|
scale = 1024 * 1024;
|
2003-05-07 01:03:16 +08:00
|
|
|
break;
|
2003-04-28 23:06:39 +08:00
|
|
|
|
2003-05-07 01:03:16 +08:00
|
|
|
default:
|
2003-04-28 23:06:39 +08:00
|
|
|
scale = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = ngx_atoi(value[1].data, len);
|
|
|
|
if (size == NGX_ERROR) {
|
2003-05-07 01:03:16 +08:00
|
|
|
return "invalid value";
|
2002-12-26 15:24:21 +08:00
|
|
|
}
|
|
|
|
|
2003-04-28 23:06:39 +08:00
|
|
|
size *= scale;
|
|
|
|
|
2003-05-30 22:27:59 +08:00
|
|
|
*(int *) (p + cmd->offset) = size;
|
2002-09-11 23:18:33 +08:00
|
|
|
|
2003-01-09 13:36:00 +08:00
|
|
|
return NGX_CONF_OK;
|
2002-09-11 23:18:33 +08:00
|
|
|
}
|
2002-09-16 23:01:44 +08:00
|
|
|
|
2002-12-26 15:24:21 +08:00
|
|
|
|
2003-05-27 20:18:54 +08:00
|
|
|
char *ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
2002-09-16 23:01:44 +08:00
|
|
|
{
|
2003-05-30 22:27:59 +08:00
|
|
|
char *p = conf;
|
|
|
|
|
2003-05-15 23:42:53 +08:00
|
|
|
int size, total, len, scale;
|
|
|
|
u_int max, i;
|
2003-05-07 01:03:16 +08:00
|
|
|
char last, *start;
|
2002-12-26 15:24:21 +08:00
|
|
|
ngx_str_t *value;
|
|
|
|
|
2003-05-30 22:27:59 +08:00
|
|
|
if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) {
|
2003-05-20 23:37:55 +08:00
|
|
|
return "is duplicate";
|
|
|
|
}
|
|
|
|
|
2002-12-26 15:24:21 +08:00
|
|
|
value = (ngx_str_t *) cf->args->elts;
|
2003-05-07 01:03:16 +08:00
|
|
|
start = value[1].data;
|
|
|
|
len = 0;
|
|
|
|
total = 0;
|
2002-09-16 23:01:44 +08:00
|
|
|
|
2003-05-07 01:03:16 +08:00
|
|
|
for (i = 0; /* void */ ; i++) {
|
2003-04-28 23:06:39 +08:00
|
|
|
|
2003-05-07 01:03:16 +08:00
|
|
|
if (i < value[1].len) {
|
|
|
|
if (value[1].data[i] != ' ') {
|
|
|
|
len++;
|
|
|
|
continue;
|
|
|
|
}
|
2003-04-28 23:06:39 +08:00
|
|
|
|
2003-05-07 01:03:16 +08:00
|
|
|
if (value[1].data[i] == ' ' && len == 0) {
|
|
|
|
start = &value[1].data[i + 1];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2003-04-28 23:06:39 +08:00
|
|
|
|
2003-05-07 01:03:16 +08:00
|
|
|
if (len == 0) {
|
|
|
|
break;
|
|
|
|
}
|
2003-04-28 23:06:39 +08:00
|
|
|
|
2003-05-07 01:03:16 +08:00
|
|
|
last = value[1].data[i - 1];
|
2003-04-28 23:06:39 +08:00
|
|
|
|
2003-05-07 01:03:16 +08:00
|
|
|
switch (last) {
|
|
|
|
case 'm':
|
|
|
|
len--;
|
|
|
|
max = 35791;
|
|
|
|
scale = 1000 * 60;
|
|
|
|
break;
|
2003-04-28 23:06:39 +08:00
|
|
|
|
2003-05-07 01:03:16 +08:00
|
|
|
case 'h':
|
|
|
|
len--;
|
|
|
|
max = 596;
|
|
|
|
scale = 1000 * 60 * 60;
|
|
|
|
break;
|
2003-04-28 23:06:39 +08:00
|
|
|
|
2003-05-07 01:03:16 +08:00
|
|
|
case 'd':
|
|
|
|
len--;
|
|
|
|
max = 24;
|
|
|
|
scale = 1000 * 60 * 60 * 24;
|
|
|
|
break;
|
2003-04-28 23:06:39 +08:00
|
|
|
|
2003-05-07 01:03:16 +08:00
|
|
|
case 's':
|
2003-04-28 23:06:39 +08:00
|
|
|
len--;
|
2003-05-07 01:03:16 +08:00
|
|
|
if (value[1].data[i - 2] == 'm') {
|
|
|
|
len--;
|
|
|
|
max = 2147483647;
|
|
|
|
scale = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall thru */
|
2003-04-28 23:06:39 +08:00
|
|
|
|
2003-05-07 01:03:16 +08:00
|
|
|
default:
|
|
|
|
max = 2147483;
|
2003-04-28 23:06:39 +08:00
|
|
|
scale = 1000;
|
|
|
|
}
|
|
|
|
|
2003-05-07 01:03:16 +08:00
|
|
|
size = ngx_atoi(start, len);
|
|
|
|
if (size < 0) {
|
|
|
|
return "invalid value";
|
|
|
|
}
|
2003-04-28 23:06:39 +08:00
|
|
|
|
2003-05-07 01:03:16 +08:00
|
|
|
if ((u_int) size > max) {
|
|
|
|
return "value must be less than 597 hours";
|
|
|
|
}
|
|
|
|
|
|
|
|
total += size * scale;
|
|
|
|
|
|
|
|
if (i >= value[1].len) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
start = &value[1].data[i + 1];
|
2002-12-26 15:24:21 +08:00
|
|
|
}
|
2002-09-16 23:01:44 +08:00
|
|
|
|
2003-05-30 22:27:59 +08:00
|
|
|
*(int *) (p + cmd->offset) = total;
|
2003-04-28 23:06:39 +08:00
|
|
|
|
2003-05-07 01:03:16 +08:00
|
|
|
return NGX_CONF_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-27 20:18:54 +08:00
|
|
|
char *ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
2003-05-07 01:03:16 +08:00
|
|
|
{
|
2003-05-30 22:27:59 +08:00
|
|
|
char *p = conf;
|
|
|
|
|
2003-05-15 23:42:53 +08:00
|
|
|
int size, total, len, scale;
|
|
|
|
u_int max, i;
|
2003-05-07 01:03:16 +08:00
|
|
|
char last, *start;
|
|
|
|
ngx_str_t *value;
|
|
|
|
|
2003-05-30 22:27:59 +08:00
|
|
|
if (*(int *) (p + cmd->offset) != NGX_CONF_UNSET) {
|
2003-05-20 23:37:55 +08:00
|
|
|
return "is duplicate";
|
|
|
|
}
|
|
|
|
|
2003-05-07 01:03:16 +08:00
|
|
|
value = (ngx_str_t *) cf->args->elts;
|
|
|
|
start = value[1].data;
|
|
|
|
len = 0;
|
|
|
|
total = 0;
|
|
|
|
|
|
|
|
for (i = 0; /* void */ ; i++) {
|
|
|
|
|
|
|
|
if (i < value[1].len) {
|
|
|
|
if (value[1].data[i] != ' ') {
|
|
|
|
len++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value[1].data[i] == ' ' && len == 0) {
|
|
|
|
start = &value[1].data[i + 1];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
last = value[1].data[i - 1];
|
|
|
|
|
|
|
|
switch (last) {
|
|
|
|
case 'm':
|
|
|
|
len--;
|
|
|
|
max = 35791394;
|
|
|
|
scale = 60;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'h':
|
|
|
|
len--;
|
|
|
|
max = 596523;
|
|
|
|
scale = 60 * 60;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
len--;
|
|
|
|
max = 24855;
|
|
|
|
scale = 60 * 60 * 24;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'w':
|
|
|
|
len--;
|
|
|
|
max = 3550;
|
|
|
|
scale = 60 * 60 * 24 * 7;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'M':
|
|
|
|
len--;
|
|
|
|
max = 828;
|
|
|
|
scale = 60 * 60 * 24 * 30;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'y':
|
|
|
|
len--;
|
|
|
|
max = 68;
|
|
|
|
scale = 60 * 60 * 24 * 365;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
len--;
|
|
|
|
/* fall thru */
|
|
|
|
|
|
|
|
default:
|
|
|
|
max = 2147483647;
|
|
|
|
scale = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = ngx_atoi(start, len);
|
|
|
|
if (size < 0) {
|
|
|
|
return "invalid value";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((u_int) size > max) {
|
|
|
|
return "value must be less than 68 years";
|
|
|
|
}
|
|
|
|
|
|
|
|
total += size * scale;
|
|
|
|
|
|
|
|
if (i >= value[1].len) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
start = &value[1].data[i + 1];
|
|
|
|
}
|
|
|
|
|
2003-05-30 22:27:59 +08:00
|
|
|
*(int *) (p + cmd->offset) = total;
|
2002-12-26 15:24:21 +08:00
|
|
|
|
2003-01-09 13:36:00 +08:00
|
|
|
return NGX_CONF_OK;
|
2002-09-16 23:01:44 +08:00
|
|
|
}
|
2003-03-04 14:33:48 +08:00
|
|
|
|
2003-05-07 01:03:16 +08:00
|
|
|
|
2003-10-08 23:32:54 +08:00
|
|
|
char *ngx_conf_set_bufs_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
|
|
{
|
|
|
|
char *p = conf;
|
|
|
|
|
|
|
|
int len, scale;
|
|
|
|
char last;
|
|
|
|
ngx_str_t *value;
|
|
|
|
ngx_bufs_t *bufs;
|
|
|
|
|
|
|
|
|
|
|
|
bufs = (ngx_bufs_t *) (p + cmd->offset);
|
|
|
|
|
|
|
|
if (bufs->num) {
|
|
|
|
return "is duplicate";
|
|
|
|
}
|
|
|
|
|
|
|
|
value = (ngx_str_t *) cf->args->elts;
|
|
|
|
|
|
|
|
bufs->num = ngx_atoi(value[1].data, value[1].len);
|
|
|
|
if (bufs->num == NGX_ERROR || bufs->num == 0) {
|
|
|
|
return "invalid value";
|
|
|
|
}
|
|
|
|
|
|
|
|
len = value[2].len;
|
|
|
|
last = value[2].data[len - 1];
|
|
|
|
|
|
|
|
switch (last) {
|
|
|
|
case 'K':
|
|
|
|
case 'k':
|
|
|
|
len--;
|
|
|
|
scale = 1024;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'M':
|
|
|
|
case 'm':
|
|
|
|
len--;
|
|
|
|
scale = 1024 * 1024;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
scale = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bufs->size = ngx_atoi(value[2].data, len);
|
|
|
|
if (bufs->size == NGX_ERROR || bufs->size == 0) {
|
|
|
|
return "invalid value";
|
|
|
|
}
|
|
|
|
|
|
|
|
bufs->size *= scale;
|
|
|
|
|
|
|
|
return NGX_CONF_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-27 20:18:54 +08:00
|
|
|
char *ngx_conf_unsupported(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
2003-03-04 14:33:48 +08:00
|
|
|
{
|
|
|
|
return "unsupported on this platform";
|
|
|
|
}
|