nginx-0.0.10-2004-09-09-19:40:48 import
diff --git a/src/imap/ngx_imap_handler.c b/src/imap/ngx_imap_handler.c
index 61c59c9..55808fa 100644
--- a/src/imap/ngx_imap_handler.c
+++ b/src/imap/ngx_imap_handler.c
@@ -6,7 +6,7 @@
#include <nginx.h>
-static void ngx_imap_auth_state(ngx_event_t *rev);
+static void ngx_imap_init_session(ngx_event_t *rev);
static char pop3_greeting[] = "+OK " NGINX_VER " ready" CRLF;
@@ -15,36 +15,66 @@
void ngx_imap_init_connection(ngx_connection_t *c)
{
- ngx_int_t n;
+ char *greeting;
+ ssize_t size;
+ ngx_int_t n;
ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0,
"imap init connection");
c->log_error = NGX_ERROR_INFO;
- n = ngx_send(c, pop3_greeting, sizeof(pop3_greeting) - 1);
+ greeting = pop3_greeting;
+ size = sizeof(pop3_greeting) - 1;
- if (n == NGX_ERROR) {
+ n = ngx_send(c, greeting, size);
+
+ if (n < size) {
+ /*
+ * we treat the incomplete sending as NGX_ERROR
+ * because it is very strange here
+ */
ngx_imap_close_connection(c);
return;
}
- c->read->event_handler = ngx_imap_auth_state;
+ c->read->event_handler = ngx_imap_init_session;
+
+ ngx_add_timer(c->read, /* STUB */ 60000);
if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) {
ngx_imap_close_connection(c);
- return;
}
}
-static void ngx_imap_auth_state(ngx_event_t *rev)
+static void ngx_imap_init_session(ngx_event_t *rev)
{
- ngx_connection_t *c;
+ ngx_connection_t *c;
+ ngx_imap_session_t *s;
c = rev->data;
- ngx_imap_close_connection(c);
+ if (!(s = ngx_pcalloc(c->pool, sizeof(ngx_imap_session_t)))) {
+ ngx_imap_close_connection(c);
+ return;
+ }
+
+ c->data = s;
+ s->connection = c;
+
+ if (ngx_array_init(&s->args, c->pool, 2, sizeof(ngx_str_t)) == NGX_ERROR) {
+ ngx_imap_close_connection(s->connection);
+ return;
+ }
+
+ s->buffer = ngx_create_temp_buf(s->connection->pool, /* STUB */ 4096);
+ if (s->buffer == NULL) {
+ ngx_imap_close_connection(s->connection);
+ return;
+ }
+
+ ngx_imap_proxy_init(s);
}