Mercurial > hg > nginx-vendor-current
comparison src/imap/ngx_imap_proxy_module.c @ 136:3656228c0b56 NGINX_0_3_15
nginx 0.3.15
*) Feature: the new 444 code of the "return" directive to close
connection.
*) Feature: the "so_keepalive" directive in IMAP/POP3 proxy.
*) Bugfix: if there are unclosed connection nginx now calls abort()
only on gracefull quit and active "debug_points" directive.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Wed, 07 Dec 2005 00:00:00 +0300 |
parents | 91372f004adf |
children | 8e6d4d96ec4c |
comparison
equal
deleted
inserted
replaced
135:c1ac76c0e9df | 136:3656228c0b56 |
---|---|
89 | 89 |
90 | 90 |
91 void | 91 void |
92 ngx_imap_proxy_init(ngx_imap_session_t *s, ngx_peers_t *peers) | 92 ngx_imap_proxy_init(ngx_imap_session_t *s, ngx_peers_t *peers) |
93 { | 93 { |
94 int keepalive; | |
94 ngx_int_t rc; | 95 ngx_int_t rc; |
95 ngx_imap_proxy_ctx_t *p; | 96 ngx_imap_proxy_ctx_t *p; |
96 ngx_imap_core_srv_conf_t *cscf; | 97 ngx_imap_core_srv_conf_t *cscf; |
97 | 98 |
99 s->connection->log->action = "connecting to upstream"; | |
100 | |
101 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module); | |
102 | |
103 if (cscf->so_keepalive) { | |
104 keepalive = 1; | |
105 | |
106 if (setsockopt(s->connection->fd, SOL_SOCKET, SO_KEEPALIVE, | |
107 (const void *) &keepalive, sizeof(int)) | |
108 == -1) | |
109 { | |
110 ngx_log_error(NGX_LOG_ALERT, s->connection->log, ngx_socket_errno, | |
111 "setsockopt(SO_KEEPALIVE) failed"); | |
112 } | |
113 } | |
114 | |
98 p = ngx_pcalloc(s->connection->pool, sizeof(ngx_imap_proxy_ctx_t)); | 115 p = ngx_pcalloc(s->connection->pool, sizeof(ngx_imap_proxy_ctx_t)); |
99 if (p == NULL) { | 116 if (p == NULL) { |
100 ngx_imap_session_internal_server_error(s); | 117 ngx_imap_session_internal_server_error(s); |
101 return; | 118 return; |
102 } | 119 } |
105 | 122 |
106 p->upstream.peers = peers; | 123 p->upstream.peers = peers; |
107 p->upstream.log = s->connection->log; | 124 p->upstream.log = s->connection->log; |
108 p->upstream.log_error = NGX_ERROR_ERR; | 125 p->upstream.log_error = NGX_ERROR_ERR; |
109 | 126 |
110 s->connection->log->action = "in upstream auth state"; | |
111 | |
112 rc = ngx_event_connect_peer(&p->upstream); | 127 rc = ngx_event_connect_peer(&p->upstream); |
113 | 128 |
114 if (rc == NGX_ERROR || rc == NGX_BUSY || rc == NGX_DECLINED) { | 129 if (rc == NGX_ERROR || rc == NGX_BUSY || rc == NGX_DECLINED) { |
115 ngx_imap_proxy_internal_server_error(s); | 130 ngx_imap_proxy_internal_server_error(s); |
116 return; | 131 return; |
117 } | 132 } |
118 | 133 |
119 cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module); | |
120 ngx_add_timer(p->upstream.connection->read, cscf->timeout); | 134 ngx_add_timer(p->upstream.connection->read, cscf->timeout); |
121 | 135 |
122 p->upstream.connection->data = s; | 136 p->upstream.connection->data = s; |
123 p->upstream.connection->pool = s->connection->pool; | 137 p->upstream.connection->pool = s->connection->pool; |
124 | 138 |
203 | 217 |
204 case ngx_imap_start: | 218 case ngx_imap_start: |
205 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, | 219 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, |
206 "imap proxy send login"); | 220 "imap proxy send login"); |
207 | 221 |
222 s->connection->log->action = "sending LOGIN command to upstream"; | |
223 | |
208 line.len = s->tag.len + sizeof("LOGIN ") - 1 | 224 line.len = s->tag.len + sizeof("LOGIN ") - 1 |
209 + 1 + NGX_SIZE_T_LEN + 1 + 2; | 225 + 1 + NGX_SIZE_T_LEN + 1 + 2; |
210 line.data = ngx_palloc(c->pool, line.len); | 226 line.data = ngx_palloc(c->pool, line.len); |
211 if (line.data == NULL) { | 227 if (line.data == NULL) { |
212 ngx_imap_proxy_internal_server_error(s); | 228 ngx_imap_proxy_internal_server_error(s); |
221 break; | 237 break; |
222 | 238 |
223 case ngx_imap_login: | 239 case ngx_imap_login: |
224 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send user"); | 240 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send user"); |
225 | 241 |
242 s->connection->log->action = "sending user name to upstream"; | |
243 | |
226 line.len = s->login.len + 1 + 1 + NGX_SIZE_T_LEN + 1 + 2; | 244 line.len = s->login.len + 1 + 1 + NGX_SIZE_T_LEN + 1 + 2; |
227 line.data = ngx_palloc(c->pool, line.len); | 245 line.data = ngx_palloc(c->pool, line.len); |
228 if (line.data == NULL) { | 246 if (line.data == NULL) { |
229 ngx_imap_proxy_internal_server_error(s); | 247 ngx_imap_proxy_internal_server_error(s); |
230 return; | 248 return; |
238 break; | 256 break; |
239 | 257 |
240 case ngx_imap_user: | 258 case ngx_imap_user: |
241 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, | 259 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, |
242 "imap proxy send passwd"); | 260 "imap proxy send passwd"); |
261 | |
262 s->connection->log->action = "sending password to upstream"; | |
243 | 263 |
244 line.len = s->passwd.len + 2; | 264 line.len = s->passwd.len + 2; |
245 line.data = ngx_palloc(c->pool, line.len); | 265 line.data = ngx_palloc(c->pool, line.len); |
246 if (line.data == NULL) { | 266 if (line.data == NULL) { |
247 ngx_imap_proxy_internal_server_error(s); | 267 ngx_imap_proxy_internal_server_error(s); |
338 switch (s->imap_state) { | 358 switch (s->imap_state) { |
339 | 359 |
340 case ngx_pop3_start: | 360 case ngx_pop3_start: |
341 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send user"); | 361 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send user"); |
342 | 362 |
363 s->connection->log->action = "sending user name to upstream"; | |
364 | |
343 line.len = sizeof("USER ") - 1 + s->login.len + 2; | 365 line.len = sizeof("USER ") - 1 + s->login.len + 2; |
344 line.data = ngx_palloc(c->pool, line.len); | 366 line.data = ngx_palloc(c->pool, line.len); |
345 if (line.data == NULL) { | 367 if (line.data == NULL) { |
346 ngx_imap_proxy_internal_server_error(s); | 368 ngx_imap_proxy_internal_server_error(s); |
347 return; | 369 return; |
354 s->imap_state = ngx_pop3_user; | 376 s->imap_state = ngx_pop3_user; |
355 break; | 377 break; |
356 | 378 |
357 case ngx_pop3_user: | 379 case ngx_pop3_user: |
358 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send pass"); | 380 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send pass"); |
381 | |
382 s->connection->log->action = "sending password to upstream"; | |
359 | 383 |
360 line.len = sizeof("PASS ") - 1 + s->passwd.len + 2; | 384 line.len = sizeof("PASS ") - 1 + s->passwd.len + 2; |
361 line.data = ngx_palloc(c->pool, line.len); | 385 line.data = ngx_palloc(c->pool, line.len); |
362 if (line.data == NULL) { | 386 if (line.data == NULL) { |
363 ngx_imap_proxy_internal_server_error(s); | 387 ngx_imap_proxy_internal_server_error(s); |
428 ngx_imap_proxy_read_response(ngx_imap_session_t *s, ngx_uint_t what) | 452 ngx_imap_proxy_read_response(ngx_imap_session_t *s, ngx_uint_t what) |
429 { | 453 { |
430 u_char *p; | 454 u_char *p; |
431 ssize_t n; | 455 ssize_t n; |
432 ngx_buf_t *b; | 456 ngx_buf_t *b; |
457 | |
458 s->connection->log->action = "reading response from upstream"; | |
433 | 459 |
434 b = s->proxy->buffer; | 460 b = s->proxy->buffer; |
435 | 461 |
436 n = s->proxy->upstream.connection->recv(s->proxy->upstream.connection, | 462 n = s->proxy->upstream.connection->recv(s->proxy->upstream.connection, |
437 b->last, b->end - b->last); | 463 b->last, b->end - b->last); |