nginx-0.0.10-2004-09-07-19:29:22 import
diff --git a/src/imap/ngx_imap.c b/src/imap/ngx_imap.c
index 900dcb3..13855f1 100644
--- a/src/imap/ngx_imap.c
+++ b/src/imap/ngx_imap.c
@@ -2,6 +2,10 @@
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_event.h>
+#include <ngx_imap.h>
+
+
+static char *ngx_imap_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static ngx_command_t ngx_imap_commands[] = {
@@ -30,5 +34,28 @@
ngx_imap_commands, /* module directives */
NGX_CORE_MODULE, /* module type */
NULL, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
+
+
+static char *ngx_imap_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+ ngx_listening_t *ls;
+
+ /* STUB */
+
+ ls = ngx_listening_inet_stream_socket(cf, 0, 8110);
+ if (ls == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ ls->backlog = -1;
+ ls->handler = ngx_imap_init_connection;
+ ls->pool_size = 16384;
+ /* ls->post_accept_timeout = 0; */
+ ls->log = cf->cycle->new_log;
+
+ /* */
+
+ return NGX_CONF_OK;
+}
diff --git a/src/imap/ngx_imap.h b/src/imap/ngx_imap.h
new file mode 100644
index 0000000..5dc48df
--- /dev/null
+++ b/src/imap/ngx_imap.h
@@ -0,0 +1,32 @@
+#ifndef _NGX_IMAP_H_INCLUDED_
+#define _NGX_IMAP_H_INCLUDED_
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+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
+
+
+void ngx_imap_init_connection(ngx_connection_t *c);
+void ngx_imap_close_connection(ngx_connection_t *c);
+
+
+#endif /* _NGX_IMAP_H_INCLUDED_ */
diff --git a/src/imap/ngx_imap_handler.c b/src/imap/ngx_imap_handler.c
index 635ae02..bbedc9c 100644
--- a/src/imap/ngx_imap_handler.c
+++ b/src/imap/ngx_imap_handler.c
@@ -2,18 +2,56 @@
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_event.h>
+#include <ngx_imap.h>
+#include <nginx.h>
+
+
+static void ngx_imap_auth_state(ngx_event_t *rev);
+
+
+static char pop3_greeting[] = "+OK " NGINX_VER " ready" CRLF;
+static char imap_greeting[] = "* OK " NGINX_VER " ready" CRLF;
void ngx_imap_init_connection(ngx_connection_t *c)
{
+ ngx_int_t rc;
+
ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0,
"imap init connection");
- if (ngx_close_socket(c->fd) == -1) {
+ c->log_error = NGX_ERROR_INFO;
- /* we use ngx_cycle->log because c->log was in c->pool */
+ rc = ngx_send(c, pop3_greeting, sizeof(pop3_greeting) - 1);
- ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno,
- ngx_close_socket_n " failed");
+ if (rc == NGX_ERROR) {
+ ngx_imap_close_connection(c);
+ return;
}
+
+ c->read->event_handler = ngx_imap_auth_state;
+
+ if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) {
+ ngx_imap_close_connection(c);
+ return;
+ }
+}
+
+
+static void ngx_imap_auth_state(ngx_event_t *rev)
+{
+ ngx_connection_t *c;
+
+ c = rev->data;
+
+ ngx_imap_close_connection(c);
+}
+
+
+void ngx_imap_close_connection(ngx_connection_t *c)
+{
+ ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0,
+ "close imap connection: %d", c->fd);
+
+ ngx_close_connection(c);
}
diff --git a/src/imap/ngx_imap_parse.c b/src/imap/ngx_imap_parse.c
new file mode 100644
index 0000000..08ff863
--- /dev/null
+++ b/src/imap/ngx_imap_parse.c
@@ -0,0 +1,68 @@
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+#include <ngx_event.h>
+#include <ngx_imap.h>
+
+
+ngx_int_t ngx_pop3_parse_command(ngx_imap_request_t *r)
+{
+ u_char ch, *p, *c;
+ enum {
+ sw_start = 0,
+ sw_done
+ } state;
+
+ while (p < r->buf->last && state < sw_done) {
+ ch = *p++;
+
+ switch (state) {
+
+ /* POP3 commands */
+ case sw_start:
+ if (ch == ' ') {
+ c = r->buf->start;
+
+ if (p - 1 - m == 4) {
+
+ if (*c == 'U' && *(c + 1) == 'S'
+ && *(c + 2) == 'E' && *(c + 3) == 'R')
+ {
+ r->command = NGX_POP3_USER;
+
+ } else if (*c == 'P' && *(c + 1) == 'A'
+ && *(c + 2) == 'A' && *(c + 3) == 'S')
+ {
+ r->method = NGX_POP3_PASS;
+
+ } else if (*c == 'Q' && *(c + 1) == 'U'
+ && *(c + 2) == 'I' && *(c + 3) == 'T')
+ {
+ r->method = NGX_POP3_QUIT;
+
+ } else if (*c == 'N' && *(c + 1) == 'O'
+ && *(c + 2) == 'O' && *(c + 3) == 'P')
+ {
+ r->method = NGX_POP3_NOOP;
+ }
+ }
+
+ state = sw_spaces_before_arg;
+ break;
+ }
+
+ if (ch < 'A' || ch > 'Z') {
+ return NGX_IMAP_PARSE_INVALID_COMMAND;
+ }
+
+ break;
+ }
+
+ /* suppress warning */
+ case sw_done:
+ break;
+ }
+ }
+
+ return NGX_OK;
+}