Mercurial > hg > nginx-quic
annotate src/imap/ngx_imap_core_module.c @ 1053:b9fa23cda4cc
ngx_file_access() and ngx_de_access()
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 18 Jan 2007 20:31:22 +0000 |
parents | a0310ac2814f |
children |
rev | line source |
---|---|
521 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_event.h> | |
10 #include <ngx_imap.h> | |
11 | |
12 | |
13 static void *ngx_imap_core_create_main_conf(ngx_conf_t *cf); | |
14 static void *ngx_imap_core_create_srv_conf(ngx_conf_t *cf); | |
15 static char *ngx_imap_core_merge_srv_conf(ngx_conf_t *cf, void *parent, | |
16 void *child); | |
17 static char *ngx_imap_core_server(ngx_conf_t *cf, ngx_command_t *cmd, | |
18 void *conf); | |
19 static char *ngx_imap_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, | |
20 void *conf); | |
527 | 21 static char *ngx_imap_core_capability(ngx_conf_t *cf, ngx_command_t *cmd, |
22 void *conf); | |
521 | 23 |
24 | |
25 static ngx_conf_enum_t ngx_imap_core_procotol[] = { | |
26 { ngx_string("pop3"), NGX_IMAP_POP3_PROTOCOL }, | |
27 { ngx_string("imap"), NGX_IMAP_IMAP_PROTOCOL }, | |
28 { ngx_null_string, 0 } | |
29 }; | |
30 | |
31 | |
527 | 32 static ngx_str_t ngx_pop3_default_capabilities[] = { |
33 ngx_string("TOP"), | |
34 ngx_string("USER"), | |
35 ngx_string("UIDL"), | |
36 ngx_null_string | |
37 }; | |
38 | |
39 | |
40 static ngx_str_t ngx_imap_default_capabilities[] = { | |
41 ngx_string("IMAP4"), | |
42 ngx_string("IMAP4rev1"), | |
43 ngx_string("UIDPLUS"), | |
44 ngx_null_string | |
45 }; | |
46 | |
47 | |
800 | 48 static ngx_conf_bitmask_t ngx_imap_auth_methods[] = { |
49 { ngx_string("plain"), NGX_IMAP_AUTH_PLAIN_ENABLED }, | |
50 { ngx_string("apop"), NGX_IMAP_AUTH_APOP_ENABLED }, | |
809 | 51 { ngx_string("cram-md5"), NGX_IMAP_AUTH_CRAM_MD5_ENABLED }, |
800 | 52 { ngx_null_string, 0 } |
53 }; | |
54 | |
55 | |
809 | 56 static ngx_str_t ngx_pop3_auth_plain_capability = |
57 ngx_string("+OK methods supported:" CRLF | |
58 "LOGIN" CRLF | |
59 "PLAIN" CRLF | |
60 "." CRLF); | |
61 | |
62 | |
63 static ngx_str_t ngx_pop3_auth_cram_md5_capability = | |
64 ngx_string("+OK methods supported:" CRLF | |
65 "LOGIN" CRLF | |
66 "PLAIN" CRLF | |
67 "CRAM-MD5" CRLF | |
68 "." CRLF); | |
69 | |
70 | |
71 | |
521 | 72 static ngx_command_t ngx_imap_core_commands[] = { |
73 | |
74 { ngx_string("server"), | |
75 NGX_IMAP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, | |
76 ngx_imap_core_server, | |
77 0, | |
78 0, | |
79 NULL }, | |
80 | |
81 { ngx_string("listen"), | |
641 | 82 NGX_IMAP_SRV_CONF|NGX_CONF_TAKE12, |
521 | 83 ngx_imap_core_listen, |
84 0, | |
85 0, | |
86 NULL }, | |
87 | |
88 { ngx_string("protocol"), | |
89 NGX_IMAP_SRV_CONF|NGX_CONF_TAKE1, | |
90 ngx_conf_set_enum_slot, | |
91 NGX_IMAP_SRV_CONF_OFFSET, | |
92 offsetof(ngx_imap_core_srv_conf_t, protocol), | |
93 &ngx_imap_core_procotol }, | |
94 | |
95 { ngx_string("imap_client_buffer"), | |
96 NGX_IMAP_MAIN_CONF|NGX_IMAP_SRV_CONF|NGX_CONF_TAKE1, | |
97 ngx_conf_set_size_slot, | |
98 NGX_IMAP_SRV_CONF_OFFSET, | |
99 offsetof(ngx_imap_core_srv_conf_t, imap_client_buffer_size), | |
100 NULL }, | |
101 | |
587 | 102 { ngx_string("so_keepalive"), |
103 NGX_IMAP_MAIN_CONF|NGX_IMAP_SRV_CONF|NGX_CONF_FLAG, | |
104 ngx_conf_set_flag_slot, | |
105 NGX_IMAP_SRV_CONF_OFFSET, | |
106 offsetof(ngx_imap_core_srv_conf_t, so_keepalive), | |
107 NULL }, | |
108 | |
521 | 109 { ngx_string("timeout"), |
110 NGX_IMAP_MAIN_CONF|NGX_IMAP_SRV_CONF|NGX_CONF_TAKE1, | |
111 ngx_conf_set_msec_slot, | |
112 NGX_IMAP_SRV_CONF_OFFSET, | |
113 offsetof(ngx_imap_core_srv_conf_t, timeout), | |
114 NULL }, | |
115 | |
527 | 116 { ngx_string("pop3_capabilities"), |
117 NGX_IMAP_MAIN_CONF|NGX_IMAP_SRV_CONF|NGX_CONF_1MORE, | |
118 ngx_imap_core_capability, | |
119 NGX_IMAP_SRV_CONF_OFFSET, | |
120 offsetof(ngx_imap_core_srv_conf_t, pop3_capabilities), | |
121 NULL }, | |
122 | |
123 { ngx_string("imap_capabilities"), | |
124 NGX_IMAP_MAIN_CONF|NGX_IMAP_SRV_CONF|NGX_CONF_1MORE, | |
125 ngx_imap_core_capability, | |
126 NGX_IMAP_SRV_CONF_OFFSET, | |
127 offsetof(ngx_imap_core_srv_conf_t, imap_capabilities), | |
128 NULL }, | |
129 | |
800 | 130 { ngx_string("server_name"), |
131 NGX_IMAP_MAIN_CONF|NGX_IMAP_SRV_CONF|NGX_CONF_TAKE1, | |
132 ngx_conf_set_str_slot, | |
133 NGX_IMAP_SRV_CONF_OFFSET, | |
134 offsetof(ngx_imap_core_srv_conf_t, server_name), | |
135 NULL }, | |
136 | |
137 { ngx_string("auth"), | |
138 NGX_IMAP_MAIN_CONF|NGX_IMAP_SRV_CONF|NGX_CONF_1MORE, | |
139 ngx_conf_set_bitmask_slot, | |
140 NGX_IMAP_SRV_CONF_OFFSET, | |
141 offsetof(ngx_imap_core_srv_conf_t, auth_methods), | |
142 &ngx_imap_auth_methods }, | |
143 | |
521 | 144 ngx_null_command |
145 }; | |
146 | |
147 | |
148 static ngx_imap_module_t ngx_imap_core_module_ctx = { | |
149 ngx_imap_core_create_main_conf, /* create main configuration */ | |
150 NULL, /* init main configuration */ | |
151 | |
152 ngx_imap_core_create_srv_conf, /* create server configuration */ | |
153 ngx_imap_core_merge_srv_conf /* merge server configuration */ | |
154 }; | |
155 | |
156 | |
157 ngx_module_t ngx_imap_core_module = { | |
158 NGX_MODULE_V1, | |
159 &ngx_imap_core_module_ctx, /* module context */ | |
160 ngx_imap_core_commands, /* module directives */ | |
161 NGX_IMAP_MODULE, /* module type */ | |
541 | 162 NULL, /* init master */ |
521 | 163 NULL, /* init module */ |
541 | 164 NULL, /* init process */ |
165 NULL, /* init thread */ | |
166 NULL, /* exit thread */ | |
167 NULL, /* exit process */ | |
168 NULL, /* exit master */ | |
169 NGX_MODULE_V1_PADDING | |
521 | 170 }; |
171 | |
172 | |
173 static void * | |
174 ngx_imap_core_create_main_conf(ngx_conf_t *cf) | |
577 | 175 { |
521 | 176 ngx_imap_core_main_conf_t *cmcf; |
177 | |
178 cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_imap_core_main_conf_t)); | |
179 if (cmcf == NULL) { | |
180 return NGX_CONF_ERROR; | |
181 } | |
182 | |
183 if (ngx_array_init(&cmcf->servers, cf->pool, 4, | |
641 | 184 sizeof(ngx_imap_core_srv_conf_t *)) |
185 != NGX_OK) | |
186 { | |
187 return NGX_CONF_ERROR; | |
188 } | |
189 | |
190 if (ngx_array_init(&cmcf->listen, cf->pool, 4, sizeof(ngx_imap_listen_t)) | |
191 != NGX_OK) | |
521 | 192 { |
193 return NGX_CONF_ERROR; | |
194 } | |
195 | |
196 return cmcf; | |
197 } | |
198 | |
199 | |
200 static void * | |
201 ngx_imap_core_create_srv_conf(ngx_conf_t *cf) | |
577 | 202 { |
521 | 203 ngx_imap_core_srv_conf_t *cscf; |
577 | 204 |
521 | 205 cscf = ngx_pcalloc(cf->pool, sizeof(ngx_imap_core_srv_conf_t)); |
206 if (cscf == NULL) { | |
527 | 207 return NULL; |
521 | 208 } |
209 | |
210 cscf->imap_client_buffer_size = NGX_CONF_UNSET_SIZE; | |
587 | 211 cscf->protocol = NGX_CONF_UNSET_UINT; |
521 | 212 cscf->timeout = NGX_CONF_UNSET_MSEC; |
587 | 213 cscf->so_keepalive = NGX_CONF_UNSET; |
521 | 214 |
527 | 215 if (ngx_array_init(&cscf->pop3_capabilities, cf->pool, 4, sizeof(ngx_str_t)) |
216 != NGX_OK) | |
217 { | |
218 return NULL; | |
219 } | |
220 | |
221 if (ngx_array_init(&cscf->imap_capabilities, cf->pool, 4, sizeof(ngx_str_t)) | |
222 != NGX_OK) | |
223 { | |
224 return NULL; | |
225 } | |
226 | |
521 | 227 return cscf; |
228 } | |
229 | |
230 | |
231 static char * | |
232 ngx_imap_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) | |
233 { | |
234 ngx_imap_core_srv_conf_t *prev = parent; | |
235 ngx_imap_core_srv_conf_t *conf = child; | |
236 | |
583 | 237 u_char *p; |
527 | 238 size_t size; |
239 ngx_str_t *c, *d; | |
240 ngx_uint_t i; | |
241 | |
521 | 242 ngx_conf_merge_size_value(conf->imap_client_buffer_size, |
243 prev->imap_client_buffer_size, | |
244 (size_t) ngx_pagesize); | |
245 ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000); | |
663 | 246 ngx_conf_merge_uint_value(conf->protocol, prev->protocol, |
521 | 247 NGX_IMAP_IMAP_PROTOCOL); |
587 | 248 ngx_conf_merge_value(conf->so_keepalive, prev->so_keepalive, 0); |
521 | 249 |
527 | 250 |
800 | 251 ngx_conf_merge_bitmask_value(conf->auth_methods, prev->auth_methods, |
252 (NGX_CONF_BITMASK_SET|NGX_IMAP_AUTH_PLAIN_ENABLED)); | |
253 | |
254 | |
255 ngx_conf_merge_str_value(conf->server_name, prev->server_name, ""); | |
256 | |
257 if (conf->server_name.len == 0) { | |
258 conf->server_name.data = ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN); | |
259 if (conf->server_name.data == NULL) { | |
260 return NGX_CONF_ERROR; | |
261 } | |
262 | |
263 if (gethostname((char *) conf->server_name.data, NGX_MAXHOSTNAMELEN) | |
264 == -1) | |
265 { | |
266 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, | |
267 "gethostname() failed"); | |
268 return NGX_CONF_ERROR; | |
269 } | |
270 | |
271 conf->server_name.len = ngx_strlen(conf->server_name.data); | |
272 } | |
273 | |
274 | |
527 | 275 if (conf->pop3_capabilities.nelts == 0) { |
276 conf->pop3_capabilities = prev->pop3_capabilities; | |
277 } | |
278 | |
279 if (conf->pop3_capabilities.nelts == 0) { | |
280 | |
281 for (d = ngx_pop3_default_capabilities; d->len; d++) { | |
282 c = ngx_array_push(&conf->pop3_capabilities); | |
283 if (c == NULL) { | |
284 return NGX_CONF_ERROR; | |
285 } | |
286 | |
287 *c = *d; | |
288 } | |
289 } | |
290 | |
291 size = sizeof("+OK Capability list follows" CRLF) - 1 | |
292 + sizeof("." CRLF) - 1; | |
293 | |
294 c = conf->pop3_capabilities.elts; | |
295 for (i = 0; i < conf->pop3_capabilities.nelts; i++) { | |
296 size += c[i].len + sizeof(CRLF) - 1; | |
297 } | |
298 | |
809 | 299 if (conf->auth_methods & NGX_IMAP_AUTH_CRAM_MD5_ENABLED) { |
300 size += sizeof("SASL LOGIN PLAIN CRAM-MD5" CRLF) - 1; | |
301 | |
302 } else { | |
303 size += sizeof("SASL LOGIN PLAIN" CRLF) - 1; | |
304 } | |
305 | |
583 | 306 p = ngx_palloc(cf->pool, size); |
307 if (p == NULL) { | |
527 | 308 return NGX_CONF_ERROR; |
309 } | |
310 | |
583 | 311 conf->pop3_capability.len = size; |
312 conf->pop3_capability.data = p; | |
313 | |
314 p = ngx_cpymem(p, "+OK Capability list follows" CRLF, | |
315 sizeof("+OK Capability list follows" CRLF) - 1); | |
527 | 316 |
317 for (i = 0; i < conf->pop3_capabilities.nelts; i++) { | |
583 | 318 p = ngx_cpymem(p, c[i].data, c[i].len); |
319 *p++ = CR; *p++ = LF; | |
527 | 320 } |
321 | |
809 | 322 if (conf->auth_methods & NGX_IMAP_AUTH_CRAM_MD5_ENABLED) { |
323 p = ngx_cpymem(p, "SASL LOGIN PLAIN CRAM-MD5" CRLF, | |
324 sizeof("SASL LOGIN PLAIN CRAM-MD5" CRLF) - 1); | |
325 | |
326 } else { | |
327 p = ngx_cpymem(p, "SASL LOGIN PLAIN" CRLF, | |
328 sizeof("SASL LOGIN PLAIN" CRLF) - 1); | |
329 } | |
330 | |
583 | 331 *p++ = '.'; *p++ = CR; *p = LF; |
332 | |
333 | |
334 size += sizeof("STLS" CRLF) - 1; | |
527 | 335 |
583 | 336 p = ngx_palloc(cf->pool, size); |
337 if (p == NULL) { | |
338 return NGX_CONF_ERROR; | |
339 } | |
340 | |
341 conf->pop3_starttls_capability.len = size; | |
342 conf->pop3_starttls_capability.data = p; | |
343 | |
344 p = ngx_cpymem(p, conf->pop3_capability.data, | |
345 conf->pop3_capability.len - (sizeof("." CRLF) - 1)); | |
346 | |
347 p = ngx_cpymem(p, "STLS" CRLF, sizeof("STLS" CRLF) - 1); | |
348 *p++ = '.'; *p++ = CR; *p = LF; | |
527 | 349 |
350 | |
809 | 351 if (conf->auth_methods & NGX_IMAP_AUTH_CRAM_MD5_ENABLED) { |
352 conf->pop3_auth_capability = ngx_pop3_auth_cram_md5_capability; | |
353 | |
354 } else { | |
355 conf->pop3_auth_capability = ngx_pop3_auth_plain_capability; | |
356 } | |
357 | |
358 | |
527 | 359 if (conf->imap_capabilities.nelts == 0) { |
360 conf->imap_capabilities = prev->imap_capabilities; | |
361 } | |
362 | |
363 if (conf->imap_capabilities.nelts == 0) { | |
364 | |
365 for (d = ngx_imap_default_capabilities; d->len; d++) { | |
366 c = ngx_array_push(&conf->imap_capabilities); | |
367 if (c == NULL) { | |
368 return NGX_CONF_ERROR; | |
369 } | |
370 | |
371 *c = *d; | |
372 } | |
373 } | |
374 | |
375 size = sizeof("* CAPABILITY") - 1 + sizeof(CRLF) - 1; | |
376 | |
377 c = conf->imap_capabilities.elts; | |
378 for (i = 0; i < conf->imap_capabilities.nelts; i++) { | |
379 size += 1 + c[i].len; | |
380 } | |
381 | |
583 | 382 p = ngx_palloc(cf->pool, size); |
383 if (p == NULL) { | |
384 return NGX_CONF_ERROR; | |
385 } | |
386 | |
387 conf->imap_capability.len = size; | |
388 conf->imap_capability.data = p; | |
389 | |
390 p = ngx_cpymem(p, "* CAPABILITY", sizeof("* CAPABILITY") - 1); | |
391 | |
392 for (i = 0; i < conf->imap_capabilities.nelts; i++) { | |
393 *p++ = ' '; | |
394 p = ngx_cpymem(p, c[i].data, c[i].len); | |
395 } | |
396 | |
397 *p++ = CR; *p = LF; | |
398 | |
399 | |
400 size += sizeof(" STARTTLS") - 1; | |
401 | |
402 p = ngx_palloc(cf->pool, size); | |
403 if (p == NULL) { | |
527 | 404 return NGX_CONF_ERROR; |
405 } | |
406 | |
583 | 407 conf->imap_starttls_capability.len = size; |
408 conf->imap_starttls_capability.data = p; | |
527 | 409 |
583 | 410 p = ngx_cpymem(p, conf->imap_capability.data, |
411 conf->imap_capability.len - (sizeof(CRLF) - 1)); | |
412 p = ngx_cpymem(p, " STARTTLS", sizeof(" STARTTLS") - 1); | |
413 *p++ = CR; *p = LF; | |
414 | |
415 | |
416 size += sizeof(" LOGINDISABLED") - 1; | |
417 | |
418 p = ngx_palloc(cf->pool, size); | |
419 if (p == NULL) { | |
420 return NGX_CONF_ERROR; | |
527 | 421 } |
422 | |
583 | 423 conf->imap_starttls_only_capability.len = size; |
424 conf->imap_starttls_only_capability.data = p; | |
527 | 425 |
583 | 426 p = ngx_cpymem(p, conf->imap_starttls_capability.data, |
427 conf->imap_starttls_capability.len - (sizeof(CRLF) - 1)); | |
428 p = ngx_cpymem(p, " LOGINDISABLED", sizeof(" LOGINDISABLED") - 1); | |
429 *p++ = CR; *p = LF; | |
430 | |
527 | 431 |
521 | 432 return NGX_CONF_OK; |
433 } | |
434 | |
435 | |
436 static char * | |
437 ngx_imap_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
438 { | |
439 char *rv; | |
440 void *mconf; | |
441 ngx_uint_t m; | |
442 ngx_conf_t pcf; | |
443 ngx_imap_module_t *module; | |
444 ngx_imap_conf_ctx_t *ctx, *imap_ctx; | |
445 ngx_imap_core_srv_conf_t *cscf, **cscfp; | |
446 ngx_imap_core_main_conf_t *cmcf; | |
447 | |
448 | |
449 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_imap_conf_ctx_t)); | |
450 if (ctx == NULL) { | |
451 return NGX_CONF_ERROR; | |
452 } | |
453 | |
454 imap_ctx = cf->ctx; | |
455 ctx->main_conf = imap_ctx->main_conf; | |
577 | 456 |
521 | 457 /* the server{}'s srv_conf */ |
458 | |
459 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_imap_max_module); | |
460 if (ctx->srv_conf == NULL) { | |
461 return NGX_CONF_ERROR; | |
462 } | |
463 | |
464 for (m = 0; ngx_modules[m]; m++) { | |
465 if (ngx_modules[m]->type != NGX_IMAP_MODULE) { | |
466 continue; | |
467 } | |
468 | |
469 module = ngx_modules[m]->ctx; | |
470 | |
471 if (module->create_srv_conf) { | |
472 mconf = module->create_srv_conf(cf); | |
473 if (mconf == NULL) { | |
474 return NGX_CONF_ERROR; | |
475 } | |
476 | |
477 ctx->srv_conf[ngx_modules[m]->ctx_index] = mconf; | |
478 } | |
479 } | |
480 | |
481 /* the server configuration context */ | |
482 | |
483 cscf = ctx->srv_conf[ngx_imap_core_module.ctx_index]; | |
484 cscf->ctx = ctx; | |
485 | |
486 cmcf = ctx->main_conf[ngx_imap_core_module.ctx_index]; | |
487 | |
488 cscfp = ngx_array_push(&cmcf->servers); | |
489 if (cscfp == NULL) { | |
490 return NGX_CONF_ERROR; | |
491 } | |
492 | |
493 *cscfp = cscf; | |
494 | |
495 | |
496 /* parse inside server{} */ | |
497 | |
498 pcf = *cf; | |
499 cf->ctx = ctx; | |
500 cf->cmd_type = NGX_IMAP_SRV_CONF; | |
501 | |
502 rv = ngx_conf_parse(cf, NULL); | |
503 | |
504 *cf = pcf; | |
505 | |
506 return rv; | |
507 } | |
508 | |
509 | |
510 /* AF_INET only */ | |
511 | |
512 static char * | |
513 ngx_imap_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
514 { | |
641 | 515 ngx_str_t *value; |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
516 ngx_url_t u; |
641 | 517 ngx_uint_t i; |
518 ngx_imap_listen_t *imls; | |
519 ngx_imap_core_main_conf_t *cmcf; | |
521 | 520 |
521 value = cf->args->elts; | |
522 | |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
523 ngx_memzero(&u, sizeof(ngx_url_t)); |
521 | 524 |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
525 u.url = value[1]; |
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
526 u.listen = 1; |
619 | 527 |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
528 if (ngx_parse_url(cf, &u) != NGX_OK) { |
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
529 if (u.err) { |
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
530 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
531 "%s in \"%V\" of the \"listen\" directive", |
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
532 u.err, &u.url); |
521 | 533 } |
534 | |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
535 return NGX_CONF_ERROR; |
521 | 536 } |
537 | |
641 | 538 cmcf = ngx_imap_conf_get_module_main_conf(cf, ngx_imap_core_module); |
521 | 539 |
641 | 540 imls = cmcf->listen.elts; |
541 | |
542 for (i = 0; i < cmcf->listen.nelts; i++) { | |
543 | |
906 | 544 if (imls[i].addr != u.addr.in_addr || imls[i].port != u.port) { |
641 | 545 continue; |
546 } | |
547 | |
548 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
549 "duplicate \"%V\" address and port pair", &u.url); |
577 | 550 return NGX_CONF_ERROR; |
521 | 551 } |
552 | |
641 | 553 imls = ngx_array_push(&cmcf->listen); |
554 if (imls == NULL) { | |
555 return NGX_CONF_ERROR; | |
556 } | |
563 | 557 |
641 | 558 ngx_memzero(imls, sizeof(ngx_imap_listen_t)); |
559 | |
804
472cd9768ac2
now the "listen" directives use ngx_parse_url()
Igor Sysoev <igor@sysoev.ru>
parents:
800
diff
changeset
|
560 imls->addr = u.addr.in_addr; |
906 | 561 imls->port = u.port; |
641 | 562 imls->family = AF_INET; |
563 imls->ctx = cf->ctx; | |
521 | 564 |
641 | 565 if (cf->args->nelts == 2) { |
566 return NGX_CONF_OK; | |
567 } | |
521 | 568 |
641 | 569 if (ngx_strcmp(value[2].data, "bind") == 0) { |
570 imls->bind = 1; | |
571 return NGX_CONF_OK; | |
572 } | |
521 | 573 |
641 | 574 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
575 "the invalid \"%V\" parameter", &value[2]); | |
576 return NGX_CONF_ERROR; | |
521 | 577 } |
527 | 578 |
579 | |
580 static char * | |
581 ngx_imap_core_capability(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
582 { | |
583 char *p = conf; | |
584 | |
585 ngx_str_t *c, *value; | |
586 ngx_uint_t i; | |
587 ngx_array_t *a; | |
588 | |
589 a = (ngx_array_t *) (p + cmd->offset); | |
590 | |
591 value = cf->args->elts; | |
592 | |
593 for (i = 1; i < cf->args->nelts; i++) { | |
594 c = ngx_array_push(a); | |
595 if (c == NULL) { | |
596 return NGX_CONF_ERROR; | |
597 } | |
598 | |
599 *c = value[i]; | |
600 } | |
601 | |
602 return NGX_CONF_OK; | |
603 } |