aboutsummaryrefslogtreecommitdiff
path: root/src/imap/ngx_imap_proxy_module.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2005-12-07 14:51:31 +0000
committerIgor Sysoev <igor@sysoev.ru>2005-12-07 14:51:31 +0000
commitcdc463042b9406e4703d21202bc363e86321bb5d (patch)
tree1f6d050377dafbf42bb3d7c8c7e15e86939500ff /src/imap/ngx_imap_proxy_module.c
parentc20f0c28ff5478dcafd2ce2e5056da3757eb62ff (diff)
downloadnginx-cdc463042b9406e4703d21202bc363e86321bb5d.tar.gz
nginx-cdc463042b9406e4703d21202bc363e86321bb5d.zip
nginx-0.3.15-RELEASE importrelease-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.
Diffstat (limited to 'src/imap/ngx_imap_proxy_module.c')
-rw-r--r--src/imap/ngx_imap_proxy_module.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/imap/ngx_imap_proxy_module.c b/src/imap/ngx_imap_proxy_module.c
index bdce364b9..7eb1b947b 100644
--- a/src/imap/ngx_imap_proxy_module.c
+++ b/src/imap/ngx_imap_proxy_module.c
@@ -91,10 +91,27 @@ ngx_module_t ngx_imap_proxy_module = {
void
ngx_imap_proxy_init(ngx_imap_session_t *s, ngx_peers_t *peers)
{
+ int keepalive;
ngx_int_t rc;
ngx_imap_proxy_ctx_t *p;
ngx_imap_core_srv_conf_t *cscf;
+ s->connection->log->action = "connecting to upstream";
+
+ cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module);
+
+ if (cscf->so_keepalive) {
+ keepalive = 1;
+
+ if (setsockopt(s->connection->fd, SOL_SOCKET, SO_KEEPALIVE,
+ (const void *) &keepalive, sizeof(int))
+ == -1)
+ {
+ ngx_log_error(NGX_LOG_ALERT, s->connection->log, ngx_socket_errno,
+ "setsockopt(SO_KEEPALIVE) failed");
+ }
+ }
+
p = ngx_pcalloc(s->connection->pool, sizeof(ngx_imap_proxy_ctx_t));
if (p == NULL) {
ngx_imap_session_internal_server_error(s);
@@ -107,8 +124,6 @@ ngx_imap_proxy_init(ngx_imap_session_t *s, ngx_peers_t *peers)
p->upstream.log = s->connection->log;
p->upstream.log_error = NGX_ERROR_ERR;
- s->connection->log->action = "in upstream auth state";
-
rc = ngx_event_connect_peer(&p->upstream);
if (rc == NGX_ERROR || rc == NGX_BUSY || rc == NGX_DECLINED) {
@@ -116,7 +131,6 @@ ngx_imap_proxy_init(ngx_imap_session_t *s, ngx_peers_t *peers)
return;
}
- cscf = ngx_imap_get_module_srv_conf(s, ngx_imap_core_module);
ngx_add_timer(p->upstream.connection->read, cscf->timeout);
p->upstream.connection->data = s;
@@ -205,6 +219,8 @@ ngx_imap_proxy_imap_handler(ngx_event_t *rev)
ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0,
"imap proxy send login");
+ s->connection->log->action = "sending LOGIN command to upstream";
+
line.len = s->tag.len + sizeof("LOGIN ") - 1
+ 1 + NGX_SIZE_T_LEN + 1 + 2;
line.data = ngx_palloc(c->pool, line.len);
@@ -223,6 +239,8 @@ ngx_imap_proxy_imap_handler(ngx_event_t *rev)
case ngx_imap_login:
ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send user");
+ s->connection->log->action = "sending user name to upstream";
+
line.len = s->login.len + 1 + 1 + NGX_SIZE_T_LEN + 1 + 2;
line.data = ngx_palloc(c->pool, line.len);
if (line.data == NULL) {
@@ -241,6 +259,8 @@ ngx_imap_proxy_imap_handler(ngx_event_t *rev)
ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0,
"imap proxy send passwd");
+ s->connection->log->action = "sending password to upstream";
+
line.len = s->passwd.len + 2;
line.data = ngx_palloc(c->pool, line.len);
if (line.data == NULL) {
@@ -340,6 +360,8 @@ ngx_imap_proxy_pop3_handler(ngx_event_t *rev)
case ngx_pop3_start:
ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send user");
+ s->connection->log->action = "sending user name to upstream";
+
line.len = sizeof("USER ") - 1 + s->login.len + 2;
line.data = ngx_palloc(c->pool, line.len);
if (line.data == NULL) {
@@ -357,6 +379,8 @@ ngx_imap_proxy_pop3_handler(ngx_event_t *rev)
case ngx_pop3_user:
ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send pass");
+ s->connection->log->action = "sending password to upstream";
+
line.len = sizeof("PASS ") - 1 + s->passwd.len + 2;
line.data = ngx_palloc(c->pool, line.len);
if (line.data == NULL) {
@@ -431,6 +455,8 @@ ngx_imap_proxy_read_response(ngx_imap_session_t *s, ngx_uint_t what)
ssize_t n;
ngx_buf_t *b;
+ s->connection->log->action = "reading response from upstream";
+
b = s->proxy->buffer;
n = s->proxy->upstream.connection->recv(s->proxy->upstream.connection,