comparison src/mail/ngx_mail_core_module.c @ 410:cd9cb7a3ff9e

Merge with nginx 0.7.8.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 11 Aug 2008 22:07:06 +0400
parents 52b28d322d76 edf1cb6c328e
children 3ff402661f4c
comparison
equal deleted inserted replaced
409:52b28d322d76 410:cd9cb7a3ff9e
18 void *conf); 18 void *conf);
19 static char *ngx_mail_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, 19 static char *ngx_mail_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
20 void *conf); 20 void *conf);
21 static char *ngx_mail_core_protocol(ngx_conf_t *cf, ngx_command_t *cmd, 21 static char *ngx_mail_core_protocol(ngx_conf_t *cf, ngx_command_t *cmd,
22 void *conf); 22 void *conf);
23 static char *ngx_mail_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
24 void *conf);
23 25
24 26
25 static ngx_command_t ngx_mail_core_commands[] = { 27 static ngx_command_t ngx_mail_core_commands[] = {
26 28
27 { ngx_string("server"), 29 { ngx_string("server"),
62 { ngx_string("server_name"), 64 { ngx_string("server_name"),
63 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, 65 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
64 ngx_conf_set_str_slot, 66 ngx_conf_set_str_slot,
65 NGX_MAIL_SRV_CONF_OFFSET, 67 NGX_MAIL_SRV_CONF_OFFSET,
66 offsetof(ngx_mail_core_srv_conf_t, server_name), 68 offsetof(ngx_mail_core_srv_conf_t, server_name),
69 NULL },
70
71 { ngx_string("resolver"),
72 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
73 ngx_mail_core_resolver,
74 NGX_MAIL_SRV_CONF_OFFSET,
75 0,
76 NULL },
77
78 { ngx_string("resolver_timeout"),
79 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
80 ngx_conf_set_msec_slot,
81 NGX_MAIL_SRV_CONF_OFFSET,
82 offsetof(ngx_mail_core_srv_conf_t, resolver_timeout),
67 NULL }, 83 NULL },
68 84
69 ngx_null_command 85 ngx_null_command
70 }; 86 };
71 87
139 * 155 *
140 * cscf->protocol = NULL; 156 * cscf->protocol = NULL;
141 */ 157 */
142 158
143 cscf->timeout = NGX_CONF_UNSET_MSEC; 159 cscf->timeout = NGX_CONF_UNSET_MSEC;
160 cscf->resolver_timeout = NGX_CONF_UNSET_MSEC;
144 cscf->so_keepalive = NGX_CONF_UNSET; 161 cscf->so_keepalive = NGX_CONF_UNSET;
162
163 cscf->resolver = NGX_CONF_UNSET_PTR;
164
165 cscf->file_name = cf->conf_file->file.name.data;
166 cscf->line = cf->conf_file->line;
145 167
146 return cscf; 168 return cscf;
147 } 169 }
148 170
149 171
152 { 174 {
153 ngx_mail_core_srv_conf_t *prev = parent; 175 ngx_mail_core_srv_conf_t *prev = parent;
154 ngx_mail_core_srv_conf_t *conf = child; 176 ngx_mail_core_srv_conf_t *conf = child;
155 177
156 ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000); 178 ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000);
179 ngx_conf_merge_msec_value(conf->resolver_timeout, prev->resolver_timeout,
180 30000);
157 181
158 ngx_conf_merge_value(conf->so_keepalive, prev->so_keepalive, 0); 182 ngx_conf_merge_value(conf->so_keepalive, prev->so_keepalive, 0);
159 183
160 184
161 ngx_conf_merge_str_value(conf->server_name, prev->server_name, ""); 185 ngx_conf_merge_str_value(conf->server_name, prev->server_name, "");
162 186
163 if (conf->server_name.len == 0) { 187 if (conf->server_name.len == 0) {
164 conf->server_name.data = ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN); 188 conf->server_name = cf->cycle->hostname;
165 if (conf->server_name.data == NULL) {
166 return NGX_CONF_ERROR;
167 }
168
169 if (gethostname((char *) conf->server_name.data, NGX_MAXHOSTNAMELEN)
170 == -1)
171 {
172 ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
173 "gethostname() failed");
174 return NGX_CONF_ERROR;
175 }
176
177 conf->server_name.len = ngx_strlen(conf->server_name.data);
178 } 189 }
179 190
180 if (conf->protocol == NULL) { 191 if (conf->protocol == NULL) {
181 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, 192 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
182 "unknown mail protocol for server in %s:%ui", 193 "unknown mail protocol for server in %s:%ui",
183 conf->file_name, conf->line); 194 conf->file_name, conf->line);
184 return NGX_CONF_ERROR; 195 return NGX_CONF_ERROR;
185 } 196 }
197
198 ngx_conf_merge_ptr_value(conf->resolver, prev->resolver, NULL);
186 199
187 return NGX_CONF_OK; 200 return NGX_CONF_OK;
188 } 201 }
189 202
190 203
235 /* the server configuration context */ 248 /* the server configuration context */
236 249
237 cscf = ctx->srv_conf[ngx_mail_core_module.ctx_index]; 250 cscf = ctx->srv_conf[ngx_mail_core_module.ctx_index];
238 cscf->ctx = ctx; 251 cscf->ctx = ctx;
239 252
240 cscf->file_name = cf->conf_file->file.name.data;
241 cscf->line = cf->conf_file->line;
242
243 cmcf = ctx->main_conf[ngx_mail_core_module.ctx_index]; 253 cmcf = ctx->main_conf[ngx_mail_core_module.ctx_index];
244 254
245 cscfp = ngx_array_push(&cmcf->servers); 255 cscfp = ngx_array_push(&cmcf->servers);
246 if (cscfp == NULL) { 256 if (cscfp == NULL) {
247 return NGX_CONF_ERROR; 257 return NGX_CONF_ERROR;
283 ngx_memzero(&u, sizeof(ngx_url_t)); 293 ngx_memzero(&u, sizeof(ngx_url_t));
284 294
285 u.url = value[1]; 295 u.url = value[1];
286 u.listen = 1; 296 u.listen = 1;
287 297
288 if (ngx_parse_url(cf, &u) != NGX_OK) { 298 if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
289 if (u.err) { 299 if (u.err) {
290 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 300 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
291 "%s in \"%V\" of the \"listen\" directive", 301 "%s in \"%V\" of the \"listen\" directive",
292 u.err, &u.url); 302 u.err, &u.url);
293 } 303 }
387 "unknown protocol \"%V\"", &value[1]); 397 "unknown protocol \"%V\"", &value[1]);
388 return NGX_CONF_ERROR; 398 return NGX_CONF_ERROR;
389 } 399 }
390 400
391 401
402 static char *
403 ngx_mail_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
404 {
405 ngx_mail_core_srv_conf_t *cscf = conf;
406
407 ngx_url_t u;
408 ngx_str_t *value;
409
410 value = cf->args->elts;
411
412 if (cscf->resolver != NGX_CONF_UNSET_PTR) {
413 return "is duplicate";
414 }
415
416 if (ngx_strcmp(value[1].data, "off") == 0) {
417 cscf->resolver = NULL;
418 return NGX_CONF_OK;
419 }
420
421 ngx_memzero(&u, sizeof(ngx_url_t));
422
423 u.host = value[1];
424 u.port = 53;
425
426 if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
427 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V: %s", &u.host, u.err);
428 return NGX_CONF_ERROR;
429 }
430
431 cscf->resolver = ngx_resolver_create(cf, &u.addrs[0]);
432 if (cscf->resolver == NULL) {
433 return NGX_CONF_OK;
434 }
435
436 return NGX_CONF_OK;
437 }
438
439
392 char * 440 char *
393 ngx_mail_capabilities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 441 ngx_mail_capabilities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
394 { 442 {
395 char *p = conf; 443 char *p = conf;
396 444