Mercurial > hg > nginx-quic
annotate src/imap/ngx_imap_handler.c @ 577:4d9ea73a627a release-0.3.10
nginx-0.3.10-RELEASE import
*) Change: the "valid_referers" directive and the "$invalid_referer"
variable were moved to the new ngx_http_referer_module from the
ngx_http_rewrite_module.
*) Change: the "$apache_bytes_sent" variable name was changed to
"$body_bytes_sent".
*) Feature: the "$sent_http_..." variables.
*) Feature: the "if" directive supports the "=" and "!=" operations.
*) Feature: the "proxy_pass" directive supports the HTTPS protocol.
*) Feature: the "proxy_set_body" directive.
*) Feature: the "post_action" directive.
*) Feature: the ngx_http_empty_gif_module.
*) Feature: the "worker_cpu_affinity" directive for Linux.
*) Bugfix: the "rewrite" directive did not unescape URI part in
redirect, now it is unescaped except the %00-%25 and %7F-%FF
characters.
*) Bugfix: nginx could not be built by the icc 9.0 compiler.
*) Bugfix: if the SSI was enabled for zero size static file, then the
chunked response was encoded incorrectly.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 15 Nov 2005 13:30:52 +0000 |
parents | 174f1e853e1e |
children | 4e296b7d25bf |
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:
423
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:
423
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:
423
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:
423
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 |
547 | 13 static void ngx_imap_init_session(ngx_connection_t *c); |
541 | 14 static void ngx_imap_init_protocol(ngx_event_t *rev); |
527 | 15 static ngx_int_t ngx_imap_read_command(ngx_imap_session_t *s); |
541 | 16 static u_char *ngx_imap_log_error(ngx_log_t *log, u_char *buf, size_t len); |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
17 |
539 | 18 #if (NGX_IMAP_SSL) |
547 | 19 static void ngx_imap_ssl_handshake_handler(ngx_connection_t *c); |
539 | 20 #endif |
21 | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
22 |
521 | 23 static ngx_str_t greetings[] = { |
527 | 24 ngx_string("+OK POP3 ready" CRLF), |
529 | 25 ngx_string("* OK IMAP4 ready" CRLF) |
521 | 26 }; |
27 | |
525 | 28 static ngx_str_t internal_server_errors[] = { |
29 ngx_string("-ERR internal server error" CRLF), | |
30 ngx_string("* BAD internal server error" CRLF), | |
31 }; | |
32 | |
521 | 33 static u_char pop3_ok[] = "+OK" CRLF; |
34 static u_char pop3_invalid_command[] = "-ERR invalid command" CRLF; | |
35 | |
543 | 36 static u_char imap_star[] = "* "; |
529 | 37 static u_char imap_ok[] = "OK completed" CRLF; |
527 | 38 static u_char imap_next[] = "+ OK" CRLF; |
39 static u_char imap_bye[] = "* BYE" CRLF; | |
40 static u_char imap_invalid_command[] = "BAD invalid command" CRLF; | |
41 | |
521 | 42 |
43 void | |
44 ngx_imap_init_connection(ngx_connection_t *c) | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
45 { |
547 | 46 ngx_imap_log_ctx_t *lctx; |
543 | 47 #if (NGX_IMAP_SSL) |
547 | 48 ngx_imap_conf_ctx_t *ctx; |
49 ngx_imap_ssl_conf_t *sslcf; | |
50 ngx_imap_core_srv_conf_t *cscf; | |
543 | 51 #endif |
541 | 52 |
547 | 53 ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%ui client %V connected to %V", |
54 c->number, &c->addr_text, &c->listening->addr_text); | |
541 | 55 |
543 | 56 lctx = ngx_palloc(c->pool, sizeof(ngx_imap_log_ctx_t)); |
57 if (lctx == NULL) { | |
541 | 58 ngx_imap_close_connection(c); |
59 return; | |
577 | 60 } |
541 | 61 |
543 | 62 lctx->client = &c->addr_text; |
63 lctx->session = NULL; | |
541 | 64 |
65 c->log->connection = c->number; | |
66 c->log->handler = ngx_imap_log_error; | |
543 | 67 c->log->data = lctx; |
541 | 68 c->log->action = "sending client greeting line"; |
69 | |
70 c->log_error = NGX_ERROR_INFO; | |
71 | |
543 | 72 #if (NGX_IMAP_SSL) |
73 | |
74 ctx = c->ctx; | |
75 sslcf = ngx_imap_get_module_srv_conf(ctx, ngx_imap_ssl_module); | |
76 | |
77 if (sslcf->enable) { | |
547 | 78 if (ngx_ssl_create_connection(&sslcf->ssl, c, 0) == NGX_ERROR) { |
543 | 79 ngx_imap_close_connection(c); |
80 return; | |
81 } | |
82 | |
547 | 83 if (ngx_ssl_handshake(c) == NGX_AGAIN) { |
84 | |
85 cscf = ngx_imap_get_module_srv_conf(ctx, ngx_imap_core_module); | |
86 | |
87 ngx_add_timer(c->read, cscf->timeout); | |
88 | |
89 c->ssl->handler = ngx_imap_ssl_handshake_handler; | |
90 | |
91 return; | |
92 } | |
93 | |
94 ngx_imap_ssl_handshake_handler(c); | |
95 return; | |
543 | 96 } |
97 | |
98 #endif | |
99 | |
547 | 100 ngx_imap_init_session(c); |
541 | 101 } |
102 | |
103 | |
547 | 104 #if (NGX_IMAP_SSL) |
105 | |
541 | 106 static void |
547 | 107 ngx_imap_ssl_handshake_handler(ngx_connection_t *c) |
577 | 108 { |
547 | 109 if (c->ssl->handshaked) { |
110 ngx_imap_init_session(c); | |
111 return; | |
112 } | |
113 | |
114 ngx_imap_close_connection(c); | |
115 return; | |
116 } | |
117 | |
118 #endif | |
119 | |
120 | |
121 static void | |
122 ngx_imap_init_session(ngx_connection_t *c) | |
541 | 123 { |
539 | 124 ngx_imap_session_t *s; |
541 | 125 ngx_imap_log_ctx_t *lctx; |
521 | 126 ngx_imap_conf_ctx_t *ctx; |
541 | 127 ngx_imap_core_srv_conf_t *cscf; |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
128 |
547 | 129 c->read->handler = ngx_imap_init_protocol; |
130 c->write->handler = ngx_imap_send; | |
539 | 131 |
132 s = ngx_pcalloc(c->pool, sizeof(ngx_imap_session_t)); | |
133 if (s == NULL) { | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
134 ngx_imap_close_connection(c); |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
135 return; |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
136 } |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
137 |
547 | 138 ctx = c->ctx; |
139 cscf = ngx_imap_get_module_srv_conf(ctx, ngx_imap_core_module); | |
140 | |
539 | 141 c->data = s; |
142 s->connection = c; | |
143 | |
144 s->protocol = cscf->protocol; | |
145 | |
146 s->ctx = ngx_pcalloc(c->pool, sizeof(void *) * ngx_imap_max_module); | |
147 if (s->ctx == NULL) { | |
148 ngx_imap_session_internal_server_error(s); | |
149 return; | |
150 } | |
151 | |
152 s->main_conf = ctx->main_conf; | |
153 s->srv_conf = ctx->srv_conf; | |
154 | |
155 s->out = greetings[s->protocol]; | |
156 | |
541 | 157 lctx = c->log->data; |
158 lctx->session = s; | |
159 | |
547 | 160 ngx_add_timer(c->read, cscf->timeout); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
161 |
547 | 162 if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) { |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
163 ngx_imap_close_connection(c); |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 } |
539 | 165 |
166 ngx_imap_send(c->write); | |
167 } | |
168 | |
169 | |
170 void | |
171 ngx_imap_send(ngx_event_t *wev) | |
172 { | |
541 | 173 ngx_int_t n; |
174 ngx_connection_t *c; | |
175 ngx_imap_session_t *s; | |
176 ngx_imap_core_srv_conf_t *cscf; | |
539 | 177 |
178 c = wev->data; | |
179 s = c->data; | |
180 | |
181 if (wev->timedout) { | |
182 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); | |
577 | 183 c->timedout = 1; |
539 | 184 ngx_imap_close_connection(c); |
185 return; | |
186 } | |
187 | |
188 if (s->out.len == 0) { | |
189 if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) { | |
190 ngx_imap_close_connection(c); | |
191 } | |
192 | |
193 return; | |
194 } | |
195 | |
196 n = c->send(c, s->out.data, s->out.len); | |
197 | |
198 if (n > 0) { | |
199 s->out.len -= n; | |
200 | |
541 | 201 if (wev->timer_set) { |
202 ngx_del_timer(wev); | |
203 } | |
204 | |
539 | 205 if (s->quit) { |
206 ngx_imap_close_connection(c); | |
207 return; | |
208 } | |
209 | |
210 if (s->blocked) { | |
211 c->read->handler(c->read); | |
212 } | |
213 | |
214 return; | |
215 } | |
216 | |
217 if (n == NGX_ERROR) { | |
218 ngx_imap_close_connection(c); | |
219 return; | |
220 } | |
221 | |
222 /* n == NGX_AGAIN */ | |
223 | |
541 | 224 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module); |
225 | |
226 ngx_add_timer(c->write, cscf->timeout); | |
227 | |
539 | 228 if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) { |
229 ngx_imap_close_connection(c); | |
230 return; | |
231 } | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
232 } |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
233 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
234 |
521 | 235 static void |
541 | 236 ngx_imap_init_protocol(ngx_event_t *rev) |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
237 { |
521 | 238 size_t size; |
239 ngx_connection_t *c; | |
240 ngx_imap_session_t *s; | |
241 ngx_imap_core_srv_conf_t *cscf; | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
242 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
243 c = rev->data; |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
244 |
541 | 245 c->log->action = "in auth state"; |
246 | |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
247 if (rev->timedout) { |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
248 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); |
577 | 249 c->timedout = 1; |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
250 ngx_imap_close_connection(c); |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
251 return; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
252 } |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
253 |
539 | 254 s = c->data; |
521 | 255 |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
256 if (ngx_array_init(&s->args, c->pool, 2, sizeof(ngx_str_t)) == NGX_ERROR) { |
527 | 257 ngx_imap_session_internal_server_error(s); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
258 return; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
259 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
260 |
539 | 261 if (s->protocol == NGX_IMAP_POP3_PROTOCOL) { |
521 | 262 size = 128; |
527 | 263 s->imap_state = ngx_pop3_start; |
521 | 264 c->read->handler = ngx_pop3_auth_state; |
265 | |
266 } else { | |
539 | 267 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module); |
521 | 268 size = cscf->imap_client_buffer_size; |
527 | 269 s->imap_state = ngx_imap_start; |
521 | 270 c->read->handler = ngx_imap_auth_state; |
271 } | |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
272 |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
273 s->buffer = ngx_create_temp_buf(c->pool, size); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
274 if (s->buffer == NULL) { |
527 | 275 ngx_imap_session_internal_server_error(s); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
276 return; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
277 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
278 |
521 | 279 c->read->handler(rev); |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
280 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
281 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
282 |
527 | 283 void |
521 | 284 ngx_imap_auth_state(ngx_event_t *rev) |
285 { | |
543 | 286 u_char *text, *last, *p, *dst, *src, *end; |
539 | 287 ssize_t text_len, last_len; |
527 | 288 ngx_str_t *arg; |
289 ngx_int_t rc; | |
543 | 290 ngx_uint_t tag, i; |
527 | 291 ngx_connection_t *c; |
292 ngx_imap_session_t *s; | |
293 ngx_imap_core_srv_conf_t *cscf; | |
521 | 294 |
295 c = rev->data; | |
527 | 296 s = c->data; |
521 | 297 |
527 | 298 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap auth state"); |
299 | |
300 if (rev->timedout) { | |
301 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); | |
577 | 302 c->timedout = 1; |
527 | 303 ngx_imap_close_connection(c); |
304 return; | |
305 } | |
306 | |
539 | 307 if (s->out.len) { |
308 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap send handler busy"); | |
309 s->blocked = 1; | |
310 return; | |
311 } | |
312 | |
313 s->blocked = 0; | |
314 | |
527 | 315 rc = ngx_imap_read_command(s); |
316 | |
317 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap auth: %i", rc); | |
318 | |
319 if (rc == NGX_AGAIN || rc == NGX_ERROR) { | |
320 return; | |
321 } | |
322 | |
323 tag = 1; | |
324 | |
325 text = NULL; | |
326 text_len = 0; | |
327 | |
328 last = imap_ok; | |
329 last_len = sizeof(imap_ok) - 1; | |
330 | |
331 if (rc == NGX_OK) { | |
332 | |
333 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap auth command: %i", | |
334 s->command); | |
335 | |
543 | 336 if (s->backslash) { |
337 | |
338 arg = s->args.elts; | |
339 | |
340 for (i = 0; i < s->args.nelts; i++) { | |
341 dst = arg[i].data; | |
342 end = dst + arg[i].len; | |
343 | |
344 for (src = dst; src < end; dst++) { | |
345 *dst = *src; | |
346 if (*src++ == '\\') { | |
347 *dst = *src++; | |
348 } | |
349 } | |
350 | |
351 arg[i].len = dst - arg[i].data; | |
352 } | |
353 | |
354 s->backslash = 0; | |
355 } | |
356 | |
527 | 357 switch (s->command) { |
358 | |
359 case NGX_IMAP_LOGIN: | |
569 | 360 arg = s->args.elts; |
527 | 361 |
569 | 362 if (s->args.nelts == 2 && arg[0].len) { |
527 | 363 |
364 s->login.len = arg[0].len; | |
365 s->login.data = ngx_palloc(c->pool, s->login.len); | |
366 if (s->login.data == NULL) { | |
367 ngx_imap_session_internal_server_error(s); | |
368 return; | |
369 } | |
370 | |
371 ngx_memcpy(s->login.data, arg[0].data, s->login.len); | |
372 | |
373 s->passwd.len = arg[1].len; | |
374 s->passwd.data = ngx_palloc(c->pool, s->passwd.len); | |
375 if (s->passwd.data == NULL) { | |
376 ngx_imap_session_internal_server_error(s); | |
377 return; | |
378 } | |
379 | |
380 ngx_memcpy(s->passwd.data, arg[1].data, s->passwd.len); | |
381 | |
547 | 382 #if (NGX_DEBUG_IMAP_PASSWD) |
527 | 383 ngx_log_debug2(NGX_LOG_DEBUG_IMAP, c->log, 0, |
384 "imap login:\"%V\" passwd:\"%V\"", | |
385 &s->login, &s->passwd); | |
547 | 386 #else |
387 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, | |
388 "imap login:\"%V\"", &s->login); | |
389 #endif | |
527 | 390 |
391 s->args.nelts = 0; | |
392 s->buffer->pos = s->buffer->start; | |
393 s->buffer->last = s->buffer->start; | |
394 | |
395 if (rev->timer_set) { | |
396 ngx_del_timer(rev); | |
397 } | |
398 | |
399 s->login_attempt++; | |
400 | |
401 ngx_imap_auth_http_init(s); | |
402 | |
403 return; | |
404 | |
405 } else { | |
406 rc = NGX_IMAP_PARSE_INVALID_COMMAND; | |
407 } | |
408 | |
409 break; | |
410 | |
411 case NGX_IMAP_CAPABILITY: | |
412 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module); | |
413 text = cscf->imap_capability->pos; | |
414 text_len = cscf->imap_capability->last - cscf->imap_capability->pos; | |
415 break; | |
416 | |
417 case NGX_IMAP_LOGOUT: | |
539 | 418 s->quit = 1; |
527 | 419 text = imap_bye; |
420 text_len = sizeof(imap_bye) - 1; | |
421 break; | |
422 | |
423 case NGX_IMAP_NOOP: | |
424 break; | |
425 | |
426 default: | |
427 rc = NGX_IMAP_PARSE_INVALID_COMMAND; | |
428 break; | |
429 } | |
430 | |
431 } else if (rc == NGX_IMAP_NEXT) { | |
432 last = imap_next; | |
433 last_len = sizeof(imap_next) - 1; | |
434 tag = 0; | |
435 } | |
436 | |
437 if (rc == NGX_IMAP_PARSE_INVALID_COMMAND) { | |
438 last = imap_invalid_command; | |
439 last_len = sizeof(imap_invalid_command) - 1; | |
440 } | |
441 | |
442 if (tag) { | |
543 | 443 if (s->tag.len == 0) { |
444 s->tag.len = sizeof(imap_star) - 1; | |
445 s->tag.data = (u_char *) imap_star; | |
446 } | |
447 | |
539 | 448 if (s->tagged_line.len < s->tag.len + text_len + last_len) { |
449 s->tagged_line.len = s->tag.len + text_len + last_len; | |
450 s->tagged_line.data = ngx_palloc(c->pool, s->tagged_line.len); | |
451 if (s->tagged_line.data == NULL) { | |
527 | 452 ngx_imap_close_connection(c); |
453 return; | |
454 } | |
455 } | |
456 | |
539 | 457 s->out.data = s->tagged_line.data; |
458 s->out.len = s->tag.len + text_len + last_len; | |
459 | |
460 p = s->out.data; | |
527 | 461 |
462 if (text) { | |
463 p = ngx_cpymem(p, text, text_len); | |
464 } | |
465 p = ngx_cpymem(p, s->tag.data, s->tag.len); | |
466 ngx_memcpy(p, last, last_len); | |
467 | |
468 | |
469 } else { | |
539 | 470 s->out.data = last; |
471 s->out.len = last_len; | |
527 | 472 } |
473 | |
539 | 474 if (rc != NGX_IMAP_NEXT) { |
475 s->args.nelts = 0; | |
476 s->buffer->pos = s->buffer->start; | |
477 s->buffer->last = s->buffer->start; | |
478 s->tag.len = 0; | |
527 | 479 } |
480 | |
539 | 481 ngx_imap_send(c->write); |
521 | 482 } |
483 | |
484 | |
527 | 485 void |
521 | 486 ngx_pop3_auth_state(ngx_event_t *rev) |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
487 { |
527 | 488 u_char *text; |
489 ssize_t size; | |
490 ngx_int_t rc; | |
491 ngx_str_t *arg; | |
492 ngx_connection_t *c; | |
493 ngx_imap_session_t *s; | |
494 ngx_imap_core_srv_conf_t *cscf; | |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
495 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
496 c = rev->data; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
497 s = c->data; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
498 |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
499 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "pop3 auth state"); |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
500 |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
501 if (rev->timedout) { |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
502 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); |
577 | 503 c->timedout = 1; |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
504 ngx_imap_close_connection(c); |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
505 return; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
506 } |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
507 |
539 | 508 if (s->out.len) { |
509 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap send handler busy"); | |
510 s->blocked = 1; | |
511 return; | |
512 } | |
513 | |
514 s->blocked = 0; | |
515 | |
527 | 516 rc = ngx_imap_read_command(s); |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
517 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
518 if (rc == NGX_AGAIN || rc == NGX_ERROR) { |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
519 return; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
520 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
521 |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
522 text = pop3_ok; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
523 size = sizeof(pop3_ok) - 1; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
524 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
525 if (rc == NGX_OK) { |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
526 switch (s->imap_state) { |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
527 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
528 case ngx_pop3_start: |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
529 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
530 switch (s->command) { |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
531 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
532 case NGX_POP3_USER: |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
533 if (s->args.nelts == 1) { |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
534 s->imap_state = ngx_pop3_user; |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
535 |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
536 arg = s->args.elts; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
537 s->login.len = arg[0].len; |
527 | 538 s->login.data = ngx_palloc(c->pool, s->login.len); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
539 if (s->login.data == NULL) { |
527 | 540 ngx_imap_session_internal_server_error(s); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
541 return; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
542 } |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
543 |
527 | 544 ngx_memcpy(s->login.data, arg[0].data, s->login.len); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
545 |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
546 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, |
527 | 547 "pop3 login: \"%V\"", &s->login); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
548 |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
549 } else { |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
550 rc = NGX_IMAP_PARSE_INVALID_COMMAND; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
551 } |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
552 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
553 break; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
554 |
527 | 555 case NGX_POP3_CAPA: |
556 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module); | |
557 text = cscf->pop3_capability->pos; | |
558 size = cscf->pop3_capability->last - cscf->pop3_capability->pos; | |
559 break; | |
560 | |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
561 case NGX_POP3_QUIT: |
539 | 562 s->quit = 1; |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
563 break; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
564 |
527 | 565 case NGX_POP3_NOOP: |
566 break; | |
567 | |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
568 default: |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
569 s->imap_state = ngx_pop3_start; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
570 rc = NGX_IMAP_PARSE_INVALID_COMMAND; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
571 break; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
572 } |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
573 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
574 break; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
575 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
576 case ngx_pop3_user: |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
577 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
578 switch (s->command) { |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
579 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
580 case NGX_POP3_PASS: |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
581 if (s->args.nelts == 1) { |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
582 /* STUB */ s->imap_state = ngx_pop3_start; |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
583 |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
584 arg = s->args.elts; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
585 s->passwd.len = arg[0].len; |
527 | 586 s->passwd.data = ngx_palloc(c->pool, s->passwd.len); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
587 if (s->passwd.data == NULL) { |
527 | 588 ngx_imap_session_internal_server_error(s); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
589 return; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
590 } |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
591 |
527 | 592 ngx_memcpy(s->passwd.data, arg[0].data, s->passwd.len); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
593 |
547 | 594 #if (NGX_DEBUG_IMAP_PASSWD) |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
595 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, |
527 | 596 "pop3 passwd: \"%V\"", &s->passwd); |
547 | 597 #endif |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
598 |
527 | 599 s->args.nelts = 0; |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
600 s->buffer->pos = s->buffer->start; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
601 s->buffer->last = s->buffer->start; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
602 |
527 | 603 if (rev->timer_set) { |
604 ngx_del_timer(rev); | |
605 } | |
606 | |
521 | 607 ngx_imap_auth_http_init(s); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
608 |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
609 return; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
421
diff
changeset
|
610 |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
611 } else { |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
612 rc = NGX_IMAP_PARSE_INVALID_COMMAND; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
613 } |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
614 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
615 break; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
616 |
527 | 617 case NGX_POP3_CAPA: |
618 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module); | |
619 text = cscf->pop3_capability->pos; | |
620 size = cscf->pop3_capability->last - cscf->pop3_capability->pos; | |
621 break; | |
622 | |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
623 case NGX_POP3_QUIT: |
539 | 624 s->quit = 1; |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
625 break; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
626 |
527 | 627 case NGX_POP3_NOOP: |
628 break; | |
629 | |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
630 default: |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
631 s->imap_state = ngx_pop3_start; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
632 rc = NGX_IMAP_PARSE_INVALID_COMMAND; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
633 break; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
634 } |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
635 |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
636 break; |
527 | 637 |
638 /* suppress warinings */ | |
639 case ngx_pop3_passwd: | |
640 break; | |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
641 } |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
642 } |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
643 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
644 if (rc == NGX_IMAP_PARSE_INVALID_COMMAND) { |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
645 text = pop3_invalid_command; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
646 size = sizeof(pop3_invalid_command) - 1; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
647 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
648 |
421
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
649 s->args.nelts = 0; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
650 s->buffer->pos = s->buffer->start; |
01456a419cf9
nginx-0.0.10-2004-09-10-18:32:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
420
diff
changeset
|
651 s->buffer->last = s->buffer->start; |
539 | 652 |
653 s->out.data = text; | |
654 s->out.len = size; | |
655 | |
656 ngx_imap_send(c->write); | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
657 } |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
658 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
659 |
521 | 660 static ngx_int_t |
527 | 661 ngx_imap_read_command(ngx_imap_session_t *s) |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
662 { |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
663 ssize_t n; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
664 ngx_int_t rc; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
665 |
539 | 666 n = s->connection->recv(s->connection, s->buffer->last, |
667 s->buffer->end - s->buffer->last); | |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
668 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
669 if (n == NGX_ERROR || n == 0) { |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
670 ngx_imap_close_connection(s->connection); |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
671 return NGX_ERROR; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
672 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
673 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
674 if (n > 0) { |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
675 s->buffer->last += n; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
676 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
677 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
678 if (n == NGX_AGAIN) { |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
679 if (ngx_handle_read_event(s->connection->read, 0) == NGX_ERROR) { |
527 | 680 ngx_imap_session_internal_server_error(s); |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
681 return NGX_ERROR; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
682 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
683 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
684 return NGX_AGAIN; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
685 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
686 |
527 | 687 if (s->protocol == NGX_IMAP_POP3_PROTOCOL) { |
688 rc = ngx_pop3_parse_command(s); | |
689 } else { | |
690 rc = ngx_imap_parse_command(s); | |
691 } | |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
692 |
527 | 693 if (rc == NGX_AGAIN |
694 || rc == NGX_IMAP_NEXT | |
695 || rc == NGX_IMAP_PARSE_INVALID_COMMAND) | |
696 { | |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
697 return rc; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
698 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
699 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
700 if (rc == NGX_ERROR) { |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
701 ngx_imap_close_connection(s->connection); |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
702 return NGX_ERROR; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
703 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
704 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
705 return NGX_OK; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
706 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
707 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
708 |
521 | 709 void |
525 | 710 ngx_imap_session_internal_server_error(ngx_imap_session_t *s) |
711 { | |
539 | 712 s->out = internal_server_errors[s->protocol]; |
713 s->quit = 1; | |
525 | 714 |
539 | 715 ngx_imap_send(s->connection->write); |
525 | 716 } |
717 | |
718 | |
719 void | |
521 | 720 ngx_imap_close_connection(ngx_connection_t *c) |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
721 { |
479 | 722 ngx_pool_t *pool; |
723 | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
724 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
725 "close imap connection: %d", c->fd); |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
726 |
539 | 727 #if (NGX_IMAP_SSL) |
728 | |
729 if (c->ssl) { | |
730 if (ngx_ssl_shutdown(c) == NGX_AGAIN) { | |
577 | 731 c->ssl->handler = ngx_imap_close_connection; |
539 | 732 return; |
733 } | |
734 } | |
735 | |
736 #endif | |
737 | |
543 | 738 c->closed = 1; |
739 | |
479 | 740 pool = c->pool; |
741 | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
742 ngx_close_connection(c); |
479 | 743 |
501 | 744 ngx_destroy_pool(pool); |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
745 } |
539 | 746 |
747 | |
541 | 748 static u_char * |
749 ngx_imap_log_error(ngx_log_t *log, u_char *buf, size_t len) | |
750 { | |
567 | 751 u_char *p; |
752 ngx_imap_session_t *s; | |
753 ngx_imap_log_ctx_t *ctx; | |
541 | 754 |
755 if (log->action) { | |
756 p = ngx_snprintf(buf, len, " while %s", log->action); | |
757 len -= p - buf; | |
758 buf = p; | |
759 } | |
577 | 760 |
541 | 761 ctx = log->data; |
762 | |
763 p = ngx_snprintf(buf, len, ", client: %V", ctx->client); | |
764 len -= p - buf; | |
765 buf = p; | |
766 | |
767 s = ctx->session; | |
768 | |
769 if (s == NULL) { | |
770 return p; | |
771 } | |
772 | |
773 p = ngx_snprintf(buf, len, ", server: %V", | |
774 &s->connection->listening->addr_text); | |
775 len -= p - buf; | |
776 buf = p; | |
777 | |
778 if (s->login.len == 0) { | |
779 return p; | |
780 } | |
781 | |
782 p = ngx_snprintf(buf, len, ", login: \"%V\"", &s->login); | |
783 len -= p - buf; | |
784 buf = p; | |
785 | |
786 if (s->proxy == NULL) { | |
787 return p; | |
788 } | |
789 | |
790 p = ngx_snprintf(buf, len, ", upstream: %V", | |
791 &s->proxy->upstream.peers->peer[0].name); | |
792 | |
793 return p; | |
794 } |