Mercurial > hg > nginx-quic
annotate src/imap/ngx_imap.c @ 588:0a2c30f516e6
release-0.3.15 tag
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 07 Dec 2005 14:51:31 +0000 |
parents | 4d9ea73a627a |
children | 5e8fb59c18c1 |
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> |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
10 #include <ngx_imap.h> |
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 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
13 static char *ngx_imap_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
14 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
15 |
521 | 16 ngx_uint_t ngx_imap_max_module; |
17 | |
18 | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
19 static ngx_command_t ngx_imap_commands[] = { |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
20 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
21 { ngx_string("imap"), |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
22 NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
23 ngx_imap_block, |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
24 0, |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
25 0, |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
26 NULL }, |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
27 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 ngx_null_command |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 }; |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
30 |
577 | 31 |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
32 static ngx_core_module_t ngx_imap_module_ctx = { |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
33 ngx_string("imap"), |
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 NULL |
577 | 36 }; |
413
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 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 ngx_module_t ngx_imap_module = { |
509 | 40 NGX_MODULE_V1, |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 &ngx_imap_module_ctx, /* module context */ |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
42 ngx_imap_commands, /* module directives */ |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
43 NGX_CORE_MODULE, /* module type */ |
541 | 44 NULL, /* init master */ |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
45 NULL, /* init module */ |
541 | 46 NULL, /* init process */ |
47 NULL, /* init thread */ | |
48 NULL, /* exit thread */ | |
49 NULL, /* exit process */ | |
50 NULL, /* exit master */ | |
51 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
|
52 }; |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
53 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
54 |
521 | 55 static char * |
56 ngx_imap_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
|
57 { |
521 | 58 char *rv; |
59 ngx_uint_t m, mi, s; | |
60 ngx_conf_t pcf; | |
61 ngx_imap_module_t *module; | |
62 ngx_imap_conf_ctx_t *ctx; | |
63 ngx_imap_core_srv_conf_t **cscfp; | |
64 ngx_imap_core_main_conf_t *cmcf; | |
65 | |
66 /* the main imap context */ | |
67 | |
68 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_imap_conf_ctx_t)); | |
69 if (ctx == NULL) { | |
70 return NGX_CONF_ERROR; | |
71 } | |
72 | |
73 *(ngx_imap_conf_ctx_t **) conf = ctx; | |
74 | |
75 /* 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
|
76 |
521 | 77 ngx_imap_max_module = 0; |
78 for (m = 0; ngx_modules[m]; m++) { | |
79 if (ngx_modules[m]->type != NGX_IMAP_MODULE) { | |
80 continue; | |
81 } | |
82 | |
83 ngx_modules[m]->ctx_index = ngx_imap_max_module++; | |
84 } | |
85 | |
86 | |
87 /* the imap main_conf context, it is the same in the all imap contexts */ | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
88 |
521 | 89 ctx->main_conf = ngx_pcalloc(cf->pool, |
90 sizeof(void *) * ngx_imap_max_module); | |
91 if (ctx->main_conf == NULL) { | |
92 return NGX_CONF_ERROR; | |
93 } | |
94 | |
95 | |
96 /* | |
97 * the imap null srv_conf context, it is used to merge | |
98 * the server{}s' srv_conf's | |
99 */ | |
100 | |
101 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_imap_max_module); | |
102 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
|
103 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
|
104 } |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
105 |
521 | 106 |
107 /* | |
108 * create the main_conf's, the null srv_conf's, and the null loc_conf's | |
109 * of the all imap modules | |
110 */ | |
111 | |
112 for (m = 0; ngx_modules[m]; m++) { | |
113 if (ngx_modules[m]->type != NGX_IMAP_MODULE) { | |
114 continue; | |
115 } | |
116 | |
117 module = ngx_modules[m]->ctx; | |
118 mi = ngx_modules[m]->ctx_index; | |
119 | |
120 if (module->create_main_conf) { | |
121 ctx->main_conf[mi] = module->create_main_conf(cf); | |
122 if (ctx->main_conf[mi] == NULL) { | |
123 return NGX_CONF_ERROR; | |
124 } | |
125 } | |
126 | |
127 if (module->create_srv_conf) { | |
128 ctx->srv_conf[mi] = module->create_srv_conf(cf); | |
129 if (ctx->srv_conf[mi] == NULL) { | |
130 return NGX_CONF_ERROR; | |
131 } | |
132 } | |
133 } | |
134 | |
135 | |
136 /* parse inside the imap{} block */ | |
137 | |
138 pcf = *cf; | |
139 cf->ctx = ctx; | |
140 | |
141 cf->module_type = NGX_IMAP_MODULE; | |
142 cf->cmd_type = NGX_IMAP_MAIN_CONF; | |
143 rv = ngx_conf_parse(cf, NULL); | |
144 | |
145 if (rv != NGX_CONF_OK) { | |
146 *cf = pcf; | |
147 return rv; | |
148 } | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
149 |
521 | 150 |
151 /* init imap{} main_conf's, merge the server{}s' srv_conf's */ | |
152 | |
153 cmcf = ctx->main_conf[ngx_imap_core_module.ctx_index]; | |
154 cscfp = cmcf->servers.elts; | |
155 | |
156 for (m = 0; ngx_modules[m]; m++) { | |
157 if (ngx_modules[m]->type != NGX_IMAP_MODULE) { | |
158 continue; | |
159 } | |
160 | |
161 module = ngx_modules[m]->ctx; | |
162 mi = ngx_modules[m]->ctx_index; | |
163 | |
164 /* init imap{} main_conf's */ | |
165 | |
166 if (module->init_main_conf) { | |
577 | 167 rv = module->init_main_conf(cf, ctx->main_conf[mi]); |
521 | 168 if (rv != NGX_CONF_OK) { |
169 *cf = pcf; | |
170 return rv; | |
171 } | |
172 } | |
173 | |
174 for (s = 0; s < cmcf->servers.nelts; s++) { | |
577 | 175 |
521 | 176 /* merge the server{}s' srv_conf's */ |
577 | 177 |
521 | 178 if (module->merge_srv_conf) { |
179 rv = module->merge_srv_conf(cf, | |
180 ctx->srv_conf[mi], | |
181 cscfp[s]->ctx->srv_conf[mi]); | |
182 if (rv != NGX_CONF_OK) { | |
183 *cf = pcf; | |
184 return rv; | |
185 } | |
186 } | |
187 } | |
188 } | |
189 | |
577 | 190 /* imap{}'s cf->ctx was needed while the configuration merging */ |
191 | |
192 *cf = pcf; | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
193 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
194 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
|
195 } |