Mercurial > hg > nginx-quic
annotate src/mail/ngx_mail_proxy_module.c @ 1436:ccbf588fb517
win32 ngx_is_exec() stub
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 30 Aug 2007 18:57:38 +0000 |
parents | be2e13691c60 |
children | f69493e8faab |
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:
426
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:
426
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:
426
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:
426
diff
changeset
|
5 |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_event.h> |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
10 #include <ngx_event_connect.h> |
1136 | 11 #include <ngx_mail.h> |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
13 |
521 | 14 typedef struct { |
15 ngx_flag_t enable; | |
857 | 16 ngx_flag_t pass_error_message; |
1136 | 17 ngx_flag_t xclient; |
539 | 18 size_t buffer_size; |
19 ngx_msec_t timeout; | |
1136 | 20 } ngx_mail_proxy_conf_t; |
521 | 21 |
22 | |
1136 | 23 static void ngx_mail_proxy_block_read(ngx_event_t *rev); |
24 static void ngx_mail_proxy_pop3_handler(ngx_event_t *rev); | |
25 static void ngx_mail_proxy_imap_handler(ngx_event_t *rev); | |
26 static void ngx_mail_proxy_smtp_handler(ngx_event_t *rev); | |
27 static void ngx_mail_proxy_dummy_handler(ngx_event_t *ev); | |
28 static ngx_int_t ngx_mail_proxy_read_response(ngx_mail_session_t *s, | |
663 | 29 ngx_uint_t state); |
1136 | 30 static void ngx_mail_proxy_handler(ngx_event_t *ev); |
31 static void ngx_mail_proxy_upstream_error(ngx_mail_session_t *s); | |
32 static void ngx_mail_proxy_internal_server_error(ngx_mail_session_t *s); | |
33 static void ngx_mail_proxy_close_session(ngx_mail_session_t *s); | |
34 static void *ngx_mail_proxy_create_conf(ngx_conf_t *cf); | |
35 static char *ngx_mail_proxy_merge_conf(ngx_conf_t *cf, void *parent, | |
521 | 36 void *child); |
37 | |
38 | |
1136 | 39 static ngx_command_t ngx_mail_proxy_commands[] = { |
539 | 40 |
521 | 41 { ngx_string("proxy"), |
1136 | 42 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG, |
521 | 43 ngx_conf_set_flag_slot, |
1136 | 44 NGX_MAIL_SRV_CONF_OFFSET, |
45 offsetof(ngx_mail_proxy_conf_t, enable), | |
521 | 46 NULL }, |
47 | |
539 | 48 { ngx_string("proxy_buffer"), |
1136 | 49 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
539 | 50 ngx_conf_set_size_slot, |
1136 | 51 NGX_MAIL_SRV_CONF_OFFSET, |
52 offsetof(ngx_mail_proxy_conf_t, buffer_size), | |
539 | 53 NULL }, |
54 | |
55 { ngx_string("proxy_timeout"), | |
1136 | 56 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
539 | 57 ngx_conf_set_msec_slot, |
1136 | 58 NGX_MAIL_SRV_CONF_OFFSET, |
59 offsetof(ngx_mail_proxy_conf_t, timeout), | |
539 | 60 NULL }, |
61 | |
857 | 62 { ngx_string("proxy_pass_error_message"), |
1136 | 63 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, |
857 | 64 ngx_conf_set_flag_slot, |
1136 | 65 NGX_MAIL_SRV_CONF_OFFSET, |
66 offsetof(ngx_mail_proxy_conf_t, pass_error_message), | |
67 NULL }, | |
68 | |
69 { ngx_string("xclient"), | |
70 NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG, | |
71 ngx_conf_set_flag_slot, | |
72 NGX_MAIL_SRV_CONF_OFFSET, | |
73 offsetof(ngx_mail_proxy_conf_t, xclient), | |
857 | 74 NULL }, |
75 | |
521 | 76 ngx_null_command |
77 }; | |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
78 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
79 |
1136 | 80 static ngx_mail_module_t ngx_mail_proxy_module_ctx = { |
521 | 81 NULL, /* create main configuration */ |
82 NULL, /* init main configuration */ | |
83 | |
1136 | 84 ngx_mail_proxy_create_conf, /* create server configuration */ |
85 ngx_mail_proxy_merge_conf /* merge server configuration */ | |
521 | 86 }; |
87 | |
88 | |
1136 | 89 ngx_module_t ngx_mail_proxy_module = { |
521 | 90 NGX_MODULE_V1, |
1136 | 91 &ngx_mail_proxy_module_ctx, /* module context */ |
92 ngx_mail_proxy_commands, /* module directives */ | |
93 NGX_MAIL_MODULE, /* module type */ | |
541 | 94 NULL, /* init master */ |
521 | 95 NULL, /* init module */ |
541 | 96 NULL, /* init process */ |
97 NULL, /* init thread */ | |
98 NULL, /* exit thread */ | |
99 NULL, /* exit process */ | |
100 NULL, /* exit master */ | |
101 NGX_MODULE_V1_PADDING | |
521 | 102 }; |
103 | |
104 | |
1136 | 105 static u_char smtp_ok[] = "235 2.0.0 OK" CRLF; |
106 | |
107 | |
521 | 108 void |
1136 | 109 ngx_mail_proxy_init(ngx_mail_session_t *s, ngx_peer_addr_t *peer) |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
110 { |
587 | 111 int keepalive; |
527 | 112 ngx_int_t rc; |
1136 | 113 ngx_mail_proxy_ctx_t *p; |
114 ngx_mail_proxy_conf_t *pcf; | |
115 ngx_mail_core_srv_conf_t *cscf; | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
116 |
587 | 117 s->connection->log->action = "connecting to upstream"; |
118 | |
1136 | 119 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
587 | 120 |
121 if (cscf->so_keepalive) { | |
122 keepalive = 1; | |
123 | |
124 if (setsockopt(s->connection->fd, SOL_SOCKET, SO_KEEPALIVE, | |
125 (const void *) &keepalive, sizeof(int)) | |
126 == -1) | |
127 { | |
128 ngx_log_error(NGX_LOG_ALERT, s->connection->log, ngx_socket_errno, | |
129 "setsockopt(SO_KEEPALIVE) failed"); | |
130 } | |
131 } | |
132 | |
1136 | 133 p = ngx_pcalloc(s->connection->pool, sizeof(ngx_mail_proxy_ctx_t)); |
501 | 134 if (p == NULL) { |
1136 | 135 ngx_mail_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
|
136 return; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
137 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
138 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
139 s->proxy = p; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
140 |
884 | 141 p->upstream.sockaddr = peer->sockaddr; |
142 p->upstream.socklen = peer->socklen; | |
143 p->upstream.name = &peer->name; | |
144 p->upstream.get = ngx_event_get_peer; | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
145 p->upstream.log = s->connection->log; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
146 p->upstream.log_error = NGX_ERROR_ERR; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
147 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
148 rc = ngx_event_connect_peer(&p->upstream); |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
149 |
543 | 150 if (rc == NGX_ERROR || rc == NGX_BUSY || rc == NGX_DECLINED) { |
1136 | 151 ngx_mail_proxy_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
|
152 return; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
153 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
154 |
527 | 155 ngx_add_timer(p->upstream.connection->read, cscf->timeout); |
156 | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
157 p->upstream.connection->data = s; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
158 p->upstream.connection->pool = s->connection->pool; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
159 |
1136 | 160 s->connection->read->handler = ngx_mail_proxy_block_read; |
161 p->upstream.connection->write->handler = ngx_mail_proxy_dummy_handler; | |
162 | |
163 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); | |
164 | |
165 s->proxy->buffer = ngx_create_temp_buf(s->connection->pool, | |
166 pcf->buffer_size); | |
167 if (s->proxy->buffer == NULL) { | |
168 ngx_mail_proxy_internal_server_error(s); | |
169 return; | |
170 } | |
171 | |
172 switch (s->protocol) { | |
527 | 173 |
1136 | 174 case NGX_MAIL_POP3_PROTOCOL: |
175 p->upstream.connection->read->handler = ngx_mail_proxy_pop3_handler; | |
176 s->mail_state = ngx_pop3_start; | |
177 break; | |
527 | 178 |
1136 | 179 case NGX_MAIL_IMAP_PROTOCOL: |
180 p->upstream.connection->read->handler = ngx_mail_proxy_imap_handler; | |
181 s->mail_state = ngx_imap_start; | |
182 break; | |
183 | |
184 default: /* NGX_MAIL_SMTP_PROTOCOL */ | |
185 p->upstream.connection->read->handler = ngx_mail_proxy_smtp_handler; | |
186 s->mail_state = ngx_smtp_start; | |
187 break; | |
527 | 188 } |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
189 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
190 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
191 |
521 | 192 static void |
1136 | 193 ngx_mail_proxy_block_read(ngx_event_t *rev) |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
194 { |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
195 ngx_connection_t *c; |
1136 | 196 ngx_mail_session_t *s; |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
197 |
1136 | 198 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy block read"); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
199 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
200 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
201 c = rev->data; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
202 s = c->data; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
203 |
1136 | 204 ngx_mail_proxy_close_session(s); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
205 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
206 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
207 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
208 |
521 | 209 static void |
1136 | 210 ngx_mail_proxy_pop3_handler(ngx_event_t *rev) |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
211 { |
539 | 212 u_char *p; |
213 ngx_int_t rc; | |
214 ngx_str_t line; | |
215 ngx_connection_t *c; | |
1136 | 216 ngx_mail_session_t *s; |
217 ngx_mail_proxy_conf_t *pcf; | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
218 |
1136 | 219 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, |
220 "mail proxy pop3 auth handler"); | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
221 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
222 c = rev->data; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
223 s = c->data; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
224 |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
225 if (rev->timedout) { |
527 | 226 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, |
227 "upstream timed out"); | |
577 | 228 c->timedout = 1; |
1136 | 229 ngx_mail_proxy_internal_server_error(s); |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
230 return; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
231 } |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
232 |
1136 | 233 rc = ngx_mail_proxy_read_response(s, 0); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
234 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
235 if (rc == NGX_AGAIN) { |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
236 return; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
237 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
238 |
571 | 239 if (rc == NGX_ERROR) { |
1136 | 240 ngx_mail_proxy_upstream_error(s); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
241 return; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
242 } |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
243 |
1136 | 244 switch (s->mail_state) { |
587 | 245 |
1136 | 246 case ngx_pop3_start: |
247 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy send user"); | |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
248 |
587 | 249 s->connection->log->action = "sending user name to upstream"; |
250 | |
1136 | 251 line.len = sizeof("USER ") - 1 + s->login.len + 2; |
527 | 252 line.data = ngx_palloc(c->pool, line.len); |
253 if (line.data == NULL) { | |
1136 | 254 ngx_mail_proxy_internal_server_error(s); |
527 | 255 return; |
256 } | |
257 | |
1136 | 258 p = ngx_cpymem(line.data, "USER ", sizeof("USER ") - 1); |
259 p = ngx_cpymem(p, s->login.data, s->login.len); | |
260 *p++ = CR; *p = LF; | |
527 | 261 |
1136 | 262 s->mail_state = ngx_pop3_user; |
527 | 263 break; |
264 | |
1136 | 265 case ngx_pop3_user: |
266 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy send pass"); | |
527 | 267 |
587 | 268 s->connection->log->action = "sending password to upstream"; |
269 | |
1136 | 270 line.len = sizeof("PASS ") - 1 + s->passwd.len + 2; |
501 | 271 line.data = ngx_palloc(c->pool, line.len); |
272 if (line.data == NULL) { | |
1136 | 273 ngx_mail_proxy_internal_server_error(s); |
527 | 274 return; |
275 } | |
276 | |
1136 | 277 p = ngx_cpymem(line.data, "PASS ", sizeof("PASS ") - 1); |
278 p = ngx_cpymem(p, s->passwd.data, s->passwd.len); | |
527 | 279 *p++ = CR; *p = LF; |
280 | |
1136 | 281 s->mail_state = ngx_pop3_passwd; |
527 | 282 break; |
283 | |
1136 | 284 case ngx_pop3_passwd: |
285 s->connection->read->handler = ngx_mail_proxy_handler; | |
286 s->connection->write->handler = ngx_mail_proxy_handler; | |
287 rev->handler = ngx_mail_proxy_handler; | |
288 c->write->handler = ngx_mail_proxy_handler; | |
663 | 289 |
1136 | 290 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); |
663 | 291 ngx_add_timer(s->connection->read, pcf->timeout); |
292 ngx_del_timer(c->read); | |
293 | |
294 c->log->action = NULL; | |
295 ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in"); | |
296 | |
1136 | 297 ngx_mail_proxy_handler(s->connection->write); |
663 | 298 |
299 return; | |
300 | |
527 | 301 default: |
302 #if (NGX_SUPPRESS_WARN) | |
303 line.len = 0; | |
304 line.data = NULL; | |
305 #endif | |
306 break; | |
307 } | |
308 | |
539 | 309 if (c->send(c, line.data, line.len) < (ssize_t) line.len) { |
527 | 310 /* |
311 * we treat the incomplete sending as NGX_ERROR | |
312 * because it is very strange here | |
313 */ | |
1136 | 314 ngx_mail_proxy_internal_server_error(s); |
527 | 315 return; |
316 } | |
317 | |
318 s->proxy->buffer->pos = s->proxy->buffer->start; | |
319 s->proxy->buffer->last = s->proxy->buffer->start; | |
320 } | |
321 | |
322 | |
323 static void | |
1136 | 324 ngx_mail_proxy_imap_handler(ngx_event_t *rev) |
527 | 325 { |
539 | 326 u_char *p; |
327 ngx_int_t rc; | |
328 ngx_str_t line; | |
329 ngx_connection_t *c; | |
1136 | 330 ngx_mail_session_t *s; |
331 ngx_mail_proxy_conf_t *pcf; | |
527 | 332 |
1136 | 333 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, |
334 "mail proxy imap auth handler"); | |
527 | 335 |
336 c = rev->data; | |
337 s = c->data; | |
338 | |
339 if (rev->timedout) { | |
340 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, | |
341 "upstream timed out"); | |
577 | 342 c->timedout = 1; |
1136 | 343 ngx_mail_proxy_internal_server_error(s); |
527 | 344 return; |
345 } | |
346 | |
1136 | 347 rc = ngx_mail_proxy_read_response(s, s->mail_state); |
527 | 348 |
349 if (rc == NGX_AGAIN) { | |
350 return; | |
351 } | |
352 | |
571 | 353 if (rc == NGX_ERROR) { |
1136 | 354 ngx_mail_proxy_upstream_error(s); |
527 | 355 return; |
356 } | |
357 | |
1136 | 358 switch (s->mail_state) { |
527 | 359 |
1136 | 360 case ngx_imap_start: |
361 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | |
362 "mail proxy send login"); | |
527 | 363 |
1136 | 364 s->connection->log->action = "sending LOGIN command to upstream"; |
587 | 365 |
1136 | 366 line.len = s->tag.len + sizeof("LOGIN ") - 1 |
367 + 1 + NGX_SIZE_T_LEN + 1 + 2; | |
527 | 368 line.data = ngx_palloc(c->pool, line.len); |
369 if (line.data == NULL) { | |
1136 | 370 ngx_mail_proxy_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
|
371 return; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
372 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
373 |
1136 | 374 line.len = ngx_sprintf(line.data, "%VLOGIN {%uz}" CRLF, |
375 &s->tag, s->login.len) | |
376 - line.data; | |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
377 |
1136 | 378 s->mail_state = ngx_imap_login; |
527 | 379 break; |
380 | |
1136 | 381 case ngx_imap_login: |
382 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy send user"); | |
383 | |
384 s->connection->log->action = "sending user name to upstream"; | |
385 | |
386 line.len = s->login.len + 1 + 1 + NGX_SIZE_T_LEN + 1 + 2; | |
387 line.data = ngx_palloc(c->pool, line.len); | |
388 if (line.data == NULL) { | |
389 ngx_mail_proxy_internal_server_error(s); | |
390 return; | |
391 } | |
392 | |
393 line.len = ngx_sprintf(line.data, "%V {%uz}" CRLF, | |
394 &s->login, s->passwd.len) | |
395 - line.data; | |
396 | |
397 s->mail_state = ngx_imap_user; | |
398 break; | |
399 | |
400 case ngx_imap_user: | |
401 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | |
402 "mail proxy send passwd"); | |
527 | 403 |
587 | 404 s->connection->log->action = "sending password to upstream"; |
405 | |
1136 | 406 line.len = s->passwd.len + 2; |
527 | 407 line.data = ngx_palloc(c->pool, line.len); |
408 if (line.data == NULL) { | |
1136 | 409 ngx_mail_proxy_internal_server_error(s); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
410 return; |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
411 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
412 |
1136 | 413 p = ngx_cpymem(line.data, s->passwd.data, s->passwd.len); |
527 | 414 *p++ = CR; *p = LF; |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
415 |
1136 | 416 s->mail_state = ngx_imap_passwd; |
527 | 417 break; |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
418 |
1136 | 419 case ngx_imap_passwd: |
420 s->connection->read->handler = ngx_mail_proxy_handler; | |
421 s->connection->write->handler = ngx_mail_proxy_handler; | |
422 rev->handler = ngx_mail_proxy_handler; | |
423 c->write->handler = ngx_mail_proxy_handler; | |
663 | 424 |
1136 | 425 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); |
663 | 426 ngx_add_timer(s->connection->read, pcf->timeout); |
427 ngx_del_timer(c->read); | |
428 | |
429 c->log->action = NULL; | |
430 ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in"); | |
431 | |
1136 | 432 ngx_mail_proxy_handler(s->connection->write); |
663 | 433 |
434 return; | |
435 | |
527 | 436 default: |
437 #if (NGX_SUPPRESS_WARN) | |
438 line.len = 0; | |
439 line.data = NULL; | |
440 #endif | |
441 break; | |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
442 } |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
443 |
539 | 444 if (c->send(c, line.data, line.len) < (ssize_t) line.len) { |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
445 /* |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
446 * we treat the incomplete sending as NGX_ERROR |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
447 * because it is very strange here |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
448 */ |
1136 | 449 ngx_mail_proxy_internal_server_error(s); |
422
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
450 return; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
451 } |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
452 |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
453 s->proxy->buffer->pos = s->proxy->buffer->start; |
edaefb2a20fc
nginx-0.0.10-2004-09-12-00:22:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
454 s->proxy->buffer->last = s->proxy->buffer->start; |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
455 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
456 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
457 |
521 | 458 static void |
1136 | 459 ngx_mail_proxy_smtp_handler(ngx_event_t *rev) |
460 { | |
461 u_char *p; | |
462 ngx_int_t rc; | |
463 ngx_str_t line; | |
464 ngx_connection_t *c; | |
465 ngx_mail_session_t *s; | |
466 ngx_mail_proxy_conf_t *pcf; | |
467 ngx_mail_core_srv_conf_t *cscf; | |
468 | |
469 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | |
470 "mail proxy smtp auth handler"); | |
471 | |
472 c = rev->data; | |
473 s = c->data; | |
474 | |
475 if (rev->timedout) { | |
476 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, | |
477 "upstream timed out"); | |
478 c->timedout = 1; | |
479 ngx_mail_proxy_internal_server_error(s); | |
480 return; | |
481 } | |
482 | |
483 rc = ngx_mail_proxy_read_response(s, s->mail_state); | |
484 | |
485 if (rc == NGX_AGAIN) { | |
486 return; | |
487 } | |
488 | |
489 if (rc == NGX_ERROR) { | |
490 ngx_mail_proxy_upstream_error(s); | |
491 return; | |
492 } | |
493 | |
494 switch (s->mail_state) { | |
495 | |
496 case ngx_smtp_start: | |
497 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy send ehlo"); | |
498 | |
499 s->connection->log->action = "sending HELO/EHLO to upstream"; | |
500 | |
501 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); | |
502 | |
503 line.len = sizeof("HELO ") - 1 + cscf->server_name.len + 2; | |
504 line.data = ngx_palloc(c->pool, line.len); | |
505 if (line.data == NULL) { | |
506 ngx_mail_proxy_internal_server_error(s); | |
507 return; | |
508 } | |
509 | |
510 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); | |
511 | |
512 p = ngx_cpymem(line.data, | |
513 ((s->esmtp || pcf->xclient) ? "EHLO " : "HELO "), | |
514 sizeof("HELO ") - 1); | |
515 | |
516 p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len); | |
517 *p++ = CR; *p = LF; | |
518 | |
519 s->mail_state = pcf->xclient ? ngx_smtp_helo: ngx_smtp_noxclient; | |
520 | |
521 break; | |
522 | |
523 case ngx_smtp_helo: | |
524 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | |
525 "mail proxy send xclient"); | |
526 | |
527 s->connection->log->action = "sending XCLIENT to upstream"; | |
528 | |
529 line.len = sizeof("XCLIENT PROTO=SMTP HELO= ADDR= LOGIN= " | |
530 "NAME=[UNAVAILABLE]" CRLF) - 1 | |
531 + s->esmtp + s->smtp_helo.len | |
532 + s->connection->addr_text.len + s->login.len; | |
533 | |
534 line.data = ngx_palloc(c->pool, line.len); | |
535 if (line.data == NULL) { | |
536 ngx_mail_proxy_internal_server_error(s); | |
537 return; | |
538 } | |
539 | |
540 if (s->smtp_helo.len) { | |
541 line.len = ngx_sprintf(line.data, | |
542 "XCLIENT PROTO=%sSMTP HELO=%V ADDR=%V LOGIN=%V " | |
543 "NAME=[UNAVAILABLE]" CRLF, | |
544 (s->esmtp ? "E" : ""), &s->smtp_helo, | |
545 &s->connection->addr_text, &s->login) | |
546 - line.data; | |
547 } else { | |
548 line.len = ngx_sprintf(line.data, | |
549 "XCLIENT PROTO=SMTP ADDR=%V LOGIN=%V " | |
550 "NAME=[UNAVAILABLE]" CRLF, | |
551 &s->connection->addr_text, &s->login) | |
552 - line.data; | |
553 } | |
554 | |
555 s->mail_state = ngx_smtp_xclient; | |
556 break; | |
557 | |
558 case ngx_smtp_noxclient: | |
559 case ngx_smtp_xclient: | |
560 | |
561 ngx_memcpy(s->proxy->buffer->start, smtp_ok, sizeof(smtp_ok) - 1); | |
562 | |
563 s->proxy->buffer->pos = s->proxy->buffer->start; | |
564 s->proxy->buffer->last = s->proxy->buffer->start + sizeof(smtp_ok) - 1; | |
565 | |
566 s->connection->read->handler = ngx_mail_proxy_handler; | |
567 s->connection->write->handler = ngx_mail_proxy_handler; | |
568 rev->handler = ngx_mail_proxy_handler; | |
569 c->write->handler = ngx_mail_proxy_handler; | |
570 | |
571 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); | |
572 ngx_add_timer(s->connection->read, pcf->timeout); | |
573 ngx_del_timer(c->read); | |
574 | |
575 c->log->action = NULL; | |
576 ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in"); | |
577 | |
578 ngx_mail_proxy_handler(s->connection->write); | |
579 | |
580 return; | |
581 | |
582 default: | |
583 #if (NGX_SUPPRESS_WARN) | |
584 line.len = 0; | |
585 line.data = NULL; | |
586 #endif | |
587 break; | |
588 } | |
589 | |
590 if (c->send(c, line.data, line.len) < (ssize_t) line.len) { | |
591 /* | |
592 * we treat the incomplete sending as NGX_ERROR | |
593 * because it is very strange here | |
594 */ | |
595 ngx_mail_proxy_internal_server_error(s); | |
596 return; | |
597 } | |
598 | |
599 s->proxy->buffer->pos = s->proxy->buffer->start; | |
600 s->proxy->buffer->last = s->proxy->buffer->start; | |
601 } | |
602 | |
603 | |
604 static void | |
605 ngx_mail_proxy_dummy_handler(ngx_event_t *wev) | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
606 { |
583 | 607 ngx_connection_t *c; |
1136 | 608 ngx_mail_session_t *s; |
583 | 609 |
1136 | 610 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, wev->log, 0, "mail proxy dummy handler"); |
583 | 611 |
612 if (ngx_handle_write_event(wev, 0) == NGX_ERROR) { | |
613 c = wev->data; | |
614 s = c->data; | |
615 | |
1136 | 616 ngx_mail_proxy_close_session(s); |
583 | 617 } |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
618 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
619 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
620 |
521 | 621 static ngx_int_t |
1136 | 622 ngx_mail_proxy_read_response(ngx_mail_session_t *s, ngx_uint_t state) |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
623 { |
857 | 624 u_char *p; |
625 ssize_t n; | |
626 ngx_buf_t *b; | |
1136 | 627 ngx_mail_proxy_conf_t *pcf; |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
628 |
587 | 629 s->connection->log->action = "reading response from upstream"; |
630 | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
631 b = s->proxy->buffer; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
632 |
539 | 633 n = s->proxy->upstream.connection->recv(s->proxy->upstream.connection, |
634 b->last, b->end - b->last); | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
635 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
636 if (n == NGX_ERROR || n == 0) { |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
637 return NGX_ERROR; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
638 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
639 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
640 if (n == NGX_AGAIN) { |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
641 return NGX_AGAIN; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
642 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
643 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
644 b->last += n; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
645 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
646 if (b->last - b->pos < 5) { |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
647 return NGX_AGAIN; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
648 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
649 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
650 if (*(b->last - 2) != CR || *(b->last - 1) != LF) { |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
651 if (b->last == b->end) { |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
652 *(b->last - 1) = '\0'; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
653 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
654 "upstream sent too long response line: \"%s\"", |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
655 b->pos); |
571 | 656 return NGX_ERROR; |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
657 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
658 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
659 return NGX_AGAIN; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
660 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
661 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
662 p = b->pos; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
663 |
1136 | 664 switch (s->protocol) { |
665 | |
666 case NGX_MAIL_POP3_PROTOCOL: | |
527 | 667 if (p[0] == '+' && p[1] == 'O' && p[2] == 'K') { |
668 return NGX_OK; | |
669 } | |
1136 | 670 break; |
527 | 671 |
1136 | 672 case NGX_MAIL_IMAP_PROTOCOL: |
663 | 673 switch (state) { |
674 | |
675 case ngx_imap_start: | |
527 | 676 if (p[0] == '*' && p[1] == ' ' && p[2] == 'O' && p[3] == 'K') { |
677 return NGX_OK; | |
678 } | |
663 | 679 break; |
527 | 680 |
663 | 681 case ngx_imap_login: |
682 case ngx_imap_user: | |
529 | 683 if (p[0] == '+') { |
527 | 684 return NGX_OK; |
685 } | |
663 | 686 break; |
687 | |
688 case ngx_imap_passwd: | |
689 if (ngx_strncmp(p, s->tag.data, s->tag.len) == 0) { | |
690 p += s->tag.len; | |
691 if (p[0] == 'O' && p[1] == 'K') { | |
692 return NGX_OK; | |
693 } | |
694 } | |
695 break; | |
527 | 696 } |
1136 | 697 |
698 break; | |
699 | |
700 default: /* NGX_MAIL_SMTP_PROTOCOL */ | |
701 switch (state) { | |
702 | |
703 case ngx_smtp_helo: | |
704 case ngx_smtp_noxclient: | |
1166 | 705 if (p[0] == '2' && p[1] == '5' && p[2] == '0') { |
706 return NGX_OK; | |
707 } | |
708 break; | |
1136 | 709 |
710 case ngx_smtp_start: | |
711 case ngx_smtp_xclient: | |
1166 | 712 if (p[0] == '2' && p[1] == '2' && p[2] == '0') { |
713 return NGX_OK; | |
714 } | |
715 break; | |
1136 | 716 } |
717 | |
1166 | 718 break; |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
719 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
720 |
1136 | 721 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); |
857 | 722 |
723 if (pcf->pass_error_message == 0) { | |
724 *(b->last - 2) = '\0'; | |
725 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, | |
726 "upstream sent invalid response: \"%s\"", p); | |
727 return NGX_ERROR; | |
728 } | |
729 | |
730 s->out.len = b->last - p - 2; | |
731 s->out.data = p; | |
732 | |
733 ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, | |
734 "upstream sent invalid response: \"%V\"", &s->out); | |
735 | |
736 s->out.len = b->last - b->pos; | |
737 s->out.data = b->pos; | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
738 |
571 | 739 return NGX_ERROR; |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
740 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
741 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
742 |
521 | 743 static void |
1136 | 744 ngx_mail_proxy_handler(ngx_event_t *ev) |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
745 { |
583 | 746 char *action, *recv_action, *send_action; |
539 | 747 size_t size; |
748 ssize_t n; | |
749 ngx_buf_t *b; | |
583 | 750 ngx_uint_t do_write; |
539 | 751 ngx_connection_t *c, *src, *dst; |
1136 | 752 ngx_mail_session_t *s; |
753 ngx_mail_proxy_conf_t *pcf; | |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
754 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
755 c = ev->data; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
756 s = c->data; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
757 |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
758 if (ev->timedout) { |
583 | 759 c->log->action = "proxying"; |
760 | |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
761 if (c == s->connection) { |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
762 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
763 "client timed out"); |
577 | 764 c->timedout = 1; |
765 | |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
766 } else { |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
767 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
768 "upstream timed out"); |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
769 } |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
770 |
1136 | 771 ngx_mail_proxy_close_session(s); |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
772 return; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
773 } |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
774 |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
775 if (c == s->connection) { |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
776 if (ev->write) { |
583 | 777 recv_action = "proxying and reading from upstream"; |
778 send_action = "proxying and sending to client"; | |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
779 src = s->proxy->upstream.connection; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
780 dst = c; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
781 b = s->proxy->buffer; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
782 |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
783 } else { |
583 | 784 recv_action = "proxying and reading from client"; |
785 send_action = "proxying and sending to upstream"; | |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
786 src = c; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
787 dst = s->proxy->upstream.connection; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
788 b = s->buffer; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
789 } |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
790 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
791 } else { |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
792 if (ev->write) { |
589 | 793 recv_action = "proxying and reading from client"; |
794 send_action = "proxying and sending to upstream"; | |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
795 src = s->connection; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
796 dst = c; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
797 b = s->buffer; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
798 |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
799 } else { |
589 | 800 recv_action = "proxying and reading from upstream"; |
801 send_action = "proxying and sending to client"; | |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
802 src = c; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
803 dst = s->connection; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
804 b = s->proxy->buffer; |
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
805 } |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
806 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
807 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
808 do_write = ev->write ? 1 : 0; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
809 |
1136 | 810 ngx_log_debug3(NGX_LOG_DEBUG_MAIL, ev->log, 0, |
811 "mail proxy handler: %d, #%d > #%d", | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
812 do_write, src->fd, dst->fd); |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
813 |
583 | 814 for ( ;; ) { |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
815 |
583 | 816 if (do_write) { |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
817 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
818 size = b->last - b->pos; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
819 |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
820 if (size && dst->write->ready) { |
583 | 821 c->log->action = send_action; |
822 | |
539 | 823 n = dst->send(dst, b->pos, size); |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
824 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
825 if (n == NGX_ERROR) { |
1136 | 826 ngx_mail_proxy_close_session(s); |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
827 return; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
828 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
829 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
830 if (n > 0) { |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
831 b->pos += n; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
832 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
833 if (b->pos == b->last) { |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
834 b->pos = b->start; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
835 b->last = b->start; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
836 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
837 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
838 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
839 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
840 |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
841 size = b->end - b->last; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
842 |
423
fda5987b188d
nginx-0.0.10-2004-09-13-20:18:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
422
diff
changeset
|
843 if (size && src->read->ready) { |
583 | 844 c->log->action = recv_action; |
845 | |
539 | 846 n = src->recv(src, b->last, size); |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
847 |
583 | 848 if (n == NGX_AGAIN || n == 0) { |
849 break; | |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
850 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
851 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
852 if (n > 0) { |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
853 do_write = 1; |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
854 b->last += n; |
583 | 855 |
856 continue; | |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
857 } |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
858 |
583 | 859 if (n == NGX_ERROR) { |
860 src->read->eof = 1; | |
539 | 861 } |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
862 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
863 |
583 | 864 break; |
865 } | |
866 | |
867 c->log->action = "proxying"; | |
868 | |
1342
be2e13691c60
fix case when client has closed connection but upstream buffer is not empty
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
869 if ((s->connection->read->eof && s->buffer->pos == s->buffer->last) |
be2e13691c60
fix case when client has closed connection but upstream buffer is not empty
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
870 || (s->proxy->upstream.connection->read->eof |
be2e13691c60
fix case when client has closed connection but upstream buffer is not empty
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
871 && s->proxy->buffer->pos == s->proxy->buffer->last) |
be2e13691c60
fix case when client has closed connection but upstream buffer is not empty
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
872 || (s->connection->read->eof |
be2e13691c60
fix case when client has closed connection but upstream buffer is not empty
Igor Sysoev <igor@sysoev.ru>
parents:
1166
diff
changeset
|
873 && s->proxy->upstream.connection->read->eof)) |
583 | 874 { |
875 action = c->log->action; | |
876 c->log->action = NULL; | |
877 ngx_log_error(NGX_LOG_INFO, c->log, 0, "proxied session done"); | |
878 c->log->action = action; | |
879 | |
1136 | 880 ngx_mail_proxy_close_session(s); |
583 | 881 return; |
882 } | |
883 | |
884 if (ngx_handle_write_event(dst->write, 0) == NGX_ERROR) { | |
1136 | 885 ngx_mail_proxy_close_session(s); |
583 | 886 return; |
887 } | |
888 | |
889 if (ngx_handle_read_event(dst->read, 0) == NGX_ERROR) { | |
1136 | 890 ngx_mail_proxy_close_session(s); |
583 | 891 return; |
892 } | |
893 | |
894 if (ngx_handle_write_event(src->write, 0) == NGX_ERROR) { | |
1136 | 895 ngx_mail_proxy_close_session(s); |
583 | 896 return; |
897 } | |
898 | |
899 if (ngx_handle_read_event(src->read, 0) == NGX_ERROR) { | |
1136 | 900 ngx_mail_proxy_close_session(s); |
583 | 901 return; |
902 } | |
903 | |
904 if (c == s->connection) { | |
1136 | 905 pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module); |
583 | 906 ngx_add_timer(c->read, pcf->timeout); |
907 } | |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
908 } |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
909 |
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
910 |
521 | 911 static void |
1136 | 912 ngx_mail_proxy_upstream_error(ngx_mail_session_t *s) |
857 | 913 { |
914 if (s->proxy->upstream.connection) { | |
1136 | 915 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, s->connection->log, 0, |
916 "close mail proxy connection: %d", | |
857 | 917 s->proxy->upstream.connection->fd); |
918 | |
919 ngx_close_connection(s->proxy->upstream.connection); | |
920 } | |
921 | |
922 if (s->out.len == 0) { | |
1136 | 923 ngx_mail_session_internal_server_error(s); |
857 | 924 return; |
925 } | |
926 | |
927 s->quit = 1; | |
1136 | 928 ngx_mail_send(s->connection->write); |
857 | 929 } |
930 | |
931 | |
932 static void | |
1136 | 933 ngx_mail_proxy_internal_server_error(ngx_mail_session_t *s) |
527 | 934 { |
935 if (s->proxy->upstream.connection) { | |
1136 | 936 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, s->connection->log, 0, |
937 "close mail proxy connection: %d", | |
527 | 938 s->proxy->upstream.connection->fd); |
939 | |
940 ngx_close_connection(s->proxy->upstream.connection); | |
941 } | |
942 | |
1136 | 943 ngx_mail_session_internal_server_error(s); |
527 | 944 } |
945 | |
946 | |
947 static void | |
1136 | 948 ngx_mail_proxy_close_session(ngx_mail_session_t *s) |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
949 { |
521 | 950 if (s->proxy->upstream.connection) { |
1136 | 951 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, s->connection->log, 0, |
952 "close mail proxy connection: %d", | |
521 | 953 s->proxy->upstream.connection->fd); |
954 | |
955 ngx_close_connection(s->proxy->upstream.connection); | |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
956 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
418
diff
changeset
|
957 |
1136 | 958 ngx_mail_close_connection(s->connection); |
418
cf072d26d6d6
nginx-0.0.10-2004-09-08-09:18:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
959 } |
521 | 960 |
961 | |
962 static void * | |
1136 | 963 ngx_mail_proxy_create_conf(ngx_conf_t *cf) |
577 | 964 { |
1136 | 965 ngx_mail_proxy_conf_t *pcf; |
577 | 966 |
1136 | 967 pcf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_proxy_conf_t)); |
521 | 968 if (pcf == NULL) { |
969 return NGX_CONF_ERROR; | |
970 } | |
971 | |
972 pcf->enable = NGX_CONF_UNSET; | |
857 | 973 pcf->pass_error_message = NGX_CONF_UNSET; |
1136 | 974 pcf->xclient = NGX_CONF_UNSET; |
539 | 975 pcf->buffer_size = NGX_CONF_UNSET_SIZE; |
976 pcf->timeout = NGX_CONF_UNSET_MSEC; | |
521 | 977 |
978 return pcf; | |
979 } | |
980 | |
981 | |
982 static char * | |
1136 | 983 ngx_mail_proxy_merge_conf(ngx_conf_t *cf, void *parent, void *child) |
521 | 984 { |
1136 | 985 ngx_mail_proxy_conf_t *prev = parent; |
986 ngx_mail_proxy_conf_t *conf = child; | |
521 | 987 |
539 | 988 ngx_conf_merge_value(conf->enable, prev->enable, 0); |
857 | 989 ngx_conf_merge_value(conf->pass_error_message, prev->pass_error_message, 0); |
1136 | 990 ngx_conf_merge_value(conf->xclient, prev->xclient, 1); |
539 | 991 ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size, |
992 (size_t) ngx_pagesize); | |
993 ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 24 * 60 * 60000); | |
521 | 994 |
995 return NGX_CONF_OK; | |
996 } |