From d3283ff9224a41a1a24c2d89f671811c0747480a Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Mon, 5 Dec 2005 13:18:09 +0000 Subject: nginx-0.3.13-RELEASE import *) Feature: the IMAP/POP3 proxy supports STARTTLS and STLS. *) Bugfix: the IMAP/POP3 proxy did not work with the select, poll, and /dev/poll methods. *) Bugfix: in SSI handling. *) Bugfix: now Solaris sendfilev() is not used to transfer the client request body to FastCGI-server via the unix domain socket. *) Bugfix: the "auth_basic" directive did not disable the authorization; the bug had appeared in 0.3.11. --- src/core/nginx.h | 2 +- src/core/ngx_conf_file.c | 2 + src/core/ngx_connection.h | 3 +- src/core/ngx_hash.c | 12 +++ src/core/ngx_palloc.c | 6 +- src/core/ngx_rbtree.h | 2 +- src/core/ngx_resolver.c | 183 ++++++++++++++++++++++++++++++++++++++++++++++ src/core/ngx_string.c | 16 ++++ src/core/ngx_string.h | 9 +++ 9 files changed, 229 insertions(+), 6 deletions(-) create mode 100644 src/core/ngx_resolver.c (limited to 'src/core') diff --git a/src/core/nginx.h b/src/core/nginx.h index 44b15f9f2..9505aee96 100644 --- a/src/core/nginx.h +++ b/src/core/nginx.h @@ -8,7 +8,7 @@ #define _NGINX_H_INCLUDED_ -#define NGINX_VER "nginx/0.3.12" +#define NGINX_VER "nginx/0.3.13" #define NGINX_VAR "NGINX" #define NGX_OLDPID_EXT ".oldbin" diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c index d89fa7f32..377cad5bc 100644 --- a/src/core/ngx_conf_file.c +++ b/src/core/ngx_conf_file.c @@ -182,6 +182,8 @@ ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename) if (filename) { + ngx_pfree(cf->pool, cf->conf_file->buffer->start); + cf->conf_file = prev; if (ngx_close_file(fd) == NGX_FILE_ERROR) { diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h index 279efb689..38a59bcb1 100644 --- a/src/core/ngx_connection.h +++ b/src/core/ngx_connection.h @@ -140,7 +140,8 @@ struct ngx_connection_s { unsigned single_connection:1; unsigned unexpected_eof:1; unsigned timedout:1; - unsigned closed:1; + unsigned error:1; + unsigned destroyed:1; unsigned sendfile:1; unsigned sndlowat:1; diff --git a/src/core/ngx_hash.c b/src/core/ngx_hash.c index 6b75fa598..9d41df63b 100644 --- a/src/core/ngx_hash.c +++ b/src/core/ngx_hash.c @@ -47,6 +47,10 @@ ngx_hash_init(ngx_hash_t *hash, ngx_pool_t *pool, void *names, ngx_uint_t nelts) n < nelts; n++, name = (ngx_str_t *) ((char *) name + hash->bucket_size)) { + if (name->data == NULL) { + continue; + } + key = 0; for (i = 0; i < name->len; i++) { @@ -104,6 +108,10 @@ ngx_hash_init(ngx_hash_t *hash, ngx_pool_t *pool, void *names, ngx_uint_t nelts) n < nelts; n++, name = (ngx_str_t *) ((char *) name + hash->bucket_size)) { + if (name->data == NULL) { + continue; + } + key = 0; for (i = 0; i < name->len; i++) { @@ -135,6 +143,10 @@ ngx_hash_init(ngx_hash_t *hash, ngx_pool_t *pool, void *names, ngx_uint_t nelts) n < nelts; n++, name = (ngx_str_t *) ((char *) name + hash->bucket_size)) { + if (name->data == NULL) { + continue; + } + key = 0; for (i = 0; i < name->len; i++) { diff --git a/src/core/ngx_palloc.c b/src/core/ngx_palloc.c index a1f9d59cd..3bb0b3598 100644 --- a/src/core/ngx_palloc.c +++ b/src/core/ngx_palloc.c @@ -102,7 +102,7 @@ ngx_palloc(ngx_pool_t *pool, size_t size) } if ((size_t) (p->end - m) < NGX_ALIGNMENT) { - p->current = p->next; + pool->current = p->next; } if (p->next == NULL) { @@ -117,8 +117,8 @@ ngx_palloc(ngx_pool_t *pool, size_t size) return NULL; } - if (p->current == NULL) { - p->current = n; + if (pool->current == NULL) { + pool->current = n; } p->next = n; diff --git a/src/core/ngx_rbtree.h b/src/core/ngx_rbtree.h index 1b1322d3c..a57ec778d 100644 --- a/src/core/ngx_rbtree.h +++ b/src/core/ngx_rbtree.h @@ -29,7 +29,7 @@ struct ngx_rbtree_node_s { typedef struct ngx_rbtree_s ngx_rbtree_t; -typedef ngx_rbtree_t *(*ngx_rbtree_insert_pt) (ngx_rbtree_node_t *root, +typedef ngx_rbtree_node_t *(*ngx_rbtree_insert_pt) (ngx_rbtree_node_t *root, ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel); struct ngx_rbtree_s { diff --git a/src/core/ngx_resolver.c b/src/core/ngx_resolver.c new file mode 100644 index 000000000..cf47cd8f5 --- /dev/null +++ b/src/core/ngx_resolver.c @@ -0,0 +1,183 @@ + +/* + * Copyright (C) Igor Sysoev + */ + + +#include +#include +#include + + +typedef struct { + ngx_connection_t *connection; + + struct sockaddr *sockaddr; + socklen_t socklen; + + ngx_str_r server; + ngx_str_r name; + + ngx_event_handler_pt handler; + + ngx_log_t *pool; + ngx_log_t *log; +} ngx_resolver_t; + + +ngx_int_t +ngx_gethostbyname(ngx_resolver_t *r) +{ + ngx_socket_t s; + + if (r->connection) { + return NGX_OK; + } + + s = ngx_socket(AF_INET, SOCK_DGRAM, 0); + + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, r->log, 0, "socket %d", s); + + if (s == -1) { + ngx_log_error(NGX_LOG_ALERT, r->log, ngx_socket_errno, + ngx_socket_n " failed"); + return NGX_ERROR; + } + + c = ngx_get_connection(s, r->log); + + if (c == NULL) { + if (ngx_close_socket(s) == -1) { + ngx_log_error(NGX_LOG_ALERT, r->log, ngx_socket_errno, + ngx_close_socket_n "failed"); + } + + return NGX_ERROR; + } + + rev = c->read; + wev = c->write; + + rev->log = pc->log; + wev->log = pc->log; + + r->connection = c; + + /* + * TODO: MT: - ngx_atomic_fetch_add() + * or protection by critical section or mutex + * + * TODO: MP: - allocated in a shared memory + * - ngx_atomic_fetch_add() + * or protection by critical section or mutex + */ + + c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1); + +#if (NGX_THREADS) + rev->lock = pc->lock; + wev->lock = pc->lock; + rev->own_lock = &c->lock; + wev->own_lock = &c->lock; +#endif + + ngx_log_debug3(NGX_LOG_DEBUG_EVENT, pc->log, 0, + "connect to %V, fd:%d #%d", &r->server, s, c->number); + + rc = connect(s, r->sockaddr, r->socklen); + + if (rc == -1) { + ngx_log_error(level, r->log, ngx_socket_errno, + "connect() to %V failed", &r->server); + + return NGX_ERROR; + } + + + + + + + + if (ngx_add_conn) { + if (ngx_add_conn(c) == NGX_ERROR) { + return NGX_ERROR; + } + } + + + if (ngx_add_conn) { + if (rc == -1) { + + /* NGX_EINPROGRESS */ + + return NGX_AGAIN; + } + + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, pc->log, 0, "connected"); + + wev->ready = 1; + + return NGX_OK; + } + + if (ngx_event_flags & NGX_USE_AIO_EVENT) { + + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pc->log, ngx_socket_errno, + "connect(): %d", rc); + + /* aio, iocp */ + + if (ngx_blocking(s) == -1) { + ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, + ngx_blocking_n " failed"); + return NGX_ERROR; + } + + /* + * FreeBSD's aio allows to post an operation on non-connected socket. + * NT does not support it. + * + * TODO: check in Win32, etc. As workaround we can use NGX_ONESHOT_EVENT + */ + + rev->ready = 1; + wev->ready = 1; + + return NGX_OK; + } + + if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { + + /* kqueue */ + + event = NGX_CLEAR_EVENT; + + } else { + + /* select, poll, /dev/poll */ + + event = NGX_LEVEL_EVENT; + } + + if (ngx_add_event(rev, NGX_READ_EVENT, event) != NGX_OK) { + return NGX_ERROR; + } + + if (rc == -1) { + + /* NGX_EINPROGRESS */ + + if (ngx_add_event(wev, NGX_WRITE_EVENT, event) != NGX_OK) { + return NGX_ERROR; + } + + return NGX_AGAIN; + } + + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, pc->log, 0, "connected"); + + wev->ready = 1; + + return NGX_OK; +} diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c index fc3738234..f042d7c33 100644 --- a/src/core/ngx_string.c +++ b/src/core/ngx_string.c @@ -1036,3 +1036,19 @@ done: *dst = d; *src = s; } + + +#if (NGX_MEMCPY_LIMIT) + +void * +ngx_memcpy(void *dst, void *src, size_t n) +{ + if (n > NGX_MEMCPY_LIMIT) { + ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "memcpy %uz bytes", n); + ngx_debug_point(); + } + + return memcpy(dst, src, n); +} + +#endif diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h index 0bee98bb3..0192a3068 100644 --- a/src/core/ngx_string.h +++ b/src/core/ngx_string.h @@ -63,6 +63,13 @@ typedef struct { #define ngx_memset(buf, c, n) (void) memset(buf, c, n) +#if (NGX_MEMCPY_LIMIT) + +void *ngx_memcpy(void *dst, void *src, size_t n); +#define ngx_cpymem(dst, src, n) ((u_char *) ngx_memcpy(dst, src, n)) + (n) + +#else + /* * gcc3, msvc, and icc7 compile memcpy() to the inline "rep movs". * gcc3 compiles memcpy(d, s, 4) to the inline "mov"es. @@ -71,6 +78,8 @@ typedef struct { #define ngx_memcpy(dst, src, n) (void) memcpy(dst, src, n) #define ngx_cpymem(dst, src, n) ((u_char *) memcpy(dst, src, n)) + (n) +#endif + #if ( __INTEL_COMPILER >= 800 ) -- cgit v1.2.3