Mercurial > hg > nginx-vendor-0-8
comparison src/mail/ngx_mail_handler.c @ 492:98143f74eb3d NGINX_0_7_58
nginx 0.7.58
*) Feature: a "listen" directive of the mail proxy module supports IPv6.
*) Feature: the "image_filter_jpeg_quality" directive.
*) Feature: the "client_body_in_single_buffer" directive.
*) Feature: the $request_body variable.
*) Bugfix: in ngx_http_autoindex_module in file name links having a ":"
symbol in the name.
*) Bugfix: "make upgrade" procedure did not work; the bug had appeared
in 0.7.53.
Thanks to Denis F. Latypoff.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 18 May 2009 00:00:00 +0400 |
parents | 6484cbba0222 |
children | f0cac61857ae |
comparison
equal
deleted
inserted
replaced
491:bb2281a3edb6 | 492:98143f74eb3d |
---|---|
19 | 19 |
20 | 20 |
21 void | 21 void |
22 ngx_mail_init_connection(ngx_connection_t *c) | 22 ngx_mail_init_connection(ngx_connection_t *c) |
23 { | 23 { |
24 in_addr_t in_addr; | 24 ngx_uint_t i; |
25 socklen_t len; | 25 ngx_mail_port_t *port; |
26 ngx_uint_t i; | 26 struct sockaddr *sa; |
27 struct sockaddr_in sin; | 27 struct sockaddr_in *sin; |
28 ngx_mail_log_ctx_t *ctx; | 28 ngx_mail_log_ctx_t *ctx; |
29 ngx_mail_in_port_t *mip; | 29 ngx_mail_in_addr_t *addr; |
30 ngx_mail_in_addr_t *mia; | 30 ngx_mail_session_t *s; |
31 ngx_mail_session_t *s; | 31 ngx_mail_addr_conf_t *addr_conf; |
32 #if (NGX_HAVE_INET6) | |
33 struct sockaddr_in6 *sin6; | |
34 ngx_mail_in6_addr_t *addr6; | |
35 #endif | |
36 | |
32 | 37 |
33 /* find the server configuration for the address:port */ | 38 /* find the server configuration for the address:port */ |
34 | 39 |
35 /* AF_INET only */ | 40 /* AF_INET only */ |
36 | 41 |
37 mip = c->listening->servers; | 42 port = c->listening->servers; |
38 mia = mip->addrs; | 43 |
39 | 44 if (port->naddrs > 1) { |
40 i = 0; | |
41 | |
42 if (mip->naddrs > 1) { | |
43 | 45 |
44 /* | 46 /* |
45 * There are several addresses on this port and one of them | 47 * There are several addresses on this port and one of them |
46 * is the "*:port" wildcard so getsockname() is needed to determine | 48 * is the "*:port" wildcard so getsockname() is needed to determine |
47 * the server address. | 49 * the server address. |
48 * | 50 * |
49 * AcceptEx() already gave this address. | 51 * AcceptEx() already gave this address. |
50 */ | 52 */ |
51 | 53 |
52 #if (NGX_WIN32) | 54 if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) { |
53 if (c->local_sockaddr) { | 55 ngx_mail_close_connection(c); |
54 in_addr = | 56 return; |
55 ((struct sockaddr_in *) c->local_sockaddr)->sin_addr.s_addr; | 57 } |
56 | 58 |
57 } else | 59 sa = c->local_sockaddr; |
58 #endif | 60 |
59 { | 61 switch (sa->sa_family) { |
60 len = sizeof(struct sockaddr_in); | 62 |
61 if (getsockname(c->fd, (struct sockaddr *) &sin, &len) == -1) { | 63 #if (NGX_HAVE_INET6) |
62 ngx_connection_error(c, ngx_socket_errno, | 64 case AF_INET6: |
63 "getsockname() failed"); | 65 sin6 = (struct sockaddr_in6 *) sa; |
64 ngx_mail_close_connection(c); | 66 |
65 return; | 67 addr6 = port->addrs; |
68 | |
69 /* the last address is "*" */ | |
70 | |
71 for (i = 0; i < port->naddrs - 1; i++) { | |
72 if (ngx_memcmp(&addr6[i].addr6, &sin6->sin6_addr, 16) == 0) { | |
73 break; | |
74 } | |
66 } | 75 } |
67 | 76 |
68 in_addr = sin.sin_addr.s_addr; | 77 addr_conf = &addr6[i].conf; |
69 } | 78 |
70 | 79 break; |
71 /* the last address is "*" */ | 80 #endif |
72 | 81 |
73 for ( /* void */ ; i < mip->naddrs - 1; i++) { | 82 default: /* AF_INET */ |
74 if (in_addr == mia[i].addr) { | 83 sin = (struct sockaddr_in *) sa; |
75 break; | 84 |
85 addr = port->addrs; | |
86 | |
87 /* the last address is "*" */ | |
88 | |
89 for (i = 0; i < port->naddrs - 1; i++) { | |
90 if (addr[i].addr == sin->sin_addr.s_addr) { | |
91 break; | |
92 } | |
76 } | 93 } |
77 } | 94 |
78 } | 95 addr_conf = &addr[i].conf; |
79 | 96 |
97 break; | |
98 } | |
99 | |
100 } else { | |
101 switch (c->local_sockaddr->sa_family) { | |
102 | |
103 #if (NGX_HAVE_INET6) | |
104 case AF_INET6: | |
105 addr6 = port->addrs; | |
106 addr_conf = &addr6[0].conf; | |
107 break; | |
108 #endif | |
109 | |
110 default: /* AF_INET */ | |
111 addr = port->addrs; | |
112 addr_conf = &addr[0].conf; | |
113 break; | |
114 } | |
115 } | |
80 | 116 |
81 s = ngx_pcalloc(c->pool, sizeof(ngx_mail_session_t)); | 117 s = ngx_pcalloc(c->pool, sizeof(ngx_mail_session_t)); |
82 if (s == NULL) { | 118 if (s == NULL) { |
83 ngx_mail_close_connection(c); | 119 ngx_mail_close_connection(c); |
84 return; | 120 return; |
85 } | 121 } |
86 | 122 |
87 s->main_conf = mia[i].ctx->main_conf; | 123 s->main_conf = addr_conf->ctx->main_conf; |
88 s->srv_conf = mia[i].ctx->srv_conf; | 124 s->srv_conf = addr_conf->ctx->srv_conf; |
89 | 125 |
90 s->addr_text = &mia[i].addr_text; | 126 s->addr_text = &addr_conf->addr_text; |
91 | 127 |
92 c->data = s; | 128 c->data = s; |
93 s->connection = c; | 129 s->connection = c; |
94 | 130 |
95 ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%ui client %V connected to %V", | 131 ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%ui client %V connected to %V", |
122 | 158 |
123 ngx_mail_ssl_init_connection(&sslcf->ssl, c); | 159 ngx_mail_ssl_init_connection(&sslcf->ssl, c); |
124 return; | 160 return; |
125 } | 161 } |
126 | 162 |
127 if (mia[i].ssl) { | 163 if (addr_conf->ssl) { |
128 | 164 |
129 c->log->action = "SSL handshaking"; | 165 c->log->action = "SSL handshaking"; |
130 | 166 |
131 if (sslcf->ssl.ctx == NULL) { | 167 if (sslcf->ssl.ctx == NULL) { |
132 ngx_log_error(NGX_LOG_ERR, c->log, 0, | 168 ngx_log_error(NGX_LOG_ERR, c->log, 0, |