Mercurial > hg > nginx
comparison src/imap/ngx_imap_handler.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 | 09b42134ac0c |
comparison
equal
deleted
inserted
replaced
520:1fecc7e0d717 | 521:6f00349b98e5 |
---|---|
10 #include <ngx_imap.h> | 10 #include <ngx_imap.h> |
11 #include <nginx.h> | 11 #include <nginx.h> |
12 | 12 |
13 | 13 |
14 static void ngx_imap_init_session(ngx_event_t *rev); | 14 static void ngx_imap_init_session(ngx_event_t *rev); |
15 | |
15 static void ngx_pop3_auth_state(ngx_event_t *rev); | 16 static void ngx_pop3_auth_state(ngx_event_t *rev); |
16 static ngx_int_t ngx_pop3_read_command(ngx_imap_session_t *s); | 17 static ngx_int_t ngx_pop3_read_command(ngx_imap_session_t *s); |
17 | 18 |
18 | 19 static void ngx_imap_auth_state(ngx_event_t *rev); |
19 static u_char pop3_greeting[] = "+OK " NGINX_VER " ready" CRLF; | 20 |
20 #if 0 | 21 |
21 static u_char imap_greeting[] = "* OK " NGINX_VER " ready" CRLF; | 22 static ngx_str_t greetings[] = { |
22 #endif | 23 ngx_string("+OK " NGINX_VER " ready" CRLF), |
23 | 24 ngx_string("* OK " NGINX_VER " ready" CRLF) |
24 static u_char pop3_ok[] = "+OK" CRLF; | 25 }; |
25 static u_char pop3_invalid_command[] = "-ERR invalid command" CRLF; | 26 |
26 | 27 static u_char pop3_ok[] = "+OK" CRLF; |
27 | 28 static u_char pop3_invalid_command[] = "-ERR invalid command" CRLF; |
28 void ngx_imap_init_connection(ngx_connection_t *c) | 29 |
29 { | 30 |
30 u_char *greeting; | 31 void |
31 ssize_t size; | 32 ngx_imap_init_connection(ngx_connection_t *c) |
32 | 33 { |
33 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, | 34 ssize_t size; |
34 "imap init connection"); | 35 ngx_imap_conf_ctx_t *ctx; |
36 ngx_imap_core_srv_conf_t *cscf; | |
37 | |
38 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "imap init connection"); | |
35 | 39 |
36 c->log_error = NGX_ERROR_INFO; | 40 c->log_error = NGX_ERROR_INFO; |
37 | 41 |
38 greeting = pop3_greeting; | 42 ctx = c->ctx; |
39 size = sizeof(pop3_greeting) - 1; | 43 cscf = ngx_imap_get_module_srv_conf(ctx, ngx_imap_core_module); |
40 | 44 |
41 if (ngx_send(c, greeting, size) < size) { | 45 size = greetings[cscf->protocol].len; |
46 | |
47 if (ngx_send(c, greetings[cscf->protocol].data, size) < size) { | |
42 /* | 48 /* |
43 * we treat the incomplete sending as NGX_ERROR | 49 * we treat the incomplete sending as NGX_ERROR |
44 * because it is very strange here | 50 * because it is very strange here |
45 */ | 51 */ |
46 ngx_imap_close_connection(c); | 52 ngx_imap_close_connection(c); |
47 return; | 53 return; |
48 } | 54 } |
49 | 55 |
50 c->read->handler = ngx_imap_init_session; | 56 c->read->handler = ngx_imap_init_session; |
51 | 57 |
52 ngx_add_timer(c->read, /* STUB */ 60000); | 58 ngx_add_timer(c->read, cscf->timeout); |
53 | 59 |
54 if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) { | 60 if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) { |
55 ngx_imap_close_connection(c); | 61 ngx_imap_close_connection(c); |
56 } | 62 } |
57 } | 63 } |
58 | 64 |
59 | 65 |
60 static void ngx_imap_init_session(ngx_event_t *rev) | 66 static void |
61 { | 67 ngx_imap_init_session(ngx_event_t *rev) |
62 size_t size; | 68 { |
63 ngx_connection_t *c; | 69 size_t size; |
64 ngx_imap_session_t *s; | 70 ngx_connection_t *c; |
71 ngx_imap_session_t *s; | |
72 ngx_imap_conf_ctx_t *ctx; | |
73 ngx_imap_core_srv_conf_t *cscf; | |
65 | 74 |
66 c = rev->data; | 75 c = rev->data; |
67 | 76 |
68 if (rev->timedout) { | 77 if (rev->timedout) { |
69 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); | 78 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); |
78 } | 87 } |
79 | 88 |
80 c->data = s; | 89 c->data = s; |
81 s->connection = c; | 90 s->connection = c; |
82 | 91 |
92 s->ctx = ngx_pcalloc(c->pool, sizeof(void *) * ngx_imap_max_module); | |
93 if (s->ctx == NULL) { | |
94 ngx_imap_close_connection(c); | |
95 return; | |
96 } | |
97 | |
98 ctx = c->ctx; | |
99 s->main_conf = ctx->main_conf; | |
100 s->srv_conf = ctx->srv_conf; | |
101 | |
83 if (ngx_array_init(&s->args, c->pool, 2, sizeof(ngx_str_t)) == NGX_ERROR) { | 102 if (ngx_array_init(&s->args, c->pool, 2, sizeof(ngx_str_t)) == NGX_ERROR) { |
84 ngx_imap_close_connection(c); | 103 ngx_imap_close_connection(c); |
85 return; | 104 return; |
86 } | 105 } |
87 | 106 |
88 size = /* STUB: pop3: 128, imap: configurable 4K default */ 128; | 107 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module); |
108 | |
109 s->protocol = cscf->protocol; | |
110 | |
111 if (cscf->protocol == NGX_IMAP_POP3_PROTOCOL) { | |
112 size = 128; | |
113 c->read->handler = ngx_pop3_auth_state; | |
114 | |
115 } else { | |
116 size = cscf->imap_client_buffer_size; | |
117 c->read->handler = ngx_imap_auth_state; | |
118 } | |
89 | 119 |
90 s->buffer = ngx_create_temp_buf(c->pool, size); | 120 s->buffer = ngx_create_temp_buf(c->pool, size); |
91 if (s->buffer == NULL) { | 121 if (s->buffer == NULL) { |
92 ngx_imap_close_connection(c); | 122 ngx_imap_close_connection(c); |
93 return; | 123 return; |
94 } | 124 } |
95 | 125 |
96 c->read->handler = ngx_pop3_auth_state; | 126 c->read->handler(rev); |
97 | 127 } |
98 ngx_pop3_auth_state(rev); | 128 |
99 } | 129 |
100 | 130 static void |
101 | 131 ngx_imap_auth_state(ngx_event_t *rev) |
102 static void ngx_pop3_auth_state(ngx_event_t *rev) | 132 { |
133 ngx_connection_t *c; | |
134 | |
135 c = rev->data; | |
136 | |
137 ngx_imap_close_connection(c); | |
138 } | |
139 | |
140 | |
141 static void | |
142 ngx_pop3_auth_state(ngx_event_t *rev) | |
103 { | 143 { |
104 u_char *text; | 144 u_char *text; |
105 ssize_t size; | 145 ssize_t size; |
106 ngx_int_t rc; | 146 ngx_int_t rc; |
107 ngx_uint_t quit; | 147 ngx_uint_t quit; |
194 "pop3 passwd: \"%s\"", s->passwd.data); | 234 "pop3 passwd: \"%s\"", s->passwd.data); |
195 | 235 |
196 s->buffer->pos = s->buffer->start; | 236 s->buffer->pos = s->buffer->start; |
197 s->buffer->last = s->buffer->start; | 237 s->buffer->last = s->buffer->start; |
198 | 238 |
199 ngx_imap_proxy_init(s); | 239 ngx_imap_auth_http_init(s); |
200 | 240 |
201 return; | 241 return; |
202 | 242 |
203 } else { | 243 } else { |
204 rc = NGX_IMAP_PARSE_INVALID_COMMAND; | 244 rc = NGX_IMAP_PARSE_INVALID_COMMAND; |
243 s->buffer->pos = s->buffer->start; | 283 s->buffer->pos = s->buffer->start; |
244 s->buffer->last = s->buffer->start; | 284 s->buffer->last = s->buffer->start; |
245 } | 285 } |
246 | 286 |
247 | 287 |
248 static ngx_int_t ngx_pop3_read_command(ngx_imap_session_t *s) | 288 static ngx_int_t |
289 ngx_pop3_read_command(ngx_imap_session_t *s) | |
249 { | 290 { |
250 ssize_t n; | 291 ssize_t n; |
251 ngx_int_t rc; | 292 ngx_int_t rc; |
252 | 293 |
253 n = ngx_recv(s->connection, s->buffer->last, | 294 n = ngx_recv(s->connection, s->buffer->last, |
286 } | 327 } |
287 | 328 |
288 | 329 |
289 #if 0 | 330 #if 0 |
290 | 331 |
291 void ngx_imap_close_session(ngx_imap_session_t *s) | 332 void |
333 ngx_imap_close_session(ngx_imap_session_t *s) | |
292 { | 334 { |
293 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, s->connection->log, 0, | 335 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, s->connection->log, 0, |
294 "close imap session"); | 336 "close imap session"); |
295 | 337 |
296 ngx_imap_close_connection(s->connection); | 338 ngx_imap_close_connection(s->connection); |
297 } | 339 } |
298 | 340 |
299 #endif | 341 #endif |
300 | 342 |
301 | 343 |
302 void ngx_imap_close_connection(ngx_connection_t *c) | 344 void |
345 ngx_imap_close_connection(ngx_connection_t *c) | |
303 { | 346 { |
304 ngx_pool_t *pool; | 347 ngx_pool_t *pool; |
305 | 348 |
306 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, | 349 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0, |
307 "close imap connection: %d", c->fd); | 350 "close imap connection: %d", c->fd); |