Compare commits

...

96 Commits

Author SHA1 Message Date
Igor Sysoev 0338943b71 release-0.6.39 tag 2009-09-14 13:13:22 +00:00
Igor Sysoev f3f1513422 nginx-0.6.39-RELEASE 2009-09-14 13:13:21 +00:00
Igor Sysoev fea0cb7118 merge 2411:
handle "/../" case more reliably
2009-09-07 11:57:04 +00:00
Igor Sysoev 14c4d27e85 merge r3076, r3080:
fix segfault when a header starts with "\rX"
and logging is set to info or debug level
2009-09-07 11:54:51 +00:00
Igor Sysoev c712d68209 bump version 2009-09-07 11:53:09 +00:00
Igor Sysoev e9692d0c10 release-0.6.38 tag 2009-06-22 10:11:56 +00:00
Igor Sysoev 48da7b4f02 nginx-0.6.38-RELEASE 2009-06-22 10:11:55 +00:00
Igor Sysoev 96ee7035a4 merge r2889:
keepalive_requests
2009-06-22 09:50:51 +00:00
Igor Sysoev add97522c2 bump version 2009-06-22 09:43:52 +00:00
Igor Sysoev 83c37fee7d release-0.6.37 tag 2009-05-18 16:29:58 +00:00
Igor Sysoev a45a289913 nginx-0.6.37-RELEASE 2009-05-18 16:29:57 +00:00
Igor Sysoev 379dd67026 r2821 merge:
test already destroyed request
2009-05-18 16:19:49 +00:00
Igor Sysoev 9340000e4e r2756 merge:
add quotes for configure options with spaces
2009-05-18 16:17:51 +00:00
Igor Sysoev 394b5de7a4 r2754 merge:
merge SSL context inside "if" block
2009-05-18 16:13:02 +00:00
Igor Sysoev 4764c735ef r2719 merge:
fix building on platforms which have no atomic operations support,
the bug was introduced in r2653 (r2564 in trunk)
2009-05-18 16:05:02 +00:00
Igor Sysoev 13433f719a r2614 merge:
update cpuid for Core 2 and Atom
2009-05-18 16:02:06 +00:00
Igor Sysoev 3a98a9da5c r2496, r2749 merge:
compatibility with Microsoft's
    AUTH LOGIN [base64 encoded user name ]
patch by Maxim Dounin
2009-05-18 15:58:46 +00:00
Igor Sysoev a745b22650 r2296 merge:
fix r2105 (r2067 in trunk)
2009-05-18 15:39:08 +00:00
Igor Sysoev 786a2bc835 bump version 2009-05-18 15:36:12 +00:00
Igor Sysoev de0667e0f9 release-0.6.36 tag 2009-04-02 06:48:51 +00:00
Igor Sysoev d5a9869296 nginx-0.6.36-RELEASE 2009-04-02 06:48:50 +00:00
Igor Sysoev f3014dc746 r2202, r2408, r2425, r2454, r2459, r2482, r2504, r2542, r2565, r2579,
r2580, r2585, r2586, r2587, r2591, r2626 merge:

try_files
2009-04-02 06:44:45 +00:00
Igor Sysoev 50eb90a22f r2582, r2583 merge:
--with-pcre
2009-04-01 16:44:53 +00:00
Igor Sysoev 9ba4a1bd96 r2561 merge:
ignore EINVAL from setsockopt() on Solaris
2009-04-01 16:42:09 +00:00
Igor Sysoev b6db56da3b r2564 merge:
compatibility with Tru64 UNIX: fcntl(F_SETLK, F_WRLCK) returns EINVAL if busy
2009-04-01 16:39:29 +00:00
Igor Sysoev 39be0dc53f r2581 merge:
test wildcard tail hash existance
2009-04-01 16:36:47 +00:00
Igor Sysoev 254e886549 r2505 merge:
load SSL engine before certificates,
otherwise RSA keys will use built-in RSA methods
2009-04-01 16:32:47 +00:00
Igor Sysoev de772df553 r2499 merge:
fix /?new=arg?old=arg redirect case
2009-04-01 16:31:18 +00:00
Igor Sysoev 41e58134b7 r2495 merge:
AIX has no WCOREDUMP()
2009-04-01 16:28:47 +00:00
Igor Sysoev 6e37d58163 r2490 merge:
avoid a double redirect response if
*) a request is going in a keep alive state,
*) the request body should be discarded,
*) epoll/rtsig reports about the response header has been sent,
*) and write event handler calls core phase handler
2009-04-01 16:28:06 +00:00
Igor Sysoev 283214bf5a r2483, r2484, r2485, r2487, r2488, r2489, r2491 merge:
bugfixes in reverse resolver and SMTP proxy
2009-04-01 16:25:12 +00:00
Igor Sysoev a8952fb3d7 r2464 merge:
fix fastcgi_store
2009-04-01 16:21:05 +00:00
Igor Sysoev a730ec4a34 r2447, r2466, r2467 merge:
set the error level as default http error_log level
2009-04-01 16:19:22 +00:00
Igor Sysoev f6f84092ab r2446 merge:
proxy/fastcgi_store did not delete incomplete files
2009-04-01 16:15:54 +00:00
Igor Sysoev fa0c987a01 r2372 merge:
skip protected symlinks in autoindex
2009-04-01 16:02:24 +00:00
Igor Sysoev 4a84f30a82 r2371 merge:
allow POST without Content-Length
2009-04-01 16:01:01 +00:00
Igor Sysoev b98820ddc2 r2362, r2497 merge:
if_modified_since
2009-04-01 15:58:21 +00:00
Igor Sysoev 90adc10d7e r2361 merge:
read and process upstream header in cycle,
this fixes the case when local FastCGI server sends many warnings in stderr
2009-04-01 15:51:04 +00:00
Igor Sysoev 30fc974145 r2336, r2337, r2339, r2390 merge:
bugfixes in error logging:
*) ngx_strerror_r() style and size == 0 bug fix
*) increase ngx_conf_log_error() buffer
*) always log an error code
*) fix segfault on close error
*) compact win32 errno logging
2009-04-01 15:47:12 +00:00
Igor Sysoev eed477d46e r2138, r2308, r2360 merge:
$arg_... and $cookie_ variables
2009-04-01 15:36:15 +00:00
Igor Sysoev af7948bbc6 bump version 2009-04-01 15:30:54 +00:00
Igor Sysoev efc9f0e0fb release-0.6.35 tag 2009-01-26 15:31:48 +00:00
Igor Sysoev 015ae6ced8 nginx-0.6.35-RELEASE 2009-01-26 15:31:47 +00:00
Igor Sysoev cfea3a0ea5 fix slab page or more sized allocations if nginx was build without debug 2009-01-26 15:24:14 +00:00
Igor Sysoev 279dbe9cf1 update year and delete blank line 2009-01-26 15:23:11 +00:00
Igor Sysoev 6f911ba618 r2420, r2421, r2435, r2436, r2437 merge:
*) send "100 Continue" for HTTP/1.1 only
*) do not send "100 Continue" for subrequests
*) send "100 Continue" just before reading request body
*) set send() slot for POSIX systems
2009-01-26 15:22:24 +00:00
Igor Sysoev 2fdc0a3865 r2414 merge:
fix segfault
2009-01-26 15:17:50 +00:00
Igor Sysoev c65f18673d r2121, r2126 merge:
*) fix utf-8 names in autoindex
*) rename ngx_utf_...() to ngx_utf8_...()
2009-01-26 15:09:55 +00:00
Igor Sysoev d6088a0284 bump version 2009-01-26 15:06:20 +00:00
Igor Sysoev 712d12f5b3 release-0.6.34 tag 2008-11-27 15:32:52 +00:00
Igor Sysoev dccc819013 nginx-0.6.34-RELEASE 2008-11-27 15:32:51 +00:00
Igor Sysoev be6bfbe864 r2220 merge:
set listen configuration to default server,
this fixes the case, when default server is not the first one
2008-11-27 14:46:01 +00:00
Igor Sysoev caafe12b9c r2163, r2164, r2165 merge:
*) ngx_next_time()
*) expires daily time
2008-11-27 14:40:35 +00:00
Igor Sysoev bb23b107df r2161 merge:
consider log_not_found while testing index files
2008-11-27 14:35:19 +00:00
Igor Sysoev 5505e205fb r2141 merge:
if upstream sent a location header without status use 302
2008-11-27 14:31:44 +00:00
Igor Sysoev 5185273c17 r2118 merge:
handle connect()'s EAGAIN on Linux
2008-11-27 14:28:19 +00:00
Igor Sysoev e62442c637 r2087 merge:
allow several values in query string
2008-11-27 14:24:39 +00:00
Igor Sysoev 66307e3c5a r2068 merge:
the "Expect" header support
2008-11-27 14:22:34 +00:00
Igor Sysoev be4b668df4 r2055 merge:
auto detect https redirect in rewrite
2008-11-27 14:13:48 +00:00
Igor Sysoev d595b0d1e5 r2052, r2082 merge:
"gzip_vary on" always sends "Vary: Accept-Encoding" header
2008-11-27 14:12:18 +00:00
Igor Sysoev e2031ef3fa r2051 merge:
disable charset if there is "Content-Encoding" header
2008-11-27 14:06:46 +00:00
Igor Sysoev 0bf8d5cefe r2039 merge:
add args in redirect to a directory
2008-11-27 14:02:52 +00:00
Igor Sysoev c1173524b6 bump version 2008-11-27 14:01:11 +00:00
Igor Sysoev 943728e49d release-0.6.33 tag 2008-11-20 17:26:45 +00:00
Igor Sysoev 89eeaec954 nginx-0.6.33-RELEASE 2008-11-20 17:26:44 +00:00
Igor Sysoev 624032a645 r2315 merge:
fix compression pointer for big (>255) DNS responses
2008-11-20 17:24:16 +00:00
Igor Sysoev 5e87f63530 r2303 merge:
compatibility with glibc 2.3, warn_unused_result attribute for write()
2008-11-20 17:23:08 +00:00
Igor Sysoev dad8f96c52 r2281 merge:
always use buffer, if connection is buffered,
this fixes OpenSSL "bad write retry" error, when
*) nginx passed a single buf greater than our buffer (say 32K) to OpenSSL,
*) OpenSSL returns SSL_ERROR_WANT_WRITE,
*) after some time nginx has to send a new data,
*) so there are at least two bufs nginx does pass them directly to OpenSSL,
*) but copies the first buf part to buffer, and sends the buffer to OpenSSL.
*) because the data length is lesser than it was in previous SSL_write():
   16K < 32K, OpenSSL returns SSL_R_BAD_WRITE_RETRY.
2008-11-20 17:20:15 +00:00
Igor Sysoev 50f4a8f38f r2245 merge:
strip charset name quotes
2008-11-20 17:18:12 +00:00
Igor Sysoev b08ad2f405 r2205 merge:
fix divide by zero if max_fails=0
2008-11-20 17:16:39 +00:00
Igor Sysoev a096ecd188 r2194 merge:
fix $r->header_in() for "User-Agent", "Connection", and "Host"
broken in r2091 and r2093 merges
2008-11-20 17:12:15 +00:00
Igor Sysoev c617cd8f25 r2193 merge:
leave HEAD method while error_page redirection
2008-11-20 17:09:15 +00:00
Igor Sysoev ff3113d66d r2183, r2192 merge:
*) allow file existence test for POST requests in static module
*) do not discard body while error_page redirection
2008-11-20 17:07:22 +00:00
Igor Sysoev 5c1459c81b r2182 merge:
ignore NGX_EACCES error while directory test
2008-11-20 17:02:02 +00:00
Igor Sysoev 1922047720 r2175 merge:
disable error_page loop in 500 error when recursive errors are enabled
2008-11-20 16:58:41 +00:00
Igor Sysoev 0693b2b816 bump version 2008-11-20 16:55:27 +00:00
Igor Sysoev 8b4c448747 release-0.6.32 tag 2008-07-07 11:44:12 +00:00
Igor Sysoev 70bffb2599 nginx-0.6.32-RELEASE 2008-07-07 11:44:11 +00:00
Igor Sysoev 00bc960934 r2080 merge:
fix error when response parsed by sub filter, then by SSI filter
and some response parts are output as file buffers
2008-07-07 11:33:29 +00:00
Igor Sysoev fb8f48757d r2067 merge:
fix bug when inactive subrequest is truncated,
if output_buffers are less than subrequest size
2008-07-07 11:32:02 +00:00
Igor Sysoev f4df21217f r2053 merge:
fix "proxy_pass https://..." broken in r1427
2008-07-07 11:30:24 +00:00
Igor Sysoev c208b7a83d r2033 merge:
ssl_session_cache none
2008-07-07 11:28:48 +00:00
Igor Sysoev 69ab30d52d r2032 merge:
read channel until EAGAIN
2008-07-07 11:25:22 +00:00
Igor Sysoev de2569fca8 r2019 merge:
fix building on modern Fedora 9 caused by IOV_MAX
2008-07-07 11:24:19 +00:00
Igor Sysoev d35a729745 r2015 merge:
avoid recursive loop
2008-07-07 11:23:28 +00:00
Igor Sysoev f67cbe3d1c r2014 merge:
expires modified
2008-07-07 11:22:34 +00:00
Igor Sysoev d6f90efb6e r2013 merge:
$uid_got and $uid_set may used at any time
2008-07-07 11:22:04 +00:00
Igor Sysoev da56115be5 r2012 merge:
$hostname variable
2008-07-07 11:20:46 +00:00
Igor Sysoev 8c9d659090 r2011 merge:
simplify library autoconfigure
2008-07-07 10:25:46 +00:00
Igor Sysoev b9fe9a4faa r2010 merge:
DESTDIR support
2008-07-07 10:25:08 +00:00
Igor Sysoev 08c1c41777 r2009 merge:
escape 0x00-0x1f, ", and \ in access log variables
2008-07-07 10:24:25 +00:00
Igor Sysoev 0c7bd716fe r2008 merge:
*) host in request line has priority
*) allow several Host headers
*) validate host
2008-07-07 10:22:30 +00:00
Igor Sysoev f8f26bfe3f r2007, r2025, r2042 merge:
style fixes
2008-07-07 10:18:41 +00:00
Igor Sysoev 9657de8e13 r2005, r2006 merge:
test user agent in header callback
2008-07-07 10:13:55 +00:00
Igor Sysoev 5b6559c137 bump version 2008-05-12 10:05:04 +00:00
Igor Sysoev 5b8eaa57c7 stable 0.6 branch 2008-05-12 09:56:52 +00:00
89 changed files with 2829 additions and 1090 deletions

2
auto/configure vendored
View File

@ -3,8 +3,6 @@
# Copyright (C) Igor Sysoev
NGX_CONFIGURE=`echo $@ | sed 's/"/\\\\"/g'`
. auto/options
. auto/init
. auto/sources

View File

@ -17,47 +17,53 @@ fi
cat << END >> $NGX_MAKEFILE
install: $NGX_OBJS${ngx_dirsep}nginx${ngx_binext} \
install: $NGX_OBJS${ngx_dirsep}nginx${ngx_binext} \
$NGX_INSTALL_PERL_MODULES
test -d '$NGX_PREFIX' || mkdir -p '$NGX_PREFIX'
test -d '\$(DESTDIR)$NGX_PREFIX' || mkdir -p '\$(DESTDIR)$NGX_PREFIX'
test -d '`dirname "$NGX_SBIN_PATH"`' \
|| mkdir -p '`dirname "$NGX_SBIN_PATH"`'
test ! -f '$NGX_SBIN_PATH' || mv '$NGX_SBIN_PATH' '$NGX_SBIN_PATH.old'
cp $NGX_OBJS/nginx '$NGX_SBIN_PATH'
test -d '\$(DESTDIR)`dirname "$NGX_SBIN_PATH"`' \
|| mkdir -p '\$(DESTDIR)`dirname "$NGX_SBIN_PATH"`'
test ! -f '\$(DESTDIR)$NGX_SBIN_PATH' \
|| mv '\$(DESTDIR)$NGX_SBIN_PATH' \
'\$(DESTDIR)$NGX_SBIN_PATH.old'
cp $NGX_OBJS/nginx '\$(DESTDIR)$NGX_SBIN_PATH'
test -d '$NGX_CONF_PREFIX' || mkdir -p '$NGX_CONF_PREFIX'
test -d '\$(DESTDIR)$NGX_CONF_PREFIX' \
|| mkdir -p '\$(DESTDIR)$NGX_CONF_PREFIX'
cp conf/koi-win '$NGX_CONF_PREFIX'
cp conf/koi-utf '$NGX_CONF_PREFIX'
cp conf/win-utf '$NGX_CONF_PREFIX'
cp conf/koi-win '\$(DESTDIR)$NGX_CONF_PREFIX'
cp conf/koi-utf '\$(DESTDIR)$NGX_CONF_PREFIX'
cp conf/win-utf '\$(DESTDIR)$NGX_CONF_PREFIX'
test -f '$NGX_CONF_PREFIX/mime.types' \
|| cp conf/mime.types '$NGX_CONF_PREFIX'
cp conf/mime.types '$NGX_CONF_PREFIX/mime.types.default'
test -f '\$(DESTDIR)$NGX_CONF_PREFIX/mime.types' \
|| cp conf/mime.types '\$(DESTDIR)$NGX_CONF_PREFIX'
cp conf/mime.types '\$(DESTDIR)$NGX_CONF_PREFIX/mime.types.default'
test -f '$NGX_CONF_PREFIX/fastcgi_params' \
|| cp conf/fastcgi_params '$NGX_CONF_PREFIX'
cp conf/fastcgi_params '$NGX_CONF_PREFIX/fastcgi_params.default'
test -f '\$(DESTDIR)$NGX_CONF_PREFIX/fastcgi_params' \
|| cp conf/fastcgi_params '\$(DESTDIR)$NGX_CONF_PREFIX'
cp conf/fastcgi_params \
'\$(DESTDIR)$NGX_CONF_PREFIX/fastcgi_params.default'
test -f '$NGX_CONF_PATH' || cp conf/nginx.conf '$NGX_CONF_PREFIX'
cp conf/nginx.conf '$NGX_CONF_PREFIX/nginx.conf.default'
test -f '\$(DESTDIR)$NGX_CONF_PATH' \
|| cp conf/nginx.conf '\$(DESTDIR)$NGX_CONF_PREFIX'
cp conf/nginx.conf '\$(DESTDIR)$NGX_CONF_PREFIX/nginx.conf.default'
test -d '`dirname "$NGX_PID_PATH"`' \
|| mkdir -p '`dirname "$NGX_PID_PATH"`'
test -d '\$(DESTDIR)`dirname "$NGX_PID_PATH"`' \
|| mkdir -p '\$(DESTDIR)`dirname "$NGX_PID_PATH"`'
test -d '`dirname "$NGX_HTTP_LOG_PATH"`' || \
mkdir -p '`dirname "$NGX_HTTP_LOG_PATH"`'
test -d '\$(DESTDIR)`dirname "$NGX_HTTP_LOG_PATH"`' || \
mkdir -p '\$(DESTDIR)`dirname "$NGX_HTTP_LOG_PATH"`'
test -d '$NGX_PREFIX/html' || cp -r html '$NGX_PREFIX'
test -d '\$(DESTDIR)$NGX_PREFIX/html' \
|| cp -r html '\$(DESTDIR)$NGX_PREFIX'
END
if test -n "$NGX_ERROR_LOG_PATH"; then
if test -n "\$(DESTDIR)$NGX_ERROR_LOG_PATH"; then
cat << END >> $NGX_MAKEFILE
test -d '`dirname "$NGX_ERROR_LOG_PATH"`' || \
mkdir -p '`dirname "$NGX_ERROR_LOG_PATH"`'
test -d '\$(DESTDIR)`dirname "$NGX_ERROR_LOG_PATH"`' || \
mkdir -p '\$(DESTDIR)`dirname "$NGX_ERROR_LOG_PATH"`'
END
fi

View File

@ -16,6 +16,7 @@ if [ $USE_MD5 = YES ]; then
have=NGX_HAVE_OPENSSL_MD5_H . auto/have
have=NGX_OPENSSL_MD5 . auto/have
MD5=YES
MD5_LIB=OpenSSL
else
. auto/lib/md5/conf
@ -28,6 +29,7 @@ if [ $USE_SHA1 = YES ]; then
if [ $OPENSSL != NONE -a $OPENSSL != NO ]; then
have=NGX_HAVE_OPENSSL_SHA1_H . auto/have
SHA1=YES
SHA1_LIB=OpenSSL
else
. auto/lib/sha1/conf

View File

@ -45,6 +45,7 @@ if [ $MD5 != NONE ]; then
else
if [ "$NGX_PLATFORM" != win32 ]; then
MD5=NO
# Solaris 8/9
@ -58,55 +59,43 @@ else
ngx_feature_test="MD5_CTX md5; MD5Init(&md5)"
. auto/feature
if [ $ngx_found = yes ]; then
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
MD5=YES
MD5_LIB=md5
ngx_found=no
ngx_md5_lib="system md5"
if [ $ngx_found = no ]; then
else
# FreeBSD
ngx_feature="rsaref md library"
ngx_feature_name=
ngx_feature_run=no
ngx_feature_incs="#include <md5.h>"
ngx_feature_path=
ngx_feature_libs="-lmd"
ngx_feature_test="MD5_CTX md5; MD5Init(&md5)"
. auto/feature
ngx_md5_lib="system md"
fi
if [ $ngx_found = no ]; then
if [ $ngx_found = yes ]; then
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
MD5=YES
MD5_LIB=md
ngx_found=no
# OpenSSL crypto library
else
if [ $MD5 = NO ]; then
ngx_feature="OpenSSL md5 crypto library"
ngx_feature_name="NGX_OPENSSL_MD5"
ngx_feature_incs="#include <openssl/md5.h>"
ngx_feature_libs="-lcrypto"
ngx_feature_test="MD5_CTX md5; MD5_Init(&md5)"
. auto/feature
# OpenSSL crypto library
ngx_md5_lib="system crypto"
ngx_feature="OpenSSL md5 crypto library"
ngx_feature_name="NGX_OPENSSL_MD5"
ngx_feature_run=no
ngx_feature_incs="#include <openssl/md5.h>"
ngx_feature_path=
ngx_feature_libs="-lcrypto"
ngx_feature_test="MD5_CTX md5; MD5_Init(&md5)"
. auto/feature
if [ $ngx_found = yes ]; then
have=NGX_HAVE_OPENSSL_MD5_H . auto/have
fi
fi
if [ $ngx_found = yes ]; then
have=NGX_HAVE_OPENSSL_MD5_H . auto/have
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
MD5=YES
MD5_LIB=crypto
MD5_LIB=$ngx_md5_lib
fi
fi
fi

View File

@ -84,6 +84,7 @@ if [ $PCRE != NONE ]; then
else
if [ "$NGX_PLATFORM" != win32 ]; then
PCRE=NO
ngx_feature="PCRE library"
@ -95,20 +96,11 @@ else
ngx_feature_test="pcre *re; re = pcre_compile(NULL, 0, NULL, 0, NULL)"
. auto/feature
if [ $ngx_found = yes ]; then
CORE_DEPS="$CORE_DEPS $REGEX_DEPS"
CORE_SRCS="$CORE_SRCS $REGEX_SRCS"
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
PCRE=YES
ngx_found=no
if [ $ngx_found = no ]; then
else
# FreeBSD port
ngx_feature="PCRE library in /usr/local/"
ngx_feature_name="NGX_PCRE"
ngx_feature_run=no
ngx_feature_incs="#include <pcre.h>"
ngx_feature_path="/usr/local/include"
if [ $NGX_RPATH = YES ]; then
@ -117,8 +109,49 @@ else
ngx_feature_libs="-L/usr/local/lib -lpcre"
fi
ngx_feature_test="pcre *re;
re = pcre_compile(NULL, 0, NULL, 0, NULL)"
. auto/feature
fi
if [ $ngx_found = no ]; then
# Linux package
ngx_feature="PCRE library in /usr/include/pcre/"
ngx_feature_path="/usr/include/pcre"
ngx_feature_libs="-lpcre"
. auto/feature
fi
if [ $ngx_found = no ]; then
# NetBSD port
ngx_feature="PCRE library in /usr/pkg/"
ngx_feature_path="/usr/pkg/include"
if [ $NGX_RPATH = YES ]; then
ngx_feature_libs="-R/usr/pkg/lib -L/usr/pkg/lib -lpcre"
else
ngx_feature_libs="-L/usr/pkg/lib -lpcre"
fi
. auto/feature
fi
if [ $ngx_found = no ]; then
# MacPorts
ngx_feature="PCRE library in /opt/local/"
ngx_feature_path="/opt/local/include"
if [ $NGX_RPATH = YES ]; then
ngx_feature_libs="-R/opt/local/lib -L/opt/local/lib -lpcre"
else
ngx_feature_libs="-L/opt/local/lib -lpcre"
fi
. auto/feature
fi
@ -128,94 +161,6 @@ else
CORE_INCS="$CORE_INCS $ngx_feature_path"
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
PCRE=YES
ngx_found=no
else
# Linux package
if [ $PCRE = NO ]; then
ngx_feature="PCRE library in /usr/include/pcre/"
ngx_feature_name="NGX_PCRE"
ngx_feature_run=no
ngx_feature_incs="#include <pcre.h>"
ngx_feature_path="/usr/include/pcre"
ngx_feature_libs="-lpcre"
ngx_feature_test="pcre *re;
re = pcre_compile(NULL, 0, NULL, 0, NULL)"
. auto/feature
fi
fi
if [ $ngx_found = yes ]; then
CORE_DEPS="$CORE_DEPS $REGEX_DEPS"
CORE_SRCS="$CORE_SRCS $REGEX_SRCS"
CORE_INCS="$CORE_INCS $ngx_feature_path"
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
PCRE=YES
ngx_found=no
else
# NetBSD port
if [ $PCRE = NO ]; then
ngx_feature="PCRE library in /usr/pkg/"
ngx_feature_name="NGX_PCRE"
ngx_feature_run=no
ngx_feature_incs="#include <pcre.h>"
ngx_feature_path="/usr/pkg/include"
if [ $NGX_RPATH = YES ]; then
ngx_feature_libs="-R/usr/pkg/lib -L/usr/pkg/lib -lpcre"
else
ngx_feature_libs="-L/usr/pkg/lib -lpcre"
fi
ngx_feature_test="pcre *re;
re = pcre_compile(NULL, 0, NULL, 0, NULL)"
. auto/feature
fi
fi
if [ $ngx_found = yes ]; then
CORE_DEPS="$CORE_DEPS $REGEX_DEPS"
CORE_SRCS="$CORE_SRCS $REGEX_SRCS"
CORE_INCS="$CORE_INCS $ngx_feature_path"
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
PCRE=YES
ngx_found=no
else
# MacPorts
if [ $PCRE = NO ]; then
ngx_feature="PCRE library in /opt/local/"
ngx_feature_name="NGX_PCRE"
ngx_feature_run=no
ngx_feature_incs="#include <pcre.h>"
ngx_feature_path="/opt/local/include"
if [ $NGX_RPATH = YES ]; then
ngx_feature_libs="-R/opt/local/lib -L/opt/local/lib -lpcre"
else
ngx_feature_libs="-L/opt/local/lib -lpcre"
fi
ngx_feature_test="pcre *re;
re = pcre_compile(NULL, 0, NULL, 0, NULL)"
. auto/feature
fi
fi
if [ $ngx_found = yes ]; then
CORE_DEPS="$CORE_DEPS $REGEX_DEPS"
CORE_SRCS="$CORE_SRCS $REGEX_SRCS"
CORE_INCS="$CORE_INCS $ngx_feature_path"
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
PCRE=YES
ngx_found=no
fi
fi

View File

@ -35,6 +35,7 @@ if [ $SHA1 != NONE ]; then
else
if [ "$NGX_PLATFORM" != win32 ]; then
SHA1=NO
# FreeBSD
@ -48,35 +49,28 @@ else
ngx_feature_test="SHA_CTX sha1; SHA1_Init(&sha1)"
. auto/feature
ngx_sha1_lib="system md"
if [ $ngx_found = yes ]; then
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
SHA1=YES
SHA1_LIB=md
ngx_found=no
if [ $ngx_found = no ]; then
else
if [ $SHA1 = NO ]; then
# OpenSSL crypto library
# OpenSSL crypto library
ngx_feature="OpenSSL sha1 crypto library"
ngx_feature_incs="#include <openssl/sha.h>"
ngx_feature_libs="-lcrypto"
. auto/feature
ngx_feature="OpenSSL sha1 crypto library"
ngx_feature_name=
ngx_feature_run=no
ngx_feature_incs="#include <openssl/sha.h>"
ngx_feature_path=
ngx_feature_libs="-lcrypto"
ngx_feature_test="SHA_CTX sha1; SHA1_Init(&sha1)"
. auto/feature
ngx_sha1_lib="system crypto"
if [ $ngx_found = yes ]; then
have=NGX_HAVE_OPENSSL_SHA1_H . auto/have
fi
fi
if [ $ngx_found = yes ]; then
have=NGX_HAVE_OPENSSL_SHA1_H . auto/have
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
SHA1=YES
SHA1_LIB=crypto
SHA1_LIB=$ngx_sha1_lib
fi
fi

View File

@ -119,9 +119,12 @@ NGX_GOOGLE_PERFTOOLS=NO
NGX_CPU_CACHE_LINE=
opt=
for option
do
opt="$opt `echo $option | sed -e \"s/\(--[^=]*=\)\(.* .*\)/\1'\2'/\"`"
case "$option" in
-*=*) value=`echo "$option" | sed -e 's/[-_a-zA-Z0-9]*=//'` ;;
*) value="" ;;
@ -215,6 +218,7 @@ do
--with-debug) NGX_DEBUG=YES ;;
--without-pcre) USE_PCRE=DISABLED ;;
--with-pcre) USE_PCRE=YES ;;
--with-pcre=*) PCRE="$value" ;;
--with-pcre-opt=*) PCRE_OPT="$value" ;;
@ -247,6 +251,9 @@ do
done
NGX_CONFIGURE="$opt"
if [ $help = yes ]; then
cat << END
@ -333,7 +340,8 @@ cat << END
pentium, pentiumpro, pentium3, pentium4,
athlon, opteron, sparc32, sparc64, ppc64
--without-pcre disable PCRE libarary usage
--without-pcre disable PCRE library usage
--with-pcre force PCRE library usage
--with-pcre=DIR set path to PCRE library sources
--with-pcre-opt=OPTIONS set additional options for PCRE building

View File

@ -51,26 +51,14 @@ case $OPENSSL in
esac
case $MD5 in
YES)
case $OPENSSL in
NONE|NO) echo " + md5: using system $MD5_LIB library" ;;
*) echo " + md5: using OpenSSL library" ;;
esac
;;
YES) echo " + md5: using $MD5_LIB library" ;;
NONE) echo " + md5 library is not used" ;;
NO) echo " + md5 library is not found" ;;
*) echo " + using md5 library: $MD5" ;;
esac
case $SHA1 in
YES)
case $OPENSSL in
NONE|NO) echo " + sha1: using system $SHA1_LIB library" ;;
*) echo " + sha1: using OpenSSL library" ;;
esac
;;
YES) echo " + sha1: using $SHA1_LIB library" ;;
NONE) echo " + sha1 library is not used" ;;
NO) echo " + sha1 library is not found" ;;
*) echo " + using sha1 library: $SHA1" ;;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2002-2008 Igor Sysoev
* Copyright (C) 2002-2009 Igor Sysoev
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -21,5 +21,4 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/

File diff suppressed because it is too large Load Diff

View File

@ -192,6 +192,8 @@ static char **ngx_os_environ;
int ngx_cdecl
main(int argc, char *const *argv)
{
char *p;
ssize_t n;
ngx_int_t i;
ngx_log_t *log;
ngx_cycle_t *cycle, init_cycle;
@ -241,23 +243,30 @@ main(int argc, char *const *argv)
}
if (ngx_show_version) {
ngx_write_fd(ngx_stderr_fileno, "nginx version: " NGINX_VER CRLF,
sizeof("nginx version: " NGINX_VER CRLF) - 1);
p = "nginx version: " NGINX_VER CRLF;
n = sizeof("nginx version: " NGINX_VER CRLF) - 1;
if (ngx_write_fd(ngx_stderr_fileno, p, n) != n) {
return 1;
}
if (ngx_show_configure) {
#ifdef NGX_COMPILER
ngx_write_fd(ngx_stderr_fileno, "built by " NGX_COMPILER CRLF,
sizeof("built by " NGX_COMPILER CRLF) - 1);
p = "built by " NGX_COMPILER CRLF;
n = sizeof("built by " NGX_COMPILER CRLF) - 1;
if (ngx_write_fd(ngx_stderr_fileno, p, n) != n) {
return 1;
}
#endif
#ifndef __WATCOMC__
p = "configure arguments:" NGX_CONFIGURE CRLF;
n = sizeof("configure arguments:" NGX_CONFIGURE CRLF) - 1;
/* OpenWatcomC could not build the long NGX_CONFIGURE string */
ngx_write_fd(ngx_stderr_fileno,
"configure arguments: " NGX_CONFIGURE CRLF,
sizeof("configure arguments :" NGX_CONFIGURE CRLF) - 1);
#endif
if (ngx_write_fd(ngx_stderr_fileno, p, n) != n) {
return 1;
}
}
if (!ngx_test_config) {
@ -1078,7 +1087,7 @@ ngx_set_cpu_affinity(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid character \"%c\" in \"worker_cpu_affinity\"",
ch);
return NGX_CONF_ERROR ;
return NGX_CONF_ERROR;
}
}

View File

@ -8,7 +8,8 @@
#define _NGINX_H_INCLUDED_
#define NGINX_VERSION "0.6.31"
#define nginx_version 006039
#define NGINX_VERSION "0.6.39"
#define NGINX_VER "nginx/" NGINX_VERSION
#define NGINX_VAR "NGINX"

View File

@ -201,14 +201,14 @@ done:
if (filename) {
ngx_free(cf->conf_file->buffer->start);
cf->conf_file = prev;
if (ngx_close_file(fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
ngx_close_file_n " %s failed",
cf->conf_file->file.name.data);
return NGX_CONF_ERROR;
}
cf->conf_file = prev;
}
if (rc == NGX_ERROR) {
@ -806,6 +806,7 @@ ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
static void
ngx_conf_flush_files(ngx_cycle_t *cycle)
{
ssize_t n, len;
ngx_uint_t i;
ngx_list_part_t *part;
ngx_open_file_t *file;
@ -826,11 +827,24 @@ ngx_conf_flush_files(ngx_cycle_t *cycle)
i = 0;
}
if (file[i].buffer == NULL || file[i].pos - file[i].buffer == 0) {
len = file[i].pos - file[i].buffer;
if (file[i].buffer == NULL || len == 0) {
continue;
}
ngx_write_fd(file[i].fd, file[i].buffer, file[i].pos - file[i].buffer);
n = ngx_write_fd(file[i].fd, file[i].buffer, len);
if (n == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
ngx_write_fd_n " to \"%s\" failed",
file[i].name.data);
} else if (n != len) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz",
file[i].name.data, n, len);
}
}
}
@ -839,31 +853,47 @@ void ngx_cdecl
ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err,
char *fmt, ...)
{
u_char errstr[NGX_MAX_CONF_ERRSTR], *buf, *last;
u_char errstr[NGX_MAX_CONF_ERRSTR], *p, *last;
va_list args;
last = errstr + NGX_MAX_CONF_ERRSTR;
va_start(args, fmt);
buf = ngx_vsnprintf(errstr, last - errstr, fmt, args);
p = ngx_vsnprintf(errstr, last - errstr, fmt, args);
va_end(args);
*buf = '\0';
if (err) {
buf = ngx_snprintf(buf, last - buf - 1, " (%d: ", err);
buf = ngx_strerror_r(err, buf, last - buf - 1);
*buf++ = ')';
*buf = '\0';
if (p > last - 50) {
/* leave a space for an error code */
p = last - 50;
*p++ = '.';
*p++ = '.';
*p++ = '.';
}
#if (NGX_WIN32)
p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000)
? " (%d: " : " (%Xd: ", err);
#else
p = ngx_snprintf(p, last - p, " (%d: ", err);
#endif
p = ngx_strerror_r(err, p, last - p);
*p++ = ')';
}
if (cf->conf_file == NULL) {
ngx_log_error(level, cf->log, 0, "%s", errstr);
ngx_log_error(level, cf->log, 0, "%*s", p - errstr, errstr);
return;
}
ngx_log_error(level, cf->log, 0, "%s in %s:%ui",
errstr, cf->conf_file->file.name.data, cf->conf_file->line);
ngx_log_error(level, cf->log, 0, "%*s in %s:%ui",
p - errstr, errstr,
cf->conf_file->file.name.data, cf->conf_file->line);
}

View File

@ -71,7 +71,7 @@
#define NGX_CONF_MODULE 0x464E4F43 /* "CONF" */
#define NGX_MAX_CONF_ERRSTR 256
#define NGX_MAX_CONF_ERRSTR 1024
struct ngx_command_s {

View File

@ -116,10 +116,11 @@ typedef intptr_t ngx_flag_t;
#define INET_ADDRSTRLEN 16
#endif
#define NGX_MAXHOSTNAMELEN 64
/*
#define NGX_MAXHOSTNAMELEN MAXHOSTNAMELEN
*/
#ifdef MAXHOSTNAMELEN
#define NGX_MAXHOSTNAMELEN MAXHOSTNAMELEN
#else
#define NGX_MAXHOSTNAMELEN 256
#endif
#if ((__GNU__ == 2) && (__GNUC_MINOR__ < 8))

View File

@ -229,7 +229,7 @@ ngx_open_listening_sockets(ngx_cycle_t *cycle)
/* TODO: configurable try number */
for (tries = 5 ; tries; tries--) {
for (tries = 5; tries; tries--) {
failed = 0;
/* for each listening socket */
@ -779,12 +779,16 @@ ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text)
{
ngx_uint_t level;
if (err == NGX_ECONNRESET
&& c->log_error == NGX_ERROR_IGNORE_ECONNRESET)
{
if (err == NGX_ECONNRESET && c->log_error == NGX_ERROR_IGNORE_ECONNRESET) {
return 0;
}
#if (NGX_SOLARIS)
if (err == NGX_EINVAL && c->log_error == NGX_ERROR_IGNORE_EINVAL) {
return 0;
}
#endif
if (err == 0
|| err == NGX_ECONNRESET
#if !(NGX_WIN32)
@ -800,6 +804,7 @@ ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text)
{
switch (c->log_error) {
case NGX_ERROR_IGNORE_EINVAL:
case NGX_ERROR_IGNORE_ECONNRESET:
case NGX_ERROR_INFO:
level = NGX_LOG_INFO;

View File

@ -71,10 +71,11 @@ struct ngx_listening_s {
typedef enum {
NGX_ERROR_CRIT = 0,
NGX_ERROR_ALERT = 0,
NGX_ERROR_ERR,
NGX_ERROR_INFO,
NGX_ERROR_IGNORE_ECONNRESET
NGX_ERROR_IGNORE_ECONNRESET,
NGX_ERROR_IGNORE_EINVAL
} ngx_connection_log_error_e;
@ -133,9 +134,11 @@ struct ngx_connection_s {
ngx_atomic_uint_t number;
ngx_uint_t requests;
unsigned buffered:8;
unsigned log_error:2; /* ngx_connection_log_error_e */
unsigned log_error:3; /* ngx_connection_log_error_e */
unsigned single_connection:1;
unsigned unexpected_eof:1;

View File

@ -72,7 +72,7 @@ void
ngx_cpuinfo(void)
{
u_char *vendor;
uint32_t vbuf[5], cpu[4];
uint32_t vbuf[5], cpu[4], model;
vbuf[0] = 0;
vbuf[1] = 0;
@ -103,8 +103,10 @@ ngx_cpuinfo(void)
case 6:
ngx_cacheline_size = 32;
if ((cpu[0] & 0xf0) >= 0xd0) {
/* Intel Core */
model = ((cpu[0] & 0xf0000) >> 8) | (cpu[0] & 0xf0);
if (model >= 0xd0) {
/* Intel Core, Core 2, Atom */
ngx_cacheline_size = 64;
}

View File

@ -57,6 +57,7 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
ngx_listening_t *ls, *nls;
ngx_core_conf_t *ccf, *old_ccf;
ngx_core_module_t *module;
char hostname[NGX_MAXHOSTNAMELEN];
log = old_cycle->log;
@ -170,6 +171,26 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
}
if (gethostname(hostname, NGX_MAXHOSTNAMELEN) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "gethostname() failed");
ngx_destroy_pool(pool);
return NULL;
}
/* on Linux gethostname() silently truncates name that does not fit */
hostname[NGX_MAXHOSTNAMELEN - 1] = '\0';
cycle->hostname.len = ngx_strlen(hostname);
cycle->hostname.data = ngx_palloc(pool, cycle->hostname.len);
if (cycle->hostname.data == NULL) {
ngx_destroy_pool(pool);
return NULL;
}
ngx_memcpy(cycle->hostname.data, hostname, cycle->hostname.len);
for (i = 0; ngx_modules[i]; i++) {
if (ngx_modules[i]->type != NGX_CORE_MODULE) {
continue;
@ -949,6 +970,7 @@ ngx_test_lockfile(u_char *file, ngx_log_t *log)
void
ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
{
ssize_t n, len;
ngx_fd_t fd;
ngx_uint_t i;
ngx_list_part_t *part;
@ -972,9 +994,23 @@ ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
continue;
}
if (file[i].buffer && file[i].pos - file[i].buffer != 0) {
ngx_write_fd(file[i].fd, file[i].buffer,
file[i].pos - file[i].buffer);
len = file[i].pos - file[i].buffer;
if (file[i].buffer && len != 0) {
n = ngx_write_fd(file[i].fd, file[i].buffer, len);
if (n == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
ngx_write_fd_n " to \"%s\" failed",
file[i].name.data);
} else if (n != len) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz",
file[i].name.data, n, len);
}
file[i].pos = file[i].buffer;
}

View File

@ -62,6 +62,7 @@ struct ngx_cycle_s {
ngx_str_t conf_file;
ngx_str_t root;
ngx_str_t lock_file;
ngx_str_t hostname;
};

View File

@ -127,18 +127,10 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
}
#if (NGX_WIN32)
if ((unsigned) err >= 0x80000000) {
p = ngx_snprintf(p, last - p, " (%Xd: ", err);
} else {
p = ngx_snprintf(p, last - p, " (%d: ", err);
}
p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000)
? " (%d: " : " (%Xd: ", err);
#else
p = ngx_snprintf(p, last - p, " (%d: ", err);
#endif
p = ngx_strerror_r(err, p, last - p);
@ -158,7 +150,7 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
ngx_linefeed(p);
ngx_write_fd(log->file->fd, errstr, p - errstr);
(void) ngx_write_fd(log->file->fd, errstr, p - errstr);
}
@ -192,9 +184,9 @@ ngx_log_debug_core(ngx_log_t *log, ngx_err_t err, const char *fmt, ...)
void
ngx_log_abort(ngx_err_t err, const char *text)
ngx_log_abort(ngx_err_t err, const char *text, void *param)
{
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, err, text);
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, err, text, param);
}
@ -310,7 +302,10 @@ ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log)
}
}
if (log->log_level == NGX_LOG_DEBUG) {
if (log->log_level == 0) {
log->log_level = NGX_LOG_ERR;
} else if (log->log_level == NGX_LOG_DEBUG) {
log->log_level = NGX_LOG_DEBUG_ALL;
}

View File

@ -198,7 +198,7 @@ void ngx_cdecl ngx_log_debug_core(ngx_log_t *log, ngx_err_t err,
ngx_log_t *ngx_log_init(void);
ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args);
char *ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log);
void ngx_log_abort(ngx_err_t err, const char *text);
void ngx_log_abort(ngx_err_t err, const char *text, void *param);
extern ngx_module_t ngx_errlog_module;

View File

@ -413,13 +413,13 @@ failed:
if (file->count == 0) {
if (file->fd != NGX_INVALID_FILE) {
if (ngx_close_file(file->fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, pool->log, ngx_errno,
ngx_close_file_n " \"%s\" failed",
if (file->fd != NGX_INVALID_FILE) {
if (ngx_close_file(file->fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, pool->log, ngx_errno,
ngx_close_file_n " \"%s\" failed",
file->name);
}
}
}
}
ngx_free(file->name);
ngx_free(file);

View File

@ -202,7 +202,7 @@ ngx_resolver_cleanup_tree(ngx_resolver_t *r, ngx_rbtree_t *tree)
ngx_queue_remove(&rn->queue);
for (ctx = rn->waiting; ctx; ctx = next) {
next = ctx->next;
next = ctx->next;
if (ctx->event) {
ngx_resolver_free(r, ctx->event);
@ -578,6 +578,7 @@ failed:
ngx_int_t
ngx_resolve_addr(ngx_resolver_ctx_t *ctx)
{
u_char *name;
ngx_resolver_t *r;
ngx_resolver_node_t *rn;
@ -601,19 +602,21 @@ ngx_resolve_addr(ngx_resolver_ctx_t *ctx)
ngx_queue_insert_head(&r->addr_expire_queue, &rn->queue);
ctx->name.len = rn->nlen;
ctx->name.data = ngx_resolver_dup(r, rn->name, rn->nlen);
if (ctx->name.data == NULL) {
name = ngx_resolver_dup(r, rn->name, rn->nlen);
if (name == NULL) {
goto failed;
}
ctx->name.len = rn->nlen;
ctx->name.data = name;
/* unlock addr mutex */
ctx->state = NGX_OK;
ctx->handler(ctx);
ngx_resolver_free(r, ctx->name.data);
ngx_resolver_free(r, name);
return NGX_OK;
}
@ -623,7 +626,9 @@ ngx_resolve_addr(ngx_resolver_ctx_t *ctx)
ctx->next = rn->waiting;
rn->waiting = ctx;
return NGX_AGAIN;
/* unlock addr mutex */
return NGX_OK;
}
ngx_queue_remove(&rn->queue);
@ -1306,7 +1311,7 @@ ngx_resolver_process_a(ngx_resolver_t *r, u_char *buf, size_t last,
ctx->handler(ctx);
}
if (naddrs) {
if (naddrs > 1) {
ngx_resolver_free(r, addrs);
}
@ -1483,20 +1488,23 @@ ngx_resolver_process_ptr(ngx_resolver_t *r, u_char *buf, size_t n,
goto short_response;
}
len -= 2;
if (ngx_resolver_copy(r, &name, buf, &buf[i], &buf[n]) != NGX_OK) {
return;
}
ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, "resolver an:%V", &name);
if (len != (size_t) rn->nlen || ngx_strncmp(name.data, rn->name, len) != 0)
if (name.len != (size_t) rn->nlen
|| ngx_strncmp(name.data, rn->name, name.len) != 0)
{
ngx_resolver_free(r, rn->name);
if (rn->nlen) {
ngx_resolver_free(r, rn->name);
}
rn->nlen = (u_short) name.len;
rn->name = name.data;
name.data = ngx_resolver_dup(r, rn->name, len);
name.data = ngx_resolver_dup(r, rn->name, name.len);
if (name.data == NULL) {
goto failed;
}
@ -1836,7 +1844,7 @@ ngx_resolver_copy(ngx_resolver_t *r, ngx_str_t *name, u_char *buf, u_char *src,
}
if (n & 0xc0) {
n = (n & 0x3f << 8) + *p;
n = ((n & 0x3f) << 8) + *p;
p = &buf[n];
} else {
@ -1886,7 +1894,7 @@ done:
}
} else {
n = (n & 0x3f << 8) + *src;
n = ((n & 0x3f) << 8) + *src;
src = &buf[n];
n = *src++;

View File

@ -57,7 +57,15 @@ ngx_shmtx_trylock(ngx_shmtx_t *mtx)
return 0;
}
ngx_log_abort(err, ngx_trylock_fd_n " failed");
#if __osf__ /* Tru64 UNIX */
if (err == NGX_EACCESS) {
return 0;
}
#endif
ngx_log_abort(err, ngx_trylock_fd_n " %s failed", mtx->name);
return 0;
}
@ -74,7 +82,7 @@ ngx_shmtx_lock(ngx_shmtx_t *mtx)
return;
}
ngx_log_abort(err, ngx_lock_fd_n " failed");
ngx_log_abort(err, ngx_lock_fd_n " %s failed", mtx->name);
}
@ -89,7 +97,7 @@ ngx_shmtx_unlock(ngx_shmtx_t *mtx)
return;
}
ngx_log_abort(err, ngx_unlock_fd_n " failed");
ngx_log_abort(err, ngx_unlock_fd_n " %s failed", mtx->name);
}

View File

@ -661,11 +661,8 @@ ngx_slab_alloc_pages(ngx_slab_pool_t *pool, ngx_uint_t pages)
}
page->slab = pages | NGX_SLAB_PAGE_START;
#if (NGX_DEBUG)
page->next = NULL;
page->prev = NGX_SLAB_PAGE;
#endif
if (--pages == 0) {
return page;
@ -673,10 +670,8 @@ ngx_slab_alloc_pages(ngx_slab_pool_t *pool, ngx_uint_t pages)
for (p = page + 1; pages; pages--) {
p->slab = NGX_SLAB_PAGE_BUSY;
#if (NGX_DEBUG)
p->next = NULL;
p->prev = NGX_SLAB_PAGE;
#endif
p++;
}

View File

@ -952,16 +952,16 @@ ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src)
/*
* ngx_utf_decode() decodes two and more bytes UTF sequences only
* ngx_utf8_decode() decodes two and more bytes UTF sequences only
* the return values:
* 0x80 - 0x10ffff valid character
* 0x10ffff - 0xfffffffd invalid sequence
* 0x110000 - 0xfffffffd invalid sequence
* 0xfffffffe incomplete sequence
* 0xffffffff error
*/
uint32_t
ngx_utf_decode(u_char **p, size_t n)
ngx_utf8_decode(u_char **p, size_t n)
{
size_t len;
uint32_t u, i, valid;
@ -1018,31 +1018,26 @@ ngx_utf_decode(u_char **p, size_t n)
size_t
ngx_utf_length(u_char *p, size_t n)
ngx_utf8_length(u_char *p, size_t n)
{
u_char c;
size_t len;
ngx_uint_t i;
u_char c, *last;
size_t len;
for (len = 0, i = 0; i < n; len++, i++) {
last = p + n;
c = p[i];
for (len = 0; p < last; len++) {
c = *p;
if (c < 0x80) {
p++;
continue;
}
if (c >= 0xc0) {
for (c <<= 1; c & 0x80; c <<= 1) {
i++;
}
continue;
if (ngx_utf8_decode(&p, n) > 0x10ffff) {
/* invalid UTF-8 */
return n;
}
/* invalid utf */
return n;
}
return len;
@ -1050,36 +1045,45 @@ ngx_utf_length(u_char *p, size_t n)
u_char *
ngx_utf_cpystrn(u_char *dst, u_char *src, size_t n)
ngx_utf8_cpystrn(u_char *dst, u_char *src, size_t n, size_t len)
{
u_char c;
u_char c, *next;
if (n == 0) {
return dst;
}
for ( /* void */ ; --n; dst++, src++) {
while (--n) {
c = *src;
*dst = c;
if (c < 0x80) {
if (*dst != '\0') {
if (c != '\0') {
dst++;
src++;
len--;
continue;
}
return dst;
}
if (c >= 0xc0) {
for (c <<= 1; c & 0x80; c <<= 1) {
*++dst = *++src;
}
next = src;
continue;
if (ngx_utf8_decode(&next, len) > 0x10ffff) {
/* invalid UTF-8 */
break;
}
/* invalid utf */
len--;
while (src < next) {
*++dst = *++src;
len--;
}
}
*dst = '\0';

View File

@ -25,11 +25,12 @@ typedef struct {
typedef struct {
unsigned len:29;
unsigned len:28;
unsigned valid:1;
unsigned no_cacheable:1;
unsigned not_found:1;
unsigned escape:1;
u_char *data;
} ngx_variable_value_t;
@ -51,9 +52,25 @@ typedef struct {
#define ngx_strstr(s1, s2) strstr((const char *) s1, (const char *) s2)
#define ngx_strchr(s1, c) strchr((const char *) s1, (int) c)
#define ngx_strlen(s) strlen((const char *) s)
#define ngx_strchr(s1, c) strchr((const char *) s1, (int) c)
static ngx_inline u_char *
ngx_strlchr(u_char *p, u_char *last, u_char c)
{
while (p < last) {
if (*p == c) {
return p;
}
p++;
}
return NULL;
}
/*
* msvc and icc7 compile memset() to the inline "rep stos"
@ -150,9 +167,9 @@ u_char *ngx_hex_dump(u_char *dst, u_char *src, size_t len);
void ngx_encode_base64(ngx_str_t *dst, ngx_str_t *src);
ngx_int_t ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src);
uint32_t ngx_utf_decode(u_char **p, size_t n);
size_t ngx_utf_length(u_char *p, size_t n);
u_char *ngx_utf_cpystrn(u_char *dst, u_char *src, size_t n);
uint32_t ngx_utf8_decode(u_char **p, size_t n);
size_t ngx_utf8_length(u_char *p, size_t n);
u_char *ngx_utf8_cpystrn(u_char *dst, u_char *src, size_t n, size_t len);
#define NGX_ESCAPE_URI 0

View File

@ -291,3 +291,42 @@ ngx_gmtime(time_t t, ngx_tm_t *tp)
tp->ngx_tm_year = (ngx_tm_year_t) year;
tp->ngx_tm_wday = (ngx_tm_wday_t) wday;
}
time_t
ngx_next_time(time_t when)
{
time_t now, next;
struct tm tm;
now = ngx_time();
ngx_libc_localtime(now, &tm);
tm.tm_hour = (int) (when / 3600);
when %= 3600;
tm.tm_min = (int) (when / 60);
tm.tm_sec = (int) (when % 60);
next = mktime(&tm);
if (next == -1) {
return -1;
}
if (next - now > 0) {
return next;
}
tm.tm_mday++;
/* mktime() should normalize a date (Jan 32, etc) */
next = mktime(&tm);
if (next != -1) {
return next;
}
return -1;
}

View File

@ -25,6 +25,9 @@ u_char *ngx_http_time(u_char *buf, time_t t);
u_char *ngx_http_cookie_time(u_char *buf, time_t t);
void ngx_gmtime(time_t t, ngx_tm_t *tp);
time_t ngx_next_time(time_t when);
#define ngx_next_time_n "mktime()"
extern volatile ngx_time_t *ngx_cached_time;

View File

@ -446,7 +446,7 @@ ngx_kqueue_set_event(ngx_event_t *ev, ngx_int_t filter, ngx_uint_t flags)
|| __FreeBSD_version >= 500018
|NOTE_REVOKE
#endif
;
;
kev->data = 0;
} else {

View File

@ -942,7 +942,7 @@ ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_str_t *value;
if (ecf->connections != NGX_CONF_UNSET_UINT) {
return "is duplicate" ;
return "is duplicate";
}
if (ngx_strcmp(cmd->name.data, "connections") == 0) {
@ -977,7 +977,7 @@ ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_event_module_t *module;
if (ecf->use != NGX_CONF_UNSET_UINT) {
return "is duplicate" ;
return "is duplicate";
}
value = cf->args->elts;

View File

@ -139,11 +139,22 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc)
if (rc == -1) {
err = ngx_socket_errno;
/* Winsock returns WSAEWOULDBLOCK (NGX_EAGAIN) */
if (err != NGX_EINPROGRESS && err != NGX_EAGAIN) {
if (err != NGX_EINPROGRESS
#if (NGX_WIN32)
/* Winsock returns WSAEWOULDBLOCK (NGX_EAGAIN) */
&& err != NGX_EAGAIN
#endif
)
{
if (err == NGX_ECONNREFUSED
#if (NGX_LINUX)
/*
* Linux returns EAGAIN instead of ECONNREFUSED
* for unix sockets if listen queue is full
*/
|| err == NGX_EAGAIN
#endif
|| err == NGX_ENETDOWN
|| err == NGX_ENETUNREACH
|| err == NGX_EHOSTDOWN

View File

@ -10,7 +10,7 @@
typedef struct {
ngx_str_t engine;
ngx_uint_t engine; /* unsigned engine:1; */
} ngx_openssl_conf_t;
@ -37,26 +37,17 @@ static void ngx_ssl_session_rbtree_insert_value(ngx_rbtree_node_t *temp,
ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel);
static void *ngx_openssl_create_conf(ngx_cycle_t *cycle);
static char *ngx_openssl_init_conf(ngx_cycle_t *cycle, void *conf);
static char *ngx_openssl_engine(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static void ngx_openssl_exit(ngx_cycle_t *cycle);
#if !(NGX_SSL_ENGINE)
static char *ngx_openssl_noengine(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
#endif
static ngx_command_t ngx_openssl_commands[] = {
{ ngx_string("ssl_engine"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
#if (NGX_SSL_ENGINE)
ngx_conf_set_str_slot,
#else
ngx_openssl_noengine,
#endif
ngx_openssl_engine,
0,
0,
offsetof(ngx_openssl_conf_t, engine),
NULL },
ngx_null_command
@ -66,7 +57,7 @@ static ngx_command_t ngx_openssl_commands[] = {
static ngx_core_module_t ngx_openssl_module_ctx = {
ngx_string("openssl"),
ngx_openssl_create_conf,
ngx_openssl_init_conf
NULL
};
@ -187,13 +178,6 @@ ngx_ssl_create(ngx_ssl_t *ssl, ngx_uint_t protocols, void *data)
SSL_CTX_set_options(ssl->ctx, ngx_ssl_protocols[protocols >> 1]);
}
/*
* we need this option because in ngx_ssl_send_chain()
* we may switch to a buffered write and may copy leftover part of
* previously unbuffered data to our internal buffer
*/
SSL_CTX_set_mode(ssl->ctx, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
SSL_CTX_set_read_ahead(ssl->ctx, 1);
return NGX_OK;
@ -590,6 +574,11 @@ ngx_ssl_recv_chain(ngx_connection_t *c, ngx_chain_t *cl)
}
if (bytes) {
if (n == 0 || n == NGX_ERROR) {
c->read->ready = 1;
}
return bytes;
}
@ -771,14 +760,7 @@ ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
ssize_t send, size;
ngx_buf_t *buf;
if (!c->ssl->buffer
|| (in && in->next == NULL && !(c->buffered & NGX_SSL_BUFFERED)))
{
/*
* we avoid a buffer copy if
* we do not need to buffer the output
* or the incoming buf is a single and our buffer is empty
*/
if (!c->ssl->buffer) {
while (in) {
if (ngx_buf_special(in->buf)) {
@ -1267,6 +1249,29 @@ ngx_ssl_session_cache(ngx_ssl_t *ssl, ngx_str_t *sess_ctx,
return NGX_OK;
}
if (builtin_session_cache == NGX_SSL_NONE_SCACHE) {
/*
* If the server explicitly says that it does not support
* session reuse (see SSL_SESS_CACHE_OFF above), then
* Outlook Express fails to upload a sent email to
* the Sent Items folder on the IMAP server via a separate IMAP
* connection in the background. Therefore we have a special
* mode (SSL_SESS_CACHE_SERVER|SSL_SESS_CACHE_NO_INTERNAL_STORE)
* where the server pretends that it supports session reuse,
* but it does not actually store any session.
*/
SSL_CTX_set_session_cache_mode(ssl->ctx,
SSL_SESS_CACHE_SERVER
|SSL_SESS_CACHE_NO_AUTO_CLEAR
|SSL_SESS_CACHE_NO_INTERNAL_STORE);
SSL_CTX_sess_set_cache_size(ssl->ctx, 1);
return NGX_OK;
}
cache_mode = SSL_SESS_CACHE_SERVER;
if (shm_zone && builtin_session_cache == NGX_SSL_NO_BUILTIN_SCACHE) {
@ -1907,8 +1912,7 @@ ngx_openssl_create_conf(ngx_cycle_t *cycle)
/*
* set by ngx_pcalloc():
*
* oscf->engine.len = 0;
* oscf->engine.data = NULL;
* oscf->engine = 0;
*/
return oscf;
@ -1916,53 +1920,54 @@ ngx_openssl_create_conf(ngx_cycle_t *cycle)
static char *
ngx_openssl_init_conf(ngx_cycle_t *cycle, void *conf)
ngx_openssl_engine(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
#if (NGX_SSL_ENGINE)
ngx_openssl_conf_t *oscf = conf;
ENGINE *engine;
ENGINE *engine;
ngx_str_t *value;
if (oscf->engine.len == 0) {
return NGX_CONF_OK;
if (oscf->engine) {
return "is duplicate";
}
engine = ENGINE_by_id((const char *) oscf->engine.data);
oscf->engine = 1;
value = cf->args->elts;
engine = ENGINE_by_id((const char *) value[1].data);
if (engine == NULL) {
ngx_ssl_error(NGX_LOG_WARN, cycle->log, 0,
"ENGINE_by_id(\"%V\") failed", &oscf->engine);
ngx_ssl_error(NGX_LOG_WARN, cf->log, 0,
"ENGINE_by_id(\"%V\") failed", &value[1]);
return NGX_CONF_ERROR;
}
if (ENGINE_set_default(engine, ENGINE_METHOD_ALL) == 0) {
ngx_ssl_error(NGX_LOG_WARN, cycle->log, 0,
ngx_ssl_error(NGX_LOG_WARN, cf->log, 0,
"ENGINE_set_default(\"%V\", ENGINE_METHOD_ALL) failed",
&oscf->engine);
&value[1]);
ENGINE_free(engine);
return NGX_CONF_ERROR;
}
ENGINE_free(engine);
#endif
return NGX_CONF_OK;
}
#else
#if !(NGX_SSL_ENGINE)
static char *
ngx_openssl_noengine(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"\"ssl_engine\" directive is available only in "
"OpenSSL 0.9.7 and higher,");
return NGX_CONF_ERROR;
}
#endif
}
static void

View File

@ -51,9 +51,10 @@ typedef struct {
} ngx_ssl_connection_t;
#define NGX_SSL_DFLT_BUILTIN_SCACHE -2
#define NGX_SSL_NO_BUILTIN_SCACHE -3
#define NGX_SSL_NO_SCACHE -4
#define NGX_SSL_NO_SCACHE -2
#define NGX_SSL_NONE_SCACHE -3
#define NGX_SSL_NO_BUILTIN_SCACHE -4
#define NGX_SSL_DFLT_BUILTIN_SCACHE -5
#define NGX_SSL_MAX_SESSION_SIZE 4096

View File

@ -880,7 +880,7 @@ ngx_event_pipe_free_shadow_raw_buf(ngx_chain_t **free, ngx_buf_t *buf)
ll = free;
for (cl = *free ; cl; cl = cl->next) {
for (cl = *free; cl; cl = cl->next) {
if (cl->buf == s) {
*ll = cl->next;
break;

View File

@ -135,7 +135,7 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
{
u_char *last, *filename, scale;
off_t length;
size_t len, copy, allocated, root;
size_t len, utf_len, allocated, root;
ngx_tm_t tm;
ngx_err_t err;
ngx_buf_t *b;
@ -299,6 +299,11 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
if (err != NGX_ENOENT) {
ngx_log_error(NGX_LOG_CRIT, r->connection->log, err,
ngx_de_info_n " \"%s\" failed", filename);
if (err == NGX_EACCES) {
continue;
}
return ngx_http_autoindex_error(r, &dir, &path);
}
@ -329,7 +334,7 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
NGX_ESCAPE_HTML);
if (r->utf8) {
entry->utf_len = ngx_utf_length(entry->name.data, entry->name.len);
entry->utf_len = ngx_utf8_length(entry->name.data, entry->name.len);
} else {
entry->utf_len = len;
}
@ -412,15 +417,16 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
len = entry[i].utf_len;
if (entry[i].name.len - len) {
if (entry[i].name.len != len) {
if (len > NGX_HTTP_AUTOINDEX_NAME_LEN) {
copy = NGX_HTTP_AUTOINDEX_NAME_LEN - 3 + 1;
utf_len = NGX_HTTP_AUTOINDEX_NAME_LEN - 3 + 1;
} else {
copy = NGX_HTTP_AUTOINDEX_NAME_LEN + 1;
utf_len = NGX_HTTP_AUTOINDEX_NAME_LEN + 1;
}
b->last = ngx_utf_cpystrn(b->last, entry[i].name.data, copy);
b->last = ngx_utf8_cpystrn(b->last, entry[i].name.data,
utf_len, entry[i].name.len + 1);
last = b->last;
} else {

View File

@ -204,6 +204,12 @@ ngx_http_charset_header_filter(ngx_http_request_t *r)
if (r == r->main) {
if (r->headers_out.content_encoding
&& r->headers_out.content_encoding->value.len)
{
return ngx_http_next_header_filter(r);
}
if (r->headers_out.content_type.len == 0) {
return ngx_http_next_header_filter(r);
}
@ -636,7 +642,7 @@ ngx_http_charset_recode_from_utf8(ngx_pool_t *pool, ngx_buf_t *buf,
size = buf->last - src;
saved = src;
n = ngx_utf_decode(&saved, size);
n = ngx_utf8_decode(&saved, size);
if (n == 0xfffffffe) {
/* incomplete UTF-8 symbol */
@ -704,7 +710,7 @@ ngx_http_charset_recode_from_utf8(ngx_pool_t *pool, ngx_buf_t *buf,
}
saved = ctx->saved;
n = ngx_utf_decode(&saved, i);
n = ngx_utf8_decode(&saved, i);
c = '\0';
@ -812,7 +818,7 @@ recode:
len = buf->last - src;
n = ngx_utf_decode(&src, len);
n = ngx_utf8_decode(&src, len);
if (n < 0x10000) {
@ -1264,7 +1270,7 @@ ngx_http_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
p = &table->src2dst[src * NGX_UTF_LEN] + 1;
n = ngx_utf_decode(&p, i);
n = ngx_utf8_decode(&p, i);
if (n > 0xffff) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,

View File

@ -512,7 +512,7 @@ ngx_http_dav_mkcol_handler(ngx_http_request_t *r, ngx_http_dav_loc_conf_t *dlcf)
static ngx_int_t
ngx_http_dav_copy_move_handler(ngx_http_request_t *r)
{
u_char *p, *desthost, *last, ch;
u_char *p, *host, *last, ch;
size_t len, root;
ngx_err_t err;
ngx_int_t rc, depth;
@ -520,7 +520,7 @@ ngx_http_dav_copy_move_handler(ngx_http_request_t *r)
ngx_str_t path, uri;
ngx_tree_ctx_t tree;
ngx_file_info_t fi;
ngx_table_elt_t *host, *dest, *over;
ngx_table_elt_t *dest, *over;
ngx_http_dav_copy_ctx_t copy;
ngx_http_dav_loc_conf_t *dlcf;
@ -536,9 +536,9 @@ ngx_http_dav_copy_move_handler(ngx_http_request_t *r)
return NGX_HTTP_BAD_REQUEST;
}
host = r->headers_in.host;
len = r->headers_in.server.len;
if (host == NULL) {
if (len == 0) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"client sent no \"Host\" header");
return NGX_HTTP_BAD_REQUEST;
@ -553,7 +553,7 @@ ngx_http_dav_copy_move_handler(ngx_http_request_t *r)
goto invalid_destination;
}
desthost = dest->value.data + sizeof("https://") - 1;
host = dest->value.data + sizeof("https://") - 1;
} else
#endif
@ -564,12 +564,10 @@ ngx_http_dav_copy_move_handler(ngx_http_request_t *r)
goto invalid_destination;
}
desthost = dest->value.data + sizeof("http://") - 1;
host = dest->value.data + sizeof("http://") - 1;
}
len = r->headers_in.host_name_len;
if (ngx_strncmp(desthost, host->value.data, len) != 0) {
if (ngx_strncmp(host, r->headers_in.server.data, len) != 0) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"\"Destination\" URI \"%V\" is handled by "
"different repository than the source URI",
@ -579,7 +577,7 @@ ngx_http_dav_copy_move_handler(ngx_http_request_t *r)
last = dest->value.data + dest->value.len;
for (p = desthost + len; p < last; p++) {
for (p = host + len; p < last; p++) {
if (*p == '/') {
goto destination_done;
}

View File

@ -1189,6 +1189,13 @@ ngx_http_fastcgi_process_header(ngx_http_request_t *r)
u->headers_in.status_n = status;
u->headers_in.status_line = *status_line;
} else if (u->headers_in.location) {
u->headers_in.status_n = 302;
u->headers_in.status_line.len =
sizeof("302 Moved Temporarily") - 1;
u->headers_in.status_line.data =
(u_char *) "302 Moved Temporarily";
} else {
u->headers_in.status_n = 200;
u->headers_in.status_line.len = sizeof("200 OK") - 1;

View File

@ -60,7 +60,7 @@ ngx_module_t ngx_http_flv_module = {
static ngx_int_t
ngx_http_flv_handler(ngx_http_request_t *r)
{
u_char *p, *last;
u_char *p, *n, *last;
off_t start, len;
size_t root;
ngx_int_t rc;
@ -168,7 +168,13 @@ ngx_http_flv_handler(ngx_http_request_t *r)
if (p) {
p += 6;
start = ngx_atoof(p, r->args.len - (p - r->args.data));
for (n = p; n < r->args.data + r->args.len; n++) {
if (*n == '&') {
break;
}
}
start = ngx_atoof(p, n - p);
if (start == NGX_ERROR || start >= len) {
start = 0;

View File

@ -204,12 +204,11 @@ static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
static ngx_int_t
ngx_http_gzip_header_filter(ngx_http_request_t *r)
{
ngx_str_t *type;
ngx_uint_t i;
ngx_table_elt_t *h;
ngx_http_gzip_ctx_t *ctx;
ngx_http_gzip_conf_t *conf;
ngx_http_core_loc_conf_t *clcf;
ngx_str_t *type;
ngx_uint_t i;
ngx_table_elt_t *h;
ngx_http_gzip_ctx_t *ctx;
ngx_http_gzip_conf_t *conf;
conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
@ -264,21 +263,6 @@ found:
r->headers_out.content_encoding = h;
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
if (clcf->gzip_vary) {
h = ngx_list_push(&r->headers_out.headers);
if (h == NULL) {
return NGX_ERROR;
}
h->hash = 1;
h->key.len = sizeof("Vary") - 1;
h->key.data = (u_char *) "Vary";
h->value.len = sizeof("Accept-Encoding") - 1;
h->value.data = (u_char *) "Accept-Encoding";
}
ctx->length = r->headers_out.content_length_n;
r->main_filter_need_in_memory = 1;

View File

@ -203,19 +203,6 @@ ngx_http_gzip_static_handler(ngx_http_request_t *r)
r->headers_out.content_encoding = h;
if (clcf->gzip_vary) {
h = ngx_list_push(&r->headers_out.headers);
if (h == NULL) {
return NGX_ERROR;
}
h->hash = 1;
h->key.len = sizeof("Vary") - 1;
h->key.data = (u_char *) "Vary";
h->value.len = sizeof("Accept-Encoding") - 1;
h->value.data = (u_char *) "Accept-Encoding";
}
/* we need to allocate all before the header would be sent */
b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));

View File

@ -31,18 +31,21 @@ struct ngx_http_header_val_s {
};
#define NGX_HTTP_EXPIRES_OFF 0
#define NGX_HTTP_EXPIRES_EPOCH 1
#define NGX_HTTP_EXPIRES_MAX 2
#define NGX_HTTP_EXPIRES_ACCESS 3
#define NGX_HTTP_EXPIRES_MODIFIED 4
#define NGX_HTTP_EXPIRES_DAILY 5
typedef struct {
time_t expires;
ngx_uint_t expires;
time_t expires_time;
ngx_array_t *headers;
} ngx_http_headers_conf_t;
#define NGX_HTTP_EXPIRES_UNSET -2147483647
#define NGX_HTTP_EXPIRES_OFF -2147483646
#define NGX_HTTP_EXPIRES_EPOCH -2147483645
#define NGX_HTTP_EXPIRES_MAX -2147483644
static ngx_int_t ngx_http_set_expires(ngx_http_request_t *r,
ngx_http_headers_conf_t *conf);
static ngx_int_t ngx_http_add_cache_control(ngx_http_request_t *r,
@ -76,7 +79,7 @@ static ngx_command_t ngx_http_headers_filter_commands[] = {
{ ngx_string("expires"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|NGX_CONF_TAKE1,
|NGX_CONF_TAKE12,
ngx_http_headers_expires,
NGX_HTTP_LOC_CONF_OFFSET,
0,
@ -185,6 +188,7 @@ static ngx_int_t
ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
{
size_t len;
time_t now, expires_time, max_age;
ngx_uint_t i;
ngx_table_elt_t *expires, *cc, **ccp;
@ -266,7 +270,7 @@ ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
return NGX_ERROR;
}
if (conf->expires == 0) {
if (conf->expires_time == 0) {
ngx_memcpy(expires->value.data, ngx_cached_http_time.data,
ngx_cached_http_time.len + 1);
@ -276,9 +280,26 @@ ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
return NGX_OK;
}
ngx_http_time(expires->value.data, ngx_time() + conf->expires);
now = ngx_time();
if (conf->expires < 0) {
if (conf->expires == NGX_HTTP_EXPIRES_ACCESS
|| r->headers_out.last_modified_time == -1)
{
expires_time = now + conf->expires_time;
max_age = conf->expires_time;
} else if (conf->expires == NGX_HTTP_EXPIRES_DAILY) {
expires_time = ngx_next_time(conf->expires_time);
max_age = expires_time - now;
} else {
expires_time = r->headers_out.last_modified_time + conf->expires_time;
max_age = expires_time - now;
}
ngx_http_time(expires->value.data, expires_time);
if (conf->expires_time < 0) {
cc->value.len = sizeof("no-cache") - 1;
cc->value.data = (u_char *) "no-cache";
@ -291,7 +312,7 @@ ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
return NGX_ERROR;
}
cc->value.len = ngx_sprintf(cc->value.data, "max-age=%T", conf->expires)
cc->value.len = ngx_sprintf(cc->value.data, "max-age=%T", max_age)
- cc->value.data;
return NGX_OK;
@ -413,9 +434,10 @@ ngx_http_headers_create_conf(ngx_conf_t *cf)
* set by ngx_pcalloc():
*
* conf->headers = NULL;
* conf->expires_time = 0;
*/
conf->expires = NGX_HTTP_EXPIRES_UNSET;
conf->expires = NGX_CONF_UNSET_UINT;
return conf;
}
@ -427,9 +449,13 @@ ngx_http_headers_merge_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_http_headers_conf_t *prev = parent;
ngx_http_headers_conf_t *conf = child;
if (conf->expires == NGX_HTTP_EXPIRES_UNSET) {
conf->expires = (prev->expires == NGX_HTTP_EXPIRES_UNSET) ?
NGX_HTTP_EXPIRES_OFF : prev->expires;
if (conf->expires == NGX_CONF_UNSET_UINT) {
conf->expires = prev->expires;
conf->expires_time = prev->expires_time;
if (conf->expires == NGX_CONF_UNSET_UINT) {
conf->expires = NGX_HTTP_EXPIRES_OFF;
}
}
if (conf->headers == NULL) {
@ -455,56 +481,90 @@ ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_headers_conf_t *hcf = conf;
ngx_uint_t minus;
ngx_uint_t minus, n;
ngx_str_t *value;
if (hcf->expires != NGX_HTTP_EXPIRES_UNSET) {
if (hcf->expires != NGX_CONF_UNSET_UINT) {
return "is duplicate";
}
value = cf->args->elts;
if (ngx_strcmp(value[1].data, "epoch") == 0) {
hcf->expires = NGX_HTTP_EXPIRES_EPOCH;
return NGX_CONF_OK;
if (cf->args->nelts == 2) {
if (ngx_strcmp(value[1].data, "epoch") == 0) {
hcf->expires = NGX_HTTP_EXPIRES_EPOCH;
return NGX_CONF_OK;
}
if (ngx_strcmp(value[1].data, "max") == 0) {
hcf->expires = NGX_HTTP_EXPIRES_MAX;
return NGX_CONF_OK;
}
if (ngx_strcmp(value[1].data, "off") == 0) {
hcf->expires = NGX_HTTP_EXPIRES_OFF;
return NGX_CONF_OK;
}
hcf->expires = NGX_HTTP_EXPIRES_ACCESS;
n = 1;
} else { /* cf->args->nelts == 3 */
if (ngx_strcmp(value[1].data, "modified") != 0) {
return "invalid value";
}
hcf->expires = NGX_HTTP_EXPIRES_MODIFIED;
n = 2;
}
if (ngx_strcmp(value[1].data, "max") == 0) {
hcf->expires = NGX_HTTP_EXPIRES_MAX;
return NGX_CONF_OK;
}
if (ngx_strcmp(value[1].data, "off") == 0) {
hcf->expires = NGX_HTTP_EXPIRES_OFF;
return NGX_CONF_OK;
}
if (value[1].data[0] == '+') {
value[1].data++;
value[1].len--;
if (value[n].data[0] == '@') {
value[n].data++;
value[n].len--;
minus = 0;
} else if (value[1].data[0] == '-') {
value[1].data++;
value[1].len--;
if (hcf->expires == NGX_HTTP_EXPIRES_MODIFIED) {
return "daily time can not be used with \"modified\" parameter";
}
hcf->expires = NGX_HTTP_EXPIRES_DAILY;
} else if (value[n].data[0] == '+') {
value[n].data++;
value[n].len--;
minus = 0;
} else if (value[n].data[0] == '-') {
value[n].data++;
value[n].len--;
minus = 1;
} else {
minus = 0;
}
hcf->expires = ngx_parse_time(&value[1], 1);
hcf->expires_time = ngx_parse_time(&value[n], 1);
if (hcf->expires == NGX_ERROR) {
if (hcf->expires_time == NGX_ERROR) {
return "invalid value";
}
if (hcf->expires == NGX_PARSE_LARGE_TIME) {
if (hcf->expires == NGX_HTTP_EXPIRES_DAILY
&& hcf->expires_time > 24 * 60 * 60)
{
return "daily time value must be less than 24 hours";
}
if (hcf->expires_time == NGX_PARSE_LARGE_TIME) {
return "value must be less than 68 years";
}
if (minus) {
hcf->expires = - hcf->expires;
hcf->expires_time = - hcf->expires_time;
}
return NGX_CONF_OK;

View File

@ -27,8 +27,8 @@ typedef struct {
static ngx_int_t ngx_http_index_test_dir(ngx_http_request_t *r,
ngx_http_core_loc_conf_t *clcf, u_char *path, u_char *last);
static ngx_int_t ngx_http_index_error(ngx_http_request_t *r, u_char *file,
ngx_err_t err);
static ngx_int_t ngx_http_index_error(ngx_http_request_t *r,
ngx_http_core_loc_conf_t *clcf, u_char *file, ngx_err_t err);
static ngx_int_t ngx_http_index_init(ngx_conf_t *cf);
static void *ngx_http_index_create_loc_conf(ngx_conf_t *cf);
@ -225,7 +225,7 @@ ngx_http_index_handler(ngx_http_request_t *r)
}
if (of.err == NGX_ENOTDIR || of.err == NGX_EACCES) {
return ngx_http_index_error(r, path.data, of.err);
return ngx_http_index_error(r, clcf, path.data, of.err);
}
if (!dir_tested) {
@ -303,7 +303,20 @@ ngx_http_index_test_dir(ngx_http_request_t *r, ngx_http_core_loc_conf_t *clcf,
if (of.err == NGX_ENOENT) {
*last = c;
return ngx_http_index_error(r, dir.data, NGX_ENOENT);
return ngx_http_index_error(r, clcf, dir.data, NGX_ENOENT);
}
if (of.err == NGX_EACCES) {
*last = c;
/*
* ngx_http_index_test_dir() is called after the first index
* file testing has returned an error distinct from NGX_EACCES.
* This means that directory searching is allowed.
*/
return NGX_OK;
}
ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
@ -327,7 +340,8 @@ ngx_http_index_test_dir(ngx_http_request_t *r, ngx_http_core_loc_conf_t *clcf,
static ngx_int_t
ngx_http_index_error(ngx_http_request_t *r, u_char *file, ngx_err_t err)
ngx_http_index_error(ngx_http_request_t *r, ngx_http_core_loc_conf_t *clcf,
u_char *file, ngx_err_t err)
{
if (err == NGX_EACCES) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, err,
@ -336,8 +350,10 @@ ngx_http_index_error(ngx_http_request_t *r, u_char *file, ngx_err_t err)
return NGX_HTTP_FORBIDDEN;
}
ngx_log_error(NGX_LOG_ERR, r->connection->log, err,
"\"%s\" is not found", file);
if (clcf->log_not_found) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, err,
"\"%s\" is not found", file);
}
return NGX_HTTP_NOT_FOUND;
}

View File

@ -88,6 +88,7 @@ static size_t ngx_http_log_variable_getlen(ngx_http_request_t *r,
uintptr_t data);
static u_char *ngx_http_log_variable(ngx_http_request_t *r, u_char *buf,
ngx_http_log_op_t *op);
static uintptr_t ngx_http_log_escape(u_char *dst, u_char *src, size_t size);
static void *ngx_http_log_create_main_conf(ngx_conf_t *cf);
@ -478,6 +479,7 @@ ngx_http_log_variable_compile(ngx_conf_t *cf, ngx_http_log_op_t *op,
static size_t
ngx_http_log_variable_getlen(ngx_http_request_t *r, uintptr_t data)
{
uintptr_t len;
ngx_http_variable_value_t *value;
value = ngx_http_get_indexed_variable(r, data);
@ -486,7 +488,11 @@ ngx_http_log_variable_getlen(ngx_http_request_t *r, uintptr_t data)
return 1;
}
return value->len;
len = ngx_http_log_escape(NULL, value->data, value->len);
value->escape = len ? 1 : 0;
return value->len + len * 3;
}
@ -502,7 +508,70 @@ ngx_http_log_variable(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op)
return buf + 1;
}
return ngx_cpymem(buf, value->data, value->len);
if (value->escape == 0) {
return ngx_cpymem(buf, value->data, value->len);
} else {
return (u_char *) ngx_http_log_escape(buf, value->data, value->len);
}
}
static uintptr_t
ngx_http_log_escape(u_char *dst, u_char *src, size_t size)
{
ngx_uint_t i, n;
static u_char hex[] = "0123456789ABCDEF";
static uint32_t escape[] = {
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
/* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
0x00000004, /* 0000 0000 0000 0000 0000 0000 0000 0100 */
/* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
0x10000000, /* 0001 0000 0000 0000 0000 0000 0000 0000 */
/* ~}| {zyx wvut srqp onml kjih gfed cba` */
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
};
if (dst == NULL) {
/* find the number of the characters to be escaped */
n = 0;
for (i = 0; i < size; i++) {
if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
n++;
}
src++;
}
return (uintptr_t) n;
}
for (i = 0; i < size; i++) {
if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
*dst++ = '\\';
*dst++ = 'x';
*dst++ = hex[*src >> 4];
*dst++ = hex[*src & 0xf];
src++;
} else {
*dst++ = *src++;
}
}
return (uintptr_t) dst;
}

View File

@ -50,7 +50,8 @@ static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
static
ngx_int_t ngx_http_not_modified_header_filter(ngx_http_request_t *r)
{
time_t ims;
time_t ims;
ngx_http_core_loc_conf_t *clcf;
if (r->headers_out.status != NGX_HTTP_OK
|| r != r->main
@ -60,23 +61,32 @@ ngx_int_t ngx_http_not_modified_header_filter(ngx_http_request_t *r)
return ngx_http_next_header_filter(r);
}
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
if (clcf->if_modified_since == NGX_HTTP_IMS_OFF) {
return ngx_http_next_header_filter(r);
}
ims = ngx_http_parse_time(r->headers_in.if_modified_since->value.data,
r->headers_in.if_modified_since->value.len);
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http ims:%d lm:%d", ims, r->headers_out.last_modified_time);
/*
* I think that the equality of the dates is correcter
*/
if (ims != r->headers_out.last_modified_time) {
if (ims == r->headers_out.last_modified_time) {
r->headers_out.status = NGX_HTTP_NOT_MODIFIED;
r->headers_out.content_type.len = 0;
ngx_http_clear_content_length(r);
ngx_http_clear_accept_ranges(r);
if (clcf->if_modified_since == NGX_HTTP_IMS_EXACT
|| ims < r->headers_out.last_modified_time)
{
return ngx_http_next_header_filter(r);
}
}
r->headers_out.status = NGX_HTTP_NOT_MODIFIED;
r->headers_out.content_type.len = 0;
ngx_http_clear_content_length(r);
ngx_http_clear_accept_ranges(r);
return ngx_http_next_header_filter(r);
}

View File

@ -424,6 +424,7 @@ static ngx_keyval_t ngx_http_proxy_headers[] = {
{ ngx_string("Host"), ngx_string("$proxy_host") },
{ ngx_string("Connection"), ngx_string("close") },
{ ngx_string("Keep-Alive"), ngx_string("") },
{ ngx_string("Expect"), ngx_string("") },
{ ngx_null_string, ngx_null_string }
};
@ -1224,7 +1225,7 @@ ngx_http_proxy_process_header(ngx_http_request_t *r)
umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);
for ( ;; ) {
for ( ;; ) {
rc = ngx_http_parse_header_line(r, &r->upstream->buffer);
@ -1898,6 +1899,12 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
conf->proxy_values = prev->proxy_values;
}
#if (NGX_HTTP_SSL)
if (conf->upstream.ssl == NULL) {
conf->upstream.ssl = prev->upstream.ssl;
}
#endif
ngx_conf_merge_uint_value(conf->headers_hash_max_size,
prev->headers_hash_max_size, 512);

View File

@ -357,6 +357,12 @@ ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
last = 1;
}
if (ngx_strncmp(value[2].data, "https://", sizeof("https://") - 1) == 0) {
regex->status = NGX_HTTP_MOVED_TEMPORARILY;
regex->redirect = 1;
last = 1;
}
if (cf->args->nelts == 4) {
if (ngx_strcmp(value[3].data, "last") == 0) {
last = 1;

View File

@ -100,7 +100,7 @@ static ngx_int_t ngx_http_ssi_endblock(ngx_http_request_t *r,
ngx_http_ssi_ctx_t *ctx, ngx_str_t **params);
static ngx_int_t ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t gmt);
ngx_http_variable_value_t *v, uintptr_t gmt);
static char *ngx_http_ssi_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
@ -558,8 +558,9 @@ ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
if (b->in_file) {
if (slcf->min_file_chunk < (size_t) (b->last - b->pos))
{
b->file_last = b->file_pos + (b->last - b->start);
b->file_pos += b->pos - b->start;
b->file_last = b->file_pos
+ (b->last - ctx->buf->pos);
b->file_pos += b->pos - ctx->buf->pos;
} else {
b->in_file = 0;
@ -1637,7 +1638,7 @@ ngx_http_ssi_evaluate_string(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
quoted = 0;
for (i = 0 ; i < text->len; i++) {
for (i = 0; i < text->len; i++) {
ch = text->data[i];
if (!quoted) {
@ -2647,7 +2648,7 @@ ngx_http_ssi_endblock(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
static ngx_int_t
ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t gmt)
ngx_http_variable_value_t *v, uintptr_t gmt)
{
ngx_http_ssi_ctx_t *ctx;
ngx_time_t *tp;

View File

@ -415,7 +415,7 @@ ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
}
ngx_conf_merge_value(conf->builtin_session_cache,
prev->builtin_session_cache, NGX_SSL_NO_SCACHE);
prev->builtin_session_cache, NGX_SSL_NONE_SCACHE);
if (conf->shm_zone == NULL) {
conf->shm_zone = prev->shm_zone;
@ -452,6 +452,11 @@ ngx_http_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
continue;
}
if (ngx_strcmp(value[i].data, "none") == 0) {
sscf->builtin_session_cache = NGX_SSL_NONE_SCACHE;
continue;
}
if (ngx_strcmp(value[i].data, "builtin") == 0) {
sscf->builtin_session_cache = NGX_SSL_DFLT_BUILTIN_SCACHE;
continue;

View File

@ -48,7 +48,7 @@ static ngx_int_t
ngx_http_static_handler(ngx_http_request_t *r)
{
u_char *last, *location;
size_t root;
size_t root, len;
ngx_str_t path;
ngx_int_t rc;
ngx_uint_t level;
@ -58,7 +58,7 @@ ngx_http_static_handler(ngx_http_request_t *r)
ngx_open_file_info_t of;
ngx_http_core_loc_conf_t *clcf;
if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD|NGX_HTTP_POST))) {
return NGX_HTTP_NOT_ALLOWED;
}
@ -71,12 +71,6 @@ ngx_http_static_handler(ngx_http_request_t *r)
return NGX_DECLINED;
}
rc = ngx_http_discard_request_body(r);
if (rc != NGX_OK) {
return rc;
}
log = r->connection->log;
/*
@ -150,26 +144,39 @@ ngx_http_static_handler(ngx_http_request_t *r)
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
if (!clcf->alias && clcf->root_lengths == NULL) {
len = r->uri.len + 1;
if (!clcf->alias && clcf->root_lengths == NULL && r->args.len == 0) {
location = path.data + clcf->root.len;
*last = '/';
} else {
location = ngx_palloc(r->pool, r->uri.len + 1);
if (r->args.len) {
len += r->args.len + 1;
}
location = ngx_palloc(r->pool, len);
if (location == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
last = ngx_copy(location, r->uri.data, r->uri.len);
}
*last = '/';
*last = '/';
if (r->args.len) {
*++last = '?';
ngx_memcpy(++last, r->args.data, r->args.len);
}
}
/*
* we do not need to set the r->headers_out.location->hash and
* r->headers_out.location->key fields
*/
r->headers_out.location->value.len = r->uri.len + 1;
r->headers_out.location->value.len = len;
r->headers_out.location->value.data = location;
return NGX_HTTP_MOVED_PERMANENTLY;
@ -186,6 +193,16 @@ ngx_http_static_handler(ngx_http_request_t *r)
#endif
if (r->method & NGX_HTTP_POST) {
return NGX_HTTP_NOT_ALLOWED;
}
rc = ngx_http_discard_request_body(r);
if (rc != NGX_OK) {
return rc;
}
log->action = "sending response to client";
r->headers_out.status = NGX_HTTP_OK;

View File

@ -322,8 +322,8 @@ ngx_http_sub_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
b->recycled = 0;
if (b->in_file) {
b->file_last = b->file_pos + (b->last - b->start);
b->file_pos += b->pos - b->start;
b->file_last = b->file_pos + (b->last - ctx->buf->pos);
b->file_pos += b->pos - ctx->buf->pos;
}
cl->next = NULL;

View File

@ -41,15 +41,14 @@ typedef struct {
} ngx_http_userid_ctx_t;
static void ngx_http_userid_get_uid(ngx_http_request_t *r,
ngx_http_userid_ctx_t *ctx, ngx_http_userid_conf_t *conf);
static ngx_http_userid_ctx_t *ngx_http_userid_get_uid(ngx_http_request_t *r,
ngx_http_userid_conf_t *conf);
static ngx_int_t ngx_http_userid_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, ngx_str_t *name, uint32_t *uid);
static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
ngx_http_userid_ctx_t *ctx, ngx_http_userid_conf_t *conf);
static ngx_int_t ngx_http_userid_add_variables(ngx_conf_t *cf);
static ngx_int_t ngx_http_userid_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_userid_init(ngx_conf_t *cf);
static void *ngx_http_userid_create_conf(ngx_conf_t *cf);
static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent,
@ -191,7 +190,6 @@ static ngx_str_t ngx_http_userid_set = ngx_string("uid_set");
static ngx_int_t
ngx_http_userid_filter(ngx_http_request_t *r)
{
ngx_int_t rc;
ngx_http_userid_ctx_t *ctx;
ngx_http_userid_conf_t *conf;
@ -201,25 +199,18 @@ ngx_http_userid_filter(ngx_http_request_t *r)
conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module);
if (conf->enable == NGX_HTTP_USERID_OFF) {
if (conf->enable <= NGX_HTTP_USERID_LOG) {
return ngx_http_next_header_filter(r);
}
ctx = ngx_http_userid_get_uid(r, conf);
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_userid_ctx_t));
if (ctx == NULL) {
return NGX_ERROR;
}
ngx_http_set_ctx(r, ctx, ngx_http_userid_filter_module);
ngx_http_userid_get_uid(r, ctx, conf);
if (conf->enable == NGX_HTTP_USERID_LOG) {
return ngx_http_next_header_filter(r);
}
if (ctx->uid_got[3] != 0) {
if (conf->mark == '\0') {
return ngx_http_next_header_filter(r);
@ -233,28 +224,95 @@ ngx_http_userid_filter(ngx_http_request_t *r)
}
}
rc = ngx_http_userid_set_uid(r, ctx, conf);
/* ctx->status == NGX_DECLINED */
if (rc != NGX_OK) {
return rc;
if (ngx_http_userid_set_uid(r, ctx, conf) == NGX_OK) {
return ngx_http_next_header_filter(r);
}
return ngx_http_next_header_filter(r);
return NGX_ERROR;
}
static void
ngx_http_userid_get_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
ngx_http_userid_conf_t *conf)
static ngx_int_t
ngx_http_userid_got_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data)
{
ngx_int_t n;
ngx_str_t src, dst;
ngx_table_elt_t **cookies;
ngx_http_userid_ctx_t *ctx;
ngx_http_userid_conf_t *conf;
conf = ngx_http_get_module_loc_conf(r->main, ngx_http_userid_filter_module);
if (conf->enable == NGX_HTTP_USERID_OFF) {
v->not_found = 1;
return NGX_OK;
}
ctx = ngx_http_userid_get_uid(r, conf);
if (ctx == NULL) {
return NGX_ERROR;
}
if (ctx->uid_got[3] != 0) {
return ngx_http_userid_variable(r, v, &conf->name, ctx->uid_got);
}
/* ctx->status == NGX_DECLINED */
v->not_found = 1;
return NGX_OK;
}
static ngx_int_t
ngx_http_userid_set_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data)
{
ngx_http_userid_ctx_t *ctx;
ngx_http_userid_conf_t *conf;
ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module);
if (ctx == NULL || ctx->uid_set[3] == 0) {
v->not_found = 1;
return NGX_OK;
}
conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module);
return ngx_http_userid_variable(r, v, &conf->name, ctx->uid_set);
}
static ngx_http_userid_ctx_t *
ngx_http_userid_get_uid(ngx_http_request_t *r, ngx_http_userid_conf_t *conf)
{
ngx_int_t n;
ngx_str_t src, dst;
ngx_table_elt_t **cookies;
ngx_http_userid_ctx_t *ctx;
ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module);
if (ctx) {
return ctx;
}
if (ctx == NULL) {
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_userid_ctx_t));
if (ctx == NULL) {
return NULL;
}
ngx_http_set_ctx(r, ctx, ngx_http_userid_filter_module);
}
n = ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &conf->name,
&ctx->cookie);
if (n == NGX_DECLINED) {
return;
return ctx;
}
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
@ -265,7 +323,7 @@ ngx_http_userid_get_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"client sent too short userid cookie \"%V\"",
&cookies[n]->value);
return;
return ctx;
}
src = ctx->cookie;
@ -286,13 +344,15 @@ ngx_http_userid_get_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"client sent invalid userid cookie \"%V\"",
&cookies[n]->value);
return;
return ctx;
}
ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"uid: %08XD%08XD%08XD%08XD",
ctx->uid_got[0], ctx->uid_got[1],
ctx->uid_got[2], ctx->uid_got[3]);
return ctx;
}
@ -304,7 +364,6 @@ ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
size_t len;
ngx_str_t src, dst;
ngx_table_elt_t *set_cookie, *p3p;
/*
* TODO: in the threaded mode the sequencers should be in TLS and their
* ranges should be divided between threads
@ -432,51 +491,11 @@ ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
}
static ngx_int_t
ngx_http_userid_add_variables(ngx_conf_t *cf)
{
ngx_http_variable_t *var;
var = ngx_http_add_variable(cf, &ngx_http_userid_got, NGX_HTTP_VAR_NOHASH);
if (var == NULL) {
return NGX_ERROR;
}
var->get_handler = ngx_http_userid_variable;
var->data = offsetof(ngx_http_userid_ctx_t, uid_got);
var = ngx_http_add_variable(cf, &ngx_http_userid_set, NGX_HTTP_VAR_NOHASH);
if (var == NULL) {
return NGX_ERROR;
}
var->get_handler = ngx_http_userid_variable;
var->data = offsetof(ngx_http_userid_ctx_t, uid_set);
return NGX_OK;
}
static ngx_int_t
ngx_http_userid_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
uintptr_t data)
ngx_str_t *name, uint32_t *uid)
{
uint32_t *uid;
ngx_http_userid_ctx_t *ctx;
ngx_http_userid_conf_t *conf;
ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module);
uid = (uint32_t *) ((char *) ctx + data);
if (ctx == NULL || uid[3] == 0) {
v->not_found = 1;
return NGX_OK;
}
conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module);
v->len = conf->name.len + sizeof("=00001111222233334444555566667777") - 1;
v->len = name->len + sizeof("=00001111222233334444555566667777") - 1;
v->data = ngx_palloc(r->pool, v->len);
if (v->data == NULL) {
return NGX_ERROR;
@ -487,7 +506,30 @@ ngx_http_userid_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
v->not_found = 0;
ngx_sprintf(v->data, "%V=%08XD%08XD%08XD%08XD",
&conf->name, uid[0], uid[1], uid[2], uid[3]);
name, uid[0], uid[1], uid[2], uid[3]);
return NGX_OK;
}
static ngx_int_t
ngx_http_userid_add_variables(ngx_conf_t *cf)
{
ngx_http_variable_t *var;
var = ngx_http_add_variable(cf, &ngx_http_userid_got, NGX_HTTP_VAR_NOHASH);
if (var == NULL) {
return NGX_ERROR;
}
var->get_handler = ngx_http_userid_got_variable;
var = ngx_http_add_variable(cf, &ngx_http_userid_set, NGX_HTTP_VAR_NOHASH);
if (var == NULL) {
return NGX_ERROR;
}
var->get_handler = ngx_http_userid_set_variable;
return NGX_OK;
}

View File

@ -47,7 +47,7 @@ our @EXPORT = qw(
HTTP_INSUFFICIENT_STORAGE
);
our $VERSION = '0.6.31';
our $VERSION = '0.6.39';
require XSLoader;
XSLoader::load('nginx', $VERSION);

View File

@ -406,7 +406,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
use_rewrite = cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers.nelts ? 1 : 0;
use_access = cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers.nelts ? 1 : 0;
n = use_rewrite + use_access + 1; /* find config phase */
n = use_rewrite + use_access + cmcf->try_files + 1 /* find config phase */;
for (i = 0; i < NGX_HTTP_LOG_PHASE; i++) {
n += cmcf->phases[i].handlers.nelts;
@ -475,6 +475,15 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
continue;
case NGX_HTTP_TRY_FILES_PHASE:
if (cmcf->try_files) {
ph->checker = ngx_http_core_try_files_phase;
n++;
ph++;
}
continue;
case NGX_HTTP_CONTENT_PHASE:
checker = ngx_http_core_content_phase;
break;
@ -558,6 +567,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
in_addr[a].core_srv_conf = cscfp[s];
in_addr[a].default_server = 1;
in_addr[a].listen_conf = &lscf[l].conf;
}
goto found;
@ -895,8 +905,8 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (in_addr[i].hash.buckets == NULL
&& (in_addr[i].wc_head == NULL
|| in_addr[i].wc_head->hash.buckets == NULL)
&& (in_addr[i].wc_head == NULL
|| in_addr[i].wc_head->hash.buckets == NULL))
&& (in_addr[i].wc_tail == NULL
|| in_addr[i].wc_tail->hash.buckets == NULL))
{
continue;
}

View File

@ -71,6 +71,8 @@ ngx_int_t ngx_http_parse_unsafe_uri(ngx_http_request_t *r, ngx_str_t *uri,
ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b);
ngx_int_t ngx_http_parse_multi_header_lines(ngx_array_t *headers,
ngx_str_t *name, ngx_str_t *value);
void ngx_http_split_args(ngx_http_request_t *r, ngx_str_t *uri,
ngx_str_t *args);
ngx_int_t ngx_http_find_server_conf(ngx_http_request_t *r);
void ngx_http_update_location_config(ngx_http_request_t *r);

View File

@ -62,6 +62,8 @@ static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static char *ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static char *ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
@ -114,6 +116,14 @@ static ngx_conf_enum_t ngx_http_core_satisfy[] = {
};
static ngx_conf_enum_t ngx_http_core_if_modified_since[] = {
{ ngx_string("off"), NGX_HTTP_IMS_OFF },
{ ngx_string("exact"), NGX_HTTP_IMS_EXACT },
{ ngx_string("before"), NGX_HTTP_IMS_BEFORE },
{ ngx_null_string, 0 }
};
#if (NGX_HTTP_GZIP)
static ngx_conf_enum_t ngx_http_gzip_http_version[] = {
@ -416,6 +426,13 @@ static ngx_command_t ngx_http_core_commands[] = {
0,
NULL },
{ ngx_string("keepalive_requests"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_num_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_core_loc_conf_t, keepalive_requests),
NULL },
{ ngx_string("satisfy"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_enum_slot,
@ -507,6 +524,13 @@ static ngx_command_t ngx_http_core_commands[] = {
offsetof(ngx_http_core_loc_conf_t, server_tokens),
NULL },
{ ngx_string("if_modified_since"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_enum_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_core_loc_conf_t, if_modified_since),
&ngx_http_core_if_modified_since },
{ ngx_string("error_page"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|NGX_CONF_2MORE,
@ -515,6 +539,13 @@ static ngx_command_t ngx_http_core_commands[] = {
0,
NULL },
{ ngx_string("try_files"),
NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE,
ngx_http_core_try_files,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL },
{ ngx_string("post_action"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|NGX_CONF_TAKE1,
@ -832,7 +863,6 @@ ngx_http_core_find_config_phase(ngx_http_request_t *r,
return NGX_OK;
}
if (rc == NGX_HTTP_LOCATION_AUTO_REDIRECT) {
r->headers_out.location = ngx_list_push(&r->headers_out.headers);
if (r->headers_out.location == NULL) {
@ -997,6 +1027,185 @@ ngx_http_core_post_access_phase(ngx_http_request_t *r,
}
ngx_int_t
ngx_http_core_try_files_phase(ngx_http_request_t *r,
ngx_http_phase_handler_t *ph)
{
size_t len, root, alias, reserve, allocated;
u_char *p, *name;
ngx_str_t path, args;
ngx_uint_t test_dir;
ngx_http_try_file_t *tf;
ngx_open_file_info_t of;
ngx_http_script_code_pt code;
ngx_http_script_engine_t e;
ngx_http_core_loc_conf_t *clcf;
ngx_http_script_len_code_pt lcode;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"try files phase: %ui", r->phase_handler);
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
if (clcf->try_files == NULL) {
r->phase_handler++;
return NGX_AGAIN;
}
allocated = 0;
root = 0;
name = NULL;
/* suppress MSVC warning */
path.data = NULL;
tf = clcf->try_files;
alias = clcf->alias ? clcf->name.len : 0;
for ( ;; ) {
if (tf->lengths) {
ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
e.ip = tf->lengths->elts;
e.request = r;
/* 1 is for terminating '\0' as in static names */
len = 1;
while (*(uintptr_t *) e.ip) {
lcode = *(ngx_http_script_len_code_pt *) e.ip;
len += lcode(&e);
}
} else {
len = tf->name.len;
}
/* 16 bytes are preallocation */
reserve = ngx_abs((ssize_t) (len - r->uri.len)) + alias + 16;
if (reserve > allocated) {
/* we just need to allocate path and to copy a root */
if (ngx_http_map_uri_to_path(r, &path, &root, reserve) == NULL) {
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
return NGX_OK;
}
name = path.data + root;
allocated = path.len - root - (r->uri.len - alias);
}
if (tf->values == NULL) {
/* tf->name.len includes the terminating '\0' */
ngx_memcpy(name, tf->name.data, tf->name.len);
path.len = (name + tf->name.len - 1) - path.data;
} else {
e.ip = tf->values->elts;
e.pos = name;
e.flushed = 1;
while (*(uintptr_t *) e.ip) {
code = *(ngx_http_script_code_pt *) e.ip;
code((ngx_http_script_engine_t *) &e);
}
path.len = e.pos - path.data;
*e.pos = '\0';
if (alias && ngx_strncmp(name, clcf->name.data, alias) == 0) {
ngx_memcpy(name, name + alias, len - alias);
path.len -= alias;
}
}
test_dir = tf->test_dir;
tf++;
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"try to use file: \"%s\" \"%s\"", name, path.data);
if (tf->lengths == NULL && tf->name.len == 0) {
path.len -= root;
path.data += root;
if (path.data[0] == '@') {
(void) ngx_http_named_location(r, &path);
} else {
ngx_http_split_args(r, &path, &args);
(void) ngx_http_internal_redirect(r, &path, &args);
}
return NGX_OK;
}
ngx_memzero(&of, sizeof(ngx_open_file_info_t));
of.valid = clcf->open_file_cache_valid;
of.min_uses = clcf->open_file_cache_min_uses;
of.errors = clcf->open_file_cache_errors;
of.events = clcf->open_file_cache_events;
if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
!= NGX_OK)
{
if (of.err != NGX_ENOENT && of.err != NGX_ENOTDIR) {
ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
ngx_open_file_n " \"%s\" failed", path.data);
}
continue;
}
if (of.is_dir && !test_dir) {
continue;
}
path.len -= root;
path.data += root;
if (!alias) {
r->uri = path;
} else {
r->uri.len = alias + path.len;
r->uri.data = ngx_palloc(r->pool, r->uri.len);
if (r->uri.data == NULL) {
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
return NGX_OK;
}
p = ngx_copy(r->uri.data, clcf->name.data, alias);
ngx_memcpy(p, name, path.len);
}
if (ngx_http_set_exten(r) != NGX_OK) {
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
return NGX_OK;
}
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"try file uri: \"%V\"", &r->uri);
r->phase_handler++;
return NGX_AGAIN;
}
/* not reached */
}
ngx_int_t
ngx_http_core_content_phase(ngx_http_request_t *r,
ngx_http_phase_handler_t *ph)
@ -1092,8 +1301,13 @@ ngx_http_update_location_config(ngx_http_request_t *r)
r->request_body_file_log_level = NGX_LOG_WARN;
}
if (r->keepalive && clcf->keepalive_timeout == 0) {
r->keepalive = 0;
if (r->keepalive) {
if (clcf->keepalive_timeout == 0) {
r->keepalive = 0;
} else if (r->connection->requests >= clcf->keepalive_requests) {
r->keepalive = 0;
}
}
if (!clcf->tcp_nopush) {
@ -1355,16 +1569,24 @@ ngx_http_send_header(ngx_http_request_t *r)
ngx_int_t
ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
ngx_int_t rc;
ngx_int_t rc;
ngx_connection_t *c;
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
c = r->connection;
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http output filter \"%V?%V\"", &r->uri, &r->args);
rc = ngx_http_top_body_filter(r, in);
if (rc == NGX_ERROR) {
if (c->destroyed) {
return NGX_DONE;
}
/* NGX_ERROR may be returned by any filter */
r->connection->error = 1;
c->error = 1;
}
return rc;
@ -1813,6 +2035,7 @@ ngx_http_subrequest(ngx_http_request_t *r,
sr->fast_subrequest = 1;
sr->discard_body = r->discard_body;
sr->expect_tested = 1;
sr->main_filter_need_in_memory = r->main_filter_need_in_memory;
sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1;
@ -2606,20 +2829,7 @@ ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
}
if (conf->server_name.data == NULL) {
conf->server_name.data = ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN);
if (conf->server_name.data == NULL) {
return NGX_CONF_ERROR;
}
if (gethostname((char *) conf->server_name.data, NGX_MAXHOSTNAMELEN)
== -1)
{
ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
"gethostname() failed");
return NGX_CONF_ERROR;
}
conf->server_name.len = ngx_strlen(conf->server_name.data);
conf->server_name = cf->cycle->hostname;
sn = ngx_array_push(&conf->server_names);
if (sn == NULL) {
@ -2685,6 +2895,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
* lcf->default_type = { 0, NULL };
* lcf->err_log = NULL;
* lcf->error_pages = NULL;
* lcf->try_files = NULL;
* lcf->client_body_path = NULL;
* lcf->regex = NULL;
* lcf->exact_match = 0;
@ -2697,6 +2908,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
lcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
lcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
lcf->satisfy = NGX_CONF_UNSET_UINT;
lcf->if_modified_since = NGX_CONF_UNSET_UINT;
lcf->internal = NGX_CONF_UNSET;
lcf->client_body_in_file_only = NGX_CONF_UNSET;
lcf->sendfile = NGX_CONF_UNSET;
@ -2709,6 +2921,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
lcf->limit_rate = NGX_CONF_UNSET_SIZE;
lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
lcf->keepalive_header = NGX_CONF_UNSET;
lcf->keepalive_requests = NGX_CONF_UNSET_UINT;
lcf->lingering_time = NGX_CONF_UNSET_MSEC;
lcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
lcf->resolver_timeout = NGX_CONF_UNSET_MSEC;
@ -2883,6 +3096,8 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_uint_value(conf->satisfy, prev->satisfy,
NGX_HTTP_SATISFY_ALL);
ngx_conf_merge_uint_value(conf->if_modified_since, prev->if_modified_since,
NGX_HTTP_IMS_EXACT);
ngx_conf_merge_value(conf->internal, prev->internal, 0);
ngx_conf_merge_value(conf->client_body_in_file_only,
prev->client_body_in_file_only, 0);
@ -2901,6 +3116,8 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
prev->keepalive_timeout, 75000);
ngx_conf_merge_sec_value(conf->keepalive_header,
prev->keepalive_header, 0);
ngx_conf_merge_uint_value(conf->keepalive_requests,
prev->keepalive_requests, 100);
ngx_conf_merge_msec_value(conf->lingering_time,
prev->lingering_time, 30000);
ngx_conf_merge_msec_value(conf->lingering_timeout,
@ -2922,7 +3139,7 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
return NGX_CONF_ERROR;
}
}
conf->resolver = prev->resolver;
}
@ -3216,8 +3433,7 @@ ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
value[i].len--;
value[i].data++;
sn->regex = ngx_regex_compile(&value[i], NGX_REGEX_CASELESS, cf->pool,
&err);
sn->regex = ngx_regex_compile(&value[i], 0, cf->pool, &err);
if (sn->regex == NULL) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
@ -3601,6 +3817,71 @@ ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
static char *
ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_core_loc_conf_t *clcf = conf;
ngx_str_t *value;
ngx_uint_t i, n;
ngx_http_try_file_t *tf;
ngx_http_script_compile_t sc;
ngx_http_core_main_conf_t *cmcf;
if (clcf->try_files) {
return "is duplicate";
}
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
cmcf->try_files = 1;
tf = ngx_pcalloc(cf->pool, cf->args->nelts * sizeof(ngx_http_try_file_t));
if (tf == NULL) {
return NGX_CONF_ERROR;
}
clcf->try_files = tf;
value = cf->args->elts;
for (i = 0; i < cf->args->nelts - 1; i++) {
tf[i].name = value[i + 1];
if (tf[i].name.data[tf[i].name.len - 1] == '/') {
tf[i].test_dir = 1;
tf[i].name.len--;
tf[i].name.data[tf[i].name.len] = '\0';
}
n = ngx_http_script_variables_count(&tf[i].name);
if (n) {
ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
sc.cf = cf;
sc.source = &tf[i].name;
sc.lengths = &tf[i].lengths;
sc.values = &tf[i].values;
sc.variables = n;
sc.complete_lengths = 1;
sc.complete_values = 1;
if (ngx_http_script_compile(&sc) != NGX_OK) {
return NGX_CONF_ERROR;
}
} else {
/* add trailing '\0' to length */
tf[i].name.len++;
}
}
return NGX_CONF_OK;
}
static char *
ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{

View File

@ -28,6 +28,11 @@
#define NGX_HTTP_SATISFY_ANY 1
#define NGX_HTTP_IMS_OFF 0
#define NGX_HTTP_IMS_EXACT 1
#define NGX_HTTP_IMS_BEFORE 2
typedef struct {
unsigned default_server:1;
unsigned bind:1;
@ -74,6 +79,7 @@ typedef enum {
NGX_HTTP_ACCESS_PHASE,
NGX_HTTP_POST_ACCESS_PHASE,
NGX_HTTP_TRY_FILES_PHASE,
NGX_HTTP_CONTENT_PHASE,
NGX_HTTP_LOG_PHASE
@ -122,6 +128,8 @@ typedef struct {
ngx_hash_keys_arrays_t *variables_keys;
ngx_uint_t try_files; /* unsigned try_files:1 */
ngx_http_phase_t phases[NGX_HTTP_LOG_PHASE + 1];
} ngx_http_core_main_conf_t;
@ -231,6 +239,14 @@ typedef struct {
} ngx_http_err_page_t;
typedef struct {
ngx_array_t *lengths;
ngx_array_t *values;
ngx_str_t name;
ngx_uint_t test_dir; /* unsigned test_dir:1; */
} ngx_http_try_file_t;
typedef struct ngx_http_core_loc_conf_s ngx_http_core_loc_conf_t;
struct ngx_http_core_loc_conf_s {
@ -255,10 +271,10 @@ struct ngx_http_core_loc_conf_s {
ngx_array_t *locations;
/* pointer to the modules' loc_conf */
void **loc_conf ;
void **loc_conf;
uint32_t limit_except;
void **limit_except_loc_conf ;
void **limit_except_loc_conf;
ngx_http_handler_pt handler;
@ -291,7 +307,9 @@ struct ngx_http_core_loc_conf_s {
time_t keepalive_header; /* keepalive_timeout */
ngx_uint_t keepalive_requests; /* keepalive_requests */
ngx_uint_t satisfy; /* satisfy */
ngx_uint_t if_modified_since; /* if_modified_since */
ngx_flag_t internal; /* internal */
ngx_flag_t client_body_in_file_only; /* client_body_in_file_only */
@ -319,6 +337,7 @@ struct ngx_http_core_loc_conf_s {
#endif
ngx_array_t *error_pages; /* error_page */
ngx_http_try_file_t *try_files; /* try_files */
ngx_path_t *client_body_temp_path; /* client_body_temp_path */
@ -350,6 +369,8 @@ ngx_int_t ngx_http_core_access_phase(ngx_http_request_t *r,
ngx_http_phase_handler_t *ph);
ngx_int_t ngx_http_core_post_access_phase(ngx_http_request_t *r,
ngx_http_phase_handler_t *ph);
ngx_int_t ngx_http_core_try_files_phase(ngx_http_request_t *r,
ngx_http_phase_handler_t *ph);
ngx_int_t ngx_http_core_content_phase(ngx_http_request_t *r,
ngx_http_phase_handler_t *ph);
@ -401,7 +422,7 @@ extern ngx_uint_t ngx_http_max_module;
\
r->allow_ranges = 0; \
if (r->headers_out.accept_ranges) { \
r->headers_out.accept_ranges->hash = 0 ; \
r->headers_out.accept_ranges->hash = 0; \
r->headers_out.accept_ranges = NULL; \
}

View File

@ -286,9 +286,8 @@ ngx_http_header_filter(ngx_http_request_t *r)
cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
host = cscf->server_name;
} else if (r->headers_in.host) {
host.len = r->headers_in.host_name_len;
host.data = r->headers_in.host->value.data;
} else if (r->headers_in.server.len) {
host = r->headers_in.server;
} else {
host.data = addr;
@ -348,6 +347,12 @@ ngx_http_header_filter(ngx_http_request_t *r)
len += sizeof("Connection: closed" CRLF) - 1;
}
#if (NGX_HTTP_GZIP)
if (r->gzip && clcf->gzip_vary) {
len += sizeof("Vary: Accept-Encoding" CRLF) - 1;
}
#endif
part = &r->headers_out.headers.part;
header = part->elts;
@ -517,6 +522,13 @@ ngx_http_header_filter(ngx_http_request_t *r)
sizeof("Connection: close" CRLF) - 1);
}
#if (NGX_HTTP_GZIP)
if (r->gzip && clcf->gzip_vary) {
b->last = ngx_cpymem(b->last, "Vary: Accept-Encoding" CRLF,
sizeof("Vary: Accept-Encoding" CRLF) - 1);
}
#endif
part = &r->headers_out.headers.part;
header = part->elts;
@ -537,7 +549,7 @@ ngx_http_header_filter(ngx_http_request_t *r)
}
b->last = ngx_copy(b->last, header[i].key.data, header[i].key.len);
*b->last++ = ':' ; *b->last++ = ' ' ;
*b->last++ = ':'; *b->last++ = ' ';
b->last = ngx_copy(b->last, header[i].value.data, header[i].value.len);
*b->last++ = CR; *b->last++ = LF;

View File

@ -738,6 +738,7 @@ ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b)
/* first char */
case sw_start:
r->header_name_start = p;
r->invalid_header = 0;
switch (ch) {
@ -750,7 +751,6 @@ ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b)
goto header_done;
default:
state = sw_name;
r->header_name_start = p;
c = lowcase[ch];
@ -1123,11 +1123,15 @@ ngx_http_parse_complex_uri(ngx_http_request_t *r, ngx_uint_t merge_slashes)
#endif
case '/':
state = sw_slash;
u -= 4;
if (u < r->uri.data) {
return NGX_HTTP_PARSE_INVALID_REQUEST;
}
while (*(u - 1) != '/') {
u -= 5;
for ( ;; ) {
if (u < r->uri.data) {
return NGX_HTTP_PARSE_INVALID_REQUEST;
}
if (*u == '/') {
u++;
break;
}
u--;
}
break;
@ -1467,3 +1471,39 @@ ngx_http_parse_multi_header_lines(ngx_array_t *headers, ngx_str_t *name,
return NGX_DECLINED;
}
void
ngx_http_split_args(ngx_http_request_t *r, ngx_str_t *uri, ngx_str_t *args)
{
u_char ch, *p, *last;
p = uri->data;
last = p + uri->len;
args->len = 0;
while (p < last) {
ch = *p++;
if (ch == '?') {
args->len = last - p;
args->data = p;
uri->len = p - 1 - uri->data;
if (ngx_strlchr(p, last, '\0') != NULL) {
r->zero_in_uri = 1;
}
return;
}
if (ch == '\0') {
r->zero_in_uri = 1;
continue;
}
}
}

View File

@ -168,7 +168,7 @@ ngx_http_postpone_filter_output_postponed_request(ngx_http_request_t *r)
pr = r->postponed;
if (pr == NULL) {
return NGX_OK;
break;
}
if (pr->request) {
@ -196,7 +196,7 @@ ngx_http_postpone_filter_output_postponed_request(ngx_http_request_t *r)
}
if (pr == NULL) {
return NGX_OK;
break;
}
out = pr->out;
@ -215,6 +215,17 @@ ngx_http_postpone_filter_output_postponed_request(ngx_http_request_t *r)
r->postponed = r->postponed->next;
}
if (r != r->main && r->out) {
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http postpone filter out again \"%V?%V\"",
&r->uri, &r->args);
r->connection->data = r;
return NGX_AGAIN;
}
return NGX_OK;
}

View File

@ -21,15 +21,20 @@ static ngx_int_t ngx_http_process_header_line(ngx_http_request_t *r,
ngx_table_elt_t *h, ngx_uint_t offset);
static ngx_int_t ngx_http_process_unique_header_line(ngx_http_request_t *r,
ngx_table_elt_t *h, ngx_uint_t offset);
static ngx_int_t ngx_http_process_host(ngx_http_request_t *r,
ngx_table_elt_t *h, ngx_uint_t offset);
static ngx_int_t ngx_http_process_connection(ngx_http_request_t *r,
ngx_table_elt_t *h, ngx_uint_t offset);
static ngx_int_t ngx_http_process_user_agent(ngx_http_request_t *r,
ngx_table_elt_t *h, ngx_uint_t offset);
static ngx_int_t ngx_http_process_cookie(ngx_http_request_t *r,
ngx_table_elt_t *h, ngx_uint_t offset);
static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r);
static void ngx_http_process_request(ngx_http_request_t *r);
static void ngx_http_find_virtual_server(ngx_http_request_t *r, u_char *host,
size_t len, ngx_uint_t hash);
static ssize_t ngx_http_validate_host(u_char *host, size_t len);
static ngx_int_t ngx_http_find_virtual_server(ngx_http_request_t *r,
u_char *host, size_t len);
static void ngx_http_request_handler(ngx_event_t *ev);
static ngx_int_t ngx_http_set_write_handler(ngx_http_request_t *r);
@ -70,7 +75,7 @@ static char *ngx_http_client_errors[] = {
ngx_http_header_t ngx_http_headers_in[] = {
{ ngx_string("Host"), offsetof(ngx_http_headers_in_t, host),
ngx_http_process_unique_header_line },
ngx_http_process_host },
{ ngx_string("Connection"), offsetof(ngx_http_headers_in_t, connection),
ngx_http_process_connection },
@ -80,7 +85,7 @@ ngx_http_header_t ngx_http_headers_in[] = {
ngx_http_process_unique_header_line },
{ ngx_string("User-Agent"), offsetof(ngx_http_headers_in_t, user_agent),
ngx_http_process_header_line },
ngx_http_process_user_agent },
{ ngx_string("Referer"), offsetof(ngx_http_headers_in_t, referer),
ngx_http_process_header_line },
@ -104,6 +109,10 @@ ngx_http_header_t ngx_http_headers_in[] = {
offsetof(ngx_http_headers_in_t, transfer_encoding),
ngx_http_process_header_line },
{ ngx_string("Expect"),
offsetof(ngx_http_headers_in_t, expect),
ngx_http_process_unique_header_line },
#if (NGX_HTTP_GZIP)
{ ngx_string("Accept-Encoding"),
offsetof(ngx_http_headers_in_t, accept_encoding),
@ -244,6 +253,8 @@ ngx_http_init_request(ngx_event_t *rev)
return;
}
c->requests++;
hc = c->data;
if (hc == NULL) {
@ -562,8 +573,6 @@ ngx_http_ssl_handshake_handler(ngx_connection_t *c)
int
ngx_http_ssl_servername(ngx_ssl_conn_t *ssl_conn, int *ad, void *arg)
{
u_char *p;
ngx_uint_t hash;
const char *servername;
ngx_connection_t *c;
ngx_http_request_t *r;
@ -582,21 +591,13 @@ ngx_http_ssl_servername(ngx_ssl_conn_t *ssl_conn, int *ad, void *arg)
r = c->data;
if (r->virtual_names == NULL) {
if (ngx_http_find_virtual_server(r, (u_char *) servername,
ngx_strlen(servername))
!= NGX_OK)
{
return SSL_TLSEXT_ERR_NOACK;
}
/* it seems browsers send low case server name */
hash = 0;
for (p = (u_char *) servername; *p; p++) {
hash = ngx_hash(hash, *p);
}
ngx_http_find_virtual_server(r, (u_char *) servername,
p - (u_char *) servername, hash);
sscf = ngx_http_get_module_srv_conf(r, ngx_http_ssl_module);
SSL_set_SSL_CTX(ssl_conn, sscf->ssl.ctx);
@ -651,6 +652,7 @@ ngx_http_process_request_line(ngx_event_t *rev)
r->request_line.len = r->request_end - r->request_start;
r->request_line.data = r->request_start;
*r->request_end = '\0';
if (r->args_start) {
@ -726,7 +728,31 @@ ngx_http_process_request_line(ngx_event_t *rev)
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http exten: \"%V\"", &r->exten);
if (r->host_start && r->host_end) {
n = ngx_http_validate_host(r->host_start,
r->host_end - r->host_start);
if (n <= 0) {
ngx_log_error(NGX_LOG_INFO, c->log, 0,
"client sent invalid host in request line");
ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
return;
}
r->headers_in.server.len = n;
r->headers_in.server.data = r->host_start;
}
if (r->http_version < NGX_HTTP_VERSION_10) {
if (ngx_http_find_virtual_server(r, r->headers_in.server.data,
r->headers_in.server.len)
== NGX_ERROR)
{
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
ngx_http_process_request(r);
return;
}
@ -1216,6 +1242,36 @@ ngx_http_process_unique_header_line(ngx_http_request_t *r, ngx_table_elt_t *h,
}
static ngx_int_t
ngx_http_process_host(ngx_http_request_t *r, ngx_table_elt_t *h,
ngx_uint_t offset)
{
ssize_t len;
if (r->headers_in.host == NULL) {
r->headers_in.host = h;
}
len = ngx_http_validate_host(h->value.data, h->value.len);
if (len <= 0) {
ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
"client sent invalid host header");
ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
return NGX_ERROR;
}
if (r->headers_in.server.len) {
return NGX_OK;
}
r->headers_in.server.len = len;
r->headers_in.server.data = h->value.data;
return NGX_OK;
}
static ngx_int_t
ngx_http_process_connection(ngx_http_request_t *r, ngx_table_elt_t *h,
ngx_uint_t offset)
@ -1231,6 +1287,60 @@ ngx_http_process_connection(ngx_http_request_t *r, ngx_table_elt_t *h,
}
static ngx_int_t
ngx_http_process_user_agent(ngx_http_request_t *r, ngx_table_elt_t *h,
ngx_uint_t offset)
{
u_char *ua, *user_agent;
if (r->headers_in.user_agent) {
return NGX_OK;
}
r->headers_in.user_agent = h;
/* check some widespread browsers while the header is in CPU cache */
user_agent = h->value.data;
ua = ngx_strstrn(user_agent, "MSIE", 4 - 1);
if (ua && ua + 8 < user_agent + h->value.len) {
r->headers_in.msie = 1;
if (ua[4] == ' ' && ua[5] == '4' && ua[6] == '.') {
r->headers_in.msie4 = 1;
}
#if 0
/* MSIE ignores the SSL "close notify" alert */
if (c->ssl) {
c->ssl->no_send_shutdown = 1;
}
#endif
}
if (ngx_strstrn(user_agent, "Opera", 5 - 1)) {
r->headers_in.opera = 1;
r->headers_in.msie = 0;
r->headers_in.msie4 = 0;
}
if (!r->headers_in.msie && !r->headers_in.opera) {
if (ngx_strstrn(user_agent, "Gecko/", 6 - 1)) {
r->headers_in.gecko = 1;
} else if (ngx_strstrn(user_agent, "Konqueror", 9 - 1)) {
r->headers_in.konqueror = 1;
}
}
return NGX_OK;
}
static ngx_int_t
ngx_http_process_cookie(ngx_http_request_t *r, ngx_table_elt_t *h,
ngx_uint_t offset)
@ -1252,57 +1362,19 @@ ngx_http_process_cookie(ngx_http_request_t *r, ngx_table_elt_t *h,
static ngx_int_t
ngx_http_process_request_header(ngx_http_request_t *r)
{
size_t len;
u_char *host, *ua, *user_agent, ch;
ngx_uint_t hash;
if (ngx_http_find_virtual_server(r, r->headers_in.server.data,
r->headers_in.server.len)
== NGX_ERROR)
{
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
return NGX_ERROR;
}
if (r->headers_in.host) {
hash = 0;
for (len = 0; len < r->headers_in.host->value.len; len++) {
ch = r->headers_in.host->value.data[len];
if (ch == ':') {
break;
}
ch = ngx_tolower(ch);
r->headers_in.host->value.data[len] = ch;
hash = ngx_hash(hash, ch);
}
if (len && r->headers_in.host->value.data[len - 1] == '.') {
len--;
hash = ngx_hash_key(r->headers_in.host->value.data, len);
}
r->headers_in.host_name_len = len;
if (r->virtual_names) {
host = r->host_start;
if (host == NULL) {
host = r->headers_in.host->value.data;
len = r->headers_in.host_name_len;
} else {
len = r->host_end - host;
}
ngx_http_find_virtual_server(r, host, len, hash);
}
} else {
if (r->http_version > NGX_HTTP_VERSION_10) {
ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
"client sent HTTP/1.1 request without \"Host\" header");
ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
return NGX_ERROR;
}
r->headers_in.host_name_len = 0;
if (r->headers_in.host == NULL && r->http_version > NGX_HTTP_VERSION_10) {
ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
"client sent HTTP/1.1 request without \"Host\" header");
ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
return NGX_ERROR;
}
if (r->headers_in.content_length) {
@ -1318,9 +1390,7 @@ ngx_http_process_request_header(ngx_http_request_t *r)
}
}
if (r->method & (NGX_HTTP_POST|NGX_HTTP_PUT)
&& r->headers_in.content_length_n == -1)
{
if (r->method & NGX_HTTP_PUT && r->headers_in.content_length_n == -1) {
ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
"client sent %V method without \"Content-Length\" header",
&r->method_name);
@ -1353,50 +1423,6 @@ ngx_http_process_request_header(ngx_http_request_t *r)
}
}
if (r->headers_in.user_agent) {
/*
* check some widespread browsers while the headers are still
* in CPU cache
*/
user_agent = r->headers_in.user_agent->value.data;
ua = ngx_strstrn(user_agent, "MSIE", 4 - 1);
if (ua && ua + 8 < user_agent + r->headers_in.user_agent->value.len) {
r->headers_in.msie = 1;
if (ua[4] == ' ' && ua[5] == '4' && ua[6] == '.') {
r->headers_in.msie4 = 1;
}
#if 0
/* MSIE ignores the SSL "close notify" alert */
if (c->ssl) {
c->ssl->no_send_shutdown = 1;
}
#endif
}
if (ngx_strstrn(user_agent, "Opera", 5 - 1)) {
r->headers_in.opera = 1;
r->headers_in.msie = 0;
r->headers_in.msie4 = 0;
}
if (!r->headers_in.msie && !r->headers_in.opera) {
if (ngx_strstrn(user_agent, "Gecko/", 6 - 1)) {
r->headers_in.gecko = 1;
} else if (ngx_strstrn(user_agent, "Konqueror", 9 - 1)) {
r->headers_in.konqueror = 1;
}
}
}
return NGX_OK;
}
@ -1479,14 +1505,89 @@ ngx_http_process_request(ngx_http_request_t *r)
}
static void
ngx_http_find_virtual_server(ngx_http_request_t *r, u_char *host, size_t len,
ngx_uint_t hash)
static ssize_t
ngx_http_validate_host(u_char *host, size_t len)
{
u_char ch;
size_t i, last;
ngx_uint_t dot;
last = len;
dot = 0;
for (i = 0; i < len; i++) {
ch = host[i];
if (ch == '.') {
if (dot) {
return -1;
}
dot = 1;
continue;
}
dot = 0;
if (ch == ':') {
last = i;
continue;
}
if (ch == '/' || ch == '\0') {
return -1;
}
#if (NGX_WIN32)
if (ch == '\\') {
return -1;
}
#endif
}
if (dot) {
last--;
}
return last;
}
static ngx_int_t
ngx_http_find_virtual_server(ngx_http_request_t *r, u_char *host, size_t len)
{
u_char *server, ch;
ngx_uint_t i, hash;
ngx_http_core_loc_conf_t *clcf;
ngx_http_core_srv_conf_t *cscf;
u_char buf[32];
cscf = ngx_hash_find_combined(&r->virtual_names->names, hash, host, len);
if (len == 0 || r->virtual_names == NULL) {
return NGX_DECLINED;
}
if (len <= 32) {
server = buf;
} else {
server = ngx_palloc(r->pool, len);
if (server == NULL) {
return NGX_ERROR;
}
}
hash = 0;
for (i = 0; i < len; i++) {
ch = host[i];
ch = ngx_tolower(ch);
server[i] = ch;
hash = ngx_hash(hash, ch);
}
cscf = ngx_hash_find_combined(&r->virtual_names->names, hash, server, len);
if (cscf) {
goto found;
@ -1501,7 +1602,7 @@ ngx_http_find_virtual_server(ngx_http_request_t *r, u_char *host, size_t len,
ngx_http_server_name_t *sn;
name.len = len;
name.data = host;
name.data = server;
sn = r->virtual_names->regex;
@ -1518,7 +1619,7 @@ ngx_http_find_virtual_server(ngx_http_request_t *r, u_char *host, size_t len,
ngx_regex_exec_n
" failed: %d on \"%V\" using \"%V\"",
n, &name, &sn[i].name);
return;
return NGX_ERROR;
}
/* match */
@ -1531,7 +1632,7 @@ ngx_http_find_virtual_server(ngx_http_request_t *r, u_char *host, size_t len,
#endif
return;
return NGX_OK;
found:
@ -1545,7 +1646,7 @@ found:
r->connection->log->log_level = clcf->err_log->log_level;
}
return;
return NGX_OK;
}
@ -1991,6 +2092,7 @@ ngx_http_set_keepalive(ngx_http_request_t *r)
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "set http keepalive handler");
if (r->discard_body) {
r->write_event_handler = ngx_http_request_empty_handler;
r->lingering_time = ngx_time() + (time_t) (clcf->lingering_time / 1000);
ngx_add_timer(rev, clcf->lingering_timeout);
return;
@ -2064,7 +2166,8 @@ ngx_http_set_keepalive(ngx_http_request_t *r)
hc->pipeline = 1;
c->log->action = "reading client pipelined request line";
ngx_http_init_request(rev);
rev->handler = ngx_http_init_request;
ngx_post_event(rev, &ngx_posted_events);
return;
}
@ -2163,8 +2266,15 @@ ngx_http_set_keepalive(ngx_http_request_t *r)
(const void *) &tcp_nodelay, sizeof(int))
== -1)
{
#if (NGX_SOLARIS)
/* Solaris returns EINVAL if a socket has been shut down */
c->log_error = NGX_ERROR_IGNORE_EINVAL;
#endif
ngx_connection_error(c, ngx_socket_errno,
"setsockopt(TCP_NODELAY) failed");
c->log_error = NGX_ERROR_INFO;
ngx_http_close_connection(c);
return;
}
@ -2180,7 +2290,7 @@ ngx_http_set_keepalive(ngx_http_request_t *r)
c->idle = 1;
if (rev->ready) {
ngx_http_keepalive_handler(rev);
ngx_post_event(rev, &ngx_posted_events);
}
}

View File

@ -171,6 +171,7 @@ typedef struct {
ngx_table_elt_t *if_range;
ngx_table_elt_t *transfer_encoding;
ngx_table_elt_t *expect;
#if (NGX_HTTP_GZIP)
ngx_table_elt_t *accept_encoding;
@ -206,7 +207,7 @@ typedef struct {
ngx_array_t cookies;
size_t host_name_len;
ngx_str_t server;
off_t content_length_n;
time_t keep_alive_n;
@ -467,6 +468,7 @@ struct ngx_http_request_s {
unsigned request_complete:1;
unsigned request_output:1;
unsigned header_sent:1;
unsigned expect_tested:1;
unsigned done:1;
unsigned utf8:1;

View File

@ -16,6 +16,7 @@ static ngx_int_t ngx_http_write_request_body(ngx_http_request_t *r,
ngx_chain_t *body);
static void ngx_http_read_discarded_request_body_handler(ngx_http_request_t *r);
static ngx_int_t ngx_http_read_discarded_request_body(ngx_http_request_t *r);
static ngx_int_t ngx_http_test_expect(ngx_http_request_t *r);
/*
@ -42,6 +43,10 @@ ngx_http_read_client_request_body(ngx_http_request_t *r,
return NGX_OK;
}
if (ngx_http_test_expect(r) != NGX_OK) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t));
if (rb == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
@ -434,6 +439,10 @@ ngx_http_discard_request_body(ngx_http_request_t *r)
return NGX_OK;
}
if (ngx_http_test_expect(r) != NGX_OK) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
rev = r->connection->read;
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http set discard body");
@ -582,3 +591,45 @@ ngx_http_read_discarded_request_body(ngx_http_request_t *r)
return NGX_AGAIN;
}
static ngx_int_t
ngx_http_test_expect(ngx_http_request_t *r)
{
ngx_int_t n;
ngx_str_t *expect;
if (r->expect_tested
|| r->headers_in.expect == NULL
|| r->http_version < NGX_HTTP_VERSION_11)
{
return NGX_OK;
}
r->expect_tested = 1;
expect = &r->headers_in.expect->value;
if (expect->len != sizeof("100-continue") - 1
|| ngx_strncasecmp(expect->data, (u_char *) "100-continue",
sizeof("100-continue") - 1)
!= 0)
{
return NGX_OK;
}
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"send 100 Continue");
n = r->connection->send(r->connection,
(u_char *) "HTTP/1.1 100 Continue" CRLF CRLF,
sizeof("HTTP/1.1 100 Continue" CRLF CRLF) - 1);
if (n == sizeof("HTTP/1.1 100 Continue" CRLF CRLF) - 1) {
return NGX_OK;
}
/* we assume that such small packet should be send successfully */
return NGX_ERROR;
}

View File

@ -244,10 +244,21 @@ ngx_http_script_compile(ngx_http_script_compile_t *sc)
name.data = &sc->source->data[i];
while (i < sc->source->len
&& sc->source->data[i] != '$'
&& !(sc->source->data[i] == '?' && sc->compile_args))
{
while (i < sc->source->len) {
if (sc->source->data[i] == '$') {
break;
}
if (sc->source->data[i] == '?') {
sc->args = 1;
if (sc->compile_args) {
break;
}
}
i++;
name.len++;
}

View File

@ -327,7 +327,6 @@ static ngx_str_t ngx_http_get_name = { 3, (u_char *) "GET " };
ngx_int_t
ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
{
ngx_int_t rc;
ngx_uint_t i, err;
ngx_http_err_page_t *err_page;
ngx_http_core_loc_conf_t *clcf;
@ -335,12 +334,6 @@ ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http special response: %d, \"%V\"", error, &r->uri);
rc = ngx_http_discard_request_body(r);
if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) {
error = NGX_HTTP_INTERNAL_SERVER_ERROR;
}
r->err_status = error;
if (r->keepalive != 0) {
@ -370,7 +363,7 @@ ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
if (!r->error_page && clcf->error_pages) {
if (!r->error_page && clcf->error_pages && r->uri_changes != 0) {
if (clcf->recursive_error_pages == 0) {
r->error_page = 1;
@ -385,6 +378,12 @@ ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
}
}
r->expect_tested = 1;
if (ngx_http_discard_request_body(r) != NGX_OK) {
error = NGX_HTTP_INTERNAL_SERVER_ERROR;
}
if (clcf->msie_refresh
&& r->headers_in.msie
&& (error == NGX_HTTP_MOVED_PERMANENTLY
@ -433,11 +432,18 @@ static ngx_int_t
ngx_http_send_error_page(ngx_http_request_t *r, ngx_http_err_page_t *err_page)
{
u_char ch, *p, *last;
ngx_int_t overwrite;
ngx_str_t *uri, *args, u, a;
ngx_table_elt_t *location;
ngx_http_core_loc_conf_t *clcf;
r->err_status = err_page->overwrite;
overwrite = err_page->overwrite;
if (overwrite && overwrite != NGX_HTTP_OK) {
r->expect_tested = 1;
}
r->err_status = overwrite;
r->zero_in_uri = 0;
@ -492,8 +498,10 @@ ngx_http_send_error_page(ngx_http_request_t *r, ngx_http_err_page_t *err_page)
if (uri->data[0] == '/') {
r->method = NGX_HTTP_GET;
r->method_name = ngx_http_get_name;
if (r->method != NGX_HTTP_HEAD) {
r->method = NGX_HTTP_GET;
r->method_name = ngx_http_get_name;
}
return ngx_http_internal_redirect(r, uri, args);
}
@ -619,7 +627,7 @@ ngx_http_send_special_response(ngx_http_request_t *r,
b->last = tail + len;
out[1].buf = b;
out[1].next = NULL;;
out[1].next = NULL;
if (msie_padding) {
b = ngx_calloc_buf(r->pool);
@ -633,7 +641,7 @@ ngx_http_send_special_response(ngx_http_request_t *r,
out[1].next = &out[2];
out[2].buf = b;
out[2].next = NULL;;
out[2].next = NULL;
}
if (r == r->main) {

View File

@ -137,7 +137,8 @@ ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = {
ngx_http_upstream_copy_header_line, 0, 0 },
{ ngx_string("Location"),
ngx_http_upstream_ignore_header_line, 0,
ngx_http_upstream_process_header_line,
offsetof(ngx_http_upstream_headers_in_t, location),
ngx_http_upstream_rewrite_location, 0, 0 },
{ ngx_string("Refresh"),
@ -1098,62 +1099,59 @@ ngx_http_upstream_process_header(ngx_event_t *rev)
#endif
}
n = c->recv(c, u->buffer.last, u->buffer.end - u->buffer.last);
for ( ;; ) {
if (n == NGX_AGAIN) {
n = c->recv(c, u->buffer.last, u->buffer.end - u->buffer.last);
if (n == NGX_AGAIN) {
#if 0
ngx_add_timer(rev, u->read_timeout);
ngx_add_timer(rev, u->read_timeout);
#endif
if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
ngx_http_upstream_finalize_request(r, u,
if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
ngx_http_upstream_finalize_request(r, u,
NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
return;
}
return;
}
if (n == 0) {
ngx_log_error(NGX_LOG_ERR, rev->log, 0,
"upstream prematurely closed connection");
}
if (n == NGX_ERROR || n == 0) {
ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
return;
}
u->buffer.last += n;
#if 0
u->valid_header_in = 0;
u->peer.cached = 0;
#endif
rc = u->process_header(r);
if (rc == NGX_AGAIN) {
#if 0
ngx_add_timer(rev, u->read_timeout);
#endif
if (u->buffer.pos == u->buffer.end) {
if (n == 0) {
ngx_log_error(NGX_LOG_ERR, rev->log, 0,
"upstream sent too big header");
"upstream prematurely closed connection");
}
ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_INVALID_HEADER);
if (n == NGX_ERROR || n == 0) {
ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
return;
}
if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
ngx_http_upstream_finalize_request(r, u,
NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
u->buffer.last += n;
#if 0
u->valid_header_in = 0;
u->peer.cached = 0;
#endif
rc = u->process_header(r);
if (rc == NGX_AGAIN) {
if (u->buffer.pos == u->buffer.end) {
ngx_log_error(NGX_LOG_ERR, rev->log, 0,
"upstream sent too big header");
ngx_http_upstream_next(r, u,
NGX_HTTP_UPSTREAM_FT_INVALID_HEADER);
return;
}
continue;
}
return;
break;
}
if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
@ -1961,6 +1959,7 @@ ngx_http_upstream_process_downstream(ngx_http_request_t *r)
static void
ngx_http_upstream_process_body(ngx_event_t *ev)
{
ngx_uint_t del;
ngx_temp_file_t *tf;
ngx_event_pipe_t *p;
ngx_connection_t *c, *downstream;
@ -2056,20 +2055,25 @@ ngx_http_upstream_process_body(ngx_event_t *ev)
if (u->store) {
del = p->upstream_error;
tf = u->pipe->temp_file;
if (p->upstream_eof
&& u->headers_in.status_n == NGX_HTTP_OK
&& (u->headers_in.content_length_n == -1
|| (u->headers_in.content_length_n == tf->offset)))
{
ngx_http_upstream_store(r, u);
if (p->upstream_eof || p->upstream_done) {
if (u->headers_in.status_n == NGX_HTTP_OK
&& (u->headers_in.content_length_n == -1
|| (u->headers_in.content_length_n == tf->offset)))
{
ngx_http_upstream_store(r, u);
} else {
del = 1;
}
}
if (del && tf->file.fd != NGX_INVALID_FILE) {
} else if ((p->upstream_error
|| (p->upstream_eof
&& u->headers_in.status_n != NGX_HTTP_OK))
&& tf->file.fd != NGX_INVALID_FILE)
{
if (ngx_delete_file(tf->file.name.data) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
@ -2344,7 +2348,9 @@ ngx_http_upstream_finalize_request(ngx_http_request_t *r,
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"finalize http upstream request: %i", rc);
*u->cleanup = NULL;
if (u->cleanup) {
*u->cleanup = NULL;
}
if (u->state && u->state->response_sec) {
tp = ngx_timeofday();
@ -2625,7 +2631,17 @@ ngx_http_upstream_copy_content_type(ngx_http_request_t *r, ngx_table_elt_t *h,
r->headers_out.content_type_len = last - h->value.data;
r->headers_out.charset.len = h->value.data + h->value.len - p;
if (*p == '"') {
p++;
}
last = h->value.data + h->value.len;
if (*(last - 1) == '"') {
last--;
}
r->headers_out.charset.len = last - p;
r->headers_out.charset.data = p;
return NGX_OK;

View File

@ -645,7 +645,9 @@ ngx_http_upstream_free_round_robin_peer(ngx_peer_connection_t *pc, void *data,
peer->fails++;
peer->accessed = now;
peer->current_weight -= peer->weight / peer->max_fails;
if (peer->max_fails) {
peer->current_weight -= peer->weight / peer->max_fails;
}
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,
"free rr peer failed: %ui %i",

View File

@ -26,6 +26,10 @@ static ngx_int_t ngx_http_variable_unknown_header_in(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_variable_unknown_header_out(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_variable_cookie(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_variable_argument(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_variable_host(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
@ -75,6 +79,8 @@ static ngx_int_t ngx_http_variable_sent_transfer_encoding(ngx_http_request_t *r,
static ngx_int_t ngx_http_variable_nginx_version(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_variable_hostname(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
/*
* TODO:
@ -221,6 +227,9 @@ static ngx_http_variable_t ngx_http_core_variables[] = {
{ ngx_string("nginx_version"), NULL, ngx_http_variable_nginx_version,
0, 0, 0 },
{ ngx_string("hostname"), NULL, ngx_http_variable_hostname,
0, 0, 0 },
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
};
@ -476,6 +485,24 @@ ngx_http_get_variable(ngx_http_request_t *r, ngx_str_t *name, ngx_uint_t key,
return NULL;
}
if (ngx_strncmp(name->data, "cookie_", 7) == 0) {
if (ngx_http_variable_cookie(r, vv, (uintptr_t) name) == NGX_OK) {
return vv;
}
return NULL;
}
if (ngx_strncmp(name->data, "arg_", 4) == 0) {
if (ngx_http_variable_argument(r, vv, (uintptr_t) name) == NGX_OK) {
return vv;
}
return NULL;
}
vv->not_found = 1;
if (nowarn == 0) {
@ -706,32 +733,105 @@ ngx_http_variable_unknown_header(ngx_http_variable_value_t *v, ngx_str_t *var,
}
static ngx_int_t
ngx_http_variable_cookie(ngx_http_request_t *r, ngx_http_variable_value_t *v,
uintptr_t data)
{
ngx_str_t *name = (ngx_str_t *) data;
ngx_str_t cookie, s;
s.len = name->len - (sizeof("cookie_") - 1);
s.data = name->data + sizeof("cookie_") - 1;
if (ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &s, &cookie)
== NGX_DECLINED)
{
v->not_found = 1;
return NGX_OK;
}
v->len = cookie.len;
v->valid = 1;
v->no_cacheable = 0;
v->not_found = 0;
v->data = cookie.data;
return NGX_OK;
}
static ngx_int_t
ngx_http_variable_argument(ngx_http_request_t *r, ngx_http_variable_value_t *v,
uintptr_t data)
{
ngx_str_t *name = (ngx_str_t *) data;
u_char *p, *arg;
size_t len;
if (r->args.len == 0) {
v->not_found = 1;
return NGX_OK;
}
len = name->len - 1 - (sizeof("arg_") - 1);
arg = name->data + sizeof("arg_") - 1;
for (p = r->args.data; *p && *p != ' '; p++) {
/*
* although r->args.data is not null-terminated by itself,
* however, there is null in the end of request line
*/
p = ngx_strcasestrn(p, (char *) arg, len);
if (p == NULL) {
v->not_found = 1;
return NGX_OK;
}
if ((p == r->args.data || *(p - 1) == '&') && *(p + len + 1) == '=') {
v->data = p + len + 2;
p = (u_char *) ngx_strchr(p, '&');
if (p == NULL) {
p = r->args.data + r->args.len;
}
v->len = p - v->data;
v->valid = 1;
v->no_cacheable = 0;
v->not_found = 0;
return NGX_OK;
}
}
v->not_found = 1;
return NGX_OK;
}
static ngx_int_t
ngx_http_variable_host(ngx_http_request_t *r, ngx_http_variable_value_t *v,
uintptr_t data)
{
ngx_http_core_srv_conf_t *cscf;
if (r->host_start == NULL) {
if (r->headers_in.host) {
v->len = r->headers_in.host_name_len;
v->data = r->headers_in.host->value.data;
} else {
cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
v->len = cscf->server_name.len;
v->data = cscf->server_name.data;
}
} else if (r->host_end) {
v->len = r->host_end - r->host_start;
v->data = r->host_start;
if (r->headers_in.server.len) {
v->len = r->headers_in.server.len;
v->data = r->headers_in.server.data;
} else {
v->not_found = 1;
return NGX_OK;
cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
v->len = cscf->server_name.len;
v->data = cscf->server_name.data;
}
v->valid = 1;
@ -1283,6 +1383,20 @@ ngx_http_variable_nginx_version(ngx_http_request_t *r,
}
static ngx_int_t
ngx_http_variable_hostname(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data)
{
v->len = ngx_cycle->hostname.len;
v->valid = 1;
v->no_cacheable = 0;
v->not_found = 0;
v->data = ngx_cycle->hostname.data;
return NGX_OK;
}
ngx_int_t
ngx_http_variables_add_core_vars(ngx_conf_t *cf)
{
@ -1388,6 +1502,20 @@ ngx_http_variables_init_vars(ngx_conf_t *cf)
continue;
}
if (ngx_strncmp(v[i].name.data, "cookie_", 7) == 0) {
v[i].get_handler = ngx_http_variable_cookie;
v[i].data = (uintptr_t) &v[i].name;
continue;
}
if (ngx_strncmp(v[i].name.data, "arg_", 4) == 0) {
v[i].get_handler = ngx_http_variable_argument;
v[i].data = (uintptr_t) &v[i].name;
continue;
}
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
"unknown \"%V\" variable", &v[i].name);

View File

@ -16,7 +16,7 @@
typedef ngx_variable_value_t ngx_http_variable_value_t;
#define ngx_http_variable(v) { sizeof(v) - 1, 1, 0, 0, (u_char *) v }
#define ngx_http_variable(v) { sizeof(v) - 1, 1, 0, 0, 0, (u_char *) v }
typedef struct ngx_http_variable_s ngx_http_variable_t;

View File

@ -164,7 +164,7 @@ typedef struct {
unsigned no_sync_literal:1;
unsigned starttls:1;
unsigned esmtp:1;
unsigned auth_method:2;
unsigned auth_method:3;
unsigned auth_wait:1;
ngx_str_t login;
@ -243,10 +243,11 @@ typedef struct {
#define NGX_SMTP_STARTTLS 13
#define NGX_MAIL_AUTH_PLAIN 0
#define NGX_MAIL_AUTH_LOGIN 1
#define NGX_MAIL_AUTH_APOP 2
#define NGX_MAIL_AUTH_CRAM_MD5 3
#define NGX_MAIL_AUTH_PLAIN 0
#define NGX_MAIL_AUTH_LOGIN 1
#define NGX_MAIL_AUTH_LOGIN_USERNAME 2
#define NGX_MAIL_AUTH_APOP 3
#define NGX_MAIL_AUTH_CRAM_MD5 4
#define NGX_MAIL_AUTH_PLAIN_ENABLED 0x0002
@ -329,7 +330,7 @@ ngx_int_t ngx_mail_salt(ngx_mail_session_t *s, ngx_connection_t *c,
ngx_int_t ngx_mail_auth_plain(ngx_mail_session_t *s, ngx_connection_t *c,
ngx_uint_t n);
ngx_int_t ngx_mail_auth_login_username(ngx_mail_session_t *s,
ngx_connection_t *c);
ngx_connection_t *c, ngx_uint_t n);
ngx_int_t ngx_mail_auth_login_password(ngx_mail_session_t *s,
ngx_connection_t *c);
ngx_int_t ngx_mail_auth_cram_md5_salt(ngx_mail_session_t *s,

View File

@ -138,6 +138,7 @@ ngx_module_t ngx_mail_auth_http_module = {
static ngx_str_t ngx_mail_auth_http_method[] = {
ngx_string("plain"),
ngx_string("plain"),
ngx_string("plain"),
ngx_string("apop"),

View File

@ -185,20 +185,7 @@ ngx_mail_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_str_value(conf->server_name, prev->server_name, "");
if (conf->server_name.len == 0) {
conf->server_name.data = ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN);
if (conf->server_name.data == NULL) {
return NGX_CONF_ERROR;
}
if (gethostname((char *) conf->server_name.data, NGX_MAXHOSTNAMELEN)
== -1)
{
ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
"gethostname() failed");
return NGX_CONF_ERROR;
}
conf->server_name.len = ngx_strlen(conf->server_name.data);
conf->server_name = cf->cycle->hostname;
}
if (conf->protocol == NULL) {

View File

@ -335,21 +335,22 @@ ngx_mail_auth_plain(ngx_mail_session_t *s, ngx_connection_t *c, ngx_uint_t n)
ngx_int_t
ngx_mail_auth_login_username(ngx_mail_session_t *s, ngx_connection_t *c)
ngx_mail_auth_login_username(ngx_mail_session_t *s, ngx_connection_t *c,
ngx_uint_t n)
{
ngx_str_t *arg;
arg = s->args.elts;
ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
"mail auth login username: \"%V\"", &arg[0]);
"mail auth login username: \"%V\"", &arg[n]);
s->login.data = ngx_palloc(c->pool, ngx_base64_decoded_length(arg[0].len));
s->login.data = ngx_palloc(c->pool, ngx_base64_decoded_length(arg[n].len));
if (s->login.data == NULL){
return NGX_ERROR;
}
if (ngx_decode_base64(&s->login, &arg[0]) != NGX_OK) {
if (ngx_decode_base64(&s->login, &arg[n]) != NGX_OK) {
ngx_log_error(NGX_LOG_INFO, c->log, 0,
"client sent invalid base64 encoding in AUTH LOGIN command");
return NGX_MAIL_PARSE_INVALID_COMMAND;

View File

@ -205,7 +205,7 @@ ngx_mail_imap_auth_state(ngx_event_t *rev)
break;
case ngx_imap_auth_login_username:
rc = ngx_mail_auth_login_username(s, c);
rc = ngx_mail_auth_login_username(s, c, 0);
tag = 0;
s->out.len = sizeof(imap_password) - 1;
@ -370,6 +370,14 @@ ngx_mail_imap_authenticate(ngx_mail_session_t *s, ngx_connection_t *c)
return NGX_OK;
case NGX_MAIL_AUTH_LOGIN_USERNAME:
s->out.len = sizeof(imap_password) - 1;
s->out.data = imap_password;
s->mail_state = ngx_imap_auth_login_password;
return ngx_mail_auth_login_username(s, c, 1);
case NGX_MAIL_AUTH_PLAIN:
s->out.len = sizeof(imap_plain_next) - 1;

View File

@ -848,6 +848,10 @@ ngx_mail_auth_parse(ngx_mail_session_t *s, ngx_connection_t *c)
return NGX_MAIL_AUTH_LOGIN;
}
if (s->args.nelts == 2) {
return NGX_MAIL_AUTH_LOGIN_USERNAME;
}
return NGX_MAIL_PARSE_INVALID_COMMAND;
}

View File

@ -226,7 +226,7 @@ ngx_mail_pop3_auth_state(ngx_event_t *rev)
break;
case ngx_pop3_auth_login_username:
rc = ngx_mail_auth_login_username(s, c);
rc = ngx_mail_auth_login_username(s, c, 0);
s->out.len = sizeof(pop3_password) - 1;
s->out.data = pop3_password;
@ -474,6 +474,14 @@ ngx_mail_pop3_auth(ngx_mail_session_t *s, ngx_connection_t *c)
return NGX_OK;
case NGX_MAIL_AUTH_LOGIN_USERNAME:
s->out.len = sizeof(pop3_password) - 1;
s->out.data = pop3_password;
s->mail_state = ngx_pop3_auth_login_password;
return ngx_mail_auth_login_username(s, c, 1);
case NGX_MAIL_AUTH_PLAIN:
s->out.len = sizeof(pop3_next) - 1;

View File

@ -12,6 +12,7 @@
static void ngx_mail_smtp_resolve_addr_handler(ngx_resolver_ctx_t *ctx);
static void ngx_mail_smtp_resolve_name(ngx_event_t *rev);
static void ngx_mail_smtp_resolve_name_handler(ngx_resolver_ctx_t *ctx);
static void ngx_mail_smtp_greeting(ngx_mail_session_t *s, ngx_connection_t *c);
static void ngx_mail_smtp_invalid_pipelining(ngx_event_t *rev);
@ -88,9 +89,8 @@ ngx_mail_smtp_init_session(ngx_mail_session_t *s, ngx_connection_t *c)
static void
ngx_mail_smtp_resolve_addr_handler(ngx_resolver_ctx_t *ctx)
{
ngx_connection_t *c;
ngx_mail_session_t *s;
ngx_mail_core_srv_conf_t *cscf;
ngx_connection_t *c;
ngx_mail_session_t *s;
s = ctx->data;
c = s->connection;
@ -131,6 +131,23 @@ ngx_mail_smtp_resolve_addr_handler(ngx_resolver_ctx_t *ctx)
ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
"address resolved: %V", &s->host);
c->read->handler = ngx_mail_smtp_resolve_name;
ngx_post_event(c->read, &ngx_posted_events);
}
static void
ngx_mail_smtp_resolve_name(ngx_event_t *rev)
{
ngx_connection_t *c;
ngx_mail_session_t *s;
ngx_resolver_ctx_t *ctx;
ngx_mail_core_srv_conf_t *cscf;
c = rev->data;
s = c->data;
cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
ctx = ngx_resolve_start(cscf->resolver, NULL);
@ -435,7 +452,7 @@ ngx_mail_smtp_auth_state(ngx_event_t *rev)
break;
case ngx_smtp_auth_login_username:
rc = ngx_mail_auth_login_username(s, c);
rc = ngx_mail_auth_login_username(s, c, 0);
s->out.len = sizeof(smtp_password) - 1;
s->out.data = smtp_password;
@ -579,6 +596,14 @@ ngx_mail_smtp_auth(ngx_mail_session_t *s, ngx_connection_t *c)
return NGX_OK;
case NGX_MAIL_AUTH_LOGIN_USERNAME:
s->out.len = sizeof(smtp_password) - 1;
s->out.data = smtp_password;
s->mail_state = ngx_smtp_auth_login_password;
return ngx_mail_auth_login_username(s, c, 1);
case NGX_MAIL_AUTH_PLAIN:
s->out.len = sizeof(smtp_next) - 1;

View File

@ -261,7 +261,7 @@ ngx_mail_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child)
}
ngx_conf_merge_value(conf->builtin_session_cache,
prev->builtin_session_cache, NGX_SSL_NO_SCACHE);
prev->builtin_session_cache, NGX_SSL_NONE_SCACHE);
if (conf->shm_zone == NULL) {
conf->shm_zone = prev->shm_zone;
@ -298,6 +298,11 @@ ngx_mail_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
continue;
}
if (ngx_strcmp(value[i].data, "none") == 0) {
scf->builtin_session_cache = NGX_SSL_NONE_SCACHE;
continue;
}
if (ngx_strcmp(value[i].data, "builtin") == 0) {
scf->builtin_session_cache = NGX_SSL_DFLT_BUILTIN_SCACHE;
continue;

View File

@ -10,10 +10,11 @@
#if (NGX_HAVE_STRERROR_R)
u_char *ngx_strerror_r(int err, u_char *errstr, size_t size)
u_char *
ngx_strerror_r(int err, u_char *errstr, size_t size)
{
if (size == 0) {
return 0;
return errstr;
}
errstr[0] = '\0';
@ -32,12 +33,13 @@ u_char *ngx_strerror_r(int err, u_char *errstr, size_t size)
/* Linux strerror_r() */
u_char *ngx_strerror_r(int err, u_char *errstr, size_t size)
u_char *
ngx_strerror_r(int err, u_char *errstr, size_t size)
{
char *str;
if (size == 0) {
return 0;
return errstr;
}
errstr[0] = '\0';

View File

@ -68,7 +68,17 @@ ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *ce,
#define ngx_read_fd read
#define ngx_read_fd_n "read()"
#define ngx_write_fd write
/*
* we use inlined function instead of simple #define
* because glibc 2.3 sets warn_unused_result attribute for write()
* and in this case gcc 4.3 ignores (void) cast
*/
static ngx_inline ssize_t
ngx_write_fd(ngx_fd_t fd, void *buf, size_t n)
{
return write(fd, buf, n);
}
#define ngx_write_fd_n "write()"
#define ngx_linefeed(p) *p++ = LF;

View File

@ -47,6 +47,7 @@
#include <time.h> /* tzset() */
#include <malloc.h> /* memalign() */
#include <limits.h> /* IOV_MAX */
#include <sys/ioctl.h>
#include <sys/sysctl.h>
#include <crypt.h>

View File

@ -110,7 +110,7 @@
#include <sys/param.h> /* ALIGN() */
/*
/*
* FreeBSD 3.x has no CMSG_SPACE() and CMSG_LEN() and has the broken CMSG_DATA()
*/

View File

@ -22,7 +22,7 @@ ngx_os_io_t ngx_os_io = {
ngx_unix_recv,
ngx_readv_chain,
ngx_udp_unix_recv,
NULL,
ngx_unix_send,
ngx_writev_chain,
0
};

View File

@ -494,10 +494,16 @@ ngx_process_get_status(void)
}
if (WTERMSIG(status)) {
#ifdef WCOREDUMP
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
"%s %P exited on signal %d%s",
process, pid, WTERMSIG(status),
WCOREDUMP(status) ? " (core dumped)" : "");
#else
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
"%s %P exited on signal %d",
process, pid, WTERMSIG(status));
#endif
} else {
ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0,

View File

@ -1054,70 +1054,74 @@ ngx_channel_handler(ngx_event_t *ev)
ngx_log_debug0(NGX_LOG_DEBUG_CORE, ev->log, 0, "channel handler");
n = ngx_read_channel(c->fd, &ch, sizeof(ngx_channel_t), ev->log);
for ( ;; ) {
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, "channel: %i", n);
n = ngx_read_channel(c->fd, &ch, sizeof(ngx_channel_t), ev->log);
if (n == NGX_ERROR) {
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, "channel: %i", n);
if (ngx_event_flags & NGX_USE_EPOLL_EVENT) {
ngx_del_conn(c, 0);
}
if (n == NGX_ERROR) {
ngx_close_connection(c);
return;
}
if (ngx_event_flags & NGX_USE_EPOLL_EVENT) {
ngx_del_conn(c, 0);
}
if (ngx_event_flags & NGX_USE_EVENTPORT_EVENT) {
if (ngx_add_event(ev, NGX_READ_EVENT, 0) == NGX_ERROR) {
ngx_close_connection(c);
return;
}
}
if (n == NGX_AGAIN) {
return;
}
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0,
"channel command: %d", ch.command);
switch (ch.command) {
case NGX_CMD_QUIT:
ngx_quit = 1;
break;
case NGX_CMD_TERMINATE:
ngx_terminate = 1;
break;
case NGX_CMD_REOPEN:
ngx_reopen = 1;
break;
case NGX_CMD_OPEN_CHANNEL:
ngx_log_debug3(NGX_LOG_DEBUG_CORE, ev->log, 0,
"get channel s:%i pid:%P fd:%d", ch.slot, ch.pid, ch.fd);
ngx_processes[ch.slot].pid = ch.pid;
ngx_processes[ch.slot].channel[0] = ch.fd;
break;
case NGX_CMD_CLOSE_CHANNEL:
ngx_log_debug4(NGX_LOG_DEBUG_CORE, ev->log, 0,
"close channel s:%i pid:%P our:%P fd:%d",
ch.slot, ch.pid, ngx_processes[ch.slot].pid,
ngx_processes[ch.slot].channel[0]);
if (close(ngx_processes[ch.slot].channel[0]) == -1) {
ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
"close() channel failed");
if (ngx_event_flags & NGX_USE_EVENTPORT_EVENT) {
if (ngx_add_event(ev, NGX_READ_EVENT, 0) == NGX_ERROR) {
return;
}
}
ngx_processes[ch.slot].channel[0] = -1;
break;
if (n == NGX_AGAIN) {
return;
}
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0,
"channel command: %d", ch.command);
switch (ch.command) {
case NGX_CMD_QUIT:
ngx_quit = 1;
break;
case NGX_CMD_TERMINATE:
ngx_terminate = 1;
break;
case NGX_CMD_REOPEN:
ngx_reopen = 1;
break;
case NGX_CMD_OPEN_CHANNEL:
ngx_log_debug3(NGX_LOG_DEBUG_CORE, ev->log, 0,
"get channel s:%i pid:%P fd:%d",
ch.slot, ch.pid, ch.fd);
ngx_processes[ch.slot].pid = ch.pid;
ngx_processes[ch.slot].channel[0] = ch.fd;
break;
case NGX_CMD_CLOSE_CHANNEL:
ngx_log_debug4(NGX_LOG_DEBUG_CORE, ev->log, 0,
"close channel s:%i pid:%P our:%P fd:%d",
ch.slot, ch.pid, ngx_processes[ch.slot].pid,
ngx_processes[ch.slot].channel[0]);
if (close(ngx_processes[ch.slot].channel[0]) == -1) {
ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
"close() channel failed");
}
ngx_processes[ch.slot].channel[0] = -1;
break;
}
}
}

View File

@ -91,7 +91,8 @@ static ngx_str_t wsa_errors[] = {
};
u_char *ngx_strerror_r(ngx_err_t err, u_char *errstr, size_t size)
u_char *
ngx_strerror_r(ngx_err_t err, u_char *errstr, size_t size)
{
int n;
u_int len;

View File

@ -36,13 +36,8 @@ ngx_message_box(char *title, ngx_uint_t type, ngx_err_t err,
*p++ = '.';
}
if ((unsigned) err >= 0x80000000) {
p = ngx_snprintf(p, last - p, " (%Xd: ", err);
} else {
p = ngx_snprintf(p, last - p, " (%d: ", err);
}
p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000)
? " (%d: " : " (%Xd: ", err);
p = ngx_strerror_r(err, p, last - p);
if (p < last) {