Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 1 | |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 2 | /* |
Igor Sysoev | ff8da91 | 2004-09-29 16:00:49 +0000 | [diff] [blame] | 3 | * Copyright (C) Igor Sysoev |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 7 | #include <ngx_config.h> |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 8 | #include <ngx_core.h> |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 9 | |
| 10 | |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 11 | static ngx_int_t ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last); |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 12 | static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf); |
Igor Sysoev | ab517d5 | 2004-05-18 15:29:08 +0000 | [diff] [blame] | 13 | static char *ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
Igor Sysoev | 697d1ae | 2005-10-27 15:46:13 +0000 | [diff] [blame] | 14 | static void ngx_conf_flush_files(ngx_cycle_t *cycle); |
Igor Sysoev | ab517d5 | 2004-05-18 15:29:08 +0000 | [diff] [blame] | 15 | |
| 16 | |
| 17 | static ngx_command_t ngx_conf_commands[] = { |
| 18 | |
| 19 | { ngx_string("include"), |
| 20 | NGX_ANY_CONF|NGX_CONF_TAKE1, |
| 21 | ngx_conf_include, |
| 22 | 0, |
| 23 | 0, |
| 24 | NULL }, |
| 25 | |
| 26 | ngx_null_command |
| 27 | }; |
| 28 | |
| 29 | |
| 30 | ngx_module_t ngx_conf_module = { |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 31 | NGX_MODULE_V1, |
Igor Sysoev | ab517d5 | 2004-05-18 15:29:08 +0000 | [diff] [blame] | 32 | NULL, /* module context */ |
| 33 | ngx_conf_commands, /* module directives */ |
| 34 | NGX_CONF_MODULE, /* module type */ |
Igor Sysoev | e573380 | 2005-09-08 14:36:09 +0000 | [diff] [blame] | 35 | NULL, /* init master */ |
Igor Sysoev | ab517d5 | 2004-05-18 15:29:08 +0000 | [diff] [blame] | 36 | NULL, /* init module */ |
Igor Sysoev | e573380 | 2005-09-08 14:36:09 +0000 | [diff] [blame] | 37 | NULL, /* init process */ |
| 38 | NULL, /* init thread */ |
| 39 | NULL, /* exit thread */ |
Igor Sysoev | 697d1ae | 2005-10-27 15:46:13 +0000 | [diff] [blame] | 40 | ngx_conf_flush_files, /* exit process */ |
Igor Sysoev | e573380 | 2005-09-08 14:36:09 +0000 | [diff] [blame] | 41 | NULL, /* exit master */ |
| 42 | NGX_MODULE_V1_PADDING |
Igor Sysoev | ab517d5 | 2004-05-18 15:29:08 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | |
Igor Sysoev | ab517d5 | 2004-05-18 15:29:08 +0000 | [diff] [blame] | 46 | /* The ten fixed arguments */ |
Igor Sysoev | dc9dd43 | 2003-10-22 16:38:26 +0000 | [diff] [blame] | 47 | |
Igor Sysoev | a6e337f | 2008-08-26 21:04:06 +0000 | [diff] [blame] | 48 | static ngx_uint_t argument_number[] = { |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 49 | NGX_CONF_NOARGS, |
| 50 | NGX_CONF_TAKE1, |
Igor Sysoev | dc9dd43 | 2003-10-22 16:38:26 +0000 | [diff] [blame] | 51 | NGX_CONF_TAKE2, |
| 52 | NGX_CONF_TAKE3, |
| 53 | NGX_CONF_TAKE4, |
| 54 | NGX_CONF_TAKE5, |
| 55 | NGX_CONF_TAKE6, |
Igor Sysoev | 43f1319 | 2004-04-12 16:38:09 +0000 | [diff] [blame] | 56 | NGX_CONF_TAKE7 |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 59 | |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 60 | char * |
Igor Sysoev | b4fbdcf | 2008-06-30 12:35:16 +0000 | [diff] [blame] | 61 | ngx_conf_param(ngx_conf_t *cf) |
| 62 | { |
| 63 | ngx_str_t *param; |
| 64 | ngx_buf_t b; |
| 65 | ngx_conf_file_t conf_file; |
| 66 | |
| 67 | param = &cf->cycle->conf_param; |
| 68 | |
| 69 | if (param->len == 0) { |
| 70 | return NGX_CONF_OK; |
| 71 | } |
| 72 | |
| 73 | ngx_memzero(&conf_file, sizeof(ngx_conf_file_t)); |
| 74 | |
| 75 | ngx_memzero(&b, sizeof(ngx_buf_t)); |
| 76 | |
| 77 | b.start = param->data; |
| 78 | b.pos = param->data; |
| 79 | b.last = param->data + param->len; |
| 80 | b.end = b.last; |
| 81 | b.temporary = 1; |
| 82 | |
| 83 | conf_file.file.fd = NGX_INVALID_FILE; |
| 84 | conf_file.file.name.data = (u_char *) "command line"; |
| 85 | conf_file.line = 1; |
| 86 | |
| 87 | cf->conf_file = &conf_file; |
| 88 | cf->conf_file->buffer = &b; |
| 89 | |
| 90 | return ngx_conf_parse(cf, NULL); |
| 91 | } |
| 92 | |
| 93 | |
| 94 | char * |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 95 | ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 96 | { |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 97 | char *rv; |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 98 | ngx_fd_t fd; |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 99 | ngx_int_t rc; |
Igor Sysoev | 6d16e1e | 2006-04-05 13:40:54 +0000 | [diff] [blame] | 100 | ngx_buf_t *b; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 101 | ngx_conf_file_t *prev; |
Igor Sysoev | b4fbdcf | 2008-06-30 12:35:16 +0000 | [diff] [blame] | 102 | enum { |
| 103 | parse_file = 0, |
| 104 | parse_block, |
| 105 | parse_param |
| 106 | } type; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 107 | |
Igor Sysoev | 9d63952 | 2003-07-07 06:11:50 +0000 | [diff] [blame] | 108 | #if (NGX_SUPPRESS_WARN) |
| 109 | fd = NGX_INVALID_FILE; |
| 110 | prev = NULL; |
| 111 | #endif |
| 112 | |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 113 | if (filename) { |
| 114 | |
Igor Sysoev | bb4ec5c | 2003-05-16 15:27:48 +0000 | [diff] [blame] | 115 | /* open configuration file */ |
| 116 | |
Igor Sysoev | 50034b8 | 2007-01-18 20:15:09 +0000 | [diff] [blame] | 117 | fd = ngx_open_file(filename->data, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0); |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 118 | if (fd == NGX_INVALID_FILE) { |
Igor Sysoev | c31a9bb | 2005-11-26 10:11:11 +0000 | [diff] [blame] | 119 | ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 120 | ngx_open_file_n " \"%s\" failed", |
| 121 | filename->data); |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 122 | return NGX_CONF_ERROR; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 125 | prev = cf->conf_file; |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 126 | |
| 127 | cf->conf_file = ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)); |
| 128 | if (cf->conf_file == NULL) { |
Igor Sysoev | 369145c | 2004-05-28 15:49:23 +0000 | [diff] [blame] | 129 | return NGX_CONF_ERROR; |
| 130 | } |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 131 | |
Igor Sysoev | f2e676a | 2003-11-16 21:49:42 +0000 | [diff] [blame] | 132 | if (ngx_fd_info(fd, &cf->conf_file->file.info) == -1) { |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 133 | ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 134 | ngx_fd_info_n " \"%s\" failed", filename->data); |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Igor Sysoev | 6d16e1e | 2006-04-05 13:40:54 +0000 | [diff] [blame] | 137 | b = ngx_calloc_buf(cf->pool); |
| 138 | if (b == NULL) { |
Igor Sysoev | 369145c | 2004-05-28 15:49:23 +0000 | [diff] [blame] | 139 | return NGX_CONF_ERROR; |
| 140 | } |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 141 | |
Igor Sysoev | 6d16e1e | 2006-04-05 13:40:54 +0000 | [diff] [blame] | 142 | cf->conf_file->buffer = b; |
| 143 | |
| 144 | b->start = ngx_alloc(ngx_pagesize, cf->log); |
| 145 | if (b->start == NULL) { |
| 146 | return NGX_CONF_ERROR; |
| 147 | } |
| 148 | |
| 149 | b->pos = b->start; |
| 150 | b->last = b->start; |
| 151 | b->end = b->last + ngx_pagesize; |
| 152 | b->temporary = 1; |
| 153 | |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 154 | cf->conf_file->file.fd = fd; |
| 155 | cf->conf_file->file.name.len = filename->len; |
| 156 | cf->conf_file->file.name.data = filename->data; |
Igor Sysoev | 9d63952 | 2003-07-07 06:11:50 +0000 | [diff] [blame] | 157 | cf->conf_file->file.offset = 0; |
Igor Sysoev | bfb23bf | 2007-10-09 20:11:03 +0000 | [diff] [blame] | 158 | cf->conf_file->file.log = cf->log; |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 159 | cf->conf_file->line = 1; |
Igor Sysoev | 31eb8c0 | 2005-09-23 11:02:22 +0000 | [diff] [blame] | 160 | |
Igor Sysoev | b4fbdcf | 2008-06-30 12:35:16 +0000 | [diff] [blame] | 161 | type = parse_file; |
| 162 | |
| 163 | } else if (cf->conf_file->file.fd != NGX_INVALID_FILE) { |
| 164 | |
| 165 | type = parse_block; |
Igor Sysoev | 31eb8c0 | 2005-09-23 11:02:22 +0000 | [diff] [blame] | 166 | |
| 167 | } else { |
Igor Sysoev | b4fbdcf | 2008-06-30 12:35:16 +0000 | [diff] [blame] | 168 | type = parse_param; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Igor Sysoev | 31eb8c0 | 2005-09-23 11:02:22 +0000 | [diff] [blame] | 171 | |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 172 | for ( ;; ) { |
| 173 | rc = ngx_conf_read_token(cf); |
| 174 | |
Igor Sysoev | 369145c | 2004-05-28 15:49:23 +0000 | [diff] [blame] | 175 | /* |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 176 | * ngx_conf_read_token() may return |
Igor Sysoev | 31eb8c0 | 2005-09-23 11:02:22 +0000 | [diff] [blame] | 177 | * |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 178 | * NGX_ERROR there is error |
| 179 | * NGX_OK the token terminated by ";" was found |
| 180 | * NGX_CONF_BLOCK_START the token terminated by "{" was found |
| 181 | * NGX_CONF_BLOCK_DONE the "}" was found |
| 182 | * NGX_CONF_FILE_DONE the configuration file is done |
Igor Sysoev | 369145c | 2004-05-28 15:49:23 +0000 | [diff] [blame] | 183 | */ |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 184 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 185 | if (rc == NGX_ERROR) { |
Igor Sysoev | bb4c112 | 2007-02-20 14:36:48 +0000 | [diff] [blame] | 186 | goto done; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Igor Sysoev | 31eb8c0 | 2005-09-23 11:02:22 +0000 | [diff] [blame] | 189 | if (rc == NGX_CONF_BLOCK_DONE) { |
Igor Sysoev | eb03ea7 | 2008-06-25 14:56:14 +0000 | [diff] [blame] | 190 | |
Igor Sysoev | b4fbdcf | 2008-06-30 12:35:16 +0000 | [diff] [blame] | 191 | if (type != parse_block) { |
Igor Sysoev | 83fe662 | 2007-02-20 14:33:26 +0000 | [diff] [blame] | 192 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "unexpected \"}\""); |
Igor Sysoev | bb4c112 | 2007-02-20 14:36:48 +0000 | [diff] [blame] | 193 | goto failed; |
Igor Sysoev | 83fe662 | 2007-02-20 14:33:26 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Igor Sysoev | bb4c112 | 2007-02-20 14:36:48 +0000 | [diff] [blame] | 196 | goto done; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Igor Sysoev | eb03ea7 | 2008-06-25 14:56:14 +0000 | [diff] [blame] | 199 | if (rc == NGX_CONF_FILE_DONE) { |
| 200 | |
Igor Sysoev | b4fbdcf | 2008-06-30 12:35:16 +0000 | [diff] [blame] | 201 | if (type == parse_block) { |
Igor Sysoev | eb03ea7 | 2008-06-25 14:56:14 +0000 | [diff] [blame] | 202 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 203 | "unexpected end of file, expecting \"}\""); |
| 204 | goto failed; |
| 205 | } |
| 206 | |
| 207 | goto done; |
| 208 | } |
| 209 | |
Igor Sysoev | b4fbdcf | 2008-06-30 12:35:16 +0000 | [diff] [blame] | 210 | if (rc == NGX_CONF_BLOCK_START) { |
| 211 | |
| 212 | if (type == parse_param) { |
| 213 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 214 | "block directives are not supported " |
| 215 | "in -g option"); |
| 216 | goto failed; |
| 217 | } |
| 218 | } |
| 219 | |
Igor Sysoev | eb03ea7 | 2008-06-25 14:56:14 +0000 | [diff] [blame] | 220 | /* rc == NGX_OK || rc == NGX_CONF_BLOCK_START */ |
| 221 | |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 222 | if (cf->handler) { |
| 223 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 224 | /* |
| 225 | * the custom handler, i.e., that is used in the http's |
| 226 | * "types { ... }" directive |
| 227 | */ |
Igor Sysoev | bb4ec5c | 2003-05-16 15:27:48 +0000 | [diff] [blame] | 228 | |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 229 | rv = (*cf->handler)(cf, NULL, cf->handler_conf); |
| 230 | if (rv == NGX_CONF_OK) { |
| 231 | continue; |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 232 | } |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 233 | |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 234 | if (rv == NGX_CONF_ERROR) { |
Igor Sysoev | bb4c112 | 2007-02-20 14:36:48 +0000 | [diff] [blame] | 235 | goto failed; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 236 | } |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 237 | |
Igor Sysoev | 40460ba | 2007-02-20 15:47:54 +0000 | [diff] [blame] | 238 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, rv); |
Igor Sysoev | bb4c112 | 2007-02-20 14:36:48 +0000 | [diff] [blame] | 239 | |
| 240 | goto failed; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 241 | } |
Igor Sysoev | 8e1fbe6 | 2003-07-18 14:44:05 +0000 | [diff] [blame] | 242 | |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 243 | |
| 244 | rc = ngx_conf_handler(cf, rc); |
| 245 | |
Igor Sysoev | 8e1fbe6 | 2003-07-18 14:44:05 +0000 | [diff] [blame] | 246 | if (rc == NGX_ERROR) { |
Igor Sysoev | bb4c112 | 2007-02-20 14:36:48 +0000 | [diff] [blame] | 247 | goto failed; |
Igor Sysoev | 8e1fbe6 | 2003-07-18 14:44:05 +0000 | [diff] [blame] | 248 | } |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 249 | } |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 250 | |
Igor Sysoev | bb4c112 | 2007-02-20 14:36:48 +0000 | [diff] [blame] | 251 | failed: |
| 252 | |
| 253 | rc = NGX_ERROR; |
| 254 | |
| 255 | done: |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 256 | |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 257 | if (filename) { |
Igor Sysoev | 6d16e1e | 2006-04-05 13:40:54 +0000 | [diff] [blame] | 258 | ngx_free(cf->conf_file->buffer->start); |
Igor Sysoev | d3283ff | 2005-12-05 13:18:09 +0000 | [diff] [blame] | 259 | |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 260 | cf->conf_file = prev; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 261 | |
| 262 | if (ngx_close_file(fd) == NGX_FILE_ERROR) { |
Igor Sysoev | bb4ec5c | 2003-05-16 15:27:48 +0000 | [diff] [blame] | 263 | ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno, |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 264 | ngx_close_file_n " %s failed", |
| 265 | cf->conf_file->file.name.data); |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 266 | return NGX_CONF_ERROR; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | |
Igor Sysoev | 9d63952 | 2003-07-07 06:11:50 +0000 | [diff] [blame] | 270 | if (rc == NGX_ERROR) { |
| 271 | return NGX_CONF_ERROR; |
| 272 | } |
| 273 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 274 | return NGX_CONF_OK; |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 275 | } |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 276 | |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 277 | |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 278 | static ngx_int_t |
| 279 | ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last) |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 280 | { |
| 281 | char *rv; |
| 282 | void *conf, **confp; |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 283 | ngx_uint_t i, multi; |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 284 | ngx_str_t *name; |
| 285 | ngx_command_t *cmd; |
| 286 | |
| 287 | name = cf->args->elts; |
| 288 | |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 289 | multi = 0; |
| 290 | |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 291 | for (i = 0; ngx_modules[i]; i++) { |
| 292 | |
| 293 | /* look up the directive in the appropriate modules */ |
| 294 | |
| 295 | if (ngx_modules[i]->type != NGX_CONF_MODULE |
| 296 | && ngx_modules[i]->type != cf->module_type) |
| 297 | { |
| 298 | continue; |
| 299 | } |
| 300 | |
| 301 | cmd = ngx_modules[i]->commands; |
| 302 | if (cmd == NULL) { |
| 303 | continue; |
| 304 | } |
| 305 | |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 306 | for ( /* void */ ; cmd->name.len; cmd++) { |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 307 | |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 308 | if (name->len != cmd->name.len) { |
| 309 | continue; |
| 310 | } |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 311 | |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 312 | if (ngx_strcmp(name->data, cmd->name.data) != 0) { |
| 313 | continue; |
| 314 | } |
| 315 | |
| 316 | |
| 317 | /* is the directive's location right ? */ |
| 318 | |
| 319 | if (!(cmd->type & cf->cmd_type)) { |
| 320 | if (cmd->type & NGX_CONF_MULTI) { |
| 321 | multi = 1; |
| 322 | continue; |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 325 | goto not_allowed; |
| 326 | } |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 327 | |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 328 | if (!(cmd->type & NGX_CONF_BLOCK) && last != NGX_OK) { |
Igor Sysoev | 40460ba | 2007-02-20 15:47:54 +0000 | [diff] [blame] | 329 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 330 | "directive \"%s\" is not terminated by \";\"", |
| 331 | name->data); |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 332 | return NGX_ERROR; |
| 333 | } |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 334 | |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 335 | if ((cmd->type & NGX_CONF_BLOCK) && last != NGX_CONF_BLOCK_START) { |
Igor Sysoev | 40460ba | 2007-02-20 15:47:54 +0000 | [diff] [blame] | 336 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 337 | "directive \"%s\" has no opening \"{\"", |
| 338 | name->data); |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 339 | return NGX_ERROR; |
| 340 | } |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 341 | |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 342 | /* is the directive's argument count right ? */ |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 343 | |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 344 | if (!(cmd->type & NGX_CONF_ANY)) { |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 345 | |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 346 | if (cmd->type & NGX_CONF_FLAG) { |
| 347 | |
| 348 | if (cf->args->nelts != 2) { |
| 349 | goto invalid; |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | } else if (cmd->type & NGX_CONF_1MORE) { |
| 353 | |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 354 | if (cf->args->nelts < 2) { |
| 355 | goto invalid; |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | } else if (cmd->type & NGX_CONF_2MORE) { |
| 359 | |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 360 | if (cf->args->nelts < 3) { |
| 361 | goto invalid; |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 362 | } |
| 363 | |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 364 | } else if (cf->args->nelts > NGX_CONF_MAX_ARGS) { |
| 365 | |
| 366 | goto invalid; |
| 367 | |
| 368 | } else if (!(cmd->type & argument_number[cf->args->nelts - 1])) |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 369 | { |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 370 | goto invalid; |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 371 | } |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 372 | } |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 373 | |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 374 | /* set up the directive's configuration context */ |
| 375 | |
| 376 | conf = NULL; |
| 377 | |
| 378 | if (cmd->type & NGX_DIRECT_CONF) { |
| 379 | conf = ((void **) cf->ctx)[ngx_modules[i]->index]; |
| 380 | |
| 381 | } else if (cmd->type & NGX_MAIN_CONF) { |
| 382 | conf = &(((void **) cf->ctx)[ngx_modules[i]->index]); |
| 383 | |
| 384 | } else if (cf->ctx) { |
| 385 | confp = *(void **) ((char *) cf->ctx + cmd->conf); |
| 386 | |
| 387 | if (confp) { |
| 388 | conf = confp[ngx_modules[i]->ctx_index]; |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 389 | } |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 390 | } |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 391 | |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 392 | rv = cmd->set(cf, cmd, conf); |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 393 | |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 394 | if (rv == NGX_CONF_OK) { |
| 395 | return NGX_OK; |
| 396 | } |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 397 | |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 398 | if (rv == NGX_CONF_ERROR) { |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 399 | return NGX_ERROR; |
| 400 | } |
| 401 | |
Igor Sysoev | 40460ba | 2007-02-20 15:47:54 +0000 | [diff] [blame] | 402 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
Igor Sysoev | 1849ba8 | 2007-06-05 11:55:39 +0000 | [diff] [blame] | 403 | "\"%s\" directive %s", name->data, rv); |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 404 | |
| 405 | return NGX_ERROR; |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 406 | } |
| 407 | } |
| 408 | |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 409 | if (multi == 0) { |
Igor Sysoev | 40460ba | 2007-02-20 15:47:54 +0000 | [diff] [blame] | 410 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 411 | "unknown directive \"%s\"", name->data); |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 412 | |
| 413 | return NGX_ERROR; |
| 414 | } |
| 415 | |
| 416 | not_allowed: |
| 417 | |
Igor Sysoev | 40460ba | 2007-02-20 15:47:54 +0000 | [diff] [blame] | 418 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
Igor Sysoev | 1849ba8 | 2007-06-05 11:55:39 +0000 | [diff] [blame] | 419 | "\"%s\" directive is not allowed here", name->data); |
Igor Sysoev | ac72bd1 | 2006-05-04 15:32:46 +0000 | [diff] [blame] | 420 | return NGX_ERROR; |
| 421 | |
| 422 | invalid: |
| 423 | |
Igor Sysoev | 40460ba | 2007-02-20 15:47:54 +0000 | [diff] [blame] | 424 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
Igor Sysoev | e7e7ded | 2007-08-31 06:15:50 +0000 | [diff] [blame] | 425 | "invalid number of arguments in \"%s\" directive", |
Igor Sysoev | 40460ba | 2007-02-20 15:47:54 +0000 | [diff] [blame] | 426 | name->data); |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 427 | |
| 428 | return NGX_ERROR; |
| 429 | } |
| 430 | |
| 431 | |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 432 | static ngx_int_t |
| 433 | ngx_conf_read_token(ngx_conf_t *cf) |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 434 | { |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 435 | u_char *start, ch, *src, *dst; |
Igor Sysoev | a6e337f | 2008-08-26 21:04:06 +0000 | [diff] [blame] | 436 | size_t len; |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 437 | ssize_t n; |
Igor Sysoev | a6e337f | 2008-08-26 21:04:06 +0000 | [diff] [blame] | 438 | ngx_uint_t found, need_space, last_space, sharp_comment, variable; |
Igor Sysoev | 6d09950 | 2008-08-26 21:10:20 +0000 | [diff] [blame] | 439 | ngx_uint_t quoted, s_quoted, d_quoted, start_line; |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 440 | ngx_str_t *word; |
Igor Sysoev | 369145c | 2004-05-28 15:49:23 +0000 | [diff] [blame] | 441 | ngx_buf_t *b; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 442 | |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 443 | found = 0; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 444 | need_space = 0; |
| 445 | last_space = 1; |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 446 | sharp_comment = 0; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 447 | variable = 0; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 448 | quoted = s_quoted = d_quoted = 0; |
| 449 | |
| 450 | cf->args->nelts = 0; |
Igor Sysoev | 369145c | 2004-05-28 15:49:23 +0000 | [diff] [blame] | 451 | b = cf->conf_file->buffer; |
| 452 | start = b->pos; |
Igor Sysoev | 6d09950 | 2008-08-26 21:10:20 +0000 | [diff] [blame] | 453 | start_line = cf->conf_file->line; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 454 | |
Igor Sysoev | 295bb63 | 2002-12-23 18:22:18 +0000 | [diff] [blame] | 455 | for ( ;; ) { |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 456 | |
Igor Sysoev | 369145c | 2004-05-28 15:49:23 +0000 | [diff] [blame] | 457 | if (b->pos >= b->last) { |
Igor Sysoev | b4fbdcf | 2008-06-30 12:35:16 +0000 | [diff] [blame] | 458 | |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 459 | if (cf->conf_file->file.offset |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 460 | >= ngx_file_size(&cf->conf_file->file.info)) |
| 461 | { |
| 462 | if (cf->args->nelts > 0) { |
Igor Sysoev | b4fbdcf | 2008-06-30 12:35:16 +0000 | [diff] [blame] | 463 | |
| 464 | if (cf->conf_file->file.fd == NGX_INVALID_FILE) { |
| 465 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 466 | "unexpected end of parameter, " |
| 467 | "expecting \";\""); |
| 468 | return NGX_ERROR; |
| 469 | } |
| 470 | |
Igor Sysoev | 40460ba | 2007-02-20 15:47:54 +0000 | [diff] [blame] | 471 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 472 | "unexpected end of file, " |
| 473 | "expecting \";\" or \"}\""); |
Igor Sysoev | aa82861 | 2005-02-09 14:31:07 +0000 | [diff] [blame] | 474 | return NGX_ERROR; |
| 475 | } |
| 476 | |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 477 | return NGX_CONF_FILE_DONE; |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Igor Sysoev | 6d09950 | 2008-08-26 21:10:20 +0000 | [diff] [blame] | 480 | len = b->pos - start; |
| 481 | |
| 482 | if (len == ngx_pagesize) { |
| 483 | cf->conf_file->line = start_line; |
| 484 | |
Igor Sysoev | c48f49f | 2008-08-27 12:19:07 +0000 | [diff] [blame^] | 485 | if (d_quoted) { |
| 486 | ch = '"'; |
| 487 | |
| 488 | } else if (s_quoted) { |
| 489 | ch = '\''; |
| 490 | |
| 491 | } else { |
| 492 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 493 | "too long parameter \"%*s...\" started", |
| 494 | 10, start); |
| 495 | return NGX_ERROR; |
| 496 | } |
| 497 | |
Igor Sysoev | 6d09950 | 2008-08-26 21:10:20 +0000 | [diff] [blame] | 498 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
Igor Sysoev | c48f49f | 2008-08-27 12:19:07 +0000 | [diff] [blame^] | 499 | "too long parameter, probably " |
| 500 | "missing terminating \"%c\" character", ch); |
Igor Sysoev | 6d09950 | 2008-08-26 21:10:20 +0000 | [diff] [blame] | 501 | return NGX_ERROR; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 502 | } |
| 503 | |
Igor Sysoev | 6d09950 | 2008-08-26 21:10:20 +0000 | [diff] [blame] | 504 | if (len) { |
| 505 | ngx_memcpy(b->start, start, len); |
| 506 | } |
| 507 | |
| 508 | n = ngx_read_file(&cf->conf_file->file, b->start + len, |
| 509 | b->end - (b->start + len), |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 510 | cf->conf_file->file.offset); |
| 511 | |
| 512 | if (n == NGX_ERROR) { |
| 513 | return NGX_ERROR; |
| 514 | } |
| 515 | |
Igor Sysoev | 6d09950 | 2008-08-26 21:10:20 +0000 | [diff] [blame] | 516 | b->pos = b->start + len; |
Igor Sysoev | 369145c | 2004-05-28 15:49:23 +0000 | [diff] [blame] | 517 | b->last = b->pos + n; |
Igor Sysoev | 6d09950 | 2008-08-26 21:10:20 +0000 | [diff] [blame] | 518 | start = b->start; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 519 | } |
| 520 | |
Igor Sysoev | 369145c | 2004-05-28 15:49:23 +0000 | [diff] [blame] | 521 | ch = *b->pos++; |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 522 | |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 523 | if (ch == LF) { |
| 524 | cf->conf_file->line++; |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 525 | |
| 526 | if (sharp_comment) { |
| 527 | sharp_comment = 0; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | if (sharp_comment) { |
| 532 | continue; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 533 | } |
| 534 | |
Igor Sysoev | 295bb63 | 2002-12-23 18:22:18 +0000 | [diff] [blame] | 535 | if (quoted) { |
| 536 | quoted = 0; |
| 537 | continue; |
| 538 | } |
| 539 | |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 540 | if (need_space) { |
| 541 | if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) { |
| 542 | last_space = 1; |
| 543 | need_space = 0; |
| 544 | continue; |
| 545 | } |
| 546 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 547 | if (ch == ';') { |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 548 | return NGX_OK; |
| 549 | } |
| 550 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 551 | if (ch == '{') { |
| 552 | return NGX_CONF_BLOCK_START; |
| 553 | } |
| 554 | |
Igor Sysoev | c31a9bb | 2005-11-26 10:11:11 +0000 | [diff] [blame] | 555 | if (ch == ')') { |
| 556 | last_space = 1; |
| 557 | need_space = 0; |
Igor Sysoev | 7832933 | 2003-11-10 17:17:31 +0000 | [diff] [blame] | 558 | |
Igor Sysoev | c31a9bb | 2005-11-26 10:11:11 +0000 | [diff] [blame] | 559 | } else { |
Igor Sysoev | 40460ba | 2007-02-20 15:47:54 +0000 | [diff] [blame] | 560 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 561 | "unexpected \"%c\"", ch); |
Igor Sysoev | c31a9bb | 2005-11-26 10:11:11 +0000 | [diff] [blame] | 562 | return NGX_ERROR; |
| 563 | } |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 564 | } |
| 565 | |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 566 | if (last_space) { |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 567 | if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) { |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 568 | continue; |
| 569 | } |
| 570 | |
Igor Sysoev | 369145c | 2004-05-28 15:49:23 +0000 | [diff] [blame] | 571 | start = b->pos - 1; |
Igor Sysoev | 6d09950 | 2008-08-26 21:10:20 +0000 | [diff] [blame] | 572 | start_line = cf->conf_file->line; |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 573 | |
| 574 | switch (ch) { |
| 575 | |
Igor Sysoev | 295bb63 | 2002-12-23 18:22:18 +0000 | [diff] [blame] | 576 | case ';': |
| 577 | case '{': |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 578 | if (cf->args->nelts == 0) { |
Igor Sysoev | 40460ba | 2007-02-20 15:47:54 +0000 | [diff] [blame] | 579 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 580 | "unexpected \"%c\"", ch); |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 581 | return NGX_ERROR; |
| 582 | } |
| 583 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 584 | if (ch == '{') { |
| 585 | return NGX_CONF_BLOCK_START; |
| 586 | } |
| 587 | |
Igor Sysoev | 295bb63 | 2002-12-23 18:22:18 +0000 | [diff] [blame] | 588 | return NGX_OK; |
| 589 | |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 590 | case '}': |
Igor Sysoev | 4959ec4 | 2005-05-23 12:07:45 +0000 | [diff] [blame] | 591 | if (cf->args->nelts != 0) { |
Igor Sysoev | 40460ba | 2007-02-20 15:47:54 +0000 | [diff] [blame] | 592 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 593 | "unexpected \"}\""); |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 594 | return NGX_ERROR; |
| 595 | } |
| 596 | |
| 597 | return NGX_CONF_BLOCK_DONE; |
| 598 | |
| 599 | case '#': |
| 600 | sharp_comment = 1; |
| 601 | continue; |
| 602 | |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 603 | case '\\': |
| 604 | quoted = 1; |
| 605 | last_space = 0; |
| 606 | continue; |
| 607 | |
| 608 | case '"': |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 609 | start++; |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 610 | d_quoted = 1; |
| 611 | last_space = 0; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 612 | continue; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 613 | |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 614 | case '\'': |
| 615 | start++; |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 616 | s_quoted = 1; |
| 617 | last_space = 0; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 618 | continue; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 619 | |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 620 | default: |
| 621 | last_space = 0; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | } else { |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 625 | if (ch == '{' && variable) { |
| 626 | continue; |
| 627 | } |
| 628 | |
| 629 | variable = 0; |
| 630 | |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 631 | if (ch == '\\') { |
| 632 | quoted = 1; |
| 633 | continue; |
| 634 | } |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 635 | |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 636 | if (ch == '$') { |
| 637 | variable = 1; |
| 638 | continue; |
| 639 | } |
| 640 | |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 641 | if (d_quoted) { |
| 642 | if (ch == '"') { |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 643 | d_quoted = 0; |
| 644 | need_space = 1; |
| 645 | found = 1; |
| 646 | } |
| 647 | |
| 648 | } else if (s_quoted) { |
| 649 | if (ch == '\'') { |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 650 | s_quoted = 0; |
| 651 | need_space = 1; |
| 652 | found = 1; |
| 653 | } |
| 654 | |
| 655 | } else if (ch == ' ' || ch == '\t' || ch == CR || ch == LF |
| 656 | || ch == ';' || ch == '{') { |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 657 | last_space = 1; |
| 658 | found = 1; |
| 659 | } |
| 660 | |
| 661 | if (found) { |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 662 | word = ngx_array_push(cf->args); |
| 663 | if (word == NULL) { |
Igor Sysoev | 369145c | 2004-05-28 15:49:23 +0000 | [diff] [blame] | 664 | return NGX_ERROR; |
| 665 | } |
| 666 | |
Igor Sysoev | 7f6b2ff | 2008-06-17 15:00:30 +0000 | [diff] [blame] | 667 | word->data = ngx_pnalloc(cf->pool, b->pos - start + 1); |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 668 | if (word->data == NULL) { |
Igor Sysoev | 369145c | 2004-05-28 15:49:23 +0000 | [diff] [blame] | 669 | return NGX_ERROR; |
| 670 | } |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 671 | |
Igor Sysoev | 295bb63 | 2002-12-23 18:22:18 +0000 | [diff] [blame] | 672 | for (dst = word->data, src = start, len = 0; |
Igor Sysoev | 369145c | 2004-05-28 15:49:23 +0000 | [diff] [blame] | 673 | src < b->pos - 1; |
Igor Sysoev | 295bb63 | 2002-12-23 18:22:18 +0000 | [diff] [blame] | 674 | len++) |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 675 | { |
| 676 | if (*src == '\\') { |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 677 | switch (src[1]) { |
| 678 | case '"': |
| 679 | case '\'': |
| 680 | case '\\': |
| 681 | src++; |
| 682 | break; |
| 683 | |
| 684 | case 't': |
| 685 | *dst++ = '\t'; |
| 686 | src += 2; |
| 687 | continue; |
| 688 | |
| 689 | case 'r': |
| 690 | *dst++ = '\r'; |
| 691 | src += 2; |
| 692 | continue; |
| 693 | |
| 694 | case 'n': |
| 695 | *dst++ = '\n'; |
| 696 | src += 2; |
| 697 | continue; |
| 698 | } |
| 699 | |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 700 | } |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 701 | *dst++ = *src++; |
| 702 | } |
| 703 | *dst = '\0'; |
Igor Sysoev | 295bb63 | 2002-12-23 18:22:18 +0000 | [diff] [blame] | 704 | word->len = len; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 705 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 706 | if (ch == ';') { |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 707 | return NGX_OK; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 708 | } |
| 709 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 710 | if (ch == '{') { |
| 711 | return NGX_CONF_BLOCK_START; |
| 712 | } |
| 713 | |
Igor Sysoev | a6717c4 | 2002-12-23 06:29:22 +0000 | [diff] [blame] | 714 | found = 0; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 715 | } |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | } |
| 719 | |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 720 | |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 721 | static char * |
| 722 | ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | ab517d5 | 2004-05-18 15:29:08 +0000 | [diff] [blame] | 723 | { |
Igor Sysoev | 97c2f46 | 2006-10-02 08:46:45 +0000 | [diff] [blame] | 724 | char *rv; |
| 725 | ngx_int_t n; |
Igor Sysoev | 85d6a3e | 2008-03-03 17:12:05 +0000 | [diff] [blame] | 726 | ngx_str_t *value, file, name; |
Igor Sysoev | 97c2f46 | 2006-10-02 08:46:45 +0000 | [diff] [blame] | 727 | ngx_glob_t gl; |
Igor Sysoev | ab517d5 | 2004-05-18 15:29:08 +0000 | [diff] [blame] | 728 | |
| 729 | value = cf->args->elts; |
Igor Sysoev | 6d2a14a | 2004-09-27 16:03:21 +0000 | [diff] [blame] | 730 | file = value[1]; |
Igor Sysoev | ab517d5 | 2004-05-18 15:29:08 +0000 | [diff] [blame] | 731 | |
Igor Sysoev | 97c2f46 | 2006-10-02 08:46:45 +0000 | [diff] [blame] | 732 | ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data); |
| 733 | |
Igor Sysoev | a1df416 | 2007-07-29 18:05:45 +0000 | [diff] [blame] | 734 | if (ngx_conf_full_name(cf->cycle, &file, 1) == NGX_ERROR) { |
Igor Sysoev | ab517d5 | 2004-05-18 15:29:08 +0000 | [diff] [blame] | 735 | return NGX_CONF_ERROR; |
| 736 | } |
| 737 | |
Igor Sysoev | a13b3b9 | 2008-04-29 09:28:42 +0000 | [diff] [blame] | 738 | if (strpbrk((char *) file.data, "*?[") == NULL) { |
| 739 | |
| 740 | ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data); |
| 741 | |
| 742 | return ngx_conf_parse(cf, &file); |
| 743 | } |
| 744 | |
Igor Sysoev | 97c2f46 | 2006-10-02 08:46:45 +0000 | [diff] [blame] | 745 | ngx_memzero(&gl, sizeof(ngx_glob_t)); |
Igor Sysoev | ab517d5 | 2004-05-18 15:29:08 +0000 | [diff] [blame] | 746 | |
Igor Sysoev | 97c2f46 | 2006-10-02 08:46:45 +0000 | [diff] [blame] | 747 | gl.pattern = file.data; |
| 748 | gl.log = cf->log; |
Igor Sysoev | a13b3b9 | 2008-04-29 09:28:42 +0000 | [diff] [blame] | 749 | gl.test = 1; |
Igor Sysoev | 97c2f46 | 2006-10-02 08:46:45 +0000 | [diff] [blame] | 750 | |
| 751 | if (ngx_open_glob(&gl) != NGX_OK) { |
| 752 | ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, |
| 753 | ngx_open_glob_n " \"%s\" failed", file.data); |
| 754 | return NGX_CONF_ERROR; |
| 755 | } |
| 756 | |
| 757 | rv = NGX_CONF_OK; |
| 758 | |
| 759 | for ( ;; ) { |
Igor Sysoev | 85d6a3e | 2008-03-03 17:12:05 +0000 | [diff] [blame] | 760 | n = ngx_read_glob(&gl, &name); |
Igor Sysoev | 97c2f46 | 2006-10-02 08:46:45 +0000 | [diff] [blame] | 761 | |
| 762 | if (n != NGX_OK) { |
| 763 | break; |
| 764 | } |
| 765 | |
Igor Sysoev | 85d6a3e | 2008-03-03 17:12:05 +0000 | [diff] [blame] | 766 | file.len = name.len++; |
| 767 | file.data = ngx_pstrdup(cf->pool, &name); |
| 768 | |
Igor Sysoev | 97c2f46 | 2006-10-02 08:46:45 +0000 | [diff] [blame] | 769 | ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data); |
| 770 | |
| 771 | rv = ngx_conf_parse(cf, &file); |
| 772 | |
| 773 | if (rv != NGX_CONF_OK) { |
| 774 | break; |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | ngx_close_glob(&gl); |
| 779 | |
| 780 | return rv; |
Igor Sysoev | ab517d5 | 2004-05-18 15:29:08 +0000 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 784 | ngx_int_t |
Igor Sysoev | a1df416 | 2007-07-29 18:05:45 +0000 | [diff] [blame] | 785 | ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name, ngx_uint_t conf_prefix) |
Igor Sysoev | 6d2a14a | 2004-09-27 16:03:21 +0000 | [diff] [blame] | 786 | { |
Igor Sysoev | a1df416 | 2007-07-29 18:05:45 +0000 | [diff] [blame] | 787 | size_t len; |
| 788 | u_char *p, *prefix; |
Igor Sysoev | 6d2a14a | 2004-09-27 16:03:21 +0000 | [diff] [blame] | 789 | ngx_str_t old; |
| 790 | |
| 791 | if (name->data[0] == '/') { |
| 792 | return NGX_OK; |
| 793 | } |
| 794 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 795 | #if (NGX_WIN32) |
| 796 | |
| 797 | if (name->len > 2 |
| 798 | && name->data[1] == ':' |
| 799 | && ((name->data[0] >= 'a' && name->data[0] <= 'z') |
| 800 | || (name->data[0] >= 'A' && name->data[0] <= 'Z'))) |
| 801 | { |
| 802 | return NGX_OK; |
| 803 | } |
| 804 | |
| 805 | #endif |
| 806 | |
Igor Sysoev | 6d2a14a | 2004-09-27 16:03:21 +0000 | [diff] [blame] | 807 | old = *name; |
| 808 | |
Igor Sysoev | a1df416 | 2007-07-29 18:05:45 +0000 | [diff] [blame] | 809 | if (conf_prefix) { |
| 810 | len = sizeof(NGX_CONF_PREFIX) - 1; |
| 811 | prefix = (u_char *) NGX_CONF_PREFIX; |
Igor Sysoev | 6d2a14a | 2004-09-27 16:03:21 +0000 | [diff] [blame] | 812 | |
Igor Sysoev | a1df416 | 2007-07-29 18:05:45 +0000 | [diff] [blame] | 813 | } else { |
| 814 | len = cycle->root.len; |
| 815 | prefix = cycle->root.data; |
| 816 | } |
| 817 | |
| 818 | name->len = len + old.len; |
Igor Sysoev | 7f6b2ff | 2008-06-17 15:00:30 +0000 | [diff] [blame] | 819 | name->data = ngx_pnalloc(cycle->pool, name->len + 1); |
Igor Sysoev | 9e58019 | 2006-02-01 18:22:15 +0000 | [diff] [blame] | 820 | if (name->data == NULL) { |
| 821 | return NGX_ERROR; |
Igor Sysoev | 6d2a14a | 2004-09-27 16:03:21 +0000 | [diff] [blame] | 822 | } |
| 823 | |
Igor Sysoev | a1df416 | 2007-07-29 18:05:45 +0000 | [diff] [blame] | 824 | p = ngx_cpymem(name->data, prefix, len); |
Igor Sysoev | 6d2a14a | 2004-09-27 16:03:21 +0000 | [diff] [blame] | 825 | ngx_cpystrn(p, old.data, old.len + 1); |
| 826 | |
| 827 | return NGX_OK; |
| 828 | } |
| 829 | |
| 830 | |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 831 | ngx_open_file_t * |
| 832 | ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name) |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 833 | { |
Igor Sysoev | 6d2a14a | 2004-09-27 16:03:21 +0000 | [diff] [blame] | 834 | ngx_str_t full; |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 835 | ngx_uint_t i; |
Igor Sysoev | b9e3441 | 2004-09-03 15:50:30 +0000 | [diff] [blame] | 836 | ngx_list_part_t *part; |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 837 | ngx_open_file_t *file; |
| 838 | |
Igor Sysoev | aad1b89 | 2004-10-03 20:02:06 +0000 | [diff] [blame] | 839 | #if (NGX_SUPPRESS_WARN) |
| 840 | full.len = 0; |
| 841 | full.data = NULL; |
| 842 | #endif |
| 843 | |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 844 | if (name) { |
Igor Sysoev | 6d2a14a | 2004-09-27 16:03:21 +0000 | [diff] [blame] | 845 | full = *name; |
| 846 | |
Igor Sysoev | a1df416 | 2007-07-29 18:05:45 +0000 | [diff] [blame] | 847 | if (ngx_conf_full_name(cycle, &full, 0) == NGX_ERROR) { |
Igor Sysoev | 6d2a14a | 2004-09-27 16:03:21 +0000 | [diff] [blame] | 848 | return NULL; |
| 849 | } |
| 850 | |
Igor Sysoev | b9e3441 | 2004-09-03 15:50:30 +0000 | [diff] [blame] | 851 | part = &cycle->open_files.part; |
| 852 | file = part->elts; |
| 853 | |
| 854 | for (i = 0; /* void */ ; i++) { |
| 855 | |
| 856 | if (i >= part->nelts) { |
| 857 | if (part->next == NULL) { |
| 858 | break; |
| 859 | } |
| 860 | part = part->next; |
| 861 | file = part->elts; |
| 862 | i = 0; |
| 863 | } |
| 864 | |
Igor Sysoev | 6d2a14a | 2004-09-27 16:03:21 +0000 | [diff] [blame] | 865 | if (full.len != file[i].name.len) { |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 866 | continue; |
| 867 | } |
| 868 | |
Igor Sysoev | 6d2a14a | 2004-09-27 16:03:21 +0000 | [diff] [blame] | 869 | if (ngx_strcmp(full.data, file[i].name.data) == 0) { |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 870 | return &file[i]; |
| 871 | } |
| 872 | } |
| 873 | } |
| 874 | |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 875 | file = ngx_list_push(&cycle->open_files); |
| 876 | if (file == NULL) { |
Igor Sysoev | 369145c | 2004-05-28 15:49:23 +0000 | [diff] [blame] | 877 | return NULL; |
| 878 | } |
| 879 | |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 880 | if (name) { |
Igor Sysoev | 4bed15b | 2004-09-30 19:44:38 +0000 | [diff] [blame] | 881 | file->fd = NGX_INVALID_FILE; |
Igor Sysoev | 6d2a14a | 2004-09-27 16:03:21 +0000 | [diff] [blame] | 882 | file->name = full; |
| 883 | |
Igor Sysoev | 980a924 | 2004-09-05 19:54:02 +0000 | [diff] [blame] | 884 | } else { |
Igor Sysoev | aad1b89 | 2004-10-03 20:02:06 +0000 | [diff] [blame] | 885 | file->fd = ngx_stderr_fileno; |
Igor Sysoev | 980a924 | 2004-09-05 19:54:02 +0000 | [diff] [blame] | 886 | file->name.len = 0; |
| 887 | file->name.data = NULL; |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 888 | } |
| 889 | |
Igor Sysoev | 697d1ae | 2005-10-27 15:46:13 +0000 | [diff] [blame] | 890 | file->buffer = NULL; |
| 891 | |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 892 | return file; |
| 893 | } |
| 894 | |
| 895 | |
Igor Sysoev | 697d1ae | 2005-10-27 15:46:13 +0000 | [diff] [blame] | 896 | static void |
| 897 | ngx_conf_flush_files(ngx_cycle_t *cycle) |
| 898 | { |
| 899 | ngx_uint_t i; |
| 900 | ngx_list_part_t *part; |
| 901 | ngx_open_file_t *file; |
| 902 | |
| 903 | ngx_log_debug0(NGX_LOG_DEBUG_CORE, cycle->log, 0, "flush files"); |
| 904 | |
| 905 | part = &cycle->open_files.part; |
| 906 | file = part->elts; |
| 907 | |
| 908 | for (i = 0; /* void */ ; i++) { |
| 909 | |
| 910 | if (i >= part->nelts) { |
| 911 | if (part->next == NULL) { |
| 912 | break; |
| 913 | } |
| 914 | part = part->next; |
| 915 | file = part->elts; |
| 916 | i = 0; |
| 917 | } |
| 918 | |
| 919 | if (file[i].buffer == NULL || file[i].pos - file[i].buffer == 0) { |
| 920 | continue; |
| 921 | } |
| 922 | |
| 923 | ngx_write_fd(file[i].fd, file[i].buffer, file[i].pos - file[i].buffer); |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 928 | void ngx_cdecl |
| 929 | ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err, |
| 930 | char *fmt, ...) |
Igor Sysoev | 8e1fbe6 | 2003-07-18 14:44:05 +0000 | [diff] [blame] | 931 | { |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 932 | u_char errstr[NGX_MAX_CONF_ERRSTR], *buf, *last; |
Igor Sysoev | 8e1fbe6 | 2003-07-18 14:44:05 +0000 | [diff] [blame] | 933 | va_list args; |
| 934 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 935 | last = errstr + NGX_MAX_CONF_ERRSTR; |
| 936 | |
Igor Sysoev | 8e1fbe6 | 2003-07-18 14:44:05 +0000 | [diff] [blame] | 937 | va_start(args, fmt); |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 938 | buf = ngx_vsnprintf(errstr, last - errstr, fmt, args); |
Igor Sysoev | 8e1fbe6 | 2003-07-18 14:44:05 +0000 | [diff] [blame] | 939 | va_end(args); |
| 940 | |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 941 | *buf = '\0'; |
| 942 | |
Igor Sysoev | 8e1fbe6 | 2003-07-18 14:44:05 +0000 | [diff] [blame] | 943 | if (err) { |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 944 | buf = ngx_snprintf(buf, last - buf - 1, " (%d: ", err); |
| 945 | buf = ngx_strerror_r(err, buf, last - buf - 1); |
| 946 | *buf++ = ')'; |
| 947 | *buf = '\0'; |
Igor Sysoev | 8e1fbe6 | 2003-07-18 14:44:05 +0000 | [diff] [blame] | 948 | } |
| 949 | |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 950 | if (cf->conf_file == NULL) { |
| 951 | ngx_log_error(level, cf->log, 0, "%s", errstr); |
| 952 | return; |
| 953 | } |
| 954 | |
Igor Sysoev | 02f742b | 2005-04-08 15:18:55 +0000 | [diff] [blame] | 955 | ngx_log_error(level, cf->log, 0, "%s in %s:%ui", |
Igor Sysoev | 8e1fbe6 | 2003-07-18 14:44:05 +0000 | [diff] [blame] | 956 | errstr, cf->conf_file->file.name.data, cf->conf_file->line); |
| 957 | } |
| 958 | |
| 959 | |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 960 | char * |
| 961 | ngx_conf_set_flag_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | 6a644c6 | 2003-03-04 06:33:48 +0000 | [diff] [blame] | 962 | { |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 963 | char *p = conf; |
| 964 | |
Igor Sysoev | 85080d0 | 2004-09-22 16:18:21 +0000 | [diff] [blame] | 965 | ngx_str_t *value; |
| 966 | ngx_flag_t *fp; |
| 967 | ngx_conf_post_t *post; |
Igor Sysoev | 6a644c6 | 2003-03-04 06:33:48 +0000 | [diff] [blame] | 968 | |
Igor Sysoev | 85080d0 | 2004-09-22 16:18:21 +0000 | [diff] [blame] | 969 | fp = (ngx_flag_t *) (p + cmd->offset); |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 970 | |
Igor Sysoev | 85080d0 | 2004-09-22 16:18:21 +0000 | [diff] [blame] | 971 | if (*fp != NGX_CONF_UNSET) { |
Igor Sysoev | 1c13c66 | 2003-05-20 15:37:55 +0000 | [diff] [blame] | 972 | return "is duplicate"; |
| 973 | } |
| 974 | |
Igor Sysoev | a367724 | 2004-04-14 05:57:36 +0000 | [diff] [blame] | 975 | value = cf->args->elts; |
Igor Sysoev | 6a644c6 | 2003-03-04 06:33:48 +0000 | [diff] [blame] | 976 | |
Igor Sysoev | 722231f | 2007-02-14 18:51:19 +0000 | [diff] [blame] | 977 | if (ngx_strcasecmp(value[1].data, (u_char *) "on") == 0) { |
Igor Sysoev | 85080d0 | 2004-09-22 16:18:21 +0000 | [diff] [blame] | 978 | *fp = 1; |
Igor Sysoev | 6a644c6 | 2003-03-04 06:33:48 +0000 | [diff] [blame] | 979 | |
Igor Sysoev | 722231f | 2007-02-14 18:51:19 +0000 | [diff] [blame] | 980 | } else if (ngx_strcasecmp(value[1].data, (u_char *) "off") == 0) { |
Igor Sysoev | 85080d0 | 2004-09-22 16:18:21 +0000 | [diff] [blame] | 981 | *fp = 0; |
Igor Sysoev | 6a644c6 | 2003-03-04 06:33:48 +0000 | [diff] [blame] | 982 | |
| 983 | } else { |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 984 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 985 | "invalid value \"%s\" in \"%s\" directive, " |
| 986 | "it must be \"on\" or \"off\"", |
| 987 | value[1].data, cmd->name.data); |
| 988 | return NGX_CONF_ERROR; |
Igor Sysoev | 6a644c6 | 2003-03-04 06:33:48 +0000 | [diff] [blame] | 989 | } |
| 990 | |
Igor Sysoev | 85080d0 | 2004-09-22 16:18:21 +0000 | [diff] [blame] | 991 | if (cmd->post) { |
| 992 | post = cmd->post; |
| 993 | return post->post_handler(cf, post, fp); |
| 994 | } |
Igor Sysoev | 6a644c6 | 2003-03-04 06:33:48 +0000 | [diff] [blame] | 995 | |
| 996 | return NGX_CONF_OK; |
| 997 | } |
| 998 | |
| 999 | |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 1000 | char * |
| 1001 | ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1002 | { |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 1003 | char *p = conf; |
| 1004 | |
Igor Sysoev | 13836ce | 2004-08-31 15:32:52 +0000 | [diff] [blame] | 1005 | ngx_str_t *field, *value; |
| 1006 | ngx_conf_post_t *post; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1007 | |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 1008 | field = (ngx_str_t *) (p + cmd->offset); |
Igor Sysoev | 1c13c66 | 2003-05-20 15:37:55 +0000 | [diff] [blame] | 1009 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 1010 | if (field->data) { |
Igor Sysoev | 1c13c66 | 2003-05-20 15:37:55 +0000 | [diff] [blame] | 1011 | return "is duplicate"; |
| 1012 | } |
| 1013 | |
Igor Sysoev | a367724 | 2004-04-14 05:57:36 +0000 | [diff] [blame] | 1014 | value = cf->args->elts; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1015 | |
Igor Sysoev | dc9dd43 | 2003-10-22 16:38:26 +0000 | [diff] [blame] | 1016 | *field = value[1]; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1017 | |
Igor Sysoev | 13836ce | 2004-08-31 15:32:52 +0000 | [diff] [blame] | 1018 | if (cmd->post) { |
| 1019 | post = cmd->post; |
| 1020 | return post->post_handler(cf, post, field); |
| 1021 | } |
| 1022 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1023 | return NGX_CONF_OK; |
| 1024 | } |
| 1025 | |
| 1026 | |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 1027 | char * |
Igor Sysoev | 3338cfd | 2006-05-11 14:43:47 +0000 | [diff] [blame] | 1028 | ngx_conf_set_str_array_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 1029 | { |
| 1030 | char *p = conf; |
| 1031 | |
Igor Sysoev | 3338cfd | 2006-05-11 14:43:47 +0000 | [diff] [blame] | 1032 | ngx_str_t *value, *s; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 1033 | ngx_array_t **a; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 1034 | ngx_conf_post_t *post; |
| 1035 | |
| 1036 | a = (ngx_array_t **) (p + cmd->offset); |
| 1037 | |
Igor Sysoev | cb54061 | 2007-12-09 18:03:20 +0000 | [diff] [blame] | 1038 | if (*a == NGX_CONF_UNSET_PTR) { |
Igor Sysoev | 3338cfd | 2006-05-11 14:43:47 +0000 | [diff] [blame] | 1039 | *a = ngx_array_create(cf->pool, 4, sizeof(ngx_str_t)); |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 1040 | if (*a == NULL) { |
| 1041 | return NGX_CONF_ERROR; |
| 1042 | } |
| 1043 | } |
| 1044 | |
Igor Sysoev | 3338cfd | 2006-05-11 14:43:47 +0000 | [diff] [blame] | 1045 | s = ngx_array_push(*a); |
| 1046 | if (s == NULL) { |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 1047 | return NGX_CONF_ERROR; |
| 1048 | } |
| 1049 | |
| 1050 | value = cf->args->elts; |
| 1051 | |
Igor Sysoev | 3338cfd | 2006-05-11 14:43:47 +0000 | [diff] [blame] | 1052 | *s = value[1]; |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 1053 | |
| 1054 | if (cmd->post) { |
| 1055 | post = cmd->post; |
Igor Sysoev | 3338cfd | 2006-05-11 14:43:47 +0000 | [diff] [blame] | 1056 | return post->post_handler(cf, post, s); |
| 1057 | } |
| 1058 | |
| 1059 | return NGX_CONF_OK; |
| 1060 | } |
| 1061 | |
| 1062 | |
| 1063 | char * |
| 1064 | ngx_conf_set_keyval_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 1065 | { |
| 1066 | char *p = conf; |
| 1067 | |
| 1068 | ngx_str_t *value; |
| 1069 | ngx_array_t **a; |
| 1070 | ngx_keyval_t *kv; |
| 1071 | ngx_conf_post_t *post; |
| 1072 | |
| 1073 | a = (ngx_array_t **) (p + cmd->offset); |
| 1074 | |
| 1075 | if (*a == NULL) { |
| 1076 | *a = ngx_array_create(cf->pool, 4, sizeof(ngx_keyval_t)); |
| 1077 | if (*a == NULL) { |
| 1078 | return NGX_CONF_ERROR; |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | kv = ngx_array_push(*a); |
| 1083 | if (kv == NULL) { |
| 1084 | return NGX_CONF_ERROR; |
| 1085 | } |
| 1086 | |
| 1087 | value = cf->args->elts; |
| 1088 | |
| 1089 | kv->key = value[1]; |
| 1090 | kv->value = value[2]; |
| 1091 | |
| 1092 | if (cmd->post) { |
| 1093 | post = cmd->post; |
| 1094 | return post->post_handler(cf, post, kv); |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | return NGX_CONF_OK; |
| 1098 | } |
| 1099 | |
| 1100 | |
| 1101 | char * |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 1102 | ngx_conf_set_num_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | bb4ec5c | 2003-05-16 15:27:48 +0000 | [diff] [blame] | 1103 | { |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 1104 | char *p = conf; |
| 1105 | |
Igor Sysoev | 0ee5d3c | 2004-02-20 16:48:59 +0000 | [diff] [blame] | 1106 | ngx_int_t *np; |
Igor Sysoev | 12b4b00 | 2003-10-24 06:53:41 +0000 | [diff] [blame] | 1107 | ngx_str_t *value; |
| 1108 | ngx_conf_post_t *post; |
Igor Sysoev | bb4ec5c | 2003-05-16 15:27:48 +0000 | [diff] [blame] | 1109 | |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 1110 | |
Igor Sysoev | 0ee5d3c | 2004-02-20 16:48:59 +0000 | [diff] [blame] | 1111 | np = (ngx_int_t *) (p + cmd->offset); |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 1112 | |
| 1113 | if (*np != NGX_CONF_UNSET) { |
Igor Sysoev | 1c13c66 | 2003-05-20 15:37:55 +0000 | [diff] [blame] | 1114 | return "is duplicate"; |
| 1115 | } |
| 1116 | |
Igor Sysoev | a367724 | 2004-04-14 05:57:36 +0000 | [diff] [blame] | 1117 | value = cf->args->elts; |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 1118 | *np = ngx_atoi(value[1].data, value[1].len); |
| 1119 | if (*np == NGX_ERROR) { |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 1120 | return "invalid number"; |
Igor Sysoev | bb4ec5c | 2003-05-16 15:27:48 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
Igor Sysoev | 12b4b00 | 2003-10-24 06:53:41 +0000 | [diff] [blame] | 1123 | if (cmd->post) { |
| 1124 | post = cmd->post; |
| 1125 | return post->post_handler(cf, post, np); |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 1126 | } |
Igor Sysoev | bb4ec5c | 2003-05-16 15:27:48 +0000 | [diff] [blame] | 1127 | |
| 1128 | return NGX_CONF_OK; |
| 1129 | } |
| 1130 | |
| 1131 | |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 1132 | char * |
| 1133 | ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 1134 | { |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 1135 | char *p = conf; |
| 1136 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1137 | size_t *sp; |
Igor Sysoev | 12b4b00 | 2003-10-24 06:53:41 +0000 | [diff] [blame] | 1138 | ngx_str_t *value; |
| 1139 | ngx_conf_post_t *post; |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 1140 | |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 1141 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1142 | sp = (size_t *) (p + cmd->offset); |
| 1143 | if (*sp != NGX_CONF_UNSET_SIZE) { |
Igor Sysoev | 1c13c66 | 2003-05-20 15:37:55 +0000 | [diff] [blame] | 1144 | return "is duplicate"; |
| 1145 | } |
| 1146 | |
Igor Sysoev | a367724 | 2004-04-14 05:57:36 +0000 | [diff] [blame] | 1147 | value = cf->args->elts; |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 1148 | |
Igor Sysoev | 0ee5d3c | 2004-02-20 16:48:59 +0000 | [diff] [blame] | 1149 | *sp = ngx_parse_size(&value[1]); |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1150 | if (*sp == (size_t) NGX_ERROR) { |
Igor Sysoev | 3d09c8d | 2003-05-06 17:03:16 +0000 | [diff] [blame] | 1151 | return "invalid value"; |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 1152 | } |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 1153 | |
Igor Sysoev | 12b4b00 | 2003-10-24 06:53:41 +0000 | [diff] [blame] | 1154 | if (cmd->post) { |
| 1155 | post = cmd->post; |
Igor Sysoev | 0ee5d3c | 2004-02-20 16:48:59 +0000 | [diff] [blame] | 1156 | return post->post_handler(cf, post, sp); |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 1157 | } |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 1158 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1159 | return NGX_CONF_OK; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 1162 | |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 1163 | char * |
Igor Sysoev | 1765f47 | 2006-07-07 16:33:19 +0000 | [diff] [blame] | 1164 | ngx_conf_set_off_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 1165 | { |
| 1166 | char *p = conf; |
| 1167 | |
| 1168 | off_t *op; |
| 1169 | ngx_str_t *value; |
| 1170 | ngx_conf_post_t *post; |
| 1171 | |
| 1172 | |
| 1173 | op = (off_t *) (p + cmd->offset); |
| 1174 | if (*op != NGX_CONF_UNSET) { |
| 1175 | return "is duplicate"; |
| 1176 | } |
| 1177 | |
| 1178 | value = cf->args->elts; |
| 1179 | |
| 1180 | *op = ngx_parse_offset(&value[1]); |
| 1181 | if (*op == (off_t) NGX_ERROR) { |
| 1182 | return "invalid value"; |
| 1183 | } |
| 1184 | |
| 1185 | if (cmd->post) { |
| 1186 | post = cmd->post; |
| 1187 | return post->post_handler(cf, post, op); |
| 1188 | } |
| 1189 | |
| 1190 | return NGX_CONF_OK; |
| 1191 | } |
| 1192 | |
| 1193 | |
| 1194 | char * |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 1195 | ngx_conf_set_msec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 1196 | { |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 1197 | char *p = conf; |
| 1198 | |
Igor Sysoev | 0ee5d3c | 2004-02-20 16:48:59 +0000 | [diff] [blame] | 1199 | ngx_msec_t *msp; |
Igor Sysoev | 12b4b00 | 2003-10-24 06:53:41 +0000 | [diff] [blame] | 1200 | ngx_str_t *value; |
| 1201 | ngx_conf_post_t *post; |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 1202 | |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 1203 | |
Igor Sysoev | 0ee5d3c | 2004-02-20 16:48:59 +0000 | [diff] [blame] | 1204 | msp = (ngx_msec_t *) (p + cmd->offset); |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1205 | if (*msp != NGX_CONF_UNSET_MSEC) { |
Igor Sysoev | 1c13c66 | 2003-05-20 15:37:55 +0000 | [diff] [blame] | 1206 | return "is duplicate"; |
| 1207 | } |
| 1208 | |
Igor Sysoev | a367724 | 2004-04-14 05:57:36 +0000 | [diff] [blame] | 1209 | value = cf->args->elts; |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 1210 | |
Igor Sysoev | 0ee5d3c | 2004-02-20 16:48:59 +0000 | [diff] [blame] | 1211 | *msp = ngx_parse_time(&value[1], 0); |
| 1212 | if (*msp == (ngx_msec_t) NGX_ERROR) { |
Igor Sysoev | 8556e6d | 2003-10-23 15:54:19 +0000 | [diff] [blame] | 1213 | return "invalid value"; |
Igor Sysoev | 1d8d9ee | 2003-04-28 15:06:39 +0000 | [diff] [blame] | 1214 | } |
| 1215 | |
Igor Sysoev | 0ee5d3c | 2004-02-20 16:48:59 +0000 | [diff] [blame] | 1216 | if (*msp == (ngx_msec_t) NGX_PARSE_LARGE_TIME) { |
Igor Sysoev | 8556e6d | 2003-10-23 15:54:19 +0000 | [diff] [blame] | 1217 | return "value must be less than 597 hours"; |
| 1218 | } |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 1219 | |
Igor Sysoev | 12b4b00 | 2003-10-24 06:53:41 +0000 | [diff] [blame] | 1220 | if (cmd->post) { |
| 1221 | post = cmd->post; |
Igor Sysoev | 0ee5d3c | 2004-02-20 16:48:59 +0000 | [diff] [blame] | 1222 | return post->post_handler(cf, post, msp); |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 1223 | } |
Igor Sysoev | 960ffa4 | 2002-12-26 07:24:21 +0000 | [diff] [blame] | 1224 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1225 | return NGX_CONF_OK; |
Igor Sysoev | 8809257 | 2002-12-19 07:08:55 +0000 | [diff] [blame] | 1226 | } |
Igor Sysoev | 6a644c6 | 2003-03-04 06:33:48 +0000 | [diff] [blame] | 1227 | |
Igor Sysoev | 3d09c8d | 2003-05-06 17:03:16 +0000 | [diff] [blame] | 1228 | |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 1229 | char * |
| 1230 | ngx_conf_set_sec_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | 3d09c8d | 2003-05-06 17:03:16 +0000 | [diff] [blame] | 1231 | { |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 1232 | char *p = conf; |
| 1233 | |
Igor Sysoev | 0ee5d3c | 2004-02-20 16:48:59 +0000 | [diff] [blame] | 1234 | time_t *sp; |
Igor Sysoev | 12b4b00 | 2003-10-24 06:53:41 +0000 | [diff] [blame] | 1235 | ngx_str_t *value; |
| 1236 | ngx_conf_post_t *post; |
Igor Sysoev | 3d09c8d | 2003-05-06 17:03:16 +0000 | [diff] [blame] | 1237 | |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 1238 | |
Igor Sysoev | 0ee5d3c | 2004-02-20 16:48:59 +0000 | [diff] [blame] | 1239 | sp = (time_t *) (p + cmd->offset); |
| 1240 | if (*sp != NGX_CONF_UNSET) { |
Igor Sysoev | 1c13c66 | 2003-05-20 15:37:55 +0000 | [diff] [blame] | 1241 | return "is duplicate"; |
| 1242 | } |
| 1243 | |
Igor Sysoev | a367724 | 2004-04-14 05:57:36 +0000 | [diff] [blame] | 1244 | value = cf->args->elts; |
Igor Sysoev | 3d09c8d | 2003-05-06 17:03:16 +0000 | [diff] [blame] | 1245 | |
Igor Sysoev | 0ee5d3c | 2004-02-20 16:48:59 +0000 | [diff] [blame] | 1246 | *sp = ngx_parse_time(&value[1], 1); |
| 1247 | if (*sp == NGX_ERROR) { |
Igor Sysoev | 8556e6d | 2003-10-23 15:54:19 +0000 | [diff] [blame] | 1248 | return "invalid value"; |
Igor Sysoev | 3d09c8d | 2003-05-06 17:03:16 +0000 | [diff] [blame] | 1249 | } |
| 1250 | |
Igor Sysoev | 0ee5d3c | 2004-02-20 16:48:59 +0000 | [diff] [blame] | 1251 | if (*sp == NGX_PARSE_LARGE_TIME) { |
Igor Sysoev | 8556e6d | 2003-10-23 15:54:19 +0000 | [diff] [blame] | 1252 | return "value must be less than 68 years"; |
| 1253 | } |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 1254 | |
Igor Sysoev | 12b4b00 | 2003-10-24 06:53:41 +0000 | [diff] [blame] | 1255 | if (cmd->post) { |
| 1256 | post = cmd->post; |
Igor Sysoev | 0ee5d3c | 2004-02-20 16:48:59 +0000 | [diff] [blame] | 1257 | return post->post_handler(cf, post, sp); |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 1258 | } |
Igor Sysoev | 3d09c8d | 2003-05-06 17:03:16 +0000 | [diff] [blame] | 1259 | |
| 1260 | return NGX_CONF_OK; |
| 1261 | } |
| 1262 | |
| 1263 | |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 1264 | char * |
| 1265 | ngx_conf_set_bufs_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | 3ae3248 | 2003-10-08 15:32:54 +0000 | [diff] [blame] | 1266 | { |
Igor Sysoev | 68ee8f1 | 2003-10-30 08:51:06 +0000 | [diff] [blame] | 1267 | char *p = conf; |
Igor Sysoev | 3ae3248 | 2003-10-08 15:32:54 +0000 | [diff] [blame] | 1268 | |
Igor Sysoev | 3ae3248 | 2003-10-08 15:32:54 +0000 | [diff] [blame] | 1269 | ngx_str_t *value; |
| 1270 | ngx_bufs_t *bufs; |
| 1271 | |
| 1272 | |
| 1273 | bufs = (ngx_bufs_t *) (p + cmd->offset); |
Igor Sysoev | 3ae3248 | 2003-10-08 15:32:54 +0000 | [diff] [blame] | 1274 | if (bufs->num) { |
| 1275 | return "is duplicate"; |
| 1276 | } |
| 1277 | |
Igor Sysoev | a367724 | 2004-04-14 05:57:36 +0000 | [diff] [blame] | 1278 | value = cf->args->elts; |
Igor Sysoev | 3ae3248 | 2003-10-08 15:32:54 +0000 | [diff] [blame] | 1279 | |
| 1280 | bufs->num = ngx_atoi(value[1].data, value[1].len); |
| 1281 | if (bufs->num == NGX_ERROR || bufs->num == 0) { |
| 1282 | return "invalid value"; |
| 1283 | } |
| 1284 | |
Igor Sysoev | 8556e6d | 2003-10-23 15:54:19 +0000 | [diff] [blame] | 1285 | bufs->size = ngx_parse_size(&value[2]); |
Igor Sysoev | b5910d4 | 2003-10-30 16:51:33 +0000 | [diff] [blame] | 1286 | if (bufs->size == (size_t) NGX_ERROR || bufs->size == 0) { |
Igor Sysoev | 3ae3248 | 2003-10-08 15:32:54 +0000 | [diff] [blame] | 1287 | return "invalid value"; |
| 1288 | } |
| 1289 | |
Igor Sysoev | 3ae3248 | 2003-10-08 15:32:54 +0000 | [diff] [blame] | 1290 | return NGX_CONF_OK; |
| 1291 | } |
| 1292 | |
| 1293 | |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 1294 | char * |
| 1295 | ngx_conf_set_enum_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | a367724 | 2004-04-14 05:57:36 +0000 | [diff] [blame] | 1296 | { |
| 1297 | char *p = conf; |
| 1298 | |
| 1299 | ngx_uint_t *np, i; |
| 1300 | ngx_str_t *value; |
| 1301 | ngx_conf_enum_t *e; |
| 1302 | |
| 1303 | np = (ngx_uint_t *) (p + cmd->offset); |
| 1304 | |
| 1305 | if (*np != NGX_CONF_UNSET_UINT) { |
| 1306 | return "is duplicate"; |
| 1307 | } |
| 1308 | |
| 1309 | value = cf->args->elts; |
| 1310 | e = cmd->post; |
| 1311 | |
| 1312 | for (i = 0; e[i].name.len != 0; i++) { |
| 1313 | if (e[i].name.len != value[1].len |
| 1314 | || ngx_strcasecmp(e[i].name.data, value[1].data) != 0) |
| 1315 | { |
| 1316 | continue; |
| 1317 | } |
| 1318 | |
| 1319 | *np = e[i].value; |
| 1320 | |
| 1321 | return NGX_CONF_OK; |
| 1322 | } |
| 1323 | |
| 1324 | ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
| 1325 | "invalid value \"%s\"", value[1].data); |
| 1326 | |
| 1327 | return NGX_CONF_ERROR; |
| 1328 | } |
| 1329 | |
| 1330 | |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 1331 | char * |
| 1332 | ngx_conf_set_bitmask_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | 68ee8f1 | 2003-10-30 08:51:06 +0000 | [diff] [blame] | 1333 | { |
| 1334 | char *p = conf; |
| 1335 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1336 | ngx_uint_t *np, i, m; |
Igor Sysoev | 68ee8f1 | 2003-10-30 08:51:06 +0000 | [diff] [blame] | 1337 | ngx_str_t *value; |
| 1338 | ngx_conf_bitmask_t *mask; |
| 1339 | |
| 1340 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1341 | np = (ngx_uint_t *) (p + cmd->offset); |
Igor Sysoev | a367724 | 2004-04-14 05:57:36 +0000 | [diff] [blame] | 1342 | value = cf->args->elts; |
Igor Sysoev | 68ee8f1 | 2003-10-30 08:51:06 +0000 | [diff] [blame] | 1343 | mask = cmd->post; |
| 1344 | |
| 1345 | for (i = 1; i < cf->args->nelts; i++) { |
| 1346 | for (m = 0; mask[m].name.len != 0; m++) { |
| 1347 | |
| 1348 | if (mask[m].name.len != value[i].len |
Igor Sysoev | a367724 | 2004-04-14 05:57:36 +0000 | [diff] [blame] | 1349 | || ngx_strcasecmp(mask[m].name.data, value[i].data) != 0) |
Igor Sysoev | 68ee8f1 | 2003-10-30 08:51:06 +0000 | [diff] [blame] | 1350 | { |
| 1351 | continue; |
| 1352 | } |
| 1353 | |
| 1354 | if (*np & mask[m].mask) { |
| 1355 | ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
| 1356 | "duplicate value \"%s\"", value[i].data); |
| 1357 | |
| 1358 | } else { |
| 1359 | *np |= mask[m].mask; |
| 1360 | } |
| 1361 | |
| 1362 | break; |
| 1363 | } |
| 1364 | |
| 1365 | if (mask[m].name.len == 0) { |
| 1366 | ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
| 1367 | "invalid value \"%s\"", value[i].data); |
| 1368 | |
| 1369 | return NGX_CONF_ERROR; |
| 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | return NGX_CONF_OK; |
| 1374 | } |
| 1375 | |
| 1376 | |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 1377 | char * |
| 1378 | ngx_conf_unsupported(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | 6a644c6 | 2003-03-04 06:33:48 +0000 | [diff] [blame] | 1379 | { |
| 1380 | return "unsupported on this platform"; |
| 1381 | } |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 1382 | |
| 1383 | |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 1384 | char * |
Igor Sysoev | c31a9bb | 2005-11-26 10:11:11 +0000 | [diff] [blame] | 1385 | ngx_conf_deprecated(ngx_conf_t *cf, void *post, void *data) |
| 1386 | { |
| 1387 | ngx_conf_deprecated_t *d = post; |
| 1388 | |
| 1389 | ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
| 1390 | "the \"%s\" directive is deprecated, " |
| 1391 | "use the \"%s\" directive instead", |
| 1392 | d->old_name, d->new_name); |
| 1393 | |
| 1394 | return NGX_CONF_OK; |
| 1395 | } |
| 1396 | |
| 1397 | |
| 1398 | char * |
Igor Sysoev | 4d656dc | 2005-03-22 16:02:46 +0000 | [diff] [blame] | 1399 | ngx_conf_check_num_bounds(ngx_conf_t *cf, void *post, void *data) |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 1400 | { |
Igor Sysoev | 369145c | 2004-05-28 15:49:23 +0000 | [diff] [blame] | 1401 | ngx_conf_num_bounds_t *bounds = post; |
| 1402 | ngx_int_t *np = data; |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 1403 | |
Igor Sysoev | cf80a70 | 2003-11-03 22:20:44 +0000 | [diff] [blame] | 1404 | if (bounds->high == -1) { |
| 1405 | if (*np >= bounds->low) { |
| 1406 | return NGX_CONF_OK; |
| 1407 | } |
| 1408 | |
| 1409 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
Igor Sysoev | 02f742b | 2005-04-08 15:18:55 +0000 | [diff] [blame] | 1410 | "value must be equal or more than %i", bounds->low); |
Igor Sysoev | cf80a70 | 2003-11-03 22:20:44 +0000 | [diff] [blame] | 1411 | |
| 1412 | return NGX_CONF_ERROR; |
| 1413 | } |
| 1414 | |
| 1415 | if (*np >= bounds->low && *np <= bounds->high) { |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 1416 | return NGX_CONF_OK; |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
Igor Sysoev | cf80a70 | 2003-11-03 22:20:44 +0000 | [diff] [blame] | 1419 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
Igor Sysoev | 02f742b | 2005-04-08 15:18:55 +0000 | [diff] [blame] | 1420 | "value must be between %i and %i", |
Igor Sysoev | cf80a70 | 2003-11-03 22:20:44 +0000 | [diff] [blame] | 1421 | bounds->low, bounds->high); |
| 1422 | |
| 1423 | return NGX_CONF_ERROR; |
Igor Sysoev | f107910 | 2003-10-23 06:13:16 +0000 | [diff] [blame] | 1424 | } |