Mercurial > hg > nginx
annotate src/mail/ngx_mail_core_module.c @ 4089:e27670e1ab70
mp4_max_moov_size directive has been renamed to mp4_max_buffer_size.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 12 Sep 2011 09:38:04 +0000 |
parents | c7d57b539248 |
children | 016352c19049 4919fb357a5d |
rev | line source |
---|---|
521 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_event.h> | |
1136 | 10 #include <ngx_mail.h> |
521 | 11 |
12 | |
1136 | 13 static void *ngx_mail_core_create_main_conf(ngx_conf_t *cf); |
14 static void *ngx_mail_core_create_srv_conf(ngx_conf_t *cf); | |
15 static char *ngx_mail_core_merge_srv_conf(ngx_conf_t *cf, void *parent, | |
521 | 16 void *child); |
1136 | 17 static char *ngx_mail_core_server(ngx_conf_t *cf, ngx_command_t *cmd, |
521 | 18 void *conf); |
1136 | 19 static char *ngx_mail_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, |
521 | 20 void *conf); |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
21 static char *ngx_mail_core_protocol(ngx_conf_t *cf, ngx_command_t *cmd, |
527 | 22 void *conf); |
1892
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
23 static char *ngx_mail_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
24 void *conf); |
521 | 25 |
26 | |
1136 | 27 static ngx_command_t ngx_mail_core_commands[] = { |
521 | 28 |
29 { ngx_string("server"), | |
1136 | 30 NGX_MAIL_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, |
31 ngx_mail_core_server, | |
521 | 32 0, |
33 0, | |
34 NULL }, | |
35 | |
36 { ngx_string("listen"), | |
1136 | 37 NGX_MAIL_SRV_CONF|NGX_CONF_TAKE12, |
38 ngx_mail_core_listen, | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
39 NGX_MAIL_SRV_CONF_OFFSET, |
521 | 40 0, |
41 NULL }, | |
42 | |
43 { ngx_string("protocol"), | |
1136 | 44 NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
45 ngx_mail_core_protocol, |
1136 | 46 NGX_MAIL_SRV_CONF_OFFSET, |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
47 0, |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
48 NULL }, |
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
49 |
587 | 50 { ngx_string("so_keepalive"), |
1136 | 51 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG, |
587 | 52 ngx_conf_set_flag_slot, |
1136 | 53 NGX_MAIL_SRV_CONF_OFFSET, |
54 offsetof(ngx_mail_core_srv_conf_t, so_keepalive), | |
587 | 55 NULL }, |
56 | |
521 | 57 { ngx_string("timeout"), |
1136 | 58 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
521 | 59 ngx_conf_set_msec_slot, |
1136 | 60 NGX_MAIL_SRV_CONF_OFFSET, |
61 offsetof(ngx_mail_core_srv_conf_t, timeout), | |
521 | 62 NULL }, |
63 | |
800 | 64 { ngx_string("server_name"), |
1136 | 65 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
800 | 66 ngx_conf_set_str_slot, |
1136 | 67 NGX_MAIL_SRV_CONF_OFFSET, |
68 offsetof(ngx_mail_core_srv_conf_t, server_name), | |
800 | 69 NULL }, |
70 | |
1892
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
71 { ngx_string("resolver"), |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
72 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
73 ngx_mail_core_resolver, |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
74 NGX_MAIL_SRV_CONF_OFFSET, |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
75 0, |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
76 NULL }, |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
77 |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
78 { ngx_string("resolver_timeout"), |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
79 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
80 ngx_conf_set_msec_slot, |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
81 NGX_MAIL_SRV_CONF_OFFSET, |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
82 offsetof(ngx_mail_core_srv_conf_t, resolver_timeout), |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
83 NULL }, |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
84 |
521 | 85 ngx_null_command |
86 }; | |
87 | |
88 | |
1136 | 89 static ngx_mail_module_t ngx_mail_core_module_ctx = { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
90 NULL, /* protocol */ |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
91 |
1136 | 92 ngx_mail_core_create_main_conf, /* create main configuration */ |
521 | 93 NULL, /* init main configuration */ |
94 | |
1136 | 95 ngx_mail_core_create_srv_conf, /* create server configuration */ |
96 ngx_mail_core_merge_srv_conf /* merge server configuration */ | |
521 | 97 }; |
98 | |
99 | |
1136 | 100 ngx_module_t ngx_mail_core_module = { |
521 | 101 NGX_MODULE_V1, |
1136 | 102 &ngx_mail_core_module_ctx, /* module context */ |
103 ngx_mail_core_commands, /* module directives */ | |
104 NGX_MAIL_MODULE, /* module type */ | |
541 | 105 NULL, /* init master */ |
521 | 106 NULL, /* init module */ |
541 | 107 NULL, /* init process */ |
108 NULL, /* init thread */ | |
109 NULL, /* exit thread */ | |
110 NULL, /* exit process */ | |
111 NULL, /* exit master */ | |
112 NGX_MODULE_V1_PADDING | |
521 | 113 }; |
114 | |
115 | |
116 static void * | |
1136 | 117 ngx_mail_core_create_main_conf(ngx_conf_t *cf) |
577 | 118 { |
1136 | 119 ngx_mail_core_main_conf_t *cmcf; |
521 | 120 |
1136 | 121 cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_core_main_conf_t)); |
521 | 122 if (cmcf == NULL) { |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2855
diff
changeset
|
123 return NULL; |
521 | 124 } |
125 | |
126 if (ngx_array_init(&cmcf->servers, cf->pool, 4, | |
1136 | 127 sizeof(ngx_mail_core_srv_conf_t *)) |
641 | 128 != NGX_OK) |
129 { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2855
diff
changeset
|
130 return NULL; |
641 | 131 } |
132 | |
1136 | 133 if (ngx_array_init(&cmcf->listen, cf->pool, 4, sizeof(ngx_mail_listen_t)) |
641 | 134 != NGX_OK) |
521 | 135 { |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2855
diff
changeset
|
136 return NULL; |
521 | 137 } |
138 | |
139 return cmcf; | |
140 } | |
141 | |
142 | |
143 static void * | |
1136 | 144 ngx_mail_core_create_srv_conf(ngx_conf_t *cf) |
577 | 145 { |
1136 | 146 ngx_mail_core_srv_conf_t *cscf; |
577 | 147 |
1136 | 148 cscf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_core_srv_conf_t)); |
521 | 149 if (cscf == NULL) { |
527 | 150 return NULL; |
521 | 151 } |
152 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
153 /* |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
154 * set by ngx_pcalloc(): |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
155 * |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
156 * cscf->protocol = NULL; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
157 */ |
521 | 158 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
159 cscf->timeout = NGX_CONF_UNSET_MSEC; |
1892
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
160 cscf->resolver_timeout = NGX_CONF_UNSET_MSEC; |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
161 cscf->so_keepalive = NGX_CONF_UNSET; |
1136 | 162 |
1896
4c060e30476b
do not resolve SMTP clients by default
Igor Sysoev <igor@sysoev.ru>
parents:
1892
diff
changeset
|
163 cscf->resolver = NGX_CONF_UNSET_PTR; |
4c060e30476b
do not resolve SMTP clients by default
Igor Sysoev <igor@sysoev.ru>
parents:
1892
diff
changeset
|
164 |
1892
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
165 cscf->file_name = cf->conf_file->file.name.data; |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
166 cscf->line = cf->conf_file->line; |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
167 |
521 | 168 return cscf; |
169 } | |
170 | |
171 | |
172 static char * | |
1136 | 173 ngx_mail_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) |
521 | 174 { |
1136 | 175 ngx_mail_core_srv_conf_t *prev = parent; |
176 ngx_mail_core_srv_conf_t *conf = child; | |
521 | 177 |
178 ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000); | |
1892
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
179 ngx_conf_merge_msec_value(conf->resolver_timeout, prev->resolver_timeout, |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
180 30000); |
1481
b58ce1cf66da
smtp_client_buffer and smtp_greeting_delay
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
181 |
587 | 182 ngx_conf_merge_value(conf->so_keepalive, prev->so_keepalive, 0); |
521 | 183 |
800 | 184 |
185 ngx_conf_merge_str_value(conf->server_name, prev->server_name, ""); | |
186 | |
187 if (conf->server_name.len == 0) { | |
2011 | 188 conf->server_name = cf->cycle->hostname; |
800 | 189 } |
190 | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
191 if (conf->protocol == NULL) { |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
192 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
193 "unknown mail protocol for server in %s:%ui", |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
194 conf->file_name, conf->line); |
583 | 195 return NGX_CONF_ERROR; |
196 } | |
197 | |
1896
4c060e30476b
do not resolve SMTP clients by default
Igor Sysoev <igor@sysoev.ru>
parents:
1892
diff
changeset
|
198 ngx_conf_merge_ptr_value(conf->resolver, prev->resolver, NULL); |
1892
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
199 |
521 | 200 return NGX_CONF_OK; |
201 } | |
202 | |
203 | |
204 static char * | |
1136 | 205 ngx_mail_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
521 | 206 { |
207 char *rv; | |
208 void *mconf; | |
209 ngx_uint_t m; | |
210 ngx_conf_t pcf; | |
1136 | 211 ngx_mail_module_t *module; |
212 ngx_mail_conf_ctx_t *ctx, *mail_ctx; | |
213 ngx_mail_core_srv_conf_t *cscf, **cscfp; | |
214 ngx_mail_core_main_conf_t *cmcf; | |
521 | 215 |
1136 | 216 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_mail_conf_ctx_t)); |
521 | 217 if (ctx == NULL) { |
218 return NGX_CONF_ERROR; | |
219 } | |
220 | |
1136 | 221 mail_ctx = cf->ctx; |
222 ctx->main_conf = mail_ctx->main_conf; | |
577 | 223 |
521 | 224 /* the server{}'s srv_conf */ |
225 | |
1136 | 226 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_mail_max_module); |
521 | 227 if (ctx->srv_conf == NULL) { |
228 return NGX_CONF_ERROR; | |
229 } | |
230 | |
231 for (m = 0; ngx_modules[m]; m++) { | |
1136 | 232 if (ngx_modules[m]->type != NGX_MAIL_MODULE) { |
521 | 233 continue; |
234 } | |
235 | |
236 module = ngx_modules[m]->ctx; | |
237 | |
238 if (module->create_srv_conf) { | |
239 mconf = module->create_srv_conf(cf); | |
240 if (mconf == NULL) { | |
241 return NGX_CONF_ERROR; | |
242 } | |
243 | |
244 ctx->srv_conf[ngx_modules[m]->ctx_index] = mconf; | |
245 } | |
246 } | |
247 | |
248 /* the server configuration context */ | |
249 | |
1136 | 250 cscf = ctx->srv_conf[ngx_mail_core_module.ctx_index]; |
521 | 251 cscf->ctx = ctx; |
252 | |
1136 | 253 cmcf = ctx->main_conf[ngx_mail_core_module.ctx_index]; |
521 | 254 |
255 cscfp = ngx_array_push(&cmcf->servers); | |
256 if (cscfp == NULL) { | |
257 return NGX_CONF_ERROR; | |
258 } | |
259 | |
260 *cscfp = cscf; | |
261 | |
262 | |
263 /* parse inside server{} */ | |
264 | |
265 pcf = *cf; | |
266 cf->ctx = ctx; | |
1136 | 267 cf->cmd_type = NGX_MAIL_SRV_CONF; |
521 | 268 |
269 rv = ngx_conf_parse(cf, NULL); | |
270 | |
271 *cf = pcf; | |
272 | |
273 return rv; | |
274 } | |
275 | |
276 | |
277 static char * | |
1136 | 278 ngx_mail_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
521 | 279 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
280 ngx_mail_core_srv_conf_t *cscf = conf; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
281 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
282 size_t len, off; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
283 in_port_t port; |
641 | 284 ngx_str_t *value; |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
285 ngx_url_t u; |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
286 ngx_uint_t i, m; |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
287 struct sockaddr *sa; |
2798 | 288 ngx_mail_listen_t *ls; |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
289 ngx_mail_module_t *module; |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
290 struct sockaddr_in *sin; |
1136 | 291 ngx_mail_core_main_conf_t *cmcf; |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
292 #if (NGX_HAVE_INET6) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
293 struct sockaddr_in6 *sin6; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
294 #endif |
521 | 295 |
296 value = cf->args->elts; | |
297 | |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
298 ngx_memzero(&u, sizeof(ngx_url_t)); |
521 | 299 |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
300 u.url = value[1]; |
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
301 u.listen = 1; |
619 | 302 |
1559
fe11e2a3946d
use pool instead of ngx_conf_t
Igor Sysoev <igor@sysoev.ru>
parents:
1487
diff
changeset
|
303 if (ngx_parse_url(cf->pool, &u) != NGX_OK) { |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
304 if (u.err) { |
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
305 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
306 "%s in \"%V\" of the \"listen\" directive", |
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
307 u.err, &u.url); |
521 | 308 } |
309 | |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
310 return NGX_CONF_ERROR; |
521 | 311 } |
312 | |
1136 | 313 cmcf = ngx_mail_conf_get_module_main_conf(cf, ngx_mail_core_module); |
521 | 314 |
2798 | 315 ls = cmcf->listen.elts; |
641 | 316 |
317 for (i = 0; i < cmcf->listen.nelts; i++) { | |
318 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
319 sa = (struct sockaddr *) ls[i].sockaddr; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
320 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
321 if (sa->sa_family != u.family) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
322 continue; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
323 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
324 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
325 switch (sa->sa_family) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
326 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
327 #if (NGX_HAVE_INET6) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
328 case AF_INET6: |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
329 off = offsetof(struct sockaddr_in6, sin6_addr); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
330 len = 16; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
331 sin6 = (struct sockaddr_in6 *) sa; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
332 port = sin6->sin6_port; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
333 break; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
334 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
335 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
336 default: /* AF_INET */ |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
337 off = offsetof(struct sockaddr_in, sin_addr); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
338 len = 4; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
339 sin = (struct sockaddr_in *) sa; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
340 port = sin->sin_port; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
341 break; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
342 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
343 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
344 if (ngx_memcmp(ls[i].sockaddr + off, u.sockaddr + off, len) != 0) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
345 continue; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
346 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
347 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
348 if (port != u.port) { |
641 | 349 continue; |
350 } | |
351 | |
352 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
353 "duplicate \"%V\" address and port pair", &u.url); |
577 | 354 return NGX_CONF_ERROR; |
521 | 355 } |
356 | |
2798 | 357 ls = ngx_array_push(&cmcf->listen); |
358 if (ls == NULL) { | |
641 | 359 return NGX_CONF_ERROR; |
360 } | |
563 | 361 |
2798 | 362 ngx_memzero(ls, sizeof(ngx_mail_listen_t)); |
641 | 363 |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
364 ngx_memcpy(ls->sockaddr, u.sockaddr, u.socklen); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
365 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
366 ls->socklen = u.socklen; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
367 ls->wildcard = u.wildcard; |
2798 | 368 ls->ctx = cf->ctx; |
521 | 369 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
370 for (m = 0; ngx_modules[m]; m++) { |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
371 if (ngx_modules[m]->type != NGX_MAIL_MODULE) { |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
372 continue; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
373 } |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
374 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
375 module = ngx_modules[m]->ctx; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
376 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
377 if (module->protocol == NULL) { |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
378 continue; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
379 } |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
380 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
381 for (i = 0; module->protocol->port[i]; i++) { |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
382 if (module->protocol->port[i] == u.port) { |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
383 cscf->protocol = module->protocol; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
384 break; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
385 } |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
386 } |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
387 } |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
388 |
2224 | 389 for (i = 2; i < cf->args->nelts; i++) { |
390 | |
391 if (ngx_strcmp(value[i].data, "bind") == 0) { | |
2798 | 392 ls->bind = 1; |
2224 | 393 continue; |
394 } | |
395 | |
2855
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
396 if (ngx_strncmp(value[i].data, "ipv6only=o", 10) == 0) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
397 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
398 struct sockaddr *sa; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
399 u_char buf[NGX_SOCKADDR_STRLEN]; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
400 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
401 sa = (struct sockaddr *) ls->sockaddr; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
402 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
403 if (sa->sa_family == AF_INET6) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
404 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
405 if (ngx_strcmp(&value[i].data[10], "n") == 0) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
406 ls->ipv6only = 1; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
407 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
408 } else if (ngx_strcmp(&value[i].data[10], "ff") == 0) { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
409 ls->ipv6only = 2; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
410 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
411 } else { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
412 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
413 "invalid ipv6only flags \"%s\"", |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
414 &value[i].data[9]); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
415 return NGX_CONF_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
416 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
417 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
418 ls->bind = 1; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
419 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
420 } else { |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
421 len = ngx_sock_ntop(sa, buf, NGX_SOCKADDR_STRLEN, 1); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
422 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
423 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
424 "ipv6only is not supported " |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
425 "on addr \"%*s\", ignored", len, buf); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
426 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
427 |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
428 continue; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
429 #else |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
430 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
431 "bind ipv6only is not supported " |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
432 "on this platform"); |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
433 return NGX_CONF_ERROR; |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
434 #endif |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
435 } |
a96a8c916b0c
mail proxy listen IPv6 support
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
436 |
2224 | 437 if (ngx_strcmp(value[i].data, "ssl") == 0) { |
438 #if (NGX_MAIL_SSL) | |
2798 | 439 ls->ssl = 1; |
2224 | 440 continue; |
441 #else | |
442 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
443 "the \"ssl\" parameter requires " | |
444 "ngx_mail_ssl_module"); | |
445 return NGX_CONF_ERROR; | |
446 #endif | |
447 } | |
448 | |
449 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
450 "the invalid \"%V\" parameter", &value[i]); | |
451 return NGX_CONF_ERROR; | |
641 | 452 } |
521 | 453 |
2224 | 454 return NGX_CONF_OK; |
521 | 455 } |
527 | 456 |
457 | |
458 static char * | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
459 ngx_mail_core_protocol(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
460 { |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
461 ngx_mail_core_srv_conf_t *cscf = conf; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
462 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
463 ngx_str_t *value; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
464 ngx_uint_t m; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
465 ngx_mail_module_t *module; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
466 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
467 value = cf->args->elts; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
468 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
469 for (m = 0; ngx_modules[m]; m++) { |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
470 if (ngx_modules[m]->type != NGX_MAIL_MODULE) { |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
471 continue; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
472 } |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
473 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
474 module = ngx_modules[m]->ctx; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
475 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
476 if (module->protocol |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
477 && ngx_strcmp(module->protocol->name.data, value[1].data) == 0) |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
478 { |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
479 cscf->protocol = module->protocol; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
480 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
481 return NGX_CONF_OK; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
482 } |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
483 } |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
484 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
485 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
486 "unknown protocol \"%V\"", &value[1]); |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
487 return NGX_CONF_ERROR; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
488 } |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
489 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
490 |
1892
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
491 static char * |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
492 ngx_mail_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
493 { |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
494 ngx_mail_core_srv_conf_t *cscf = conf; |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
495 |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
496 ngx_url_t u; |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
497 ngx_str_t *value; |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
498 |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
499 value = cf->args->elts; |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
500 |
1918 | 501 if (cscf->resolver != NGX_CONF_UNSET_PTR) { |
502 return "is duplicate"; | |
503 } | |
504 | |
1896
4c060e30476b
do not resolve SMTP clients by default
Igor Sysoev <igor@sysoev.ru>
parents:
1892
diff
changeset
|
505 if (ngx_strcmp(value[1].data, "off") == 0) { |
4c060e30476b
do not resolve SMTP clients by default
Igor Sysoev <igor@sysoev.ru>
parents:
1892
diff
changeset
|
506 cscf->resolver = NULL; |
4c060e30476b
do not resolve SMTP clients by default
Igor Sysoev <igor@sysoev.ru>
parents:
1892
diff
changeset
|
507 return NGX_CONF_OK; |
4c060e30476b
do not resolve SMTP clients by default
Igor Sysoev <igor@sysoev.ru>
parents:
1892
diff
changeset
|
508 } |
4c060e30476b
do not resolve SMTP clients by default
Igor Sysoev <igor@sysoev.ru>
parents:
1892
diff
changeset
|
509 |
1892
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
510 ngx_memzero(&u, sizeof(ngx_url_t)); |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
511 |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
512 u.host = value[1]; |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
513 u.port = 53; |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
514 |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
515 if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) { |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
516 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V: %s", &u.host, u.err); |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
517 return NGX_CONF_ERROR; |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
518 } |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
519 |
1913
c0f873458e2b
use cf->cycle->new_log because at merge stage cf->pool->log is old log
Igor Sysoev <igor@sysoev.ru>
parents:
1906
diff
changeset
|
520 cscf->resolver = ngx_resolver_create(cf, &u.addrs[0]); |
1892
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
521 if (cscf->resolver == NULL) { |
1896
4c060e30476b
do not resolve SMTP clients by default
Igor Sysoev <igor@sysoev.ru>
parents:
1892
diff
changeset
|
522 return NGX_CONF_OK; |
1892
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
523 } |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
524 |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
525 return NGX_CONF_OK; |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
526 } |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
527 |
057d362ee50e
resolver in smtp proxy module
Igor Sysoev <igor@sysoev.ru>
parents:
1559
diff
changeset
|
528 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
529 char * |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1481
diff
changeset
|
530 ngx_mail_capabilities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
527 | 531 { |
532 char *p = conf; | |
533 | |
534 ngx_str_t *c, *value; | |
535 ngx_uint_t i; | |
536 ngx_array_t *a; | |
537 | |
538 a = (ngx_array_t *) (p + cmd->offset); | |
539 | |
540 value = cf->args->elts; | |
541 | |
542 for (i = 1; i < cf->args->nelts; i++) { | |
543 c = ngx_array_push(a); | |
544 if (c == NULL) { | |
545 return NGX_CONF_ERROR; | |
546 } | |
547 | |
548 *c = value[i]; | |
549 } | |
550 | |
551 return NGX_CONF_OK; | |
552 } |