changeset 1483:46f364406994

ngx_mail_smtp_create_buffer()
author Igor Sysoev <igor@sysoev.ru>
date Fri, 14 Sep 2007 14:13:25 +0000
parents 4606dce4f416
children c788d2b877be
files src/mail/ngx_mail_smtp_handler.c
diffstat 1 files changed, 36 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/mail/ngx_mail_smtp_handler.c
+++ b/src/mail/ngx_mail_smtp_handler.c
@@ -11,6 +11,8 @@
 
 
 static void ngx_mail_smtp_invalid_pipelining(ngx_event_t *rev);
+static ngx_int_t ngx_mail_smtp_create_buffer(ngx_mail_session_t *s,
+    ngx_connection_t *c);
 
 static ngx_int_t ngx_mail_smtp_helo(ngx_mail_session_t *s, ngx_connection_t *c);
 static ngx_int_t ngx_mail_smtp_auth(ngx_mail_session_t *s, ngx_connection_t *c);
@@ -51,21 +53,6 @@ ngx_mail_smtp_init_session(ngx_mail_sess
         }
     }
 
-    if (s->buffer == NULL) {
-        if (ngx_array_init(&s->args, c->pool, 2, sizeof(ngx_str_t))
-            == NGX_ERROR)
-        {
-            ngx_mail_session_internal_server_error(s);
-            return;
-        }
-
-        s->buffer = ngx_create_temp_buf(c->pool, cscf->smtp_client_buffer_size);
-        if (s->buffer == NULL) {
-            ngx_mail_session_internal_server_error(s);
-            return;
-        }
-    }
-
     timeout = cscf->smtp_greeting_delay ? cscf->smtp_greeting_delay:
                                           cscf->timeout;
     ngx_add_timer(c->read, timeout); 
@@ -120,6 +107,12 @@ ngx_mail_smtp_invalid_pipelining(ngx_eve
 
         ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "invalid pipelining");
 
+        if (s->buffer == NULL) {
+            if (ngx_mail_smtp_create_buffer(s, c) != NGX_OK) {
+                return;
+            }
+        }
+
         if (ngx_mail_smtp_discard_command(s, c,
                                 "client was rejected before greeting: \"%V\"")
             != NGX_OK)
@@ -154,6 +147,12 @@ ngx_mail_smtp_init_protocol(ngx_event_t 
 
     s = c->data;
 
+    if (s->buffer == NULL) {
+        if (ngx_mail_smtp_create_buffer(s, c) != NGX_OK) {
+            return;
+        }
+    }
+
     s->mail_state = ngx_smtp_start;
     c->read->handler = ngx_mail_smtp_auth_state;
 
@@ -161,6 +160,28 @@ ngx_mail_smtp_init_protocol(ngx_event_t 
 }
 
 
+static ngx_int_t
+ngx_mail_smtp_create_buffer(ngx_mail_session_t *s, ngx_connection_t *c)
+{
+    ngx_mail_core_srv_conf_t  *cscf;
+
+    if (ngx_array_init(&s->args, c->pool, 2, sizeof(ngx_str_t)) == NGX_ERROR) {
+        ngx_mail_session_internal_server_error(s);
+        return NGX_ERROR;
+    }
+
+    cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
+
+    s->buffer = ngx_create_temp_buf(c->pool, cscf->smtp_client_buffer_size);
+    if (s->buffer == NULL) {
+        ngx_mail_session_internal_server_error(s);
+        return NGX_ERROR;
+    }
+
+    return NGX_OK;
+}
+
+
 void
 ngx_mail_smtp_auth_state(ngx_event_t *rev)
 {