mirror of
https://github.com/nginx/nginx.git
synced 2025-06-07 17:52:38 +08:00
nginx-0.0.10-2004-09-08-09:18:51 import
This commit is contained in:
parent
59cf56c5d9
commit
0d9da9b6c3
@ -298,4 +298,5 @@ IMAP_DEPS="src/imap/ngx_imap.h"
|
|||||||
|
|
||||||
IMAP_MODULE=ngx_imap_module
|
IMAP_MODULE=ngx_imap_module
|
||||||
IMAP_SRCS="src/imap/ngx_imap.c \
|
IMAP_SRCS="src/imap/ngx_imap.c \
|
||||||
src/imap/ngx_imap_handler.c"
|
src/imap/ngx_imap_handler.c \
|
||||||
|
src/imap/ngx_imap_proxy.c"
|
||||||
|
@ -7,22 +7,33 @@
|
|||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ngx_chain_t *send;
|
ngx_connection_t *connection;
|
||||||
} ngx_imap_request_t;
|
|
||||||
|
ngx_buf_t *downstream_buffer;
|
||||||
|
ngx_buf_t *upstream_buffer;
|
||||||
|
} ngx_imap_proxy_ctx_t;
|
||||||
|
|
||||||
|
|
||||||
#define NGX_POP3_USER 1
|
typedef struct {
|
||||||
#define NGX_POP3_PASS 2
|
uint32_t signature; /* "IMAP" */
|
||||||
#define NGX_POP3_APOP 3
|
|
||||||
#define NGX_POP3_STAT 4
|
ngx_connection_t *connection;
|
||||||
#define NGX_POP3_LIST 5
|
ngx_imap_proxy_ctx_t *proxy;
|
||||||
#define NGX_POP3_RETR 6
|
} ngx_imap_session_t;
|
||||||
#define NGX_POP3_DELE 7
|
|
||||||
#define NGX_POP3_NOOP 8
|
|
||||||
#define NGX_POP3_RSET 9
|
#define NGX_POP3_USER 1
|
||||||
#define NGX_POP3_TOP 10
|
#define NGX_POP3_PASS 2
|
||||||
#define NGX_POP3_UIDL 11
|
#define NGX_POP3_APOP 3
|
||||||
#define NGX_POP3_QUIT 12
|
#define NGX_POP3_STAT 4
|
||||||
|
#define NGX_POP3_LIST 5
|
||||||
|
#define NGX_POP3_RETR 6
|
||||||
|
#define NGX_POP3_DELE 7
|
||||||
|
#define NGX_POP3_NOOP 8
|
||||||
|
#define NGX_POP3_RSET 9
|
||||||
|
#define NGX_POP3_TOP 10
|
||||||
|
#define NGX_POP3_UIDL 11
|
||||||
|
#define NGX_POP3_QUIT 12
|
||||||
|
|
||||||
|
|
||||||
void ngx_imap_init_connection(ngx_connection_t *c);
|
void ngx_imap_init_connection(ngx_connection_t *c);
|
||||||
|
@ -15,16 +15,16 @@ static char imap_greeting[] = "* OK " NGINX_VER " ready" CRLF;
|
|||||||
|
|
||||||
void ngx_imap_init_connection(ngx_connection_t *c)
|
void ngx_imap_init_connection(ngx_connection_t *c)
|
||||||
{
|
{
|
||||||
ngx_int_t rc;
|
ngx_int_t n;
|
||||||
|
|
||||||
ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0,
|
ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0,
|
||||||
"imap init connection");
|
"imap init connection");
|
||||||
|
|
||||||
c->log_error = NGX_ERROR_INFO;
|
c->log_error = NGX_ERROR_INFO;
|
||||||
|
|
||||||
rc = ngx_send(c, pop3_greeting, sizeof(pop3_greeting) - 1);
|
n = ngx_send(c, pop3_greeting, sizeof(pop3_greeting) - 1);
|
||||||
|
|
||||||
if (rc == NGX_ERROR) {
|
if (n == NGX_ERROR) {
|
||||||
ngx_imap_close_connection(c);
|
ngx_imap_close_connection(c);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
80
src/imap/ngx_imap_proxy.c
Normal file
80
src/imap/ngx_imap_proxy.c
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
|
||||||
|
#include <ngx_config.h>
|
||||||
|
#include <ngx_core.h>
|
||||||
|
#include <ngx_event.h>
|
||||||
|
#include <ngx_imap.h>
|
||||||
|
|
||||||
|
|
||||||
|
static void ngx_imap_proxy_close_session(ngx_imap_session_t *s);
|
||||||
|
|
||||||
|
|
||||||
|
void ngx_imap_proxy_handler(ngx_event_t *ev)
|
||||||
|
{
|
||||||
|
ssize_t n;
|
||||||
|
ngx_buf_t *b;
|
||||||
|
ngx_uint_t data, do_write;
|
||||||
|
ngx_connection_t *c, *src, *dst;
|
||||||
|
ngx_imap_session_t *s;
|
||||||
|
|
||||||
|
c = ev->data;
|
||||||
|
s = c->data;
|
||||||
|
|
||||||
|
if (c == s->connection) {
|
||||||
|
src = c;
|
||||||
|
dst = s->proxy->connection;
|
||||||
|
b = s->proxy->downstream_buffer;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
src = s->proxy->connection;
|
||||||
|
dst = c;
|
||||||
|
b = s->proxy->upstream_buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
do_write = ev->write ? 1 : 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
data = 0;
|
||||||
|
|
||||||
|
if (do_write == 1) {
|
||||||
|
if (dst->write->ready && b->pos < b->last) {
|
||||||
|
n = ngx_send(dst, b->pos, b->last - b->pos);
|
||||||
|
|
||||||
|
if (n == NGX_ERROR) {
|
||||||
|
ngx_imap_proxy_close_session(s);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n > 0) {
|
||||||
|
data = 1;
|
||||||
|
b->pos += n;
|
||||||
|
|
||||||
|
if (b->pos == b->last) {
|
||||||
|
b->pos = b->start;
|
||||||
|
b->last = b->start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (src->read->ready && b->last < b->end) {
|
||||||
|
n = ngx_recv(src, b->last, b->end - b->last);
|
||||||
|
|
||||||
|
if (n == NGX_ERROR || n == 0) {
|
||||||
|
ngx_imap_proxy_close_session(s);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n > 0) {
|
||||||
|
data = 1;
|
||||||
|
do_write = 1;
|
||||||
|
b->last += n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void ngx_imap_proxy_close_session(ngx_imap_session_t *s)
|
||||||
|
{
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user