comparison src/imap/ngx_imap_handler.c @ 417:0526206251f6

nginx-0.0.10-2004-09-07-19:29:22 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 07 Sep 2004 15:29:22 +0000
parents 3c56e834be46
children cf072d26d6d6
comparison
equal deleted inserted replaced
416:b9bd635011de 417:0526206251f6
1 1
2 #include <ngx_config.h> 2 #include <ngx_config.h>
3 #include <ngx_core.h> 3 #include <ngx_core.h>
4 #include <ngx_event.h> 4 #include <ngx_event.h>
5 #include <ngx_imap.h>
6 #include <nginx.h>
7
8
9 static void ngx_imap_auth_state(ngx_event_t *rev);
10
11
12 static char pop3_greeting[] = "+OK " NGINX_VER " ready" CRLF;
13 static char imap_greeting[] = "* OK " NGINX_VER " ready" CRLF;
5 14
6 15
7 void ngx_imap_init_connection(ngx_connection_t *c) 16 void ngx_imap_init_connection(ngx_connection_t *c)
8 { 17 {
18 ngx_int_t rc;
19
9 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, 20 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0,
10 "imap init connection"); 21 "imap init connection");
11 22
12 if (ngx_close_socket(c->fd) == -1) { 23 c->log_error = NGX_ERROR_INFO;
13 24
14 /* we use ngx_cycle->log because c->log was in c->pool */ 25 rc = ngx_send(c, pop3_greeting, sizeof(pop3_greeting) - 1);
15 26
16 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno, 27 if (rc == NGX_ERROR) {
17 ngx_close_socket_n " failed"); 28 ngx_imap_close_connection(c);
29 return;
30 }
31
32 c->read->event_handler = ngx_imap_auth_state;
33
34 if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) {
35 ngx_imap_close_connection(c);
36 return;
18 } 37 }
19 } 38 }
39
40
41 static void ngx_imap_auth_state(ngx_event_t *rev)
42 {
43 ngx_connection_t *c;
44
45 c = rev->data;
46
47 ngx_imap_close_connection(c);
48 }
49
50
51 void ngx_imap_close_connection(ngx_connection_t *c)
52 {
53 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0,
54 "close imap connection: %d", c->fd);
55
56 ngx_close_connection(c);
57 }