Mercurial > hg > nginx
comparison src/mail/ngx_mail_core_module.c @ 1892:057d362ee50e
resolver in smtp proxy module
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 13 Feb 2008 13:50:04 +0000 |
parents | fe11e2a3946d |
children | 4c060e30476b |
comparison
equal
deleted
inserted
replaced
1891:782af1038115 | 1892:057d362ee50e |
---|---|
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 |
136 | 152 |
137 /* | 153 /* |
138 * set by ngx_pcalloc(): | 154 * set by ngx_pcalloc(): |
139 * | 155 * |
140 * cscf->protocol = NULL; | 156 * cscf->protocol = NULL; |
157 * cscf->resolver = NULL; | |
141 */ | 158 */ |
142 | 159 |
143 cscf->timeout = NGX_CONF_UNSET_MSEC; | 160 cscf->timeout = NGX_CONF_UNSET_MSEC; |
161 cscf->resolver_timeout = NGX_CONF_UNSET_MSEC; | |
144 cscf->so_keepalive = NGX_CONF_UNSET; | 162 cscf->so_keepalive = NGX_CONF_UNSET; |
163 | |
164 cscf->file_name = cf->conf_file->file.name.data; | |
165 cscf->line = cf->conf_file->line; | |
145 | 166 |
146 return cscf; | 167 return cscf; |
147 } | 168 } |
148 | 169 |
149 | 170 |
152 { | 173 { |
153 ngx_mail_core_srv_conf_t *prev = parent; | 174 ngx_mail_core_srv_conf_t *prev = parent; |
154 ngx_mail_core_srv_conf_t *conf = child; | 175 ngx_mail_core_srv_conf_t *conf = child; |
155 | 176 |
156 ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000); | 177 ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000); |
178 ngx_conf_merge_msec_value(conf->resolver_timeout, prev->resolver_timeout, | |
179 30000); | |
157 | 180 |
158 ngx_conf_merge_value(conf->so_keepalive, prev->so_keepalive, 0); | 181 ngx_conf_merge_value(conf->so_keepalive, prev->so_keepalive, 0); |
159 | 182 |
160 | 183 |
161 ngx_conf_merge_str_value(conf->server_name, prev->server_name, ""); | 184 ngx_conf_merge_str_value(conf->server_name, prev->server_name, ""); |
180 if (conf->protocol == NULL) { | 203 if (conf->protocol == NULL) { |
181 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | 204 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
182 "unknown mail protocol for server in %s:%ui", | 205 "unknown mail protocol for server in %s:%ui", |
183 conf->file_name, conf->line); | 206 conf->file_name, conf->line); |
184 return NGX_CONF_ERROR; | 207 return NGX_CONF_ERROR; |
208 } | |
209 | |
210 if (conf->resolver == NULL) { | |
211 conf->resolver = prev->resolver; | |
185 } | 212 } |
186 | 213 |
187 return NGX_CONF_OK; | 214 return NGX_CONF_OK; |
188 } | 215 } |
189 | 216 |
235 /* the server configuration context */ | 262 /* the server configuration context */ |
236 | 263 |
237 cscf = ctx->srv_conf[ngx_mail_core_module.ctx_index]; | 264 cscf = ctx->srv_conf[ngx_mail_core_module.ctx_index]; |
238 cscf->ctx = ctx; | 265 cscf->ctx = ctx; |
239 | 266 |
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]; | 267 cmcf = ctx->main_conf[ngx_mail_core_module.ctx_index]; |
244 | 268 |
245 cscfp = ngx_array_push(&cmcf->servers); | 269 cscfp = ngx_array_push(&cmcf->servers); |
246 if (cscfp == NULL) { | 270 if (cscfp == NULL) { |
247 return NGX_CONF_ERROR; | 271 return NGX_CONF_ERROR; |
387 "unknown protocol \"%V\"", &value[1]); | 411 "unknown protocol \"%V\"", &value[1]); |
388 return NGX_CONF_ERROR; | 412 return NGX_CONF_ERROR; |
389 } | 413 } |
390 | 414 |
391 | 415 |
416 static char * | |
417 ngx_mail_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
418 { | |
419 ngx_mail_core_srv_conf_t *cscf = conf; | |
420 | |
421 ngx_url_t u; | |
422 ngx_str_t *value; | |
423 | |
424 value = cf->args->elts; | |
425 | |
426 ngx_memzero(&u, sizeof(ngx_url_t)); | |
427 | |
428 u.host = value[1]; | |
429 u.port = 53; | |
430 | |
431 if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) { | |
432 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V: %s", &u.host, u.err); | |
433 return NGX_CONF_ERROR; | |
434 } | |
435 | |
436 cscf->resolver = ngx_resolver_create(&u.addrs[0], cf->cycle->new_log); | |
437 if (cscf->resolver == NULL) { | |
438 return NGX_OK; | |
439 } | |
440 | |
441 return NGX_CONF_OK; | |
442 } | |
443 | |
444 | |
392 char * | 445 char * |
393 ngx_mail_capabilities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 446 ngx_mail_capabilities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
394 { | 447 { |
395 char *p = conf; | 448 char *p = conf; |
396 | 449 |