nginx-0.0.10-2004-09-13-20:18:09 import

This commit is contained in:
Igor Sysoev 2004-09-13 16:18:09 +00:00
parent 32e5771747
commit 0292cbbe35
10 changed files with 87 additions and 34 deletions

View File

@ -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
};

View File

@ -394,7 +394,7 @@ extern ngx_event_actions_t ngx_event_actions;
#define NGX_EVENT_MODULE 0x544E5645 /* "EVNT" */
#define NGX_EVENT_CONF 0x00200000
#define NGX_EVENT_CONF 0x02000000
typedef struct {

View File

@ -418,10 +418,10 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
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 *cf, ngx_command_t *cmd, void *conf)
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 ... */

View File

@ -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;

View File

@ -206,7 +206,7 @@ static ngx_int_t ngx_http_header_filter(ngx_http_request_t *r)
+ 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(ngx_http_request_t *r)
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,

View File

@ -202,7 +202,7 @@ static void ngx_http_init_request(ngx_event_t *rev)
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;

View File

@ -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;

View File

@ -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);

View File

@ -58,7 +58,11 @@ static void ngx_imap_init_session(ngx_event_t *rev)
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_event_t *rev)
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);

View File

@ -41,10 +41,17 @@ void ngx_imap_proxy_init(ngx_imap_session_t *s)
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(ngx_event_t *rev)
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_event_t *ev)
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_event_t *ev)
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_event_t *ev)
}
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_event_t *ev)
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_event_t *ev)
}
if (n > 0) {
data = 1;
again = 1;
do_write = 1;
b->last += n;
}
@ -323,7 +363,7 @@ static void ngx_imap_proxy_handler(ngx_event_t *ev)
}
}
} while (data);
} while (again);
}