Mercurial > hg > nginx
comparison src/imap/ngx_imap_handler.c @ 419:47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 09 Sep 2004 15:40:48 +0000 |
parents | cf072d26d6d6 |
children | 33a8253115b4 |
comparison
equal
deleted
inserted
replaced
418:cf072d26d6d6 | 419:47709bff4468 |
---|---|
4 #include <ngx_event.h> | 4 #include <ngx_event.h> |
5 #include <ngx_imap.h> | 5 #include <ngx_imap.h> |
6 #include <nginx.h> | 6 #include <nginx.h> |
7 | 7 |
8 | 8 |
9 static void ngx_imap_auth_state(ngx_event_t *rev); | 9 static void ngx_imap_init_session(ngx_event_t *rev); |
10 | 10 |
11 | 11 |
12 static char pop3_greeting[] = "+OK " NGINX_VER " ready" CRLF; | 12 static char pop3_greeting[] = "+OK " NGINX_VER " ready" CRLF; |
13 static char imap_greeting[] = "* OK " NGINX_VER " ready" CRLF; | 13 static char imap_greeting[] = "* OK " NGINX_VER " ready" CRLF; |
14 | 14 |
15 | 15 |
16 void ngx_imap_init_connection(ngx_connection_t *c) | 16 void ngx_imap_init_connection(ngx_connection_t *c) |
17 { | 17 { |
18 ngx_int_t n; | 18 char *greeting; |
19 ssize_t size; | |
20 ngx_int_t n; | |
19 | 21 |
20 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, | 22 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, |
21 "imap init connection"); | 23 "imap init connection"); |
22 | 24 |
23 c->log_error = NGX_ERROR_INFO; | 25 c->log_error = NGX_ERROR_INFO; |
24 | 26 |
25 n = ngx_send(c, pop3_greeting, sizeof(pop3_greeting) - 1); | 27 greeting = pop3_greeting; |
28 size = sizeof(pop3_greeting) - 1; | |
26 | 29 |
27 if (n == NGX_ERROR) { | 30 n = ngx_send(c, greeting, size); |
31 | |
32 if (n < size) { | |
33 /* | |
34 * we treat the incomplete sending as NGX_ERROR | |
35 * because it is very strange here | |
36 */ | |
28 ngx_imap_close_connection(c); | 37 ngx_imap_close_connection(c); |
29 return; | 38 return; |
30 } | 39 } |
31 | 40 |
32 c->read->event_handler = ngx_imap_auth_state; | 41 c->read->event_handler = ngx_imap_init_session; |
42 | |
43 ngx_add_timer(c->read, /* STUB */ 60000); | |
33 | 44 |
34 if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) { | 45 if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) { |
35 ngx_imap_close_connection(c); | 46 ngx_imap_close_connection(c); |
36 return; | |
37 } | 47 } |
38 } | 48 } |
39 | 49 |
40 | 50 |
41 static void ngx_imap_auth_state(ngx_event_t *rev) | 51 static void ngx_imap_init_session(ngx_event_t *rev) |
42 { | 52 { |
43 ngx_connection_t *c; | 53 ngx_connection_t *c; |
54 ngx_imap_session_t *s; | |
44 | 55 |
45 c = rev->data; | 56 c = rev->data; |
46 | 57 |
47 ngx_imap_close_connection(c); | 58 if (!(s = ngx_pcalloc(c->pool, sizeof(ngx_imap_session_t)))) { |
59 ngx_imap_close_connection(c); | |
60 return; | |
61 } | |
62 | |
63 c->data = s; | |
64 s->connection = c; | |
65 | |
66 if (ngx_array_init(&s->args, c->pool, 2, sizeof(ngx_str_t)) == NGX_ERROR) { | |
67 ngx_imap_close_connection(s->connection); | |
68 return; | |
69 } | |
70 | |
71 s->buffer = ngx_create_temp_buf(s->connection->pool, /* STUB */ 4096); | |
72 if (s->buffer == NULL) { | |
73 ngx_imap_close_connection(s->connection); | |
74 return; | |
75 } | |
76 | |
77 ngx_imap_proxy_init(s); | |
48 } | 78 } |
49 | 79 |
50 | 80 |
51 void ngx_imap_close_connection(ngx_connection_t *c) | 81 void ngx_imap_close_connection(ngx_connection_t *c) |
52 { | 82 { |