Mercurial > hg > nginx
comparison src/mail/ngx_mail.c @ 6171:f61049c80458
Mail: embed ngx_mail_listen_t into ngx_mail_conf_addr_t.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Mon, 08 Jun 2015 23:11:58 +0300 |
parents | 3c344ea7d88b |
children | 1729d8d3eb3a |
comparison
equal
deleted
inserted
replaced
6170:c13091e6292c | 6171:f61049c80458 |
---|---|
236 ngx_mail_conf_addr_t *addr; | 236 ngx_mail_conf_addr_t *addr; |
237 #if (NGX_HAVE_INET6) | 237 #if (NGX_HAVE_INET6) |
238 struct sockaddr_in6 *sin6; | 238 struct sockaddr_in6 *sin6; |
239 #endif | 239 #endif |
240 | 240 |
241 sa = (struct sockaddr *) &listen->sockaddr; | 241 sa = &listen->u.sockaddr; |
242 | 242 |
243 switch (sa->sa_family) { | 243 switch (sa->sa_family) { |
244 | 244 |
245 #if (NGX_HAVE_INET6) | 245 #if (NGX_HAVE_INET6) |
246 case AF_INET6: | 246 case AF_INET6: |
247 sin6 = (struct sockaddr_in6 *) sa; | 247 sin6 = &listen->u.sockaddr_in6; |
248 p = sin6->sin6_port; | 248 p = sin6->sin6_port; |
249 break; | 249 break; |
250 #endif | 250 #endif |
251 | 251 |
252 #if (NGX_HAVE_UNIX_DOMAIN) | 252 #if (NGX_HAVE_UNIX_DOMAIN) |
254 p = 0; | 254 p = 0; |
255 break; | 255 break; |
256 #endif | 256 #endif |
257 | 257 |
258 default: /* AF_INET */ | 258 default: /* AF_INET */ |
259 sin = (struct sockaddr_in *) sa; | 259 sin = &listen->u.sockaddr_in; |
260 p = sin->sin_port; | 260 p = sin->sin_port; |
261 break; | 261 break; |
262 } | 262 } |
263 | 263 |
264 port = ports->elts; | 264 port = ports->elts; |
294 addr = ngx_array_push(&port->addrs); | 294 addr = ngx_array_push(&port->addrs); |
295 if (addr == NULL) { | 295 if (addr == NULL) { |
296 return NGX_ERROR; | 296 return NGX_ERROR; |
297 } | 297 } |
298 | 298 |
299 addr->sockaddr = (struct sockaddr *) &listen->sockaddr; | 299 addr->opt = *listen; |
300 addr->socklen = listen->socklen; | |
301 addr->ctx = listen->ctx; | |
302 addr->bind = listen->bind; | |
303 addr->wildcard = listen->wildcard; | |
304 addr->so_keepalive = listen->so_keepalive; | |
305 #if (NGX_HAVE_KEEPALIVE_TUNABLE) | |
306 addr->tcp_keepidle = listen->tcp_keepidle; | |
307 addr->tcp_keepintvl = listen->tcp_keepintvl; | |
308 addr->tcp_keepcnt = listen->tcp_keepcnt; | |
309 #endif | |
310 #if (NGX_MAIL_SSL) | |
311 addr->ssl = listen->ssl; | |
312 #endif | |
313 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) | |
314 addr->ipv6only = listen->ipv6only; | |
315 #endif | |
316 | 300 |
317 return NGX_OK; | 301 return NGX_OK; |
318 } | 302 } |
319 | 303 |
320 | 304 |
340 /* | 324 /* |
341 * if there is the binding to the "*:port" then we need to bind() | 325 * if there is the binding to the "*:port" then we need to bind() |
342 * to the "*:port" only and ignore the other bindings | 326 * to the "*:port" only and ignore the other bindings |
343 */ | 327 */ |
344 | 328 |
345 if (addr[last - 1].wildcard) { | 329 if (addr[last - 1].opt.wildcard) { |
346 addr[last - 1].bind = 1; | 330 addr[last - 1].opt.bind = 1; |
347 bind_wildcard = 1; | 331 bind_wildcard = 1; |
348 | 332 |
349 } else { | 333 } else { |
350 bind_wildcard = 0; | 334 bind_wildcard = 0; |
351 } | 335 } |
352 | 336 |
353 i = 0; | 337 i = 0; |
354 | 338 |
355 while (i < last) { | 339 while (i < last) { |
356 | 340 |
357 if (bind_wildcard && !addr[i].bind) { | 341 if (bind_wildcard && !addr[i].opt.bind) { |
358 i++; | 342 i++; |
359 continue; | 343 continue; |
360 } | 344 } |
361 | 345 |
362 ls = ngx_create_listening(cf, addr[i].sockaddr, addr[i].socklen); | 346 ls = ngx_create_listening(cf, &addr[i].opt.u.sockaddr, |
347 addr[i].opt.socklen); | |
363 if (ls == NULL) { | 348 if (ls == NULL) { |
364 return NGX_CONF_ERROR; | 349 return NGX_CONF_ERROR; |
365 } | 350 } |
366 | 351 |
367 ls->addr_ntop = 1; | 352 ls->addr_ntop = 1; |
368 ls->handler = ngx_mail_init_connection; | 353 ls->handler = ngx_mail_init_connection; |
369 ls->pool_size = 256; | 354 ls->pool_size = 256; |
370 | 355 |
371 cscf = addr->ctx->srv_conf[ngx_mail_core_module.ctx_index]; | 356 cscf = addr->opt.ctx->srv_conf[ngx_mail_core_module.ctx_index]; |
372 | 357 |
373 ls->logp = cscf->error_log; | 358 ls->logp = cscf->error_log; |
374 ls->log.data = &ls->addr_text; | 359 ls->log.data = &ls->addr_text; |
375 ls->log.handler = ngx_accept_log_error; | 360 ls->log.handler = ngx_accept_log_error; |
376 | 361 |
377 ls->keepalive = addr[i].so_keepalive; | 362 ls->keepalive = addr[i].opt.so_keepalive; |
378 #if (NGX_HAVE_KEEPALIVE_TUNABLE) | 363 #if (NGX_HAVE_KEEPALIVE_TUNABLE) |
379 ls->keepidle = addr[i].tcp_keepidle; | 364 ls->keepidle = addr[i].opt.tcp_keepidle; |
380 ls->keepintvl = addr[i].tcp_keepintvl; | 365 ls->keepintvl = addr[i].opt.tcp_keepintvl; |
381 ls->keepcnt = addr[i].tcp_keepcnt; | 366 ls->keepcnt = addr[i].opt.tcp_keepcnt; |
382 #endif | 367 #endif |
383 | 368 |
384 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) | 369 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) |
385 ls->ipv6only = addr[i].ipv6only; | 370 ls->ipv6only = addr[i].opt.ipv6only; |
386 #endif | 371 #endif |
387 | 372 |
388 mport = ngx_palloc(cf->pool, sizeof(ngx_mail_port_t)); | 373 mport = ngx_palloc(cf->pool, sizeof(ngx_mail_port_t)); |
389 if (mport == NULL) { | 374 if (mport == NULL) { |
390 return NGX_CONF_ERROR; | 375 return NGX_CONF_ERROR; |
437 | 422 |
438 addrs = mport->addrs; | 423 addrs = mport->addrs; |
439 | 424 |
440 for (i = 0; i < mport->naddrs; i++) { | 425 for (i = 0; i < mport->naddrs; i++) { |
441 | 426 |
442 sin = (struct sockaddr_in *) addr[i].sockaddr; | 427 sin = &addr[i].opt.u.sockaddr_in; |
443 addrs[i].addr = sin->sin_addr.s_addr; | 428 addrs[i].addr = sin->sin_addr.s_addr; |
444 | 429 |
445 addrs[i].conf.ctx = addr[i].ctx; | 430 addrs[i].conf.ctx = addr[i].opt.ctx; |
446 #if (NGX_MAIL_SSL) | 431 #if (NGX_MAIL_SSL) |
447 addrs[i].conf.ssl = addr[i].ssl; | 432 addrs[i].conf.ssl = addr[i].opt.ssl; |
448 #endif | 433 #endif |
449 | 434 |
450 len = ngx_sock_ntop(addr[i].sockaddr, addr[i].socklen, buf, | 435 len = ngx_sock_ntop(&addr[i].opt.u.sockaddr, addr[i].opt.socklen, buf, |
451 NGX_SOCKADDR_STRLEN, 1); | 436 NGX_SOCKADDR_STRLEN, 1); |
452 | 437 |
453 p = ngx_pnalloc(cf->pool, len); | 438 p = ngx_pnalloc(cf->pool, len); |
454 if (p == NULL) { | 439 if (p == NULL) { |
455 return NGX_ERROR; | 440 return NGX_ERROR; |
486 | 471 |
487 addrs6 = mport->addrs; | 472 addrs6 = mport->addrs; |
488 | 473 |
489 for (i = 0; i < mport->naddrs; i++) { | 474 for (i = 0; i < mport->naddrs; i++) { |
490 | 475 |
491 sin6 = (struct sockaddr_in6 *) addr[i].sockaddr; | 476 sin6 = &addr[i].opt.u.sockaddr_in6; |
492 addrs6[i].addr6 = sin6->sin6_addr; | 477 addrs6[i].addr6 = sin6->sin6_addr; |
493 | 478 |
494 addrs6[i].conf.ctx = addr[i].ctx; | 479 addrs6[i].conf.ctx = addr[i].opt.ctx; |
495 #if (NGX_MAIL_SSL) | 480 #if (NGX_MAIL_SSL) |
496 addrs6[i].conf.ssl = addr[i].ssl; | 481 addrs6[i].conf.ssl = addr[i].opt.ssl; |
497 #endif | 482 #endif |
498 | 483 |
499 len = ngx_sock_ntop(addr[i].sockaddr, addr[i].socklen, buf, | 484 len = ngx_sock_ntop(&addr[i].opt.u.sockaddr, addr[i].opt.socklen, buf, |
500 NGX_SOCKADDR_STRLEN, 1); | 485 NGX_SOCKADDR_STRLEN, 1); |
501 | 486 |
502 p = ngx_pnalloc(cf->pool, len); | 487 p = ngx_pnalloc(cf->pool, len); |
503 if (p == NULL) { | 488 if (p == NULL) { |
504 return NGX_ERROR; | 489 return NGX_ERROR; |
522 ngx_mail_conf_addr_t *first, *second; | 507 ngx_mail_conf_addr_t *first, *second; |
523 | 508 |
524 first = (ngx_mail_conf_addr_t *) one; | 509 first = (ngx_mail_conf_addr_t *) one; |
525 second = (ngx_mail_conf_addr_t *) two; | 510 second = (ngx_mail_conf_addr_t *) two; |
526 | 511 |
527 if (first->wildcard) { | 512 if (first->opt.wildcard) { |
528 /* a wildcard must be the last resort, shift it to the end */ | 513 /* a wildcard must be the last resort, shift it to the end */ |
529 return 1; | 514 return 1; |
530 } | 515 } |
531 | 516 |
532 if (second->wildcard) { | 517 if (second->opt.wildcard) { |
533 /* a wildcard must be the last resort, shift it to the end */ | 518 /* a wildcard must be the last resort, shift it to the end */ |
534 return -1; | 519 return -1; |
535 } | 520 } |
536 | 521 |
537 if (first->bind && !second->bind) { | 522 if (first->opt.bind && !second->opt.bind) { |
538 /* shift explicit bind()ed addresses to the start */ | 523 /* shift explicit bind()ed addresses to the start */ |
539 return -1; | 524 return -1; |
540 } | 525 } |
541 | 526 |
542 if (!first->bind && second->bind) { | 527 if (!first->opt.bind && second->opt.bind) { |
543 /* shift explicit bind()ed addresses to the start */ | 528 /* shift explicit bind()ed addresses to the start */ |
544 return 1; | 529 return 1; |
545 } | 530 } |
546 | 531 |
547 /* do not sort by default */ | 532 /* do not sort by default */ |