Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2004-09-08 09:18:51 +0400
committerIgor Sysoev <igor@sysoev.ru>2004-09-08 09:18:51 +0400
commit0d9da9b6c3c4842eade3034e6e1f3ea140d08d6d (patch)
treee4a33bef9c97c1291fc693921ca4c555b242a7e9
parent59cf56c5d975725be9e2adc84170ffe0c638fa48 (diff)
nginx-0.0.10-2004-09-08-09:18:51 import
-rw-r--r--auto/sources3
-rw-r--r--src/imap/ngx_imap.h43
-rw-r--r--src/imap/ngx_imap_handler.c6
-rw-r--r--src/imap/ngx_imap_proxy.c80
4 files changed, 112 insertions, 20 deletions
diff --git a/auto/sources b/auto/sources
index 60ce87257..79a48e88c 100644
--- a/auto/sources
+++ b/auto/sources
@@ -298,4 +298,5 @@ IMAP_DEPS="src/imap/ngx_imap.h"
IMAP_MODULE=ngx_imap_module
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"
diff --git a/src/imap/ngx_imap.h b/src/imap/ngx_imap.h
index 5dc48df80..6f5307d3d 100644
--- a/src/imap/ngx_imap.h
+++ b/src/imap/ngx_imap.h
@@ -7,22 +7,33 @@
typedef struct {
- ngx_chain_t *send;
-} ngx_imap_request_t;
-
-
-#define NGX_POP3_USER 1
-#define NGX_POP3_PASS 2
-#define NGX_POP3_APOP 3
-#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
+ ngx_connection_t *connection;
+
+ ngx_buf_t *downstream_buffer;
+ ngx_buf_t *upstream_buffer;
+} ngx_imap_proxy_ctx_t;
+
+
+typedef struct {
+ uint32_t signature; /* "IMAP" */
+
+ ngx_connection_t *connection;
+ ngx_imap_proxy_ctx_t *proxy;
+} ngx_imap_session_t;
+
+
+#define NGX_POP3_USER 1
+#define NGX_POP3_PASS 2
+#define NGX_POP3_APOP 3
+#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);
diff --git a/src/imap/ngx_imap_handler.c b/src/imap/ngx_imap_handler.c
index bbedc9c56..61c59c98d 100644
--- a/src/imap/ngx_imap_handler.c
+++ b/src/imap/ngx_imap_handler.c
@@ -15,16 +15,16 @@ static char imap_greeting[] = "* OK " NGINX_VER " ready" CRLF;
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,
"imap init connection");
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);
return;
}
diff --git a/src/imap/ngx_imap_proxy.c b/src/imap/ngx_imap_proxy.c
new file mode 100644
index 000000000..f856159ff
--- /dev/null
+++ b/src/imap/ngx_imap_proxy.c
@@ -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)
+{
+}