diff --git a/auto/lib/md5/conf b/auto/lib/md5/conf index d5b2a0afd..8871038b0 100644 --- a/auto/lib/md5/conf +++ b/auto/lib/md5/conf @@ -40,57 +40,59 @@ if [ $MD5 != NONE ]; then else -ngx_lib_inc="#include + if [ $PLATFORM != win32 ]; then + MD5=NO + + # Solaris 8/9 + + ngx_lib_inc="#include #include " - - MD5=NO - - # Solaris 8/9 - - ngx_lib="rsaref md5" - ngx_lib_test="MD5_CTX md5; MD5Init(&md5)" - ngx_libs=-lmd5 - . auto/lib/test + ngx_lib="rsaref md5 library" + ngx_lib_test="MD5_CTX md5; MD5Init(&md5)" + ngx_libs=-lmd5 + . auto/lib/test - if [ $ngx_found = yes ]; then - CORE_LIBS="$CORE_LIBS $ngx_libs" - MD5=YES - MD5_LIB=md5 - ngx_found=no + if [ $ngx_found = yes ]; then + CORE_LIBS="$CORE_LIBS $ngx_libs" + MD5=YES + MD5_LIB=md5 + ngx_found=no - else - # FreeBSD + else + # FreeBSD - ngx_lib="rsaref md" - ngx_lib_test="MD5_CTX md5; MD5Init(&md5)" - ngx_libs=-lmd - . auto/lib/test + ngx_lib="rsaref md library" + ngx_lib_test="MD5_CTX md5; MD5Init(&md5)" + ngx_libs=-lmd + . auto/lib/test + fi + + + if [ $ngx_found = yes ]; then + CORE_LIBS="$CORE_LIBS $ngx_libs" + MD5=YES + MD5_LIB=md + ngx_found=no + + else + # OpenSSL crypto library + + ngx_inc="#include " + ngx_lib="OpenSSL md5 crypto library" + ngx_lib_test="MD5_CTX md5; MD5_Init(&md5)" + ngx_libs=-lcrypto + . auto/lib/test + fi + + + if [ $ngx_found = yes ]; then + have=HAVE_OPENSSL_MD5 . auto/have + have=HAVE_OPENSSL_MD5_H . auto/have + CORE_LIBS="$CORE_LIBS $ngx_libs" + MD5=YES + MD5_LIB=crypto + fi fi - - if [ $ngx_found = yes ]; then - CORE_LIBS="$CORE_LIBS $ngx_libs" - MD5=YES - MD5_LIB=md - ngx_found=no - - else - # OpenSSL crypto library - - ngx_inc="#include " - ngx_lib="OpenSSL md5 crypto" - ngx_lib_test="MD5_CTX md5; MD5_Init(&md5)" - ngx_libs=-lcrypto - . auto/lib/test - fi - - - if [ $ngx_found = yes ]; then - have=HAVE_OPENSSL_MD5 . auto/have - have=HAVE_OPENSSL_MD5_H . auto/have - CORE_LIBS="$CORE_LIBS $ngx_libs" - MD5=YES - MD5_LIB=crypto - fi fi diff --git a/auto/lib/pcre/conf b/auto/lib/pcre/conf index fa50c24e9..a907e8b50 100644 --- a/auto/lib/pcre/conf +++ b/auto/lib/pcre/conf @@ -40,24 +40,38 @@ if [ $PCRE != NONE ]; then else if [ $PLATFORM != win32 ]; then - ngx_lib_inc="#include " + PCRE=NO - ngx_lib="PCRE" - ngx_lib_test="pcre *re; pcre_compile(re, 0, NULL, 0, NULL)" - ngx_libs=-lpcre - . auto/lib/test + ngx_lib_inc="#include " + ngx_lib="PCRE library" + ngx_lib_test="pcre *re; pcre_compile(re, 0, NULL, 0, NULL)" + ngx_libs=-lpcre + . auto/lib/test if [ $ngx_found = yes ]; then have=HAVE_PCRE . auto/have - CORE_DEPS="$CORE_DEPS $REGEX_DEPS" CORE_SRCS="$CORE_SRCS $REGEX_SRCS" CORE_LIBS="$CORE_LIBS $ngx_libs" - PCRE=YES + else - PCRE=NO + # FreeBSD PCRE port. + + ngx_lib="PCRE library in /usr/local/" + ngx_lib_cflags="-I /usr/local/include" + . auto/lib/test + fi + + + if [ $ngx_found = yes ]; then + have=HAVE_PCRE . auto/have + CORE_DEPS="$CORE_DEPS $REGEX_DEPS" + CORE_INCS="$CORE_INCS /usr/local/include" + CORE_SRCS="$CORE_SRCS $REGEX_SRCS" + CORE_LIBS="$CORE_LIBS $ngx_libs" + PCRE=YES fi fi diff --git a/auto/lib/test b/auto/lib/test index d030655e1..3519a6c5c 100644 --- a/auto/lib/test +++ b/auto/lib/test @@ -1,5 +1,5 @@ -echo $ngx_n "checking for $ngx_lib library ..." $ngx_c +echo $ngx_n "checking for $ngx_lib ..." $ngx_c echo >> $NGX_ERR echo "checking for $ngx_lib library" >> $NGX_ERR @@ -8,7 +8,8 @@ ngx_found=no echo "$ngx_lib_inc" > $NGX_AUTOTEST.c echo "int main() { $ngx_lib_test; return 0; }" >> $NGX_AUTOTEST.c -eval "$CC $cc_test_flags -o $NGX_AUTOTEST $NGX_AUTOTEST.c $ngx_libs \ +eval "$CC $cc_test_flags $ngx_lib_cflags \ + -o $NGX_AUTOTEST $NGX_AUTOTEST.c $ngx_libs \ >> $NGX_ERR 2>&1" if [ -x $NGX_AUTOTEST ]; then diff --git a/auto/lib/zlib/conf b/auto/lib/zlib/conf index 7376abd70..9c2178fad 100644 --- a/auto/lib/zlib/conf +++ b/auto/lib/zlib/conf @@ -34,19 +34,21 @@ if [ $ZLIB != NONE ]; then else - ngx_lib_inc="#include " + if [ $PLATFORM != win32 ]; then + ngx_lib_inc="#include " - ngx_lib="zlib" - ngx_lib_test="z_stream z; deflate(&z, Z_NO_FLUSH)" - ngx_libs=-lz - . auto/lib/test + ngx_lib="zlib library" + ngx_lib_test="z_stream z; deflate(&z, Z_NO_FLUSH)" + ngx_libs=-lz + . auto/lib/test - if [ $ngx_found = yes ]; then - CORE_LIBS="$CORE_LIBS $ngx_libs" - ZLIB=YES - else - ZLIB=NO + if [ $ngx_found = yes ]; then + CORE_LIBS="$CORE_LIBS $ngx_libs" + ZLIB=YES + else + ZLIB=NO + fi fi fi diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h index d1fdab63d..87090dc09 100644 --- a/src/core/ngx_log.h +++ b/src/core/ngx_log.h @@ -6,24 +6,25 @@ #include -#define NGX_LOG_STDERR 0 -#define NGX_LOG_EMERG 1 -#define NGX_LOG_ALERT 2 -#define NGX_LOG_CRIT 3 -#define NGX_LOG_ERR 4 -#define NGX_LOG_WARN 5 -#define NGX_LOG_NOTICE 6 -#define NGX_LOG_INFO 7 -#define NGX_LOG_DEBUG 8 +#define NGX_LOG_STDERR 0 +#define NGX_LOG_EMERG 1 +#define NGX_LOG_ALERT 2 +#define NGX_LOG_CRIT 3 +#define NGX_LOG_ERR 4 +#define NGX_LOG_WARN 5 +#define NGX_LOG_NOTICE 6 +#define NGX_LOG_INFO 7 +#define NGX_LOG_DEBUG 8 -#define NGX_LOG_DEBUG_CORE 0x10 -#define NGX_LOG_DEBUG_ALLOC 0x20 -#define NGX_LOG_DEBUG_EVENT 0x40 -#define NGX_LOG_DEBUG_HTTP 0x80 +#define NGX_LOG_DEBUG_CORE 0x10 +#define NGX_LOG_DEBUG_ALLOC 0x20 +#define NGX_LOG_DEBUG_EVENT 0x40 +#define NGX_LOG_DEBUG_HTTP 0x80 -#define NGX_LOG_DEBUG_FIRST NGX_LOG_DEBUG_CORE -#define NGX_LOG_DEBUG_LAST NGX_LOG_DEBUG_HTTP -#define NGX_LOG_DEBUG_ALL 0xfffffff0 +#define NGX_LOG_DEBUG_FIRST NGX_LOG_DEBUG_CORE +#define NGX_LOG_DEBUG_LAST NGX_LOG_DEBUG_HTTP +#define NGX_LOG_DEBUG_CONNECTION 0x80000000 +#define NGX_LOG_DEBUG_ALL 0x7ffffff0 /* diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c index c339660db..abc577b1e 100644 --- a/src/event/modules/ngx_kqueue_module.c +++ b/src/event/modules/ngx_kqueue_module.c @@ -22,6 +22,8 @@ static int ngx_kqueue_add_event(ngx_event_t *ev, int event, u_int flags); static int ngx_kqueue_del_event(ngx_event_t *ev, int event, u_int flags); static int ngx_kqueue_set_event(ngx_event_t *ev, int filter, u_int flags); static int ngx_kqueue_process_events(ngx_cycle_t *cycle); +static ngx_inline void ngx_kqueue_dump_event(ngx_log_t *log, + struct kevent *kev); static void *ngx_kqueue_create_conf(ngx_cycle_t *cycle); static char *ngx_kqueue_init_conf(ngx_cycle_t *cycle, void *conf); @@ -443,17 +445,7 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle) for (i = 0; i < events; i++) { - ngx_log_debug6(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - - (event_list[i].ident > 0x8000000 - && event_list[i].ident != (unsigned) -1) ? - "kevent: " PTR_FMT ": ft:%d fl:%04X ff:%08X d:%d ud:" - PTR_FMT: - "kevent: %d: ft:%d fl:%04X ff:%08X d:%d ud:" PTR_FMT, - - event_list[i].ident, event_list[i].filter, - event_list[i].flags, event_list[i].fflags, - event_list[i].data, event_list[i].udata); + ngx_kqueue_dump_event(cycle->log, &event_list[i]); if (event_list[i].flags & EV_ERROR) { ngx_log_error(NGX_LOG_ALERT, cycle->log, event_list[i].data, @@ -472,6 +464,10 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle) ev = (ngx_event_t *) ((uintptr_t) ev & (uintptr_t) ~1); ev->returned_instance = instance; + if (ev->log && (ev->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { + ngx_kqueue_dump_event(ev->log, &event_list[i]); + } + if (!ev->active || ev->instance != instance) { /* @@ -560,6 +556,19 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle) } +static ngx_inline void ngx_kqueue_dump_event(ngx_log_t *log, struct kevent *kev) +{ + ngx_log_debug6(NGX_LOG_DEBUG_EVENT, log, 0, + (kev->ident > 0x8000000 && kev->ident != (unsigned) -1) ? + "kevent: " PTR_FMT ": ft:%d fl:%04X ff:%08X d:%d ud:" + PTR_FMT: + "kevent: %d: ft:%d fl:%04X ff:%08X d:%d ud:" PTR_FMT, + kev->ident, kev->filter, + kev->flags, kev->fflags, + kev->data, kev->udata); +} + + static void *ngx_kqueue_create_conf(ngx_cycle_t *cycle) { ngx_kqueue_conf_t *kcf; diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c index ebb56ce84..c5ea45d2c 100644 --- a/src/event/ngx_event.c +++ b/src/event/ngx_event.c @@ -35,6 +35,8 @@ static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char *ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); +static char *ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf); static void *ngx_event_create_conf(ngx_cycle_t *cycle); static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf); @@ -117,6 +119,13 @@ static ngx_command_t ngx_event_core_commands[] = { offsetof(ngx_event_conf_t, accept_mutex_delay), NULL }, + { ngx_string("debug_connection"), + NGX_EVENT_CONF|NGX_CONF_TAKE1, + ngx_event_debug_connection, + 0, + 0, + NULL }, + ngx_null_command }; @@ -517,6 +526,52 @@ static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) } +static char *ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf) +{ +#if (NGX_DEBUG) + ngx_event_conf_t *ecf = conf; + + in_addr_t *addr; + ngx_str_t *value; + struct hostent *h; + + value = cf->args->elts; + + /* AF_INET only */ + + if (!(addr = ngx_push_array(&ecf->debug_connection))) { + return NGX_CONF_ERROR; + } + + *addr = inet_addr((char *) value[1].data); + + if (*addr != INADDR_NONE) { + return NGX_OK; + } + + h = gethostbyname((char *) value[1].data); + + if (h == NULL || h->h_addr_list[0] == NULL) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "host %s not found", value[1].data); + return NGX_CONF_ERROR; + } + + *addr = *(in_addr_t *)(h->h_addr_list[0]); + +#else + + ngx_conf_log_error(NGX_LOG_WARN, cf, 0, + "\"debug_connection\" is ignored, you need to rebuild " + "nginx using --with-debug option to enable it"); + +#endif + + return NGX_OK; +} + + static void *ngx_event_create_conf(ngx_cycle_t *cycle) { ngx_event_conf_t *ecf; @@ -531,6 +586,11 @@ static void *ngx_event_create_conf(ngx_cycle_t *cycle) ecf->accept_mutex_delay = NGX_CONF_UNSET_MSEC; ecf->name = (void *) NGX_CONF_UNSET; +#if (NGX_DEBUG) + ngx_init_array(ecf->debug_connection, cycle->pool, 5, sizeof(in_addr_t), + NGX_CONF_ERROR); +#endif + return ecf; } diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h index 1dcfe5066..433d6cffc 100644 --- a/src/event/ngx_event.h +++ b/src/event/ngx_event.h @@ -381,15 +381,19 @@ extern ngx_event_actions_t ngx_event_actions; typedef struct { - ngx_int_t connections; - ngx_int_t use; + ngx_int_t connections; + ngx_int_t use; - ngx_flag_t multi_accept; - ngx_flag_t accept_mutex; + ngx_flag_t multi_accept; + ngx_flag_t accept_mutex; - ngx_msec_t accept_mutex_delay; + ngx_msec_t accept_mutex_delay; - u_char *name; + u_char *name; + +#if (NGX_DEBUG) + ngx_array_t debug_connection; +#endif } ngx_event_conf_t; diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c index c955bbfa3..70db78d71 100644 --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -275,6 +275,25 @@ void ngx_event_accept(ngx_event_t *ev) ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, "accept: fd:%d c:%d", s, c->number); +#if (NGX_DEBUG) + { + + uint32_t *addr; + in_addr_t i; + struct sockaddr_in *addr_in; + + addr_in = (struct sockaddr_in *) sa; + addr = ecf->debug_connection.elts; + for (i = 0; i < ecf->debug_connection.nelts; i++) { + if (addr[i] == addr_in->sin_addr.s_addr) { + log->log_level = NGX_LOG_DEBUG_CONNECTION|NGX_LOG_DEBUG_ALL; + break; + } + } + + } +#endif + if (ngx_add_conn) { if (ngx_add_conn(c) == NGX_ERROR) { if (ngx_close_socket(s) == -1) { diff --git a/src/http/modules/ngx_http_charset_filter.c b/src/http/modules/ngx_http_charset_filter.c index a545eafa1..052a1f822 100644 --- a/src/http/modules/ngx_http_charset_filter.c +++ b/src/http/modules/ngx_http_charset_filter.c @@ -62,6 +62,12 @@ static int ngx_http_charset_header_filter(ngx_http_request_t *r) { ngx_http_charset_loc_conf_t *lcf; + lcf = ngx_http_get_module_loc_conf(r, ngx_http_charset_filter_module); + + if (lcf->default_charset.len == 0) { + return ngx_http_next_header_filter(r); + } + if (r->headers_out.content_type == NULL || ngx_strncasecmp(r->headers_out.content_type->value.data, "text/", 5) != 0 @@ -72,8 +78,6 @@ static int ngx_http_charset_header_filter(ngx_http_request_t *r) return ngx_http_next_header_filter(r); } - lcf = ngx_http_get_module_loc_conf(r, ngx_http_charset_filter_module); - if (r->headers_out.status == NGX_HTTP_MOVED_PERMANENTLY && r->headers_out.status == NGX_HTTP_MOVED_TEMPORARILY) { @@ -135,7 +139,7 @@ static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf, ngx_http_charset_loc_conf_t *conf = child; ngx_conf_merge_str_value(conf->default_charset, - prev->default_charset, "koi8-r"); + prev->default_charset, ""); return NGX_CONF_OK; } diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 3ae61829f..6b0db2625 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -482,7 +482,9 @@ int ngx_http_find_location_config(ngx_http_request_t *r) r->loc_conf = clcfp[i]->loc_conf; clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); r->connection->log->file = clcf->err_log->file; - r->connection->log->log_level = clcf->err_log->log_level; + if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { + r->connection->log->log_level = clcf->err_log->log_level; + } if (clcfp[i]->exact_match && r->uri.len == clcfp[i]->name.len) { #if (HAVE_PCRE) @@ -529,7 +531,9 @@ int ngx_http_find_location_config(ngx_http_request_t *r) r->loc_conf = clcfp[i]->loc_conf; clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); r->connection->log->file = clcf->err_log->file; - r->connection->log->log_level = clcf->err_log->log_level; + if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { + r->connection->log->log_level = clcf->err_log->log_level; + } break; } diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index a2a0feda6..9233f89d8 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -231,7 +231,9 @@ static void ngx_http_init_request(ngx_event_t *rev) clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); c->log->file = clcf->err_log->file; - c->log->log_level = clcf->err_log->log_level; + if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { + c->log->log_level = clcf->err_log->log_level; + } if (c->buffer == NULL) { c->buffer = ngx_create_temp_hunk(c->pool, diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c index 5fa144fbc..8c1a98a91 100644 --- a/src/http/ngx_http_write_filter.c +++ b/src/http/ngx_http_write_filter.c @@ -133,7 +133,7 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) * the size of the hunks is smaller than "postpone_output" directive */ - if (!last && flush == 0 && size < conf->postpone_output) { + if (!last && flush == 0 && size < (off_t) conf->postpone_output) { return NGX_OK; }