Klaus Demo nginx / 0d9da9b
nginx-0.0.10-2004-09-08-09:18:51 import Igor Sysoev 17 years ago
4 changed file(s) with 110 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
297297
298298 IMAP_MODULE=ngx_imap_module
299299 IMAP_SRCS="src/imap/ngx_imap.c \
300 src/imap/ngx_imap_handler.c"
300 src/imap/ngx_imap_handler.c \
301 src/imap/ngx_imap_proxy.c"
66
77
88 typedef struct {
9 ngx_chain_t *send;
10 } ngx_imap_request_t;
9 ngx_connection_t *connection;
10
11 ngx_buf_t *downstream_buffer;
12 ngx_buf_t *upstream_buffer;
13 } ngx_imap_proxy_ctx_t;
1114
1215
13 #define NGX_POP3_USER 1
14 #define NGX_POP3_PASS 2
15 #define NGX_POP3_APOP 3
16 #define NGX_POP3_STAT 4
17 #define NGX_POP3_LIST 5
18 #define NGX_POP3_RETR 6
19 #define NGX_POP3_DELE 7
20 #define NGX_POP3_NOOP 8
21 #define NGX_POP3_RSET 9
22 #define NGX_POP3_TOP 10
23 #define NGX_POP3_UIDL 11
24 #define NGX_POP3_QUIT 12
16 typedef struct {
17 uint32_t signature; /* "IMAP" */
18
19 ngx_connection_t *connection;
20 ngx_imap_proxy_ctx_t *proxy;
21 } ngx_imap_session_t;
22
23
24 #define NGX_POP3_USER 1
25 #define NGX_POP3_PASS 2
26 #define NGX_POP3_APOP 3
27 #define NGX_POP3_STAT 4
28 #define NGX_POP3_LIST 5
29 #define NGX_POP3_RETR 6
30 #define NGX_POP3_DELE 7
31 #define NGX_POP3_NOOP 8
32 #define NGX_POP3_RSET 9
33 #define NGX_POP3_TOP 10
34 #define NGX_POP3_UIDL 11
35 #define NGX_POP3_QUIT 12
2536
2637
2738 void ngx_imap_init_connection(ngx_connection_t *c);
1414
1515 void ngx_imap_init_connection(ngx_connection_t *c)
1616 {
17 ngx_int_t rc;
17 ngx_int_t n;
1818
1919 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0,
2020 "imap init connection");
2121
2222 c->log_error = NGX_ERROR_INFO;
2323
24 rc = ngx_send(c, pop3_greeting, sizeof(pop3_greeting) - 1);
24 n = ngx_send(c, pop3_greeting, sizeof(pop3_greeting) - 1);
2525
26 if (rc == NGX_ERROR) {
26 if (n == NGX_ERROR) {
2727 ngx_imap_close_connection(c);
2828 return;
2929 }
0
1 #include <ngx_config.h>
2 #include <ngx_core.h>
3 #include <ngx_event.h>
4 #include <ngx_imap.h>
5
6
7 static void ngx_imap_proxy_close_session(ngx_imap_session_t *s);
8
9
10 void ngx_imap_proxy_handler(ngx_event_t *ev)
11 {
12 ssize_t n;
13 ngx_buf_t *b;
14 ngx_uint_t data, do_write;
15 ngx_connection_t *c, *src, *dst;
16 ngx_imap_session_t *s;
17
18 c = ev->data;
19 s = c->data;
20
21 if (c == s->connection) {
22 src = c;
23 dst = s->proxy->connection;
24 b = s->proxy->downstream_buffer;
25
26 } else {
27 src = s->proxy->connection;
28 dst = c;
29 b = s->proxy->upstream_buffer;
30 }
31
32 do_write = ev->write ? 1 : 0;
33
34 do {
35 data = 0;
36
37 if (do_write == 1) {
38 if (dst->write->ready && b->pos < b->last) {
39 n = ngx_send(dst, b->pos, b->last - b->pos);
40
41 if (n == NGX_ERROR) {
42 ngx_imap_proxy_close_session(s);
43 return;
44 }
45
46 if (n > 0) {
47 data = 1;
48 b->pos += n;
49
50 if (b->pos == b->last) {
51 b->pos = b->start;
52 b->last = b->start;
53 }
54 }
55 }
56 }
57
58 if (src->read->ready && b->last < b->end) {
59 n = ngx_recv(src, b->last, b->end - b->last);
60
61 if (n == NGX_ERROR || n == 0) {
62 ngx_imap_proxy_close_session(s);
63 return;
64 }
65
66 if (n > 0) {
67 data = 1;
68 do_write = 1;
69 b->last += n;
70 }
71 }
72
73 } while (data);
74 }
75
76
77 static void ngx_imap_proxy_close_session(ngx_imap_session_t *s)
78 {
79 }