aboutsummaryrefslogtreecommitdiff
path: root/src/imap/ngx_imap_proxy_module.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2006-07-07 16:33:19 +0000
committerIgor Sysoev <igor@sysoev.ru>2006-07-07 16:33:19 +0000
commit1765f475445a054994611d2053cc181fb3504615 (patch)
treea816e7cada7b3bec35e866ee9b22f78bda6c5af8 /src/imap/ngx_imap_proxy_module.c
parentb798d507122449c1baa85b1de47eec31cc0487a6 (diff)
downloadnginx-release-0.3.53.tar.gz
nginx-release-0.3.53.zip
nginx-0.3.53-RELEASE importrelease-0.3.53
*) Change: the "add_header" directive adds the string to 204, 301, and 302 responses. *) Feature: the "server" directive in the "upstream" context supports the "weight" parameter. *) Feature: the "server_name" directive supports the "*" wildcard. *) Feature: nginx supports the request body size more than 2G. *) Bugfix: if a client was successfully authorized using "satisfy_any on", then anyway the message "access forbidden by rule" was written in the log. *) Bugfix: the "PUT" method may erroneously not create a file and return the 409 code. *) Bugfix: if the IMAP/POP3 backend returned an error, then nginx continued proxying anyway.
Diffstat (limited to 'src/imap/ngx_imap_proxy_module.c')
-rw-r--r--src/imap/ngx_imap_proxy_module.c93
1 files changed, 54 insertions, 39 deletions
diff --git a/src/imap/ngx_imap_proxy_module.c b/src/imap/ngx_imap_proxy_module.c
index 97df3825b..6ab225b0c 100644
--- a/src/imap/ngx_imap_proxy_module.c
+++ b/src/imap/ngx_imap_proxy_module.c
@@ -23,7 +23,7 @@ static void ngx_imap_proxy_imap_handler(ngx_event_t *rev);
static void ngx_imap_proxy_pop3_handler(ngx_event_t *rev);
static void ngx_imap_proxy_dummy_handler(ngx_event_t *ev);
static ngx_int_t ngx_imap_proxy_read_response(ngx_imap_session_t *s,
- ngx_uint_t what);
+ ngx_uint_t state);
static void ngx_imap_proxy_handler(ngx_event_t *ev);
static void ngx_imap_proxy_internal_server_error(ngx_imap_session_t *s);
static void ngx_imap_proxy_close_session(ngx_imap_session_t *s);
@@ -32,10 +32,6 @@ static char *ngx_imap_proxy_merge_conf(ngx_conf_t *cf, void *parent,
void *child);
-#define NGX_IMAP_WAIT_OK 0
-#define NGX_IMAP_WAIT_NEXT 1
-
-
static ngx_command_t ngx_imap_proxy_commands[] = {
{ ngx_string("proxy"),
@@ -201,8 +197,7 @@ ngx_imap_proxy_imap_handler(ngx_event_t *rev)
}
}
- rc = ngx_imap_proxy_read_response(s, s->imap_state == ngx_imap_start ?
- NGX_IMAP_WAIT_OK : NGX_IMAP_WAIT_NEXT);
+ rc = ngx_imap_proxy_read_response(s, s->imap_state);
if (rc == NGX_AGAIN) {
return;
@@ -274,6 +269,23 @@ ngx_imap_proxy_imap_handler(ngx_event_t *rev)
s->imap_state = ngx_imap_passwd;
break;
+ case ngx_imap_passwd:
+ s->connection->read->handler = ngx_imap_proxy_handler;
+ s->connection->write->handler = ngx_imap_proxy_handler;
+ rev->handler = ngx_imap_proxy_handler;
+ c->write->handler = ngx_imap_proxy_handler;
+
+ pcf = ngx_imap_get_module_srv_conf(s, ngx_imap_proxy_module);
+ ngx_add_timer(s->connection->read, pcf->timeout);
+ ngx_del_timer(c->read);
+
+ c->log->action = NULL;
+ ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in");
+
+ ngx_imap_proxy_handler(s->connection->write);
+
+ return;
+
default:
#if (NGX_SUPPRESS_WARN)
line.len = 0;
@@ -293,20 +305,6 @@ ngx_imap_proxy_imap_handler(ngx_event_t *rev)
s->proxy->buffer->pos = s->proxy->buffer->start;
s->proxy->buffer->last = s->proxy->buffer->start;
-
- if (s->imap_state == ngx_imap_passwd) {
- s->connection->read->handler = ngx_imap_proxy_handler;
- s->connection->write->handler = ngx_imap_proxy_handler;
- rev->handler = ngx_imap_proxy_handler;
- c->write->handler = ngx_imap_proxy_handler;
-
- pcf = ngx_imap_get_module_srv_conf(s, ngx_imap_proxy_module);
- ngx_add_timer(s->connection->read, pcf->timeout);
- ngx_del_timer(c->read);
-
- c->log->action = NULL;
- ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in");
- }
}
@@ -344,7 +342,7 @@ ngx_imap_proxy_pop3_handler(ngx_event_t *rev)
}
}
- rc = ngx_imap_proxy_read_response(s, NGX_IMAP_WAIT_OK);
+ rc = ngx_imap_proxy_read_response(s, 0);
if (rc == NGX_AGAIN) {
return;
@@ -395,6 +393,23 @@ ngx_imap_proxy_pop3_handler(ngx_event_t *rev)
s->imap_state = ngx_pop3_passwd;
break;
+ case ngx_pop3_passwd:
+ s->connection->read->handler = ngx_imap_proxy_handler;
+ s->connection->write->handler = ngx_imap_proxy_handler;
+ rev->handler = ngx_imap_proxy_handler;
+ c->write->handler = ngx_imap_proxy_handler;
+
+ pcf = ngx_imap_get_module_srv_conf(s, ngx_imap_proxy_module);
+ ngx_add_timer(s->connection->read, pcf->timeout);
+ ngx_del_timer(c->read);
+
+ c->log->action = NULL;
+ ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in");
+
+ ngx_imap_proxy_handler(s->connection->write);
+
+ return;
+
default:
#if (NGX_SUPPRESS_WARN)
line.len = 0;
@@ -414,20 +429,6 @@ ngx_imap_proxy_pop3_handler(ngx_event_t *rev)
s->proxy->buffer->pos = s->proxy->buffer->start;
s->proxy->buffer->last = s->proxy->buffer->start;
-
- if (s->imap_state == ngx_pop3_passwd) {
- s->connection->read->handler = ngx_imap_proxy_handler;
- s->connection->write->handler = ngx_imap_proxy_handler;
- rev->handler = ngx_imap_proxy_handler;
- c->write->handler = ngx_imap_proxy_handler;
-
- pcf = ngx_imap_get_module_srv_conf(s, ngx_imap_proxy_module);
- ngx_add_timer(s->connection->read, pcf->timeout);
- ngx_del_timer(c->read);
-
- c->log->action = NULL;
- ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in");
- }
}
@@ -449,7 +450,7 @@ ngx_imap_proxy_dummy_handler(ngx_event_t *wev)
static ngx_int_t
-ngx_imap_proxy_read_response(ngx_imap_session_t *s, ngx_uint_t what)
+ngx_imap_proxy_read_response(ngx_imap_session_t *s, ngx_uint_t state)
{
u_char *p;
ssize_t n;
@@ -496,15 +497,29 @@ ngx_imap_proxy_read_response(ngx_imap_session_t *s, ngx_uint_t what)
}
} else {
- if (what == NGX_IMAP_WAIT_OK) {
+ switch (state) {
+
+ case ngx_imap_start:
if (p[0] == '*' && p[1] == ' ' && p[2] == 'O' && p[3] == 'K') {
return NGX_OK;
}
+ break;
- } else {
+ case ngx_imap_login:
+ case ngx_imap_user:
if (p[0] == '+') {
return NGX_OK;
}
+ break;
+
+ case ngx_imap_passwd:
+ if (ngx_strncmp(p, s->tag.data, s->tag.len) == 0) {
+ p += s->tag.len;
+ if (p[0] == 'O' && p[1] == 'K') {
+ return NGX_OK;
+ }
+ }
+ break;
}
}