# HG changeset patch # User Igor Sysoev # Date 1095092289 0 # Node ID fda5987b188dd5f3d92010ee617132d147a4726b # Parent edaefb2a20fc2acff2532abdb3fa5161cc96d8fe nginx-0.0.10-2004-09-13-20:18:09 import diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h --- a/src/core/ngx_conf_file.h +++ b/src/core/ngx_conf_file.h @@ -91,15 +91,15 @@ struct ngx_open_file_s { struct ngx_module_s { - ngx_uint_t ctx_index; - ngx_uint_t index; - void *ctx; - ngx_command_t *commands; - ngx_uint_t type; - ngx_int_t (*init_module)(ngx_cycle_t *cycle); - ngx_int_t (*init_process)(ngx_cycle_t *cycle); + ngx_uint_t ctx_index; + ngx_uint_t index; + void *ctx; + ngx_command_t *commands; + ngx_uint_t type; + ngx_int_t (*init_module)(ngx_cycle_t *cycle); + ngx_int_t (*init_process)(ngx_cycle_t *cycle); #if 0 - ngx_int_t (*init_thread)(ngx_cycle_t *cycle); + ngx_int_t (*init_thread)(ngx_cycle_t *cycle); #endif }; diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h --- a/src/event/ngx_event.h +++ b/src/event/ngx_event.h @@ -394,7 +394,7 @@ extern ngx_event_actions_t ngx_event_a #define NGX_EVENT_MODULE 0x544E5645 /* "EVNT" */ -#define NGX_EVENT_CONF 0x00200000 +#define NGX_EVENT_CONF 0x02000000 typedef struct { diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c @@ -418,10 +418,10 @@ static char *ngx_http_block(ngx_conf_t * in_port->port = lscf[l].port; - ngx_test_null(in_port->port_name.data, ngx_palloc(cf->pool, 7), + ngx_test_null(in_port->port_text.data, ngx_palloc(cf->pool, 7), NGX_CONF_ERROR); - in_port->port_name.len = ngx_snprintf((char *) - in_port->port_name.data, + in_port->port_text.len = ngx_snprintf((char *) + in_port->port_text.data, 7, ":%d", in_port->port); @@ -549,7 +549,7 @@ static char *ngx_http_block(ngx_conf_t * NGX_CONF_ERROR); inport->port = in_port[p].port; - inport->port_name = in_port[p].port_name; + inport->port_text = in_port[p].port_text; /* init list of the addresses ... */ diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h --- a/src/http/ngx_http_core_module.h +++ b/src/http/ngx_http_core_module.h @@ -79,7 +79,7 @@ typedef struct { typedef struct { in_port_t port; - ngx_str_t port_name; + ngx_str_t port_text; ngx_array_t addrs; /* array of ngx_http_in_addr_t */ } ngx_http_in_port_t; diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c --- a/src/http/ngx_http_header_filter.c +++ b/src/http/ngx_http_header_filter.c @@ -206,7 +206,7 @@ static ngx_int_t ngx_http_header_filter( + r->server_name->len + r->headers_out.location->value.len + 2; if (r->port != 80) { - len += r->port_name->len; + len += r->port_text->len; } } @@ -325,8 +325,8 @@ static ngx_int_t ngx_http_header_filter( b->last = ngx_cpymem(b->last, r->server_name->data, r->server_name->len); if (r->port != 80) { - b->last = ngx_cpymem(b->last, r->port_name->data, - r->port_name->len); + b->last = ngx_cpymem(b->last, r->port_text->data, + r->port_text->len); } b->last = ngx_cpymem(b->last, r->headers_out.location->value.data, diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -202,7 +202,7 @@ static void ngx_http_init_request(ngx_ev in_addr = in_port->addrs.elts; r->port = in_port->port; - r->port_name = &in_port->port_name; + r->port_text = &in_port->port_text; i = 0; diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h --- a/src/http/ngx_http_request.h +++ b/src/http/ngx_http_request.h @@ -257,7 +257,7 @@ struct ngx_http_request_s { uint32_t in_addr; ngx_uint_t port; - ngx_str_t *port_name; /* ":80" */ + ngx_str_t *port_text; /* ":80" */ ngx_str_t *server_name; ngx_array_t *virtual_names; diff --git a/src/imap/ngx_imap.h b/src/imap/ngx_imap.h --- a/src/imap/ngx_imap.h +++ b/src/imap/ngx_imap.h @@ -66,6 +66,11 @@ typedef struct { #define NGX_IMAP_PROXY_ERROR 11 +#define NGX_IMAP_MODULE 0x50414D49 /* "IMAP" */ + +#define NGX_IMAP_CONF 0x02000000 + + void ngx_imap_init_connection(ngx_connection_t *c); void ngx_imap_close_connection(ngx_connection_t *c); diff --git a/src/imap/ngx_imap_handler.c b/src/imap/ngx_imap_handler.c --- a/src/imap/ngx_imap_handler.c +++ b/src/imap/ngx_imap_handler.c @@ -58,7 +58,11 @@ static void ngx_imap_init_session(ngx_ev c = rev->data; - /* TODO: timeout */ + if (rev->timedout) { + ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); + ngx_imap_close_connection(c); + return; + } if (!(s = ngx_pcalloc(c->pool, sizeof(ngx_imap_session_t)))) { ngx_imap_close_connection(c); @@ -102,7 +106,11 @@ static void ngx_pop3_auth_state(ngx_even ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, "pop3 auth state"); - /* TODO: timeout */ + if (rev->timedout) { + ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); + ngx_imap_close_connection(c); + return; + } rc = ngx_pop3_read_command(s); diff --git a/src/imap/ngx_imap_proxy.c b/src/imap/ngx_imap_proxy.c --- a/src/imap/ngx_imap_proxy.c +++ b/src/imap/ngx_imap_proxy.c @@ -41,10 +41,17 @@ void ngx_imap_proxy_init(ngx_imap_sessio peers->number = 1; peers->max_fails = 1; +#if 0 peers->peers[0].addr = inet_addr("81.19.69.70"); peers->peers[0].addr_port_text.len = sizeof("81.19.69.70:110") - 1; peers->peers[0].addr_port_text.data = "81.19.69.70:110"; peers->peers[0].port = htons(110); +#else + peers->peers[0].addr = inet_addr("81.19.64.101"); + peers->peers[0].addr_port_text.len = sizeof("81.19.64.101:110") - 1; + peers->peers[0].addr_port_text.data = "81.19.64.101:110"; + peers->peers[0].port = htons(110); +#endif rc = ngx_event_connect_peer(&p->upstream); @@ -91,6 +98,12 @@ static void ngx_imap_proxy_auth_handler( c = rev->data; s = c->data; + if (rev->timedout) { + ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); + ngx_imap_proxy_close_session(s); + return; + } + if (s->proxy->buffer == NULL) { s->proxy->buffer = ngx_create_temp_buf(c->pool, /* STUB */ 4096); if (s->proxy->buffer == NULL) { @@ -238,22 +251,49 @@ static void ngx_imap_proxy_handler(ngx_e size_t size; ssize_t n; ngx_buf_t *b; - ngx_uint_t data, do_write; + ngx_uint_t again, do_write; ngx_connection_t *c, *src, *dst; ngx_imap_session_t *s; c = ev->data; s = c->data; + if (ev->timedout) { + if (c == s->connection) { + ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, + "client timed out"); + } else { + ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, + "upstream timed out"); + } + + ngx_imap_proxy_close_session(s); + return; + } + if (c == s->connection) { - src = c; - dst = s->proxy->upstream.connection; - b = s->buffer; + if (ev->write) { + src = s->proxy->upstream.connection; + dst = c; + b = s->proxy->buffer; + + } else { + src = c; + dst = s->proxy->upstream.connection; + b = s->buffer; + } } else { - src = c; - dst = s->connection; - b = s->proxy->buffer; + if (ev->write) { + src = s->connection; + dst = c; + b = s->buffer; + + } else { + src = c; + dst = s->connection; + b = s->proxy->buffer; + } } do_write = ev->write ? 1 : 0; @@ -263,13 +303,13 @@ static void ngx_imap_proxy_handler(ngx_e do_write, src->fd, dst->fd); do { - data = 0; + again = 0; if (do_write == 1) { size = b->last - b->pos; - if (dst->write->ready && size) { + if (size && dst->write->ready) { n = ngx_send(dst, b->pos, size); if (n == NGX_ERROR) { @@ -278,7 +318,7 @@ static void ngx_imap_proxy_handler(ngx_e } if (n > 0) { - data = 1; + again = 1; b->pos += n; if (b->pos == b->last) { @@ -301,7 +341,7 @@ static void ngx_imap_proxy_handler(ngx_e size = b->end - b->last; - if (src->read->ready && size) { + if (size && src->read->ready) { n = ngx_recv(src, b->last, size); if (n == NGX_ERROR || n == 0) { @@ -310,7 +350,7 @@ static void ngx_imap_proxy_handler(ngx_e } if (n > 0) { - data = 1; + again = 1; do_write = 1; b->last += n; } @@ -323,7 +363,7 @@ static void ngx_imap_proxy_handler(ngx_e } } - } while (data); + } while (again); }