summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2005-03-19 12:38:37 +0000
committerIgor Sysoev <igor@sysoev.ru>2005-03-19 12:38:37 +0000
commitc15717285d2157a603bb1b130b26d7baa549be7e (patch)
tree56dc8346b22bb2660eecd3bc086d263ac6d67326
parente12fbfe82a176cd386cdcecfeabf43ac8fd870a4 (diff)
downloadnginx-c15717285d2157a603bb1b130b26d7baa549be7e.tar.gz
nginx-0.1.25-RELEASE importrelease-0.1.25
*) Bugfix: nginx did run on Linux parisc. *) Feature: nginx now does not start under FreeBSD if the sysctl kern.ipc.somaxconn value is too big. *) Bugfix: if a request was internally redirected by the ngx_http_index_module module to the ngx_http_proxy_module or ngx_http_fastcgi_module modules, then the index file was not closed after request completion. *) Feature: the "proxy_pass" can be used in location with regular expression. *) Feature: the ngx_http_rewrite_filter_module module supports the condition like "if ($HTTP_USER_AGENT ~ MSIE)". *) Bugfix: nginx started too slow if the large number of addresses and text values were used in the "geo" directive. *) Change: a variable name must be declared as "$name" in the "geo" directive. The previous variant without "$" is still supported, but will be removed soon. *) Feature: the "%{VARIABLE}v" logging parameter. *) Feature: the "set $name value" directive. *) Bugfix: gcc 4.0 compatibility. *) Feature: the --with-openssl-opt=OPTIONS autoconfiguration directive.
-rw-r--r--auto/cc/gcc35
-rw-r--r--auto/cc/icc38
-rw-r--r--auto/lib/openssl/make27
-rw-r--r--auto/options3
-rw-r--r--auto/sources40
-rw-r--r--auto/summary2
-rw-r--r--docs/xml/nginx/changes.xml117
-rw-r--r--src/core/nginx.c43
-rw-r--r--src/core/nginx.h2
-rw-r--r--src/core/ngx_array.c12
-rw-r--r--src/core/ngx_array.h17
-rw-r--r--src/core/ngx_buf.c21
-rw-r--r--src/core/ngx_buf.h18
-rw-r--r--src/core/ngx_conf_file.c323
-rw-r--r--src/core/ngx_connection.c7
-rw-r--r--src/core/ngx_cycle.c23
-rw-r--r--src/core/ngx_file.c9
-rw-r--r--src/core/ngx_file.h3
-rw-r--r--src/core/ngx_garbage_collector.c3
-rw-r--r--src/core/ngx_inet.c22
-rw-r--r--src/core/ngx_list.c6
-rw-r--r--src/core/ngx_list.h8
-rw-r--r--src/core/ngx_log.c6
-rw-r--r--src/core/ngx_output_chain.c17
-rw-r--r--src/core/ngx_palloc.c33
-rw-r--r--src/core/ngx_palloc.h2
-rw-r--r--src/core/ngx_radix_tree.c12
-rw-r--r--src/core/ngx_regex.c8
-rw-r--r--src/core/ngx_regex.h5
-rw-r--r--src/core/ngx_string.c81
-rw-r--r--src/core/ngx_string.h4
-rw-r--r--src/core/ngx_times.c23
-rw-r--r--src/core/ngx_unix_domain.c6
-rw-r--r--src/event/modules/ngx_devpoll_module.c37
-rw-r--r--src/event/modules/ngx_epoll_module.c8
-rw-r--r--src/event/modules/ngx_iocp_module.c27
-rw-r--r--src/event/modules/ngx_kqueue_module.c12
-rw-r--r--src/event/modules/ngx_poll_module.c18
-rw-r--r--src/event/modules/ngx_rtsig_module.c9
-rw-r--r--src/event/modules/ngx_select_module.c37
-rw-r--r--src/event/ngx_event.c103
-rw-r--r--src/event/ngx_event_accept.c20
-rw-r--r--src/event/ngx_event_acceptex.c12
-rw-r--r--src/event/ngx_event_openssl.c10
-rw-r--r--src/event/ngx_event_pipe.c40
-rw-r--r--src/event/ngx_event_posted.c2
-rw-r--r--src/event/ngx_event_timer.c3
-rw-r--r--src/event/ngx_event_timer.h4
-rw-r--r--src/http/modules/ngx_http_access_module.c (renamed from src/http/modules/ngx_http_access_handler.c)31
-rw-r--r--src/http/modules/ngx_http_autoindex_module.c (renamed from src/http/modules/ngx_http_autoindex_handler.c)23
-rw-r--r--src/http/modules/ngx_http_charset_filter_module.c (renamed from src/http/modules/ngx_http_charset_filter.c)93
-rw-r--r--src/http/modules/ngx_http_chunked_filter_module.c (renamed from src/http/modules/ngx_http_chunked_filter.c)24
-rw-r--r--src/http/modules/ngx_http_fastcgi_module.c (renamed from src/http/modules/ngx_http_fastcgi_handler.c)94
-rw-r--r--src/http/modules/ngx_http_geo_module.c48
-rw-r--r--src/http/modules/ngx_http_gzip_filter_module.c (renamed from src/http/modules/ngx_http_gzip_filter.c)70
-rw-r--r--src/http/modules/ngx_http_headers_filter_module.c (renamed from src/http/modules/ngx_http_headers_filter.c)29
-rw-r--r--src/http/modules/ngx_http_index_module.c (renamed from src/http/modules/ngx_http_index_handler.c)51
-rw-r--r--src/http/modules/ngx_http_not_modified_filter_module.c (renamed from src/http/modules/ngx_http_not_modified_filter.c)0
-rw-r--r--src/http/modules/ngx_http_range_filter_module.c (renamed from src/http/modules/ngx_http_range_filter.c)52
-rw-r--r--src/http/modules/ngx_http_rewrite_module.c (renamed from src/http/modules/ngx_http_rewrite_handler.c)560
-rw-r--r--src/http/modules/ngx_http_ssi_filter_module.c (renamed from src/http/modules/ngx_http_ssi_filter.c)18
-rw-r--r--src/http/modules/ngx_http_ssl_module.c24
-rw-r--r--src/http/modules/ngx_http_ssl_module.h2
-rw-r--r--src/http/modules/ngx_http_static_module.c (renamed from src/http/modules/ngx_http_static_handler.c)40
-rw-r--r--src/http/modules/ngx_http_status_module.c (renamed from src/http/modules/ngx_http_status_handler.c)0
-rw-r--r--src/http/modules/ngx_http_stub_status_module.c3
-rw-r--r--src/http/modules/ngx_http_userid_filter_module.c (renamed from src/http/modules/ngx_http_userid_filter.c)4
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.c42
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_header.c9
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_upstream.c79
-rw-r--r--src/http/ngx_http.c89
-rw-r--r--src/http/ngx_http.h13
-rw-r--r--src/http/ngx_http_busy_lock.c6
-rw-r--r--src/http/ngx_http_config.h10
-rw-r--r--src/http/ngx_http_copy_filter_module.c (renamed from src/http/ngx_http_copy_filter.c)44
-rw-r--r--src/http/ngx_http_core_module.c73
-rw-r--r--src/http/ngx_http_header_filter_module.c (renamed from src/http/ngx_http_header_filter.c)15
-rw-r--r--src/http/ngx_http_log_module.c (renamed from src/http/ngx_http_log_handler.c)143
-rw-r--r--src/http/ngx_http_log_module.h (renamed from src/http/ngx_http_log_handler.h)15
-rw-r--r--src/http/ngx_http_parse.c3
-rw-r--r--src/http/ngx_http_parse_time.c6
-rw-r--r--src/http/ngx_http_request.c136
-rw-r--r--src/http/ngx_http_request.h321
-rw-r--r--src/http/ngx_http_request_body.c54
-rw-r--r--src/http/ngx_http_special_response.c55
-rw-r--r--src/http/ngx_http_upstream.c17
-rw-r--r--src/http/ngx_http_variables.c235
-rw-r--r--src/http/ngx_http_variables.h30
-rw-r--r--src/http/ngx_http_write_filter_module.c (renamed from src/http/ngx_http_write_filter.c)24
-rw-r--r--src/imap/ngx_imap_handler.c7
-rw-r--r--src/imap/ngx_imap_parse.c6
-rw-r--r--src/imap/ngx_imap_proxy.c20
-rw-r--r--src/os/unix/ngx_aio_read_chain.c1
-rw-r--r--src/os/unix/ngx_aio_write_chain.c1
-rw-r--r--src/os/unix/ngx_alloc.c18
-rw-r--r--src/os/unix/ngx_errno.c3
-rw-r--r--src/os/unix/ngx_errno.h6
-rw-r--r--src/os/unix/ngx_files.c4
-rw-r--r--src/os/unix/ngx_freebsd_init.c19
-rw-r--r--src/os/unix/ngx_freebsd_rfork_thread.c19
-rw-r--r--src/os/unix/ngx_freebsd_rfork_thread.h2
-rw-r--r--src/os/unix/ngx_freebsd_sendfile_chain.c18
-rw-r--r--src/os/unix/ngx_linux_sendfile_chain.c3
-rw-r--r--src/os/unix/ngx_posix_init.c2
-rw-r--r--src/os/unix/ngx_process.c1
-rw-r--r--src/os/unix/ngx_process_cycle.c66
-rw-r--r--src/os/unix/ngx_pthread_thread.c6
-rw-r--r--src/os/unix/ngx_readv_chain.c49
-rw-r--r--src/os/unix/ngx_setproctitle.c3
-rw-r--r--src/os/unix/ngx_socket.c28
-rw-r--r--src/os/unix/ngx_solaris_sendfilev_chain.c8
-rw-r--r--src/os/unix/ngx_writev_chain.c6
-rw-r--r--src/os/win32/ngx_alloc.c3
-rw-r--r--src/os/win32/ngx_files.c17
-rw-r--r--src/os/win32/ngx_files.h7
-rw-r--r--src/os/win32/ngx_process_cycle.c2
-rw-r--r--src/os/win32/ngx_socket.c13
-rw-r--r--src/os/win32/ngx_socket.h5
-rw-r--r--src/os/win32/ngx_thread.c16
-rw-r--r--src/os/win32/ngx_thread.h11
-rw-r--r--src/os/win32/ngx_win32_config.h24
-rw-r--r--src/os/win32/ngx_wsarecv_chain.c27
-rw-r--r--src/os/win32/ngx_wsasend_chain.c18
123 files changed, 2880 insertions, 1462 deletions
diff --git a/auto/cc/gcc b/auto/cc/gcc
index c5b4e74ee..46b0aabb9 100644
--- a/auto/cc/gcc
+++ b/auto/cc/gcc
@@ -2,8 +2,15 @@
# Copyright (C) Igor Sysoev
-# gcc 2.7.2.3, 2.8.1, 2.95.4,
+# gcc 2.7.2.3, 2.8.1, 2.95.4, egcs-1.1.2
# 3.0.4, 3.1.1, 3.2.3, 3.3.2, 3.3.3, 3.3.4, 3.4.0, 3.4.2
+# 4.0.0
+
+
+NGX_GCC_VER=`$CC -v 2>&1 | grep 'gcc version' 2>&1 \
+ | sed -e 's/^.* version \(.*\)/\1/'`
+
+echo " + gcc version: $NGX_GCC_VER"
# Solaris 7's /usr/ccs/bin/as does not support "-pipe"
@@ -24,7 +31,6 @@ if [ $ngx_found = yes ]; then
PIPE="-pipe"
fi
-
# optimizations
#NGX_GCC_OPT="-O2"
@@ -61,8 +67,12 @@ case $CPU in
esac
-# STUB for batch builds
-if [ $CC = gcc27 ]; then CPU_OPT=; fi
+case "$NGX_GCC_VER" in
+ 2.7*)
+ # batch build
+ CPU_OPT=
+ ;;
+esac
CFLAGS="$CFLAGS $PIPE $CPU_OPT"
@@ -95,8 +105,21 @@ CFLAGS="$CFLAGS -Wall -Wpointer-arith"
#CFLAGS="$CFLAGS -Wconversion"
#CFLAGS="$CFLAGS -Winline"
-# we have a lot of the unused function arguments
-CFLAGS="$CFLAGS -Wno-unused"
+
+case "$NGX_GCC_VER" in
+ 3.* | 4.* )
+ # we have a lot of the unused function arguments
+ CFLAGS="$CFLAGS -Wno-unused-parameter"
+ CFLAGS="$CFLAGS -Wno-unused-function"
+ #CFLAGS="$CFLAGS -Wunreachable-code"
+ ;;
+
+ *)
+ # we have a lot of the unused function arguments
+ CFLAGS="$CFLAGS -Wno-unused"
+ ;;
+esac
+
# stop on warning
CFLAGS="$CFLAGS -Werror"
diff --git a/auto/cc/icc b/auto/cc/icc
index 47b91d781..b6ae759fb 100644
--- a/auto/cc/icc
+++ b/auto/cc/icc
@@ -7,7 +7,7 @@
# optimizations
CFLAGS="$CFLAGS -O"
-# inline functions declared with __inline
+# inline the functions declared with __inline
#CFLAGS="$CFLAGS -Ob1"
# inline any function, at the compiler's discretion
CFLAGS="$CFLAGS -Ob2"
@@ -54,14 +54,34 @@ fi
# warnings
-CFLAGS="$CFLAGS -w1"
-#CFLAGS="$CFLAGS -w2"
-
-# disable the ICC 8.1 errors:
-# error #181: argument is incompatible with corresponding format
-# string conversion
-# error #269: invalid format string conversion
-CFLAGS="$CFLAGS -wd181 -wd269"
+CFLAGS="$CFLAGS -w2"
+
+# disable some warnings
+
+# invalid type conversion: "int" to "char *"
+CFLAGS="$CFLAGS -wd171"
+# argument is incompatible with corresponding format string conversion
+CFLAGS="$CFLAGS -wd181"
+# zero used for undefined preprocessing identifier
+CFLAGS="$CFLAGS -wd193"
+# invalid format string conversion
+CFLAGS="$CFLAGS -wd269"
+# conversion from "long long" to "size_t" may lose significant bits
+CFLAGS="$CFLAGS -wd810"
+# parameter was never referenced
+CFLAGS="$CFLAGS -wd869"
+
+# STUB
+# enumerated type mixed with another type
+CFLAGS="$CFLAGS -wd188"
+# controlling expression is constant
+CFLAGS="$CFLAGS -wd279"
+# operands are evaluated in unspecified order
+CFLAGS="$CFLAGS -wd981"
+# external definition with no prior declaration
+CFLAGS="$CFLAGS -wd1418"
+# external declaration in primary source file
+CFLAGS="$CFLAGS -wd1419"
# stop on warning
CFLAGS="$CFLAGS -Werror"
diff --git a/auto/lib/openssl/make b/auto/lib/openssl/make
index c1aec882a..ff05a380a 100644
--- a/auto/lib/openssl/make
+++ b/auto/lib/openssl/make
@@ -1,17 +1,28 @@
# Copyright (C) Igor Sysoev
+if test -n "$OPENSSL_OPT"; then
+ NGX_OPENSSL_CONFIG="./Configure \"$OPENSSL_OPT\""
+else
+ NGX_OPENSSL_CONFIG="./config"
+fi
+
+if test -n "$USE_THREADS"; then
+ NGX_OPENSSL_CONFIG="$NGX_OPENSSL_CONFIG threads"
+fi
case "$NGX_PLATFORM" in
*)
- echo "$OPENSSL/libssl.a:" >> $MAKEFILE
- echo " cd $OPENSSL \\" >> $MAKEFILE
- echo " && \$(MAKE) clean \\" >> $MAKEFILE
- echo " && CC=\"\$(CC)\" \\" >> $MAKEFILE
- echo " ./config threads no-shared \\" >> $MAKEFILE
- echo " && \$(MAKE)" >> $MAKEFILE
+ cat << END >> $NGX_MAKEFILE
+
+$OPENSSL/libssl.a:
+ cd $OPENSSL \\
+ && \$(MAKE) clean \\
+ && $NGX_OPENSSL_CONFIG no-shared \\
+ && \$(MAKE)
+
+END
+
;;
esac
-
-echo >> $MAKEFILE
diff --git a/auto/options b/auto/options
index 8b9411308..a8146d967 100644
--- a/auto/options
+++ b/auto/options
@@ -153,6 +153,7 @@ do
--with-pcre-opt=*) PCRE_OPT="$value" ;;
--with-openssl=*) OPENSSL="$value" ;;
+ --with-openssl-opt=*) OPENSSL_OPT="$value" ;;
--with-md5=*) MD5="$value" ;;
--with-md5-opt=*) MD5_OPT="$value" ;;
@@ -203,6 +204,7 @@ cat << END
--with-http_ssl_module enable ngx_http_ssl_module
--without-http_charset_module disable ngx_http_charset_module
--without-http_gzip_module disable ngx_http_gzip_module
+ --without-http_ssi_module disable ngx_http_ssi_module
--without-http_userid_module disable ngx_http_userid_module
--without-http_access_module disable ngx_http_access_module
--without-http_autoindex_module disable ngx_http_autoindex_module
@@ -241,6 +243,7 @@ cat << END
pentium, pentiumpro
--with-openssl=DIR set path to OpenSSL library sources
+ --with-openssl-opt=OPTIONS set additional options for OpenSSL building
--with-debug enable the debugging logging
diff --git a/auto/sources b/auto/sources
index 57915de70..288495f72 100644
--- a/auto/sources
+++ b/auto/sources
@@ -241,27 +241,27 @@ HTTP_DEPS="src/http/ngx_http.h \
src/http/ngx_http_variables.h \
src/http/ngx_http_upstream.h \
src/http/ngx_http_busy_lock.h \
- src/http/ngx_http_log_handler.h"
+ src/http/ngx_http_log_module.h"
HTTP_SRCS="src/http/ngx_http.c \
src/http/ngx_http_core_module.c \
src/http/ngx_http_special_response.c \
src/http/ngx_http_request.c \
src/http/ngx_http_parse.c \
- src/http/ngx_http_header_filter.c \
- src/http/ngx_http_write_filter.c \
- src/http/ngx_http_copy_filter.c \
- src/http/ngx_http_log_handler.c \
+ src/http/ngx_http_header_filter_module.c \
+ src/http/ngx_http_write_filter_module.c \
+ src/http/ngx_http_copy_filter_module.c \
+ src/http/ngx_http_log_module.c \
src/http/ngx_http_request_body.c \
src/http/ngx_http_variables.c \
src/http/ngx_http_upstream.c \
src/http/ngx_http_parse_time.c \
- src/http/modules/ngx_http_static_handler.c \
- src/http/modules/ngx_http_index_handler.c \
- src/http/modules/ngx_http_chunked_filter.c \
- src/http/modules/ngx_http_range_filter.c \
- src/http/modules/ngx_http_headers_filter.c \
- src/http/modules/ngx_http_not_modified_filter.c"
+ src/http/modules/ngx_http_static_module.c \
+ src/http/modules/ngx_http_index_module.c \
+ src/http/modules/ngx_http_chunked_filter_module.c \
+ src/http/modules/ngx_http_range_filter_module.c \
+ src/http/modules/ngx_http_headers_filter_module.c \
+ src/http/modules/ngx_http_not_modified_filter_module.c"
# STUB
HTTP_SRCS="$HTTP_SRCS src/http/ngx_http_busy_lock.c"
@@ -271,31 +271,31 @@ HTPP_FILE_CACHE_SRCS=src/http/ngx_http_file_cache.c
HTTP_CHARSET_FILTER_MODULE=ngx_http_charset_filter_module
-HTTP_CHARSET_SRCS=src/http/modules/ngx_http_charset_filter.c
+HTTP_CHARSET_SRCS=src/http/modules/ngx_http_charset_filter_module.c
HTTP_GZIP_FILTER_MODULE=ngx_http_gzip_filter_module
-HTTP_GZIP_SRCS=src/http/modules/ngx_http_gzip_filter.c
+HTTP_GZIP_SRCS=src/http/modules/ngx_http_gzip_filter_module.c
HTTP_SSI_FILTER_MODULE=ngx_http_ssi_filter_module
-HTTP_SSI_SRCS=src/http/modules/ngx_http_ssi_filter.c
+HTTP_SSI_SRCS=src/http/modules/ngx_http_ssi_filter_module.c
HTTP_USERID_FILTER_MODULE=ngx_http_userid_filter_module
-HTTP_USERID_SRCS=src/http/modules/ngx_http_userid_filter.c
+HTTP_USERID_SRCS=src/http/modules/ngx_http_userid_filter_module.c
HTTP_ACCESS_MODULE=ngx_http_access_module
-HTTP_ACCESS_SRCS=src/http/modules/ngx_http_access_handler.c
+HTTP_ACCESS_SRCS=src/http/modules/ngx_http_access_module.c
HTTP_AUTOINDEX_MODULE=ngx_http_autoindex_module
-HTTP_AUTOINDEX_SRCS=src/http/modules/ngx_http_autoindex_handler.c
+HTTP_AUTOINDEX_SRCS=src/http/modules/ngx_http_autoindex_module.c
HTTP_STATUS_MODULE=ngx_http_status_module
-HTTP_STATUS_SRCS=src/http/modules/ngx_http_status_handler.c
+HTTP_STATUS_SRCS=src/http/modules/ngx_http_status_module.c
HTTP_GEO_MODULE=ngx_http_geo_module
@@ -303,7 +303,7 @@ HTTP_GEO_SRCS=src/http/modules/ngx_http_geo_module.c
HTTP_REWRITE_MODULE=ngx_http_rewrite_module
-HTTP_REWRITE_SRCS=src/http/modules/ngx_http_rewrite_handler.c
+HTTP_REWRITE_SRCS=src/http/modules/ngx_http_rewrite_module.c
HTTP_SSL_MODULE=ngx_http_ssl_module
@@ -324,7 +324,7 @@ HTTP_PROXY_SRCS="src/http/modules/proxy/ngx_http_proxy_handler.c \
HTTP_FASTCGI_MODULE=ngx_http_fastcgi_module
-HTTP_FASTCGI_SRCS=src/http/modules/ngx_http_fastcgi_handler.c
+HTTP_FASTCGI_SRCS=src/http/modules/ngx_http_fastcgi_module.c
IMAP_INCS="src/imap"
diff --git a/auto/summary b/auto/summary
index 4848c225f..7ef6ede3c 100644
--- a/auto/summary
+++ b/auto/summary
@@ -17,7 +17,7 @@ case $USE_THREADS in
esac
if [ $USE_PCRE = DISABLED ]; then
- echo " + PCRE library is disabled"
+ echo " + PCRE library is disabled"
else
case $PCRE in
diff --git a/docs/xml/nginx/changes.xml b/docs/xml/nginx/changes.xml
index 8c555fe8f..a21df8684 100644
--- a/docs/xml/nginx/changes.xml
+++ b/docs/xml/nginx/changes.xml
@@ -9,6 +9,123 @@
<title lang="en">nginx changelog</title>
+<changes ver="0.1.25" date="19.03.2005">
+
+<change type="bugfix">
+<para lang="ru">
+nginx ÎÅ ÒÁÂÏÔÁÌ ÎÁ Linux parisc.
+</para>
+<para lang="en">
+nginx did run on Linux parisc.
+</para>
+</change>
+
+<change type="feature">
+<para lang="ru">
+nginx ÔÅÐÅÒØ ÎÅ ÚÁÐÕÓËÁÅÔÓÑ ÐÏÄ FreeBSD, ÅÓÌÉ ÚÎÁÞÅÎÉÅ
+sysctl kern.ipc.somaxconn ÓÌÉÛËÏÍ ÂÏÌØÛÏÅ.
+</para>
+<para lang="en">
+nginx now does not start under FreeBSD if the sysctl kern.ipc.somaxconn
+value is too big.
+</para>
+</change>
+
+<change type="bugfix">
+<para lang="ru">
+ÅÓÌÉ ÍÏÄÕÌØ ngx_http_index_module ÄÅÌÁÌ ×ÎÕÔÒÅÎÎÅÅ ÐÅÒÅÎÁÐÒÁ×ÌÅÎÉÅ ÚÁÐÒÏÓÁ
+× ÍÏÄÕÌÉ ngx_http_proxy_module ÉÌÉ ngx_http_fastcgi_module, ÔÏ ÆÁÊÌ ÉÎÄÅËÓÁ
+ÎÅ ÚÁËÒÙ×ÁÌÓÑ ÐÏÓÌÅ ÏÂÓÌÕÖÉ×ÁÎÉÑ ÚÁÐÒÏÓÁ.
+</para>
+<para lang="en">
+if a request was internally redirected by the ngx_http_index_module
+module to the ngx_http_proxy_module or ngx_http_fastcgi_module modules,
+then the index file was not closed after request completion.
+</para>
+</change>
+
+<change type="feature">
+<para lang="ru">
+ÄÉÒÅËÔÉ×Á proxy_pass ÍÏÖÅÔ ÉÓÐÏÌØÚÏ×ÁÔØÓÑ × location, ÚÁÄÁÎÎÙÈ ÒÅÇÕÌÑÒÎÙÍ
+×ÙÒÁÖÅÎÉÅÍ.
+</para>
+<para lang="en">
+the "proxy_pass" can be used in location with regular expression.
+</para>
+</change>
+
+<change type="feature">
+<para lang="ru">
+ÍÏÄÕÌØ ngx_http_rewrite_filter_module ÐÏÄÄÅÒÖÉ×ÁÅÔ ÕÓÌÏ×ÉÑ ×ÉÄÁ
+"if ($HTTP_USER_AGENT ~ MSIE)".
+</para>
+<para lang="en">
+the ngx_http_rewrite_filter_module module supports the condition like
+"if ($HTTP_USER_AGENT ~ MSIE)".
+</para>
+</change>
+
+<change type="bugfix">
+<para lang="ru">
+nginx ÏÞÅÎØ ÍÅÄÌÅÎÎÏ ÚÁÐÕÓËÁÌÓÑ ÐÒÉ ÂÏÌØÛÏÍ ËÏÌÉÞÅÓÔ×Å ÁÄÒÅÓÏ× É
+ÉÓÐÏÌØÚÏ×ÁÎÉÉ ÔÅËÓÔÏ×ÙÈ ÚÎÁÞÅÎÉÊ × ÄÉÒÅËÔÉ×Å geo.
+</para>
+<para lang="en">
+nginx started too slow if the large number of addresses and text values
+were used in the "geo" directive.
+</para>
+</change>
+
+<change type="change">
+<para lang="ru">
+ÉÍÑ ÐÅÒÅÍÅÎÎÏÊ × ÄÉÒÅËÔÉ×Å geo ÎÕÖÎÏ ÕËÁÚÙ×ÁÔØ, ËÁË $name.
+ðÒÅÖÎÉÊ ×ÁÒÉÁÎÔ ÂÅÚ "$" ÐÏËÁ ÒÁÂÏÔÁÅÔ, ÎÏ ×ÓËÏÒÅ ÂÕÄÅÔ ÕÂÒÁÎ.
+</para>
+<para lang="en">
+a variable name must be declared as "$name" in the "geo" directive.
+The previous variant without "$" is still supported, but will be removed soon.
+</para>
+</change>
+
+<change type="feature">
+<para lang="ru">
+ÐÁÒÁÍÅÔÒ ÌÏÇÁ "%{VARIABLE}v".
+</para>
+<para lang="en">
+the "%{VARIABLE}v" logging parameter.
+</para>
+</change>
+
+<change type="feature">
+<para lang="ru">
+ÄÉÒÅËÔÉ×Á "set $name value".
+</para>
+<para lang="en">
+the "set $name value" directive.
+</para>
+</change>
+
+<change type="bugfix">
+<para lang="ru">
+ÓÏ×ÍÅÓÔÉÍÏÓÔØ Ó gcc 4.0.
+</para>
+<para lang="en">
+gcc 4.0 compatibility.
+</para>
+</change>
+
+<change type="feature">
+<para lang="ru">
+ÐÁÒÁÍÅÔÒ Á×ÔÏËÏÎÆÉÇÕÒÁÃÉÉ --with-openssl-opt=OPTIONS.
+</para>
+<para lang="en">
+the --with-openssl-opt=OPTIONS autoconfiguration directive.
+</para>
+</change>
+
+</changes>
+
+
<changes ver="0.1.24" date="04.03.2005">
<change type="feature">
diff --git a/src/core/nginx.c b/src/core/nginx.c
index d6ee9f652..e2a35dc67 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -141,7 +141,8 @@ main(int argc, char *const *argv)
ngx_pid = ngx_getpid();
- if (!(log = ngx_log_init())) {
+ log = ngx_log_init();
+ if (log == NULL) {
return 1;
}
@@ -155,7 +156,8 @@ main(int argc, char *const *argv)
init_cycle.log = log;
ngx_cycle = &init_cycle;
- if (!(init_cycle.pool = ngx_create_pool(1024, log))) {
+ init_cycle.pool = ngx_create_pool(1024, log);
+ if (init_cycle.pool == NULL) {
return 1;
}
@@ -255,9 +257,9 @@ main(int argc, char *const *argv)
static ngx_int_t
ngx_add_inherited_sockets(ngx_cycle_t *cycle)
{
- u_char *p, *v, *inherited;
- ngx_socket_t s;
- ngx_listening_t *ls;
+ u_char *p, *v, *inherited;
+ ngx_int_t s;
+ ngx_listening_t *ls;
inherited = (u_char *) getenv(NGINX_VAR);
@@ -287,11 +289,12 @@ ngx_add_inherited_sockets(ngx_cycle_t *cycle)
v = p + 1;
- if (!(ls = ngx_array_push(&cycle->listening))) {
+ ls = ngx_array_push(&cycle->listening);
+ if (ls == NULL) {
return NGX_ERROR;
}
- ls->fd = s;
+ ls->fd = (ngx_socket_t) s;
}
}
@@ -315,7 +318,7 @@ ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv)
ctx.argv = argv;
var = ngx_alloc(sizeof(NGINX_VAR)
- + cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2,
+ + cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2,
cycle->log);
p = ngx_cpymem(var, NGINX_VAR "=", sizeof(NGINX_VAR));
@@ -411,27 +414,29 @@ static ngx_int_t ngx_getopt(ngx_cycle_t *cycle, int argc, char *const *argv)
static ngx_int_t
ngx_save_argv(ngx_cycle_t *cycle, int argc, char *const *argv)
{
- size_t len;
- ngx_int_t i;
+#if (NGX_FREEBSD)
ngx_os_argv = (char **) argv;
-
ngx_argc = argc;
-
-#if (NGX_FREEBSD)
-
ngx_argv = (char **) argv;
#else
+ size_t len;
+ ngx_int_t i;
+
+ ngx_os_argv = (char **) argv;
+ ngx_argc = argc;
- if (!(ngx_argv = ngx_alloc((argc + 1) * sizeof(char *), cycle->log))) {
+ ngx_argv = ngx_alloc((argc + 1) * sizeof(char *), cycle->log);
+ if (ngx_argv == NULL) {
return NGX_ERROR;
}
for (i = 0; i < argc; i++) {
len = ngx_strlen(argv[i]) + 1;
- if (!(ngx_argv[i] = ngx_alloc(len, cycle->log))) {
+ ngx_argv[i] = ngx_alloc(len, cycle->log);
+ if (ngx_argv[i] == NULL) {
return NGX_ERROR;
}
@@ -451,7 +456,8 @@ ngx_core_module_create_conf(ngx_cycle_t *cycle)
{
ngx_core_conf_t *ccf;
- if (!(ccf = ngx_pcalloc(cycle->pool, sizeof(ngx_core_conf_t)))) {
+ ccf = ngx_pcalloc(cycle->pool, sizeof(ngx_core_conf_t));
+ if (ccf == NULL) {
return NULL;
}
@@ -534,7 +540,8 @@ ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
ccf->newpid.len = ccf->pid.len + sizeof(NGX_NEWPID_EXT);
- if (!(ccf->newpid.data = ngx_palloc(cycle->pool, ccf->newpid.len))) {
+ ccf->newpid.data = ngx_palloc(cycle->pool, ccf->newpid.len);
+ if (ccf->newpid.data == NULL) {
return NGX_CONF_ERROR;
}
diff --git a/src/core/nginx.h b/src/core/nginx.h
index 5f76b9b01..54afca93a 100644
--- a/src/core/nginx.h
+++ b/src/core/nginx.h
@@ -8,7 +8,7 @@
#define _NGINX_H_INCLUDED_
-#define NGINX_VER "nginx/0.1.24"
+#define NGINX_VER "nginx/0.1.25"
#define NGINX_VAR "NGINX"
#define NGX_NEWPID_EXT ".newbin"
diff --git a/src/core/ngx_array.c b/src/core/ngx_array.c
index 82d5d1db8..b6167afc4 100644
--- a/src/core/ngx_array.c
+++ b/src/core/ngx_array.c
@@ -12,11 +12,13 @@ ngx_array_t *ngx_array_create(ngx_pool_t *p, ngx_uint_t n, size_t size)
{
ngx_array_t *a;
- if (!(a = ngx_palloc(p, sizeof(ngx_array_t)))) {
+ a = ngx_palloc(p, sizeof(ngx_array_t));
+ if (a == NULL) {
return NULL;
}
- if (!(a->elts = ngx_palloc(p, n * size))) {
+ a->elts = ngx_palloc(p, n * size);
+ if (a->elts == NULL) {
return NULL;
}
@@ -72,7 +74,8 @@ void *ngx_array_push(ngx_array_t *a)
} else {
/* allocate a new array */
- if (!(new = ngx_palloc(p, 2 * size))) {
+ new = ngx_palloc(p, 2 * size);
+ if (new == NULL) {
return NULL;
}
@@ -120,7 +123,8 @@ void *ngx_array_push_n(ngx_array_t *a, ngx_uint_t n)
nalloc = 2 * ((n >= a->nalloc) ? n : a->nalloc);
- if (!(new = ngx_palloc(p, nalloc * a->size))) {
+ new = ngx_palloc(p, nalloc * a->size);
+ if (new == NULL) {
return NULL;
}
diff --git a/src/core/ngx_array.h b/src/core/ngx_array.h
index d90cf76f0..5f97451aa 100644
--- a/src/core/ngx_array.h
+++ b/src/core/ngx_array.h
@@ -27,10 +27,11 @@ void *ngx_array_push(ngx_array_t *a);
void *ngx_array_push_n(ngx_array_t *a, ngx_uint_t n);
-static ngx_inline ngx_int_t ngx_array_init(ngx_array_t *array, ngx_pool_t *pool,
- ngx_uint_t n, size_t size)
+static ngx_inline ngx_int_t
+ngx_array_init(ngx_array_t *array, ngx_pool_t *pool, ngx_uint_t n, size_t size)
{
- if (!(array->elts = ngx_palloc(pool, n * size))) {
+ array->elts = ngx_palloc(pool, n * size);
+ if (array->elts == NULL) {
return NGX_ERROR;
}
@@ -43,14 +44,4 @@ static ngx_inline ngx_int_t ngx_array_init(ngx_array_t *array, ngx_pool_t *pool,
}
-/* STUB */
-#define ngx_init_array(a, p, n, s, rc) \
- ngx_test_null(a.elts, ngx_palloc(p, n * s), rc); \
- a.nelts = 0; a.size = s; a.nalloc = n; a.pool = p;
-
-#define ngx_create_array ngx_array_create
-#define ngx_push_array ngx_array_push
-/**/
-
-
#endif /* _NGX_ARRAY_H_INCLUDED_ */
diff --git a/src/core/ngx_buf.c b/src/core/ngx_buf.c
index 97c94a363..2f0356ffd 100644
--- a/src/core/ngx_buf.c
+++ b/src/core/ngx_buf.c
@@ -13,11 +13,13 @@ ngx_create_temp_buf(ngx_pool_t *pool, size_t size)
{
ngx_buf_t *b;
- if (!(b = ngx_calloc_buf(pool))) {
+ b = ngx_calloc_buf(pool);
+ if (b == NULL) {
return NULL;
}
- if (!(b->start = ngx_palloc(pool, size))) {
+ b->start = ngx_palloc(pool, size);
+ if (b->start == NULL) {
return NULL;
}
@@ -49,14 +51,17 @@ ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs)
ngx_buf_t *b;
ngx_chain_t *chain, *cl, **ll;
- if (!(p = ngx_palloc(pool, bufs->num * bufs->size))) {
+ p = ngx_palloc(pool, bufs->num * bufs->size);
+ if (p == NULL) {
return NULL;
}
ll = &chain;
for (i = 0; i < bufs->num; i++) {
- if (!(b = ngx_calloc_buf(pool))) {
+
+ b = ngx_calloc_buf(pool);
+ if (b == NULL) {
return NULL;
}
@@ -79,7 +84,8 @@ ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs)
p += bufs->size;
b->end = p;
- if (!(cl = ngx_alloc_chain_link(pool))) {
+ cl = ngx_alloc_chain_link(pool);
+ if (cl == NULL) {
return NULL;
}
@@ -106,7 +112,10 @@ ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in)
}
while (in) {
- ngx_test_null(cl, ngx_alloc_chain_link(pool), NGX_ERROR);
+ cl = ngx_alloc_chain_link(pool);
+ if (cl == NULL) {
+ return NGX_ERROR;
+ }
cl->buf = in->buf;
*ll = cl;
diff --git a/src/core/ngx_buf.h b/src/core/ngx_buf.h
index d672cf485..721b9c2df 100644
--- a/src/core/ngx_buf.h
+++ b/src/core/ngx_buf.h
@@ -119,27 +119,9 @@ ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs);
#define ngx_alloc_buf(pool) ngx_palloc(pool, sizeof(ngx_buf_t))
#define ngx_calloc_buf(pool) ngx_pcalloc(pool, sizeof(ngx_buf_t))
-
#define ngx_alloc_chain_link(pool) ngx_palloc(pool, sizeof(ngx_chain_t))
-#define ngx_alloc_link_and_set_buf(chain, b, pool, error) \
- do { \
- ngx_test_null(chain, ngx_alloc_chain_link(pool), error); \
- chain->buf = b; \
- chain->next = NULL; \
- } while (0);
-
-
-#define ngx_chain_add_link(chain, last, cl) \
- if (chain) { \
- *last = cl; \
- } else { \
- chain = cl; \
- } \
- last = &cl->next
-
-
ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in);
ngx_int_t ngx_chain_writer(void *ctx, ngx_chain_t *in);
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index 437d7a283..653ff48b3 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -8,6 +8,7 @@
#include <ngx_core.h>
+static ngx_int_t ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last);
static char *ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
@@ -53,13 +54,10 @@ static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf);
char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
{
- int m, rc, found, valid;
char *rv;
- void *conf, **confp;
ngx_fd_t fd;
- ngx_str_t *name;
+ ngx_int_t rc;
ngx_conf_file_t *prev;
- ngx_command_t *cmd;
#if (NGX_SUPPRESS_WARN)
fd = NGX_INVALID_FILE;
@@ -78,7 +76,9 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
}
prev = cf->conf_file;
- if (!(cf->conf_file = ngx_palloc(cf->pool, sizeof(ngx_conf_file_t)))) {
+
+ cf->conf_file = ngx_palloc(cf->pool, sizeof(ngx_conf_file_t));
+ if (cf->conf_file == NULL) {
return NGX_CONF_ERROR;
}
@@ -130,210 +130,204 @@ char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
rv = (*cf->handler)(cf, NULL, cf->handler_conf);
if (rv == NGX_CONF_OK) {
continue;
+ }
- } else if (rv == NGX_CONF_ERROR) {
- rc = NGX_ERROR;
- break;
-
- } else {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "%s in %s:%d",
- rv,
- cf->conf_file->file.name.data,
- cf->conf_file->line);
+ if (rv == NGX_CONF_ERROR) {
rc = NGX_ERROR;
break;
}
+
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "%s in %s:%d",
+ rv, cf->conf_file->file.name.data,
+ cf->conf_file->line);
+ rc = NGX_ERROR;
+ break;
}
- name = (ngx_str_t *) cf->args->elts;
- found = 0;
- for (m = 0; rc != NGX_ERROR && !found && ngx_modules[m]; m++) {
+ rc = ngx_conf_handler(cf, rc);
- /* look up the directive in the appropriate modules */
+ if (rc == NGX_ERROR) {
+ break;
+ }
+ }
- if (ngx_modules[m]->type != NGX_CONF_MODULE
- && ngx_modules[m]->type != cf->module_type)
- {
- continue;
- }
- cmd = ngx_modules[m]->commands;
- if (cmd == NULL) {
- continue;
- }
+ if (filename) {
+ cf->conf_file = prev;
- while (cmd->name.len) {
- if (name->len == cmd->name.len
- && ngx_strcmp(name->data, cmd->name.data) == 0)
- {
+ 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;
+ }
+ }
- found = 1;
+ if (rc == NGX_ERROR) {
+ return NGX_CONF_ERROR;
+ }
- /* is the directive's location right ? */
-
- if ((cmd->type & cf->cmd_type) == 0) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "directive \"%s\" in %s:%d "
- "is not allowed here",
- name->data,
- cf->conf_file->file.name.data,
- cf->conf_file->line);
- rc = NGX_ERROR;
- break;
- }
+ return NGX_CONF_OK;
+}
- if (!(cmd->type & NGX_CONF_BLOCK) && rc != NGX_OK)
- {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "directive \"%s\" in %s:%d "
- "is not terminated by \";\"",
- name->data,
- cf->conf_file->file.name.data,
- cf->conf_file->line);
- rc = NGX_ERROR;
- break;
- }
- if ((cmd->type & NGX_CONF_BLOCK)
- && rc != NGX_CONF_BLOCK_START)
- {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "directive \"%s\" in %s:%d "
- "has not the opening \"{\"",
- name->data,
- cf->conf_file->file.name.data,
- cf->conf_file->line);
- rc = NGX_ERROR;
- break;
- }
+static ngx_int_t ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last)
+{
+ char *rv;
+ void *conf, **confp;
+ ngx_uint_t i, valid;
+ ngx_str_t *name;
+ ngx_command_t *cmd;
- /* is the directive's argument count right ? */
+ name = cf->args->elts;
- if (cmd->type & NGX_CONF_ANY) {
- valid = 1;
+ for (i = 0; ngx_modules[i]; i++) {
- } else if (cmd->type & NGX_CONF_FLAG) {
+ /* look up the directive in the appropriate modules */
- if (cf->args->nelts == 2) {
- valid = 1;
- } else {
- valid = 0;
- }
+ if (ngx_modules[i]->type != NGX_CONF_MODULE
+ && ngx_modules[i]->type != cf->module_type)
+ {
+ continue;
+ }
- } else if (cmd->type & NGX_CONF_1MORE) {
+ cmd = ngx_modules[i]->commands;
+ if (cmd == NULL) {
+ continue;
+ }
- if (cf->args->nelts > 1) {
- valid = 1;
- } else {
- valid = 0;
- }
+ while (cmd->name.len) {
- } else if (cmd->type & NGX_CONF_2MORE) {
+ if (name->len == cmd->name.len
+ && ngx_strcmp(name->data, cmd->name.data) == 0)
+ {
+ /* is the directive's location right ? */
- if (cf->args->nelts > 2) {
- valid = 1;
- } else {
- valid = 0;
- }
+ if (!(cmd->type & cf->cmd_type)) {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "directive \"%s\" in %s:%d "
+ "is not allowed here",
+ name->data, cf->conf_file->file.name.data,
+ cf->conf_file->line);
+ return NGX_ERROR;
+ }
- } else if (cf->args->nelts <= 10
- && (cmd->type
- & argument_number[cf->args->nelts - 1]))
- {
- valid = 1;
+ if (!(cmd->type & NGX_CONF_BLOCK) && last != NGX_OK) {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "directive \"%s\" in %s:%d "
+ "is not terminated by \";\"",
+ name->data, cf->conf_file->file.name.data,
+ cf->conf_file->line);
+ return NGX_ERROR;
+ }
+
+ if ((cmd->type & NGX_CONF_BLOCK)
+ && last != NGX_CONF_BLOCK_START)
+ {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "directive \"%s\" in %s:%d "
+ "has not the opening \"{\"",
+ name->data, cf->conf_file->file.name.data,
+ cf->conf_file->line);
+ return NGX_ERROR;
+ }
+
+ /* is the directive's argument count right ? */
+ if (cmd->type & NGX_CONF_ANY) {
+ valid = 1;
+
+ } else if (cmd->type & NGX_CONF_FLAG) {
+
+ if (cf->args->nelts == 2) {
+ valid = 1;
} else {
valid = 0;
}
- if (!valid) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "invalid number arguments in "
- "directive \"%s\" in %s:%d",
- name->data,
- cf->conf_file->file.name.data,
- cf->conf_file->line);
- rc = NGX_ERROR;
- break;
+ } else if (cmd->type & NGX_CONF_1MORE) {
+
+ if (cf->args->nelts > 1) {
+ valid = 1;
+ } else {
+ valid = 0;
}
- /* set up the directive's configuration context */
+ } else if (cmd->type & NGX_CONF_2MORE) {
- conf = NULL;
+ if (cf->args->nelts > 2) {
+ valid = 1;
+ } else {
+ valid = 0;
+ }
- if (cmd->type & NGX_DIRECT_CONF) {
- conf = ((void **) cf->ctx)[ngx_modules[m]->index];
+ } else if (cf->args->nelts <= 10
+ && (cmd->type
+ & argument_number[cf->args->nelts - 1]))
+ {
+ valid = 1;
+
+ } else {
+ valid = 0;
+ }
- } else if (cmd->type & NGX_MAIN_CONF) {
- conf = &(((void **) cf->ctx)[ngx_modules[m]->index]);
+ if (!valid) {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "invalid number arguments in "
+ "directive \"%s\" in %s:%d",
+ name->data, cf->conf_file->file.name.data,
+ cf->conf_file->line);
+ return NGX_ERROR;
+ }
- } else if (cf->ctx) {
- confp = *(void **) ((char *) cf->ctx + cmd->conf);
+ /* set up the directive's configuration context */
- if (confp) {
- conf = confp[ngx_modules[m]->ctx_index];
- }
- }
+ conf = NULL;
- rv = cmd->set(cf, cmd, conf);
+ if (cmd->type & NGX_DIRECT_CONF) {
+ conf = ((void **) cf->ctx)[ngx_modules[i]->index];
- if (rv == NGX_CONF_OK) {
- break;
+ } else if (cmd->type & NGX_MAIN_CONF) {
+ conf = &(((void **) cf->ctx)[ngx_modules[i]->index]);
- } else if (rv == NGX_CONF_ERROR) {
- rc = NGX_ERROR;
- break;
+ } else if (cf->ctx) {
+ confp = *(void **) ((char *) cf->ctx + cmd->conf);
- } else {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "the \"%s\" directive %s in %s:%d",
- name->data, rv,
- cf->conf_file->file.name.data,
- cf->conf_file->line);
-
- rc = NGX_ERROR;
- break;
+ if (confp) {
+ conf = confp[ngx_modules[i]->ctx_index];
}
}
- cmd++;
- }
- }
+ rv = cmd->set(cf, cmd, conf);
- if (!found) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "unknown directive \"%s\" in %s:%d",
- name->data,
- cf->conf_file->file.name.data,
- cf->conf_file->line);
+ if (rv == NGX_CONF_OK) {
+ return NGX_OK;
+ }
- rc = NGX_ERROR;
- break;
- }
+ if (rv == NGX_CONF_ERROR) {
+ return NGX_ERROR;
+ }
- if (rc == NGX_ERROR) {
- break;
- }
- }
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "the \"%s\" directive %s in %s:%d",
+ name->data, rv, cf->conf_file->file.name.data,
+ cf->conf_file->line);
- if (filename) {
- cf->conf_file = prev;
+ return NGX_ERROR;
+ }
- 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;
+ cmd++;
}
}
- if (rc == NGX_ERROR) {
- return NGX_CONF_ERROR;
- }
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "unknown directive \"%s\" in %s:%d",
+ name->data, cf->conf_file->file.name.data,
+ cf->conf_file->line);
- return NGX_CONF_OK;
+ return NGX_ERROR;
}
@@ -523,11 +517,13 @@ static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf)
}
if (found) {
- if (!(word = ngx_push_array(cf->args))) {
+ word = ngx_array_push(cf->args);
+ if (word == NULL) {
return NGX_ERROR;
}
- if (!(word->data = ngx_palloc(cf->pool, b->pos - start + 1))) {
+ word->data = ngx_palloc(cf->pool, b->pos - start + 1);
+ if (word->data == NULL) {
return NGX_ERROR;
}
@@ -623,7 +619,8 @@ ngx_int_t ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name)
name->len = cycle->root.len + old.len;
if (cycle->connections) {
- if (!(name->data = ngx_palloc(cycle->pool, name->len + 1))) {
+ name->data = ngx_palloc(cycle->pool, name->len + 1);
+ if (name->data == NULL) {
return NGX_ERROR;
}
@@ -631,7 +628,8 @@ ngx_int_t ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name)
/* the init_cycle */
- if (!(name->data = ngx_alloc(name->len + 1, cycle->log))) {
+ name->data = ngx_alloc(name->len + 1, cycle->log);
+ if (name->data == NULL) {
return NGX_ERROR;
}
}
@@ -686,7 +684,8 @@ ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
}
}
- if (!(file = ngx_list_push(&cycle->open_files))) {
+ file = ngx_list_push(&cycle->open_files);
+ if (file == NULL) {
return NULL;
}
diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c
index e8f06fdfd..4268157bd 100644
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -20,13 +20,15 @@ ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf,
ngx_listening_t *ls;
struct sockaddr_in *sin;
- if (!(ls = ngx_array_push(&cf->cycle->listening))) {
+ ls = ngx_array_push(&cf->cycle->listening);
+ if (ls == NULL) {
return NULL;
}
ngx_memzero(ls, sizeof(ngx_listening_t));
- if (!(sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)))) {
+ sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in));
+ if (sin == NULL) {
return NULL;
}
@@ -46,7 +48,6 @@ ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf,
ls->addr_text.len = ngx_sprintf(ls->addr_text.data + len, ":%d", port)
- ls->addr_text.data;
-
ls->fd = (ngx_socket_t) -1;
ls->family = AF_INET;
ls->type = SOCK_STREAM;
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index ad9049e4e..51864e3f7 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -54,15 +54,18 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
log = old_cycle->log;
- if (!(pool = ngx_create_pool(16 * 1024, log))) {
+ pool = ngx_create_pool(16 * 1024, log);
+ if (pool == NULL) {
return NULL;
}
pool->log = log;
- if (!(cycle = ngx_pcalloc(pool, sizeof(ngx_cycle_t)))) {
+ cycle = ngx_pcalloc(pool, sizeof(ngx_cycle_t));
+ if (cycle == NULL) {
ngx_destroy_pool(pool);
return NULL;
}
+
cycle->pool = pool;
cycle->log = log;
cycle->old_cycle = old_cycle;
@@ -72,10 +75,13 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
n = old_cycle->pathes.nelts ? old_cycle->pathes.nelts : 10;
- if (!(cycle->pathes.elts = ngx_pcalloc(pool, n * sizeof(ngx_path_t *)))) {
+
+ cycle->pathes.elts = ngx_pcalloc(pool, n * sizeof(ngx_path_t *));
+ if (cycle->pathes.elts == NULL) {
ngx_destroy_pool(pool);
return NULL;
}
+
cycle->pathes.nelts = 0;
cycle->pathes.size = sizeof(ngx_path_t *);
cycle->pathes.nalloc = n;
@@ -100,7 +106,8 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
}
- if (!(cycle->new_log = ngx_log_create_errlog(cycle, NULL))) {
+ cycle->new_log = ngx_log_create_errlog(cycle, NULL);
+ if (cycle->new_log == NULL) {
ngx_destroy_pool(pool);
return NULL;
}
@@ -109,11 +116,13 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
n = old_cycle->listening.nelts ? old_cycle->listening.nelts : 10;
+
cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t));
if (cycle->listening.elts == NULL) {
ngx_destroy_pool(pool);
return NULL;
}
+
cycle->listening.nelts = 0;
cycle->listening.size = sizeof(ngx_listening_t);
cycle->listening.nalloc = n;
@@ -147,7 +156,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
ngx_memzero(&conf, sizeof(ngx_conf_t));
/* STUB: init array ? */
- conf.args = ngx_create_array(pool, 10, sizeof(ngx_str_t));
+ conf.args = ngx_array_create(pool, 10, sizeof(ngx_str_t));
if (conf.args == NULL) {
ngx_destroy_pool(pool);
return NULL;
@@ -516,7 +525,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
ngx_temp_pool->log = cycle->log;
- old = ngx_push_array(&ngx_old_cycles);
+ old = ngx_array_push(&ngx_old_cycles);
if (old == NULL) {
exit(1);
}
@@ -562,7 +571,7 @@ ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle)
{
ngx_uint_t trunc;
size_t len;
- u_char *name, pid[NGX_INT64_LEN];
+ u_char pid[NGX_INT64_LEN];
ngx_file_t file;
ngx_core_conf_t *ccf, *old_ccf;
diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c
index 561f080fd..6fe04e70d 100644
--- a/src/core/ngx_file.c
+++ b/src/core/ngx_file.c
@@ -43,7 +43,8 @@ ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path, ngx_pool_t *pool,
file->name.len = path->name.len + 1 + path->len + NGX_ATOMIC_T_LEN;
- if (!(file->name.data = ngx_palloc(pool, file->name.len + 1))) {
+ file->name.data = ngx_palloc(pool, file->name.len + 1);
+ if (file->name.data == NULL) {
return NGX_ERROR;
}
@@ -203,7 +204,8 @@ ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return "is duplicate";
}
- if (!(path = ngx_pcalloc(cf->pool, sizeof(ngx_path_t)))) {
+ path = ngx_pcalloc(cf->pool, sizeof(ngx_path_t));
+ if (path == NULL) {
return NGX_CONF_ERROR;
}
@@ -292,7 +294,8 @@ ngx_add_path(ngx_conf_t *cf, ngx_path_t **slot)
}
}
- if (!(p = ngx_array_push(&cf->cycle->pathes))) {
+ p = ngx_array_push(&cf->cycle->pathes);
+ if (p == NULL) {
return NGX_ERROR;
}
diff --git a/src/core/ngx_file.h b/src/core/ngx_file.h
index c9063c5b4..2bda85886 100644
--- a/src/core/ngx_file.h
+++ b/src/core/ngx_file.h
@@ -70,7 +70,8 @@ char *ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
#define ngx_conf_merge_path_value(curr, prev, path, l1, l2, l3, clean, cf) \
if (curr == NULL) { \
if (prev == NULL) { \
- if (!(curr = ngx_palloc(cf->pool, sizeof(ngx_path_t)))) { \
+ curr = ngx_palloc(cf->pool, sizeof(ngx_path_t)); \
+ if (curr == NULL) { \
return NGX_CONF_ERROR; \
} \
\
diff --git a/src/core/ngx_garbage_collector.c b/src/core/ngx_garbage_collector.c
index ba7d7336f..07a3f7fc5 100644
--- a/src/core/ngx_garbage_collector.c
+++ b/src/core/ngx_garbage_collector.c
@@ -77,7 +77,8 @@ ngx_int_t ngx_collect_garbage(ngx_gc_t *ctx, ngx_str_t *dname, ngx_int_t level)
buf.len = dname->len + 1 + len + NGX_DIR_MASK_LEN;
- if (!(buf.data = ngx_alloc(buf.len + 1, ctx->log))) {
+ buf.data = ngx_alloc(buf.len + 1, ctx->log);
+ if (buf.data == NULL) {
return NGX_ABORT;
}
}
diff --git a/src/core/ngx_inet.c b/src/core/ngx_inet.c
index a30ff035b..6cad053b7 100644
--- a/src/core/ngx_inet.c
+++ b/src/core/ngx_inet.c
@@ -244,7 +244,8 @@ ngx_peers_t *ngx_inet_upstream_parse(ngx_conf_t *cf, ngx_inet_upstream_t *u)
u->port = u->default_port_value;
- if (!(u->port_text.data = ngx_palloc(cf->pool, sizeof("65536") - 1))) {
+ u->port_text.data = ngx_palloc(cf->pool, sizeof("65536") - 1);
+ if (u->port_text.data == NULL) {
return NULL;
}
@@ -271,7 +272,8 @@ ngx_peers_t *ngx_inet_upstream_parse(ngx_conf_t *cf, ngx_inet_upstream_t *u)
u->port = htons(u->port);
- if (!(host = ngx_palloc(cf->pool, u->host.len + 1))) {
+ host = ngx_palloc(cf->pool, u->host.len + 1);
+ if (host == NULL) {
return NULL;
}
@@ -297,7 +299,6 @@ ngx_peers_t *ngx_inet_upstream_parse(ngx_conf_t *cf, ngx_inet_upstream_t *u)
peers = ngx_pcalloc(cf->pool,
sizeof(ngx_peers_t) + sizeof(ngx_peer_t) * (i - 1));
-
if (peers == NULL) {
return NULL;
}
@@ -307,7 +308,8 @@ ngx_peers_t *ngx_inet_upstream_parse(ngx_conf_t *cf, ngx_inet_upstream_t *u)
for (i = 0; h->h_addr_list[i] != NULL; i++) {
- if (!(sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)))) {
+ sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in));
+ if (sin == NULL) {
return NULL;
}
@@ -320,7 +322,8 @@ ngx_peers_t *ngx_inet_upstream_parse(ngx_conf_t *cf, ngx_inet_upstream_t *u)
len = INET_ADDRSTRLEN - 1 + 1 + u->port_text.len;
- if (!(peers->peer[i].name.data = ngx_palloc(cf->pool, len))) {
+ peers->peer[i].name.data = ngx_palloc(cf->pool, len);
+ if (peers->peer[i].name.data == NULL) {
return NULL;
}
@@ -345,11 +348,13 @@ ngx_peers_t *ngx_inet_upstream_parse(ngx_conf_t *cf, ngx_inet_upstream_t *u)
/* MP: ngx_shared_palloc() */
- if (!(peers = ngx_pcalloc(cf->pool, sizeof(ngx_peers_t)))) {
+ peers = ngx_pcalloc(cf->pool, sizeof(ngx_peers_t));
+ if (peers == NULL) {
return NULL;
}
- if (!(sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)))) {
+ sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in));
+ if (sin == NULL) {
return NULL;
}
@@ -366,7 +371,8 @@ ngx_peers_t *ngx_inet_upstream_parse(ngx_conf_t *cf, ngx_inet_upstream_t *u)
peers->peer[0].name.len = len;
- if (!(peers->peer[0].name.data = ngx_palloc(cf->pool, len))) {
+ peers->peer[0].name.data = ngx_palloc(cf->pool, len);
+ if (peers->peer[0].name.data == NULL) {
return NULL;
}
diff --git a/src/core/ngx_list.c b/src/core/ngx_list.c
index 236eff4f9..c082afa37 100644
--- a/src/core/ngx_list.c
+++ b/src/core/ngx_list.c
@@ -19,11 +19,13 @@ void *ngx_list_push(ngx_list_t *l)
/* the last part is full, allocate a new list part */
- if (!(last = ngx_palloc(l->pool, sizeof(ngx_list_part_t)))) {
+ last = ngx_palloc(l->pool, sizeof(ngx_list_part_t));
+ if (last == NULL) {
return NULL;
}
- if (!(last->elts = ngx_palloc(l->pool, l->nalloc * l->size))) {
+ last->elts = ngx_palloc(l->pool, l->nalloc * l->size);
+ if (last->elts == NULL) {
return NULL;
}
diff --git a/src/core/ngx_list.h b/src/core/ngx_list.h
index 2dd8ab37a..c030cf293 100644
--- a/src/core/ngx_list.h
+++ b/src/core/ngx_list.h
@@ -30,10 +30,12 @@ typedef struct {
} ngx_list_t;
-static ngx_inline ngx_int_t ngx_list_init(ngx_list_t *list, ngx_pool_t *pool,
- ngx_uint_t n, size_t size)
+static ngx_inline
+ngx_int_t ngx_list_init(ngx_list_t *list, ngx_pool_t *pool, ngx_uint_t n,
+ size_t size)
{
- if (!(list->part.elts = ngx_palloc(pool, n * size))) {
+ list->part.elts = ngx_palloc(pool, n * size);
+ if (list->part.elts == NULL) {
return NGX_ERROR;
}
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index 5d937f226..adccd5e33 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -253,11 +253,13 @@ ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args)
name = NULL;
}
- if (!(log = ngx_pcalloc(cycle->pool, sizeof(ngx_log_t)))) {
+ log = ngx_pcalloc(cycle->pool, sizeof(ngx_log_t));
+ if (log == NULL) {
return NULL;
}
- if (!(log->file = ngx_conf_open_file(cycle, name))) {
+ log->file = ngx_conf_open_file(cycle, name);
+ if (log->file == NULL) {
return NULL;
}
diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c
index 5f6970f80..313557d8e 100644
--- a/src/core/ngx_output_chain.c
+++ b/src/core/ngx_output_chain.c
@@ -155,7 +155,8 @@ ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in)
}
}
- if (!(ctx->buf = ngx_create_temp_buf(ctx->pool, size))) {
+ ctx->buf = ngx_create_temp_buf(ctx->pool, size);
+ if (ctx->buf == NULL) {
return NGX_ERROR;
}
@@ -186,9 +187,11 @@ ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in)
ctx->in = ctx->in->next;
}
- if (!(cl = ngx_alloc_chain_link(ctx->pool))) {
+ cl = ngx_alloc_chain_link(ctx->pool);
+ if (cl == NULL) {
return NGX_ERROR;
}
+
cl->buf = ctx->buf;
cl->next = NULL;
*last_out = cl;
@@ -269,7 +272,8 @@ ngx_output_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain,
while (in) {
- if (!(cl = ngx_alloc_chain_link(pool))) {
+ cl = ngx_alloc_chain_link(pool);
+ if (cl == NULL) {
return NGX_ERROR;
}
@@ -281,7 +285,8 @@ ngx_output_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain,
&& buf->file_pos < NGX_SENDFILE_LIMIT
&& buf->file_last > NGX_SENDFILE_LIMIT)
{
- if (!(b = ngx_calloc_buf(pool))) {
+ b = ngx_calloc_buf(pool);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -431,9 +436,11 @@ ngx_chain_writer(void *data, ngx_chain_t *in)
ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->connection->log, 0,
"chain writer buf size: %uz", ngx_buf_size(in->buf));
- if (!(cl = ngx_alloc_chain_link(ctx->pool))) {
+ cl = ngx_alloc_chain_link(ctx->pool);
+ if (cl == NULL) {
return NGX_ERROR;
}
+
cl->buf = in->buf;
cl->next = NULL;
*ctx->last = cl;
diff --git a/src/core/ngx_palloc.c b/src/core/ngx_palloc.c
index fc6f36e83..8faf9a77e 100644
--- a/src/core/ngx_palloc.c
+++ b/src/core/ngx_palloc.c
@@ -8,11 +8,13 @@
#include <ngx_core.h>
-ngx_pool_t *ngx_create_pool(size_t size, ngx_log_t *log)
+ngx_pool_t *
+ngx_create_pool(size_t size, ngx_log_t *log)
{
ngx_pool_t *p;
- if (!(p = ngx_alloc(size, log))) {
+ p = ngx_alloc(size, log);
+ if (p == NULL) {
return NULL;
}
@@ -26,7 +28,8 @@ ngx_pool_t *ngx_create_pool(size_t size, ngx_log_t *log)
}
-void ngx_destroy_pool(ngx_pool_t *pool)
+void
+ngx_destroy_pool(ngx_pool_t *pool)
{
ngx_pool_t *p, *n;
ngx_pool_large_t *l;
@@ -68,7 +71,8 @@ void ngx_destroy_pool(ngx_pool_t *pool)
}
-void *ngx_palloc(ngx_pool_t *pool, size_t size)
+void *
+ngx_palloc(ngx_pool_t *pool, size_t size)
{
u_char *m;
ngx_pool_t *p, *n;
@@ -94,7 +98,8 @@ void *ngx_palloc(ngx_pool_t *pool, size_t size)
/* allocate a new pool block */
- if (!(n = ngx_create_pool((size_t) (p->end - (u_char *) p), p->log))) {
+ n = ngx_create_pool((size_t) (p->end - (u_char *) p), p->log);
+ if (n == NULL) {
return NULL;
}
@@ -125,7 +130,8 @@ void *ngx_palloc(ngx_pool_t *pool, size_t size)
}
if (large == NULL) {
- if (!(large = ngx_palloc(pool, sizeof(ngx_pool_large_t)))) {
+ large = ngx_palloc(pool, sizeof(ngx_pool_large_t));
+ if (large == NULL) {
return NULL;
}
@@ -133,11 +139,13 @@ void *ngx_palloc(ngx_pool_t *pool, size_t size)
}
#if 0
- if (!(p = ngx_memalign(ngx_pagesize, size, pool->log))) {
+ p = ngx_memalign(ngx_pagesize, size, pool->log);
+ if (p == NULL) {
return NULL;
}
#else
- if (!(p = ngx_alloc(size, pool->log))) {
+ p = ngx_alloc(size, pool->log);
+ if (p == NULL) {
return NULL;
}
#endif
@@ -155,7 +163,8 @@ void *ngx_palloc(ngx_pool_t *pool, size_t size)
}
-ngx_int_t ngx_pfree(ngx_pool_t *pool, void *p)
+ngx_int_t
+ngx_pfree(ngx_pool_t *pool, void *p)
{
ngx_pool_large_t *l;
@@ -174,7 +183,8 @@ ngx_int_t ngx_pfree(ngx_pool_t *pool, void *p)
}
-void *ngx_pcalloc(ngx_pool_t *pool, size_t size)
+void *
+ngx_pcalloc(ngx_pool_t *pool, size_t size)
{
void *p;
@@ -188,7 +198,8 @@ void *ngx_pcalloc(ngx_pool_t *pool, size_t size)
#if 0
-static void *ngx_get_cached_block(size_t size)
+static void *
+ngx_get_cached_block(size_t size)
{
void *p;
ngx_cached_block_slot_t *slot;
diff --git a/src/core/ngx_palloc.h b/src/core/ngx_palloc.h
index 71be7424e..b31008288 100644
--- a/src/core/ngx_palloc.h
+++ b/src/core/ngx_palloc.h
@@ -21,8 +21,6 @@
#define NGX_DEFAULT_POOL_SIZE (16 * 1024)
-#define ngx_test_null(p, alloc, rc) if ((p = alloc) == NULL) { return rc; }
-
typedef struct ngx_pool_large_s ngx_pool_large_t;
diff --git a/src/core/ngx_radix_tree.c b/src/core/ngx_radix_tree.c
index f8deb21f0..f82a5e5b7 100644
--- a/src/core/ngx_radix_tree.c
+++ b/src/core/ngx_radix_tree.c
@@ -17,7 +17,8 @@ ngx_radix_tree_create(ngx_pool_t *pool, ngx_int_t preallocate)
uint32_t key, mask, inc;
ngx_radix_tree_t *tree;
- if (!(tree = ngx_palloc(pool, sizeof(ngx_radix_tree_t)))) {
+ tree = ngx_palloc(pool, sizeof(ngx_radix_tree_t));
+ if (tree == NULL) {
return NULL;
}
@@ -26,7 +27,8 @@ ngx_radix_tree_create(ngx_pool_t *pool, ngx_int_t preallocate)
tree->start = NULL;
tree->size = 0;
- if (!(tree->root = ngx_radix_alloc(tree))) {
+ tree->root = ngx_radix_alloc(tree);
+ if (tree->root == NULL) {
return NULL;
}
@@ -140,7 +142,8 @@ ngx_radix32tree_insert(ngx_radix_tree_t *tree, uint32_t key, uint32_t mask,
}
while (bit & mask) {
- if (!(next = ngx_radix_alloc(tree))) {
+ next = ngx_radix_alloc(tree);
+ if (next == NULL) {
return NGX_ERROR;
}
@@ -266,7 +269,8 @@ ngx_radix_alloc(ngx_radix_tree_t *tree)
}
if (tree->size < sizeof(ngx_radix_node_t)) {
- if (!(tree->start = ngx_palloc(tree->pool, ngx_pagesize))) {
+ tree->start = ngx_palloc(tree->pool, ngx_pagesize);
+ if (tree->start == NULL) {
return NULL;
}
diff --git a/src/core/ngx_regex.c b/src/core/ngx_regex.c
index bb719a52f..12579946b 100644
--- a/src/core/ngx_regex.c
+++ b/src/core/ngx_regex.c
@@ -79,7 +79,7 @@ ngx_regex_t *ngx_regex_compile(ngx_str_t *pattern, ngx_int_t options,
}
-ngx_uint_t ngx_regex_capture_count(ngx_regex_t *re)
+ngx_int_t ngx_regex_capture_count(ngx_regex_t *re)
{
int rc, n;
@@ -87,7 +87,11 @@ ngx_uint_t ngx_regex_capture_count(ngx_regex_t *re)
rc = pcre_fullinfo(re, NULL, PCRE_INFO_CAPTURECOUNT, &n);
- return (ngx_uint_t) n;
+ if (rc < 0) {
+ return (ngx_int_t) rc;
+ }
+
+ return (ngx_int_t) n;
}
diff --git a/src/core/ngx_regex.h b/src/core/ngx_regex.h
index ff07fc7fb..7eefdbe49 100644
--- a/src/core/ngx_regex.h
+++ b/src/core/ngx_regex.h
@@ -23,11 +23,12 @@ typedef pcre ngx_regex_t;
void ngx_regex_init(void);
ngx_regex_t *ngx_regex_compile(ngx_str_t *pattern, ngx_int_t options,
ngx_pool_t *pool, ngx_str_t *err);
-ngx_uint_t ngx_regex_capture_count(ngx_regex_t *re);
+ngx_int_t ngx_regex_capture_count(ngx_regex_t *re);
ngx_int_t ngx_regex_exec(ngx_regex_t *re, ngx_str_t *s,
int *captures, ngx_int_t size);
-#define ngx_regex_exec_n "pcre_exec()"
+#define ngx_regex_exec_n "pcre_exec()"
+#define ngx_regex_capture_count_n "pcre_fullinfo()"
#endif /* _NGX_REGEX_H_INCLUDED_ */
diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c
index fdb59fd9a..a1f593f96 100644
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -34,7 +34,8 @@ ngx_pstrdup(ngx_pool_t *pool, ngx_str_t *src)
{
u_char *dst;
- if (!(dst = ngx_palloc(pool, src->len))) {
+ dst = ngx_palloc(pool, src->len);
+ if (dst == NULL) {
return NULL;
}
@@ -489,6 +490,84 @@ ngx_atoi(u_char *line, size_t n)
}
+ssize_t
+ngx_atosz(u_char *line, size_t n)
+{
+ ssize_t value;
+
+ if (n == 0) {
+ return NGX_ERROR;
+ }
+
+ for (value = 0; n--; line++) {
+ if (*line < '0' || *line > '9') {
+ return NGX_ERROR;
+ }
+
+ value = value * 10 + (*line - '0');
+ }
+
+ if (value < 0) {
+ return NGX_ERROR;
+
+ } else {
+ return value;
+ }
+}
+
+
+off_t
+ngx_atoof(u_char *line, size_t n)
+{
+ off_t value;
+
+ if (n == 0) {
+ return NGX_ERROR;
+ }
+
+ for (value = 0; n--; line++) {
+ if (*line < '0' || *line > '9') {
+ return NGX_ERROR;
+ }
+
+ value = value * 10 + (*line - '0');
+ }
+
+ if (value < 0) {
+ return NGX_ERROR;
+
+ } else {
+ return value;
+ }
+}
+
+
+time_t
+ngx_atotm(u_char *line, size_t n)
+{
+ time_t value;
+
+ if (n == 0) {
+ return NGX_ERROR;
+ }
+
+ for (value = 0; n--; line++) {
+ if (*line < '0' || *line > '9') {
+ return NGX_ERROR;
+ }
+
+ value = value * 10 + (*line - '0');
+ }
+
+ if (value < 0) {
+ return NGX_ERROR;
+
+ } else {
+ return value;
+ }
+}
+
+
ngx_int_t
ngx_hextoi(u_char *line, size_t n)
{
diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h
index 52bac6a09..25b06b3f6 100644
--- a/src/core/ngx_string.h
+++ b/src/core/ngx_string.h
@@ -23,6 +23,7 @@ typedef struct {
#define ngx_tolower(c) (u_char) ((c >= 'A' && c <= 'Z') ? (c | 0x20) : c)
+#define ngx_toupper(c) (u_char) ((c >= 'a' && c <= 'z') ? (c & ~0x20) : c)
#if (NGX_WIN32)
@@ -81,6 +82,9 @@ ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n);
ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n);
ngx_int_t ngx_atoi(u_char *line, size_t n);
+ssize_t ngx_atosz(u_char *line, size_t n);
+off_t ngx_atoof(u_char *line, size_t n);
+time_t ngx_atotm(u_char *line, size_t n);
ngx_int_t ngx_hextoi(u_char *line, size_t n);
void ngx_md5_text(u_char *text, u_char *md5);
diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c
index 42932892e..e4fa69d7f 100644
--- a/src/core/ngx_times.c
+++ b/src/core/ngx_times.c
@@ -70,8 +70,8 @@ static char *week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
-
-void ngx_time_init(void)
+void
+ngx_time_init(void)
{
struct timeval tv;
@@ -104,9 +104,12 @@ void ngx_time_init(void)
#if (NGX_THREADS)
-ngx_int_t ngx_time_mutex_init(ngx_log_t *log)
+ngx_int_t
+ngx_time_mutex_init(ngx_log_t *log)
{
- if (!(ngx_time_mutex = ngx_mutex_init(log, NGX_MUTEX_LIGHT))) {
+ ngx_time_mutex = ngx_mutex_init(log, NGX_MUTEX_LIGHT);
+
+ if (ngx_time_mutex == NULL) {
return NGX_ERROR;
}
@@ -116,7 +119,8 @@ ngx_int_t ngx_time_mutex_init(ngx_log_t *log)
#endif
-void ngx_time_update(time_t s)
+void
+ngx_time_update(time_t s)
{
u_char *p;
ngx_tm_t tm;
@@ -209,7 +213,8 @@ void ngx_time_update(time_t s)
}
-u_char *ngx_http_time(u_char *buf, time_t t)
+u_char *
+ngx_http_time(u_char *buf, time_t t)
{
ngx_tm_t tm;
@@ -226,7 +231,8 @@ u_char *ngx_http_time(u_char *buf, time_t t)
}
-u_char *ngx_http_cookie_time(u_char *buf, time_t t)
+u_char *
+ngx_http_cookie_time(u_char *buf, time_t t)
{
ngx_tm_t tm;
@@ -252,7 +258,8 @@ u_char *ngx_http_cookie_time(u_char *buf, time_t t)
}
-void ngx_gmtime(time_t t, ngx_tm_t *tp)
+void
+ngx_gmtime(time_t t, ngx_tm_t *tp)
{
ngx_int_t sec, min, hour, mday, mon, year, wday, yday, days;
diff --git a/src/core/ngx_unix_domain.c b/src/core/ngx_unix_domain.c
index 436777f8f..3df83bb3e 100644
--- a/src/core/ngx_unix_domain.c
+++ b/src/core/ngx_unix_domain.c
@@ -59,11 +59,13 @@ ngx_peers_t *ngx_unix_upstream_parse(ngx_conf_t *cf,
/* MP: ngx_shared_palloc() */
- if (!(peers = ngx_pcalloc(cf->pool, sizeof(ngx_peers_t)))) {
+ peers = ngx_pcalloc(cf->pool, sizeof(ngx_peers_t));
+ if (peers == NULL) {
return NULL;
}
- if (!(sun = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_un)))) {
+ sun = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_un));
+ if (sun == NULL) {
return NULL;
}
diff --git a/src/event/modules/ngx_devpoll_module.c b/src/event/modules/ngx_devpoll_module.c
index 2d94ba477..57b6b1239 100644
--- a/src/event/modules/ngx_devpoll_module.c
+++ b/src/event/modules/ngx_devpoll_module.c
@@ -134,19 +134,21 @@ ngx_devpoll_init(ngx_cycle_t *cycle)
ngx_free(change_list);
}
- ngx_test_null(change_list,
- ngx_alloc(sizeof(struct pollfd) * dpcf->changes,
- cycle->log),
- NGX_ERROR);
+ change_list = ngx_alloc(sizeof(struct pollfd) * dpcf->changes,
+ cycle->log);
+ if (change_list == NULL) {
+ return NGX_ERROR;
+ }
if (change_index) {
ngx_free(change_index);
}
- ngx_test_null(change_index,
- ngx_alloc(sizeof(ngx_event_t *) * dpcf->changes,
- cycle->log),
- NGX_ERROR);
+ change_index = ngx_alloc(sizeof(ngx_event_t *) * dpcf->changes,
+ cycle->log);
+ if (change_index == NULL) {
+ return NGX_ERROR;
+ }
}
max_changes = dpcf->changes;
@@ -156,10 +158,11 @@ ngx_devpoll_init(ngx_cycle_t *cycle)
ngx_free(event_list);
}
- ngx_test_null(event_list,
- ngx_alloc(sizeof(struct pollfd) * dpcf->events,
- cycle->log),
- NGX_ERROR);
+ event_list = ngx_alloc(sizeof(struct pollfd) * dpcf->events,
+ cycle->log);
+ if (event_list == NULL) {
+ return NGX_ERROR;
+ }
}
nevents = dpcf->events;
@@ -318,11 +321,13 @@ ngx_devpoll_process_events(ngx_cycle_t *cycle)
{
int events, revents;
ngx_int_t i;
- ngx_uint_t j, lock, accept_lock, expire;
+ ngx_uint_t lock, accept_lock, expire;
size_t n;
ngx_msec_t timer;
ngx_err_t err;
+#if 0
ngx_cycle_t **old_cycle;
+#endif
ngx_event_t *rev, *wev;
ngx_connection_t *c;
ngx_epoch_msec_t delta;
@@ -580,8 +585,10 @@ ngx_devpoll_create_conf(ngx_cycle_t *cycle)
{
ngx_devpoll_conf_t *dpcf;
- ngx_test_null(dpcf, ngx_palloc(cycle->pool, sizeof(ngx_devpoll_conf_t)),
- NGX_CONF_ERROR);
+ dpcf = ngx_palloc(cycle->pool, sizeof(ngx_devpoll_conf_t));
+ if (dpcf == NULL) {
+ return NGX_CONF_ERROR;
+ }
dpcf->changes = NGX_CONF_UNSET;
dpcf->events = NGX_CONF_UNSET;
diff --git a/src/event/modules/ngx_epoll_module.c b/src/event/modules/ngx_epoll_module.c
index f2c973f24..14b77508c 100644
--- a/src/event/modules/ngx_epoll_module.c
+++ b/src/event/modules/ngx_epoll_module.c
@@ -133,7 +133,6 @@ ngx_module_t ngx_epoll_module = {
static ngx_int_t
ngx_epoll_init(ngx_cycle_t *cycle)
{
- size_t n;
ngx_event_conf_t *ecf;
ngx_epoll_conf_t *epcf;
@@ -380,7 +379,6 @@ static ngx_int_t
ngx_epoll_process_events(ngx_cycle_t *cycle)
{
int events;
- size_t n;
uint32_t revents;
ngx_int_t instance, i;
ngx_uint_t lock, accept_lock, expire;
@@ -663,8 +661,10 @@ ngx_epoll_create_conf(ngx_cycle_t *cycle)
{
ngx_epoll_conf_t *epcf;
- ngx_test_null(epcf, ngx_palloc(cycle->pool, sizeof(ngx_epoll_conf_t)),
- NGX_CONF_ERROR);
+ epcf = ngx_palloc(cycle->pool, sizeof(ngx_epoll_conf_t));
+ if (epcf == NULL) {
+ return NGX_CONF_ERROR;
+ }
epcf->events = NGX_CONF_UNSET;
diff --git a/src/event/modules/ngx_iocp_module.c b/src/event/modules/ngx_iocp_module.c
index 4a3cd9fe9..0a04a209a 100644
--- a/src/event/modules/ngx_iocp_module.c
+++ b/src/event/modules/ngx_iocp_module.c
@@ -90,7 +90,8 @@ ngx_os_io_t ngx_iocp_io = {
static HANDLE iocp;
-static ngx_int_t ngx_iocp_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_iocp_init(ngx_cycle_t *cycle)
{
ngx_iocp_conf_t *cf;
@@ -117,7 +118,8 @@ static ngx_int_t ngx_iocp_init(ngx_cycle_t *cycle)
}
-static void ngx_iocp_done(ngx_cycle_t *cycle)
+static void
+ngx_iocp_done(ngx_cycle_t *cycle)
{
if (CloseHandle(iocp) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
@@ -128,7 +130,8 @@ static void ngx_iocp_done(ngx_cycle_t *cycle)
}
-static ngx_int_t ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key)
+static ngx_int_t
+ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key)
{
ngx_connection_t *c;
@@ -150,7 +153,8 @@ static ngx_int_t ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key)
}
-static ngx_int_t ngx_iocp_del_connection(ngx_connection_t *c, u_int flags)
+static ngx_int_t
+ngx_iocp_del_connection(ngx_connection_t *c, u_int flags)
{
#if 0
if (flags & NGX_CLOSE_EVENT) {
@@ -167,7 +171,8 @@ static ngx_int_t ngx_iocp_del_connection(ngx_connection_t *c, u_int flags)
}
-static ngx_int_t ngx_iocp_process_events(ngx_cycle_t *cycle)
+static
+ngx_int_t ngx_iocp_process_events(ngx_cycle_t *cycle)
{
int rc;
u_int key;
@@ -301,12 +306,15 @@ static ngx_int_t ngx_iocp_process_events(ngx_cycle_t *cycle)
}
-static void *ngx_iocp_create_conf(ngx_cycle_t *cycle)
+static void *
+ngx_iocp_create_conf(ngx_cycle_t *cycle)
{
ngx_iocp_conf_t *cf;
- ngx_test_null(cf, ngx_palloc(cycle->pool, sizeof(ngx_iocp_conf_t)),
- NGX_CONF_ERROR);
+ cf = ngx_palloc(cycle->pool, sizeof(ngx_iocp_conf_t));
+ if (cf == NULL) {
+ return NGX_CONF_ERROR;
+ }
cf->threads = NGX_CONF_UNSET;
cf->post_acceptex = NGX_CONF_UNSET;
@@ -316,7 +324,8 @@ static void *ngx_iocp_create_conf(ngx_cycle_t *cycle)
}
-static char *ngx_iocp_init_conf(ngx_cycle_t *cycle, void *conf)
+static char *
+ngx_iocp_init_conf(ngx_cycle_t *cycle, void *conf)
{
ngx_iocp_conf_t *cf = conf;
diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c
index b4555d983..14bbfaf27 100644
--- a/src/event/modules/ngx_kqueue_module.c
+++ b/src/event/modules/ngx_kqueue_module.c
@@ -123,11 +123,13 @@ ngx_kqueue_init(ngx_cycle_t *cycle)
#if (NGX_THREADS)
- if (!(list_mutex = ngx_mutex_init(cycle->log, 0))) {
+ list_mutex = ngx_mutex_init(cycle->log, 0);
+ if (list_mutex == NULL) {
return NGX_ERROR;
}
- if (!(kevent_mutex = ngx_mutex_init(cycle->log, 0))) {
+ kevent_mutex = ngx_mutex_init(cycle->log, 0);
+ if (kevent_mutex == NULL) {
return NGX_ERROR;
}
@@ -797,8 +799,10 @@ ngx_kqueue_create_conf(ngx_cycle_t *cycle)
{
ngx_kqueue_conf_t *kcf;
- ngx_test_null(kcf, ngx_palloc(cycle->pool, sizeof(ngx_kqueue_conf_t)),
- NGX_CONF_ERROR);
+ kcf = ngx_palloc(cycle->pool, sizeof(ngx_kqueue_conf_t));
+ if (kcf == NULL) {
+ return NGX_CONF_ERROR;
+ }
kcf->changes = NGX_CONF_UNSET;
kcf->events = NGX_CONF_UNSET;
diff --git a/src/event/modules/ngx_poll_module.c b/src/event/modules/ngx_poll_module.c
index 6ea3af4e4..c25a5611c 100644
--- a/src/event/modules/ngx_poll_module.c
+++ b/src/event/modules/ngx_poll_module.c
@@ -73,10 +73,11 @@ ngx_poll_init(ngx_cycle_t *cycle)
|| cycle->old_cycle == NULL
|| cycle->old_cycle->connection_n < cycle->connection_n)
{
- ngx_test_null(list,
- ngx_alloc(sizeof(struct pollfd) * cycle->connection_n,
- cycle->log),
- NGX_ERROR);
+ list = ngx_alloc(sizeof(struct pollfd) * cycle->connection_n,
+ cycle->log);
+ if (list == NULL) {
+ return NGX_ERROR;
+ }
if (event_list) {
ngx_memcpy(list, event_list, sizeof(ngx_event_t *) * nevents);
@@ -90,10 +91,11 @@ ngx_poll_init(ngx_cycle_t *cycle)
ngx_free(ready_index);
}
- ngx_test_null(ready_index,
- ngx_alloc(sizeof(ngx_event_t *) * 2 * cycle->connection_n,
- cycle->log),
- NGX_ERROR);
+ ready_index = ngx_alloc(sizeof(ngx_event_t *) * 2 * cycle->connection_n,
+ cycle->log);
+ if (ready_index == NULL) {
+ return NGX_ERROR;
+ }
#endif
}
diff --git a/src/event/modules/ngx_rtsig_module.c b/src/event/modules/ngx_rtsig_module.c
index 07b8bd9d6..6c94977db 100644
--- a/src/event/modules/ngx_rtsig_module.c
+++ b/src/event/modules/ngx_rtsig_module.c
@@ -274,9 +274,8 @@ static ngx_int_t
ngx_rtsig_process_events(ngx_cycle_t *cycle)
{
int signo;
- ngx_int_t instance, i;
+ ngx_int_t instance;
ngx_uint_t expire;
- size_t n;
ngx_msec_t timer;
ngx_err_t err;
siginfo_t si;
@@ -777,8 +776,10 @@ ngx_rtsig_create_conf(ngx_cycle_t *cycle)
{
ngx_rtsig_conf_t *rtscf;
- ngx_test_null(rtscf, ngx_palloc(cycle->pool, sizeof(ngx_rtsig_conf_t)),
- NGX_CONF_ERROR);
+ rtscf = ngx_palloc(cycle->pool, sizeof(ngx_rtsig_conf_t));
+ if (rtscf == NULL) {
+ return NGX_CONF_ERROR;
+ }
rtscf->signo = NGX_CONF_UNSET;
rtscf->overflow_events = NGX_CONF_UNSET;
diff --git a/src/event/modules/ngx_select_module.c b/src/event/modules/ngx_select_module.c
index 623e13c16..6edc2840a 100644
--- a/src/event/modules/ngx_select_module.c
+++ b/src/event/modules/ngx_select_module.c
@@ -72,7 +72,8 @@ ngx_module_t ngx_select_module = {
};
-static ngx_int_t ngx_select_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_select_init(ngx_cycle_t *cycle)
{
ngx_event_t **index;
@@ -86,10 +87,11 @@ static ngx_int_t ngx_select_init(ngx_cycle_t *cycle)
|| cycle->old_cycle == NULL
|| cycle->old_cycle->connection_n < cycle->connection_n)
{
- ngx_test_null(index,
- ngx_alloc(sizeof(ngx_event_t *) * 2 * cycle->connection_n,
- cycle->log),
- NGX_ERROR);
+ index = ngx_alloc(sizeof(ngx_event_t *) * 2 * cycle->connection_n,
+ cycle->log);
+ if (index == NULL) {
+ return NGX_ERROR;
+ }
if (event_index) {
ngx_memcpy(index, event_index, sizeof(ngx_event_t *) * nevents);
@@ -101,10 +103,12 @@ static ngx_int_t ngx_select_init(ngx_cycle_t *cycle)
if (ready_index) {
ngx_free(ready_index);
}
- ngx_test_null(ready_index,
- ngx_alloc(sizeof(ngx_event_t *) * 2 * cycle->connection_n,
- cycle->log),
- NGX_ERROR);
+
+ ready_index = ngx_alloc(sizeof(ngx_event_t *) * 2 * cycle->connection_n,
+ cycle->log);
+ if (ready_index == NULL) {
+ return NGX_ERROR;
+ }
#endif
}
@@ -124,7 +128,8 @@ static ngx_int_t ngx_select_init(ngx_cycle_t *cycle)
}
-static void ngx_select_done(ngx_cycle_t *cycle)
+static void
+ngx_select_done(ngx_cycle_t *cycle)
{
ngx_free(event_index);
#if 0
@@ -135,7 +140,8 @@ static void ngx_select_done(ngx_cycle_t *cycle)
}
-static ngx_int_t ngx_select_add_event(ngx_event_t *ev, int event, u_int flags)
+static ngx_int_t
+ngx_select_add_event(ngx_event_t *ev, int event, u_int flags)
{
ngx_connection_t *c;
@@ -196,7 +202,8 @@ static ngx_int_t ngx_select_add_event(ngx_event_t *ev, int event, u_int flags)
}
-static ngx_int_t ngx_select_del_event(ngx_event_t *ev, int event, u_int flags)
+static ngx_int_t
+ngx_select_del_event(ngx_event_t *ev, int event, u_int flags)
{
ngx_connection_t *c;
@@ -248,7 +255,8 @@ static ngx_int_t ngx_select_del_event(ngx_event_t *ev, int event, u_int flags)
}
-static ngx_int_t ngx_select_process_events(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_select_process_events(ngx_cycle_t *cycle)
{
int ready, nready;
ngx_uint_t i, found, lock, expire;
@@ -592,7 +600,8 @@ static ngx_int_t ngx_select_process_events(ngx_cycle_t *cycle)
}
-static char *ngx_select_init_conf(ngx_cycle_t *cycle, void *conf)
+static char *
+ngx_select_init_conf(ngx_cycle_t *cycle, void *conf)
{
ngx_event_conf_t *ecf;
diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c
index 5a002c001..371c5c706 100644
--- a/src/event/ngx_event.c
+++ b/src/event/ngx_event.c
@@ -219,7 +219,8 @@ static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle)
#endif
- if (!(shared = ngx_create_shared_memory(size, cycle->log))) {
+ shared = ngx_create_shared_memory(size, cycle->log);
+ if (shared == NULL) {
return NGX_ERROR;
}
@@ -272,7 +273,8 @@ static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle)
}
#if (NGX_THREADS)
- if (!(ngx_posted_events_mutex = ngx_mutex_init(cycle->log, 0))) {
+ ngx_posted_events_mutex = ngx_mutex_init(cycle->log, 0);
+ if (ngx_posted_events_mutex == NULL) {
return NGX_ERROR;
}
#endif
@@ -497,42 +499,47 @@ ngx_int_t ngx_send_lowat(ngx_connection_t *c, size_t lowat)
static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
- int m;
- char *rv;
+ char *rv;
void ***ctx;
+ ngx_uint_t i;
ngx_conf_t pcf;
- ngx_event_module_t *module;
+ ngx_event_module_t *m;
/* count the number of the event modules and set up their indices */
ngx_event_max_module = 0;
- for (m = 0; ngx_modules[m]; m++) {
- if (ngx_modules[m]->type != NGX_EVENT_MODULE) {
+ for (i = 0; ngx_modules[i]; i++) {
+ if (ngx_modules[i]->type != NGX_EVENT_MODULE) {
continue;
}
- ngx_modules[m]->ctx_index = ngx_event_max_module++;
+ ngx_modules[i]->ctx_index = ngx_event_max_module++;
}
- ngx_test_null(ctx, ngx_pcalloc(cf->pool, sizeof(void *)), NGX_CONF_ERROR);
+ ctx = ngx_pcalloc(cf->pool, sizeof(void *));
+ if (ctx == NULL) {
+ return NGX_CONF_ERROR;
+ }
- ngx_test_null(*ctx,
- ngx_pcalloc(cf->pool, ngx_event_max_module * sizeof(void *)),
- NGX_CONF_ERROR);
+ *ctx = ngx_pcalloc(cf->pool, ngx_event_max_module * sizeof(void *));
+ if (*ctx == NULL) {
+ return NGX_CONF_ERROR;
+ }
*(void **) conf = ctx;
- for (m = 0; ngx_modules[m]; m++) {
- if (ngx_modules[m]->type != NGX_EVENT_MODULE) {
+ for (i = 0; ngx_modules[i]; i++) {
+ if (ngx_modules[i]->type != NGX_EVENT_MODULE) {
continue;
}
- module = ngx_modules[m]->ctx;
+ m = ngx_modules[i]->ctx;
- if (module->create_conf) {
- ngx_test_null((*ctx)[ngx_modules[m]->ctx_index],
- module->create_conf(cf->cycle),
- NGX_CONF_ERROR);
+ if (m->create_conf) {
+ (*ctx)[ngx_modules[i]->ctx_index] = m->create_conf(cf->cycle);
+ if ((*ctx)[ngx_modules[i]->ctx_index] == NULL) {
+ return NGX_CONF_ERROR;
+ }
}
}
@@ -540,22 +547,23 @@ static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
cf->ctx = ctx;
cf->module_type = NGX_EVENT_MODULE;
cf->cmd_type = NGX_EVENT_CONF;
+
rv = ngx_conf_parse(cf, NULL);
+
*cf = pcf;
if (rv != NGX_CONF_OK)
return rv;
- for (m = 0; ngx_modules[m]; m++) {
- if (ngx_modules[m]->type != NGX_EVENT_MODULE) {
+ for (i = 0; ngx_modules[i]; i++) {
+ if (ngx_modules[i]->type != NGX_EVENT_MODULE) {
continue;
}
- module = ngx_modules[m]->ctx;
+ m = ngx_modules[i]->ctx;
- if (module->init_conf) {
- rv = module->init_conf(cf->cycle,
- (*ctx)[ngx_modules[m]->ctx_index]);
+ if (m->init_conf) {
+ rv = m->init_conf(cf->cycle, (*ctx)[ngx_modules[i]->ctx_index]);
if (rv != NGX_CONF_OK) {
return rv;
}
@@ -668,7 +676,8 @@ static char *ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd,
/* AF_INET only */
- if (!(addr = ngx_push_array(&ecf->debug_connection))) {
+ addr = ngx_array_push(&ecf->debug_connection);
+ if (addr == NULL) {
return NGX_CONF_ERROR;
}
@@ -704,8 +713,10 @@ static void *ngx_event_create_conf(ngx_cycle_t *cycle)
{
ngx_event_conf_t *ecf;
- ngx_test_null(ecf, ngx_palloc(cycle->pool, sizeof(ngx_event_conf_t)),
- NGX_CONF_ERROR);
+ ecf = ngx_palloc(cycle->pool, sizeof(ngx_event_conf_t));
+ if (ecf == NULL) {
+ return NGX_CONF_ERROR;
+ }
ecf->connections = NGX_CONF_UNSET_UINT;
ecf->use = NGX_CONF_UNSET_UINT;
@@ -715,8 +726,13 @@ static void *ngx_event_create_conf(ngx_cycle_t *cycle)
ecf->name = (void *) NGX_CONF_UNSET;
#if (NGX_DEBUG)
- ngx_init_array(ecf->debug_connection, cycle->pool, 4, sizeof(in_addr_t),
- NGX_CONF_ERROR);
+
+ if (ngx_array_init(&ecf->debug_connection, cycle->pool, 4,
+ sizeof(in_addr_t)) == NGX_ERROR)
+ {
+ return NGX_CONF_ERROR;
+ }
+
#endif
return ecf;
@@ -727,7 +743,12 @@ static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
{
ngx_event_conf_t *ecf = conf;
- int fd, rtsig;
+#if (NGX_HAVE_EPOLL) && !(NGX_TEST_BUILD_EPOLL)
+ int fd;
+#endif
+#if (NGX_HAVE_RTSIG)
+ ngx_uint_t rtsig;
+#endif
ngx_int_t i, connections;
ngx_module_t *module;
ngx_core_conf_t *ccf;
@@ -735,8 +756,6 @@ static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
connections = NGX_CONF_UNSET_UINT;
module = NULL;
- rtsig = 0;
- fd = 0;
#if (NGX_HAVE_EPOLL) && !(NGX_TEST_BUILD_EPOLL)
@@ -760,6 +779,9 @@ static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
connections = DEFAULT_CONNECTIONS;
module = &ngx_rtsig_module;
rtsig = 1;
+
+ } else {
+ rtsig = 0;
}
#endif
@@ -782,11 +804,10 @@ static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
if (module == NULL) {
-#if (NGX_WIN32)
+#if (NGX_WIN32 || FD_SETSIZE >= DEFAULT_CONNECTIONS)
connections = DEFAULT_CONNECTIONS;
#else
- connections = FD_SETSIZE < DEFAULT_CONNECTIONS ? FD_SETSIZE:
- DEFAULT_CONNECTIONS;
+ connections = FD_SETSIZE;
#endif
module = &ngx_select_module;
}
@@ -828,7 +849,15 @@ static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
ngx_conf_init_msec_value(ecf->accept_mutex_delay, 500);
- if (!rtsig || ecf->accept_mutex) {
+#if (NGX_HAVE_RTSIG)
+
+ if (!rtsig) {
+ return NGX_CONF_OK;
+ }
+
+#endif
+
+ if (ecf->accept_mutex) {
return NGX_CONF_OK;
}
diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c
index f30e1fcc3..8e2a1ea9a 100644
--- a/src/event/ngx_event_accept.c
+++ b/src/event/ngx_event_accept.c
@@ -16,7 +16,10 @@ static u_char *ngx_accept_log_error(ngx_log_t *log, u_char *buf, size_t len);
void
ngx_event_accept(ngx_event_t *ev)
{
- ngx_uint_t instance, accepted;
+ ngx_uint_t instance;
+#if 0
+ ngx_uint_t accepted;
+#endif
socklen_t len;
struct sockaddr *sa;
ngx_err_t err;
@@ -43,8 +46,10 @@ ngx_event_accept(ngx_event_t *ev)
&ls->listening->addr_text, ev->available);
ev->ready = 0;
- accepted = 0;
pool = NULL;
+#if 0
+ accepted = 0;
+#endif
do {
@@ -56,17 +61,20 @@ ngx_event_accept(ngx_event_t *ev)
* case and besides the pool can be got from the free pool list.
*/
- if (!(pool = ngx_create_pool(ls->listening->pool_size, ev->log))) {
+ pool = ngx_create_pool(ls->listening->pool_size, ev->log);
+ if (pool == NULL) {
return;
}
}
- if (!(sa = ngx_palloc(pool, ls->listening->socklen))) {
+ sa = ngx_palloc(pool, ls->listening->socklen);
+ if (sa == NULL) {
ngx_destroy_pool(pool);
return;
}
- if (!(log = ngx_palloc(pool, sizeof(ngx_log_t)))) {
+ log = ngx_palloc(pool, sizeof(ngx_log_t));
+ if (log == NULL) {
ngx_destroy_pool(pool);
return;
}
@@ -331,7 +339,9 @@ ngx_event_accept(ngx_event_t *ev)
ev->available--;
}
+#if 0
accepted++;
+#endif
} while (ev->available);
}
diff --git a/src/event/ngx_event_acceptex.c b/src/event/ngx_event_acceptex.c
index d01dbf122..b02dfd0d5 100644
--- a/src/event/ngx_event_acceptex.c
+++ b/src/event/ngx_event_acceptex.c
@@ -153,7 +153,8 @@ int ngx_event_post_acceptex(ngx_listening_t *ls, int n)
c->recv = ngx_recv;
c->send_chain = ngx_send_chain;
- if (!(c->pool = ngx_create_pool(ls->pool_size, ls->log))) {
+ c->pool = ngx_create_pool(ls->pool_size, ls->log);
+ if (c->pool == NULL) {
return NGX_ERROR;
}
@@ -164,15 +165,18 @@ int ngx_event_post_acceptex(ngx_listening_t *ls, int n)
return NGX_ERROR;
}
- if (!(c->local_sockaddr = ngx_palloc(c->pool, ls->socklen))) {
+ c->local_sockaddr = ngx_palloc(c->pool, ls->socklen);
+ if (c->local_sockaddr == NULL) {
return NGX_ERROR;
}
- if (!(c->sockaddr = ngx_palloc(c->pool, ls->socklen))) {
+ c->sockaddr = ngx_palloc(c->pool, ls->socklen);
+ if (c->sockaddr == NULL) {
return NGX_ERROR;
}
- if (!(c->log = ngx_palloc(c->pool, sizeof(ngx_log_t)))) {
+ c->log = ngx_palloc(c->pool, sizeof(ngx_log_t));
+ if (c->log == NULL) {
return NGX_ERROR;
}
diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
index b65779088..d213eb158 100644
--- a/src/event/ngx_event_openssl.c
+++ b/src/event/ngx_event_openssl.c
@@ -20,8 +20,6 @@ static void ngx_ssl_read_handler(ngx_event_t *rev);
ngx_int_t
ngx_ssl_init(ngx_log_t *log)
{
- ENGINE *engine;
-
SSL_library_init();
SSL_load_error_strings();
ENGINE_load_builtin_engines();
@@ -36,11 +34,13 @@ ngx_ssl_create_session(ngx_ssl_ctx_t *ssl_ctx, ngx_connection_t *c,
{
ngx_ssl_t *ssl;
- if (!(ssl = ngx_pcalloc(c->pool, sizeof(ngx_ssl_t)))) {
+ ssl = ngx_pcalloc(c->pool, sizeof(ngx_ssl_t));
+ if (ssl == NULL) {
return NGX_ERROR;
}
- if (!(ssl->buf = ngx_create_temp_buf(c->pool, NGX_SSL_BUFSIZE))) {
+ ssl->buf = ngx_create_temp_buf(c->pool, NGX_SSL_BUFSIZE);
+ if (ssl->buf == NULL) {
return NGX_ERROR;
}
@@ -586,7 +586,7 @@ ngx_ssl_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, char *fmt, ...)
p = ngx_vsnprintf(errstr, sizeof(errstr) - 1, fmt, args);
va_end(args);
- p = ngx_cpystrn(p, " (SSL: ", last - p);
+ p = ngx_cpystrn(p, (u_char *) " (SSL: ", last - p);
ERR_error_string_n(ERR_get_error(), (char *) p, last - p);
diff --git a/src/event/ngx_event_pipe.c b/src/event/ngx_event_pipe.c
index 0206bf8fe..b5488ba7d 100644
--- a/src/event/ngx_event_pipe.c
+++ b/src/event/ngx_event_pipe.c
@@ -165,13 +165,15 @@ static ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p)
/* allocate a new buf if it's still allowed */
- if (!(b = ngx_create_temp_buf(p->pool, p->bufs.size))) {
+ b = ngx_create_temp_buf(p->pool, p->bufs.size);
+ if (b == NULL) {
return NGX_ABORT;
}
p->allocated++;
- if (!(chain = ngx_alloc_chain_link(p->pool))) {
+ chain = ngx_alloc_chain_link(p->pool);
+ if (chain == NULL) {
return NGX_ABORT;
}
@@ -495,7 +497,13 @@ static ngx_int_t ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p)
}
cl->next = NULL;
- ngx_chain_add_link(out, ll, cl);
+
+ if (out) {
+ *ll = cl;
+ } else {
+ out = cl;
+ }
+ ll = &cl->next;
}
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0,
@@ -635,11 +643,17 @@ static ngx_int_t ngx_event_pipe_write_chain_to_temp_file(ngx_event_pipe_t *p)
b->in_file = 1;
b->temp_file = 1;
- ngx_chain_add_link(p->out, p->last_out, cl);
+ if (p->out) {
+ *p->last_out = cl;
+ } else {
+ p->out = cl;
+ }
+ p->last_out = &cl->next;
if (b->last_shadow) {
- if (!(tl = ngx_alloc_chain_link(p->pool))) {
+ tl = ngx_alloc_chain_link(p->pool);
+ if (tl == NULL) {
return NGX_ABORT;
}
@@ -676,7 +690,8 @@ ngx_int_t ngx_event_pipe_copy_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
p->free = p->free->next;
} else {
- if (!(b = ngx_alloc_buf(p->pool))) {
+ b = ngx_alloc_buf(p->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
}
@@ -688,7 +703,8 @@ ngx_int_t ngx_event_pipe_copy_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
b->recycled = 1;
buf->shadow = b;
- if (!(cl = ngx_alloc_chain_link(p->pool))) {
+ cl = ngx_alloc_chain_link(p->pool);
+ if (cl == NULL) {
return NGX_ERROR;
}
@@ -697,7 +713,12 @@ ngx_int_t ngx_event_pipe_copy_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "input buf #%d", b->num);
- ngx_chain_add_link(p->in, p->last_in, cl);
+ if (p->in) {
+ *p->last_in = cl;
+ } else {
+ p->in = cl;
+ }
+ p->last_in = &cl->next;
return NGX_OK;
}
@@ -766,7 +787,8 @@ ngx_int_t ngx_event_pipe_add_free_buf(ngx_event_pipe_t *p, ngx_buf_t *b)
{
ngx_chain_t *cl;
- if (!(cl = ngx_alloc_chain_link(p->pool))) {
+ cl = ngx_alloc_chain_link(p->pool);
+ if (cl == NULL) {
return NGX_ERROR;
}
diff --git a/src/event/ngx_event_posted.c b/src/event/ngx_event_posted.c
index a99a434cb..8050c326f 100644
--- a/src/event/ngx_event_posted.c
+++ b/src/event/ngx_event_posted.c
@@ -43,10 +43,10 @@ void ngx_event_process_posted(ngx_cycle_t *cycle)
void ngx_wakeup_worker_thread(ngx_cycle_t *cycle)
{
ngx_int_t i;
+#if 0
ngx_uint_t busy;
ngx_event_t *ev;
-#if 0
busy = 1;
if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
diff --git a/src/event/ngx_event_timer.c b/src/event/ngx_event_timer.c
index 4b9865650..7655c4fd8 100644
--- a/src/event/ngx_event_timer.c
+++ b/src/event/ngx_event_timer.c
@@ -31,7 +31,8 @@ ngx_event_timer_init(ngx_log_t *log)
ngx_event_timer_rbtree = &ngx_event_timer_sentinel;
#if (NGX_THREADS)
- if (!(ngx_event_timer_mutex = ngx_mutex_init(log, 0))) {
+ ngx_event_timer_mutex = ngx_mutex_init(log, 0);
+ if (ngx_event_timer_mutex == NULL) {
return NGX_ERROR;
}
#endif
diff --git a/src/event/ngx_event_timer.h b/src/event/ngx_event_timer.h
index edbfcf604..4954809e7 100644
--- a/src/event/ngx_event_timer.h
+++ b/src/event/ngx_event_timer.h
@@ -13,8 +13,8 @@
#include <ngx_event.h>
-#define NGX_TIMER_INFINITE -1
-#define NGX_TIMER_ERROR -2
+#define NGX_TIMER_INFINITE (ngx_msec_t) -1
+#define NGX_TIMER_ERROR (ngx_msec_t) -2
/*
diff --git a/src/http/modules/ngx_http_access_handler.c b/src/http/modules/ngx_http_access_module.c
index 285570f23..685d15d57 100644
--- a/src/http/modules/ngx_http_access_handler.c
+++ b/src/http/modules/ngx_http_access_module.c
@@ -25,10 +25,10 @@ typedef struct {
static ngx_int_t ngx_http_access_handler(ngx_http_request_t *r);
static char *ngx_http_access_rule(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
+ void *conf);
static void *ngx_http_access_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_access_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child);
+ void *parent, void *child);
static ngx_int_t ngx_http_access_init(ngx_cycle_t *cycle);
@@ -77,7 +77,8 @@ ngx_module_t ngx_http_access_module = {
};
-static ngx_int_t ngx_http_access_handler(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_access_handler(ngx_http_request_t *r)
{
ngx_uint_t i;
struct sockaddr_in *sin;
@@ -117,8 +118,8 @@ static ngx_int_t ngx_http_access_handler(ngx_http_request_t *r)
}
-static char *ngx_http_access_rule(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+static char *
+ngx_http_access_rule(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_access_loc_conf_t *alcf = conf;
@@ -127,14 +128,15 @@ static char *ngx_http_access_rule(ngx_conf_t *cf, ngx_command_t *cmd,
ngx_http_access_rule_t *rule;
if (alcf->rules == NULL) {
- alcf->rules = ngx_create_array(cf->pool, 4,
+ alcf->rules = ngx_array_create(cf->pool, 4,
sizeof(ngx_http_access_rule_t));
if (alcf->rules == NULL) {
return NGX_CONF_ERROR;
}
}
- if (!(rule = ngx_push_array(alcf->rules))) {
+ rule = ngx_array_push(alcf->rules);
+ if (rule == NULL) {
return NGX_CONF_ERROR;
}
@@ -170,11 +172,13 @@ static char *ngx_http_access_rule(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static void *ngx_http_access_create_loc_conf(ngx_conf_t *cf)
+static void *
+ngx_http_access_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_access_loc_conf_t *conf;
- if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_access_loc_conf_t)))) {
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_access_loc_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -182,8 +186,8 @@ static void *ngx_http_access_create_loc_conf(ngx_conf_t *cf)
}
-static char *ngx_http_access_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child)
+static char *
+ngx_http_access_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_access_loc_conf_t *prev = parent;
ngx_http_access_loc_conf_t *conf = child;
@@ -196,14 +200,15 @@ static char *ngx_http_access_merge_loc_conf(ngx_conf_t *cf,
}
-static ngx_int_t ngx_http_access_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_access_init(ngx_cycle_t *cycle)
{
ngx_http_handler_pt *h;
ngx_http_core_main_conf_t *cmcf;
cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
- h = ngx_push_array(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers);
+ h = ngx_array_push(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers);
if (h == NULL) {
return NGX_ERROR;
}
diff --git a/src/http/modules/ngx_http_autoindex_handler.c b/src/http/modules/ngx_http_autoindex_module.c
index 8976ad546..a7b998678 100644
--- a/src/http/modules/ngx_http_autoindex_handler.c
+++ b/src/http/modules/ngx_http_autoindex_module.c
@@ -218,10 +218,7 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
if (ngx_read_dir(&dir) == NGX_ERROR) {
err = ngx_errno;
- if (err == NGX_ENOMOREFILES) {
- rc = NGX_OK;
-
- } else {
+ if (err != NGX_ENOMOREFILES) {
ngx_log_error(NGX_LOG_CRIT, r->connection->log, err,
ngx_read_dir_n " \"%s\" failed", dname.data);
return ngx_http_autoindex_error(r, &dir, dname.data);
@@ -251,7 +248,8 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
if (dname.len + 1 + len > fname.len) {
fname.len = dname.len + 1 + len + 32;
- if (!(fname.data = ngx_palloc(pool, fname.len))) {
+ fname.data = ngx_palloc(pool, fname.len);
+ if (fname.data == NULL) {
return ngx_http_autoindex_error(r, &dir, dname.data);
}
@@ -280,7 +278,8 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
}
}
- if (!(entry = ngx_array_push(&entries))) {
+ entry = ngx_array_push(&entries);
+ if (entry == NULL) {
return ngx_http_autoindex_error(r, &dir, dname.data);
}
@@ -288,7 +287,8 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
entry->escape = 2 * ngx_escape_uri(NULL, ngx_de_name(&dir), len,
NGX_ESCAPE_HTML);
- if (!(entry->name.data = ngx_palloc(pool, len + entry->escape + 1))) {
+ entry->name.data = ngx_palloc(pool, len + entry->escape + 1);
+ if (entry->name.data == NULL) {
return ngx_http_autoindex_error(r, &dir, dname.data);
}
@@ -326,7 +326,8 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
+ 2;
}
- if (!(b = ngx_create_temp_buf(r->pool, len))) {
+ b = ngx_create_temp_buf(r->pool, len);
+ if (b == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -481,11 +482,13 @@ ngx_http_autoindex_alloc(ngx_http_autoindex_ctx_t *ctx, size_t size)
ctx->size += ctx->buf->last - ctx->buf->pos;
}
- if (!(ctx->buf = ngx_create_temp_buf(ctx->pool, ctx->alloc_size))) {
+ ctx->buf = ngx_create_temp_buf(ctx->pool, ctx->alloc_size);
+ if (ctx->buf == NULL) {
return NULL;
}
- if (!(cl = ngx_alloc_chain_link(ctx->pool))) {
+ cl = ngx_alloc_chain_link(ctx->pool);
+ if (cl == NULL) {
return NULL;
}
diff --git a/src/http/modules/ngx_http_charset_filter.c b/src/http/modules/ngx_http_charset_filter_module.c
index cbd0fca75..dad26ba91 100644
--- a/src/http/modules/ngx_http_charset_filter.c
+++ b/src/http/modules/ngx_http_charset_filter_module.c
@@ -48,11 +48,11 @@ typedef struct {
static ngx_uint_t ngx_charset_recode(ngx_buf_t *b, char *table);
static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
+ void *conf);
static char *ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf);
static char *ngx_http_set_charset_slot(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
+ void *conf);
static ngx_int_t ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name);
static ngx_int_t ngx_http_charset_filter_init(ngx_cycle_t *cycle);
@@ -61,7 +61,7 @@ static void *ngx_http_charset_create_main_conf(ngx_conf_t *cf);
static char *ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf);
static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child);
+ void *parent, void *child);
static ngx_command_t ngx_http_charset_filter_commands[] = {
@@ -133,7 +133,8 @@ static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
-static ngx_int_t ngx_http_charset_header_filter(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_charset_header_filter(ngx_http_request_t *r)
{
ngx_http_charset_t *charsets;
ngx_http_charset_ctx_t *ctx;
@@ -165,7 +166,7 @@ static ngx_int_t ngx_http_charset_header_filter(ngx_http_request_t *r)
}
if (r->headers_out.status == NGX_HTTP_MOVED_PERMANENTLY
- && r->headers_out.status == NGX_HTTP_MOVED_TEMPORARILY)
+ || r->headers_out.status == NGX_HTTP_MOVED_TEMPORARILY)
{
/*
* do not set charset for the redirect because NN 4.x uses this
@@ -187,8 +188,14 @@ static ngx_int_t ngx_http_charset_header_filter(ngx_http_request_t *r)
return ngx_http_next_header_filter(r);
}
- ngx_http_create_ctx(r, ctx, ngx_http_charset_filter_module,
- sizeof(ngx_http_charset_ctx_t), NGX_ERROR);
+
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_charset_ctx_t));
+ if (ctx == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_http_set_ctx(r, ctx, ngx_http_charset_filter_module);
+
r->filter_need_in_memory = 1;
@@ -196,8 +203,8 @@ static ngx_int_t ngx_http_charset_header_filter(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_charset_body_filter(ngx_http_request_t *r,
- ngx_chain_t *in)
+static ngx_int_t
+ngx_http_charset_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
char *table;
ngx_chain_t *cl;
@@ -226,7 +233,8 @@ static ngx_int_t ngx_http_charset_body_filter(ngx_http_request_t *r,
}
-static ngx_uint_t ngx_charset_recode(ngx_buf_t *b, char *table)
+static ngx_uint_t
+ngx_charset_recode(ngx_buf_t *b, char *table)
{
u_char *p;
ngx_uint_t change;
@@ -254,8 +262,8 @@ static ngx_uint_t ngx_charset_recode(ngx_buf_t *b, char *table)
}
-static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+static char *
+ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_charset_main_conf_t *mcf = conf;
@@ -297,18 +305,21 @@ static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd,
}
}
- if (!(table = ngx_push_array(&mcf->tables))) {
+ table = ngx_array_push(&mcf->tables);
+ if (table == NULL) {
return NGX_CONF_ERROR;
}
table->src = src;
table->dst = dst;
- if (!(table->src2dst = ngx_palloc(cf->pool, 256))) {
+ table->src2dst = ngx_palloc(cf->pool, 256);
+ if (table->src2dst == NULL) {
return NGX_CONF_ERROR;
}
- if (!(table->dst2src = ngx_palloc(cf->pool, 256))) {
+ table->dst2src = ngx_palloc(cf->pool, 256);
+ if (table->dst2src == NULL) {
return NGX_CONF_ERROR;
}
@@ -326,14 +337,17 @@ static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd,
cf->ctx = table;
cf->handler = ngx_charset_map;
cf->handler_conf = conf;
+
rv = ngx_conf_parse(cf, NULL);
+
*cf = pvcf;
return rv;
}
-static char *ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
+static char *
+ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
{
ngx_int_t src, dst;
ngx_str_t *value;
@@ -369,8 +383,8 @@ static char *ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
}
-static char *ngx_http_set_charset_slot(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+static char *
+ngx_http_set_charset_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *p = conf;
@@ -404,7 +418,8 @@ static char *ngx_http_set_charset_slot(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static ngx_int_t ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name)
+static ngx_int_t
+ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name)
{
ngx_uint_t i;
ngx_http_charset_t *c;
@@ -424,7 +439,8 @@ static ngx_int_t ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name)
return i;
}
- if (!(c = ngx_push_array(charsets))) {
+ c = ngx_array_push(charsets);
+ if (c == NULL) {
return NGX_ERROR;
}
@@ -436,7 +452,8 @@ static ngx_int_t ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name)
}
-static ngx_int_t ngx_http_charset_filter_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_charset_filter_init(ngx_cycle_t *cycle)
{
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_charset_header_filter;
@@ -448,25 +465,34 @@ static ngx_int_t ngx_http_charset_filter_init(ngx_cycle_t *cycle)
}
-static void *ngx_http_charset_create_main_conf(ngx_conf_t *cf)
+static void *
+ngx_http_charset_create_main_conf(ngx_conf_t *cf)
{
ngx_http_charset_main_conf_t *mcf;
- if (!(mcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_main_conf_t)))) {
+ mcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_main_conf_t));
+ if (mcf == NULL) {
return NGX_CONF_ERROR;
}
- ngx_init_array(mcf->charsets, cf->pool, 2, sizeof(ngx_http_charset_t),
- NGX_CONF_ERROR);
+ if (ngx_array_init(&mcf->charsets, cf->pool, 2, sizeof(ngx_http_charset_t))
+ == NGX_ERROR)
+ {
+ return NGX_CONF_ERROR;
+ }
- ngx_init_array(mcf->tables, cf->pool, 4, sizeof(ngx_http_charset_tables_t),
- NGX_CONF_ERROR);
+ if (ngx_array_init(&mcf->tables, cf->pool, 4,
+ sizeof(ngx_http_charset_tables_t)) == NGX_ERROR)
+ {
+ return NGX_CONF_ERROR;
+ }
return mcf;
}
-static char *ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf)
+static char *
+ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf)
{
ngx_http_charset_main_conf_t *mcf = conf;
@@ -484,7 +510,6 @@ static char *ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf)
charset[i].tables = ngx_pcalloc(cf->pool,
sizeof(char *) * mcf->charsets.nelts);
-
if (charset[i].tables == NULL) {
return NGX_CONF_ERROR;
}
@@ -527,11 +552,13 @@ static char *ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf)
}
-static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf)
+static void *
+ngx_http_charset_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_charset_loc_conf_t *lcf;
- if (!(lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_loc_conf_t)))) {
+ lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_loc_conf_t));
+ if (lcf == NULL) {
return NGX_CONF_ERROR;
}
@@ -544,8 +571,8 @@ static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf)
}
-static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child)
+static char *
+ngx_http_charset_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_charset_loc_conf_t *prev = parent;
ngx_http_charset_loc_conf_t *conf = child;
diff --git a/src/http/modules/ngx_http_chunked_filter.c b/src/http/modules/ngx_http_chunked_filter_module.c
index 5145ff67f..b742dbb7c 100644
--- a/src/http/modules/ngx_http_chunked_filter.c
+++ b/src/http/modules/ngx_http_chunked_filter_module.c
@@ -40,7 +40,8 @@ static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
-static ngx_int_t ngx_http_chunked_header_filter(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_chunked_header_filter(ngx_http_request_t *r)
{
if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED) {
return ngx_http_next_header_filter(r);
@@ -59,8 +60,8 @@ static ngx_int_t ngx_http_chunked_header_filter(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r,
- ngx_chain_t *in)
+static ngx_int_t
+ngx_http_chunked_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
u_char *chunk;
off_t size;
@@ -85,7 +86,8 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r,
if (cl->buf->flush || ngx_buf_in_memory(cl->buf) || cl->buf->in_file) {
- if (!(tl = ngx_alloc_chain_link(r->pool))) {
+ tl = ngx_alloc_chain_link(r->pool);
+ if (tl == NULL) {
return NGX_ERROR;
}
@@ -102,10 +104,13 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r,
}
if (size) {
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
+ /* the "0000000000000000" is 64-bit hexadimal string */
+
chunk = ngx_palloc(r->pool, sizeof("0000000000000000" CRLF) - 1);
if (chunk == NULL) {
return NGX_ERROR;
@@ -119,7 +124,8 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r,
}
if (cl->buf->last_buf) {
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -144,7 +150,8 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r,
return ngx_http_next_body_filter(r, out.next);
}
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -161,7 +168,8 @@ static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r,
}
-static ngx_int_t ngx_http_chunked_filter_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_chunked_filter_init(ngx_cycle_t *cycle)
{
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_chunked_header_filter;
diff --git a/src/http/modules/ngx_http_fastcgi_handler.c b/src/http/modules/ngx_http_fastcgi_module.c
index 5b384b86e..a5f9a02c8 100644
--- a/src/http/modules/ngx_http_fastcgi_handler.c
+++ b/src/http/modules/ngx_http_fastcgi_module.c
@@ -377,7 +377,8 @@ ngx_http_fastcgi_handler(ngx_http_request_t *r)
flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
- if (!(u = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_t)))) {
+ u = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_t));
+ if (u == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -492,25 +493,24 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
index = (r->uri.data[r->uri.len - 1] == '/') ? flcf->index.len : 0;
len += 1 + ((flcf->root.len + r->uri.len + index > 127) ? 4 : 1)
- + sizeof("PATH_TRANSLATED") - 1
- + flcf->root.len + r->uri.len + index;
+ + sizeof("PATH_TRANSLATED") - 1 + flcf->root.len + r->uri.len + index;
if (r->args.len) {
len += 1 + ((r->args.len > 127) ? 4 : 1) + sizeof("QUERY_STRING") - 1
- + r->args.len;
+ + r->args.len;
}
if (r->headers_in.content_length_n > 0) {
len += 1 + ((r->headers_in.content_length->value.len > 127) ? 4 : 1)
- + sizeof("CONTENT_LENGTH") - 1
- + r->headers_in.content_length->value.len;
+ + sizeof("CONTENT_LENGTH") - 1
+ + r->headers_in.content_length->value.len;
}
if (r->headers_in.content_type) {
len += 1 + ((r->headers_in.content_type->value.len > 127) ? 4 : 1)
- + sizeof("CONTENT_TYPE") - 1
- + r->headers_in.content_type->value.len;
+ + sizeof("CONTENT_TYPE") - 1
+ + r->headers_in.content_type->value.len;
}
@@ -520,24 +520,24 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
if (flcf->params & NGX_HTTP_FASTCGI_REQUEST_URI) {
len += 1 + ((r->unparsed_uri.len > 127) ? 4 : 1)
- + sizeof("REQUEST_URI") - 1 + r->unparsed_uri.len;
+ + sizeof("REQUEST_URI") - 1 + r->unparsed_uri.len;
}
if (flcf->params & NGX_HTTP_FASTCGI_DOCUMENT_ROOT) {
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
len += 1 + ((clcf->root.len > 127) ? 4 : 1)
- + sizeof("DOCUMENT_ROOT") - 1 + clcf->root.len;
+ + sizeof("DOCUMENT_ROOT") - 1 + clcf->root.len;
}
if (flcf->params & NGX_HTTP_FASTCGI_SCRIPT_FILENAME) {
len += 1 + ((flcf->root.len + r->uri.len + index > 127) ? 4 : 1)
- + sizeof("SCRIPT_FILENAME") - 1
- + flcf->root.len + r->uri.len + index;
+ + sizeof("SCRIPT_FILENAME") - 1
+ + flcf->root.len + r->uri.len + index;
}
if (flcf->params & NGX_HTTP_FASTCGI_SCRIPT_NAME) {
len += 1 + ((r->uri.len + index > 127) ? 4 : 1)
- + sizeof("SCRIPT_NAME") - 1 + r->uri.len + index ;
+ + sizeof("SCRIPT_NAME") - 1 + r->uri.len + index ;
}
if (flcf->params & NGX_HTTP_FASTCGI_REMOTE_ADDR) {
@@ -579,7 +579,7 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
&& r->http_protocol.len)
{
len += 1 + ((r->http_protocol.len > 127) ? 4 : 1)
- + sizeof("SERVER_PROTOCOL") - 1 + r->http_protocol.len;
+ + sizeof("SERVER_PROTOCOL") - 1 + r->http_protocol.len;
}
if (flcf->params & NGX_HTTP_FASTCGI_SERVER_SOFTWARE) {
@@ -599,7 +599,8 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
for (i = 0; i < flcf->vars->nelts; i++) {
- if (!(value = ngx_http_get_indexed_variable(r, vindex[i]))) {
+ value = ngx_http_get_indexed_variable(r, vindex[i]);
+ if (value == NULL) {
continue;
}
@@ -626,8 +627,8 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
}
len += ((header[i].key.len > 127) ? 4 : 1)
- + ((header[i].value.len > 127) ? 4 : 1)
- + 5 + header[i].key.len + header[i].value.len;
+ + ((header[i].value.len > 127) ? 4 : 1)
+ + 5 + header[i].key.len + header[i].value.len;
}
@@ -652,11 +653,13 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
+ sizeof(ngx_http_fastcgi_header_t); /* NGX_HTTP_FASTCGI_STDIN */
- if (!(b = ngx_create_temp_buf(r->pool, size))) {
+ b = ngx_create_temp_buf(r->pool, size);
+ if (b == NULL) {
return NGX_ERROR;
}
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
return NGX_ERROR;
}
@@ -998,7 +1001,8 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
if (flcf->vars) {
for (i = 0; i < flcf->vars->nelts; i++) {
- if (!(value = ngx_http_get_indexed_variable(r, vindex[i]))) {
+ value = ngx_http_get_indexed_variable(r, vindex[i]);
+ if (value == NULL) {
continue;
}
@@ -1115,7 +1119,8 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
next = 0;
do {
- if (!(b = ngx_alloc_buf(r->pool))) {
+ b = ngx_alloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -1158,7 +1163,8 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
h->padding_length = (u_char) padding;
h->reserved = 0;
- if (!(cl->next = ngx_alloc_chain_link(r->pool))) {
+ cl->next = ngx_alloc_chain_link(r->pool);
+ if (cl->next == NULL) {
return NGX_ERROR;
}
@@ -1179,7 +1185,8 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
h = (ngx_http_fastcgi_header_t *) b->last;
b->last += sizeof(ngx_http_fastcgi_header_t);
- if (!(cl->next = ngx_alloc_chain_link(r->pool))) {
+ cl->next = ngx_alloc_chain_link(r->pool);
+ if (cl->next == NULL) {
return NGX_ERROR;
}
@@ -1248,7 +1255,8 @@ static ngx_int_t ngx_http_fastcgi_process_header(ngx_http_request_t *r)
f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
if (f == NULL) {
- if (!(f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t)))) {
+ f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t));
+ if (f == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -1413,7 +1421,8 @@ static ngx_int_t ngx_http_fastcgi_process_header(ngx_http_request_t *r)
/* a header line has been parsed successfully */
- if (!(h = ngx_list_push(&f->upstream->headers_in.headers))) {
+ h = ngx_list_push(&f->upstream->headers_in.headers);
+ if (h == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -1580,7 +1589,8 @@ ngx_http_fastcgi_send_header(ngx_http_request_t *r)
/* copy some header pointers and set up r->headers_out */
- if (!(ho = ngx_list_push(&r->headers_out.headers))) {
+ ho = ngx_list_push(&r->headers_out.headers);
+ if (ho == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -1733,7 +1743,8 @@ ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
p->free = p->free->next;
} else {
- if (!(b = ngx_alloc_buf(p->pool))) {
+ b = ngx_alloc_buf(p->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
}
@@ -1750,18 +1761,26 @@ ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
*prev = b;
prev = &b->shadow;
- if (!(cl = ngx_alloc_chain_link(p->pool))) {
+ cl = ngx_alloc_chain_link(p->pool);
+ if (cl == NULL) {
return NGX_ERROR;
}
cl->buf = b;
cl->next = NULL;
+ if (p->in) {
+ *p->last_in = cl;
+ } else {
+ p->in = cl;
+ }
+ p->last_in = &cl->next;
+
+
/* STUB */ b->num = buf->num;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "input buf #%d", b->num);
- ngx_chain_add_link(p->in, p->last_in, cl);
if (f->pos + f->length < f->last) {
@@ -1820,11 +1839,8 @@ ngx_http_fastcgi_process_record(ngx_http_request_t *r,
ngx_http_fastcgi_ctx_t *f)
{
u_char ch, *p;
- ngx_http_upstream_t *u;
ngx_http_fastcgi_state_e state;
- u = r->upstream;
-
state = f->state;
for (p = f->pos; p < f->last; p++) {
@@ -1968,7 +1984,8 @@ ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
unix_upstream.name = value[1];
unix_upstream.url = value[1];
- if (!(lcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream))) {
+ lcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream);
+ if (lcf->peers == NULL) {
return NGX_CONF_ERROR;
}
@@ -1986,7 +2003,8 @@ ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
inet_upstream.name = value[1];
inet_upstream.url = value[1];
- if (!(lcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream))) {
+ lcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream);
+ if (lcf->peers == NULL) {
return NGX_CONF_ERROR;
}
}
@@ -1996,7 +2014,7 @@ ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
clcf->handler = ngx_http_fastcgi_handler;
#if (NGX_PCRE)
- lcf->location = clcf->regex ? &ngx_http_fastcgi_uri: &clcf->name;
+ lcf->location = clcf->regex ? &ngx_http_fastcgi_uri : &clcf->name;
#else
lcf->location = &clcf->name;
#endif
@@ -2035,7 +2053,8 @@ ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
for (i = 0; i < cmcf->variables.nelts; i++) {
if (ngx_strcasecmp(var[i].name.data, value[1].data) == 0) {
- if (!(index = ngx_array_push(lcf->vars))) {
+ index = ngx_array_push(lcf->vars);
+ if (index == NULL) {
return NGX_CONF_ERROR;
}
@@ -2084,7 +2103,8 @@ ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_fastcgi_loc_conf_t *conf;
- if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_fastcgi_loc_conf_t)))) {
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_fastcgi_loc_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/ngx_http_geo_module.c b/src/http/modules/ngx_http_geo_module.c
index 0d8267d8e..865f82551 100644
--- a/src/http/modules/ngx_http_geo_module.c
+++ b/src/http/modules/ngx_http_geo_module.c
@@ -64,9 +64,9 @@ static ngx_http_variable_value_t ngx_http_geo_null_value =
/* AF_INET only */
static ngx_http_variable_value_t *
-ngx_http_geo_variable(ngx_http_request_t *r, void *data)
+ngx_http_geo_variable(ngx_http_request_t *r, uintptr_t data)
{
- ngx_radix_tree_t *tree = data;
+ ngx_radix_tree_t *tree = (ngx_radix_tree_t *) data;
struct sockaddr_in *sin;
ngx_http_variable_value_t *var;
@@ -90,33 +90,46 @@ static char *
ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *rv;
- ngx_str_t *value;
+ ngx_str_t *value, name;
ngx_conf_t save;
ngx_pool_t *pool;
ngx_radix_tree_t *tree;
ngx_http_geo_conf_t geo;
ngx_http_variable_t *var;
- if (!(var = ngx_http_add_variable(cf))) {
- return NGX_CONF_ERROR;
+ value = cf->args->elts;
+
+ name = value[1];
+
+ if (name.data[0] != '$') {
+ ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
+ "\"%V\" variable name should start with '$'",
+ &value[1]);
+ } else {
+ name.len--;
+ name.data++;
}
- if (!(tree = ngx_radix_tree_create(cf->pool, -1))) {
+ var = ngx_http_add_variable(cf, &name, 1);
+ if (var == NULL) {
return NGX_CONF_ERROR;
}
- value = cf->args->elts;
+ tree = ngx_radix_tree_create(cf->pool, -1);
+ if (tree == NULL) {
+ return NGX_CONF_ERROR;
+ }
- var->name = value[1];
var->handler = ngx_http_geo_variable;
- var->data = tree;
+ var->data = (uintptr_t) tree;
/*
* create the temporary pool of a huge initial size
* to process quickly a large number of geo lines
*/
- if (!(pool = ngx_create_pool(512 * 1024, cf->log))) {
+ pool = ngx_create_pool(512 * 1024, cf->log);
+ if (pool == NULL) {
return NGX_CONF_ERROR;
}
@@ -212,7 +225,12 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
if (n == NGX_ERROR) {
for (i = 0; i < geo->values.nelts; i++) {
- if (ngx_strcmp(value[1].data, v[i]->text.data) == 0) {
+ if (v[i]->text.len != value[1].len) {
+ continue;
+ }
+
+ if (ngx_strncmp(value[1].data, v[i]->text.data, value[1].len) == 0)
+ {
var = v[i];
break;
}
@@ -227,20 +245,22 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
}
}
- if (i == geo->values.nelts) {
+ if (var == NULL) {
var = ngx_palloc(geo->pool, sizeof(ngx_http_variable_value_t));
if (var == NULL) {
return NGX_CONF_ERROR;
}
var->text.len = value[1].len;
- if (!(var->text.data = ngx_pstrdup(geo->pool, &value[1]))) {
+ var->text.data = ngx_pstrdup(geo->pool, &value[1]);
+ if (var->text.data == NULL) {
return NGX_CONF_ERROR;
}
var->value = (n == NGX_ERROR) ? 0 : n;
- if (!(v = ngx_array_push(&geo->values))) {
+ v = ngx_array_push(&geo->values);
+ if (v == NULL) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter_module.c
index eec6a134d..4a4da7f58 100644
--- a/src/http/modules/ngx_http_gzip_filter.c
+++ b/src/http/modules/ngx_http_gzip_filter_module.c
@@ -331,9 +331,14 @@ ngx_http_gzip_header_filter(ngx_http_request_t *r)
return ngx_http_next_header_filter(r);
}
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_gzip_ctx_t));
+ if (ctx == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_http_set_ctx(r, ctx, ngx_http_gzip_filter_module);
+
- ngx_http_create_ctx(r, ctx, ngx_http_gzip_filter_module,
- sizeof(ngx_http_gzip_ctx_t), NGX_ERROR);
ctx->request = r;
r->headers_out.content_encoding = ngx_list_push(&r->headers_out.headers);
@@ -445,7 +450,7 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ngx_int_t last;
struct gztrailer *trailer;
ngx_buf_t *b;
- ngx_chain_t *cl;
+ ngx_chain_t *cl, out;
ngx_http_gzip_ctx_t *ctx;
ngx_http_gzip_conf_t *conf;
@@ -485,7 +490,8 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ctx->allocated = 8192 + (1 << (wbits + 2)) + (1 << (memlevel + 9));
- if (!(ctx->preallocated = ngx_palloc(r->pool, ctx->allocated))) {
+ ctx->preallocated = ngx_palloc(r->pool, ctx->allocated);
+ if (ctx->preallocated == NULL) {
return NGX_ERROR;
}
@@ -505,7 +511,8 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
return NGX_ERROR;
}
- if (!(b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)))) {
+ b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
+ if (b == NULL) {
ngx_http_gzip_error(ctx);
return NGX_ERROR;
}
@@ -514,12 +521,8 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
b->pos = gzheader;
b->last = b->pos + 10;
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
- ngx_http_gzip_error(ctx);
- return NGX_ERROR;
- }
- cl->buf = b;
- cl->next = NULL;
+ out.buf = b;
+ out.next = NULL;
/*
* We pass the gzheader to the next filter now to avoid its linking
@@ -528,7 +531,7 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
* to the ctx->busy chain would be flushed by ngx_http_write_filter().
*/
- if (ngx_http_next_body_filter(r, cl) == NGX_ERROR) {
+ if (ngx_http_next_body_filter(r, &out) == NGX_ERROR) {
ngx_http_gzip_error(ctx);
return NGX_ERROR;
}
@@ -673,10 +676,12 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
/* zlib wants to output some more gzipped data */
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
ngx_http_gzip_error(ctx);
return NGX_ERROR;
}
+
cl->buf = ctx->out_buf;
cl->next = NULL;
*ctx->last_out = cl;
@@ -694,10 +699,12 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ctx->out_buf->flush = 0;
ctx->flush = Z_NO_FLUSH;
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
ngx_http_gzip_error(ctx);
return NGX_ERROR;
}
+
cl->buf = ctx->out_buf;
cl->next = NULL;
*ctx->last_out = cl;
@@ -722,10 +729,12 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ngx_pfree(r->pool, ctx->preallocated);
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
ngx_http_gzip_error(ctx);
return NGX_ERROR;
}
+
cl->buf = ctx->out_buf;
cl->next = NULL;
*ctx->last_out = cl;
@@ -737,17 +746,20 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ctx->out_buf->last_buf = 1;
} else {
- if (!(b = ngx_create_temp_buf(r->pool, 8))) {
+ b = ngx_create_temp_buf(r->pool, 8);
+ if (b == NULL) {
ngx_http_gzip_error(ctx);
return NGX_ERROR;
}
b->last_buf = 1;
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
ngx_http_gzip_error(ctx);
return NGX_ERROR;
}
+
cl->buf = b;
cl->next = NULL;
*ctx->last_out = cl;
@@ -782,10 +794,13 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
if (conf->no_buffer && ctx->in == NULL) {
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
+
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
ngx_http_gzip_error(ctx);
return NGX_ERROR;
}
+
cl->buf = ctx->out_buf;
cl->next = NULL;
*ctx->last_out = cl;
@@ -816,7 +831,7 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
ngx_chain_update_chains(&ctx->free, &ctx->busy, &ctx->out,
- (ngx_buf_tag_t) &ngx_http_gzip_filter_module);
+ (ngx_buf_tag_t) &ngx_http_gzip_filter_module);
ctx->last_out = &ctx->out;
if (ctx->done) {
@@ -969,7 +984,8 @@ ngx_http_gzip_create_conf(ngx_conf_t *cf)
{
ngx_http_gzip_conf_t *conf;
- if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_gzip_conf_t)))) {
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_gzip_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -1027,7 +1043,8 @@ ngx_http_gzip_merge_conf(ngx_conf_t *cf, void *parent, void *child)
return NGX_CONF_ERROR;
}
- if (!(type = ngx_array_push(conf->types))) {
+ type = ngx_array_push(conf->types);
+ if (type == NULL) {
return NGX_CONF_ERROR;
}
@@ -1055,12 +1072,13 @@ ngx_http_gzip_set_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (gcf->types == NULL) {
gcf->types = ngx_array_create(cf->pool, 4,
- sizeof(ngx_http_gzip_type_t));
+ sizeof(ngx_http_gzip_type_t));
if (gcf->types == NULL) {
return NGX_CONF_ERROR;
}
- if (!(type = ngx_array_push(gcf->types))) {
+ type = ngx_array_push(gcf->types);
+ if (type == NULL) {
return NGX_CONF_ERROR;
}
@@ -1077,13 +1095,15 @@ ngx_http_gzip_set_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
continue;
}
- if (!(type = ngx_array_push(gcf->types))) {
+ type = ngx_array_push(gcf->types);
+ if (type == NULL) {
return NGX_CONF_ERROR;
}
type->name.len = value[i].len;
- if (!(type->name.data = ngx_palloc(cf->pool, type->name.len + 1))) {
+ type->name.data = ngx_palloc(cf->pool, type->name.len + 1);
+ if (type->name.data == NULL) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/ngx_http_headers_filter.c b/src/http/modules/ngx_http_headers_filter_module.c
index 39b35837b..793cefd48 100644
--- a/src/http/modules/ngx_http_headers_filter.c
+++ b/src/http/modules/ngx_http_headers_filter_module.c
@@ -23,7 +23,8 @@ static ngx_int_t ngx_http_headers_filter_init(ngx_cycle_t *cycle);
static void *ngx_http_headers_create_conf(ngx_conf_t *cf);
static char *ngx_http_headers_merge_conf(ngx_conf_t *cf,
void *parent, void *child);
-char *ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
+static char *ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd,
+ void *conf);
static ngx_command_t ngx_http_headers_filter_commands[] = {
@@ -66,7 +67,8 @@ ngx_module_t ngx_http_headers_filter_module = {
static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
-static ngx_int_t ngx_http_headers_filter(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_headers_filter(ngx_http_request_t *r)
{
size_t len;
ngx_table_elt_t *expires, *cc;
@@ -80,13 +82,15 @@ static ngx_int_t ngx_http_headers_filter(ngx_http_request_t *r)
if (conf->expires != NGX_HTTP_EXPIRES_OFF) {
- if (!(expires = ngx_list_push(&r->headers_out.headers))) {
+ expires = ngx_list_push(&r->headers_out.headers);
+ if (expires == NULL) {
return NGX_ERROR;
}
r->headers_out.expires = expires;
- if (!(cc = ngx_list_push(&r->headers_out.headers))) {
+ cc = ngx_list_push(&r->headers_out.headers);
+ if (cc == NULL) {
return NGX_ERROR;
}
@@ -147,7 +151,8 @@ static ngx_int_t ngx_http_headers_filter(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_headers_filter_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_headers_filter_init(ngx_cycle_t *cycle)
{
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_headers_filter;
@@ -156,11 +161,13 @@ static ngx_int_t ngx_http_headers_filter_init(ngx_cycle_t *cycle)
}
-static void *ngx_http_headers_create_conf(ngx_conf_t *cf)
+static void *
+ngx_http_headers_create_conf(ngx_conf_t *cf)
{
ngx_http_headers_conf_t *conf;
- if (!(conf = ngx_palloc(cf->pool, sizeof(ngx_http_headers_conf_t)))) {
+ conf = ngx_palloc(cf->pool, sizeof(ngx_http_headers_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -170,8 +177,8 @@ static void *ngx_http_headers_create_conf(ngx_conf_t *cf)
}
-static char *ngx_http_headers_merge_conf(ngx_conf_t *cf,
- void *parent, void *child)
+static char *
+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;
@@ -185,7 +192,8 @@ static char *ngx_http_headers_merge_conf(ngx_conf_t *cf,
}
-char *ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+static char *
+ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_headers_conf_t *hcf = conf;
@@ -223,6 +231,7 @@ char *ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
hcf->expires = ngx_parse_time(&value[1], 1);
+
if (hcf->expires == NGX_ERROR) {
return "invalid value";
}
diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_module.c
index 4e3755766..373c31552 100644
--- a/src/http/modules/ngx_http_index_handler.c
+++ b/src/http/modules/ngx_http_index_module.c
@@ -93,10 +93,10 @@ ngx_module_t ngx_http_index_module = {
/*
* Try to open the first index file before the test of the directory existence
* because the valid requests should be many more than invalid ones.
- * If open() failed then stat() should be more quickly because some data
+ * If open() would fail, then stat() should be more quickly because some data
* is already cached in the kernel.
- * Besides Win32 has ERROR_PATH_NOT_FOUND (NGX_ENOTDIR).
- * Unix has ENOTDIR error, although it less helpfull - it shows only
+ * Besides, Win32 has ERROR_PATH_NOT_FOUND (NGX_ENOTDIR).
+ * Unix has ENOTDIR error, although it less helpfull - it points only
* that path contains the usual file in place of the directory.
*/
@@ -137,9 +137,13 @@ static ngx_int_t ngx_http_index_handler(ngx_http_request_t *r)
ctx = ngx_http_get_module_ctx(r, ngx_http_index_module);
if (ctx == NULL) {
- ngx_http_create_ctx(r, ctx, ngx_http_index_module,
- sizeof(ngx_http_index_ctx_t),
- NGX_HTTP_INTERNAL_SERVER_ERROR);
+
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_index_ctx_t));
+ if (ctx == NULL) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ ngx_http_set_ctx(r, ctx, ngx_http_index_module);
#if (NGX_HTTP_CACHE)
@@ -417,7 +421,7 @@ static ngx_int_t ngx_http_index_init(ngx_cycle_t *cycle)
cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
- h = ngx_push_array(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
+ h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
if (h == NULL) {
return NGX_ERROR;
}
@@ -432,11 +436,17 @@ static void *ngx_http_index_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_index_loc_conf_t *conf;
- ngx_test_null(conf, ngx_palloc(cf->pool, sizeof(ngx_http_index_loc_conf_t)),
- NGX_CONF_ERROR);
+ conf = ngx_palloc(cf->pool, sizeof(ngx_http_index_loc_conf_t));
+ if (conf == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ if (ngx_array_init(&conf->indices, cf->pool, 2, sizeof(ngx_str_t))
+ == NGX_ERROR)
+ {
+ return NGX_CONF_ERROR;
+ }
- ngx_init_array(conf->indices, cf->pool, 3, sizeof(ngx_str_t),
- NGX_CONF_ERROR);
conf->max_index_len = 0;
conf->index_cache = NULL;
@@ -461,7 +471,11 @@ static char *ngx_http_index_merge_loc_conf(ngx_conf_t *cf,
return NGX_CONF_OK;
}
- ngx_test_null(index, ngx_push_array(&conf->indices), NGX_CONF_ERROR);
+ index = ngx_array_push(&conf->indices);
+ if (index == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
index->len = sizeof(NGX_HTTP_DEFAULT_INDEX) - 1;
index->data = (u_char *) NGX_HTTP_DEFAULT_INDEX;
conf->max_index_len = sizeof(NGX_HTTP_DEFAULT_INDEX);
@@ -475,8 +489,11 @@ static char *ngx_http_index_merge_loc_conf(ngx_conf_t *cf,
prev_index = prev->indices.elts;
for (i = 0; i < prev->indices.nelts; i++) {
- ngx_test_null(index, ngx_push_array(&conf->indices),
- NGX_CONF_ERROR);
+ index = ngx_array_push(&conf->indices);
+ if (index == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
index->len = prev_index[i].len;
index->data = prev_index[i].data;
}
@@ -524,7 +541,11 @@ static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd,
return NGX_CONF_ERROR;
}
- ngx_test_null(index, ngx_push_array(&ilcf->indices), NGX_CONF_ERROR);
+ index = ngx_array_push(&ilcf->indices);
+ if (index == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
index->len = value[i].len;
index->data = value[i].data;
diff --git a/src/http/modules/ngx_http_not_modified_filter.c b/src/http/modules/ngx_http_not_modified_filter_module.c
index 24ea58d90..24ea58d90 100644
--- a/src/http/modules/ngx_http_not_modified_filter.c
+++ b/src/http/modules/ngx_http_not_modified_filter_module.c
diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter_module.c
index 03f274560..84381c930 100644
--- a/src/http/modules/ngx_http_range_filter.c
+++ b/src/http/modules/ngx_http_range_filter_module.c
@@ -186,7 +186,8 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
while (*p == ' ') { p++; }
if (*p == ',' || *p == '\0') {
- if (!(range = ngx_array_push(&r->headers_out.ranges))) {
+ range = ngx_array_push(&r->headers_out.ranges);
+ if (range == NULL) {
return NGX_ERROR;
}
@@ -231,7 +232,8 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
break;
}
- if (!(range = ngx_array_push(&r->headers_out.ranges))) {
+ range = ngx_array_push(&r->headers_out.ranges);
+ if (range == NULL) {
return NGX_ERROR;
}
@@ -260,7 +262,8 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
r->headers_out.status = rc;
r->headers_out.ranges.nelts = 0;
- if (!(content_range = ngx_list_push(&r->headers_out.headers))) {
+ content_range = ngx_list_push(&r->headers_out.headers);
+ if (content_range == NULL) {
return NGX_ERROR;
}
@@ -269,9 +272,8 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
content_range->key.len = sizeof("Content-Range") - 1;
content_range->key.data = (u_char *) "Content-Range";
- content_range->value.data =
- ngx_palloc(r->pool, sizeof("bytes */") - 1 + NGX_OFF_T_LEN);
-
+ content_range->value.data = ngx_palloc(r->pool,
+ sizeof("bytes */") - 1 + NGX_OFF_T_LEN);
if (content_range->value.data == NULL) {
return NGX_ERROR;
}
@@ -294,7 +296,8 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
if (r->headers_out.ranges.nelts == 1) {
- if (!(content_range = ngx_list_push(&r->headers_out.headers))) {
+ content_range = ngx_list_push(&r->headers_out.headers);
+ if (content_range == NULL) {
return NGX_ERROR;
}
@@ -325,8 +328,12 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
/* TODO: what if no content_type ?? */
- ngx_http_create_ctx(r, ctx, ngx_http_range_body_filter_module,
- sizeof(ngx_http_range_filter_ctx_t), NGX_ERROR);
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_range_filter_ctx_t));
+ if (ctx == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_http_set_ctx(r, ctx, ngx_http_range_body_filter_module);
len = sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN
@@ -338,7 +345,8 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
len += sizeof("; charset=") - 1 + r->headers_out.charset.len;
}
- if (!(ctx->boundary_header.data = ngx_palloc(r->pool, len))) {
+ ctx->boundary_header.data = ngx_palloc(r->pool, len);
+ if (ctx->boundary_header.data == NULL) {
return NGX_ERROR;
}
@@ -466,7 +474,8 @@ ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
* "Content-Range: bytes "
*/
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -474,7 +483,8 @@ ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
b->pos = ctx->boundary_header.data;
b->last = ctx->boundary_header.data + ctx->boundary_header.len;
- if (!(hcl = ngx_alloc_chain_link(r->pool))) {
+ hcl = ngx_alloc_chain_link(r->pool);
+ if (hcl == NULL) {
return NGX_ERROR;
}
@@ -483,7 +493,8 @@ ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
/* "SSSS-EEEE/TTTT" CRLF CRLF */
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -491,7 +502,8 @@ ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
b->pos = range[i].content_range.data;
b->last = range[i].content_range.data + range[i].content_range.len;
- if (!(rcl = ngx_alloc_chain_link(r->pool))) {
+ rcl = ngx_alloc_chain_link(r->pool);
+ if (rcl == NULL) {
return NGX_ERROR;
}
@@ -500,7 +512,8 @@ ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
/* the range data */
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -509,7 +522,8 @@ ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
b->file_last = range[i].end;
b->file = in->buf->file;
- if (!(dcl = ngx_alloc_chain_link(r->pool))) {
+ dcl = ngx_alloc_chain_link(r->pool);
+ if (dcl == NULL) {
return NGX_ERROR;
}
@@ -523,7 +537,8 @@ ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
/* the last boundary CRLF "--0123456789--" CRLF */
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -540,7 +555,8 @@ ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
*b->last++ = '-'; *b->last++ = '-';
*b->last++ = CR; *b->last++ = LF;
- if (!(hcl = ngx_alloc_chain_link(r->pool))) {
+ hcl = ngx_alloc_chain_link(r->pool);
+ if (hcl == NULL) {
return NGX_ERROR;
}
diff --git a/src/http/modules/ngx_http_rewrite_handler.c b/src/http/modules/ngx_http_rewrite_module.c
index 3080bd6f4..d0313a01f 100644
--- a/src/http/modules/ngx_http_rewrite_handler.c
+++ b/src/http/modules/ngx_http_rewrite_module.c
@@ -21,6 +21,12 @@ typedef struct {
typedef struct {
+ ngx_str_t *name;
+ ngx_http_variable_value_t *value;
+} ngx_http_rewrite_variable_t;
+
+
+typedef struct {
ngx_array_t *codes; /* uintptr_t */
ngx_array_t *referers; /* ngx_http_rewrite_referer_t */
@@ -41,6 +47,7 @@ typedef struct {
uintptr_t status;
uintptr_t next;
+ uintptr_t test:1;
uintptr_t uri:1;
/* add the r->args to the new arguments */
@@ -92,13 +99,21 @@ typedef struct {
typedef struct {
ngx_http_rewrite_code_pt code;
+ uintptr_t value;
+ uintptr_t text_len;
+ uintptr_t text_data;
+} ngx_http_rewrite_value_code_t;
+
+
+typedef struct {
+ ngx_http_rewrite_code_pt code;
uintptr_t index;
} ngx_http_rewrite_var_code_t;
struct ngx_http_rewrite_engine_s {
u_char *ip;
- uintptr_t *sp;
+ ngx_http_variable_value_t *sp;
ngx_str_t buf;
ngx_str_t *line;
@@ -128,8 +143,14 @@ static char *ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static char *ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
+static char * ngx_http_rewrite_if_condition(ngx_conf_t *cf,
+ ngx_http_rewrite_loc_conf_t *lcf);
+static char *ngx_http_rewrite_variable(ngx_conf_t *cf,
+ ngx_http_rewrite_loc_conf_t *lcf, ngx_str_t *value);
static char *ngx_http_rewrite_valid_referers(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf);
+static char * ngx_http_rewrite_set(ngx_conf_t *cf, ngx_command_t *cmd,
+ void *conf);
static void *ngx_http_rewrite_start_code(ngx_pool_t *pool,
ngx_array_t **codes, size_t size);
static void *ngx_http_rewrite_add_code(ngx_array_t *codes, size_t size,
@@ -168,6 +189,14 @@ static ngx_command_t ngx_http_rewrite_commands[] = {
0,
NULL },
+ { ngx_string("set"),
+ NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
+ |NGX_CONF_TAKE2,
+ ngx_http_rewrite_set,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ 0,
+ NULL },
+
{ ngx_string("rewrite_log"),
NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|NGX_CONF_TAKE1,
@@ -208,6 +237,9 @@ ngx_module_t ngx_http_rewrite_module = {
uintptr_t ngx_http_rewrite_exit_code = (uintptr_t) NULL;
+static ngx_http_variable_value_t ngx_http_rewrite_null_value =
+ { 0, ngx_string("") };
+
static ngx_int_t
ngx_http_rewrite_handler(ngx_http_request_t *r)
@@ -222,11 +254,13 @@ ngx_http_rewrite_handler(ngx_http_request_t *r)
return NGX_DECLINED;
}
- if (!(e = ngx_palloc(r->pool, sizeof(ngx_http_rewrite_engine_t)))) {
+ e = ngx_palloc(r->pool, sizeof(ngx_http_rewrite_engine_t));
+ if (e == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
- e->sp = ngx_palloc(r->pool, cf->stack_size * sizeof(ngx_int_t));
+ e->sp = ngx_palloc(r->pool,
+ cf->stack_size * sizeof(ngx_http_variable_value_t));
if (e->sp == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -274,12 +308,13 @@ ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e)
r = e->request;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http rewrite start: \"%V\"", &code->name);
+ "http rewrite regex: \"%V\"", &code->name);
if (code->uri) {
e->line = &r->uri;
} else {
- e->line = *(ngx_str_t **) e->sp--;
+ e->sp--;
+ e->line = &e->sp->text;
}
rc = ngx_regex_exec(code->regex, e->line, e->captures, code->ncaptures);
@@ -290,6 +325,16 @@ ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e)
"\"%V\" does not match \"%V\"", &code->name, e->line);
}
+ if (code->test) {
+ e->sp->value = 0;
+ e->sp->text.len = 0;
+ e->sp->text.data = (u_char *) "";
+ e->sp++;
+
+ e->ip += sizeof(ngx_http_rewrite_regex_code_t);
+ return;
+ }
+
e->ip += code->next;
return;
}
@@ -309,6 +354,16 @@ ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e)
"\"%V\" matches \"%V\"", &code->name, e->line);
}
+ if (code->test) {
+ e->sp->value = 1;
+ e->sp->text.len = 1;
+ e->sp->text.data = (u_char *) "1";
+ e->sp++;
+
+ e->ip += sizeof(ngx_http_rewrite_regex_code_t);
+ return;
+ }
+
if (code->status) {
e->status = code->status;
@@ -339,7 +394,8 @@ ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e)
e->buf.len += r->args.len + 1;
}
- if (!(e->buf.data = ngx_palloc(r->pool, e->buf.len))) {
+ e->buf.data = ngx_palloc(r->pool, e->buf.len);
+ if (e->buf.data == NULL) {
e->ip = ngx_http_rewrite_exit;
e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
return;
@@ -366,7 +422,7 @@ ngx_http_rewrite_regex_end_code(ngx_http_rewrite_engine_t *e)
e->quote = 0;
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http rewrite end");
+ "http rewrite regex end");
if (e->args) {
e->buf.len = e->args - e->buf.data;
@@ -414,7 +470,8 @@ ngx_http_rewrite_regex_end_code(ngx_http_rewrite_engine_t *e)
ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
"rewritten redirect: \"%V\"", &e->buf);
- if (!(r->headers_out.location = ngx_list_push(&r->headers_out.headers))) {
+ r->headers_out.location = ngx_list_push(&r->headers_out.headers);
+ if (r->headers_out.location == NULL) {
e->ip = ngx_http_rewrite_exit;
e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
return;
@@ -468,7 +525,7 @@ ngx_http_rewrite_copy_code(ngx_http_rewrite_engine_t *e)
code->len);
e->ip += sizeof(ngx_http_rewrite_copy_code_t)
- + ((code->len + sizeof(uintptr_t) - 1) & ~(sizeof(uintptr_t) - 1));
+ + ((code->len + sizeof(uintptr_t) - 1) & ~(sizeof(uintptr_t) - 1));
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
"http rewrite copy: \"%V\"", &e->buf);
@@ -509,7 +566,9 @@ ngx_http_rewrite_if_code(ngx_http_rewrite_engine_t *e)
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
"http rewrite if");
- if (*e->sp--) {
+ e->sp--;
+
+ if (e->sp->value) {
if (code->loc_conf) {
e->request->loc_conf = code->loc_conf;
}
@@ -526,6 +585,69 @@ ngx_http_rewrite_if_code(ngx_http_rewrite_engine_t *e)
static void
+ngx_http_rewrite_value_code(ngx_http_rewrite_engine_t *e)
+{
+ ngx_http_rewrite_value_code_t *code;
+
+ code = (ngx_http_rewrite_value_code_t *) e->ip;
+
+ e->ip += sizeof(ngx_http_rewrite_value_code_t);
+
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
+ "http rewrite value");
+
+ e->sp->value = (ngx_uint_t) code->value;
+ e->sp->text.len = (size_t) code->text_len;
+ e->sp->text.data = (u_char *) code->text_data;
+ e->sp++;
+}
+
+
+static void
+ngx_http_rewrite_set_var_code(ngx_http_rewrite_engine_t *e)
+{
+ ngx_http_request_t *r;
+ ngx_http_variable_value_t *value;
+ ngx_http_core_main_conf_t *cmcf;
+ ngx_http_rewrite_var_code_t *code;
+
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
+ "http rewrite set var");
+
+ code = (ngx_http_rewrite_var_code_t *) e->ip;
+
+ e->ip += sizeof(ngx_http_rewrite_var_code_t);
+
+ r = e->request;
+
+ if (r->variables == NULL) {
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
+
+ r->variables = ngx_pcalloc(r->pool, cmcf->variables.nelts
+ * sizeof(ngx_http_variable_value_t *));
+ if (r->variables == NULL) {
+ e->ip = ngx_http_rewrite_exit;
+ e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
+ return;
+ }
+ }
+
+ value = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
+ if (value == NULL) {
+ e->ip = ngx_http_rewrite_exit;
+ e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
+ return;
+ }
+
+ e->sp--;
+
+ *value = *e->sp;
+
+ r->variables[code->index] = value;
+}
+
+
+static void
ngx_http_rewrite_var_code(ngx_http_rewrite_engine_t *e)
{
ngx_http_variable_value_t *value;
@@ -536,19 +658,24 @@ ngx_http_rewrite_var_code(ngx_http_rewrite_engine_t *e)
code = (ngx_http_rewrite_var_code_t *) e->ip;
- e->sp++;
-
e->ip += sizeof(ngx_http_rewrite_var_code_t);
- if (!(value = ngx_http_get_indexed_variable(e->request, code->index))) {
- *e->sp = (uintptr_t) 0;
+ value = ngx_http_get_indexed_variable(e->request, code->index);
+
+ if (value == NULL || value == NGX_HTTP_VARIABLE_NOT_FOUND) {
+ e->sp->value = 0;
+ e->sp->text.len = 0;
+ e->sp->text.data = (u_char *) "";
+ e->sp++;
+
return;
}
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
- "http rewrite var: %p", value->value);
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
+ "http rewrite var: %ui, \"%V\"", value->value, &value->text);
- *e->sp = value->value;
+ *e->sp = *value;
+ e->sp++;
}
@@ -569,20 +696,31 @@ ngx_http_rewrite_invalid_referer_code(ngx_http_rewrite_engine_t *e)
cf = ngx_http_get_module_loc_conf(r, ngx_http_rewrite_module);
- e->sp++;
e->ip += sizeof(uintptr_t);
if (cf->referers == NULL) {
- *e->sp = (uintptr_t) 0;
+ e->sp->value = 0;
+ e->sp->text.len = 0;
+ e->sp->text.data = (u_char *) "";
+ e->sp++;
+
return;
}
if (r->headers_in.referer == NULL) {
if (cf->no_referer) {
- *e->sp = (uintptr_t) 0;
+ e->sp->value = 0;
+ e->sp->text.len = 0;
+ e->sp->text.data = (u_char *) "";
+ e->sp++;
+
return;
} else {
- *e->sp = (uintptr_t) 1;
+ e->sp->value = 1;
+ e->sp->text.len = 1;
+ e->sp->text.data = (u_char *) "1";
+ e->sp++;
+
return;
}
}
@@ -593,7 +731,11 @@ ngx_http_rewrite_invalid_referer_code(ngx_http_rewrite_engine_t *e)
if (len < sizeof("http://i.ru") - 1
|| (ngx_strncasecmp(ref, "http://", 7) != 0))
{
- *e->sp = (uintptr_t) 1;
+ e->sp->value = 1;
+ e->sp->text.len = 1;
+ e->sp->text.data = (u_char *) "1";
+ e->sp++;
+
return;
}
@@ -620,7 +762,11 @@ ngx_http_rewrite_invalid_referer_code(ngx_http_rewrite_engine_t *e)
if (ngx_strncmp(&ref[n], refs[i].name.data,
refs[i].name.len) == 0)
{
- *e->sp = (uintptr_t) 0;
+ e->sp->value = 0;
+ e->sp->text.len = 0;
+ e->sp->text.data = (u_char *) "";
+ e->sp++;
+
return;
}
}
@@ -628,13 +774,20 @@ ngx_http_rewrite_invalid_referer_code(ngx_http_rewrite_engine_t *e)
} else {
if (ngx_strncasecmp(refs[i].name.data, ref, refs[i].name.len) == 0)
{
- *e->sp = (uintptr_t) 0;
+ e->sp->value = 0;
+ e->sp->text.len = 0;
+ e->sp->text.data = (u_char *) "";
+ e->sp++;
+
return;
}
}
}
- *e->sp = (uintptr_t) 1;
+ e->sp->value = 1;
+ e->sp->text.len = 1;
+ e->sp->text.data = (u_char *) "1";
+ e->sp++;
}
@@ -645,6 +798,29 @@ ngx_http_rewrite_nop_code(ngx_http_rewrite_engine_t *e)
}
+static ngx_http_variable_value_t *
+ngx_http_rewrite_var(ngx_http_request_t *r, uintptr_t data)
+{
+ ngx_http_variable_t *var;
+ ngx_http_core_main_conf_t *cmcf;
+
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
+
+ var = cmcf->variables.elts;
+
+ /*
+ * the ngx_http_rewrite_module sets variables directly in r->variables,
+ * and they should be handle by ngx_http_get_indexed_variable(),
+ * so the handler is called only if the variable is not initialized
+ */
+
+ ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
+ "using uninitialized \"%V\" variable", &var[data].name);
+
+ return &ngx_http_rewrite_null_value;
+}
+
+
static ngx_int_t
ngx_http_rewrite_init(ngx_cycle_t *cycle)
{
@@ -653,7 +829,7 @@ ngx_http_rewrite_init(ngx_cycle_t *cycle)
cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
- h = ngx_push_array(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers);
+ h = ngx_array_push(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers);
if (h == NULL) {
return NGX_ERROR;
}
@@ -669,7 +845,8 @@ ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_rewrite_loc_conf_t *conf;
- if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_rewrite_loc_conf_t)))) {
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_rewrite_loc_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -724,30 +901,53 @@ ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
conf->max_captures = regex->ncaptures;
}
code = (uintptr_t *) ((u_char *) code + regex->next);
+ continue;
}
if (*code == (uintptr_t) &ngx_http_rewrite_if_code) {
code += sizeof(ngx_http_rewrite_if_code_t) / sizeof(uintptr_t);
+ continue;
}
if (*code == (uintptr_t) &ngx_http_rewrite_return_code) {
code += sizeof(ngx_http_rewrite_return_code_t) / sizeof(uintptr_t);
+ continue;
+ }
+
+ if (*code == (uintptr_t) &ngx_http_rewrite_set_var_code) {
+ code += sizeof(ngx_http_rewrite_var_code_t) / sizeof(uintptr_t);
+ continue;
}
if (*code == (uintptr_t) &ngx_http_rewrite_var_code) {
code += sizeof(ngx_http_rewrite_var_code_t) / sizeof(uintptr_t);
+ continue;
+ }
+
+ if (*code == (uintptr_t) &ngx_http_rewrite_value_code) {
+ code += sizeof(ngx_http_rewrite_value_code_t) / sizeof(uintptr_t);
+ continue;
}
if (*code == (uintptr_t) &ngx_http_rewrite_invalid_referer_code) {
code++;
+ continue;
}
if (*code == (uintptr_t) &ngx_http_rewrite_nop_code) {
code++;
+ continue;
}
+
+#if (NGX_DEBUG)
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "unknown rewrite code: %p", *code);
+ return NGX_CONF_ERROR;
+#endif
}
- if (!(code = ngx_array_push_n(conf->codes, sizeof(uintptr_t)))) {
+ code = ngx_array_push_n(conf->codes, sizeof(uintptr_t));
+ if (code == NULL) {
return NGX_CONF_ERROR;
}
@@ -765,7 +965,8 @@ ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
u_char *data;
size_t len, size;
ngx_str_t *value, err;
- ngx_uint_t i, n, last;
+ ngx_int_t n;
+ ngx_uint_t i, last;
ngx_http_rewrite_code_pt *code;
ngx_http_rewrite_copy_code_t *copy;
ngx_http_rewrite_regex_code_t *regex;
@@ -797,6 +998,7 @@ ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
regex->size = 0;
regex->ncaptures = 0;
regex->status = 0;
+ regex->test = 0;
regex->uri = 1;
regex->args = 1;
regex->redirect = 0;
@@ -946,7 +1148,14 @@ ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
n = ngx_regex_capture_count(regex->regex);
- if (regex->ncaptures > n) {
+ if (n < 0) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ ngx_regex_capture_count_n " failed for "
+ "pattern \"%V\"", &value[1]);
+ return NGX_CONF_ERROR;
+ }
+
+ if (regex->ncaptures > (ngx_uint_t) n) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"pattern \"%V\" has less captures "
"than referrenced in substitution \"%V\"",
@@ -954,8 +1163,8 @@ ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}
- if (regex->ncaptures < n) {
- regex->ncaptures = n;
+ if (regex->ncaptures < (ngx_uint_t) n) {
+ regex->ncaptures = (ngx_uint_t) n;
}
if (regex->ncaptures) {
@@ -1028,20 +1237,16 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
void *mconf;
char *rv;
u_char *elts;
- ngx_str_t *value;
- ngx_int_t index;
ngx_uint_t i;
ngx_conf_t save;
- ngx_http_rewrite_code_pt *code;
ngx_http_module_t *module;
ngx_http_conf_ctx_t *ctx, *pctx;
ngx_http_core_loc_conf_t *clcf, *pclcf, **clcfp;
- ngx_http_core_main_conf_t *cmcf;
ngx_http_rewrite_if_code_t *if_code;
- ngx_http_rewrite_var_code_t *var_code;
ngx_http_rewrite_loc_conf_t *nlcf;
- if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) {
+ ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
+ if (ctx == NULL) {
return NGX_CONF_ERROR;
}
@@ -1063,7 +1268,8 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (module->create_loc_conf) {
- if (!(mconf = module->create_loc_conf(cf))) {
+ mconf = module->create_loc_conf(cf);
+ if (mconf == NULL) {
return NGX_CONF_ERROR;
}
@@ -1086,63 +1292,18 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
}
- if (!(clcfp = ngx_push_array(&pclcf->locations))) {
+ clcfp = ngx_array_push(&pclcf->locations);
+ if (clcfp == NULL) {
return NGX_CONF_ERROR;
}
*clcfp = clcf;
- /* STUB: "if ($var)" */
-
- value = cf->args->elts;
-
- if (value[1].len < 2
- || value[1].data[0] != '('
- || value[1].data[1] != '$'
- || value[1].data[value[1].len - 1] != ')')
- {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid condition \"%V\"", &value[1]);
+ if (ngx_http_rewrite_if_condition(cf, lcf) != NGX_CONF_OK) {
return NGX_CONF_ERROR;
}
- value[1].len -= 3;
- value[1].data += 2;
-
- if (value[1].len == sizeof("invalid_referer") - 1
- && ngx_strncmp(value[1].data, "invalid_referer",
- sizeof("invalid_referer") - 1) == 0)
- {
- code = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
- sizeof(ngx_http_rewrite_code_pt));
- if (code == NULL) {
- return NGX_CONF_ERROR;
- }
-
- *code = ngx_http_rewrite_invalid_referer_code;
-
- } else {
- cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
-
- index = ngx_http_get_variable_index(cmcf, &value[1]);
-
- if (index == -1) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "unknown variable name \"%V\"", &value[1]);
- return NGX_CONF_ERROR;
- }
-
- var_code = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
- sizeof(ngx_http_rewrite_var_code_t));
- if (var_code == NULL) {
- return NGX_CONF_ERROR;
- }
-
- var_code->code = ngx_http_rewrite_var_code;
- var_code->index = index;
- }
-
if_code = ngx_array_push_n(lcf->codes, sizeof(ngx_http_rewrite_if_code_t));
if (if_code == NULL) {
return NULL;
@@ -1193,6 +1354,156 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
static char *
+ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
+{
+ ngx_str_t *value, err;
+ ngx_uint_t cur, last;
+ ngx_http_rewrite_regex_code_t *regex;
+ u_char errstr[NGX_MAX_CONF_ERRSTR];
+
+ value = cf->args->elts;
+ last = cf->args->nelts - 1;
+
+ if (value[1].len < 1 || value[1].data[0] != '(') {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid condition \"%V\"", &value[1]);
+ return NGX_CONF_ERROR;
+ }
+
+ if (value[1].len == 1) {
+ cur = 2;
+
+ } else {
+ cur = 1;
+ value[1].len--;
+ value[1].data++;
+ }
+
+ if (value[last].len < 1 || value[last].data[value[last].len - 1] != ')') {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid condition \"%V\"", &value[last]);
+ return NGX_CONF_ERROR;
+ }
+
+ if (value[last].len == 1) {
+ last--;
+
+ } else {
+ value[last].len--;
+ value[last].data[value[last].len] = '\0';
+ }
+
+ if (value[cur].len > 1 && value[cur].data[0] == '$') {
+
+ if (cur != last && cur + 2 != last) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid condition \"%V\"", &value[cur]);
+ return NGX_CONF_ERROR;
+ }
+
+ if (ngx_http_rewrite_variable(cf, lcf, &value[cur])!= NGX_CONF_OK) {
+ return NGX_CONF_ERROR;
+ }
+
+ if (cur == last) {
+ return NGX_CONF_OK;
+ }
+
+ cur++;
+
+ if ((value[cur].len == 1 && value[cur].data[0] != '~')
+ || (value[cur].len == 2
+ && value[cur].data[0] != '~' && value[cur].data[1] != '*'))
+ {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "unexpected \"%V\" in condition", &value[cur]);
+ return NGX_CONF_ERROR;
+ }
+
+ regex = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
+ sizeof(ngx_http_rewrite_regex_code_t));
+ if (regex == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ err.len = NGX_MAX_CONF_ERRSTR;
+ err.data = errstr;
+
+ regex->regex = ngx_regex_compile(&value[last],
+ (value[cur].len == 2) ? NGX_REGEX_CASELESS : 0,
+ cf->pool, &err);
+
+ if (regex->regex == NULL) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
+ return NGX_CONF_ERROR;
+ }
+
+ regex->code = ngx_http_rewrite_regex_start_code;
+ regex->size = 0;
+ regex->ncaptures = 0;
+ regex->status = 0;
+ regex->next = sizeof(ngx_http_rewrite_regex_code_t);
+ regex->test = 1;
+ regex->uri = 0;
+ regex->args = 0;
+ regex->redirect = 0;
+ regex->name = value[last];
+
+ return NGX_CONF_OK;
+ }
+
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid condition \"%V\"", &value[cur]);
+
+ return NGX_CONF_ERROR;
+}
+
+
+static char *
+ngx_http_rewrite_variable(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf,
+ ngx_str_t *value)
+{
+ ngx_http_variable_t *var;
+ ngx_http_rewrite_code_pt *code;
+ ngx_http_rewrite_var_code_t *var_code;
+
+ value->len--;
+ value->data++;
+
+ if (value->len == sizeof("invalid_referer") - 1
+ && ngx_strncmp(value->data, "invalid_referer",
+ sizeof("invalid_referer") - 1) == 0)
+ {
+ code = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
+ sizeof(ngx_http_rewrite_code_pt));
+ if (code == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ *code = ngx_http_rewrite_invalid_referer_code;
+
+ } else {
+ var = ngx_http_add_variable(cf, value, 0);
+
+ if (var == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ var_code = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
+ sizeof(ngx_http_rewrite_var_code_t));
+ if (var_code == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ var_code->code = ngx_http_rewrite_var_code;
+ var_code->index = var->index;
+ }
+
+ return NGX_CONF_OK;
+}
+
+
+static char *
ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_rewrite_loc_conf_t *lcf = conf;
@@ -1234,7 +1545,8 @@ ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
continue;
}
- if (!(ref = ngx_array_push(lcf->referers))) {
+ ref = ngx_array_push(lcf->referers);
+ if (ref == NULL) {
return NGX_CONF_ERROR;
}
@@ -1261,12 +1573,14 @@ ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
sn = cscf->server_names.elts;
for (i = 0; i < cscf->server_names.nelts; i++) {
- if (!(ref = ngx_array_push(lcf->referers))) {
+ ref = ngx_array_push(lcf->referers);
+ if (ref == NULL) {
return NGX_CONF_ERROR;
}
ref->name.len = sn[i].name.len + 1;
- if (!(ref->name.data = ngx_palloc(cf->pool, ref->name.len))) {
+ ref->name.data = ngx_palloc(cf->pool, ref->name.len);
+ if (ref->name.data == NULL) {
return NGX_CONF_ERROR;
}
@@ -1279,11 +1593,72 @@ ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
+static char *
+ngx_http_rewrite_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+ ngx_http_rewrite_loc_conf_t *lcf = conf;
+
+ ngx_int_t n;
+ ngx_str_t *value;
+ ngx_http_variable_t *v;
+ ngx_http_rewrite_var_code_t *var;
+ ngx_http_rewrite_value_code_t *val;
+
+ value = cf->args->elts;
+
+ if (value[1].data[0] != '$') {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid variable name \"%V\"", &value[1]);
+ return NGX_CONF_ERROR;
+ }
+
+ value[1].len--;
+ value[1].data++;
+
+ v = ngx_http_add_variable(cf, &value[1], 1);
+ if (v == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ v->handler = ngx_http_rewrite_var;
+ v->data = v->index;
+
+ val = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
+ sizeof(ngx_http_rewrite_value_code_t));
+ if (val == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ n = ngx_atoi(value[2].data, value[2].len);
+
+ if (n == NGX_ERROR) {
+ n = 0;
+ }
+
+ val->code = ngx_http_rewrite_value_code;
+ val->value = (uintptr_t) n;
+ val->text_len = (uintptr_t) value[2].len;
+ val->text_data = (uintptr_t) value[2].data;
+
+ var = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
+ sizeof(ngx_http_rewrite_var_code_t));
+ if (var == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ var->code = ngx_http_rewrite_set_var_code;
+ var->index = (uintptr_t) v->index;
+
+ return NGX_CONF_OK;
+}
+
+
static void *
ngx_http_rewrite_start_code(ngx_pool_t *pool, ngx_array_t **codes, size_t size)
{
if (*codes == NULL) {
- if (!(*codes = ngx_array_create(pool, 256, 1))) {
+ *codes = ngx_array_create(pool, 256, 1);
+ if (*codes == NULL) {
return NULL;
}
}
@@ -1300,7 +1675,8 @@ ngx_http_rewrite_add_code(ngx_array_t *codes, size_t size, void *code)
elts = codes->elts;
- if (!(new = ngx_array_push_n(codes, size))) {
+ new = ngx_array_push_n(codes, size);
+ if (new == NULL) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/ngx_http_ssi_filter.c b/src/http/modules/ngx_http_ssi_filter_module.c
index ca877ac94..a351747b5 100644
--- a/src/http/modules/ngx_http_ssi_filter.c
+++ b/src/http/modules/ngx_http_ssi_filter_module.c
@@ -98,8 +98,6 @@ typedef enum {
} ngx_http_ssi_state_e;
-static ngx_int_t ngx_http_ssi_error(ngx_http_request_t *r,
- ngx_http_ssi_ctx_t *ctx);
static ngx_int_t ngx_http_ssi_parse(ngx_http_request_t *r,
ngx_http_ssi_ctx_t *ctx);
@@ -1147,21 +1145,25 @@ static ngx_int_t
ngx_http_ssi_echo(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
ngx_str_t **params)
{
+ ngx_uint_t i;
ngx_buf_t *b;
ngx_str_t *var, *value;
ngx_chain_t *cl;
- ngx_http_variable_value_t *v;
+ ngx_http_variable_value_t *vv;
var = params[NGX_HTTP_SSI_ECHO_VAR];
- value = NULL;
- v = ngx_http_get_variable(r, var);
+ for (i = 0; i < var->len; i++) {
+ var->data[i] = ngx_toupper(var->data[i]);
+ }
+
+ vv = ngx_http_get_variable(r, var);
- if (v == NULL) {
+ if (vv == NULL) {
return NGX_HTTP_SSI_ERROR;
}
- if (v == NGX_HTTP_VARIABLE_NOT_FOUND) {
+ if (vv == NGX_HTTP_VARIABLE_NOT_FOUND) {
value = params[NGX_HTTP_SSI_ECHO_DEFAULT];
if (value == NULL) {
@@ -1172,7 +1174,7 @@ ngx_http_ssi_echo(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
}
} else {
- value = &v->text;
+ value = &vv->text;
if (value->len == 0) {
return NGX_OK;
diff --git a/src/http/modules/ngx_http_ssl_module.c b/src/http/modules/ngx_http_ssl_module.c
index 883e44fbc..1c4128ca1 100644
--- a/src/http/modules/ngx_http_ssl_module.c
+++ b/src/http/modules/ngx_http_ssl_module.c
@@ -19,7 +19,7 @@ static void *ngx_http_ssl_create_main_conf(ngx_conf_t *cf);
static char *ngx_http_ssl_init_main_conf(ngx_conf_t *cf, void *conf);
static void *ngx_http_ssl_create_srv_conf(ngx_conf_t *cf);
static char *ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf,
- void *parent, void *child);
+ void *parent, void *child);
static ngx_command_t ngx_http_ssl_commands[] = {
@@ -87,11 +87,13 @@ ngx_module_t ngx_http_ssl_module = {
};
-static void *ngx_http_ssl_create_main_conf(ngx_conf_t *cf)
+static void *
+ngx_http_ssl_create_main_conf(ngx_conf_t *cf)
{
ngx_http_ssl_main_conf_t *mcf;
- if (!(mcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssl_main_conf_t)))) {
+ mcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssl_main_conf_t));
+ if (mcf == NULL) {
return NGX_CONF_ERROR;
}
@@ -106,7 +108,8 @@ static void *ngx_http_ssl_create_main_conf(ngx_conf_t *cf)
}
-static char *ngx_http_ssl_init_main_conf(ngx_conf_t *cf, void *conf)
+static char *
+ngx_http_ssl_init_main_conf(ngx_conf_t *cf, void *conf)
{
ngx_http_ssl_main_conf_t *mcf = conf;
@@ -137,11 +140,13 @@ static char *ngx_http_ssl_init_main_conf(ngx_conf_t *cf, void *conf)
}
-static void *ngx_http_ssl_create_srv_conf(ngx_conf_t *cf)
+static void *
+ngx_http_ssl_create_srv_conf(ngx_conf_t *cf)
{
ngx_http_ssl_srv_conf_t *scf;
- if (!(scf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssl_srv_conf_t)))) {
+ scf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssl_srv_conf_t));
+ if (scf == NULL) {
return NGX_CONF_ERROR;
}
@@ -162,8 +167,8 @@ static void *ngx_http_ssl_create_srv_conf(ngx_conf_t *cf)
}
-static char *ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf,
- void *parent, void *child)
+static char *
+ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_ssl_srv_conf_t *prev = parent;
ngx_http_ssl_srv_conf_t *conf = child;
@@ -226,7 +231,8 @@ static char *ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf,
#if 0
-static ngx_int_t ngx_http_ssl_init_process(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_ssl_init_process(ngx_cycle_t *cycle)
{
ngx_uint_t i;
ngx_http_ssl_srv_conf_t *sscf;
diff --git a/src/http/modules/ngx_http_ssl_module.h b/src/http/modules/ngx_http_ssl_module.h
index 87166877f..bf6036634 100644
--- a/src/http/modules/ngx_http_ssl_module.h
+++ b/src/http/modules/ngx_http_ssl_module.h
@@ -32,7 +32,7 @@ typedef struct {
ngx_int_t ngx_http_ssl_read(ngx_http_request_t *r, u_char *buf, size_t size);
ngx_int_t ngx_http_ssl_shutdown(ngx_http_request_t *r);
ngx_chain_t *ngx_http_ssl_write(ngx_connection_t *c, ngx_chain_t *in,
- off_t limit);
+ off_t limit);
void ngx_http_ssl_close_connection(SSL *ssl, ngx_log_t *log);
diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_module.c
index 4f0f96dc0..c2c45828f 100644
--- a/src/http/modules/ngx_http_static_handler.c
+++ b/src/http/modules/ngx_http_static_module.c
@@ -75,10 +75,13 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
ngx_buf_t *b;
ngx_chain_t out;
ngx_file_info_t fi;
- ngx_http_cleanup_t *file_cleanup, *redirect_cleanup;
+ ngx_http_cleanup_t *file_cleanup;
+#if (NGX_HTTP_CACHE)
+ ngx_http_cleanup_t *redirect_cleanup;
+#endif
ngx_http_core_loc_conf_t *clcf;
- ngx_http_static_loc_conf_t *slcf;
#if (NGX_HTTP_CACHE)
+ ngx_http_static_loc_conf_t *slcf;
uint32_t file_crc, redirect_crc;
ngx_http_cache_t *file, *redirect;
#endif
@@ -176,14 +179,18 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
/* allocate cleanups */
- if (!(file_cleanup = ngx_push_array(&r->cleanup))) {
+ file_cleanup = ngx_array_push(&r->cleanup);
+ if (file_cleanup == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
file_cleanup->valid = 0;
+#if (NGX_HTTP_CACHE)
+
slcf = ngx_http_get_module_loc_conf(r, ngx_http_static_module);
if (slcf->redirect_cache) {
- if (!(redirect_cleanup = ngx_push_array(&r->cleanup))) {
+ redirect_cleanup = ngx_array_push(&r->cleanup);
+ if (redirect_cleanup == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
redirect_cleanup->valid = 0;
@@ -192,8 +199,6 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
redirect_cleanup = NULL;
}
-#if (NGX_HTTP_CACHE)
-
/* look up an open files cache */
if (clcf->open_files) {
@@ -232,9 +237,9 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
* should keep more popular redirects in cache.
*/
- if (!(r->headers_out.location =
- ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
- {
+ r->headers_out.location = ngx_http_add_header(&r->headers_out,
+ ngx_http_headers_out);
+ if (r->headers_out.location == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -283,9 +288,9 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
"HTTP DIR: \"%s\"", name.data);
- if (!(r->headers_out.location =
- ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
- {
+ r->headers_out.location = ngx_http_add_header(&r->headers_out,
+ ngx_http_headers_out);
+ if (r->headers_out.location == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -506,11 +511,13 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
if (!r->header_only) {
/* we need to allocate all before the header would be sent */
- if (!(b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)))) {
+ b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
+ if (b == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
- if (!(b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)))) {
+ b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
+ if (b->file == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -547,7 +554,8 @@ static void *ngx_http_static_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_static_loc_conf_t *conf;
- if (!(conf = ngx_palloc(cf->pool, sizeof(ngx_http_static_loc_conf_t)))) {
+ conf = ngx_palloc(cf->pool, sizeof(ngx_http_static_loc_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -578,7 +586,7 @@ static ngx_int_t ngx_http_static_init(ngx_cycle_t *cycle)
cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
- h = ngx_push_array(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
+ h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
if (h == NULL) {
return NGX_ERROR;
}
diff --git a/src/http/modules/ngx_http_status_handler.c b/src/http/modules/ngx_http_status_module.c
index ce49ae426..ce49ae426 100644
--- a/src/http/modules/ngx_http_status_handler.c
+++ b/src/http/modules/ngx_http_status_module.c
diff --git a/src/http/modules/ngx_http_stub_status_module.c b/src/http/modules/ngx_http_stub_status_module.c
index 7eeef5986..1a01bcea8 100644
--- a/src/http/modules/ngx_http_stub_status_module.c
+++ b/src/http/modules/ngx_http_stub_status_module.c
@@ -88,7 +88,8 @@ static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r)
+ 6 + 3 * NGX_ATOMIC_T_LEN
+ sizeof("Reading: Writing: Waiting: \n") + 3 * NGX_ATOMIC_T_LEN;
- if (!(b = ngx_create_temp_buf(r->pool, size))) {
+ b = ngx_create_temp_buf(r->pool, size);
+ if (b == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
diff --git a/src/http/modules/ngx_http_userid_filter.c b/src/http/modules/ngx_http_userid_filter_module.c
index ea49f928b..62d40ac34 100644
--- a/src/http/modules/ngx_http_userid_filter.c
+++ b/src/http/modules/ngx_http_userid_filter_module.c
@@ -618,7 +618,7 @@ ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data)
}
p = ngx_cpymem(new, "; domain=", sizeof("; domain=") - 1);
- p = ngx_cpymem(p, domain->data, domain->len);
+ ngx_memcpy(p, domain->data, domain->len);
domain->len += sizeof("; domain=") - 1;
domain->data = new;
@@ -640,7 +640,7 @@ ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data)
}
p = ngx_cpymem(new, "; path=", sizeof("; path=") - 1);
- p = ngx_cpymem(p, path->data, path->len);
+ ngx_memcpy(p, path->data, path->len);
path->len += sizeof("; path=") - 1;
path->data = new;
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index d213d6929..edad22cdf 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -11,7 +11,9 @@
static ngx_int_t ngx_http_proxy_handler(ngx_http_request_t *r);
+#if 0
static ngx_int_t ngx_http_proxy_cache_get(ngx_http_proxy_ctx_t *p);
+#endif
static size_t ngx_http_proxy_log_proxy_state_getlen(ngx_http_request_t *r,
uintptr_t data);
@@ -33,8 +35,6 @@ static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf,
static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
-static char *ngx_http_proxy_parse_upstream(ngx_str_t *url,
- ngx_http_proxy_upstream_conf_t *u);
static char *ngx_http_proxy_set_x_var(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
@@ -362,13 +362,20 @@ static ngx_str_t cache_reasons[] = {
};
+static ngx_str_t ngx_http_proxy_uri = ngx_string("/");
+
+
static ngx_int_t ngx_http_proxy_handler(ngx_http_request_t *r)
{
ngx_http_proxy_ctx_t *p;
- ngx_http_create_ctx(r, p, ngx_http_proxy_module,
- sizeof(ngx_http_proxy_ctx_t),
- NGX_HTTP_INTERNAL_SERVER_ERROR);
+ p = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_ctx_t));
+ if (p == NULL) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ ngx_http_set_ctx(r, p, ngx_http_proxy_module);
+
p->lcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
p->request = r;
@@ -382,7 +389,8 @@ static ngx_int_t ngx_http_proxy_handler(ngx_http_request_t *r)
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
- if (!(p->state = ngx_array_push(&p->states))) {
+ p->state = ngx_array_push(&p->states);
+ if (p->state == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -439,7 +447,8 @@ static ngx_int_t ngx_http_proxy_cache_get(ngx_http_proxy_ctx_t *p)
u = p->lcf->upstream;
ctx.key.len = u->url.len + r->uri.len - u->location->len + r->args.len;
- if (!(ctx.key.data = ngx_palloc(r->pool, ctx.key.len))) {
+ ctx.key.data = ngx_palloc(r->pool, ctx.key.len);
+ if (ctx.key.data == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -1072,7 +1081,8 @@ static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_proxy_loc_conf_t *conf;
- if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_loc_conf_t)))) {
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_loc_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -1332,7 +1342,8 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
unix_upstream.url.data = url->data + 7;
unix_upstream.uri_part = 1;
- if (!(lcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream))) {
+ lcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream);
+ if (lcf->peers == NULL) {
return NGX_CONF_ERROR;
}
@@ -1359,7 +1370,8 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
inet_upstream.default_port_value = 80;
inet_upstream.uri_part = 1;
- if (!(lcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream))) {
+ lcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream);
+ if (lcf->peers == NULL) {
return NGX_CONF_ERROR;
}
@@ -1372,9 +1384,14 @@ static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
- lcf->upstream->location = &clcf->name;
clcf->handler = ngx_http_proxy_handler;
+#if (NGX_PCRE)
+ lcf->upstream->location = clcf->regex ? &ngx_http_proxy_uri : &clcf->name;
+#else
+ lcf->upstream->location = &clcf->name;
+#endif
+
if (clcf->name.data[clcf->name.len - 1] == '/') {
clcf->auto_redirect = 1;
}
@@ -1409,7 +1426,8 @@ static char *ngx_http_proxy_set_x_var(ngx_conf_t *cf, ngx_command_t *cmd,
for (i = 0; i < cmcf->variables.nelts; i++) {
if (ngx_strcasecmp(var[i].name.data, value[1].data) == 0) {
- if (!(index = ngx_array_push(lcf->x_vars))) {
+ index = ngx_array_push(lcf->x_vars);
+ if (index == NULL) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/proxy/ngx_http_proxy_header.c b/src/http/modules/proxy/ngx_http_proxy_header.c
index 78ae6530f..a46ff9e2a 100644
--- a/src/http/modules/proxy/ngx_http_proxy_header.c
+++ b/src/http/modules/proxy/ngx_http_proxy_header.c
@@ -87,7 +87,8 @@ int ngx_http_proxy_copy_header(ngx_http_proxy_ctx_t *p,
/* copy some header pointers and set up r->headers_out */
- if (!(ho = ngx_list_push(&r->headers_out.headers))) {
+ ho = ngx_list_push(&r->headers_out.headers);
+ if (ho == NULL) {
return NGX_ERROR;
}
@@ -162,7 +163,8 @@ static int ngx_http_proxy_rewrite_location_header(ngx_http_proxy_ctx_t *p,
r = p->request;
uc = p->lcf->upstream;
- if (!(location = ngx_list_push(&r->headers_out.headers))) {
+ location = ngx_list_push(&r->headers_out.headers);
+ if (location == NULL) {
return NGX_ERROR;
}
@@ -189,7 +191,8 @@ static int ngx_http_proxy_rewrite_location_header(ngx_http_proxy_ctx_t *p,
location->value.len = uc->location->len
+ (loc->value.len - uc->url.len) + 1;
- if (!(location->value.data = ngx_palloc(r->pool, location->value.len))) {
+ location->value.data = ngx_palloc(r->pool, location->value.len);
+ if (location->value.data == NULL) {
return NGX_ERROR;
}
diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c
index 061ab9f0e..45dc04d70 100644
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -58,7 +58,8 @@ int ngx_http_proxy_request_upstream(ngx_http_proxy_ctx_t *p)
r = p->request;
- if (!(u = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_upstream_t)))) {
+ u = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_upstream_t));
+ if (u == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -85,7 +86,7 @@ int ngx_http_proxy_request_upstream(ngx_http_proxy_ctx_t *p)
static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
{
- size_t len;
+ size_t len, loc_len;
ngx_uint_t i, escape, *index;
ngx_buf_t *b;
ngx_chain_t *chain;
@@ -94,6 +95,7 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
ngx_http_request_t *r;
ngx_http_variable_t *var;
ngx_http_variable_value_t *value;
+ ngx_http_core_loc_conf_t *clcf;
ngx_http_core_main_conf_t *cmcf;
ngx_http_proxy_upstream_conf_t *uc;
@@ -112,16 +114,23 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
len = r->method_name.len;
}
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
+#if (NGX_PCRE)
+ loc_len = (clcf->regex) ? 1 : clcf->name.len;
+#else
+ loc_len = clcf->name.len;
+#endif
+
if (r->quoted_uri) {
- escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len,
- r->uri.len - uc->location->len,
- NGX_ESCAPE_URI);
+ escape = 2 * ngx_escape_uri(NULL, r->uri.data + loc_len,
+ r->uri.len - loc_len, NGX_ESCAPE_URI);
} else {
escape = 0;
}
len += uc->uri.len
- + r->uri.len - uc->location->len + escape
+ + r->uri.len - loc_len + escape
+ sizeof("?") - 1 + r->args.len
+ sizeof(http_version) - 1
+ sizeof(connection_close_header) - 1
@@ -190,7 +199,8 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
for (i = 0; i < p->lcf->x_vars->nelts; i++) {
- if (!(value = ngx_http_get_indexed_variable(r, index[i]))) {
+ value = ngx_http_get_indexed_variable(r, index[i]);
+ if (value == NULL) {
continue;
}
@@ -233,11 +243,13 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
len++;
#endif
- if (!(b = ngx_create_temp_buf(r->pool, len))) {
+ b = ngx_create_temp_buf(r->pool, len);
+ if (b == NULL) {
return NULL;
}
- if (!(chain = ngx_alloc_chain_link(r->pool))) {
+ chain = ngx_alloc_chain_link(r->pool);
+ if (chain == NULL) {
return NULL;
}
@@ -258,14 +270,13 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
b->last = ngx_cpymem(b->last, uc->uri.data, uc->uri.len);
if (escape) {
- ngx_escape_uri(b->last, r->uri.data + uc->location->len,
- r->uri.len - uc->location->len, NGX_ESCAPE_URI);
- b->last += r->uri.len - uc->location->len + escape;
+ ngx_escape_uri(b->last, r->uri.data + loc_len,
+ r->uri.len - loc_len, NGX_ESCAPE_URI);
+ b->last += r->uri.len - loc_len + escape;
} else {
- b->last = ngx_cpymem(b->last,
- r->uri.data + uc->location->len,
- r->uri.len - uc->location->len);
+ b->last = ngx_cpymem(b->last, r->uri.data + loc_len,
+ r->uri.len - loc_len);
}
if (r->args.len > 0) {
@@ -379,7 +390,8 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
if (p->lcf->x_vars) {
for (i = 0; i < p->lcf->x_vars->nelts; i++) {
- if (!(value = ngx_http_get_indexed_variable(r, index[i]))) {
+ value = ngx_http_get_indexed_variable(r, index[i]);
+ if (value == NULL) {
continue;
}
@@ -506,7 +518,8 @@ static void ngx_http_proxy_init_upstream(ngx_http_request_t *r)
}
- if (!(cl = ngx_http_proxy_create_request(p))) {
+ cl = ngx_http_proxy_create_request(p);
+ if (cl == NULL) {
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
@@ -517,7 +530,8 @@ static void ngx_http_proxy_init_upstream(ngx_http_request_t *r)
r->request_body->bufs = cl;
- if (!(ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_log_ctx_t)))) {
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_log_ctx_t));
+ if (ctx == NULL) {
ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
@@ -531,7 +545,8 @@ static void ngx_http_proxy_init_upstream(ngx_http_request_t *r)
r->connection->log->handler = ngx_http_proxy_log_error;
p->action = "connecting to upstream";
- if (!(output = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t)))) {
+ output = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t));
+ if (output == NULL) {
ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
@@ -544,7 +559,8 @@ static void ngx_http_proxy_init_upstream(ngx_http_request_t *r)
output->tag = (ngx_buf_tag_t) &ngx_http_proxy_module;
output->output_filter = ngx_chain_writer;
- if (!(writer = ngx_palloc(r->pool, sizeof(ngx_chain_writer_ctx_t)))) {
+ writer = ngx_palloc(r->pool, sizeof(ngx_chain_writer_ctx_t));
+ if (writer == NULL) {
ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
@@ -603,7 +619,8 @@ static void ngx_http_proxy_reinit_upstream(ngx_http_proxy_ctx_t *p)
state = p->state->cache_state;
- if (!(p->state = ngx_push_array(&p->states))) {
+ p->state = ngx_array_push(&p->states);
+ if (p->state == NULL) {
ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
@@ -775,7 +792,8 @@ static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p)
if (r->request_body->buf) {
if (r->request_body->temp_file) {
- if (!(output->free = ngx_alloc_chain_link(r->pool))) {
+ output->free = ngx_alloc_chain_link(r->pool);
+ if (output->free == NULL) {
ngx_http_proxy_finalize_request(p,
NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
@@ -1005,7 +1023,7 @@ static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev)
rc = ngx_http_proxy_parse_status_line(p);
if (rc == NGX_AGAIN) {
- if (p->header_in->pos == p->header_in->last) {
+ if (p->header_in->pos == p->header_in->end) {
ngx_log_error(NGX_LOG_ERR, rev->log, 0,
"upstream sent too long status line");
ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_INVALID_HEADER);
@@ -1158,7 +1176,8 @@ static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev)
/* a header line has been parsed successfully */
- if (!(h = ngx_list_push(&p->upstream->headers_in.headers))) {
+ h = ngx_list_push(&p->upstream->headers_in.headers);
+ if (h == NULL) {
ngx_http_proxy_finalize_request(p,
NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
@@ -1315,6 +1334,11 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
rc = ngx_http_send_header(r);
+ if (rc == NGX_ERROR || rc > NGX_OK) {
+ ngx_http_proxy_finalize_request(p, rc);
+ return;
+ }
+
p->header_sent = 1;
if (p->cache && p->cache->ctx.file.fd != NGX_INVALID_FILE) {
@@ -1361,7 +1385,8 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
ep->cachable = p->cachable;
- if (!(ep->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)))) {
+ ep->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
+ if (ep->temp_file == NULL) {
ngx_http_proxy_finalize_request(p, 0);
return;
}
@@ -1381,7 +1406,8 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
ep->max_temp_file_size = p->lcf->max_temp_file_size;
ep->temp_file_write_size = p->lcf->temp_file_write_size;
- if (!(ep->preread_bufs = ngx_alloc_chain_link(r->pool))) {
+ ep->preread_bufs = ngx_alloc_chain_link(r->pool);
+ if (ep->preread_bufs == NULL) {
ngx_http_proxy_finalize_request(p, 0);
return;
}
@@ -1467,7 +1493,6 @@ static void ngx_http_proxy_process_body(ngx_event_t *ev)
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0,
"http proxy process upstream");
p = c->data;
- r = p->request;
p->action = "reading upstream body";
}
diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c
index f9c926091..e4c8f2e9c 100644
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -92,7 +92,8 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
/* the main http context */
- if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) {
+ ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
+ if (ctx == NULL) {
return NGX_CONF_ERROR;
}
@@ -162,19 +163,22 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
if (module->create_main_conf) {
- if (!(ctx->main_conf[mi] = module->create_main_conf(cf))) {
+ ctx->main_conf[mi] = module->create_main_conf(cf);
+ if (ctx->main_conf[mi] == NULL) {
return NGX_CONF_ERROR;
}
}
if (module->create_srv_conf) {
- if (!(ctx->srv_conf[mi] = module->create_srv_conf(cf))) {
+ ctx->srv_conf[mi] = module->create_srv_conf(cf);
+ if (ctx->srv_conf[mi] == NULL) {
return NGX_CONF_ERROR;
}
}
if (module->create_loc_conf) {
- if (!(ctx->loc_conf[mi] = module->create_loc_conf(cf))) {
+ ctx->loc_conf[mi] = module->create_loc_conf(cf);
+ if (ctx->loc_conf[mi] == NULL) {
return NGX_CONF_ERROR;
}
}
@@ -261,13 +265,14 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
/* we needed http{}'s cf->ctx while the merging configuration */
+
*cf = pcf;
/* init lists of the handlers */
if (ngx_array_init(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers,
- cf->pool, 1, sizeof(ngx_http_handler_pt)) == NGX_ERROR)
+ cf->pool, 1, sizeof(ngx_http_handler_pt)) != NGX_OK)
{
return NGX_CONF_ERROR;
}
@@ -278,14 +283,14 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
/* the special find config phase for a single handler */
if (ngx_array_init(&cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].handlers,
- cf->pool, 1, sizeof(ngx_http_handler_pt)) == NGX_ERROR)
+ cf->pool, 1, sizeof(ngx_http_handler_pt)) != NGX_OK)
{
return NGX_CONF_ERROR;
}
cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].type = NGX_OK;
- h = ngx_push_array(&cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].handlers);
+ h = ngx_array_push(&cmcf->phases[NGX_HTTP_FIND_CONFIG_PHASE].handlers);
if (h == NULL) {
return NGX_CONF_ERROR;
}
@@ -294,7 +299,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (ngx_array_init(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers,
- cf->pool, 1, sizeof(ngx_http_handler_pt)) == NGX_ERROR)
+ cf->pool, 1, sizeof(ngx_http_handler_pt)) != NGX_OK)
{
return NGX_CONF_ERROR;
}
@@ -303,7 +308,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (ngx_array_init(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers,
- cf->pool, 4, sizeof(ngx_http_handler_pt)) == NGX_ERROR)
+ cf->pool, 4, sizeof(ngx_http_handler_pt)) != NGX_OK)
{
return NGX_CONF_ERROR;
}
@@ -317,7 +322,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
*/
if (ngx_array_init(&in_ports, cf->pool, 10, sizeof(ngx_http_in_port_t))
- == NGX_ERROR)
+ != NGX_OK)
{
return NGX_CONF_ERROR;
}
@@ -354,7 +359,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
/* the address is already in the address list */
if (ngx_http_add_names(cf, &in_addr[a], cscfp[s])
- == NGX_ERROR)
+ != NGX_OK)
{
return NGX_CONF_ERROR;
}
@@ -386,7 +391,8 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
/* the INADDR_ANY is always the last address */
- if (!(inaddr = ngx_array_push(&in_port[p].addrs))) {
+ inaddr = ngx_array_push(&in_port[p].addrs);
+ if (inaddr == NULL) {
return NGX_CONF_ERROR;
}
@@ -407,7 +413,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
in_addr[a].core_srv_conf = cscfp[s];
if (ngx_http_add_names(cf, &in_addr[a], cscfp[s])
- == NGX_ERROR)
+ != NGX_OK)
{
return NGX_CONF_ERROR;
}
@@ -426,7 +432,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
*/
if (ngx_http_add_address(cf, &in_port[p], &lscf[l],
- cscfp[s]) == NGX_ERROR)
+ cscfp[s]) != NGX_OK)
{
return NGX_CONF_ERROR;
}
@@ -438,14 +444,16 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
/* add the port to the in_port list */
- if (!(in_port = ngx_array_push(&in_ports))) {
+ in_port = ngx_array_push(&in_ports);
+ if (in_port == NULL) {
return NGX_CONF_ERROR;
}
in_port->port = lscf[l].port;
in_port->addrs.elts = NULL;
- if (!(in_port->port_text.data = ngx_palloc(cf->pool, 7))) {
+ in_port->port_text.data = ngx_palloc(cf->pool, 7);
+ if (in_port->port_text.data == NULL) {
return NGX_CONF_ERROR;
}
@@ -454,7 +462,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
- in_port->port_text.data;
if (ngx_http_add_address(cf, in_port, &lscf[l], cscfp[s])
- == NGX_ERROR)
+ != NGX_OK)
{
return NGX_CONF_ERROR;
}
@@ -484,7 +492,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
for (n = 0; n < in_addr[a].names.nelts; n++) {
if (in_addr[a].core_srv_conf != name[n].core_srv_conf
|| name[n].core_srv_conf->restrict_host_names
- != NGX_HTTP_RESTRICT_HOST_OFF)
+ != NGX_HTTP_RESTRICT_HOST_OFF)
{
virtual_names = 1;
break;
@@ -496,7 +504,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
for (n = 0; n < in_addr[a].wildcards.nelts; n++) {
if (in_addr[a].core_srv_conf != name[n].core_srv_conf
|| name[n].core_srv_conf->restrict_host_names
- != NGX_HTTP_RESTRICT_HOST_OFF)
+ != NGX_HTTP_RESTRICT_HOST_OFF)
{
virtual_names = 1;
break;
@@ -532,7 +540,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
for (n = 0; n < cmcf->server_names_hash; n++) {
if (ngx_array_init(&in_addr[a].hash[n], cf->pool, 5,
- sizeof(ngx_http_server_name_t)) == NGX_ERROR)
+ sizeof(ngx_http_server_name_t)) != NGX_OK)
{
return NGX_CONF_ERROR;
}
@@ -544,7 +552,8 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
name[s].name.len,
cmcf->server_names_hash);
- if (!(s_name = ngx_array_push(&in_addr[a].hash[key]))) {
+ s_name = ngx_array_push(&in_addr[a].hash[key]);
+ if (s_name == NULL) {
return NGX_CONF_ERROR;
}
@@ -575,13 +584,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
ls->backlog = -1;
-#if 0
-#if 0
- ls->nonblocking = 1;
-#else
- ls->nonblocking = 0;
-#endif
-#endif
+
ls->addr_ntop = 1;
ls->handler = ngx_http_init_connection;
@@ -612,19 +615,21 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
* the separate ngx_http_in_port_t for the all bindings
*/
- ngx_test_null(inport,
- ngx_palloc(cf->pool,
- sizeof(ngx_http_in_port_t)),
- NGX_CONF_ERROR);
+ inport = ngx_palloc(cf->pool, sizeof(ngx_http_in_port_t));
+ if (inport == NULL) {
+ return NGX_CONF_ERROR;
+ }
inport->port = in_port[p].port;
inport->port_text = in_port[p].port_text;
/* init list of the addresses ... */
- ngx_init_array(inport->addrs, cf->pool, 1,
- sizeof(ngx_http_in_addr_t),
- NGX_CONF_ERROR);
+ if (ngx_array_init(&inport->addrs, cf->pool, 1,
+ sizeof(ngx_http_in_addr_t)) != NGX_OK)
+ {
+ return NGX_CONF_ERROR;
+ }
/* ... and set up it with the first address */
@@ -636,7 +641,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
/* prepare for the next cycle */
in_port[p].addrs.elts = (char *) in_port[p].addrs.elts
- + in_port[p].addrs.size;
+ + in_port[p].addrs.size;
in_port[p].addrs.nelts--;
in_addr = (ngx_http_in_addr_t *) in_port[p].addrs.elts;
@@ -705,13 +710,14 @@ ngx_http_add_address(ngx_conf_t *cf, ngx_http_in_port_t *in_port,
if (in_port->addrs.elts == NULL) {
if (ngx_array_init(&in_port->addrs, cf->pool, 10,
- sizeof(ngx_http_in_addr_t)) == NGX_ERROR)
+ sizeof(ngx_http_in_addr_t)) != NGX_OK)
{
return NGX_ERROR;
}
}
- if (!(in_addr = ngx_array_push(&in_port->addrs))) {
+ in_addr = ngx_array_push(&in_port->addrs);
+ if (in_addr == NULL) {
return NGX_ERROR;
}
@@ -750,7 +756,7 @@ ngx_http_add_names(ngx_conf_t *cf, ngx_http_in_addr_t *in_addr,
if (in_addr->names.elts == NULL) {
if (ngx_array_init(&in_addr->names, cf->pool, 10,
- sizeof(ngx_http_server_name_t)) == NGX_ERROR)
+ sizeof(ngx_http_server_name_t)) != NGX_OK)
{
return NGX_ERROR;
}
@@ -758,7 +764,7 @@ ngx_http_add_names(ngx_conf_t *cf, ngx_http_in_addr_t *in_addr,
if (in_addr->wildcards.elts == NULL) {
if (ngx_array_init(&in_addr->wildcards, cf->pool, 10,
- sizeof(ngx_http_server_name_t)) == NGX_ERROR)
+ sizeof(ngx_http_server_name_t)) != NGX_OK)
{
return NGX_ERROR;
}
@@ -785,7 +791,8 @@ ngx_http_add_names(ngx_conf_t *cf, ngx_http_in_addr_t *in_addr,
array = &in_addr->names;
}
- if (!(name = ngx_array_push(array))) {
+ name = ngx_array_push(array);
+ if (name == NULL) {
return NGX_ERROR;
}
diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h
index 6f19af1c8..2d4158f1a 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -16,6 +16,8 @@ typedef struct ngx_http_request_s ngx_http_request_t;
typedef struct ngx_http_log_ctx_s ngx_http_log_ctx_t;
typedef struct ngx_http_cleanup_s ngx_http_cleanup_t;
typedef struct ngx_http_in_addr_s ngx_http_in_addr_t;
+typedef struct ngx_http_variable_value_s ngx_http_variable_value_t;
+
#if (NGX_HTTP_CACHE)
#include <ngx_http_cache.h>
@@ -27,7 +29,7 @@ typedef struct ngx_http_in_addr_s ngx_http_in_addr_t;
#include <ngx_http_request.h>
#include <ngx_http_config.h>
#include <ngx_http_busy_lock.h>
-#include <ngx_http_log_handler.h>
+#include <ngx_http_log_module.h>
#include <ngx_http_core_module.h>
#include <ngx_http_variables.h>
@@ -46,16 +48,7 @@ struct ngx_http_log_ctx_s {
#define ngx_http_get_module_err_ctx(r, module) \
((r)->err_ctx ? (r)->err_ctx[module.ctx_index] : (r)->ctx[module.ctx_index])
-/* STUB */
-#define ngx_http_create_ctx(r, cx, module, size, error) \
- do { \
- ngx_test_null(cx, ngx_pcalloc(r->pool, size), error); \
- r->ctx[module.ctx_index] = cx; \
- } while (0)
-/**/
-
#define ngx_http_set_ctx(r, c, module) r->ctx[module.ctx_index] = c;
-
#define ngx_http_delete_ctx(r, module) r->ctx[module.ctx_index] = NULL;
diff --git a/src/http/ngx_http_busy_lock.c b/src/http/ngx_http_busy_lock.c
index 2b3ee105d..fe04390a1 100644
--- a/src/http/ngx_http_busy_lock.c
+++ b/src/http/ngx_http_busy_lock.c
@@ -205,13 +205,15 @@ char *ngx_http_set_busy_lock_slot(ngx_conf_t *cf, ngx_command_t *cmd,
}
/* ngx_calloc_shared() */
- if (!(bl = ngx_pcalloc(cf->pool, sizeof(ngx_http_busy_lock_t)))) {
+ bl = ngx_pcalloc(cf->pool, sizeof(ngx_http_busy_lock_t));
+ if (bl == NULL) {
return NGX_CONF_ERROR;
}
*blp = bl;
/* ngx_calloc_shared() */
- if (!(bl->mutex = ngx_pcalloc(cf->pool, sizeof(ngx_event_mutex_t)))) {
+ bl->mutex = ngx_pcalloc(cf->pool, sizeof(ngx_event_mutex_t));
+ if (bl->mutex == NULL) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/ngx_http_config.h b/src/http/ngx_http_config.h
index 0bf63385c..581556fe4 100644
--- a/src/http/ngx_http_config.h
+++ b/src/http/ngx_http_config.h
@@ -59,15 +59,15 @@ typedef struct {
*/
#define ngx_http_conf_get_module_main_conf(cf, module) \
- ((ngx_http_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index]
+ ((ngx_http_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index]
#define ngx_http_conf_get_module_srv_conf(cf, module) \
- ((ngx_http_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index]
+ ((ngx_http_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index]
#define ngx_http_conf_get_module_loc_conf(cf, module) \
- ((ngx_http_conf_ctx_t *) cf->ctx)->loc_conf[module.ctx_index]
+ ((ngx_http_conf_ctx_t *) cf->ctx)->loc_conf[module.ctx_index]
#define ngx_http_cycle_get_module_main_conf(cycle, module) \
- ((ngx_http_conf_ctx_t *) \
- cycle->conf_ctx[ngx_http_module.index])->main_conf[module.ctx_index]
+ ((ngx_http_conf_ctx_t *) \
+ cycle->conf_ctx[ngx_http_module.index])->main_conf[module.ctx_index]
diff --git a/src/http/ngx_http_copy_filter.c b/src/http/ngx_http_copy_filter_module.c
index 10c574f4a..4e8943844 100644
--- a/src/http/ngx_http_copy_filter.c
+++ b/src/http/ngx_http_copy_filter_module.c
@@ -16,20 +16,20 @@ typedef struct {
static void *ngx_http_copy_filter_create_conf(ngx_conf_t *cf);
static char *ngx_http_copy_filter_merge_conf(ngx_conf_t *cf,
- void *parent, void *child);
+ void *parent, void *child);
static ngx_int_t ngx_http_copy_filter_init(ngx_cycle_t *cycle);
static ngx_command_t ngx_http_copy_filter_commands[] = {
- {ngx_string("output_buffers"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
- ngx_conf_set_bufs_slot,
- NGX_HTTP_LOC_CONF_OFFSET,
- offsetof(ngx_http_copy_filter_conf_t, bufs),
- NULL},
+ { ngx_string("output_buffers"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
+ ngx_conf_set_bufs_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_copy_filter_conf_t, bufs),
+ NULL },
- ngx_null_command
+ ngx_null_command
};
@@ -60,7 +60,8 @@ ngx_module_t ngx_http_copy_filter_module = {
static ngx_http_output_body_filter_pt ngx_http_next_filter;
-ngx_int_t ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
+static ngx_int_t
+ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
ngx_output_chain_ctx_t *ctx;
ngx_http_copy_filter_conf_t *conf;
@@ -76,8 +77,12 @@ ngx_int_t ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
conf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
ngx_http_copy_filter_module);
- ngx_http_create_ctx(r, ctx, ngx_http_copy_filter_module,
- sizeof(ngx_output_chain_ctx_t), NGX_ERROR);
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t));
+ if (ctx == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_http_set_ctx(r, ctx, ngx_http_copy_filter_module);
ctx->sendfile = r->connection->sendfile;
ctx->need_in_memory = r->filter_need_in_memory;
@@ -96,13 +101,15 @@ ngx_int_t ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
-static void *ngx_http_copy_filter_create_conf(ngx_conf_t *cf)
+static void *
+ngx_http_copy_filter_create_conf(ngx_conf_t *cf)
{
ngx_http_copy_filter_conf_t *conf;
- ngx_test_null(conf,
- ngx_palloc(cf->pool, sizeof(ngx_http_copy_filter_conf_t)),
- NULL);
+ conf = ngx_palloc(cf->pool, sizeof(ngx_http_copy_filter_conf_t));
+ if (conf == NULL) {
+ return NULL;
+ }
conf->bufs.num = 0;
@@ -110,8 +117,8 @@ static void *ngx_http_copy_filter_create_conf(ngx_conf_t *cf)
}
-static char *ngx_http_copy_filter_merge_conf(ngx_conf_t *cf,
- void *parent, void *child)
+static char *
+ngx_http_copy_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_copy_filter_conf_t *prev = parent;
ngx_http_copy_filter_conf_t *conf = child;
@@ -122,7 +129,8 @@ static char *ngx_http_copy_filter_merge_conf(ngx_conf_t *cf,
}
-static ngx_int_t ngx_http_copy_filter_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_copy_filter_init(ngx_cycle_t *cycle)
{
ngx_http_next_filter = ngx_http_top_body_filter;
ngx_http_top_body_filter = ngx_http_copy_filter;
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index c773d8ff4..620d2e9e5 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -785,7 +785,8 @@ ngx_http_set_content_type(ngx_http_request_t *r)
}
if (i < r->exten.len) {
- if (!(p = ngx_palloc(r->pool, r->exten.len))) {
+ p = ngx_palloc(r->pool, r->exten.len);
+ if (p == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -897,7 +898,8 @@ ngx_http_set_exten(ngx_http_request_t *r)
r->exten.len = r->uri.len - i - 1;
if (r->exten.len > 0) {
- if (!(r->exten.data = ngx_palloc(r->pool, r->exten.len + 1))) {
+ r->exten.data = ngx_palloc(r->pool, r->exten.len + 1);
+ if (r->exten.data == NULL) {
return NGX_ERROR;
}
@@ -997,7 +999,8 @@ ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
ngx_http_core_srv_conf_t *cscf, **cscfp;
ngx_http_core_main_conf_t *cmcf;
- if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) {
+ ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
+ if (ctx == NULL) {
return NGX_CONF_ERROR;
}
@@ -1026,7 +1029,8 @@ ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
module = ngx_modules[m]->ctx;
if (module->create_srv_conf) {
- if (!(mconf = module->create_srv_conf(cf))) {
+ mconf = module->create_srv_conf(cf);
+ if (mconf == NULL) {
return NGX_CONF_ERROR;
}
@@ -1034,7 +1038,8 @@ ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
}
if (module->create_loc_conf) {
- if (!(mconf = module->create_loc_conf(cf))) {
+ mconf = module->create_loc_conf(cf);
+ if (mconf == NULL) {
return NGX_CONF_ERROR;
}
@@ -1051,7 +1056,8 @@ ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
- if (!(cscfp = ngx_array_push(&cmcf->servers))) {
+ cscfp = ngx_array_push(&cmcf->servers);
+ if (cscfp == NULL) {
return NGX_CONF_ERROR;
}
@@ -1095,7 +1101,8 @@ ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
u_char errstr[NGX_MAX_CONF_ERRSTR];
#endif
- if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) {
+ ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
+ if (ctx == NULL) {
return NGX_CONF_ERROR;
}
@@ -1181,7 +1188,9 @@ ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
if (pclcf->name.len == 0) {
cscf = ctx->srv_conf[ngx_http_core_module.ctx_index];
- if (!(clcfp = ngx_array_push(&cscf->locations))) {
+
+ clcfp = ngx_array_push(&cscf->locations);
+ if (clcfp == NULL) {
return NGX_CONF_ERROR;
}
@@ -1214,11 +1223,15 @@ ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
}
if (pclcf->locations.elts == NULL) {
- ngx_init_array(pclcf->locations, cf->pool, 4, sizeof(void *),
- NGX_CONF_ERROR);
+ if (ngx_array_init(&pclcf->locations, cf->pool, 4, sizeof(void *))
+ != NGX_OK)
+ {
+ return NGX_CONF_ERROR;
+ }
}
- if (!(clcfp = ngx_push_array(&pclcf->locations))) {
+ clcfp = ngx_array_push(&pclcf->locations);
+ if (clcfp == NULL) {
return NGX_CONF_ERROR;
}
}
@@ -1347,7 +1360,8 @@ ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
for (i = 1; i < cf->args->nelts; i++) {
ngx_http_types_hash_key(key, value[i]);
- if (!(type = ngx_array_push(&lcf->types[key]))) {
+ type = ngx_array_push(&lcf->types[key]);
+ if (type == NULL) {
return NGX_CONF_ERROR;
}
@@ -1364,7 +1378,8 @@ ngx_http_core_create_main_conf(ngx_conf_t *cf)
{
ngx_http_core_main_conf_t *cmcf;
- if (!(cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t)))) {
+ cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t));
+ if (cmcf == NULL) {
return NGX_CONF_ERROR;
}
@@ -1403,7 +1418,8 @@ ngx_http_core_create_srv_conf(ngx_conf_t *cf)
{
ngx_http_core_srv_conf_t *cscf;
- if (!(cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t)))) {
+ cscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t));
+ if (cscf == NULL) {
return NGX_CONF_ERROR;
}
@@ -1455,7 +1471,8 @@ ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
/* TODO: it does not merge, it inits only */
if (conf->listen.nelts == 0) {
- if (!(ls = ngx_array_push(&conf->listen))) {
+ ls = ngx_array_push(&conf->listen);
+ if (ls == NULL) {
return NGX_CONF_ERROR;
}
@@ -1470,11 +1487,13 @@ ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
}
if (conf->server_names.nelts == 0) {
- if (!(sn = ngx_array_push(&conf->server_names))) {
+ sn = ngx_array_push(&conf->server_names);
+ if (sn == NULL) {
return NGX_CONF_ERROR;
}
- if (!(sn->name.data = ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN))) {
+ sn->name.data = ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN);
+ if (sn->name.data == NULL) {
return NGX_CONF_ERROR;
}
@@ -1528,7 +1547,8 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_core_loc_conf_t *lcf;
- if (!(lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)))) {
+ lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t));
+ if (lcf == NULL) {
return NGX_CONF_ERROR;
}
@@ -1618,7 +1638,8 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
ngx_http_types_hash_key(key,
ngx_http_core_default_types[i].exten);
- if (!(type = ngx_array_push(&conf->types[key]))) {
+ type = ngx_array_push(&conf->types[key]);
+ if (type == NULL) {
return NGX_CONF_ERROR;
}
@@ -1700,7 +1721,8 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
* add resolved name to server names ???
*/
- if (!(ls = ngx_array_push(&scf->listen))) {
+ ls = ngx_array_push(&scf->listen);
+ if (ls == NULL) {
return NGX_CONF_ERROR;
}
@@ -1796,7 +1818,8 @@ ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}
- if (!(sn = ngx_array_push(&scf->server_names))) {
+ sn = ngx_array_push(&scf->server_names);
+ if (sn == NULL) {
return NGX_CONF_ERROR;
}
@@ -1908,7 +1931,8 @@ ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
for (i = 1; i < cf->args->nelts - n; i++) {
- if (!(err = ngx_array_push(lcf->error_pages))) {
+ err = ngx_array_push(lcf->error_pages);
+ if (err == NULL) {
return NGX_CONF_ERROR;
}
@@ -1981,7 +2005,8 @@ ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_core_loc_conf_t *lcf = conf;
- if (!(lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args))) {
+ lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args);
+ if (lcf->err_log == NULL) {
return NGX_CONF_ERROR;
}
@@ -2021,5 +2046,5 @@ ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data)
static ngx_int_t
ngx_http_core_init(ngx_cycle_t *cycle)
{
- return ngx_http_core_variables_init(cycle);
+ return ngx_http_variables_init(cycle);
}
diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter_module.c
index 65d8dee0a..b9dd88d5d 100644
--- a/src/http/ngx_http_header_filter.c
+++ b/src/http/ngx_http_header_filter_module.c
@@ -145,7 +145,7 @@ ngx_http_header_filter(ngx_http_request_t *r)
size_t len;
ngx_uint_t status, i;
ngx_buf_t *b;
- ngx_chain_t *ln;
+ ngx_chain_t out;
ngx_list_part_t *part;
ngx_table_elt_t *header;
ngx_http_core_loc_conf_t *clcf;
@@ -311,7 +311,8 @@ ngx_http_header_filter(ngx_http_request_t *r)
+ sizeof(CRLF) - 1;
}
- if (!(b = ngx_create_temp_buf(r->pool, len))) {
+ b = ngx_create_temp_buf(r->pool, len);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -461,14 +462,10 @@ ngx_http_header_filter(ngx_http_request_t *r)
b->last_buf = 1;
}
- if (!(ln = ngx_alloc_chain_link(r->pool))) {
- return NGX_ERROR;
- }
-
- ln->buf = b;
- ln->next = NULL;
+ out.buf = b;
+ out.next = NULL;
- return ngx_http_write_filter(r, ln);
+ return ngx_http_write_filter(r, &out);
}
diff --git a/src/http/ngx_http_log_handler.c b/src/http/ngx_http_log_module.c
index 4cb4af703..d19cae7d4 100644
--- a/src/http/ngx_http_log_handler.c
+++ b/src/http/ngx_http_log_module.c
@@ -36,8 +36,8 @@ static size_t ngx_http_log_request_getlen(ngx_http_request_t *r,
static u_char *ngx_http_log_request(ngx_http_request_t *r, u_char *buf,
ngx_http_log_op_t *op);
-static ngx_int_t ngx_http_log_header_in_compile(ngx_http_log_op_t *op,
- ngx_str_t *value);
+static ngx_int_t ngx_http_log_header_in_compile(ngx_conf_t *cf,
+ ngx_http_log_op_t *op, ngx_str_t *value);
static size_t ngx_http_log_header_in_getlen(ngx_http_request_t *r,
uintptr_t data);
static u_char *ngx_http_log_header_in(ngx_http_request_t *r, u_char *buf,
@@ -47,8 +47,8 @@ static size_t ngx_http_log_unknown_header_in_getlen(ngx_http_request_t *r,
static u_char *ngx_http_log_unknown_header_in(ngx_http_request_t *r,
u_char *buf, ngx_http_log_op_t *op);
-static ngx_int_t ngx_http_log_header_out_compile(ngx_http_log_op_t *op,
- ngx_str_t *value);
+static ngx_int_t ngx_http_log_header_out_compile(ngx_conf_t *cf,
+ ngx_http_log_op_t *op, ngx_str_t *value);
static size_t ngx_http_log_header_out_getlen(ngx_http_request_t *r,
uintptr_t data);
static u_char *ngx_http_log_header_out(ngx_http_request_t *r, u_char *buf,
@@ -66,6 +66,14 @@ static u_char *ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r,
static ngx_table_elt_t *ngx_http_log_unknown_header(ngx_list_t *headers,
ngx_str_t *value);
+static ngx_int_t ngx_http_log_variable_compile(ngx_conf_t *cf,
+ ngx_http_log_op_t *op, ngx_str_t *value);
+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 ngx_int_t ngx_http_log_set_formats(ngx_conf_t *cf);
static void *ngx_http_log_create_main_conf(ngx_conf_t *cf);
static void *ngx_http_log_create_loc_conf(ngx_conf_t *cf);
@@ -75,8 +83,6 @@ static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
-static ngx_int_t ngx_http_log_parse_format(ngx_conf_t *cf, ngx_array_t *ops,
- ngx_str_t *line);
static ngx_command_t ngx_http_log_commands[] = {
@@ -152,13 +158,12 @@ ngx_http_log_op_name_t ngx_http_log_fmt_ops[] = {
ngx_http_log_request_getlen,
ngx_http_log_request },
- { ngx_string("i"), 0, ngx_http_log_header_in_compile,
- ngx_http_log_header_in_getlen,
+ { ngx_string("i"), 0, ngx_http_log_header_in_compile, NULL,
ngx_http_log_header_in },
-
- { ngx_string("o"), 0, ngx_http_log_header_out_compile,
- ngx_http_log_header_out_getlen,
+ { ngx_string("o"), 0, ngx_http_log_header_out_compile, NULL,
ngx_http_log_header_out },
+ { ngx_string("v"), 0, ngx_http_log_variable_compile, NULL,
+ ngx_http_log_variable },
{ ngx_null_string, 0, NULL, NULL, NULL }
};
@@ -206,7 +211,8 @@ ngx_http_log_handler(ngx_http_request_t *r)
len++;
#endif
- if (!(line = ngx_palloc(r->pool, len))) {
+ line = ngx_palloc(r->pool, len);
+ if (line == NULL) {
return NGX_ERROR;
}
@@ -372,7 +378,8 @@ ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf,
static ngx_int_t
-ngx_http_log_header_in_compile(ngx_http_log_op_t *op, ngx_str_t *value)
+ngx_http_log_header_in_compile(ngx_conf_t *cf, ngx_http_log_op_t *op,
+ ngx_str_t *value)
{
ngx_uint_t i;
@@ -385,7 +392,7 @@ ngx_http_log_header_in_compile(ngx_http_log_op_t *op, ngx_str_t *value)
}
if (ngx_strncasecmp(ngx_http_headers_in[i].name.data, value->data,
- value->len) == 0)
+ value->len) == 0)
{
op->getlen = ngx_http_log_header_in_getlen;
op->run = ngx_http_log_header_in;
@@ -471,7 +478,8 @@ ngx_http_log_unknown_header_in(ngx_http_request_t *r, u_char *buf,
static ngx_int_t
-ngx_http_log_header_out_compile(ngx_http_log_op_t *op, ngx_str_t *value)
+ngx_http_log_header_out_compile(ngx_conf_t *cf, ngx_http_log_op_t *op,
+ ngx_str_t *value)
{
ngx_uint_t i;
@@ -721,6 +729,68 @@ ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r, u_char *buf,
}
+static ngx_int_t
+ngx_http_log_variable_compile(ngx_conf_t *cf, ngx_http_log_op_t *op,
+ ngx_str_t *value)
+{
+ ngx_uint_t i;
+ ngx_http_variable_t *var;
+
+ for (i = 0; i < value->len; i++) {
+ value->data[i] = ngx_toupper(value->data[i]);
+ }
+
+ var = ngx_http_add_variable(cf, value, 0);
+ if (var == NULL) {
+ return NGX_ERROR;
+ }
+
+ op->len = 0;
+ op->getlen = ngx_http_log_variable_getlen;
+ op->run = ngx_http_log_variable;
+ op->data = var->index;
+
+ return NGX_OK;
+}
+
+
+static size_t
+ngx_http_log_variable_getlen(ngx_http_request_t *r, uintptr_t data)
+{
+ ngx_http_variable_value_t *value;
+
+ value = ngx_http_get_indexed_variable(r, data);
+
+ if (value == NULL
+ || value == NGX_HTTP_VARIABLE_NOT_FOUND
+ || value->text.len == 0)
+ {
+ return 1;
+ }
+
+ return value->text.len;
+}
+
+
+static u_char *
+ngx_http_log_variable(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op)
+{
+ ngx_http_variable_value_t *value;
+
+ value = ngx_http_get_indexed_variable(r, op->data);
+
+ if (value == NULL
+ || value == NGX_HTTP_VARIABLE_NOT_FOUND
+ || value->text.len == 0)
+ {
+ *buf = '-';
+ return buf + 1;
+ }
+
+ return ngx_cpymem(buf, value->text.data, value->text.len);
+}
+
+
static ngx_int_t
ngx_http_log_set_formats(ngx_conf_t *cf)
{
@@ -741,7 +811,8 @@ ngx_http_log_create_main_conf(ngx_conf_t *cf)
char *rc;
ngx_str_t *value;
- if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_main_conf_t)))) {
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_main_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -753,18 +824,21 @@ ngx_http_log_create_main_conf(ngx_conf_t *cf)
cf->args->nelts = 0;
- if (!(value = ngx_array_push(cf->args))) {
+ value = ngx_array_push(cf->args);
+ if (value == NULL) {
return NGX_CONF_ERROR;
}
- if (!(value = ngx_array_push(cf->args))) {
+ value = ngx_array_push(cf->args);
+ if (value == NULL) {
return NGX_CONF_ERROR;
}
value->len = sizeof("combined") - 1;
value->data = (u_char *) "combined";
- if (!(value = ngx_array_push(cf->args))) {
+ value = ngx_array_push(cf->args);
+ if (value == NULL) {
return NGX_CONF_ERROR;
}
@@ -784,7 +858,8 @@ ngx_http_log_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_log_loc_conf_t *conf;
- if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_loc_conf_t)))) {
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_loc_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -823,7 +898,8 @@ ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
return NGX_CONF_ERROR;
}
- if (!(log = ngx_array_push(conf->logs))) {
+ log = ngx_array_push(conf->logs);
+ if (log == NULL) {
return NGX_CONF_ERROR;
}
@@ -871,11 +947,13 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module);
- if (!(log = ngx_array_push(llcf->logs))) {
+ log = ngx_array_push(llcf->logs);
+ if (log == NULL) {
return NGX_CONF_ERROR;
}
- if (!(log->file = ngx_conf_open_file(cf->cycle, &value[1]))) {
+ log->file = ngx_conf_open_file(cf->cycle, &value[1]);
+ if (log->file == NULL) {
return NGX_CONF_ERROR;
}
@@ -927,19 +1005,21 @@ ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
}
- if (!(fmt = ngx_push_array(&lmcf->formats))) {
+ fmt = ngx_array_push(&lmcf->formats);
+ if (fmt == NULL) {
return NGX_CONF_ERROR;
}
fmt->name = value[1];
- if (!(fmt->ops = ngx_array_create(cf->pool, 20, sizeof(ngx_http_log_op_t))))
- {
+ fmt->ops = ngx_array_create(cf->pool, 20, sizeof(ngx_http_log_op_t));
+ if (fmt->ops == NULL) {
return NGX_CONF_ERROR;
}
invalid = 0;
data = NULL;
+ arg.data = NULL;
for (s = 2; s < cf->args->nelts && !invalid; s++) {
@@ -947,7 +1027,8 @@ ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
while (i < value[s].len) {
- if (!(op = ngx_push_array(fmt->ops))) {
+ op = ngx_array_push(fmt->ops);
+ if (op == NULL) {
return NGX_CONF_ERROR;
}
@@ -1032,12 +1113,13 @@ ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}
- if (!(a = ngx_palloc(cf->pool, sizeof(ngx_str_t)))) {
+ a = ngx_palloc(cf->pool, sizeof(ngx_str_t));
+ if (a == NULL) {
return NGX_CONF_ERROR;
}
*a = arg;
- if (name->compile(op, a) == NGX_ERROR) {
+ if (name->compile(cf, op, a) == NGX_ERROR) {
return NGX_CONF_ERROR;
}
@@ -1076,7 +1158,8 @@ ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
} else {
op->run = ngx_http_log_copy_long;
- if (!(p = ngx_palloc(cf->pool, len))) {
+ p = ngx_palloc(cf->pool, len);
+ if (p == NULL) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/ngx_http_log_handler.h b/src/http/ngx_http_log_module.h
index 4472ed982..c414bc4ac 100644
--- a/src/http/ngx_http_log_handler.h
+++ b/src/http/ngx_http_log_module.h
@@ -4,8 +4,8 @@
*/
-#ifndef _NGX_HTTP_LOG_HANDLER_H_INCLUDED_
-#define _NGX_HTTP_LOG_HANDLER_H_INCLUDED_
+#ifndef _NGX_HTTP_LOG_MODULE_H_INCLUDED_
+#define _NGX_HTTP_LOG_MODULE_H_INCLUDED_
#include <ngx_config.h>
@@ -16,13 +16,14 @@
typedef struct ngx_http_log_op_s ngx_http_log_op_t;
typedef u_char *(*ngx_http_log_op_run_pt) (ngx_http_request_t *r, u_char *buf,
- ngx_http_log_op_t *op);
+ ngx_http_log_op_t *op);
typedef size_t (*ngx_http_log_op_getlen_pt) (ngx_http_request_t *r,
- uintptr_t data);
+ uintptr_t data);
+
+typedef ngx_int_t (*ngx_http_log_op_compile_pt) (ngx_conf_t *cf,
+ ngx_http_log_op_t *op, ngx_str_t *value);
-typedef ngx_int_t (*ngx_http_log_op_compile_pt) (ngx_http_log_op_t *op,
- ngx_str_t *value);
struct ngx_http_log_op_s {
size_t len;
@@ -67,4 +68,4 @@ typedef struct {
extern ngx_http_log_op_name_t ngx_http_log_fmt_ops[];
-#endif /* _NGX_HTTP_LOG_HANDLER_H_INCLUDED_ */
+#endif /* _NGX_HTTP_LOG_MODULE_H_INCLUDED_ */
diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c
index ca84d1627..a7d8fe37f 100644
--- a/src/http/ngx_http_parse.c
+++ b/src/http/ngx_http_parse.c
@@ -461,7 +461,6 @@ ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
default:
return NGX_HTTP_PARSE_INVALID_REQUEST;
}
- break;
}
}
@@ -646,7 +645,6 @@ ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b)
default:
return NGX_HTTP_PARSE_INVALID_HEADER;
}
- break;
/* end of header */
case sw_header_almost_done:
@@ -656,7 +654,6 @@ ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b)
default:
return NGX_HTTP_PARSE_INVALID_HEADER;
}
- break;
}
}
diff --git a/src/http/ngx_http_parse_time.c b/src/http/ngx_http_parse_time.c
index da9797177..549873762 100644
--- a/src/http/ngx_http_parse_time.c
+++ b/src/http/ngx_http_parse_time.c
@@ -229,10 +229,14 @@ time_t ngx_http_parse_time(u_char *value, size_t len)
return NGX_ERROR;
}
- if (sizeof(time_t) <= 4 && year >= 2038) {
+#if (NGX_TIME_T_SIZE <= 4)
+
+ if (year >= 2038) {
return NGX_ERROR;
}
+#endif
+
/*
* shift new year to March 1 and start months from 1 (not 0),
* it is needed for Gauss's formula
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index d41cb8d40..3876e39e7 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -18,7 +18,7 @@ static void ngx_http_process_request_line(ngx_event_t *rev);
static void ngx_http_process_request_headers(ngx_event_t *rev);
static ssize_t ngx_http_read_request_header(ngx_http_request_t *r);
static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r,
- ngx_uint_t request_line);
+ ngx_uint_t request_line);
static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r);
static ngx_int_t ngx_http_find_virtual_server(ngx_http_request_t *r);
@@ -34,7 +34,7 @@ static void ngx_http_set_lingering_close(ngx_http_request_t *r);
static void ngx_http_lingering_close_handler(ngx_event_t *ev);
static void ngx_http_client_error(ngx_http_request_t *r,
- int client_error, int error);
+ int client_error, int error);
static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len);
@@ -100,19 +100,22 @@ ngx_http_header_t ngx_http_headers_in[] = {
#if 0
-static void ngx_http_dummy(ngx_event_t *wev)
+static void
+ngx_http_dummy(ngx_event_t *wev)
{
return;
}
#endif
-void ngx_http_init_connection(ngx_connection_t *c)
+void
+ngx_http_init_connection(ngx_connection_t *c)
{
ngx_event_t *rev;
ngx_http_log_ctx_t *ctx;
- if (!(ctx = ngx_palloc(c->pool, sizeof(ngx_http_log_ctx_t)))) {
+ ctx = ngx_palloc(c->pool, sizeof(ngx_http_log_ctx_t));
+ if (ctx == NULL) {
ngx_http_close_connection(c);
return;
}
@@ -186,7 +189,8 @@ void ngx_http_init_connection(ngx_connection_t *c)
}
-static void ngx_http_init_request(ngx_event_t *rev)
+static
+void ngx_http_init_request(ngx_event_t *rev)
{
ngx_uint_t i;
socklen_t len;
@@ -225,7 +229,8 @@ static void ngx_http_init_request(ngx_event_t *rev)
#endif
} else {
- if (!(hc = ngx_pcalloc(c->pool, sizeof(ngx_http_connection_t)))) {
+ hc = ngx_pcalloc(c->pool, sizeof(ngx_http_connection_t));
+ if (hc == NULL) {
#if (NGX_STAT_STUB)
ngx_atomic_dec(ngx_stat_reading);
@@ -248,7 +253,8 @@ static void ngx_http_init_request(ngx_event_t *rev)
}
} else {
- if (!(r = ngx_pcalloc(c->pool, sizeof(ngx_http_request_t)))) {
+ r = ngx_pcalloc(c->pool, sizeof(ngx_http_request_t));
+ if (r == NULL) {
#if (NGX_STAT_STUB)
ngx_atomic_dec(ngx_stat_reading);
@@ -388,7 +394,8 @@ static void ngx_http_init_request(ngx_event_t *rev)
r->header_in = c->buffer;
}
- if (!(r->pool = ngx_create_pool(cscf->request_pool_size, c->log))) {
+ r->pool = ngx_create_pool(cscf->request_pool_size, c->log);
+ if (r->pool == NULL) {
ngx_http_close_connection(c);
return;
}
@@ -444,7 +451,8 @@ static void ngx_http_init_request(ngx_event_t *rev)
#if (NGX_HTTP_SSL)
-static void ngx_http_ssl_handshake(ngx_event_t *rev)
+static void
+ngx_http_ssl_handshake(ngx_event_t *rev)
{
u_char buf[1];
ssize_t n;
@@ -504,7 +512,8 @@ static void ngx_http_ssl_handshake(ngx_event_t *rev)
#endif
-static void ngx_http_process_request_line(ngx_event_t *rev)
+static void
+ngx_http_process_request_line(ngx_event_t *rev)
{
ssize_t n;
ngx_int_t rc, rv;
@@ -554,7 +563,8 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
if (r->complex_uri || r->quoted_uri) {
- if (!(r->uri.data = ngx_palloc(r->pool, r->uri.len + 1))) {
+ r->uri.data = ngx_palloc(r->pool, r->uri.len + 1);
+ if (r->uri.data == NULL) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
ngx_http_close_connection(c);
return;
@@ -707,7 +717,8 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
}
-static void ngx_http_process_request_headers(ngx_event_t *rev)
+static void
+ngx_http_process_request_headers(ngx_event_t *rev)
{
ssize_t n;
ngx_int_t rc, rv, i;
@@ -764,7 +775,8 @@ static void ngx_http_process_request_headers(ngx_event_t *rev)
r->headers_n++;
- if (!(h = ngx_list_push(&r->headers_in.headers))) {
+ h = ngx_list_push(&r->headers_in.headers);
+ if (h == NULL) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
ngx_http_close_connection(c);
return;
@@ -781,7 +793,8 @@ static void ngx_http_process_request_headers(ngx_event_t *rev)
if (h->key.len == sizeof("Cookie") - 1
&& ngx_strcasecmp(h->key.data, "Cookie") == 0)
{
- if (!(cookie = ngx_array_push(&r->headers_in.cookies))) {
+ cookie = ngx_array_push(&r->headers_in.cookies);
+ if (cookie == NULL) {
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
ngx_http_close_connection(c);
return;
@@ -879,7 +892,8 @@ static void ngx_http_process_request_headers(ngx_event_t *rev)
}
-static ssize_t ngx_http_read_request_header(ngx_http_request_t *r)
+static ssize_t
+ngx_http_read_request_header(ngx_http_request_t *r)
{
ssize_t n;
ngx_event_t *rev;
@@ -933,8 +947,9 @@ static ssize_t ngx_http_read_request_header(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r,
- ngx_uint_t request_line)
+static ngx_int_t
+ngx_http_alloc_large_header_buffer(ngx_http_request_t *r,
+ ngx_uint_t request_line)
{
u_char *old, *new;
ngx_buf_t *b;
@@ -1076,7 +1091,8 @@ static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r,
}
-static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_process_request_header(ngx_http_request_t *r)
{
u_char *ua, *user_agent, ch;
size_t len;
@@ -1106,7 +1122,7 @@ static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r)
if (r->headers_in.content_length) {
r->headers_in.content_length_n =
- ngx_atoi(r->headers_in.content_length->value.data,
+ ngx_atosz(r->headers_in.content_length->value.data,
r->headers_in.content_length->value.len);
if (r->headers_in.content_length_n == NGX_ERROR) {
@@ -1137,7 +1153,7 @@ static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r)
if (r->headers_in.keep_alive) {
r->headers_in.keep_alive_n =
- ngx_atoi(r->headers_in.keep_alive->value.data,
+ ngx_atotm(r->headers_in.keep_alive->value.data,
r->headers_in.keep_alive->value.len);
}
}
@@ -1191,7 +1207,8 @@ static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_find_virtual_server(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_find_virtual_server(ngx_http_request_t *r)
{
ngx_int_t rc;
ngx_uint_t i, n, key, found;
@@ -1297,7 +1314,8 @@ static ngx_int_t ngx_http_find_virtual_server(ngx_http_request_t *r)
}
-void ngx_http_finalize_request(ngx_http_request_t *r, int rc)
+void
+ngx_http_finalize_request(ngx_http_request_t *r, int rc)
{
ngx_http_core_loc_conf_t *clcf;
@@ -1380,7 +1398,8 @@ void ngx_http_finalize_request(ngx_http_request_t *r, int rc)
}
-static void ngx_http_set_write_handler(ngx_http_request_t *r)
+static void
+ngx_http_set_write_handler(ngx_http_request_t *r)
{
ngx_event_t *wev;
ngx_http_core_loc_conf_t *clcf;
@@ -1409,7 +1428,8 @@ static void ngx_http_set_write_handler(ngx_http_request_t *r)
}
-void ngx_http_writer(ngx_event_t *wev)
+void
+ngx_http_writer(ngx_event_t *wev)
{
int rc;
ngx_connection_t *c;
@@ -1486,7 +1506,8 @@ void ngx_http_writer(ngx_event_t *wev)
}
-static void ngx_http_block_read(ngx_event_t *rev)
+static void
+ngx_http_block_read(ngx_event_t *rev)
{
ngx_connection_t *c;
ngx_http_request_t *r;
@@ -1506,7 +1527,8 @@ static void ngx_http_block_read(ngx_event_t *rev)
}
-ngx_int_t ngx_http_discard_body(ngx_http_request_t *r)
+ngx_int_t
+ngx_http_discard_body(ngx_http_request_t *r)
{
ssize_t size;
ngx_event_t *rev;
@@ -1546,7 +1568,8 @@ ngx_int_t ngx_http_discard_body(ngx_http_request_t *r)
}
-static void ngx_http_read_discarded_body_event(ngx_event_t *rev)
+static void
+ngx_http_read_discarded_body_event(ngx_event_t *rev)
{
ngx_int_t rc;
ngx_connection_t *c;
@@ -1572,7 +1595,8 @@ static void ngx_http_read_discarded_body_event(ngx_event_t *rev)
}
-static ngx_int_t ngx_http_read_discarded_body(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_read_discarded_body(ngx_http_request_t *r)
{
ssize_t size, n;
u_char buffer[NGX_HTTP_DISCARD_BUFFER_SIZE];
@@ -1615,7 +1639,8 @@ static ngx_int_t ngx_http_read_discarded_body(ngx_http_request_t *r)
}
-static void ngx_http_set_keepalive(ngx_http_request_t *r)
+static void
+ngx_http_set_keepalive(ngx_http_request_t *r)
{
int tcp_nodelay;
ngx_int_t i;
@@ -1776,7 +1801,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
c->log->action = "keepalive";
if (c->tcp_nopush == NGX_TCP_NOPUSH_SET) {
- if (ngx_tcp_push(c->fd) == NGX_ERROR) {
+ if (ngx_tcp_push(c->fd) == -1) {
ngx_connection_error(c, ngx_socket_errno, ngx_tcp_push_n " failed");
ngx_http_close_connection(c);
return;
@@ -1818,13 +1843,13 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r)
}
-static void ngx_http_keepalive_handler(ngx_event_t *rev)
+static void
+ngx_http_keepalive_handler(ngx_event_t *rev)
{
- size_t size;
- ssize_t n;
- ngx_buf_t *b;
- ngx_connection_t *c;
- ngx_http_connection_t *hc;
+ size_t size;
+ ssize_t n;
+ ngx_buf_t *b;
+ ngx_connection_t *c;
c = rev->data;
@@ -1855,7 +1880,6 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev)
#endif
- hc = c->data;
b = c->buffer;
size = b->end - b->start;
@@ -1867,7 +1891,8 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev)
* to keep the buffer size.
*/
- if (!(b->pos = ngx_palloc(c->pool, size))) {
+ b->pos = ngx_palloc(c->pool, size);
+ if (b->pos == NULL) {
ngx_http_close_connection(c);
return;
}
@@ -1919,7 +1944,8 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev)
}
-static void ngx_http_set_lingering_close(ngx_http_request_t *r)
+static void
+ngx_http_set_lingering_close(ngx_http_request_t *r)
{
ngx_event_t *rev, *wev;
ngx_connection_t *c;
@@ -1977,7 +2003,8 @@ static void ngx_http_set_lingering_close(ngx_http_request_t *r)
}
-static void ngx_http_lingering_close_handler(ngx_event_t *rev)
+static void
+ngx_http_lingering_close_handler(ngx_event_t *rev)
{
ssize_t n;
ngx_msec_t timer;
@@ -2036,7 +2063,8 @@ static void ngx_http_lingering_close_handler(ngx_event_t *rev)
}
-void ngx_http_empty_handler(ngx_event_t *wev)
+void
+ngx_http_empty_handler(ngx_event_t *wev)
{
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0, "http empty handler");
@@ -2044,12 +2072,14 @@ void ngx_http_empty_handler(ngx_event_t *wev)
}
-ngx_int_t ngx_http_send_last(ngx_http_request_t *r)
+ngx_int_t
+ngx_http_send_last(ngx_http_request_t *r)
{
ngx_buf_t *b;
ngx_chain_t out;
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
@@ -2061,7 +2091,8 @@ ngx_int_t ngx_http_send_last(ngx_http_request_t *r)
}
-void ngx_http_close_request(ngx_http_request_t *r, int error)
+void
+ngx_http_close_request(ngx_http_request_t *r, int error)
{
ngx_uint_t i;
ngx_log_t *log;
@@ -2171,7 +2202,8 @@ void ngx_http_close_request(ngx_http_request_t *r, int error)
#if (NGX_HTTP_SSL)
-void ngx_ssl_close_handler(ngx_event_t *ev)
+void
+ngx_ssl_close_handler(ngx_event_t *ev)
{
ngx_connection_t *c;
@@ -2189,7 +2221,8 @@ void ngx_ssl_close_handler(ngx_event_t *ev)
#endif
-void ngx_http_close_connection(ngx_connection_t *c)
+void
+ngx_http_close_connection(ngx_connection_t *c)
{
ngx_pool_t *pool;
@@ -2216,12 +2249,12 @@ void ngx_http_close_connection(ngx_connection_t *c)
ngx_close_connection(c);
- ngx_destroy_pool(c->pool);
+ ngx_destroy_pool(pool);
}
-static void ngx_http_client_error(ngx_http_request_t *r,
- int client_error, int error)
+static void
+ngx_http_client_error(ngx_http_request_t *r, int client_error, int error)
{
u_char *p;
ngx_http_log_ctx_t *ctx;
@@ -2315,7 +2348,8 @@ static void ngx_http_client_error(ngx_http_request_t *r,
}
-static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len)
+static u_char *
+ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len)
{
u_char *p;
ngx_http_log_ctx_t *ctx;
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index 0e7e1054c..413af2fab 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -119,91 +119,91 @@ typedef enum {
typedef struct {
- ngx_str_t name;
- ngx_uint_t offset;
+ ngx_str_t name;
+ ngx_uint_t offset;
} ngx_http_header_t;
typedef struct {
- ngx_list_t headers;
+ ngx_list_t headers;
- ngx_table_elt_t *host;
- ngx_table_elt_t *connection;
- ngx_table_elt_t *if_modified_since;
- ngx_table_elt_t *user_agent;
- ngx_table_elt_t *referer;
- ngx_table_elt_t *content_length;
- ngx_table_elt_t *content_type;
+ ngx_table_elt_t *host;
+ ngx_table_elt_t *connection;
+ ngx_table_elt_t *if_modified_since;
+ ngx_table_elt_t *user_agent;
+ ngx_table_elt_t *referer;
+ ngx_table_elt_t *content_length;
+ ngx_table_elt_t *content_type;
- ngx_table_elt_t *range;
+ ngx_table_elt_t *range;
#if (NGX_HTTP_GZIP)
- ngx_table_elt_t *accept_encoding;
- ngx_table_elt_t *via;
+ ngx_table_elt_t *accept_encoding;
+ ngx_table_elt_t *via;
#endif
- ngx_table_elt_t *authorization;
+ ngx_table_elt_t *authorization;
- ngx_table_elt_t *keep_alive;
+ ngx_table_elt_t *keep_alive;
#if (NGX_HTTP_PROXY)
- ngx_table_elt_t *x_forwarded_for;
- ngx_table_elt_t *x_real_ip;
- ngx_table_elt_t *x_url;
+ ngx_table_elt_t *x_forwarded_for;
+ ngx_table_elt_t *x_real_ip;
+ ngx_table_elt_t *x_url;
#endif
#if (NGX_HTTP_HEADERS)
- ngx_table_elt_t *accept;
- ngx_table_elt_t *accept_language;
+ ngx_table_elt_t *accept;
+ ngx_table_elt_t *accept_language;
#endif
- ngx_array_t cookies;
+ ngx_array_t cookies;
- size_t host_name_len;
- ssize_t content_length_n;
- size_t connection_type;
- ssize_t keep_alive_n;
+ size_t host_name_len;
+ ssize_t content_length_n;
+ time_t keep_alive_n;
- unsigned msie:1;
- unsigned msie4:1;
- unsigned opera:1;
- unsigned gecko:1;
- unsigned konqueror:1;
+ unsigned connection_type:2;
+ unsigned msie:1;
+ unsigned msie4:1;
+ unsigned opera:1;
+ unsigned gecko:1;
+ unsigned konqueror:1;
} ngx_http_headers_in_t;
typedef struct {
- off_t start;
- off_t end;
- ngx_str_t content_range;
+ off_t start;
+ off_t end;
+ ngx_str_t content_range;
} ngx_http_range_t;
typedef struct {
- ngx_list_t headers;
-
- ngx_uint_t status;
- ngx_str_t status_line;
-
- ngx_table_elt_t *server;
- ngx_table_elt_t *date;
- ngx_table_elt_t *content_type;
- ngx_table_elt_t *content_length;
- ngx_table_elt_t *content_encoding;
- ngx_table_elt_t *location;
- ngx_table_elt_t *last_modified;
- ngx_table_elt_t *content_range;
- ngx_table_elt_t *accept_ranges;
- ngx_table_elt_t *expires;
- ngx_table_elt_t *cache_control;
- ngx_table_elt_t *etag;
-
- ngx_str_t charset;
- ngx_array_t ranges;
-
- off_t content_length_n;
- time_t date_time;
- time_t last_modified_time;
+ ngx_list_t headers;
+
+ ngx_uint_t status;
+ ngx_str_t status_line;
+
+ ngx_table_elt_t *server;
+ ngx_table_elt_t *date;
+ ngx_table_elt_t *content_type;
+ ngx_table_elt_t *content_length;
+ ngx_table_elt_t *content_encoding;
+ ngx_table_elt_t *location;
+ ngx_table_elt_t *last_modified;
+ ngx_table_elt_t *content_range;
+ ngx_table_elt_t *accept_ranges;
+ ngx_table_elt_t *expires;
+ ngx_table_elt_t *cache_control;
+ ngx_table_elt_t *etag;
+
+ ngx_str_t charset;
+ ngx_array_t ranges;
+
+ off_t content_length_n;
+ time_t date_time;
+ time_t last_modified_time;
} ngx_http_headers_out_t;
@@ -221,172 +221,171 @@ typedef struct {
struct ngx_http_cleanup_s {
union {
struct {
- ngx_fd_t fd;
- u_char *name;
+ ngx_fd_t fd;
+ u_char *name;
} file;
struct {
- ngx_http_cache_hash_t *hash;
- ngx_http_cache_entry_t *cache;
+ ngx_http_cache_hash_t *hash;
+ ngx_http_cache_entry_t *cache;
} cache;
} data;
- unsigned valid:1;
- unsigned cache:1;
+ unsigned valid:1;
+ unsigned cache:1;
};
typedef struct {
- ngx_http_request_t *request;
+ ngx_http_request_t *request;
- ngx_buf_t **busy;
- ngx_int_t nbusy;
+ ngx_buf_t **busy;
+ ngx_int_t nbusy;
- ngx_buf_t **free;
- ngx_int_t nfree;
+ ngx_buf_t **free;
+ ngx_int_t nfree;
- ngx_uint_t pipeline; /* unsigned pipeline:1; */
+ ngx_uint_t pipeline; /* unsigned pipeline:1; */
} ngx_http_connection_t;
typedef ngx_int_t (*ngx_http_handler_pt)(ngx_http_request_t *r);
struct ngx_http_request_s {
- uint32_t signature; /* "HTTP" */
+ uint32_t signature; /* "HTTP" */
- ngx_connection_t *connection;
+ ngx_connection_t *connection;
- void **ctx;
- void **main_conf;
- void **srv_conf;
- void **loc_conf;
+ void **ctx;
+ void **main_conf;
+ void **srv_conf;
+ void **loc_conf;
- ngx_http_cache_t *cache;
+ ngx_http_cache_t *cache;
- ngx_http_upstream_t *upstream;
+ ngx_http_upstream_t *upstream;
- ngx_file_t file;
+ ngx_file_t file;
- ngx_pool_t *pool;
- ngx_buf_t *header_in;
+ ngx_pool_t *pool;
+ ngx_buf_t *header_in;
- ngx_http_headers_in_t headers_in;
- ngx_http_headers_out_t headers_out;
+ ngx_http_headers_in_t headers_in;
+ ngx_http_headers_out_t headers_out;
- ngx_http_request_body_t *request_body;
+ ngx_http_request_body_t *request_body;
- time_t lingering_time;
- time_t start_time;
+ time_t lingering_time;
+ time_t start_time;
- ngx_uint_t method;
- ngx_uint_t http_version;
- ngx_uint_t http_major;
- ngx_uint_t http_minor;
+ ngx_uint_t method;
+ ngx_uint_t http_version;
+ ngx_uint_t http_major;
+ ngx_uint_t http_minor;
+
+ ngx_str_t request_line;
+ ngx_str_t uri;
+ ngx_str_t args;
+ ngx_str_t exten;
+ ngx_str_t unparsed_uri;
- ngx_str_t request_line;
- ngx_str_t uri;
- ngx_str_t args;
- ngx_str_t exten;
- ngx_str_t unparsed_uri;
+ ngx_str_t method_name;
+ ngx_str_t http_protocol;
+
+ ngx_http_request_t *main;
- ngx_str_t method_name;
- ngx_str_t http_protocol;
+ uint32_t in_addr;
+ ngx_uint_t port;
+ ngx_str_t *port_text; /* ":80" */
+ ngx_str_t server_name;
+ ngx_http_in_addr_t *virtual_names;
- ngx_http_request_t *main;
+ ngx_uint_t phase;
+ ngx_int_t phase_handler;
+ ngx_http_handler_pt content_handler;
- uint32_t in_addr;
- ngx_uint_t port;
- ngx_str_t *port_text; /* ":80" */
- ngx_str_t server_name;
- ngx_http_in_addr_t *virtual_names;
+ ngx_http_variable_value_t **variables;
- ngx_uint_t phase;
- ngx_int_t phase_handler;
- ngx_http_handler_pt content_handler;
-
- ngx_uint_t nvariables;
- void **variables;
-
- ngx_array_t cleanup;
+ ngx_array_t cleanup;
/* used to learn the Apache compatible response length without a header */
- size_t header_size;
+ size_t header_size;
- size_t request_length;
+ size_t request_length;
- u_char *discarded_buffer;
- void **err_ctx;
- ngx_uint_t err_status;
+ u_char *discarded_buffer;
+ void **err_ctx;
+ ngx_uint_t err_status;
- ngx_http_connection_t *http_connection;
+ ngx_http_connection_t *http_connection;
- unsigned http_state:4;
+ unsigned http_state:4;
/* URI with "/." and on Win32 with "//" */
- unsigned complex_uri:1;
+ unsigned complex_uri:1;
/* URI with "%" */
- unsigned quoted_uri:1;
+ unsigned quoted_uri:1;
/* URI with "+" */
- unsigned plus_in_uri:1;
+ unsigned plus_in_uri:1;
/* URI with "\0" or "%00" */
- unsigned zero_in_uri:1;
+ unsigned zero_in_uri:1;
- unsigned uri_changed:1;
- unsigned uri_changes:4;
+ unsigned uri_changed:1;
+ unsigned uri_changes:4;
- unsigned low_case_exten:1;
- unsigned header_timeout_set:1;
+ unsigned low_case_exten:1;
+ unsigned header_timeout_set:1;
- unsigned proxy:1;
- unsigned bypass_cache:1;
- unsigned no_cache:1;
+ unsigned proxy:1;
+ unsigned bypass_cache:1;
+ unsigned no_cache:1;
#if 0
- unsigned cachable:1;
+ unsigned cachable:1;
#endif
- unsigned pipeline:1;
+ unsigned pipeline:1;
- unsigned plain_http:1;
- unsigned chunked:1;
- unsigned header_only:1;
- unsigned keepalive:1;
- unsigned lingering_close:1;
- unsigned closed:1;
+ unsigned plain_http:1;
+ unsigned chunked:1;
+ unsigned header_only:1;
+ unsigned keepalive:1;
+ unsigned lingering_close:1;
+ unsigned closed:1;
- unsigned filter_need_in_memory:1;
- unsigned filter_ssi_need_in_memory:1;
- unsigned filter_need_temporary:1;
- unsigned filter_allow_ranges:1;
+ unsigned filter_need_in_memory:1;
+ unsigned filter_ssi_need_in_memory:1;
+ unsigned filter_need_temporary:1;
+ unsigned filter_allow_ranges:1;
#if (NGX_STAT_STUB)
- unsigned stat_reading:1;
- unsigned stat_writing:1;
+ unsigned stat_reading:1;
+ unsigned stat_writing:1;
#endif
- ngx_uint_t headers_n;
+ ngx_uint_t headers_n;
/* used to parse HTTP headers */
- ngx_uint_t state;
- u_char *uri_start;
- u_char *uri_end;
- u_char *uri_ext;
- u_char *args_start;
- u_char *request_start;
- u_char *request_end;
- u_char *method_end;
- u_char *schema_start;
- u_char *schema_end;
- u_char *host_start;
- u_char *host_end;
- u_char *port_start;
- u_char *port_end;
- u_char *header_name_start;
- u_char *header_name_end;
- u_char *header_start;
- u_char *header_end;
+ ngx_uint_t state;
+ u_char *uri_start;
+ u_char *uri_end;
+ u_char *uri_ext;
+ u_char *args_start;
+ u_char *request_start;
+ u_char *request_end;
+ u_char *method_end;
+ u_char *schema_start;
+ u_char *schema_end;
+ u_char *host_start;
+ u_char *host_end;
+ u_char *port_start;
+ u_char *port_end;
+ u_char *header_name_start;
+ u_char *header_name_end;
+ u_char *header_start;
+ u_char *header_end;
};
diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c
index 59f72208d..eeffd8afd 100644
--- a/src/http/ngx_http_request_body.c
+++ b/src/http/ngx_http_request_body.c
@@ -12,7 +12,7 @@
static void ngx_http_read_client_request_body_handler(ngx_event_t *rev);
static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r,
- ngx_connection_t *c);
+ ngx_connection_t *c);
/*
* on completion ngx_http_read_client_request_body() adds to
@@ -21,22 +21,35 @@ static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r,
* *) one memory or file buf that contains the rest of the body
*/
-ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r,
- ngx_http_client_body_handler_pt post_handler)
+ngx_int_t
+ngx_http_read_client_request_body(ngx_http_request_t *r,
+ ngx_http_client_body_handler_pt post_handler)
{
ssize_t size;
ngx_buf_t *b;
ngx_chain_t *cl;
+ ngx_connection_t *c;
ngx_http_request_body_t *rb;
ngx_http_core_loc_conf_t *clcf;
- if (!(rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t)))) {
+ rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t));
+ if (rb == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
r->request_body = rb;
+ /* STUB */
+ if (r->file.fd != NGX_INVALID_FILE) {
+ if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) {
+ ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno,
+ ngx_close_file_n " \"%V\" failed", &r->file.name);
+ }
+ r->file.fd = NGX_INVALID_FILE;
+ }
+ /**/
+
if (r->headers_in.content_length_n <= 0) {
post_handler(r);
return NGX_OK;
@@ -58,7 +71,8 @@ ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r,
/* there is the pre-read part of the request body */
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -66,7 +80,8 @@ ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r,
b->start = b->pos = r->header_in->pos;
b->end = b->last = r->header_in->last;
- if (!(rb->bufs = ngx_alloc_chain_link(r->pool))) {
+ rb->bufs = ngx_alloc_chain_link(r->pool);
+ if (rb->bufs == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -103,11 +118,13 @@ ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r,
size = clcf->client_body_buffer_size;
}
- if (!(rb->buf = ngx_create_temp_buf(r->pool, size))) {
+ rb->buf = ngx_create_temp_buf(r->pool, size);
+ if (rb->buf == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -121,14 +138,16 @@ ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r,
rb->bufs = cl;
}
- r->connection->read->event_handler =
- ngx_http_read_client_request_body_handler;
+ c = r->connection;
- return ngx_http_do_read_client_request_body(r, r->connection);
+ c->read->event_handler = ngx_http_read_client_request_body_handler;
+
+ return ngx_http_do_read_client_request_body(r, c);
}
-static void ngx_http_read_client_request_body_handler(ngx_event_t *rev)
+static void
+ngx_http_read_client_request_body_handler(ngx_event_t *rev)
{
ngx_int_t rc;
ngx_connection_t *c;
@@ -150,8 +169,9 @@ static void ngx_http_read_client_request_body_handler(ngx_event_t *rev)
}
-static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r,
- ngx_connection_t *c)
+static ngx_int_t
+ngx_http_do_read_client_request_body(ngx_http_request_t *r,
+ ngx_connection_t *c)
{
size_t size;
ssize_t n;
@@ -169,7 +189,8 @@ static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r,
if (rb->buf->last == rb->buf->end) {
if (rb->temp_file == NULL) {
- if (!(tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)))) {
+ tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
+ if (tf == NULL) {
return NGX_ERROR;
}
@@ -268,7 +289,8 @@ static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r,
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c
index 572ad0a9b..44da5f388 100644
--- a/src/http/ngx_http_special_response.c
+++ b/src/http/ngx_http_special_response.c
@@ -17,7 +17,7 @@ static u_char error_tail[] =
;
-static u_char msie_stub[] =
+static u_char ngx_http_msie_stub[] =
"<!-- The padding to disable MSIE's friendly error page -->" CRLF
"<!-- The padding to disable MSIE's friendly error page -->" CRLF
"<!-- The padding to disable MSIE's friendly error page -->" CRLF
@@ -234,9 +234,9 @@ ngx_int_t
ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
{
ngx_int_t rc;
- ngx_uint_t err, i, msie_padding;
+ ngx_uint_t i, err, msie_padding;
ngx_buf_t *b;
- ngx_chain_t *out, **ll, *cl;
+ ngx_chain_t *out, *cl;
ngx_http_err_page_t *err_page;
ngx_http_core_loc_conf_t *clcf;
@@ -327,7 +327,7 @@ ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
&& error >= NGX_HTTP_BAD_REQUEST
&& error != NGX_HTTP_REQUEST_URI_TOO_LARGE)
{
- r->headers_out.content_length_n += sizeof(msie_stub) - 1;
+ r->headers_out.content_length_n += sizeof(ngx_http_msie_stub) - 1;
msie_padding = 1;
}
@@ -360,43 +360,64 @@ ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
return NGX_OK;
}
- out = NULL;
- ll = NULL;
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
+
b->memory = 1;
b->pos = error_pages[err].data;
b->last = error_pages[err].data + error_pages[err].len;
- ngx_alloc_link_and_set_buf(cl, b, r->pool, NGX_ERROR);
- ngx_chain_add_link(out, ll, cl);
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl->buf = b;
+ out = cl;
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
+
b->memory = 1;
b->pos = error_tail;
b->last = error_tail + sizeof(error_tail) - 1;
- ngx_alloc_link_and_set_buf(cl, b, r->pool, NGX_ERROR);
- ngx_chain_add_link(out, ll, cl);
+ cl->next = ngx_alloc_chain_link(r->pool);
+ if (cl->next == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl = cl->next;
+ cl->buf = b;
if (msie_padding) {
- if (!(b = ngx_calloc_buf(r->pool))) {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
return NGX_ERROR;
}
+
b->memory = 1;
- b->pos = msie_stub;
- b->last = msie_stub + sizeof(msie_stub) - 1;
+ b->pos = ngx_http_msie_stub;
+ b->last = ngx_http_msie_stub + sizeof(ngx_http_msie_stub) - 1;
+
+ cl->next = ngx_alloc_chain_link(r->pool);
+ if (cl->next == NULL) {
+ return NGX_ERROR;
+ }
- ngx_alloc_link_and_set_buf(cl, b, r->pool, NGX_ERROR);
- ngx_chain_add_link(out, ll, cl);
+ cl = cl->next;
+ cl->buf = b;
}
b->last_buf = 1;
+ cl->next = NULL;
+
return ngx_http_output_filter(r, out);
}
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index 5b8312130..3076df7de 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -129,13 +129,14 @@ ngx_http_upstream_init(ngx_http_request_t *r)
u->writer.pool = r->pool;
if (ngx_array_init(&u->states, r->pool, u->peer.peers->number,
- sizeof(ngx_http_upstream_state_t)) == NGX_ERROR)
+ sizeof(ngx_http_upstream_state_t)) != NGX_OK)
{
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
- if (!(u->state = ngx_push_array(&u->states))) {
+ u->state = ngx_array_push(&u->states);
+ if (u->state == NULL) {
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
@@ -317,7 +318,8 @@ ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
if (r->request_body->buf) {
if (r->request_body->temp_file) {
- if (!(u->output.free = ngx_alloc_chain_link(r->pool))) {
+ u->output.free = ngx_alloc_chain_link(r->pool);
+ if (u->output.free == NULL) {
ngx_http_upstream_finalize_request(r, u,
NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
@@ -392,7 +394,8 @@ ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u)
/* add one more state */
- if (!(u->state = ngx_push_array(&u->states))) {
+ u->state = ngx_array_push(&u->states);
+ if (u->state == NULL) {
ngx_http_upstream_finalize_request(r, u,
NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
@@ -739,7 +742,8 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
p->cachable = u->cachable;
- if (!(p->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)))) {
+ p->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
+ if (p->temp_file == NULL) {
ngx_http_upstream_finalize_request(r, u, 0);
return;
}
@@ -759,7 +763,8 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
p->max_temp_file_size = u->conf->max_temp_file_size;
p->temp_file_write_size = u->conf->temp_file_write_size;
- if (!(p->preread_bufs = ngx_alloc_chain_link(r->pool))) {
+ p->preread_bufs = ngx_alloc_chain_link(r->pool);
+ if (p->preread_bufs == NULL) {
ngx_http_upstream_finalize_request(r, u, 0);
return;
}
diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c
index e65f38858..154ee1352 100644
--- a/src/http/ngx_http_variables.c
+++ b/src/http/ngx_http_variables.c
@@ -25,7 +25,7 @@
static ngx_http_variable_value_t *
ngx_http_variable_header(ngx_http_request_t *r, uintptr_t data);
static ngx_http_variable_value_t *
- ngx_http_variable_unknown_header(ngx_http_request_t *r, ngx_str_t *var);
+ ngx_http_variable_unknown_header(ngx_http_request_t *r, uintptr_t data);
static ngx_http_variable_value_t *
ngx_http_variable_remote_addr(ngx_http_request_t *r, uintptr_t data);
static ngx_http_variable_value_t *
@@ -69,39 +69,71 @@ static ngx_http_core_variable_t ngx_http_core_variables[] = {
ngx_http_variable_t *
-ngx_http_add_variable(ngx_conf_t *cf)
+ngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name, ngx_uint_t set)
{
- ngx_http_variable_t *var;
+ ngx_uint_t i;
+ ngx_http_variable_t *v;
ngx_http_core_main_conf_t *cmcf;
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
- if (cmcf->variables.elts == NULL) {
+ v = cmcf->variables.elts;
+
+ if (v == NULL) {
if (ngx_array_init(&cmcf->variables, cf->pool, 4,
sizeof(ngx_http_variable_t)) == NGX_ERROR)
{
return NULL;
}
+
+ } else {
+ for (i = 0; i < cmcf->variables.nelts; i++) {
+ if (name->len != v[i].name.len
+ || ngx_strncasecmp(name->data, v[i].name.data, name->len) != 0)
+ {
+ continue;
+ }
+
+ if (set && v[i].handler) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "the duplicate \"%V\" variable", name);
+ return NULL;
+ }
+
+ return &v[i];
+ }
}
- if (!(var = ngx_array_push(&cmcf->variables))) {
+ v = ngx_array_push(&cmcf->variables);
+ if (v == NULL) {
return NULL;
}
- var->index = cmcf->variables.nelts - 1;
+ v->name.len = name->len;
+ v->name.data = ngx_palloc(cf->pool, name->len);
+ if (v->name.data == NULL) {
+ return NULL;
+ }
+
+ for (i = 0; i < name->len; i++) {
+ v->name.data[i] = ngx_toupper(name->data[i]);
+ }
- return var;
+ v->index = cmcf->variables.nelts - 1;
+ v->handler = NULL;
+ v->data = 0;
+
+ return v;
}
ngx_http_variable_value_t *
ngx_http_get_indexed_variable(ngx_http_request_t *r, ngx_uint_t index)
{
- ngx_http_variable_t *var;
+ ngx_http_variable_t *v;
+ ngx_http_variable_value_t *vv;
ngx_http_core_main_conf_t *cmcf;
- /* TODO: cached variables */
-
cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
if (cmcf->variables.elts == NULL || cmcf->variables.nelts <= index) {
@@ -110,70 +142,70 @@ ngx_http_get_indexed_variable(ngx_http_request_t *r, ngx_uint_t index)
return NULL;
}
- var = cmcf->variables.elts;
-
- return var[index].handler(r, var[index].data);
-}
-
+ if (r->variables && r->variables[index]) {
+ return r->variables[index];
+ }
-ngx_int_t
-ngx_http_get_variable_index(ngx_http_core_main_conf_t *cmcf, ngx_str_t *name)
-{
- ngx_uint_t i;
- ngx_http_variable_t *var;
+ v = cmcf->variables.elts;
- var = cmcf->variables.elts;
- for (i = 0; i < cmcf->variables.nelts; i++) {
- if (var[i].name.len != name->len) {
- continue;
- }
+ vv = v[index].handler(r, v[index].data);
- if (ngx_strncasecmp(var[i].name.data, name->data, name->len) == 0) {
- return var[i].index;
+ if (r->variables == NULL) {
+ r->variables = ngx_pcalloc(r->pool, cmcf->variables.nelts
+ * sizeof(ngx_http_variable_value_t *));
+ if (r->variables == NULL) {
+ return NULL;
}
}
- return -1;
+ r->variables[index] = vv;
+
+ return vv;
}
ngx_http_variable_value_t *
ngx_http_get_variable(ngx_http_request_t *r, ngx_str_t *name)
{
- ngx_int_t index;
ngx_uint_t i, key;
- ngx_http_core_variable_t *var;
+ ngx_http_variable_t *v;
+ ngx_http_core_variable_t *cv;
ngx_http_core_main_conf_t *cmcf;
cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
- index = ngx_http_get_variable_index(cmcf, name);
+ v = cmcf->variables.elts;
+ for (i = 0; i < cmcf->variables.nelts; i++) {
+ if (v[i].name.len != name->len) {
+ continue;
+ }
- if (index != -1) {
- return ngx_http_get_indexed_variable(r, index);
+ if (ngx_strncmp(v[i].name.data, name->data, name->len) == 0) {
+ return ngx_http_get_indexed_variable(r, v[i].index);
+ }
}
ngx_http_vars_hash_key(key, name);
- var = ngx_http_core_variables_hash[key].elts;
+ cv = ngx_http_core_variables_hash[key].elts;
for (i = 0; i < ngx_http_core_variables_hash[key].nelts; i++) {
-
- if (var[i].name.len != name->len
- || ngx_strncasecmp(var[i].name.data, name->data, name->len) != 0)
- {
+ if (cv[i].name.len != name->len) {
continue;
}
- return var[i].handler(r, var[i].data);
+ if (ngx_strncmp(cv[i].name.data, name->data, name->len) == 0) {
+ return cv[i].handler(r, cv[i].data);
+ }
}
- if (ngx_strncasecmp(name->data, "HTTP_", 5) != 0) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "unknown \"%V\" variable", name);
- return NGX_HTTP_VARIABLE_NOT_FOUND;
+ if (ngx_strncmp(name->data, "HTTP_", 5) == 0) {
+ return ngx_http_variable_unknown_header(r, (uintptr_t) name);
}
- return ngx_http_variable_unknown_header(r, name);
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "unknown \"%V\" variable", name);
+
+ return NGX_HTTP_VARIABLE_NOT_FOUND;
}
@@ -181,7 +213,7 @@ static ngx_http_variable_value_t *
ngx_http_variable_header(ngx_http_request_t *r, uintptr_t data)
{
ngx_table_elt_t *h;
- ngx_http_variable_value_t *v;
+ ngx_http_variable_value_t *vv;
h = *(ngx_table_elt_t **) ((char *) &r->headers_in + data);
@@ -189,25 +221,28 @@ ngx_http_variable_header(ngx_http_request_t *r, uintptr_t data)
return NGX_HTTP_VARIABLE_NOT_FOUND;
}
- if (!(v = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)))) {
+ vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
+ if (vv == NULL) {
return NULL;
}
- v->value = 0;
- v->text = h->value;
+ vv->value = 0;
+ vv->text = h->value;
- return v;
+ return vv;
}
static ngx_http_variable_value_t *
-ngx_http_variable_unknown_header(ngx_http_request_t *r, ngx_str_t *var)
+ngx_http_variable_unknown_header(ngx_http_request_t *r, uintptr_t data)
{
+ ngx_str_t *var = (ngx_str_t *) data;
+
u_char ch;
ngx_uint_t i, n;
ngx_list_part_t *part;
ngx_table_elt_t *header;
- ngx_http_variable_value_t *v;
+ ngx_http_variable_value_t *vv;
part = &r->headers_in.headers.part;
header = part->elts;
@@ -241,13 +276,14 @@ ngx_http_variable_unknown_header(ngx_http_request_t *r, ngx_str_t *var)
}
if (n + 5 == var->len) {
- if (!(v = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)))) {
+ vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
+ if (vv == NULL) {
return NULL;
}
- v->value = 0;
- v->text = header[i].value;
- return v;
+ vv->value = 0;
+ vv->text = header[i].value;
+ return vv;
}
}
@@ -258,56 +294,61 @@ ngx_http_variable_unknown_header(ngx_http_request_t *r, ngx_str_t *var)
static ngx_http_variable_value_t *
ngx_http_variable_remote_addr(ngx_http_request_t *r, uintptr_t data)
{
- ngx_http_variable_value_t *v;
+ ngx_http_variable_value_t *vv;
- if (!(v = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)))) {
+ vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
+ if (vv == NULL) {
return NULL;
}
- v->value = 0;
- v->text = r->connection->addr_text;
+ vv->value = 0;
+ vv->text = r->connection->addr_text;
- return v;
+ return vv;
}
static ngx_http_variable_value_t *
ngx_http_variable_uri(ngx_http_request_t *r, uintptr_t data)
{
- ngx_http_variable_value_t *v;
+ ngx_http_variable_value_t *vv;
- if (!(v = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)))) {
+ vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
+ if (vv == NULL) {
return NULL;
}
- v->value = 0;
- v->text = r->uri;
+ vv->value = 0;
+ vv->text = r->uri;
- return v;
+ return vv;
}
static ngx_http_variable_value_t *
ngx_http_variable_query_string(ngx_http_request_t *r, uintptr_t data)
{
- ngx_http_variable_value_t *v;
+ ngx_http_variable_value_t *vv;
- if (!(v = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)))) {
+ vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
+ if (vv == NULL) {
return NULL;
}
- v->value = 0;
- v->text = r->args;
+ vv->value = 0;
+ vv->text = r->args;
- return v;
+ return vv;
}
ngx_int_t
-ngx_http_core_variables_init(ngx_cycle_t *cycle)
+ngx_http_variables_init(ngx_cycle_t *cycle)
{
- ngx_uint_t i, key;
- ngx_http_core_variable_t *var, *v;
+ ngx_uint_t i, j, key;
+ ngx_http_variable_t *v;
+ ngx_http_core_variable_t *cv, *vp;
+ ngx_http_core_main_conf_t *cmcf;
ngx_http_core_variables_hash = ngx_palloc(cycle->pool,
NGX_HTTP_VARS_HASH_PRIME
@@ -324,14 +365,54 @@ ngx_http_core_variables_init(ngx_cycle_t *cycle)
}
}
- for (var = ngx_http_core_variables; var->name.len; var++) {
- ngx_http_vars_hash_key(key, &var->name);
+ for (cv = ngx_http_core_variables; cv->name.len; cv++) {
+ ngx_http_vars_hash_key(key, &cv->name);
- if (!(v = ngx_array_push(&ngx_http_core_variables_hash[key]))) {
+ vp = ngx_array_push(&ngx_http_core_variables_hash[key]);
+ if (vp == NULL) {
return NGX_ERROR;
}
- *v = *var;
+ *vp = *cv;
+ }
+
+
+ cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
+
+ v = cmcf->variables.elts;
+ for (i = 0; i < cmcf->variables.nelts; i++) {
+
+ if (v[i].handler) {
+ continue;
+ }
+
+ ngx_http_vars_hash_key(key, &v[i].name);
+
+ cv = ngx_http_core_variables_hash[key].elts;
+ for (j = 0; j < ngx_http_core_variables_hash[key].nelts; j++) {
+ if (cv[j].name.len != v[i].name.len) {
+ continue;
+ }
+
+ if (ngx_strncmp(cv[j].name.data, v[i].name.data, v[i].name.len)
+ == 0)
+ {
+ v[i].handler = cv[j].handler;
+ v[i].data = cv[j].data;
+ continue;
+ }
+ }
+
+ if (ngx_strncmp(v[i].name.data, "HTTP_", 5) == 0) {
+ v[i].handler = ngx_http_variable_unknown_header;
+ v[i].data = (uintptr_t) &v[i].name;
+ continue;
+ }
+
+ ngx_log_error(NGX_LOG_ERR, cycle->log, 0,
+ "unknown \"%V\" variable", &v[i].name);
+
+ return NGX_ERROR;
}
return NGX_OK;
diff --git a/src/http/ngx_http_variables.h b/src/http/ngx_http_variables.h
index c7ccdc12e..bf80386cb 100644
--- a/src/http/ngx_http_variables.h
+++ b/src/http/ngx_http_variables.h
@@ -17,45 +17,41 @@
#define NGX_HTTP_VARIABLE_NOT_FOUND (ngx_http_variable_value_t *) -1
-typedef struct {
+struct ngx_http_variable_value_s {
ngx_uint_t value;
ngx_str_t text;
-} ngx_http_variable_value_t;
-
+};
typedef struct ngx_http_variable_s ngx_http_variable_t;
typedef ngx_http_variable_value_t *
- (*ngx_http_get_variable_pt) (ngx_http_request_t *r, void *var);
+ (*ngx_http_get_variable_pt) (ngx_http_request_t *r, uintptr_t data);
struct ngx_http_variable_s {
- ngx_str_t name;
- ngx_uint_t index;
- ngx_http_get_variable_pt handler;
- void *data;
- ngx_uint_t uses;
+ ngx_str_t name;
+ ngx_uint_t index;
+ ngx_http_get_variable_pt handler;
+ uintptr_t data;
};
-typedef ngx_http_variable_value_t *
- (*ngx_http_get_core_variable_pt) (ngx_http_request_t *r, uintptr_t data);
-
typedef struct {
- ngx_str_t name;
- ngx_http_get_core_variable_pt handler;
- uintptr_t data;
+ ngx_str_t name;
+ ngx_http_get_variable_pt handler;
+ uintptr_t data;
} ngx_http_core_variable_t;
-ngx_http_variable_t *ngx_http_add_variable(ngx_conf_t *cf);
+ngx_http_variable_t *ngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name,
+ ngx_uint_t set);
ngx_int_t ngx_http_get_variable_index(ngx_http_core_main_conf_t *cmcf,
ngx_str_t *name);
ngx_http_variable_value_t *ngx_http_get_indexed_variable(ngx_http_request_t *r,
ngx_uint_t index);
ngx_http_variable_value_t *ngx_http_get_variable(ngx_http_request_t *r,
ngx_str_t *name);
-ngx_int_t ngx_http_core_variables_init(ngx_cycle_t *cycle);
+ngx_int_t ngx_http_variables_init(ngx_cycle_t *cycle);
#endif /* _NGX_HTTP_VARIABLES_H_INCLUDED_ */
diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter_module.c
index 12699096e..8883907ae 100644
--- a/src/http/ngx_http_write_filter.c
+++ b/src/http/ngx_http_write_filter_module.c
@@ -42,7 +42,8 @@ ngx_module_t ngx_http_write_filter_module = {
};
-ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
+ngx_int_t
+ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
off_t size, sent;
ngx_uint_t last, flush;
@@ -55,8 +56,13 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
ngx_http_write_filter_module);
if (ctx == NULL) {
- ngx_http_create_ctx(r, ctx, ngx_http_write_filter_module,
- sizeof(ngx_http_write_filter_ctx_t), NGX_ERROR);
+
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_write_filter_ctx_t));
+ if (ctx == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_http_set_ctx(r, ctx, ngx_http_write_filter_module);
}
size = 0;
@@ -112,7 +118,8 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
/* add the new chain to the existent one */
for (ln = in; ln; ln = ln->next) {
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
return NGX_ERROR;
}
@@ -190,7 +197,11 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
if (flush) {
- while ((ctx->out = ctx->out->next)) { /* void */ }
+ do {
+ ctx->out = ctx->out->next;
+ }
+ while (ctx->out);
+
return NGX_OK;
}
@@ -230,7 +241,8 @@ ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
-static ngx_int_t ngx_http_write_filter_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_write_filter_init(ngx_cycle_t *cycle)
{
ngx_http_top_body_filter = ngx_http_write_filter;
diff --git a/src/imap/ngx_imap_handler.c b/src/imap/ngx_imap_handler.c
index 4d9e93a28..371d77f8e 100644
--- a/src/imap/ngx_imap_handler.c
+++ b/src/imap/ngx_imap_handler.c
@@ -17,7 +17,9 @@ static ngx_int_t ngx_pop3_read_command(ngx_imap_session_t *s);
static u_char pop3_greeting[] = "+OK " NGINX_VER " ready" CRLF;
+#if 0
static u_char imap_greeting[] = "* OK " NGINX_VER " ready" CRLF;
+#endif
static u_char pop3_ok[] = "+OK" CRLF;
static u_char pop3_invalid_command[] = "-ERR invalid command" CRLF;
@@ -69,7 +71,8 @@ static void ngx_imap_init_session(ngx_event_t *rev)
return;
}
- if (!(s = ngx_pcalloc(c->pool, sizeof(ngx_imap_session_t)))) {
+ s = ngx_pcalloc(c->pool, sizeof(ngx_imap_session_t));
+ if (s == NULL) {
ngx_imap_close_connection(c);
return;
}
@@ -307,5 +310,5 @@ void ngx_imap_close_connection(ngx_connection_t *c)
ngx_close_connection(c);
- ngx_destroy_pool(c->pool);
+ ngx_destroy_pool(pool);
}
diff --git a/src/imap/ngx_imap_parse.c b/src/imap/ngx_imap_parse.c
index 03951a60b..6c1c3e95a 100644
--- a/src/imap/ngx_imap_parse.c
+++ b/src/imap/ngx_imap_parse.c
@@ -122,7 +122,8 @@ ngx_int_t ngx_pop3_parse_command(ngx_imap_session_t *s)
case ' ':
case CR:
case LF:
- if (!(arg = ngx_array_push(&s->args))) {
+ arg = ngx_array_push(&s->args);
+ if (arg == NULL) {
return NGX_ERROR;
}
arg->len = p - 1 - s->arg_start;
@@ -169,7 +170,8 @@ ngx_int_t ngx_pop3_parse_command(ngx_imap_session_t *s)
if (state == sw_done) {
if (s->arg_start) {
- if (!(arg = ngx_array_push(&s->args))) {
+ arg = ngx_array_push(&s->args);
+ if (arg == NULL) {
return NGX_ERROR;
}
arg->len = s->arg_end - s->arg_start;
diff --git a/src/imap/ngx_imap_proxy.c b/src/imap/ngx_imap_proxy.c
index dde349500..451fb3770 100644
--- a/src/imap/ngx_imap_proxy.c
+++ b/src/imap/ngx_imap_proxy.c
@@ -13,7 +13,6 @@
static void ngx_imap_proxy_block_read(ngx_event_t *rev);
static void ngx_imap_proxy_auth_handler(ngx_event_t *rev);
-static void ngx_imap_proxy_init_handler(ngx_event_t *wev);
static void ngx_imap_proxy_dummy_handler(ngx_event_t *ev);
static ngx_int_t ngx_imap_proxy_read_response(ngx_imap_session_t *s);
static void ngx_imap_proxy_handler(ngx_event_t *ev);
@@ -27,7 +26,8 @@ void ngx_imap_proxy_init(ngx_imap_session_t *s)
struct sockaddr_in *sin;
ngx_imap_proxy_ctx_t *p;
- if (!(p = ngx_pcalloc(s->connection->pool, sizeof(ngx_imap_proxy_ctx_t)))) {
+ p = ngx_pcalloc(s->connection->pool, sizeof(ngx_imap_proxy_ctx_t));
+ if (p == NULL) {
ngx_imap_close_connection(s->connection);
return;
}
@@ -36,7 +36,8 @@ void ngx_imap_proxy_init(ngx_imap_session_t *s)
/**/
- if (!(peers = ngx_pcalloc(s->connection->pool, sizeof(ngx_peers_t)))) {
+ peers = ngx_pcalloc(s->connection->pool, sizeof(ngx_peers_t));
+ if (peers == NULL) {
ngx_imap_close_connection(s->connection);
return;
}
@@ -45,7 +46,8 @@ void ngx_imap_proxy_init(ngx_imap_session_t *s)
p->upstream.log = s->connection->log;
p->upstream.log_error = NGX_ERROR_ERR;
- if (!(sin = ngx_pcalloc(s->connection->pool, sizeof(struct sockaddr_in)))) {
+ sin = ngx_pcalloc(s->connection->pool, sizeof(struct sockaddr_in));
+ if (sin == NULL) {
ngx_imap_close_connection(s->connection);
return;
}
@@ -146,14 +148,15 @@ static void ngx_imap_proxy_auth_handler(ngx_event_t *rev)
ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send user");
line.len = sizeof("USER ") + s->login.len - 1 + 2;
- if (!(line.data = ngx_palloc(c->pool, line.len))) {
+ line.data = ngx_palloc(c->pool, line.len);
+ if (line.data == NULL) {
ngx_imap_proxy_close_session(s);
return;
}
p = ngx_cpymem(line.data, "USER ", sizeof("USER ") - 1);
p = ngx_cpymem(p, s->login.data, s->login.len);
- *p++ = CR; *p++ = LF;
+ *p++ = CR; *p = LF;
if (ngx_send(c, line.data, line.len) < (ssize_t) line.len) {
/*
@@ -175,14 +178,15 @@ static void ngx_imap_proxy_auth_handler(ngx_event_t *rev)
ngx_log_debug0(NGX_LOG_DEBUG_IMAP, rev->log, 0, "imap proxy send pass");
line.len = sizeof("PASS ") + s->passwd.len - 1 + 2;
- if (!(line.data = ngx_palloc(c->pool, line.len))) {
+ line.data = ngx_palloc(c->pool, line.len);
+ if (line.data == NULL) {
ngx_imap_proxy_close_session(s);
return;
}
p = ngx_cpymem(line.data, "PASS ", sizeof("PASS ") - 1);
p = ngx_cpymem(p, s->passwd.data, s->passwd.len);
- *p++ = CR; *p++ = LF;
+ *p++ = CR; *p = LF;
if (ngx_send(c, line.data, line.len) < (ssize_t) line.len) {
/*
diff --git a/src/os/unix/ngx_aio_read_chain.c b/src/os/unix/ngx_aio_read_chain.c
index 31793d5a4..c6f9aea84 100644
--- a/src/os/unix/ngx_aio_read_chain.c
+++ b/src/os/unix/ngx_aio_read_chain.c
@@ -16,7 +16,6 @@ ssize_t ngx_aio_read_chain(ngx_connection_t *c, ngx_chain_t *cl)
u_char *buf, *prev;
size_t size;
ssize_t total;
- ngx_err_t err;
if (c->read->pending_eof) {
c->read->ready = 0;
diff --git a/src/os/unix/ngx_aio_write_chain.c b/src/os/unix/ngx_aio_write_chain.c
index 88b2474c9..b90f8bba1 100644
--- a/src/os/unix/ngx_aio_write_chain.c
+++ b/src/os/unix/ngx_aio_write_chain.c
@@ -17,7 +17,6 @@ ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in,
off_t send, sent;
size_t len;
ssize_t n, size;
- ngx_err_t err;
ngx_chain_t *cl;
/* the maximum limit size is the maximum size_t value - the page size */
diff --git a/src/os/unix/ngx_alloc.c b/src/os/unix/ngx_alloc.c
index 258a10fa9..72cf4e42e 100644
--- a/src/os/unix/ngx_alloc.c
+++ b/src/os/unix/ngx_alloc.c
@@ -11,11 +11,13 @@
int ngx_pagesize;
-void *ngx_alloc(size_t size, ngx_log_t *log)
+void *
+ngx_alloc(size_t size, ngx_log_t *log)
{
void *p;
- if (!(p = malloc(size))) {
+ p = malloc(size);
+ if (p == NULL) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
"malloc() %uz bytes failed", size);
}
@@ -26,7 +28,8 @@ void *ngx_alloc(size_t size, ngx_log_t *log)
}
-void *ngx_calloc(size_t size, ngx_log_t *log)
+void *
+ngx_calloc(size_t size, ngx_log_t *log)
{
void *p;
@@ -42,7 +45,8 @@ void *ngx_calloc(size_t size, ngx_log_t *log)
#if (NGX_HAVE_POSIX_MEMALIGN)
-void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
+void *
+ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
{
void *p;
@@ -60,11 +64,13 @@ void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
#elif (NGX_HAVE_MEMALIGN)
-void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
+void *
+ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
{
void *p;
- if (!(p = memalign(alignment, size))) {
+ p = memalign(alignment, size);
+ if (p == NULL) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
"memalign() %uz bytes aligned to %uz failed",
size, alignment);
diff --git a/src/os/unix/ngx_errno.c b/src/os/unix/ngx_errno.c
index 607b361d9..a3addf00c 100644
--- a/src/os/unix/ngx_errno.c
+++ b/src/os/unix/ngx_errno.c
@@ -34,8 +34,7 @@ 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;
- size_t len;
+ char *str;
if (size == 0) {
return 0;
diff --git a/src/os/unix/ngx_errno.h b/src/os/unix/ngx_errno.h
index c1c5801d3..51d608bf4 100644
--- a/src/os/unix/ngx_errno.h
+++ b/src/os/unix/ngx_errno.h
@@ -25,7 +25,7 @@ typedef int ngx_err_t;
#define NGX_ENOTDIR ENOTDIR
#define NGX_EINVAL EINVAL
#define NGX_EPIPE EPIPE
-#define NGX_EAGAIN EWOULDBLOCK
+#define NGX_EAGAIN EAGAIN
#define NGX_EINPROGRESS EINPROGRESS
#define NGX_EADDRINUSE EADDRINUSE
#define NGX_ECONNABORTED ECONNABORTED
@@ -52,10 +52,10 @@ u_char *ngx_strerror_r(int err, u_char *errstr, size_t size);
#else
-/* Solaris has threads-safe strerror() */
+/* Solaris has thread-safe strerror() */
#define ngx_strerror_r(err, errstr, size) \
- ngx_cpystrn(errstr, (u_char *) strerror(err), size)
+ ngx_cpystrn(errstr, (u_char *) strerror(err), size)
#endif
diff --git a/src/os/unix/ngx_files.c b/src/os/unix/ngx_files.c
index e67b2cac7..f8f98c7fe 100644
--- a/src/os/unix/ngx_files.c
+++ b/src/os/unix/ngx_files.c
@@ -131,7 +131,6 @@ ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl,
u_char *prev;
size_t size;
ssize_t n;
- ngx_err_t err;
ngx_array_t vec;
struct iovec *iov, iovs[NGX_IOVS];
@@ -162,7 +161,8 @@ ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl,
iov->iov_len += cl->buf->last - cl->buf->pos;
} else {
- if (!(iov = ngx_array_push(&vec))) {
+ iov = ngx_array_push(&vec);
+ if (iov == NULL) {
return NGX_ERROR;
}
diff --git a/src/os/unix/ngx_freebsd_init.c b/src/os/unix/ngx_freebsd_init.c
index 044d9d5c9..7defb4676 100644
--- a/src/os/unix/ngx_freebsd_init.c
+++ b/src/os/unix/ngx_freebsd_init.c
@@ -14,6 +14,7 @@ char ngx_freebsd_kern_osrelease[128];
int ngx_freebsd_kern_osreldate;
int ngx_freebsd_hw_ncpu;
int ngx_freebsd_net_inet_tcp_sendspace;
+int ngx_freebsd_kern_ipc_somaxconn;
/* FreeBSD 4.9 */
int ngx_freebsd_machdep_hlt_logical_cpus;
@@ -61,6 +62,10 @@ sysctl_t sysctls[] = {
&ngx_freebsd_net_inet_tcp_sendspace,
sizeof(int), 0 },
+ { "kern.ipc.somaxconn",
+ &ngx_freebsd_kern_ipc_somaxconn,
+ sizeof(int), 0 },
+
{ "kern.ipc.zero_copy.send",
&ngx_freebsd_kern_ipc_zero_copy_send,
sizeof(int), 0 },
@@ -85,7 +90,7 @@ void ngx_debug_init()
ngx_int_t ngx_os_init(ngx_log_t *log)
{
- int version;
+ int version, somaxconn;
size_t size;
ngx_err_t err;
ngx_uint_t i;
@@ -203,6 +208,18 @@ ngx_int_t ngx_os_init(ngx_log_t *log)
ngx_ncpu = ngx_freebsd_hw_ncpu;
}
+ if (version < 600008) {
+ somaxconn = 32767;
+ } else {
+ somaxconn = 65535;
+ }
+
+ if (ngx_freebsd_kern_ipc_somaxconn > somaxconn) {
+ ngx_log_error(NGX_LOG_ALERT, log, 0,
+ "sysctl kern.ipc.somaxconn must be no more than %d",
+ somaxconn);
+ return NGX_ERROR;
+ }
ngx_tcp_nodelay_and_tcp_nopush = 1;
diff --git a/src/os/unix/ngx_freebsd_rfork_thread.c b/src/os/unix/ngx_freebsd_rfork_thread.c
index 5dfd46807..b7e803b3c 100644
--- a/src/os/unix/ngx_freebsd_rfork_thread.c
+++ b/src/os/unix/ngx_freebsd_rfork_thread.c
@@ -227,13 +227,15 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle)
/* create the thread errno' array */
- if (!(errnos = ngx_calloc(n * sizeof(int), cycle->log))) {
+ errnos = ngx_calloc(n * sizeof(int), cycle->log);
+ if (errnos == NULL) {
return NGX_ERROR;
}
/* create the thread tids array */
- if (!(tids = ngx_calloc((n + 1) * sizeof(ngx_tid_t), cycle->log))) {
+ tids = ngx_calloc((n + 1) * sizeof(ngx_tid_t), cycle->log);
+ if (tids == NULL) {
return NGX_ERROR;
}
@@ -264,8 +266,7 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle)
ngx_tid_t ngx_thread_self()
{
- int tid;
- ngx_tid_t pid;
+ ngx_int_t tid;
tid = ngx_gettid();
@@ -305,7 +306,8 @@ ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags)
ngx_mutex_t *m;
union semun op;
- if (!(m = ngx_alloc(sizeof(ngx_mutex_t), log))) {
+ m = ngx_alloc(sizeof(ngx_mutex_t), log);
+ if (m == NULL) {
return NULL;
}
@@ -353,7 +355,7 @@ void ngx_mutex_destroy(ngx_mutex_t *m)
ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
{
- uint32_t lock, new, old;
+ uint32_t lock, old;
ngx_uint_t tries;
struct sembuf op;
@@ -483,7 +485,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
{
- uint32_t lock, new, old;
+ uint32_t lock, old;
struct sembuf op;
if (!ngx_threaded) {
@@ -576,7 +578,8 @@ ngx_cond_t *ngx_cond_init(ngx_log_t *log)
{
ngx_cond_t *cv;
- if (!(cv = ngx_alloc(sizeof(ngx_cond_t), log))) {
+ cv = ngx_alloc(sizeof(ngx_cond_t), log);
+ if (cv == NULL) {
return NULL;
}
diff --git a/src/os/unix/ngx_freebsd_rfork_thread.h b/src/os/unix/ngx_freebsd_rfork_thread.h
index 2af0adb80..215d2dc86 100644
--- a/src/os/unix/ngx_freebsd_rfork_thread.h
+++ b/src/os/unix/ngx_freebsd_rfork_thread.h
@@ -56,7 +56,7 @@ extern char *ngx_freebsd_kern_usrstack;
extern size_t ngx_thread_stack_size;
-static inline int ngx_gettid()
+static ngx_inline ngx_int_t ngx_gettid()
{
char *sp;
diff --git a/src/os/unix/ngx_freebsd_sendfile_chain.c b/src/os/unix/ngx_freebsd_sendfile_chain.c
index 50cad3090..a29aaf3c9 100644
--- a/src/os/unix/ngx_freebsd_sendfile_chain.c
+++ b/src/os/unix/ngx_freebsd_sendfile_chain.c
@@ -21,19 +21,19 @@
* to postpone the sending - it not only sends a header and the first part of
* the file in one packet, but also sends the file pages in the full packets.
*
- * But until FreeBSD 4.5 the turning TCP_NOPUSH off does not flush a pending
- * data that less than MSS so that data may be sent with 5 second delay.
- * So we do not use TCP_NOPUSH on FreeBSD prior to 4.5 although it can be used
+ * But until FreeBSD 4.5 turning TCP_NOPUSH off does not flush a pending
+ * data that less than MSS, so that data may be sent with 5 second delay.
+ * So we do not use TCP_NOPUSH on FreeBSD prior to 4.5, although it can be used
* for non-keepalive HTTP connections.
*/
#define NGX_HEADERS 8
-#define NGX_TRAILERS 4
+#define NGX_TRAILERS 8
-ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
- off_t limit)
+ngx_chain_t *
+ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
{
int rc;
u_char *prev;
@@ -123,7 +123,8 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
iov->iov_len += (size_t) size;
} else {
- if (!(iov = ngx_array_push(&header))) {
+ iov = ngx_array_push(&header);
+ if (iov == NULL) {
return NGX_CHAIN_ERROR;
}
@@ -197,7 +198,8 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
iov->iov_len += (size_t) size;
} else {
- if (!(iov = ngx_array_push(&trailer))) {
+ iov = ngx_array_push(&trailer);
+ if (iov == NULL) {
return NGX_CHAIN_ERROR;
}
diff --git a/src/os/unix/ngx_linux_sendfile_chain.c b/src/os/unix/ngx_linux_sendfile_chain.c
index ac8c303eb..9ddac673a 100644
--- a/src/os/unix/ngx_linux_sendfile_chain.c
+++ b/src/os/unix/ngx_linux_sendfile_chain.c
@@ -121,7 +121,8 @@ ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
iov->iov_len += (size_t) size;
} else {
- if (!(iov = ngx_array_push(&header))) {
+ iov = ngx_array_push(&header);
+ if (iov == NULL) {
return NGX_CHAIN_ERROR;
}
diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c
index 4fb512665..d48343b30 100644
--- a/src/os/unix/ngx_posix_init.c
+++ b/src/os/unix/ngx_posix_init.c
@@ -182,7 +182,7 @@ void ngx_signal_handler(int signo)
case ngx_signal_value(NGX_NOACCEPT_SIGNAL):
ngx_noaccept = 1;
- action = ", stop the accepting connections";
+ action = ", stop accepting connections";
break;
case ngx_signal_value(NGX_RECONFIGURE_SIGNAL):
diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c
index 0825c5f3a..0562a4644 100644
--- a/src/os/unix/ngx_process.c
+++ b/src/os/unix/ngx_process.c
@@ -214,7 +214,6 @@ void ngx_process_get_status()
ngx_err_t err;
ngx_int_t i;
ngx_uint_t one;
- struct timeval tv;
one = 0;
diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c
index a48880914..9c5a7ee15 100644
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -11,7 +11,7 @@
static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n,
- ngx_int_t type);
+ ngx_int_t type);
static void ngx_start_garbage_collector(ngx_cycle_t *cycle, ngx_int_t type);
static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo);
static ngx_uint_t ngx_reap_childs(ngx_cycle_t *cycle);
@@ -23,7 +23,9 @@ static void ngx_channel_handler(ngx_event_t *ev);
static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle);
static void *ngx_worker_thread_cycle(void *data);
#endif
+#if 0
static void ngx_garbage_collector_cycle(ngx_cycle_t *cycle, void *data);
+#endif
ngx_uint_t ngx_process;
@@ -59,7 +61,8 @@ ngx_int_t ngx_threads_n;
u_char master_process[] = "master process";
-void ngx_master_process_cycle(ngx_cycle_t *cycle)
+void
+ngx_master_process_cycle(ngx_cycle_t *cycle)
{
char *title;
u_char *p;
@@ -254,7 +257,8 @@ void ngx_master_process_cycle(ngx_cycle_t *cycle)
}
-void ngx_single_process_cycle(ngx_cycle_t *cycle)
+void
+ngx_single_process_cycle(ngx_cycle_t *cycle)
{
ngx_uint_t i;
@@ -300,8 +304,8 @@ void ngx_single_process_cycle(ngx_cycle_t *cycle)
}
-static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n,
- ngx_int_t type)
+static void
+ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n, ngx_int_t type)
{
ngx_int_t i;
ngx_channel_t ch;
@@ -359,12 +363,12 @@ static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n,
}
-static void ngx_start_garbage_collector(ngx_cycle_t *cycle, ngx_int_t type)
+static void
+ngx_start_garbage_collector(ngx_cycle_t *cycle, ngx_int_t type)
{
- ngx_int_t i;
- ngx_channel_t ch;
-
- return;
+#if 0
+ ngx_int_t i;
+ ngx_channel_t ch;
ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "start garbage collector");
@@ -397,16 +401,17 @@ static void ngx_start_garbage_collector(ngx_cycle_t *cycle, ngx_int_t type)
ngx_write_channel(ngx_processes[i].channel[0],
&ch, sizeof(ngx_channel_t), cycle->log);
}
+#endif
}
-static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo)
+static void
+ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo)
{
ngx_int_t i;
ngx_err_t err;
ngx_channel_t ch;
-
switch (signo) {
case ngx_signal_value(NGX_SHUTDOWN_SIGNAL):
@@ -492,7 +497,8 @@ static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo)
}
-static ngx_uint_t ngx_reap_childs(ngx_cycle_t *cycle)
+static ngx_uint_t
+ngx_reap_childs(ngx_cycle_t *cycle)
{
ngx_int_t i, n;
ngx_uint_t live;
@@ -619,7 +625,8 @@ static ngx_uint_t ngx_reap_childs(ngx_cycle_t *cycle)
}
-static void ngx_master_exit(ngx_cycle_t *cycle)
+static void
+ngx_master_exit(ngx_cycle_t *cycle)
{
ngx_delete_pidfile(cycle);
@@ -631,11 +638,14 @@ static void ngx_master_exit(ngx_cycle_t *cycle)
}
-static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
+static void
+ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
{
+#if (NGX_THREADS)
ngx_int_t n;
ngx_err_t err;
ngx_core_conf_t *ccf;
+#endif
ngx_worker_process_init(cycle, 1);
@@ -668,7 +678,9 @@ static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
for (n = 0; n < ngx_threads_n; n++) {
- if (!(ngx_threads[n].cv = ngx_cond_init(cycle->log))) {
+ ngx_threads[n].cv = ngx_cond_init(cycle->log);
+
+ if (ngx_threads[n].cv == NULL) {
/* fatal */
exit(2);
}
@@ -748,7 +760,8 @@ static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
}
-static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
+static void
+ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
{
sigset_t set;
ngx_int_t n;
@@ -873,7 +886,8 @@ static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
}
-static void ngx_channel_handler(ngx_event_t *ev)
+static void
+ngx_channel_handler(ngx_event_t *ev)
{
ngx_int_t n;
ngx_channel_t ch;
@@ -952,7 +966,8 @@ static void ngx_channel_handler(ngx_event_t *ev)
#if (NGX_THREADS)
-static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle)
+static void
+ngx_wakeup_worker_threads(ngx_cycle_t *cycle)
{
ngx_int_t i;
ngx_uint_t live;
@@ -994,7 +1009,8 @@ static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle)
}
-static void *ngx_worker_thread_cycle(void *data)
+static void *
+ngx_worker_thread_cycle(void *data)
{
ngx_thread_t *thr = data;
@@ -1022,7 +1038,8 @@ static void *ngx_worker_thread_cycle(void *data)
ngx_setthrtitle("worker thread");
- if (!(tls = ngx_calloc(sizeof(ngx_core_tls_t), cycle->log))) {
+ tls = ngx_calloc(sizeof(ngx_core_tls_t), cycle->log);
+ if (tls == NULL) {
return (void *) 1;
}
@@ -1077,7 +1094,10 @@ static void *ngx_worker_thread_cycle(void *data)
#endif
-static void ngx_garbage_collector_cycle(ngx_cycle_t *cycle, void *data)
+#if 0
+
+static void
+ngx_garbage_collector_cycle(ngx_cycle_t *cycle, void *data)
{
ngx_uint_t i;
ngx_gc_t ctx;
@@ -1123,3 +1143,5 @@ static void ngx_garbage_collector_cycle(ngx_cycle_t *cycle, void *data)
ngx_process_events(cycle);
}
}
+
+#endif
diff --git a/src/os/unix/ngx_pthread_thread.c b/src/os/unix/ngx_pthread_thread.c
index 4903d5e50..0b55c7192 100644
--- a/src/os/unix/ngx_pthread_thread.c
+++ b/src/os/unix/ngx_pthread_thread.c
@@ -75,7 +75,8 @@ ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags)
int err;
ngx_mutex_t *m;
- if (!(m = ngx_alloc(sizeof(ngx_mutex_t), log))) {
+ m = ngx_alloc(sizeof(ngx_mutex_t), log);
+ if (m == NULL) {
return NULL;
}
@@ -189,7 +190,8 @@ ngx_cond_t *ngx_cond_init(ngx_log_t *log)
int err;
ngx_cond_t *cv;
- if (!(cv = ngx_alloc(sizeof(ngx_cond_t), log))) {
+ cv = ngx_alloc(sizeof(ngx_cond_t), log);
+ if (cv == NULL) {
return NULL;
}
diff --git a/src/os/unix/ngx_readv_chain.c b/src/os/unix/ngx_readv_chain.c
index 7c57b7abe..47d8f3b7c 100644
--- a/src/os/unix/ngx_readv_chain.c
+++ b/src/os/unix/ngx_readv_chain.c
@@ -9,16 +9,20 @@
#include <ngx_event.h>
+#define NGX_IOVS 16
+
+
#if (NGX_HAVE_KQUEUE)
-ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
+ssize_t
+ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
{
u_char *prev;
ssize_t n, size;
ngx_err_t err;
- ngx_array_t io;
+ ngx_array_t vec;
ngx_event_t *rev;
- struct iovec *iov;
+ struct iovec *iov, iovs[NGX_IOVS];
rev = c->read;
@@ -53,7 +57,11 @@ ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
iov = NULL;
size = 0;
- ngx_init_array(io, c->pool, 10, sizeof(struct iovec), NGX_ERROR);
+ vec.elts = iovs;
+ vec.nelts = 0;
+ vec.size = sizeof(struct iovec);
+ vec.nalloc = NGX_IOVS;
+ vec.pool = c->pool;
/* coalesce the neighbouring bufs */
@@ -62,7 +70,11 @@ ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
iov->iov_len += chain->buf->end - chain->buf->last;
} else {
- ngx_test_null(iov, ngx_push_array(&io), NGX_ERROR);
+ iov = ngx_array_push(&vec);
+ if (iov == NULL) {
+ return NGX_ERROR;
+ }
+
iov->iov_base = (void *) chain->buf->last;
iov->iov_len = chain->buf->end - chain->buf->last;
}
@@ -73,12 +85,12 @@ ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
}
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "readv: %d, last:%d", io.nelts, iov->iov_len);
+ "readv: %d, last:%d", vec.nelts, iov->iov_len);
rev = c->read;
do {
- n = readv(c->fd, (struct iovec *) io.elts, io.nelts);
+ n = readv(c->fd, (struct iovec *) vec.elts, vec.nelts);
if (n >= 0) {
if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
@@ -138,20 +150,25 @@ ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
#else /* ! NGX_HAVE_KQUEUE */
-ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
+ssize_t
+ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
{
u_char *prev;
ssize_t n, size;
ngx_err_t err;
- ngx_array_t io;
+ ngx_array_t vec;
ngx_event_t *rev;
- struct iovec *iov;
+ struct iovec *iov, iovs[NGX_IOVS];
prev = NULL;
iov = NULL;
size = 0;
- ngx_init_array(io, c->pool, 10, sizeof(struct iovec), NGX_ERROR);
+ vec.elts = iovs;
+ vec.nelts = 0;
+ vec.size = sizeof(struct iovec);
+ vec.nalloc = NGX_IOVS;
+ vec.pool = c->pool;
/* coalesce the neighbouring bufs */
@@ -160,7 +177,11 @@ ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
iov->iov_len += chain->buf->end - chain->buf->last;
} else {
- ngx_test_null(iov, ngx_push_array(&io), NGX_ERROR);
+ iov = ngx_array_push(&vec);
+ if (iov == NULL) {
+ return NGX_ERROR;
+ }
+
iov->iov_base = chain->buf->last;
iov->iov_len = chain->buf->end - chain->buf->last;
}
@@ -171,12 +192,12 @@ ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
}
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "readv: %d:%d", io.nelts, iov->iov_len);
+ "readv: %d:%d", vec.nelts, iov->iov_len);
rev = c->read;
do {
- n = readv(c->fd, (struct iovec *) io.elts, io.nelts);
+ n = readv(c->fd, (struct iovec *) vec.elts, vec.nelts);
if (n == 0) {
rev->ready = 0;
diff --git a/src/os/unix/ngx_setproctitle.c b/src/os/unix/ngx_setproctitle.c
index 6c95cdf4e..25bbc9b1e 100644
--- a/src/os/unix/ngx_setproctitle.c
+++ b/src/os/unix/ngx_setproctitle.c
@@ -43,7 +43,8 @@ ngx_init_setproctitle(ngx_log_t *log)
size += ngx_strlen(environ[i]) + 1;
}
- if (!(p = ngx_alloc(size, log))) {
+ p = ngx_alloc(size, log);
+ if (p == NULL) {
return NGX_ERROR;
}
diff --git a/src/os/unix/ngx_socket.c b/src/os/unix/ngx_socket.c
index 523f1f4ce..121958977 100644
--- a/src/os/unix/ngx_socket.c
+++ b/src/os/unix/ngx_socket.c
@@ -22,7 +22,8 @@
#if (NGX_HAVE_FIONBIO)
-int ngx_nonblocking(ngx_socket_t s)
+int
+ngx_nonblocking(ngx_socket_t s)
{
u_long nb;
@@ -32,7 +33,8 @@ int ngx_nonblocking(ngx_socket_t s)
}
-int ngx_blocking(ngx_socket_t s)
+int
+ngx_blocking(ngx_socket_t s)
{
u_long nb;
@@ -46,7 +48,8 @@ int ngx_blocking(ngx_socket_t s)
#if (NGX_FREEBSD)
-int ngx_tcp_nopush(ngx_socket_t s)
+int
+ngx_tcp_nopush(ngx_socket_t s)
{
int tcp_nopush;
@@ -57,7 +60,8 @@ int ngx_tcp_nopush(ngx_socket_t s)
}
-int ngx_tcp_push(ngx_socket_t s)
+int
+ngx_tcp_push(ngx_socket_t s)
{
int tcp_nopush;
@@ -69,7 +73,8 @@ int ngx_tcp_push(ngx_socket_t s)
#elif (NGX_LINUX)
-int ngx_tcp_nopush(ngx_socket_t s)
+int
+ngx_tcp_nopush(ngx_socket_t s)
{
int cork;
@@ -79,7 +84,8 @@ int ngx_tcp_nopush(ngx_socket_t s)
(const void *) &cork, sizeof(int));
}
-int ngx_tcp_push(ngx_socket_t s)
+int
+ngx_tcp_push(ngx_socket_t s)
{
int cork;
@@ -91,14 +97,16 @@ int ngx_tcp_push(ngx_socket_t s)
#else
-int ngx_tcp_nopush(ngx_socket_t s)
+int
+ngx_tcp_nopush(ngx_socket_t s)
{
- return NGX_OK;
+ return 0;
}
-int ngx_tcp_push(ngx_socket_t s)
+int
+ngx_tcp_push(ngx_socket_t s)
{
- return NGX_OK;
+ return 0;
}
#endif
diff --git a/src/os/unix/ngx_solaris_sendfilev_chain.c b/src/os/unix/ngx_solaris_sendfilev_chain.c
index c5b812091..4345385e3 100644
--- a/src/os/unix/ngx_solaris_sendfilev_chain.c
+++ b/src/os/unix/ngx_solaris_sendfilev_chain.c
@@ -47,7 +47,7 @@ ngx_chain_t *ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in,
sendfilevec_t *sfv, sfvs[NGX_SENDFILEVECS];
ngx_array_t vec;
ngx_event_t *wev;
- ngx_chain_t *cl, *tail;
+ ngx_chain_t *cl;
wev = c->write;
@@ -107,7 +107,8 @@ ngx_chain_t *ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in,
sfv->sfv_len += (size_t) size;
} else {
- if (!(sfv = ngx_array_push(&vec))) {
+ sfv = ngx_array_push(&vec);
+ if (sfv == NULL) {
return NGX_CHAIN_ERROR;
}
@@ -140,7 +141,8 @@ ngx_chain_t *ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in,
sfv->sfv_len += (size_t) size;
} else {
- if (!(sfv = ngx_array_push(&vec))) {
+ sfv = ngx_array_push(&vec);
+ if (sfv == NULL) {
return NGX_CHAIN_ERROR;
}
diff --git a/src/os/unix/ngx_writev_chain.c b/src/os/unix/ngx_writev_chain.c
index 9cbcd864d..ed3ad7158 100644
--- a/src/os/unix/ngx_writev_chain.c
+++ b/src/os/unix/ngx_writev_chain.c
@@ -12,7 +12,8 @@
#define NGX_IOVS 16
-ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
+ngx_chain_t *
+ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
{
u_char *prev;
ssize_t n, size, sent;
@@ -88,7 +89,8 @@ ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
iov->iov_len += size;
} else {
- if (!(iov = ngx_array_push(&vec))) {
+ iov = ngx_array_push(&vec);
+ if (iov == NULL) {
return NGX_CHAIN_ERROR;
}
diff --git a/src/os/win32/ngx_alloc.c b/src/os/win32/ngx_alloc.c
index e73aa32af..a3bca02a9 100644
--- a/src/os/win32/ngx_alloc.c
+++ b/src/os/win32/ngx_alloc.c
@@ -15,7 +15,8 @@ void *ngx_alloc(size_t size, ngx_log_t *log)
{
void *p;
- if (!(p = malloc(size))) {
+ p = malloc(size);
+ if (p == NULL) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
"malloc() %uz bytes failed", size);
}
diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c
index ce0fdc966..bea580b24 100644
--- a/src/os/win32/ngx_files.c
+++ b/src/os/win32/ngx_files.c
@@ -179,7 +179,8 @@ ngx_int_t ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to,
ngx_uint_t collision;
ngx_atomic_uint_t num;
- if (!(name = ngx_palloc(pool, to->len + 1 + 10 + 1 + sizeof("DELETE")))) {
+ name = ngx_palloc(pool, to->len + 1 + 10 + 1 + sizeof("DELETE"));
+ if (name == NULL) {
return NGX_ERROR;
}
@@ -301,6 +302,20 @@ ngx_int_t ngx_read_dir(ngx_dir_t *dir)
}
+ngx_int_t
+ngx_de_info(u_char *name, ngx_dir_t *dir)
+{
+ return NGX_OK;
+}
+
+
+ngx_int_t
+ngx_de_link_info(u_char *name, ngx_dir_t *dir)
+{
+ return NGX_OK;
+}
+
+
ngx_int_t ngx_file_append_mode(ngx_fd_t fd)
{
#if 0
diff --git a/src/os/win32/ngx_files.h b/src/os/win32/ngx_files.h
index 48b54b38a..a91743132 100644
--- a/src/os/win32/ngx_files.h
+++ b/src/os/win32/ngx_files.h
@@ -132,10 +132,13 @@ ngx_int_t ngx_read_dir(ngx_dir_t *dir);
#define ngx_de_name(dir) ((u_char *) (dir)->fd.cFileName)
#define ngx_de_namelen(dir) ngx_strlen((dir)->fd.cFileName)
-#define ngx_de_info(name, dir) NGX_OK
+
+ngx_int_t ngx_de_info(u_char *name, ngx_dir_t *dir);
#define ngx_de_info_n "dummy()"
-#define ngx_de_link_info(name, dir) NGX_OK
+
+ngx_int_t ngx_de_link_info(u_char *name, ngx_dir_t *dir);
#define ngx_de_link_info_n "dummy()"
+
#define ngx_de_is_dir(dir) \
((dir)->fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
#define ngx_de_is_file(dir) \
diff --git a/src/os/win32/ngx_process_cycle.c b/src/os/win32/ngx_process_cycle.c
index e0635a5eb..2251ff2df 100644
--- a/src/os/win32/ngx_process_cycle.c
+++ b/src/os/win32/ngx_process_cycle.c
@@ -206,7 +206,7 @@ static void *ngx_worker_thread_cycle(void *data)
cycle = (ngx_cycle_t *) ngx_cycle;
- for ( ;; ) {
+ while (!ngx_quit) {
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle");
ngx_process_events(cycle);
diff --git a/src/os/win32/ngx_socket.c b/src/os/win32/ngx_socket.c
index fc7743356..7590c3376 100644
--- a/src/os/win32/ngx_socket.c
+++ b/src/os/win32/ngx_socket.c
@@ -8,7 +8,8 @@
#include <ngx_core.h>
-int ngx_nonblocking(ngx_socket_t s)
+int
+ngx_nonblocking(ngx_socket_t s)
{
unsigned long nb = 1;
@@ -16,9 +17,17 @@ int ngx_nonblocking(ngx_socket_t s)
}
-int ngx_blocking(ngx_socket_t s)
+int
+ngx_blocking(ngx_socket_t s)
{
unsigned long nb = 0;
return ioctlsocket(s, FIONBIO, &nb);
}
+
+
+int
+ngx_tcp_push(ngx_socket_t s)
+{
+ return 0;
+}
diff --git a/src/os/win32/ngx_socket.h b/src/os/win32/ngx_socket.h
index 88752889a..95ecbe8cd 100644
--- a/src/os/win32/ngx_socket.h
+++ b/src/os/win32/ngx_socket.h
@@ -98,10 +98,7 @@ extern LPFN_GETACCEPTEXSOCKADDRS getacceptexsockaddrs;
extern LPFN_TRANSMITFILE transmitfile;
-static ngx_inline int ngx_tcp_push(ngx_socket_t s) {
- return 0;
-}
-
+int ngx_tcp_push(ngx_socket_t s);
#define ngx_tcp_push_n "tcp_push()"
diff --git a/src/os/win32/ngx_thread.c b/src/os/win32/ngx_thread.c
index 8fae0e379..0703ac7d4 100644
--- a/src/os/win32/ngx_thread.c
+++ b/src/os/win32/ngx_thread.c
@@ -66,3 +66,19 @@ ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags)
{
return (ngx_mutex_t *) 1;
}
+
+
+/* STUB */
+
+ngx_int_t
+ngx_mutex_lock(ngx_mutex_t *m) {
+ return NGX_OK;
+}
+
+
+ngx_int_t
+ngx_mutex_trylock(ngx_mutex_t *m) {
+ return NGX_OK;
+}
+
+/**/
diff --git a/src/os/win32/ngx_thread.h b/src/os/win32/ngx_thread.h
index 5b3c4da98..b55dcca4d 100644
--- a/src/os/win32/ngx_thread.h
+++ b/src/os/win32/ngx_thread.h
@@ -22,8 +22,8 @@ typedef struct {
} ngx_mutex_t;
-ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg,
- ngx_log_t *log);
+ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg),
+ void *arg, ngx_log_t *log);
ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle);
ngx_err_t ngx_thread_key_create(ngx_tls_key_t *key);
@@ -41,14 +41,15 @@ ngx_err_t ngx_thread_set_tls(ngx_tls_key_t *key, void *data);
ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags);
+ngx_int_t ngx_mutex_lock(ngx_mutex_t *m);
+ngx_int_t ngx_mutex_trylock(ngx_mutex_t *m);
+
/* STUB */
#define NGX_MUTEX_LIGHT 0
-#define ngx_mutex_lock(m) NGX_OK
-#define ngx_mutex_trylock(m) NGX_OK
#define ngx_mutex_unlock(m)
-/* */
+/**/
extern ngx_int_t ngx_threads_n;
diff --git a/src/os/win32/ngx_win32_config.h b/src/os/win32/ngx_win32_config.h
index 36af23906..02d4db5c6 100644
--- a/src/os/win32/ngx_win32_config.h
+++ b/src/os/win32/ngx_win32_config.h
@@ -37,7 +37,6 @@
#pragma warning(default:4201)
-
/* disable some "-W4" level warnings */
/* 'type cast': from function pointer to data pointer */
@@ -49,14 +48,13 @@
/* unreferenced formal parameter */
#pragma warning(disable:4100)
-/* conditional expression is constant */
+/* FD_SET() and FD_CLR(): conditional expression is constant */
#pragma warning(disable:4127)
-/* unreachable code */
-#pragma warning(disable:4702)
-
+#if 0
/* assignment within conditional expression */
#pragma warning(disable:4706)
+#endif
/* function 'ngx_handle_write_event' not inlined */
#pragma warning(disable:4710)
@@ -66,9 +64,6 @@
#ifdef __WATCOMC__
-/* unreachable code */
-#pragma disable_message(201)
-
/* symbol 'ngx_rbtree_min' has been defined, but not referenced */
#pragma disable_message(202)
@@ -80,25 +75,16 @@
/* the end of the precompiled headers */
#pragma hdrstop
-/*
- * 'fd' is assigned a value that is never used in function ngx_event_init_conf
- */
-#pragma warn -8004
-
-/* condition is always false */
-#pragma warn -8008
-
/* functions containing (for|while|some if) are not expanded inline */
#pragma warn -8027
/* unreferenced formal parameter */
#pragma warn -8057
+#if 0
/* assignment within conditional expression */
#pragma warn -8060
-
-/* unreachable code */
-#pragma warn -8066
+#endif
#endif
diff --git a/src/os/win32/ngx_wsarecv_chain.c b/src/os/win32/ngx_wsarecv_chain.c
index 2e2f7cc92..c22a08df7 100644
--- a/src/os/win32/ngx_wsarecv_chain.c
+++ b/src/os/win32/ngx_wsarecv_chain.c
@@ -9,16 +9,21 @@
#include <ngx_event.h>
-ssize_t ngx_wsarecv_chain(ngx_connection_t *c, ngx_chain_t *chain)
+#define NGX_WSABUFS 8
+
+
+ssize_t
+ngx_wsarecv_chain(ngx_connection_t *c, ngx_chain_t *chain)
{
int rc;
u_char *prev;
u_long bytes, flags;
size_t size;
- WSABUF *wsabuf;
ngx_err_t err;
- ngx_array_t io;
+ ngx_array_t vec;
ngx_event_t *rev;
+ LPWSABUF wsabuf;
+ WSABUF wsabufs[NGX_WSABUFS];
prev = NULL;
wsabuf = NULL;
@@ -26,7 +31,11 @@ ssize_t ngx_wsarecv_chain(ngx_connection_t *c, ngx_chain_t *chain)
size = 0;
bytes = 0;
- ngx_init_array(io, c->pool, 10, sizeof(WSABUF), NGX_ERROR);
+ vec.elts = wsabufs;
+ vec.nelts = 0;
+ vec.size = sizeof(WSABUF);
+ vec.nalloc = NGX_WSABUFS;
+ vec.pool = c->pool;
/* coalesce the neighbouring bufs */
@@ -35,7 +44,11 @@ ssize_t ngx_wsarecv_chain(ngx_connection_t *c, ngx_chain_t *chain)
wsabuf->len += chain->buf->end - chain->buf->last;
} else {
- ngx_test_null(wsabuf, ngx_push_array(&io), NGX_ERROR);
+ wsabuf = ngx_array_push(&vec);
+ if (wsabuf == NULL) {
+ return NGX_ERROR;
+ }
+
wsabuf->buf = (char *) chain->buf->last;
wsabuf->len = chain->buf->end - chain->buf->last;
}
@@ -46,10 +59,10 @@ ssize_t ngx_wsarecv_chain(ngx_connection_t *c, ngx_chain_t *chain)
}
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "WSARecv: %d:%d", io.nelts, wsabuf->len);
+ "WSARecv: %d:%d", vec.nelts, wsabuf->len);
- rc = WSARecv(c->fd, io.elts, io.nelts, &bytes, &flags, NULL, NULL);
+ rc = WSARecv(c->fd, vec.elts, vec.nelts, &bytes, &flags, NULL, NULL);
rev = c->read;
diff --git a/src/os/win32/ngx_wsasend_chain.c b/src/os/win32/ngx_wsasend_chain.c
index d5b1334a1..bc3b01574 100644
--- a/src/os/win32/ngx_wsasend_chain.c
+++ b/src/os/win32/ngx_wsasend_chain.c
@@ -12,8 +12,8 @@
#define NGX_WSABUFS 8
-ngx_chain_t *ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in,
- off_t limit)
+ngx_chain_t *
+ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
{
int rc;
u_char *prev;
@@ -22,9 +22,9 @@ ngx_chain_t *ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in,
ngx_err_t err;
ngx_event_t *wev;
ngx_array_t vec;
+ ngx_chain_t *cl;
LPWSABUF wsabuf;
WSABUF wsabufs[NGX_WSABUFS];
- ngx_chain_t *cl;
wev = c->write;
@@ -78,7 +78,8 @@ ngx_chain_t *ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in,
wsabuf->len += cl->buf->last - cl->buf->pos;
} else {
- if (!(wsabuf = ngx_array_push(&vec))) {
+ wsabuf = ngx_array_push(&vec);
+ if (wsabuf == NULL) {
return NGX_CHAIN_ERROR;
}
@@ -154,18 +155,18 @@ ngx_chain_t *ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in,
}
-ngx_chain_t *ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in,
- off_t limit)
+ngx_chain_t *
+ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
{
int rc;
u_char *prev;
u_long size, send, sent;
- LPWSABUF wsabuf;
ngx_err_t err;
ngx_event_t *wev;
ngx_array_t vec;
ngx_chain_t *cl;
LPWSAOVERLAPPED ovlp;
+ LPWSABUF wsabuf;
WSABUF wsabufs[NGX_WSABUFS];
wev = c->write;
@@ -222,7 +223,8 @@ ngx_chain_t *ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in,
wsabuf->len += cl->buf->last - cl->buf->pos;
} else {
- if (!(wsabuf = ngx_array_push(&vec))) {
+ wsabuf = ngx_array_push(&vec);
+ if (wsabuf == NULL) {
return NGX_CHAIN_ERROR;
}