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