Mercurial > hg > nginx-quic
comparison src/mail/ngx_mail_smtp_handler.c @ 5475:07dd5bd222ac
Changed resolver API to use ngx_addr_t.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Fri, 06 Dec 2013 14:30:27 +0400 |
parents | 04e43d03e153 |
children | 98876ce2a7fd |
comparison
equal
deleted
inserted
replaced
5474:b43b02bb54db | 5475:07dd5bd222ac |
---|---|
53 | 53 |
54 | 54 |
55 void | 55 void |
56 ngx_mail_smtp_init_session(ngx_mail_session_t *s, ngx_connection_t *c) | 56 ngx_mail_smtp_init_session(ngx_mail_session_t *s, ngx_connection_t *c) |
57 { | 57 { |
58 struct sockaddr_in *sin; | |
59 ngx_resolver_ctx_t *ctx; | 58 ngx_resolver_ctx_t *ctx; |
60 ngx_mail_core_srv_conf_t *cscf; | 59 ngx_mail_core_srv_conf_t *cscf; |
61 | 60 |
62 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); | 61 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
63 | 62 |
65 s->host = smtp_unavailable; | 64 s->host = smtp_unavailable; |
66 ngx_mail_smtp_greeting(s, c); | 65 ngx_mail_smtp_greeting(s, c); |
67 return; | 66 return; |
68 } | 67 } |
69 | 68 |
70 if (c->sockaddr->sa_family != AF_INET) { | 69 #if (NGX_HAVE_UNIX_DOMAIN) |
70 if (c->sockaddr->sa_family == AF_UNIX) { | |
71 s->host = smtp_tempunavail; | 71 s->host = smtp_tempunavail; |
72 ngx_mail_smtp_greeting(s, c); | 72 ngx_mail_smtp_greeting(s, c); |
73 return; | 73 return; |
74 } | 74 } |
75 #endif | |
75 | 76 |
76 c->log->action = "in resolving client address"; | 77 c->log->action = "in resolving client address"; |
77 | 78 |
78 ctx = ngx_resolve_start(cscf->resolver, NULL); | 79 ctx = ngx_resolve_start(cscf->resolver, NULL); |
79 if (ctx == NULL) { | 80 if (ctx == NULL) { |
80 ngx_mail_close_connection(c); | 81 ngx_mail_close_connection(c); |
81 return; | 82 return; |
82 } | 83 } |
83 | 84 |
84 /* AF_INET only */ | 85 ctx->addr.sockaddr = c->sockaddr; |
85 | 86 ctx->addr.socklen = c->socklen; |
86 sin = (struct sockaddr_in *) c->sockaddr; | |
87 | |
88 ctx->addr = sin->sin_addr.s_addr; | |
89 ctx->handler = ngx_mail_smtp_resolve_addr_handler; | 87 ctx->handler = ngx_mail_smtp_resolve_addr_handler; |
90 ctx->data = s; | 88 ctx->data = s; |
91 ctx->timeout = cscf->resolver_timeout; | 89 ctx->timeout = cscf->resolver_timeout; |
92 | 90 |
93 if (ngx_resolve_addr(ctx) != NGX_OK) { | 91 if (ngx_resolve_addr(ctx) != NGX_OK) { |
179 | 177 |
180 | 178 |
181 static void | 179 static void |
182 ngx_mail_smtp_resolve_name_handler(ngx_resolver_ctx_t *ctx) | 180 ngx_mail_smtp_resolve_name_handler(ngx_resolver_ctx_t *ctx) |
183 { | 181 { |
184 in_addr_t addr; | |
185 ngx_uint_t i; | 182 ngx_uint_t i; |
186 ngx_connection_t *c; | 183 ngx_connection_t *c; |
187 struct sockaddr_in *sin; | |
188 ngx_mail_session_t *s; | 184 ngx_mail_session_t *s; |
189 | 185 |
190 s = ctx->data; | 186 s = ctx->data; |
191 c = s->connection; | 187 c = s->connection; |
192 | 188 |
203 s->host = smtp_tempunavail; | 199 s->host = smtp_tempunavail; |
204 } | 200 } |
205 | 201 |
206 } else { | 202 } else { |
207 | 203 |
208 /* AF_INET only */ | 204 #if (NGX_DEBUG) |
209 | 205 { |
210 sin = (struct sockaddr_in *) c->sockaddr; | 206 u_char text[NGX_SOCKADDR_STRLEN]; |
207 ngx_str_t addr; | |
208 | |
209 addr.data = text; | |
211 | 210 |
212 for (i = 0; i < ctx->naddrs; i++) { | 211 for (i = 0; i < ctx->naddrs; i++) { |
213 | 212 addr.len = ngx_sock_ntop(ctx->addrs[i].sockaddr, |
214 addr = ctx->addrs[i]; | 213 ctx->addrs[i].socklen, |
215 | 214 text, NGX_SOCKADDR_STRLEN, 0); |
216 ngx_log_debug4(NGX_LOG_DEBUG_MAIL, c->log, 0, | 215 |
217 "name was resolved to %ud.%ud.%ud.%ud", | 216 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
218 (ntohl(addr) >> 24) & 0xff, | 217 "name was resolved to %V", &addr); |
219 (ntohl(addr) >> 16) & 0xff, | 218 } |
220 (ntohl(addr) >> 8) & 0xff, | 219 } |
221 ntohl(addr) & 0xff); | 220 #endif |
222 | 221 |
223 if (addr == sin->sin_addr.s_addr) { | 222 for (i = 0; i < ctx->naddrs; i++) { |
223 if (ngx_cmp_sockaddr(ctx->addrs[i].sockaddr, ctx->addrs[i].socklen, | |
224 c->sockaddr, c->socklen, 0) | |
225 == NGX_OK) | |
226 { | |
224 goto found; | 227 goto found; |
225 } | 228 } |
226 } | 229 } |
227 | 230 |
228 s->host = smtp_unavailable; | 231 s->host = smtp_unavailable; |