style fix and optimizations
This commit is contained in:
parent
06c3f18113
commit
7aa63131c7
7 changed files with 47 additions and 45 deletions
|
@ -307,7 +307,8 @@ typedef struct {
|
|||
typedef void (*ngx_mail_init_session_pt)(ngx_mail_session_t *s,
|
||||
ngx_connection_t *c);
|
||||
typedef void (*ngx_mail_init_protocol_pt)(ngx_event_t *rev);
|
||||
typedef ngx_int_t (*ngx_mail_parse_pt)(ngx_mail_session_t *s);
|
||||
typedef void (*ngx_mail_auth_state_pt)(ngx_event_t *rev);
|
||||
typedef ngx_int_t (*ngx_mail_parse_command_pt)(ngx_mail_session_t *s);
|
||||
|
||||
|
||||
#if (NGX_MAIL_SSL)
|
||||
|
@ -317,9 +318,9 @@ void ngx_mail_starttls_handler(ngx_event_t *rev);
|
|||
|
||||
void ngx_mail_init_connection(ngx_connection_t *c);
|
||||
|
||||
void ngx_pop3_auth_state(ngx_event_t *rev);
|
||||
void ngx_imap_auth_state(ngx_event_t *rev);
|
||||
void ngx_smtp_auth_state(ngx_event_t *rev);
|
||||
void ngx_mail_pop3_auth_state(ngx_event_t *rev);
|
||||
void ngx_mail_imap_auth_state(ngx_event_t *rev);
|
||||
void ngx_mail_smtp_auth_state(ngx_event_t *rev);
|
||||
|
||||
ngx_int_t ngx_mail_salt(ngx_mail_session_t *s, ngx_connection_t *c,
|
||||
ngx_mail_core_srv_conf_t *cscf);
|
||||
|
@ -347,9 +348,9 @@ void ngx_mail_pop3_init_protocol(ngx_event_t *rev);
|
|||
void ngx_mail_imap_init_protocol(ngx_event_t *rev);
|
||||
void ngx_mail_smtp_init_protocol(ngx_event_t *rev);
|
||||
|
||||
ngx_int_t ngx_pop3_parse_command(ngx_mail_session_t *s);
|
||||
ngx_int_t ngx_imap_parse_command(ngx_mail_session_t *s);
|
||||
ngx_int_t ngx_smtp_parse_command(ngx_mail_session_t *s);
|
||||
ngx_int_t ngx_mail_pop3_parse_command(ngx_mail_session_t *s);
|
||||
ngx_int_t ngx_mail_imap_parse_command(ngx_mail_session_t *s);
|
||||
ngx_int_t ngx_mail_smtp_parse_command(ngx_mail_session_t *s);
|
||||
|
||||
|
||||
/* STUB */
|
||||
|
|
|
@ -145,6 +145,19 @@ static ngx_str_t ngx_mail_auth_http_method[] = {
|
|||
|
||||
static ngx_str_t ngx_mail_smtp_errcode = ngx_string("535 5.7.0");
|
||||
|
||||
static ngx_uint_t ngx_mail_start_states[] = {
|
||||
ngx_pop3_start,
|
||||
ngx_imap_start,
|
||||
ngx_smtp_start
|
||||
};
|
||||
|
||||
static ngx_mail_auth_state_pt ngx_mail_auth_states[] = {
|
||||
ngx_mail_pop3_auth_state,
|
||||
ngx_mail_imap_auth_state,
|
||||
ngx_mail_smtp_auth_state
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
ngx_mail_auth_http_init(ngx_mail_session_t *s)
|
||||
{
|
||||
|
@ -868,29 +881,14 @@ ngx_mail_auth_sleep_handler(ngx_event_t *rev)
|
|||
return;
|
||||
}
|
||||
|
||||
switch (s->protocol) {
|
||||
|
||||
case NGX_MAIL_POP3_PROTOCOL:
|
||||
s->mail_state = ngx_pop3_start;
|
||||
s->connection->read->handler = ngx_pop3_auth_state;
|
||||
break;
|
||||
|
||||
case NGX_MAIL_IMAP_PROTOCOL:
|
||||
s->mail_state = ngx_imap_start;
|
||||
s->connection->read->handler = ngx_imap_auth_state;
|
||||
break;
|
||||
|
||||
default: /* NGX_MAIL_SMTP_PROTOCOL */
|
||||
s->mail_state = ngx_smtp_start;
|
||||
s->connection->read->handler = ngx_smtp_auth_state;
|
||||
break;
|
||||
}
|
||||
s->mail_state = ngx_mail_start_states[s->protocol];
|
||||
rev->handler = ngx_mail_auth_states[s->protocol];
|
||||
|
||||
s->auth_method = NGX_MAIL_AUTH_PLAIN;
|
||||
|
||||
c->log->action = "in auth state";
|
||||
|
||||
ngx_mail_send(s->connection->write);
|
||||
ngx_mail_send(c->write);
|
||||
|
||||
if (c->destroyed) {
|
||||
return;
|
||||
|
@ -901,12 +899,12 @@ ngx_mail_auth_sleep_handler(ngx_event_t *rev)
|
|||
ngx_add_timer(rev, cscf->timeout);
|
||||
|
||||
if (rev->ready) {
|
||||
s->connection->read->handler(rev);
|
||||
rev->handler(rev);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
|
||||
ngx_mail_close_connection(s->connection);
|
||||
ngx_mail_close_connection(c);
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -914,7 +912,7 @@ ngx_mail_auth_sleep_handler(ngx_event_t *rev)
|
|||
|
||||
if (rev->active) {
|
||||
if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
|
||||
ngx_mail_close_connection(s->connection);
|
||||
ngx_mail_close_connection(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,10 +32,10 @@ static ngx_mail_init_protocol_pt ngx_mail_init_protocols[] = {
|
|||
};
|
||||
|
||||
|
||||
static ngx_mail_parse_pt ngx_mail_parse[] = {
|
||||
ngx_pop3_parse_command,
|
||||
ngx_imap_parse_command,
|
||||
ngx_smtp_parse_command
|
||||
static ngx_mail_parse_command_pt ngx_mail_parse_commands[] = {
|
||||
ngx_mail_pop3_parse_command,
|
||||
ngx_mail_imap_parse_command,
|
||||
ngx_mail_smtp_parse_command
|
||||
};
|
||||
|
||||
|
||||
|
@ -546,7 +546,7 @@ ngx_mail_read_command(ngx_mail_session_t *s)
|
|||
return NGX_AGAIN;
|
||||
}
|
||||
|
||||
rc = ngx_mail_parse[s->protocol](s);
|
||||
rc = ngx_mail_parse_commands[s->protocol](s);
|
||||
|
||||
if (rc == NGX_AGAIN) {
|
||||
|
||||
|
|
|
@ -92,14 +92,14 @@ ngx_mail_imap_init_protocol(ngx_event_t *rev)
|
|||
}
|
||||
|
||||
s->mail_state = ngx_imap_start;
|
||||
c->read->handler = ngx_imap_auth_state;
|
||||
c->read->handler = ngx_mail_imap_auth_state;
|
||||
|
||||
ngx_imap_auth_state(rev);
|
||||
ngx_mail_imap_auth_state(rev);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ngx_imap_auth_state(ngx_event_t *rev)
|
||||
ngx_mail_imap_auth_state(ngx_event_t *rev)
|
||||
{
|
||||
u_char *p, *dst, *src, *end;
|
||||
ngx_str_t *arg;
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
#include <ngx_mail.h>
|
||||
|
||||
|
||||
ngx_int_t ngx_pop3_parse_command(ngx_mail_session_t *s)
|
||||
ngx_int_t
|
||||
ngx_mail_pop3_parse_command(ngx_mail_session_t *s)
|
||||
{
|
||||
u_char ch, *p, *c, c0, c1, c2, c3;
|
||||
ngx_str_t *arg;
|
||||
|
@ -207,7 +208,8 @@ invalid:
|
|||
}
|
||||
|
||||
|
||||
ngx_int_t ngx_imap_parse_command(ngx_mail_session_t *s)
|
||||
ngx_int_t
|
||||
ngx_mail_imap_parse_command(ngx_mail_session_t *s)
|
||||
{
|
||||
u_char ch, *p, *c;
|
||||
ngx_str_t *arg;
|
||||
|
@ -613,7 +615,8 @@ invalid:
|
|||
}
|
||||
|
||||
|
||||
ngx_int_t ngx_smtp_parse_command(ngx_mail_session_t *s)
|
||||
ngx_int_t
|
||||
ngx_mail_smtp_parse_command(ngx_mail_session_t *s)
|
||||
{
|
||||
u_char ch, *p, *c, c0, c1, c2, c3;
|
||||
ngx_str_t *arg;
|
||||
|
|
|
@ -101,14 +101,14 @@ ngx_mail_pop3_init_protocol(ngx_event_t *rev)
|
|||
}
|
||||
|
||||
s->mail_state = ngx_pop3_start;
|
||||
c->read->handler = ngx_pop3_auth_state;
|
||||
c->read->handler = ngx_mail_pop3_auth_state;
|
||||
|
||||
ngx_pop3_auth_state(rev);
|
||||
ngx_mail_pop3_auth_state(rev);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ngx_pop3_auth_state(ngx_event_t *rev)
|
||||
ngx_mail_pop3_auth_state(ngx_event_t *rev)
|
||||
{
|
||||
ngx_int_t rc;
|
||||
ngx_connection_t *c;
|
||||
|
|
|
@ -84,14 +84,14 @@ ngx_mail_smtp_init_protocol(ngx_event_t *rev)
|
|||
}
|
||||
|
||||
s->mail_state = ngx_smtp_start;
|
||||
c->read->handler = ngx_smtp_auth_state;
|
||||
c->read->handler = ngx_mail_smtp_auth_state;
|
||||
|
||||
ngx_smtp_auth_state(rev);
|
||||
ngx_mail_smtp_auth_state(rev);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ngx_smtp_auth_state(ngx_event_t *rev)
|
||||
ngx_mail_smtp_auth_state(ngx_event_t *rev)
|
||||
{
|
||||
ngx_int_t rc;
|
||||
ngx_connection_t *c;
|
||||
|
|
Loading…
Reference in a new issue