Welcome! Log In Create A New Profile

Advanced

[PATCH ]Mail: add guards around imap, pop3, smtp dedicated source code.

Filipe Da Silva
July 29, 2014 04:22PM
Hi,

It's a patch to cut some code that becomes useless, when you build
your binary with a ./configure option like --without-mail_smtp_module
and so on.

I re-compile the code using all combination of the 3
--without-mail_*_module options to test it.

It is just a first shot, in order to to reduce a bit the amount of
auth-http code .
Any comments are welcome.

Regards,
Filipe da Silva
# HG changeset patch
# User Filipe da Silva <fdasilvayy@gmail.com>
# Date 1389727400 -3600
# Tue Jan 14 20:23:20 2014 +0100
# Node ID 9d0d0b0d085c85590c4469a4feaa8a6eab9604dc
# Parent 675bda8dcfdbf66e4a17017839f39ed6c8cbb9f5
Mail: add guards around imap, pop3, smtp dedicated source code.

No functionnal change.
Disable some code that becomes unnecessary when adding configure directives
like --without-mail_(smtp|imap|pop3)_module .

diff -r 675bda8dcfdb auto/modules
--- a/auto/modules Thu Jun 19 13:55:59 2014 +0400
+++ b/auto/modules Thu Jun 19 22:55:55 2014 +0200
@@ -466,18 +466,21 @@ if [ $MAIL = YES ]; then
fi

if [ $MAIL_POP3 = YES ]; then
+ have=NGX_MAIL_POP3 . auto/have
modules="$modules $MAIL_POP3_MODULE"
MAIL_DEPS="$MAIL_DEPS $MAIL_POP3_DEPS"
MAIL_SRCS="$MAIL_SRCS $MAIL_POP3_SRCS"
fi

if [ $MAIL_IMAP = YES ]; then
+ have=NGX_MAIL_IMAP . auto/have
modules="$modules $MAIL_IMAP_MODULE"
MAIL_DEPS="$MAIL_DEPS $MAIL_IMAP_DEPS"
MAIL_SRCS="$MAIL_SRCS $MAIL_IMAP_SRCS"
fi

if [ $MAIL_SMTP = YES ]; then
+ have=NGX_MAIL_SMTP . auto/have
modules="$modules $MAIL_SMTP_MODULE"
MAIL_DEPS="$MAIL_DEPS $MAIL_SMTP_DEPS"
MAIL_SRCS="$MAIL_SRCS $MAIL_SMTP_SRCS"
diff -r 675bda8dcfdb src/mail/ngx_mail_auth_http_module.c
--- a/src/mail/ngx_mail_auth_http_module.c Thu Jun 19 13:55:59 2014 +0400
+++ b/src/mail/ngx_mail_auth_http_module.c Thu Jun 19 22:55:55 2014 +0200
@@ -146,7 +146,9 @@ static ngx_str_t ngx_mail_auth_http_me
ngx_string("none")
};

+#if (NGX_MAIL_SMTP)
static ngx_str_t ngx_mail_smtp_errcode = ngx_string("535 5.7.0");
+#endif


void
@@ -519,14 +521,18 @@ ngx_mail_auth_http_process_headers(ngx_m

switch (s->protocol) {

+#if (NGX_MAIL_POP3)
case NGX_MAIL_POP3_PROTOCOL:
size = sizeof("-ERR ") - 1 + len + sizeof(CRLF) - 1;
break;
+#endif

+#if (NGX_MAIL_IMAP)
case NGX_MAIL_IMAP_PROTOCOL:
size = s->tag.len + sizeof("NO ") - 1 + len
+ sizeof(CRLF) - 1;
break;
+#endif

default: /* NGX_MAIL_SMTP_PROTOCOL */
ctx->err = ctx->errmsg;
@@ -545,14 +551,18 @@ ngx_mail_auth_http_process_headers(ngx_m

switch (s->protocol) {

+#if (NGX_MAIL_POP3)
case NGX_MAIL_POP3_PROTOCOL:
*p++ = '-'; *p++ = 'E'; *p++ = 'R'; *p++ = 'R'; *p++ = ' ';
break;
+#endif

+#if (NGX_MAIL_IMAP)
case NGX_MAIL_IMAP_PROTOCOL:
p = ngx_cpymem(p, s->tag.data, s->tag.len);
*p++ = 'N'; *p++ = 'O'; *p++ = ' ';
break;
+#endif

default: /* NGX_MAIL_SMTP_PROTOCOL */
break;
@@ -688,6 +698,7 @@ ngx_mail_auth_http_process_headers(ngx_m
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
"client login failed: \"%V\"", &ctx->errmsg);

+#if (NGX_MAIL_SMTP)
if (s->protocol == NGX_MAIL_SMTP_PROTOCOL) {

if (ctx->errcode.len == 0) {
@@ -711,6 +722,7 @@ ngx_mail_auth_http_process_headers(ngx_m
p = ngx_cpymem(p, ctx->errmsg.data, ctx->errmsg.len);
*p++ = CR; *p = LF;
}
+#endif

s->out = ctx->err;
timer = ctx->sleep;
@@ -1170,9 +1182,11 @@ ngx_mail_auth_http_create_request(ngx_ma
+ sizeof("Client-IP: ") - 1 + s->connection->addr_text.len
+ sizeof(CRLF) - 1
+ sizeof("Client-Host: ") - 1 + s->host.len + sizeof(CRLF) - 1
+#if (NGX_MAIL_SMTP)
+ sizeof("Auth-SMTP-Helo: ") - 1 + s->smtp_helo.len
+ sizeof("Auth-SMTP-From: ") - 1 + s->smtp_from.len
+ sizeof("Auth-SMTP-To: ") - 1 + s->smtp_to.len
+#endif
+ ahcf->header.len
+ sizeof(CRLF) - 1;

@@ -1234,6 +1248,7 @@ ngx_mail_auth_http_create_request(ngx_ma
*b->last++ = CR; *b->last++ = LF;
}

+#if (NGX_MAIL_SMTP)
if (s->auth_method == NGX_MAIL_AUTH_NONE) {

/* HELO, MAIL FROM, and RCPT TO can't contain CRLF, no need to escape */
@@ -1254,6 +1269,7 @@ ngx_mail_auth_http_create_request(ngx_ma
*b->last++ = CR; *b->last++ = LF;

}
+#endif

if (ahcf->header.len) {
b->last = ngx_copy(b->last, ahcf->header.data, ahcf->header.len);
diff -r 675bda8dcfdb src/mail/ngx_mail_proxy_module.c
--- a/src/mail/ngx_mail_proxy_module.c Thu Jun 19 13:55:59 2014 +0400
+++ b/src/mail/ngx_mail_proxy_module.c Thu Jun 19 22:55:55 2014 +0200
@@ -22,9 +22,15 @@ typedef struct {


static void ngx_mail_proxy_block_read(ngx_event_t *rev);
+#if (NGX_MAIL_POP3)
static void ngx_mail_proxy_pop3_handler(ngx_event_t *rev);
+#endif
+#if (NGX_MAIL_IMAP)
static void ngx_mail_proxy_imap_handler(ngx_event_t *rev);
+#endif
+#if (NGX_MAIL_SMTP)
static void ngx_mail_proxy_smtp_handler(ngx_event_t *rev);
+#endif
static void ngx_mail_proxy_dummy_handler(ngx_event_t *ev);
static ngx_int_t ngx_mail_proxy_read_response(ngx_mail_session_t *s,
ngx_uint_t state);
@@ -105,7 +111,9 @@ ngx_module_t ngx_mail_proxy_module = {
};


+#if (NGX_MAIL_SMTP)
static u_char smtp_auth_ok[] = "235 2.0.0 OK" CRLF;
+#endif


void
@@ -176,20 +184,31 @@ ngx_mail_proxy_init(ngx_mail_session_t *

switch (s->protocol) {

+#if (NGX_MAIL_POP3)
case NGX_MAIL_POP3_PROTOCOL:
p->upstream.connection->read->handler = ngx_mail_proxy_pop3_handler;
s->mail_state = ngx_pop3_start;
break;
+#endif

+#if (NGX_MAIL_IMAP)
case NGX_MAIL_IMAP_PROTOCOL:
p->upstream.connection->read->handler = ngx_mail_proxy_imap_handler;
s->mail_state = ngx_imap_start;
break;
+#endif

- default: /* NGX_MAIL_SMTP_PROTOCOL */
+#if (NGX_MAIL_SMTP)
+ case NGX_MAIL_SMTP_PROTOCOL:
p->upstream.connection->read->handler = ngx_mail_proxy_smtp_handler;
s->mail_state = ngx_smtp_start;
break;
+#endif
+
+ default:
+ p->upstream.connection->read->handler = ngx_mail_proxy_dummy_handler;
+ s->mail_state = 0;
+ break;
}
}

@@ -211,6 +230,7 @@ ngx_mail_proxy_block_read(ngx_event_t *r
}


+#if (NGX_MAIL_POP3)
static void
ngx_mail_proxy_pop3_handler(ngx_event_t *rev)
{
@@ -322,8 +342,10 @@ ngx_mail_proxy_pop3_handler(ngx_event_t
s->proxy->buffer->pos = s->proxy->buffer->start;
s->proxy->buffer->last = s->proxy->buffer->start;
}
+#endif


+#if (NGX_MAIL_IMAP)
static void
ngx_mail_proxy_imap_handler(ngx_event_t *rev)
{
@@ -456,8 +478,10 @@ ngx_mail_proxy_imap_handler(ngx_event_t
s->proxy->buffer->pos = s->proxy->buffer->start;
s->proxy->buffer->last = s->proxy->buffer->start;
}
+#endif


+#if (NGX_MAIL_SMTP)
static void
ngx_mail_proxy_smtp_handler(ngx_event_t *rev)
{
@@ -708,6 +732,7 @@ ngx_mail_proxy_smtp_handler(ngx_event_t
s->proxy->buffer->pos = s->proxy->buffer->start;
s->proxy->buffer->last = s->proxy->buffer->start;
}
+#endif


static void
@@ -778,6 +803,7 @@ ngx_mail_proxy_read_response(ngx_mail_se
}
break;

+#if (NGX_MAIL_IMAP)
case NGX_MAIL_IMAP_PROTOCOL:
switch (state) {

@@ -805,6 +831,7 @@ ngx_mail_proxy_read_response(ngx_mail_se
}

break;
+#endif

default: /* NGX_MAIL_SMTP_PROTOCOL */

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH ]Mail: add guards around imap, pop3, smtp dedicated source code.

Filipe Da Silva 622 July 29, 2014 04:22PM

Re: [PATCH ]Mail: add guards around imap, pop3, smtp dedicated source code.

Maxim Dounin 317 July 29, 2014 05:54PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 135
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready