comparison src/mail/ngx_mail.c @ 2798:268d8d3faa34

axe imap module artifacts
author Igor Sysoev <igor@sysoev.ru>
date Mon, 04 May 2009 19:34:59 +0000
parents d478379e51ac
children 8b54548fef6e
comparison
equal deleted inserted replaced
2797:90422d071d3f 2798:268d8d3faa34
68 size_t len; 68 size_t len;
69 ngx_uint_t i, a, l, m, mi, s, p, last, bind_all, done; 69 ngx_uint_t i, a, l, m, mi, s, p, last, bind_all, done;
70 ngx_conf_t pcf; 70 ngx_conf_t pcf;
71 ngx_array_t in_ports; 71 ngx_array_t in_ports;
72 ngx_listening_t *ls; 72 ngx_listening_t *ls;
73 ngx_mail_listen_t *imls; 73 ngx_mail_listen_t *mls;
74 ngx_mail_module_t *module; 74 ngx_mail_module_t *module;
75 ngx_mail_in_port_t *imip; 75 ngx_mail_in_port_t *mip;
76 ngx_mail_conf_ctx_t *ctx; 76 ngx_mail_conf_ctx_t *ctx;
77 ngx_mail_conf_in_port_t *in_port; 77 ngx_mail_conf_in_port_t *in_port;
78 ngx_mail_conf_in_addr_t *in_addr; 78 ngx_mail_conf_in_addr_t *in_addr;
79 ngx_mail_core_srv_conf_t **cscfp; 79 ngx_mail_core_srv_conf_t **cscfp;
80 ngx_mail_core_main_conf_t *cmcf; 80 ngx_mail_core_main_conf_t *cmcf;
221 != NGX_OK) 221 != NGX_OK)
222 { 222 {
223 return NGX_CONF_ERROR; 223 return NGX_CONF_ERROR;
224 } 224 }
225 225
226 imls = cmcf->listen.elts; 226 mls = cmcf->listen.elts;
227 227
228 for (l = 0; l < cmcf->listen.nelts; l++) { 228 for (l = 0; l < cmcf->listen.nelts; l++) {
229 229
230 /* AF_INET only */ 230 /* AF_INET only */
231 231
232 in_port = in_ports.elts; 232 in_port = in_ports.elts;
233 for (p = 0; p < in_ports.nelts; p++) { 233 for (p = 0; p < in_ports.nelts; p++) {
234 if (in_port[p].port == imls[l].port) { 234 if (in_port[p].port == mls[l].port) {
235 in_port = &in_port[p]; 235 in_port = &in_port[p];
236 goto found; 236 goto found;
237 } 237 }
238 } 238 }
239 239
240 in_port = ngx_array_push(&in_ports); 240 in_port = ngx_array_push(&in_ports);
241 if (in_port == NULL) { 241 if (in_port == NULL) {
242 return NGX_CONF_ERROR; 242 return NGX_CONF_ERROR;
243 } 243 }
244 244
245 in_port->port = imls[l].port; 245 in_port->port = mls[l].port;
246 246
247 if (ngx_array_init(&in_port->addrs, cf->temp_pool, 2, 247 if (ngx_array_init(&in_port->addrs, cf->temp_pool, 2,
248 sizeof(ngx_mail_conf_in_addr_t)) 248 sizeof(ngx_mail_conf_in_addr_t))
249 != NGX_OK) 249 != NGX_OK)
250 { 250 {
256 in_addr = ngx_array_push(&in_port->addrs); 256 in_addr = ngx_array_push(&in_port->addrs);
257 if (in_addr == NULL) { 257 if (in_addr == NULL) {
258 return NGX_CONF_ERROR; 258 return NGX_CONF_ERROR;
259 } 259 }
260 260
261 in_addr->addr = imls[l].addr; 261 in_addr->addr = mls[l].addr;
262 in_addr->ctx = imls[l].ctx; 262 in_addr->ctx = mls[l].ctx;
263 in_addr->bind = imls[l].bind; 263 in_addr->bind = mls[l].bind;
264 #if (NGX_MAIL_SSL) 264 #if (NGX_MAIL_SSL)
265 in_addr->ssl = imls[l].ssl; 265 in_addr->ssl = mls[l].ssl;
266 #endif 266 #endif
267 } 267 }
268 268
269 /* optimize the lists of ports and addresses */ 269 /* optimize the lists of ports and addresses */
270 270
316 /* TODO: error_log directive */ 316 /* TODO: error_log directive */
317 ls->logp = &cf->cycle->new_log; 317 ls->logp = &cf->cycle->new_log;
318 ls->log.data = &ls->addr_text; 318 ls->log.data = &ls->addr_text;
319 ls->log.handler = ngx_accept_log_error; 319 ls->log.handler = ngx_accept_log_error;
320 320
321 imip = ngx_palloc(cf->pool, sizeof(ngx_mail_in_port_t)); 321 mip = ngx_palloc(cf->pool, sizeof(ngx_mail_in_port_t));
322 if (imip == NULL) { 322 if (mip == NULL) {
323 return NGX_CONF_ERROR; 323 return NGX_CONF_ERROR;
324 } 324 }
325 325
326 ls->servers = imip; 326 ls->servers = mip;
327 327
328 in_addr = in_port[p].addrs.elts; 328 in_addr = in_port[p].addrs.elts;
329 329
330 if (in_addr[a].bind && in_addr[a].addr != INADDR_ANY) { 330 if (in_addr[a].bind && in_addr[a].addr != INADDR_ANY) {
331 imip->naddrs = 1; 331 mip->naddrs = 1;
332 done = 0; 332 done = 0;
333 333
334 } else if (in_port[p].addrs.nelts > 1 334 } else if (in_port[p].addrs.nelts > 1
335 && in_addr[last - 1].addr == INADDR_ANY) 335 && in_addr[last - 1].addr == INADDR_ANY)
336 { 336 {
337 imip->naddrs = last; 337 mip->naddrs = last;
338 done = 1; 338 done = 1;
339 339
340 } else { 340 } else {
341 imip->naddrs = 1; 341 mip->naddrs = 1;
342 done = 0; 342 done = 0;
343 } 343 }
344 344
345 #if 0 345 #if 0
346 ngx_log_error(NGX_LOG_ALERT, cf->log, 0, 346 ngx_log_error(NGX_LOG_ALERT, cf->log, 0,
347 "%ui: %V %d %ui %ui", 347 "%ui: %V %d %ui %ui",
348 a, &ls->addr_text, in_addr[a].bind, 348 a, &ls->addr_text, in_addr[a].bind,
349 imip->naddrs, last); 349 mip->naddrs, last);
350 #endif 350 #endif
351 351
352 imip->addrs = ngx_pcalloc(cf->pool, 352 mip->addrs = ngx_pcalloc(cf->pool,
353 imip->naddrs * sizeof(ngx_mail_in_addr_t)); 353 mip->naddrs * sizeof(ngx_mail_in_addr_t));
354 if (imip->addrs == NULL) { 354 if (mip->addrs == NULL) {
355 return NGX_CONF_ERROR; 355 return NGX_CONF_ERROR;
356 } 356 }
357 357
358 for (i = 0; i < imip->naddrs; i++) { 358 for (i = 0; i < mip->naddrs; i++) {
359 imip->addrs[i].addr = in_addr[i].addr; 359 mip->addrs[i].addr = in_addr[i].addr;
360 imip->addrs[i].ctx = in_addr[i].ctx; 360 mip->addrs[i].ctx = in_addr[i].ctx;
361 361
362 text = ngx_pnalloc(cf->pool, 362 text = ngx_pnalloc(cf->pool,
363 NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1); 363 NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1);
364 if (text == NULL) { 364 if (text == NULL) {
365 return NGX_CONF_ERROR; 365 return NGX_CONF_ERROR;
368 len = ngx_inet_ntop(AF_INET, &in_addr[i].addr, text, 368 len = ngx_inet_ntop(AF_INET, &in_addr[i].addr, text,
369 NGX_INET_ADDRSTRLEN); 369 NGX_INET_ADDRSTRLEN);
370 370
371 len = ngx_sprintf(text + len, ":%d", in_port[p].port) - text; 371 len = ngx_sprintf(text + len, ":%d", in_port[p].port) - text;
372 372
373 imip->addrs[i].addr_text.len = len; 373 mip->addrs[i].addr_text.len = len;
374 imip->addrs[i].addr_text.data = text; 374 mip->addrs[i].addr_text.data = text;
375 375
376 #if (NGX_MAIL_SSL) 376 #if (NGX_MAIL_SSL)
377 imip->addrs[i].ssl = in_addr[i].ssl; 377 mip->addrs[i].ssl = in_addr[i].ssl;
378 #endif 378 #endif
379 } 379 }
380 380
381 if (done) { 381 if (done) {
382 break; 382 break;