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