Mercurial > hg > nginx-quic
annotate src/mail/ngx_mail.c @ 2812:dcb1b4d6ff54
bump version
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 06 May 2009 14:11:03 +0000 |
parents | a445bd4eb571 |
children | a96a8c916b0c |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
5 |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_event.h> |
1136 | 10 #include <ngx_mail.h> |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
11 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
12 |
1136 | 13 static char *ngx_mail_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
1956
cb8c0c8e0c27
use ngx_int_t in ngx_sort() callback
Igor Sysoev <igor@sysoev.ru>
parents:
1487
diff
changeset
|
14 static ngx_int_t ngx_mail_cmp_conf_in_addrs(const void *one, const void *two); |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
15 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
16 |
1136 | 17 ngx_uint_t ngx_mail_max_module; |
521 | 18 |
19 | |
1136 | 20 static ngx_command_t ngx_mail_commands[] = { |
21 | |
22 { ngx_string("mail"), | |
23 NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, | |
24 ngx_mail_block, | |
25 0, | |
26 0, | |
27 NULL }, | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 { ngx_string("imap"), |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
30 NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, |
1136 | 31 ngx_mail_block, |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
32 0, |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
33 0, |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
34 NULL }, |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
35 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
36 ngx_null_command |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 }; |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 |
577 | 39 |
1136 | 40 static ngx_core_module_t ngx_mail_module_ctx = { |
41 ngx_string("mail"), | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
42 NULL, |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
43 NULL |
577 | 44 }; |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
45 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 |
1136 | 47 ngx_module_t ngx_mail_module = { |
509 | 48 NGX_MODULE_V1, |
1136 | 49 &ngx_mail_module_ctx, /* module context */ |
50 ngx_mail_commands, /* module directives */ | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
51 NGX_CORE_MODULE, /* module type */ |
541 | 52 NULL, /* init master */ |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
53 NULL, /* init module */ |
541 | 54 NULL, /* init process */ |
55 NULL, /* init thread */ | |
56 NULL, /* exit thread */ | |
57 NULL, /* exit process */ | |
58 NULL, /* exit master */ | |
59 NGX_MODULE_V1_PADDING | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
60 }; |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
61 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
62 |
521 | 63 static char * |
1136 | 64 ngx_mail_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
65 { |
521 | 66 char *rv; |
641 | 67 u_char *text; |
68 size_t len; | |
69 ngx_uint_t i, a, l, m, mi, s, p, last, bind_all, done; | |
521 | 70 ngx_conf_t pcf; |
641 | 71 ngx_array_t in_ports; |
72 ngx_listening_t *ls; | |
2798 | 73 ngx_mail_listen_t *mls; |
1136 | 74 ngx_mail_module_t *module; |
2806 | 75 struct sockaddr_in sin; |
2798 | 76 ngx_mail_in_port_t *mip; |
1136 | 77 ngx_mail_conf_ctx_t *ctx; |
78 ngx_mail_conf_in_port_t *in_port; | |
79 ngx_mail_conf_in_addr_t *in_addr; | |
80 ngx_mail_core_srv_conf_t **cscfp; | |
81 ngx_mail_core_main_conf_t *cmcf; | |
521 | 82 |
1136 | 83 if (cmd->name.data[0] == 'i') { |
84 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
85 "the \"imap\" directive is deprecated, " | |
86 "use the \"mail\" directive instead"); | |
87 } | |
521 | 88 |
1136 | 89 /* the main mail context */ |
90 | |
91 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_mail_conf_ctx_t)); | |
521 | 92 if (ctx == NULL) { |
93 return NGX_CONF_ERROR; | |
94 } | |
95 | |
1136 | 96 *(ngx_mail_conf_ctx_t **) conf = ctx; |
521 | 97 |
98 /* count the number of the http modules and set up their indices */ | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
99 |
1136 | 100 ngx_mail_max_module = 0; |
521 | 101 for (m = 0; ngx_modules[m]; m++) { |
1136 | 102 if (ngx_modules[m]->type != NGX_MAIL_MODULE) { |
521 | 103 continue; |
104 } | |
105 | |
1136 | 106 ngx_modules[m]->ctx_index = ngx_mail_max_module++; |
521 | 107 } |
108 | |
109 | |
1136 | 110 /* the mail main_conf context, it is the same in the all mail contexts */ |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
111 |
521 | 112 ctx->main_conf = ngx_pcalloc(cf->pool, |
1136 | 113 sizeof(void *) * ngx_mail_max_module); |
521 | 114 if (ctx->main_conf == NULL) { |
115 return NGX_CONF_ERROR; | |
116 } | |
117 | |
118 | |
119 /* | |
1136 | 120 * the mail null srv_conf context, it is used to merge |
521 | 121 * the server{}s' srv_conf's |
122 */ | |
123 | |
1136 | 124 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_mail_max_module); |
521 | 125 if (ctx->srv_conf == NULL) { |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
126 return NGX_CONF_ERROR; |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
127 } |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
128 |
521 | 129 |
130 /* | |
131 * create the main_conf's, the null srv_conf's, and the null loc_conf's | |
1136 | 132 * of the all mail modules |
521 | 133 */ |
134 | |
135 for (m = 0; ngx_modules[m]; m++) { | |
1136 | 136 if (ngx_modules[m]->type != NGX_MAIL_MODULE) { |
521 | 137 continue; |
138 } | |
139 | |
140 module = ngx_modules[m]->ctx; | |
141 mi = ngx_modules[m]->ctx_index; | |
142 | |
143 if (module->create_main_conf) { | |
144 ctx->main_conf[mi] = module->create_main_conf(cf); | |
145 if (ctx->main_conf[mi] == NULL) { | |
146 return NGX_CONF_ERROR; | |
147 } | |
148 } | |
149 | |
150 if (module->create_srv_conf) { | |
151 ctx->srv_conf[mi] = module->create_srv_conf(cf); | |
152 if (ctx->srv_conf[mi] == NULL) { | |
153 return NGX_CONF_ERROR; | |
154 } | |
155 } | |
156 } | |
157 | |
158 | |
1136 | 159 /* parse inside the mail{} block */ |
521 | 160 |
161 pcf = *cf; | |
162 cf->ctx = ctx; | |
163 | |
1136 | 164 cf->module_type = NGX_MAIL_MODULE; |
165 cf->cmd_type = NGX_MAIL_MAIN_CONF; | |
521 | 166 rv = ngx_conf_parse(cf, NULL); |
167 | |
168 if (rv != NGX_CONF_OK) { | |
169 *cf = pcf; | |
170 return rv; | |
171 } | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
172 |
521 | 173 |
1136 | 174 /* init mail{} main_conf's, merge the server{}s' srv_conf's */ |
521 | 175 |
1136 | 176 cmcf = ctx->main_conf[ngx_mail_core_module.ctx_index]; |
521 | 177 cscfp = cmcf->servers.elts; |
178 | |
179 for (m = 0; ngx_modules[m]; m++) { | |
1136 | 180 if (ngx_modules[m]->type != NGX_MAIL_MODULE) { |
521 | 181 continue; |
182 } | |
183 | |
184 module = ngx_modules[m]->ctx; | |
185 mi = ngx_modules[m]->ctx_index; | |
186 | |
1136 | 187 /* init mail{} main_conf's */ |
521 | 188 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1377
diff
changeset
|
189 cf->ctx = ctx; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1377
diff
changeset
|
190 |
521 | 191 if (module->init_main_conf) { |
577 | 192 rv = module->init_main_conf(cf, ctx->main_conf[mi]); |
521 | 193 if (rv != NGX_CONF_OK) { |
194 *cf = pcf; | |
195 return rv; | |
196 } | |
197 } | |
198 | |
199 for (s = 0; s < cmcf->servers.nelts; s++) { | |
577 | 200 |
521 | 201 /* merge the server{}s' srv_conf's */ |
577 | 202 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1377
diff
changeset
|
203 cf->ctx = cscfp[s]->ctx; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1377
diff
changeset
|
204 |
521 | 205 if (module->merge_srv_conf) { |
206 rv = module->merge_srv_conf(cf, | |
207 ctx->srv_conf[mi], | |
208 cscfp[s]->ctx->srv_conf[mi]); | |
209 if (rv != NGX_CONF_OK) { | |
210 *cf = pcf; | |
211 return rv; | |
212 } | |
213 } | |
214 } | |
215 } | |
216 | |
577 | 217 *cf = pcf; |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
218 |
641 | 219 |
220 if (ngx_array_init(&in_ports, cf->temp_pool, 4, | |
1136 | 221 sizeof(ngx_mail_conf_in_port_t)) |
641 | 222 != NGX_OK) |
223 { | |
224 return NGX_CONF_ERROR; | |
225 } | |
226 | |
2798 | 227 mls = cmcf->listen.elts; |
641 | 228 |
229 for (l = 0; l < cmcf->listen.nelts; l++) { | |
230 | |
231 /* AF_INET only */ | |
232 | |
233 in_port = in_ports.elts; | |
234 for (p = 0; p < in_ports.nelts; p++) { | |
2798 | 235 if (in_port[p].port == mls[l].port) { |
641 | 236 in_port = &in_port[p]; |
237 goto found; | |
238 } | |
239 } | |
240 | |
241 in_port = ngx_array_push(&in_ports); | |
242 if (in_port == NULL) { | |
243 return NGX_CONF_ERROR; | |
244 } | |
245 | |
2798 | 246 in_port->port = mls[l].port; |
641 | 247 |
248 if (ngx_array_init(&in_port->addrs, cf->temp_pool, 2, | |
1136 | 249 sizeof(ngx_mail_conf_in_addr_t)) |
641 | 250 != NGX_OK) |
251 { | |
252 return NGX_CONF_ERROR; | |
253 } | |
254 | |
255 found: | |
256 | |
257 in_addr = ngx_array_push(&in_port->addrs); | |
258 if (in_addr == NULL) { | |
259 return NGX_CONF_ERROR; | |
260 } | |
261 | |
2798 | 262 in_addr->addr = mls[l].addr; |
263 in_addr->ctx = mls[l].ctx; | |
264 in_addr->bind = mls[l].bind; | |
2224 | 265 #if (NGX_MAIL_SSL) |
2798 | 266 in_addr->ssl = mls[l].ssl; |
2224 | 267 #endif |
641 | 268 } |
269 | |
270 /* optimize the lists of ports and addresses */ | |
271 | |
272 /* AF_INET only */ | |
273 | |
274 in_port = in_ports.elts; | |
275 for (p = 0; p < in_ports.nelts; p++) { | |
276 | |
1209
c6c33f81fd79
use stable search where it is required
Igor Sysoev <igor@sysoev.ru>
parents:
1136
diff
changeset
|
277 ngx_sort(in_port[p].addrs.elts, (size_t) in_port[p].addrs.nelts, |
c6c33f81fd79
use stable search where it is required
Igor Sysoev <igor@sysoev.ru>
parents:
1136
diff
changeset
|
278 sizeof(ngx_mail_conf_in_addr_t), ngx_mail_cmp_conf_in_addrs); |
641 | 279 |
280 in_addr = in_port[p].addrs.elts; | |
281 last = in_port[p].addrs.nelts; | |
282 | |
283 /* | |
284 * if there is the binding to the "*:port" then we need to bind() | |
285 * to the "*:port" only and ignore the other bindings | |
286 */ | |
287 | |
288 if (in_addr[last - 1].addr == INADDR_ANY) { | |
289 in_addr[last - 1].bind = 1; | |
290 bind_all = 0; | |
291 | |
292 } else { | |
293 bind_all = 1; | |
294 } | |
295 | |
296 for (a = 0; a < last; /* void */ ) { | |
297 | |
298 if (!bind_all && !in_addr[a].bind) { | |
299 a++; | |
300 continue; | |
301 } | |
302 | |
2806 | 303 ngx_memzero(&sin, sizeof(struct sockaddr_in)); |
304 | |
305 sin.sin_family = AF_INET; | |
306 sin.sin_addr.s_addr = in_addr[a].addr; | |
307 sin.sin_port = htons(in_port[p].port); | |
308 | |
309 ls = ngx_create_listening(cf, &sin, sizeof(struct sockaddr_in)); | |
641 | 310 if (ls == NULL) { |
2799
8b54548fef6e
delete ngx_listening_inet_stream_socket()
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
311 return NULL; |
8b54548fef6e
delete ngx_listening_inet_stream_socket()
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
312 } |
8b54548fef6e
delete ngx_listening_inet_stream_socket()
Igor Sysoev <igor@sysoev.ru>
parents:
2798
diff
changeset
|
313 |
641 | 314 ls->addr_ntop = 1; |
1136 | 315 ls->handler = ngx_mail_init_connection; |
641 | 316 ls->pool_size = 256; |
317 | |
2785
d478379e51ac
*) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents:
2224
diff
changeset
|
318 /* TODO: error_log directive */ |
d478379e51ac
*) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents:
2224
diff
changeset
|
319 ls->logp = &cf->cycle->new_log; |
641 | 320 ls->log.data = &ls->addr_text; |
321 ls->log.handler = ngx_accept_log_error; | |
322 | |
2798 | 323 mip = ngx_palloc(cf->pool, sizeof(ngx_mail_in_port_t)); |
324 if (mip == NULL) { | |
641 | 325 return NGX_CONF_ERROR; |
326 } | |
327 | |
2798 | 328 ls->servers = mip; |
641 | 329 |
330 in_addr = in_port[p].addrs.elts; | |
331 | |
332 if (in_addr[a].bind && in_addr[a].addr != INADDR_ANY) { | |
2798 | 333 mip->naddrs = 1; |
641 | 334 done = 0; |
335 | |
336 } else if (in_port[p].addrs.nelts > 1 | |
337 && in_addr[last - 1].addr == INADDR_ANY) | |
338 { | |
2798 | 339 mip->naddrs = last; |
641 | 340 done = 1; |
341 | |
342 } else { | |
2798 | 343 mip->naddrs = 1; |
641 | 344 done = 0; |
345 } | |
346 | |
347 #if 0 | |
348 ngx_log_error(NGX_LOG_ALERT, cf->log, 0, | |
349 "%ui: %V %d %ui %ui", | |
350 a, &ls->addr_text, in_addr[a].bind, | |
2798 | 351 mip->naddrs, last); |
641 | 352 #endif |
353 | |
2798 | 354 mip->addrs = ngx_pcalloc(cf->pool, |
355 mip->naddrs * sizeof(ngx_mail_in_addr_t)); | |
356 if (mip->addrs == NULL) { | |
641 | 357 return NGX_CONF_ERROR; |
358 } | |
359 | |
2798 | 360 for (i = 0; i < mip->naddrs; i++) { |
361 mip->addrs[i].addr = in_addr[i].addr; | |
362 mip->addrs[i].ctx = in_addr[i].ctx; | |
641 | 363 |
2049 | 364 text = ngx_pnalloc(cf->pool, |
2197
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
365 NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1); |
641 | 366 if (text == NULL) { |
367 return NGX_CONF_ERROR; | |
368 } | |
369 | |
370 len = ngx_inet_ntop(AF_INET, &in_addr[i].addr, text, | |
2197
74477ea8074f
*) remove zero termination in ngx_inet_ntop() and ngx_sock_ntop()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
371 NGX_INET_ADDRSTRLEN); |
641 | 372 |
373 len = ngx_sprintf(text + len, ":%d", in_port[p].port) - text; | |
374 | |
2798 | 375 mip->addrs[i].addr_text.len = len; |
376 mip->addrs[i].addr_text.data = text; | |
2224 | 377 |
378 #if (NGX_MAIL_SSL) | |
2798 | 379 mip->addrs[i].ssl = in_addr[i].ssl; |
2224 | 380 #endif |
641 | 381 } |
382 | |
383 if (done) { | |
384 break; | |
385 } | |
386 | |
387 in_addr++; | |
388 in_port[p].addrs.elts = in_addr; | |
389 last--; | |
390 | |
391 a = 0; | |
392 } | |
393 } | |
394 | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
395 return NGX_CONF_OK; |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
396 } |
641 | 397 |
398 | |
1956
cb8c0c8e0c27
use ngx_int_t in ngx_sort() callback
Igor Sysoev <igor@sysoev.ru>
parents:
1487
diff
changeset
|
399 static ngx_int_t |
1136 | 400 ngx_mail_cmp_conf_in_addrs(const void *one, const void *two) |
641 | 401 { |
1136 | 402 ngx_mail_conf_in_addr_t *first, *second; |
641 | 403 |
1136 | 404 first = (ngx_mail_conf_in_addr_t *) one; |
405 second = (ngx_mail_conf_in_addr_t *) two; | |
641 | 406 |
407 if (first->addr == INADDR_ANY) { | |
408 /* the INADDR_ANY must be the last resort, shift it to the end */ | |
409 return 1; | |
410 } | |
411 | |
412 if (first->bind && !second->bind) { | |
413 /* shift explicit bind()ed addresses to the start */ | |
414 return -1; | |
415 } | |
416 | |
417 if (!first->bind && second->bind) { | |
418 /* shift explicit bind()ed addresses to the start */ | |
419 return 1; | |
420 } | |
421 | |
422 /* do not sort by default */ | |
423 | |
424 return 0; | |
425 } |