diff options
author | Igor Sysoev <igor@sysoev.ru> | 2005-12-07 14:51:31 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2005-12-07 14:51:31 +0000 |
commit | cdc463042b9406e4703d21202bc363e86321bb5d (patch) | |
tree | 1f6d050377dafbf42bb3d7c8c7e15e86939500ff /src/imap | |
parent | c20f0c28ff5478dcafd2ce2e5056da3757eb62ff (diff) | |
download | nginx-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')
-rw-r--r-- | src/imap/ngx_imap.h | 2 | ||||
-rw-r--r-- | src/imap/ngx_imap_core_module.c | 11 | ||||
-rw-r--r-- | src/imap/ngx_imap_proxy_module.c | 32 |
3 files changed, 41 insertions, 4 deletions
diff --git a/src/imap/ngx_imap.h b/src/imap/ngx_imap.h index 1f3c12eea..90375bfb2 100644 --- a/src/imap/ngx_imap.h +++ b/src/imap/ngx_imap.h @@ -40,6 +40,8 @@ typedef struct { ngx_uint_t protocol; + ngx_flag_t so_keepalive; + ngx_str_t pop3_capability; ngx_str_t pop3_starttls_capability; ngx_str_t imap_capability; diff --git a/src/imap/ngx_imap_core_module.c b/src/imap/ngx_imap_core_module.c index e805a8161..44484acc8 100644 --- a/src/imap/ngx_imap_core_module.c +++ b/src/imap/ngx_imap_core_module.c @@ -75,6 +75,13 @@ static ngx_command_t ngx_imap_core_commands[] = { offsetof(ngx_imap_core_srv_conf_t, imap_client_buffer_size), NULL }, + { ngx_string("so_keepalive"), + NGX_IMAP_MAIN_CONF|NGX_IMAP_SRV_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_IMAP_SRV_CONF_OFFSET, + offsetof(ngx_imap_core_srv_conf_t, so_keepalive), + NULL }, + { ngx_string("timeout"), NGX_IMAP_MAIN_CONF|NGX_IMAP_SRV_CONF|NGX_CONF_TAKE1, ngx_conf_set_msec_slot, @@ -156,8 +163,9 @@ ngx_imap_core_create_srv_conf(ngx_conf_t *cf) } cscf->imap_client_buffer_size = NGX_CONF_UNSET_SIZE; - cscf->timeout = NGX_CONF_UNSET_MSEC; cscf->protocol = NGX_CONF_UNSET_UINT; + cscf->timeout = NGX_CONF_UNSET_MSEC; + cscf->so_keepalive = NGX_CONF_UNSET; if (ngx_array_init(&cscf->pop3_capabilities, cf->pool, 4, sizeof(ngx_str_t)) != NGX_OK) @@ -192,6 +200,7 @@ ngx_imap_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000); ngx_conf_merge_unsigned_value(conf->protocol, prev->protocol, NGX_IMAP_IMAP_PROTOCOL); + ngx_conf_merge_value(conf->so_keepalive, prev->so_keepalive, 0); if (conf->pop3_capabilities.nelts == 0) { 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, |