mirror of
https://github.com/nginx/nginx.git
synced 2024-12-20 14:13:33 -06:00
nginx-0.0.10-2004-09-12-00:22:11 import
This commit is contained in:
parent
10778353ae
commit
32e5771747
@ -220,7 +220,7 @@ extern ngx_event_actions_t ngx_event_actions;
|
||||
|
||||
/*
|
||||
* The event filter is deleted after a notification without an additional
|
||||
* syscall - select, poll, kqueue, epoll.
|
||||
* syscall - select, poll, kqueue, epoll, Solaris 10's event ports.
|
||||
*/
|
||||
#define NGX_USE_ONESHOT_EVENT 0x00000002
|
||||
|
||||
|
@ -31,6 +31,9 @@ typedef struct {
|
||||
|
||||
ngx_imap_proxy_ctx_t *proxy;
|
||||
|
||||
ngx_str_t login;
|
||||
ngx_str_t passwd;
|
||||
|
||||
ngx_uint_t command;
|
||||
ngx_array_t args;
|
||||
|
||||
|
@ -69,15 +69,15 @@ static void ngx_imap_init_session(ngx_event_t *rev)
|
||||
s->connection = c;
|
||||
|
||||
if (ngx_array_init(&s->args, c->pool, 2, sizeof(ngx_str_t)) == NGX_ERROR) {
|
||||
ngx_imap_close_connection(s->connection);
|
||||
ngx_imap_close_connection(c);
|
||||
return;
|
||||
}
|
||||
|
||||
size = /* STUB: pop3: 128, imap: configurable 4K default */ 128;
|
||||
|
||||
s->buffer = ngx_create_temp_buf(s->connection->pool, size);
|
||||
s->buffer = ngx_create_temp_buf(c->pool, size);
|
||||
if (s->buffer == NULL) {
|
||||
ngx_imap_close_connection(s->connection);
|
||||
ngx_imap_close_connection(c);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -89,10 +89,11 @@ static void ngx_imap_init_session(ngx_event_t *rev)
|
||||
|
||||
static void ngx_pop3_auth_state(ngx_event_t *rev)
|
||||
{
|
||||
ngx_uint_t quit;
|
||||
u_char *text;
|
||||
ssize_t size;
|
||||
ngx_int_t rc;
|
||||
ngx_uint_t quit;
|
||||
ngx_str_t *arg;
|
||||
ngx_connection_t *c;
|
||||
ngx_imap_session_t *s;
|
||||
|
||||
@ -123,6 +124,20 @@ static void ngx_pop3_auth_state(ngx_event_t *rev)
|
||||
case NGX_POP3_USER:
|
||||
if (s->args.nelts == 1) {
|
||||
s->imap_state = ngx_pop3_user;
|
||||
|
||||
arg = s->args.elts;
|
||||
s->login.len = arg[0].len;
|
||||
s->login.data = ngx_palloc(c->pool, s->login.len + 1);
|
||||
if (s->login.data == NULL) {
|
||||
ngx_imap_close_connection(c);
|
||||
return;
|
||||
}
|
||||
|
||||
ngx_cpystrn(s->login.data, arg[0].data, s->login.len + 1);
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0,
|
||||
"pop3 login: \"%s\"", s->login.data);
|
||||
|
||||
} else {
|
||||
rc = NGX_IMAP_PARSE_INVALID_COMMAND;
|
||||
}
|
||||
@ -148,6 +163,27 @@ static void ngx_pop3_auth_state(ngx_event_t *rev)
|
||||
case NGX_POP3_PASS:
|
||||
if (s->args.nelts == 1) {
|
||||
/* STUB */ s->imap_state = ngx_pop3_start;
|
||||
|
||||
arg = s->args.elts;
|
||||
s->passwd.len = arg[0].len;
|
||||
s->passwd.data = ngx_palloc(c->pool, s->passwd.len + 1);
|
||||
if (s->passwd.data == NULL) {
|
||||
ngx_imap_close_connection(c);
|
||||
return;
|
||||
}
|
||||
|
||||
ngx_cpystrn(s->passwd.data, arg[0].data, s->passwd.len + 1);
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0,
|
||||
"pop3 passwd: \"%s\"", s->passwd.data);
|
||||
|
||||
s->buffer->pos = s->buffer->start;
|
||||
s->buffer->last = s->buffer->start;
|
||||
|
||||
ngx_imap_proxy_init(s);
|
||||
|
||||
return;
|
||||
|
||||
} else {
|
||||
rc = NGX_IMAP_PARSE_INVALID_COMMAND;
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ ngx_int_t ngx_pop3_parse_command(ngx_imap_session_t *s)
|
||||
if (!(arg = ngx_array_push(&s->args))) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
arg->len = p - s->arg_start;
|
||||
arg->len = p - 1 - s->arg_start;
|
||||
arg->data = s->arg_start;
|
||||
s->arg_start = NULL;
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
static void ngx_imap_proxy_block_read(ngx_event_t *rev);
|
||||
static void ngx_imap_proxy_greeting_handler(ngx_event_t *rev);
|
||||
static void ngx_imap_proxy_auth_handler(ngx_event_t *rev);
|
||||
static void ngx_imap_proxy_init_handler(ngx_event_t *wev);
|
||||
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);
|
||||
@ -57,8 +57,7 @@ void ngx_imap_proxy_init(ngx_imap_session_t *s)
|
||||
p->upstream.connection->pool = s->connection->pool;
|
||||
|
||||
s->connection->read->event_handler = ngx_imap_proxy_block_read;
|
||||
p->upstream.connection->read->event_handler =
|
||||
ngx_imap_proxy_greeting_handler;
|
||||
p->upstream.connection->read->event_handler = ngx_imap_proxy_auth_handler;
|
||||
p->upstream.connection->write->event_handler = ngx_imap_proxy_dummy_handler;
|
||||
}
|
||||
|
||||
@ -79,15 +78,15 @@ static void ngx_imap_proxy_block_read(ngx_event_t *rev)
|
||||
}
|
||||
|
||||
|
||||
static void ngx_imap_proxy_greeting_handler(ngx_event_t *rev)
|
||||
static void ngx_imap_proxy_auth_handler(ngx_event_t *rev)
|
||||
{
|
||||
u_char *p;
|
||||
ngx_int_t rc;
|
||||
ngx_buf_t *b;
|
||||
ngx_str_t line;
|
||||
ngx_connection_t *c;
|
||||
ngx_imap_session_t *s;
|
||||
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0,
|
||||
"imap proxy greeting handler");
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy auth handler");
|
||||
|
||||
c = rev->data;
|
||||
s = c->data;
|
||||
@ -106,30 +105,71 @@ static void ngx_imap_proxy_greeting_handler(ngx_event_t *rev)
|
||||
return;
|
||||
}
|
||||
|
||||
if (rc == NGX_OK) {
|
||||
s->connection->read->event_handler = ngx_imap_proxy_handler;
|
||||
s->connection->write->event_handler = ngx_imap_proxy_handler;
|
||||
rev->event_handler = ngx_imap_proxy_handler;
|
||||
c->write->event_handler = ngx_imap_proxy_handler;
|
||||
if (rc == NGX_ERROR) {
|
||||
/* TODO: ngx_imap_proxy_finalize_session(s, NGX_IMAP_INTERNAL_ERROR) */
|
||||
ngx_imap_proxy_close_session(s);
|
||||
return;
|
||||
}
|
||||
|
||||
b = s->proxy->buffer;
|
||||
b->pos = b->start;
|
||||
b->last = b->start;
|
||||
if (s->imap_state == ngx_pop3_start) {
|
||||
|
||||
if (ngx_handle_read_event(s->connection->read, 0) == NGX_ERROR) {
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send user");
|
||||
|
||||
line.len = sizeof("USER ") + s->login.len - 1 + 2;
|
||||
if (!(line.data = ngx_palloc(c->pool, line.len))) {
|
||||
ngx_imap_proxy_close_session(s);
|
||||
return;
|
||||
}
|
||||
|
||||
if (s->connection->read->ready) {
|
||||
ngx_imap_proxy_handler(s->connection->read);
|
||||
p = ngx_cpymem(line.data, "USER ", sizeof("USER ") - 1);
|
||||
p = ngx_cpymem(p, s->login.data, s->login.len);
|
||||
*p++ = CR; *p++ = LF;
|
||||
|
||||
if (ngx_send(c, line.data, line.len) < (ssize_t) line.len) {
|
||||
/*
|
||||
* we treat the incomplete sending as NGX_ERROR
|
||||
* because it is very strange here
|
||||
*/
|
||||
ngx_imap_close_connection(c);
|
||||
return;
|
||||
}
|
||||
|
||||
s->imap_state = ngx_pop3_user;
|
||||
|
||||
s->proxy->buffer->pos = s->proxy->buffer->start;
|
||||
s->proxy->buffer->last = s->proxy->buffer->start;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* TODO: ngx_imap_proxy_finalize_session(s, NGX_IMAP_INTERNAL_ERROR) */
|
||||
ngx_imap_proxy_close_session(s);
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send pass");
|
||||
|
||||
line.len = sizeof("PASS ") + s->passwd.len - 1 + 2;
|
||||
if (!(line.data = ngx_palloc(c->pool, line.len))) {
|
||||
ngx_imap_proxy_close_session(s);
|
||||
return;
|
||||
}
|
||||
|
||||
p = ngx_cpymem(line.data, "PASS ", sizeof("PASS ") - 1);
|
||||
p = ngx_cpymem(p, s->passwd.data, s->passwd.len);
|
||||
*p++ = CR; *p++ = LF;
|
||||
|
||||
if (ngx_send(c, line.data, line.len) < (ssize_t) line.len) {
|
||||
/*
|
||||
* we treat the incomplete sending as NGX_ERROR
|
||||
* because it is very strange here
|
||||
*/
|
||||
ngx_imap_close_connection(c);
|
||||
return;
|
||||
}
|
||||
|
||||
s->proxy->buffer->pos = s->proxy->buffer->start;
|
||||
s->proxy->buffer->last = s->proxy->buffer->start;
|
||||
|
||||
s->connection->read->event_handler = ngx_imap_proxy_handler;
|
||||
s->connection->write->event_handler = ngx_imap_proxy_handler;
|
||||
rev->event_handler = ngx_imap_proxy_handler;
|
||||
c->write->event_handler = ngx_imap_proxy_handler;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user