Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 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> |
| 10 | #include <ngx_mail.h> |
| 11 | |
| 12 | |
| 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, |
| 16 | void *child); |
| 17 | static char *ngx_mail_core_server(ngx_conf_t *cf, ngx_command_t *cmd, |
| 18 | void *conf); |
| 19 | static char *ngx_mail_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, |
| 20 | void *conf); |
Igor Sysoev | 4871408 | 2007-09-15 16:51:16 +0000 | [diff] [blame] | 21 | static char *ngx_mail_core_protocol(ngx_conf_t *cf, ngx_command_t *cmd, |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 22 | void *conf); |
Igor Sysoev | 4545046 | 2008-02-13 13:50:04 +0000 | [diff] [blame] | 23 | static char *ngx_mail_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, |
| 24 | void *conf); |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 25 | |
| 26 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 27 | static ngx_command_t ngx_mail_core_commands[] = { |
| 28 | |
| 29 | { ngx_string("server"), |
| 30 | NGX_MAIL_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, |
| 31 | ngx_mail_core_server, |
| 32 | 0, |
| 33 | 0, |
| 34 | NULL }, |
| 35 | |
| 36 | { ngx_string("listen"), |
| 37 | NGX_MAIL_SRV_CONF|NGX_CONF_TAKE12, |
| 38 | ngx_mail_core_listen, |
Igor Sysoev | 4871408 | 2007-09-15 16:51:16 +0000 | [diff] [blame] | 39 | NGX_MAIL_SRV_CONF_OFFSET, |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 40 | 0, |
| 41 | NULL }, |
| 42 | |
| 43 | { ngx_string("protocol"), |
| 44 | NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
Igor Sysoev | 4871408 | 2007-09-15 16:51:16 +0000 | [diff] [blame] | 45 | ngx_mail_core_protocol, |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 46 | NGX_MAIL_SRV_CONF_OFFSET, |
Igor Sysoev | 4871408 | 2007-09-15 16:51:16 +0000 | [diff] [blame] | 47 | 0, |
Igor Sysoev | 711c36b | 2007-09-14 13:58:49 +0000 | [diff] [blame] | 48 | NULL }, |
| 49 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 50 | { ngx_string("so_keepalive"), |
| 51 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG, |
| 52 | ngx_conf_set_flag_slot, |
| 53 | NGX_MAIL_SRV_CONF_OFFSET, |
| 54 | offsetof(ngx_mail_core_srv_conf_t, so_keepalive), |
| 55 | NULL }, |
| 56 | |
| 57 | { ngx_string("timeout"), |
| 58 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
| 59 | ngx_conf_set_msec_slot, |
| 60 | NGX_MAIL_SRV_CONF_OFFSET, |
| 61 | offsetof(ngx_mail_core_srv_conf_t, timeout), |
| 62 | NULL }, |
| 63 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 64 | { ngx_string("server_name"), |
| 65 | NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
| 66 | ngx_conf_set_str_slot, |
| 67 | NGX_MAIL_SRV_CONF_OFFSET, |
| 68 | offsetof(ngx_mail_core_srv_conf_t, server_name), |
| 69 | NULL }, |
| 70 | |
Igor Sysoev | 4545046 | 2008-02-13 13:50:04 +0000 | [diff] [blame] | 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), |
| 83 | NULL }, |
| 84 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 85 | ngx_null_command |
| 86 | }; |
| 87 | |
| 88 | |
| 89 | static ngx_mail_module_t ngx_mail_core_module_ctx = { |
Igor Sysoev | 4871408 | 2007-09-15 16:51:16 +0000 | [diff] [blame] | 90 | NULL, /* protocol */ |
| 91 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 92 | ngx_mail_core_create_main_conf, /* create main configuration */ |
| 93 | NULL, /* init main configuration */ |
| 94 | |
| 95 | ngx_mail_core_create_srv_conf, /* create server configuration */ |
| 96 | ngx_mail_core_merge_srv_conf /* merge server configuration */ |
| 97 | }; |
| 98 | |
| 99 | |
| 100 | ngx_module_t ngx_mail_core_module = { |
| 101 | NGX_MODULE_V1, |
| 102 | &ngx_mail_core_module_ctx, /* module context */ |
| 103 | ngx_mail_core_commands, /* module directives */ |
| 104 | NGX_MAIL_MODULE, /* module type */ |
| 105 | NULL, /* init master */ |
| 106 | NULL, /* init module */ |
| 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 |
| 113 | }; |
| 114 | |
| 115 | |
| 116 | static void * |
| 117 | ngx_mail_core_create_main_conf(ngx_conf_t *cf) |
| 118 | { |
| 119 | ngx_mail_core_main_conf_t *cmcf; |
| 120 | |
| 121 | cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_core_main_conf_t)); |
| 122 | if (cmcf == NULL) { |
Igor Sysoev | 260c432 | 2009-06-02 16:09:44 +0000 | [diff] [blame] | 123 | return NULL; |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | if (ngx_array_init(&cmcf->servers, cf->pool, 4, |
| 127 | sizeof(ngx_mail_core_srv_conf_t *)) |
| 128 | != NGX_OK) |
| 129 | { |
Igor Sysoev | 260c432 | 2009-06-02 16:09:44 +0000 | [diff] [blame] | 130 | return NULL; |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | if (ngx_array_init(&cmcf->listen, cf->pool, 4, sizeof(ngx_mail_listen_t)) |
| 134 | != NGX_OK) |
| 135 | { |
Igor Sysoev | 260c432 | 2009-06-02 16:09:44 +0000 | [diff] [blame] | 136 | return NULL; |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | return cmcf; |
| 140 | } |
| 141 | |
| 142 | |
| 143 | static void * |
| 144 | ngx_mail_core_create_srv_conf(ngx_conf_t *cf) |
| 145 | { |
| 146 | ngx_mail_core_srv_conf_t *cscf; |
| 147 | |
| 148 | cscf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_core_srv_conf_t)); |
| 149 | if (cscf == NULL) { |
| 150 | return NULL; |
| 151 | } |
| 152 | |
Igor Sysoev | 4871408 | 2007-09-15 16:51:16 +0000 | [diff] [blame] | 153 | /* |
| 154 | * set by ngx_pcalloc(): |
| 155 | * |
| 156 | * cscf->protocol = NULL; |
| 157 | */ |
| 158 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 159 | cscf->timeout = NGX_CONF_UNSET_MSEC; |
Igor Sysoev | 4545046 | 2008-02-13 13:50:04 +0000 | [diff] [blame] | 160 | cscf->resolver_timeout = NGX_CONF_UNSET_MSEC; |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 161 | cscf->so_keepalive = NGX_CONF_UNSET; |
| 162 | |
Igor Sysoev | 5fa1146 | 2008-02-16 13:46:33 +0000 | [diff] [blame] | 163 | cscf->resolver = NGX_CONF_UNSET_PTR; |
| 164 | |
Igor Sysoev | 4545046 | 2008-02-13 13:50:04 +0000 | [diff] [blame] | 165 | cscf->file_name = cf->conf_file->file.name.data; |
| 166 | cscf->line = cf->conf_file->line; |
| 167 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 168 | return cscf; |
| 169 | } |
| 170 | |
| 171 | |
| 172 | static char * |
| 173 | ngx_mail_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) |
| 174 | { |
| 175 | ngx_mail_core_srv_conf_t *prev = parent; |
| 176 | ngx_mail_core_srv_conf_t *conf = child; |
| 177 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 178 | ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000); |
Igor Sysoev | 4545046 | 2008-02-13 13:50:04 +0000 | [diff] [blame] | 179 | ngx_conf_merge_msec_value(conf->resolver_timeout, prev->resolver_timeout, |
| 180 | 30000); |
Igor Sysoev | 711c36b | 2007-09-14 13:58:49 +0000 | [diff] [blame] | 181 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 182 | ngx_conf_merge_value(conf->so_keepalive, prev->so_keepalive, 0); |
| 183 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 184 | |
| 185 | ngx_conf_merge_str_value(conf->server_name, prev->server_name, ""); |
| 186 | |
| 187 | if (conf->server_name.len == 0) { |
Igor Sysoev | 3be5257 | 2008-05-16 14:39:06 +0000 | [diff] [blame] | 188 | conf->server_name = cf->cycle->hostname; |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Igor Sysoev | 4871408 | 2007-09-15 16:51:16 +0000 | [diff] [blame] | 191 | if (conf->protocol == NULL) { |
| 192 | ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
| 193 | "unknown mail protocol for server in %s:%ui", |
| 194 | conf->file_name, conf->line); |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 195 | return NGX_CONF_ERROR; |
| 196 | } |
| 197 | |
Igor Sysoev | 5fa1146 | 2008-02-16 13:46:33 +0000 | [diff] [blame] | 198 | ngx_conf_merge_ptr_value(conf->resolver, prev->resolver, NULL); |
Igor Sysoev | 4545046 | 2008-02-13 13:50:04 +0000 | [diff] [blame] | 199 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 200 | return NGX_CONF_OK; |
| 201 | } |
| 202 | |
| 203 | |
| 204 | static char * |
| 205 | ngx_mail_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 206 | { |
| 207 | char *rv; |
| 208 | void *mconf; |
| 209 | ngx_uint_t m; |
| 210 | ngx_conf_t pcf; |
| 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; |
| 215 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 216 | ctx = ngx_pcalloc(cf->pool, sizeof(ngx_mail_conf_ctx_t)); |
| 217 | if (ctx == NULL) { |
| 218 | return NGX_CONF_ERROR; |
| 219 | } |
| 220 | |
| 221 | mail_ctx = cf->ctx; |
| 222 | ctx->main_conf = mail_ctx->main_conf; |
| 223 | |
| 224 | /* the server{}'s srv_conf */ |
| 225 | |
| 226 | ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_mail_max_module); |
| 227 | if (ctx->srv_conf == NULL) { |
| 228 | return NGX_CONF_ERROR; |
| 229 | } |
| 230 | |
| 231 | for (m = 0; ngx_modules[m]; m++) { |
| 232 | if (ngx_modules[m]->type != NGX_MAIL_MODULE) { |
| 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 | |
| 250 | cscf = ctx->srv_conf[ngx_mail_core_module.ctx_index]; |
| 251 | cscf->ctx = ctx; |
| 252 | |
| 253 | cmcf = ctx->main_conf[ngx_mail_core_module.ctx_index]; |
| 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; |
| 267 | cf->cmd_type = NGX_MAIL_SRV_CONF; |
| 268 | |
| 269 | rv = ngx_conf_parse(cf, NULL); |
| 270 | |
| 271 | *cf = pcf; |
| 272 | |
| 273 | return rv; |
| 274 | } |
| 275 | |
| 276 | |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 277 | static char * |
| 278 | ngx_mail_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 279 | { |
Igor Sysoev | 4871408 | 2007-09-15 16:51:16 +0000 | [diff] [blame] | 280 | ngx_mail_core_srv_conf_t *cscf = conf; |
| 281 | |
Igor Sysoev | 610cbd4 | 2009-05-18 12:20:22 +0000 | [diff] [blame] | 282 | size_t len, off; |
| 283 | in_port_t port; |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 284 | ngx_str_t *value; |
| 285 | ngx_url_t u; |
Igor Sysoev | 4871408 | 2007-09-15 16:51:16 +0000 | [diff] [blame] | 286 | ngx_uint_t i, m; |
Igor Sysoev | 610cbd4 | 2009-05-18 12:20:22 +0000 | [diff] [blame] | 287 | struct sockaddr *sa; |
Igor Sysoev | 4c9d367 | 2009-05-04 19:34:59 +0000 | [diff] [blame] | 288 | ngx_mail_listen_t *ls; |
Igor Sysoev | 4871408 | 2007-09-15 16:51:16 +0000 | [diff] [blame] | 289 | ngx_mail_module_t *module; |
Igor Sysoev | 610cbd4 | 2009-05-18 12:20:22 +0000 | [diff] [blame] | 290 | struct sockaddr_in *sin; |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 291 | ngx_mail_core_main_conf_t *cmcf; |
Igor Sysoev | 610cbd4 | 2009-05-18 12:20:22 +0000 | [diff] [blame] | 292 | #if (NGX_HAVE_INET6) |
| 293 | struct sockaddr_in6 *sin6; |
| 294 | #endif |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 295 | |
| 296 | value = cf->args->elts; |
| 297 | |
| 298 | ngx_memzero(&u, sizeof(ngx_url_t)); |
| 299 | |
| 300 | u.url = value[1]; |
| 301 | u.listen = 1; |
| 302 | |
Igor Sysoev | 7ed63ee | 2007-10-08 08:55:12 +0000 | [diff] [blame] | 303 | if (ngx_parse_url(cf->pool, &u) != NGX_OK) { |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 304 | if (u.err) { |
| 305 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 306 | "%s in \"%V\" of the \"listen\" directive", |
| 307 | u.err, &u.url); |
| 308 | } |
| 309 | |
| 310 | return NGX_CONF_ERROR; |
| 311 | } |
| 312 | |
| 313 | cmcf = ngx_mail_conf_get_module_main_conf(cf, ngx_mail_core_module); |
| 314 | |
Igor Sysoev | 4c9d367 | 2009-05-04 19:34:59 +0000 | [diff] [blame] | 315 | ls = cmcf->listen.elts; |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 316 | |
| 317 | for (i = 0; i < cmcf->listen.nelts; i++) { |
| 318 | |
Igor Sysoev | 610cbd4 | 2009-05-18 12:20:22 +0000 | [diff] [blame] | 319 | sa = (struct sockaddr *) ls[i].sockaddr; |
| 320 | |
| 321 | if (sa->sa_family != u.family) { |
| 322 | continue; |
| 323 | } |
| 324 | |
| 325 | switch (sa->sa_family) { |
| 326 | |
| 327 | #if (NGX_HAVE_INET6) |
| 328 | case AF_INET6: |
| 329 | off = offsetof(struct sockaddr_in6, sin6_addr); |
| 330 | len = 16; |
| 331 | sin6 = (struct sockaddr_in6 *) sa; |
| 332 | port = sin6->sin6_port; |
| 333 | break; |
| 334 | #endif |
| 335 | |
| 336 | default: /* AF_INET */ |
| 337 | off = offsetof(struct sockaddr_in, sin_addr); |
| 338 | len = 4; |
| 339 | sin = (struct sockaddr_in *) sa; |
| 340 | port = sin->sin_port; |
| 341 | break; |
| 342 | } |
| 343 | |
| 344 | if (ngx_memcmp(ls[i].sockaddr + off, u.sockaddr + off, len) != 0) { |
| 345 | continue; |
| 346 | } |
| 347 | |
| 348 | if (port != u.port) { |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 349 | continue; |
| 350 | } |
| 351 | |
| 352 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 353 | "duplicate \"%V\" address and port pair", &u.url); |
| 354 | return NGX_CONF_ERROR; |
| 355 | } |
| 356 | |
Igor Sysoev | 4c9d367 | 2009-05-04 19:34:59 +0000 | [diff] [blame] | 357 | ls = ngx_array_push(&cmcf->listen); |
| 358 | if (ls == NULL) { |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 359 | return NGX_CONF_ERROR; |
| 360 | } |
| 361 | |
Igor Sysoev | 4c9d367 | 2009-05-04 19:34:59 +0000 | [diff] [blame] | 362 | ngx_memzero(ls, sizeof(ngx_mail_listen_t)); |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 363 | |
Igor Sysoev | 610cbd4 | 2009-05-18 12:20:22 +0000 | [diff] [blame] | 364 | ngx_memcpy(ls->sockaddr, u.sockaddr, u.socklen); |
| 365 | |
| 366 | ls->socklen = u.socklen; |
| 367 | ls->wildcard = u.wildcard; |
Igor Sysoev | 4c9d367 | 2009-05-04 19:34:59 +0000 | [diff] [blame] | 368 | ls->ctx = cf->ctx; |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 369 | |
Igor Sysoev | 4871408 | 2007-09-15 16:51:16 +0000 | [diff] [blame] | 370 | for (m = 0; ngx_modules[m]; m++) { |
| 371 | if (ngx_modules[m]->type != NGX_MAIL_MODULE) { |
| 372 | continue; |
| 373 | } |
| 374 | |
| 375 | module = ngx_modules[m]->ctx; |
| 376 | |
| 377 | if (module->protocol == NULL) { |
| 378 | continue; |
| 379 | } |
| 380 | |
| 381 | for (i = 0; module->protocol->port[i]; i++) { |
| 382 | if (module->protocol->port[i] == u.port) { |
| 383 | cscf->protocol = module->protocol; |
| 384 | break; |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 389 | for (i = 2; i < cf->args->nelts; i++) { |
| 390 | |
| 391 | if (ngx_strcmp(value[i].data, "bind") == 0) { |
Igor Sysoev | 4c9d367 | 2009-05-04 19:34:59 +0000 | [diff] [blame] | 392 | ls->bind = 1; |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 393 | continue; |
| 394 | } |
| 395 | |
Igor Sysoev | 610cbd4 | 2009-05-18 12:20:22 +0000 | [diff] [blame] | 396 | if (ngx_strncmp(value[i].data, "ipv6only=o", 10) == 0) { |
| 397 | #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) |
| 398 | struct sockaddr *sa; |
| 399 | u_char buf[NGX_SOCKADDR_STRLEN]; |
| 400 | |
| 401 | sa = (struct sockaddr *) ls->sockaddr; |
| 402 | |
| 403 | if (sa->sa_family == AF_INET6) { |
| 404 | |
| 405 | if (ngx_strcmp(&value[i].data[10], "n") == 0) { |
| 406 | ls->ipv6only = 1; |
| 407 | |
| 408 | } else if (ngx_strcmp(&value[i].data[10], "ff") == 0) { |
| 409 | ls->ipv6only = 2; |
| 410 | |
| 411 | } else { |
| 412 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 413 | "invalid ipv6only flags \"%s\"", |
| 414 | &value[i].data[9]); |
| 415 | return NGX_CONF_ERROR; |
| 416 | } |
| 417 | |
| 418 | ls->bind = 1; |
| 419 | |
| 420 | } else { |
| 421 | len = ngx_sock_ntop(sa, buf, NGX_SOCKADDR_STRLEN, 1); |
| 422 | |
| 423 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 424 | "ipv6only is not supported " |
| 425 | "on addr \"%*s\", ignored", len, buf); |
| 426 | } |
| 427 | |
| 428 | continue; |
| 429 | #else |
| 430 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 431 | "bind ipv6only is not supported " |
| 432 | "on this platform"); |
| 433 | return NGX_CONF_ERROR; |
| 434 | #endif |
| 435 | } |
| 436 | |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 437 | if (ngx_strcmp(value[i].data, "ssl") == 0) { |
| 438 | #if (NGX_MAIL_SSL) |
Igor Sysoev | 4c9d367 | 2009-05-04 19:34:59 +0000 | [diff] [blame] | 439 | ls->ssl = 1; |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 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; |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Igor Sysoev | f100c78 | 2008-09-01 14:19:01 +0000 | [diff] [blame] | 454 | return NGX_CONF_OK; |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | |
| 458 | static char * |
Igor Sysoev | 4871408 | 2007-09-15 16:51:16 +0000 | [diff] [blame] | 459 | ngx_mail_core_protocol(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 460 | { |
| 461 | ngx_mail_core_srv_conf_t *cscf = conf; |
| 462 | |
| 463 | ngx_str_t *value; |
| 464 | ngx_uint_t m; |
| 465 | ngx_mail_module_t *module; |
| 466 | |
| 467 | value = cf->args->elts; |
| 468 | |
| 469 | for (m = 0; ngx_modules[m]; m++) { |
| 470 | if (ngx_modules[m]->type != NGX_MAIL_MODULE) { |
| 471 | continue; |
| 472 | } |
| 473 | |
| 474 | module = ngx_modules[m]->ctx; |
| 475 | |
| 476 | if (module->protocol |
| 477 | && ngx_strcmp(module->protocol->name.data, value[1].data) == 0) |
| 478 | { |
| 479 | cscf->protocol = module->protocol; |
| 480 | |
| 481 | return NGX_CONF_OK; |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 486 | "unknown protocol \"%V\"", &value[1]); |
| 487 | return NGX_CONF_ERROR; |
| 488 | } |
| 489 | |
| 490 | |
Igor Sysoev | 4545046 | 2008-02-13 13:50:04 +0000 | [diff] [blame] | 491 | static char * |
| 492 | ngx_mail_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 493 | { |
| 494 | ngx_mail_core_srv_conf_t *cscf = conf; |
| 495 | |
| 496 | ngx_url_t u; |
| 497 | ngx_str_t *value; |
| 498 | |
| 499 | value = cf->args->elts; |
| 500 | |
Igor Sysoev | 73eb97f | 2008-03-06 08:48:25 +0000 | [diff] [blame] | 501 | if (cscf->resolver != NGX_CONF_UNSET_PTR) { |
| 502 | return "is duplicate"; |
| 503 | } |
| 504 | |
Igor Sysoev | 5fa1146 | 2008-02-16 13:46:33 +0000 | [diff] [blame] | 505 | if (ngx_strcmp(value[1].data, "off") == 0) { |
| 506 | cscf->resolver = NULL; |
| 507 | return NGX_CONF_OK; |
| 508 | } |
| 509 | |
Igor Sysoev | 4545046 | 2008-02-13 13:50:04 +0000 | [diff] [blame] | 510 | ngx_memzero(&u, sizeof(ngx_url_t)); |
| 511 | |
| 512 | u.host = value[1]; |
| 513 | u.port = 53; |
| 514 | |
| 515 | if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) { |
| 516 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V: %s", &u.host, u.err); |
| 517 | return NGX_CONF_ERROR; |
| 518 | } |
| 519 | |
Igor Sysoev | dfd5511 | 2008-03-04 10:42:05 +0000 | [diff] [blame] | 520 | cscf->resolver = ngx_resolver_create(cf, &u.addrs[0]); |
Igor Sysoev | 4545046 | 2008-02-13 13:50:04 +0000 | [diff] [blame] | 521 | if (cscf->resolver == NULL) { |
Igor Sysoev | 5fa1146 | 2008-02-16 13:46:33 +0000 | [diff] [blame] | 522 | return NGX_CONF_OK; |
Igor Sysoev | 4545046 | 2008-02-13 13:50:04 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | return NGX_CONF_OK; |
| 526 | } |
| 527 | |
| 528 | |
Igor Sysoev | 4871408 | 2007-09-15 16:51:16 +0000 | [diff] [blame] | 529 | char * |
| 530 | ngx_mail_capabilities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | 02c8d18 | 2007-03-19 13:36:56 +0000 | [diff] [blame] | 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 | } |