comparison src/imap/ngx_imap.c @ 521:6f00349b98e5 release-0.1.35

nginx-0.1.35-RELEASE import *) Feature: the "working_directory" directive. *) Feature: the "port_in_redirect" directive. *) Bugfix: the segmentation fault was occurred if the backend response header was in several packets; the bug had appeared in 0.1.29. *) Bugfix: if more than 10 servers were configured or some server did not use the "listen" directive, then the segmentation fault was occurred on the start. *) Bugfix: the segmentation fault might occur if the response was bigger than the temporary file. *) Bugfix: nginx returned the 400 response on requests like "GET http://www.domain.com/uri HTTP/1.0"; the bug had appeared in 0.1.28.
author Igor Sysoev <igor@sysoev.ru>
date Tue, 07 Jun 2005 15:56:31 +0000
parents 9b8c906f6e63
children b09ee85d0ac8
comparison
equal deleted inserted replaced
520:1fecc7e0d717 521:6f00349b98e5
9 #include <ngx_event.h> 9 #include <ngx_event.h>
10 #include <ngx_imap.h> 10 #include <ngx_imap.h>
11 11
12 12
13 static char *ngx_imap_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 13 static char *ngx_imap_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
14
15
16 ngx_uint_t ngx_imap_max_module;
14 17
15 18
16 static ngx_command_t ngx_imap_commands[] = { 19 static ngx_command_t ngx_imap_commands[] = {
17 20
18 { ngx_string("imap"), 21 { ngx_string("imap"),
41 NULL, /* init module */ 44 NULL, /* init module */
42 NULL /* init process */ 45 NULL /* init process */
43 }; 46 };
44 47
45 48
46 static char *ngx_imap_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 49 static char *
50 ngx_imap_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
47 { 51 {
48 ngx_listening_t *ls; 52 char *rv;
53 ngx_uint_t m, mi, s;
54 ngx_conf_t pcf;
55 ngx_imap_module_t *module;
56 ngx_imap_conf_ctx_t *ctx;
57 ngx_imap_core_srv_conf_t **cscfp;
58 ngx_imap_core_main_conf_t *cmcf;
49 59
50 /* STUB */ 60 /* the main imap context */
51 61
52 ls = ngx_listening_inet_stream_socket(cf, 0, 8110); 62 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_imap_conf_ctx_t));
53 if (ls == NULL) { 63 if (ctx == NULL) {
54 return NGX_CONF_ERROR; 64 return NGX_CONF_ERROR;
55 } 65 }
56 66
57 ls->backlog = -1; 67 *(ngx_imap_conf_ctx_t **) conf = ctx;
58 ls->addr_ntop = 1;
59 ls->handler = ngx_imap_init_connection;
60 ls->pool_size = 16384;
61 /* ls->post_accept_timeout = 0; */
62 ls->log = cf->cycle->new_log;
63 68
64 /* */ 69 /* count the number of the http modules and set up their indices */
70
71 ngx_imap_max_module = 0;
72 for (m = 0; ngx_modules[m]; m++) {
73 if (ngx_modules[m]->type != NGX_IMAP_MODULE) {
74 continue;
75 }
76
77 ngx_modules[m]->ctx_index = ngx_imap_max_module++;
78 }
79
80
81 /* the imap main_conf context, it is the same in the all imap contexts */
82
83 ctx->main_conf = ngx_pcalloc(cf->pool,
84 sizeof(void *) * ngx_imap_max_module);
85 if (ctx->main_conf == NULL) {
86 return NGX_CONF_ERROR;
87 }
88
89
90 /*
91 * the imap null srv_conf context, it is used to merge
92 * the server{}s' srv_conf's
93 */
94
95 ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_imap_max_module);
96 if (ctx->srv_conf == NULL) {
97 return NGX_CONF_ERROR;
98 }
99
100
101 /*
102 * create the main_conf's, the null srv_conf's, and the null loc_conf's
103 * of the all imap modules
104 */
105
106 for (m = 0; ngx_modules[m]; m++) {
107 if (ngx_modules[m]->type != NGX_IMAP_MODULE) {
108 continue;
109 }
110
111 module = ngx_modules[m]->ctx;
112 mi = ngx_modules[m]->ctx_index;
113
114 if (module->create_main_conf) {
115 ctx->main_conf[mi] = module->create_main_conf(cf);
116 if (ctx->main_conf[mi] == NULL) {
117 return NGX_CONF_ERROR;
118 }
119 }
120
121 if (module->create_srv_conf) {
122 ctx->srv_conf[mi] = module->create_srv_conf(cf);
123 if (ctx->srv_conf[mi] == NULL) {
124 return NGX_CONF_ERROR;
125 }
126 }
127 }
128
129
130 /* parse inside the imap{} block */
131
132 pcf = *cf;
133 cf->ctx = ctx;
134
135 cf->module_type = NGX_IMAP_MODULE;
136 cf->cmd_type = NGX_IMAP_MAIN_CONF;
137 rv = ngx_conf_parse(cf, NULL);
138
139 if (rv != NGX_CONF_OK) {
140 *cf = pcf;
141 return rv;
142 }
143
144
145 /* init imap{} main_conf's, merge the server{}s' srv_conf's */
146
147 cmcf = ctx->main_conf[ngx_imap_core_module.ctx_index];
148 cscfp = cmcf->servers.elts;
149
150 for (m = 0; ngx_modules[m]; m++) {
151 if (ngx_modules[m]->type != NGX_IMAP_MODULE) {
152 continue;
153 }
154
155 module = ngx_modules[m]->ctx;
156 mi = ngx_modules[m]->ctx_index;
157
158 /* init imap{} main_conf's */
159
160 if (module->init_main_conf) {
161 rv = module->init_main_conf(cf, ctx->main_conf[mi]);
162 if (rv != NGX_CONF_OK) {
163 *cf = pcf;
164 return rv;
165 }
166 }
167
168 for (s = 0; s < cmcf->servers.nelts; s++) {
169
170 /* merge the server{}s' srv_conf's */
171
172 if (module->merge_srv_conf) {
173 rv = module->merge_srv_conf(cf,
174 ctx->srv_conf[mi],
175 cscfp[s]->ctx->srv_conf[mi]);
176 if (rv != NGX_CONF_OK) {
177 *cf = pcf;
178 return rv;
179 }
180 }
181 }
182 }
183
184 /* imap{}'s cf->ctx was needed while the configuration merging */
185
186 *cf = pcf;
65 187
66 return NGX_CONF_OK; 188 return NGX_CONF_OK;
67 } 189 }