Mercurial > hg > nginx
comparison src/imap/ngx_imap_proxy.c @ 422:edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sat, 11 Sep 2004 20:22:11 +0000 |
parents | 47709bff4468 |
children | fda5987b188d |
comparison
equal
deleted
inserted
replaced
421:01456a419cf9 | 422:edaefb2a20fc |
---|---|
5 #include <ngx_event_connect.h> | 5 #include <ngx_event_connect.h> |
6 #include <ngx_imap.h> | 6 #include <ngx_imap.h> |
7 | 7 |
8 | 8 |
9 static void ngx_imap_proxy_block_read(ngx_event_t *rev); | 9 static void ngx_imap_proxy_block_read(ngx_event_t *rev); |
10 static void ngx_imap_proxy_greeting_handler(ngx_event_t *rev); | 10 static void ngx_imap_proxy_auth_handler(ngx_event_t *rev); |
11 static void ngx_imap_proxy_init_handler(ngx_event_t *wev); | 11 static void ngx_imap_proxy_init_handler(ngx_event_t *wev); |
12 static void ngx_imap_proxy_dummy_handler(ngx_event_t *ev); | 12 static void ngx_imap_proxy_dummy_handler(ngx_event_t *ev); |
13 static ngx_int_t ngx_imap_proxy_read_response(ngx_imap_session_t *s); | 13 static ngx_int_t ngx_imap_proxy_read_response(ngx_imap_session_t *s); |
14 static void ngx_imap_proxy_handler(ngx_event_t *ev); | 14 static void ngx_imap_proxy_handler(ngx_event_t *ev); |
15 static void ngx_imap_proxy_close_session(ngx_imap_session_t *s); | 15 static void ngx_imap_proxy_close_session(ngx_imap_session_t *s); |
55 | 55 |
56 p->upstream.connection->data = s; | 56 p->upstream.connection->data = s; |
57 p->upstream.connection->pool = s->connection->pool; | 57 p->upstream.connection->pool = s->connection->pool; |
58 | 58 |
59 s->connection->read->event_handler = ngx_imap_proxy_block_read; | 59 s->connection->read->event_handler = ngx_imap_proxy_block_read; |
60 p->upstream.connection->read->event_handler = | 60 p->upstream.connection->read->event_handler = ngx_imap_proxy_auth_handler; |
61 ngx_imap_proxy_greeting_handler; | |
62 p->upstream.connection->write->event_handler = ngx_imap_proxy_dummy_handler; | 61 p->upstream.connection->write->event_handler = ngx_imap_proxy_dummy_handler; |
63 } | 62 } |
64 | 63 |
65 | 64 |
66 static void ngx_imap_proxy_block_read(ngx_event_t *rev) | 65 static void ngx_imap_proxy_block_read(ngx_event_t *rev) |
77 ngx_imap_proxy_close_session(s); | 76 ngx_imap_proxy_close_session(s); |
78 } | 77 } |
79 } | 78 } |
80 | 79 |
81 | 80 |
82 static void ngx_imap_proxy_greeting_handler(ngx_event_t *rev) | 81 static void ngx_imap_proxy_auth_handler(ngx_event_t *rev) |
83 { | 82 { |
83 u_char *p; | |
84 ngx_int_t rc; | 84 ngx_int_t rc; |
85 ngx_buf_t *b; | 85 ngx_str_t line; |
86 ngx_connection_t *c; | 86 ngx_connection_t *c; |
87 ngx_imap_session_t *s; | 87 ngx_imap_session_t *s; |
88 | 88 |
89 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, | 89 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy auth handler"); |
90 "imap proxy greeting handler"); | |
91 | 90 |
92 c = rev->data; | 91 c = rev->data; |
93 s = c->data; | 92 s = c->data; |
94 | 93 |
95 if (s->proxy->buffer == NULL) { | 94 if (s->proxy->buffer == NULL) { |
104 | 103 |
105 if (rc == NGX_AGAIN) { | 104 if (rc == NGX_AGAIN) { |
106 return; | 105 return; |
107 } | 106 } |
108 | 107 |
109 if (rc == NGX_OK) { | 108 if (rc == NGX_ERROR) { |
110 s->connection->read->event_handler = ngx_imap_proxy_handler; | 109 /* TODO: ngx_imap_proxy_finalize_session(s, NGX_IMAP_INTERNAL_ERROR) */ |
111 s->connection->write->event_handler = ngx_imap_proxy_handler; | 110 ngx_imap_proxy_close_session(s); |
112 rev->event_handler = ngx_imap_proxy_handler; | 111 return; |
113 c->write->event_handler = ngx_imap_proxy_handler; | 112 } |
114 | 113 |
115 b = s->proxy->buffer; | 114 if (s->imap_state == ngx_pop3_start) { |
116 b->pos = b->start; | 115 |
117 b->last = b->start; | 116 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send user"); |
118 | 117 |
119 if (ngx_handle_read_event(s->connection->read, 0) == NGX_ERROR) { | 118 line.len = sizeof("USER ") + s->login.len - 1 + 2; |
119 if (!(line.data = ngx_palloc(c->pool, line.len))) { | |
120 ngx_imap_proxy_close_session(s); | 120 ngx_imap_proxy_close_session(s); |
121 return; | 121 return; |
122 } | 122 } |
123 | 123 |
124 if (s->connection->read->ready) { | 124 p = ngx_cpymem(line.data, "USER ", sizeof("USER ") - 1); |
125 ngx_imap_proxy_handler(s->connection->read); | 125 p = ngx_cpymem(p, s->login.data, s->login.len); |
126 } | 126 *p++ = CR; *p++ = LF; |
127 | 127 |
128 return; | 128 if (ngx_send(c, line.data, line.len) < (ssize_t) line.len) { |
129 } | 129 /* |
130 | 130 * we treat the incomplete sending as NGX_ERROR |
131 /* TODO: ngx_imap_proxy_finalize_session(s, NGX_IMAP_INTERNAL_ERROR) */ | 131 * because it is very strange here |
132 ngx_imap_proxy_close_session(s); | 132 */ |
133 ngx_imap_close_connection(c); | |
134 return; | |
135 } | |
136 | |
137 s->imap_state = ngx_pop3_user; | |
138 | |
139 s->proxy->buffer->pos = s->proxy->buffer->start; | |
140 s->proxy->buffer->last = s->proxy->buffer->start; | |
141 | |
142 return; | |
143 } | |
144 | |
145 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send pass"); | |
146 | |
147 line.len = sizeof("PASS ") + s->passwd.len - 1 + 2; | |
148 if (!(line.data = ngx_palloc(c->pool, line.len))) { | |
149 ngx_imap_proxy_close_session(s); | |
150 return; | |
151 } | |
152 | |
153 p = ngx_cpymem(line.data, "PASS ", sizeof("PASS ") - 1); | |
154 p = ngx_cpymem(p, s->passwd.data, s->passwd.len); | |
155 *p++ = CR; *p++ = LF; | |
156 | |
157 if (ngx_send(c, line.data, line.len) < (ssize_t) line.len) { | |
158 /* | |
159 * we treat the incomplete sending as NGX_ERROR | |
160 * because it is very strange here | |
161 */ | |
162 ngx_imap_close_connection(c); | |
163 return; | |
164 } | |
165 | |
166 s->proxy->buffer->pos = s->proxy->buffer->start; | |
167 s->proxy->buffer->last = s->proxy->buffer->start; | |
168 | |
169 s->connection->read->event_handler = ngx_imap_proxy_handler; | |
170 s->connection->write->event_handler = ngx_imap_proxy_handler; | |
171 rev->event_handler = ngx_imap_proxy_handler; | |
172 c->write->event_handler = ngx_imap_proxy_handler; | |
133 } | 173 } |
134 | 174 |
135 | 175 |
136 static void ngx_imap_proxy_dummy_handler(ngx_event_t *ev) | 176 static void ngx_imap_proxy_dummy_handler(ngx_event_t *ev) |
137 { | 177 { |