add ngx_devel_kit and lua-resty-env deps, support set_by_lua hook for plugins and init work on whitelisting support with modsecurity
This commit is contained in:
parent
c2402b118f
commit
79036e9751
|
@ -1,15 +1,13 @@
|
|||
# /etc/nginx/nginx.conf
|
||||
|
||||
# load dynamic modules
|
||||
load_module /usr/share/bunkerweb/modules/ndk_http_module.so;
|
||||
load_module /usr/share/bunkerweb/modules/ngx_http_cookie_flag_filter_module.so;
|
||||
#load_module /usr/share/bunkerweb/modules/ngx_http_geoip2_module.so;
|
||||
load_module /usr/share/bunkerweb/modules/ngx_http_headers_more_filter_module.so;
|
||||
load_module /usr/share/bunkerweb/modules/ngx_http_lua_module.so;
|
||||
load_module /usr/share/bunkerweb/modules/ngx_http_modsecurity_module.so;
|
||||
load_module /usr/share/bunkerweb/modules/ngx_http_brotli_filter_module.so;
|
||||
load_module /usr/share/bunkerweb/modules/ngx_http_brotli_static_module.so;
|
||||
#load_module /usr/share/bunkerweb/modules/ngx_stream_geoip2_module.so;
|
||||
#load_module /usr/share/bunkerweb/modules/ngx_stream_lua_module.so;
|
||||
|
||||
# PID file
|
||||
pid /var/tmp/bunkerweb/nginx.pid;
|
||||
|
|
|
@ -19,6 +19,7 @@ server {
|
|||
set $reason '';
|
||||
|
||||
# include LUA files
|
||||
include {{ NGINX_PREFIX }}set-lua.conf;
|
||||
include {{ NGINX_PREFIX }}access-lua.conf;
|
||||
include {{ NGINX_PREFIX }}log-lua.conf;
|
||||
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
set $dummy_set "";
|
||||
set_by_lua_block $dummy_set {
|
||||
|
||||
local utils = require "utils"
|
||||
local logger = require "logger"
|
||||
local datastore = require "datastore"
|
||||
local plugins = require "plugins"
|
||||
|
||||
logger.log(ngx.INFO, "SET", "Set phase started")
|
||||
|
||||
-- List all plugins
|
||||
local list, err = plugins:list()
|
||||
if not list then
|
||||
logger.log(ngx.ERR, "SET", "Can't list loaded plugins : " .. err)
|
||||
list = {}
|
||||
end
|
||||
|
||||
-- Call set method of plugins
|
||||
for i, plugin in ipairs(list) do
|
||||
local ret, plugin_lua = pcall(require, plugin.id .. "/" .. plugin.id)
|
||||
if ret then
|
||||
local plugin_obj = plugin_lua.new()
|
||||
if plugin_obj.set ~= nil then
|
||||
logger.log(ngx.INFO, "SET", "Executing set() of " .. plugin.id)
|
||||
local ok, err = plugin_obj:set()
|
||||
if not ok then
|
||||
logger.log(ngx.ERR, "SET", "Error while calling set() on plugin " .. plugin.id .. " : " .. err)
|
||||
else
|
||||
logger.log(ngx.INFO, "SET", "Return value from " .. plugin.id .. ".set() is : " .. err)
|
||||
end
|
||||
else
|
||||
logger.log(ngx.INFO, "SET", "set() method not found in " .. plugin.id .. ", skipped execution")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
logger.log(ngx.INFO, "SET", "Set phase ended")
|
||||
|
||||
}
|
|
@ -94,11 +94,16 @@ SecAction \
|
|||
pass,\
|
||||
t:none,\
|
||||
setvar:'tx.allowed_methods={{ ALLOWED_METHODS.replace("|", " ") }}'"
|
||||
|
||||
{% endif +%}
|
||||
|
||||
# Check if client is whitelisted
|
||||
{% if USE_WHITELIST == "yes" +%}
|
||||
SecRule ENV:is_whitelisted "yes" "id:1000,phase:1,pass,nolog,ctl:ruleEngine=Off"
|
||||
{% endif +%}
|
||||
|
||||
# include OWASP CRS rules
|
||||
include /usr/share/bunkerweb/core/modsecurity/files/coreruleset/rules/*.conf
|
||||
{% endif %}
|
||||
{% endif +%}
|
||||
|
||||
# custom rules after loading the CRS
|
||||
{% if is_custom_conf("/etc/bunkerweb/configs/modsec") %}
|
||||
|
|
|
@ -1 +1 @@
|
|||
set $is_whitelisted '';
|
||||
set $is_whitelisted 'no';
|
|
@ -1 +1 @@
|
|||
set $is_whitelisted '';
|
||||
set $is_whitelisted 'no';
|
|
@ -6,6 +6,7 @@ local datastore = require "datastore"
|
|||
local logger = require "logger"
|
||||
local cjson = require "cjson"
|
||||
local ipmatcher = require "resty.ipmatcher"
|
||||
local env = require "resty.env"
|
||||
|
||||
function _M.new()
|
||||
local self = setmetatable({}, _M)
|
||||
|
@ -48,6 +49,48 @@ function _M:init()
|
|||
return true, "successfully loaded " .. tostring(i) .. " whitelisted IP/network/rDNS/ASN/User-Agent/URI"
|
||||
end
|
||||
|
||||
function _M:set()
|
||||
|
||||
-- Set default value
|
||||
ngx.var.is_whitelisted = "no"
|
||||
env.set("is_whitelisted", "no")
|
||||
|
||||
-- Check if access is needed
|
||||
local set_needed, err = utils.get_variable("USE_WHITELIST")
|
||||
if set_needed == nil then
|
||||
return false, err
|
||||
end
|
||||
if set_needed ~= "yes" then
|
||||
return true, "whitelist not enabled"
|
||||
end
|
||||
|
||||
-- Check the cache
|
||||
local cached_ip, err = self:is_in_cache("ip" .. ngx.var.remote_addr)
|
||||
if cached_ip and cached_ip ~= "ok" then
|
||||
ngx.var.is_whitelisted = "yes"
|
||||
env.set("is_whitelisted", "yes")
|
||||
return true, "ip whitelisted"
|
||||
end
|
||||
local cached_uri, err = self:is_in_cache("uri" .. ngx.var.uri)
|
||||
if cached_uri and cached_uri ~= "ok" then
|
||||
ngx.var.is_whitelisted = "yes"
|
||||
env.set("is_whitelisted", "yes")
|
||||
return true, "uri whitelisted"
|
||||
end
|
||||
local cached_ua = true
|
||||
if ngx.var.http_user_agent then
|
||||
cached_ua, err = self:is_in_cache("ua" .. ngx.var.http_user_agent)
|
||||
if cached_ua and cached_ua ~= "ok" then
|
||||
ngx.var.is_whitelisted = "yes"
|
||||
env.set("is_whitelisted", "yes")
|
||||
return true, "ua whitelisted"
|
||||
end
|
||||
end
|
||||
|
||||
-- Not whitelisted
|
||||
return true, "not whitelisted"
|
||||
end
|
||||
|
||||
function _M:access()
|
||||
-- Check if access is needed
|
||||
local access_needed, err = utils.get_variable("USE_WHITELIST")
|
||||
|
|
|
@ -103,6 +103,7 @@ class Templator:
|
|||
"access-lua.conf",
|
||||
"init-lua.conf",
|
||||
"log-lua.conf",
|
||||
"set-lua.conf"
|
||||
]
|
||||
for root_conf in root_confs:
|
||||
if template.endswith(f"/{root_conf}"):
|
||||
|
|
|
@ -238,6 +238,10 @@ fi
|
|||
echo "ℹ️ Downloading lbase64"
|
||||
git_secure_clone "https://github.com/iskolbin/lbase64.git" "c261320edbdf82c16409d893a96c28c704aa0ab8"
|
||||
|
||||
# lua-resty-env v0.4.0
|
||||
echo "ℹ️ Downloading lua-resty-env"
|
||||
git_secure_clone "https://github.com/3scale/lua-resty-env.git" "adb294def823dd910ffa11972d2c61eab7cfce3e"
|
||||
|
||||
# ModSecurity v3.0.8 (19 commits after just in case)
|
||||
echo "ℹ️ Downloading ModSecurity"
|
||||
if [ ! -d "deps/src/ModSecurity" ] ; then
|
||||
|
@ -273,18 +277,6 @@ git_secure_clone "https://github.com/maxmind/libmaxminddb.git" "ac4d0d2480032a86
|
|||
echo "ℹ️ Downloading headers-more-nginx-module"
|
||||
git_secure_clone "https://github.com/openresty/headers-more-nginx-module.git" "bea1be3bbf6af28f6aa8cf0c01c07ee1637e2bd0"
|
||||
|
||||
# ngx_http_geoip2_module v3.3
|
||||
#echo "ℹ️ Downloading ngx_http_geoip2_module"
|
||||
#dosed="no"
|
||||
#if [ ! -d "deps/src/ngx_http_geoip2_module" ] ; then
|
||||
# dosed="yes"
|
||||
#fi
|
||||
#git_secure_clone "https://github.com/leev/ngx_http_geoip2_module.git" "5a83b6f958c67ea88d2899d0b3c2a5db8e36b211"
|
||||
#if [ "$dosed" = "yes" ] ; then
|
||||
# do_and_check_cmd sed -i '1s:^:ngx_feature_path=/opt/bunkerweb/deps/include\n:' deps/src/ngx_http_geoip2_module/config
|
||||
# do_and_check_cmd sed -i 's:^ngx_feature_libs=.*$:ngx_feature_libs="-Wl,-rpath,/opt/bunkerweb/deps/lib -L/opt/bunkerweb/deps/lib -lmaxminddb":' deps/src/ngx_http_geoip2_module/config
|
||||
#fi
|
||||
|
||||
# nginx_cookie_flag_module v1.1.0
|
||||
echo "ℹ️ Downloading nginx_cookie_flag_module"
|
||||
git_secure_clone "https://github.com/AirisX/nginx_cookie_flag_module.git" "4e48acf132952bbed43b28a8e6af0584dacb7b4c"
|
||||
|
@ -292,3 +284,7 @@ git_secure_clone "https://github.com/AirisX/nginx_cookie_flag_module.git" "4e48a
|
|||
# ngx_brotli v1.0.0
|
||||
echo "ℹ️ Downloading ngx_brotli"
|
||||
git_secure_clone "https://github.com/google/ngx_brotli.git" "6e975bcb015f62e1f303054897783355e2a877dc"
|
||||
|
||||
# ngx_devel_kit
|
||||
echo "ℹ️ Downloading ngx_devel_kit"
|
||||
git_secure_clone "https://github.com/vision5/ngx_devel_kit.git" "b4642d6ca01011bd8cd30b253f5c3872b384fd21"
|
||||
|
|
|
@ -119,6 +119,10 @@ do_and_check_cmd cp -r /tmp/bunkerweb/deps/src/luajit-geoip/geoip /usr/share/bun
|
|||
echo "ℹ️ Installing lbase64"
|
||||
do_and_check_cmd cp -r /tmp/bunkerweb/deps/src/lbase64/base64.lua /usr/share/bunkerweb/deps/lib/lua
|
||||
|
||||
# Installing lua-resty-env
|
||||
echo "ℹ️ Installing lua-resty-env"
|
||||
do_and_check_cmd cp -r /tmp/bunkerweb/deps/src/lua-resty-env/src/resty/env.lua /usr/share/bunkerweb/deps/lib/lua/resty
|
||||
|
||||
# Compile dynamic modules
|
||||
echo "ℹ️ Compiling and installing dynamic modules"
|
||||
CONFARGS="$(nginx -V 2>&1 | sed -n -e 's/^.*arguments: //p')"
|
||||
|
@ -128,7 +132,7 @@ if [ "$OS" = "fedora" ] ; then
|
|||
CONFARGS="$(echo -n "$CONFARGS" | sed "s/--with-ld-opt='.*'/--with-ld-opt=-lpcre/" | sed "s/--with-cc-opt='.*'//")"
|
||||
fi
|
||||
echo '#!/bin/bash' > "/tmp/bunkerweb/deps/src/nginx-${NGINX_VERSION}/configure-fix.sh"
|
||||
echo "./configure $CONFARGS --add-dynamic-module=/tmp/bunkerweb/deps/src/ModSecurity-nginx --add-dynamic-module=/tmp/bunkerweb/deps/src/headers-more-nginx-module --add-dynamic-module=/tmp/bunkerweb/deps/src/nginx_cookie_flag_module --add-dynamic-module=/tmp/bunkerweb/deps/src/lua-nginx-module --add-dynamic-module=/tmp/bunkerweb/deps/src/ngx_brotli" >> "/tmp/bunkerweb/deps/src/nginx-${NGINX_VERSION}/configure-fix.sh"
|
||||
echo "./configure $CONFARGS --add-dynamic-module=/tmp/bunkerweb/deps/src/ModSecurity-nginx --add-dynamic-module=/tmp/bunkerweb/deps/src/headers-more-nginx-module --add-dynamic-module=/tmp/bunkerweb/deps/src/nginx_cookie_flag_module --add-dynamic-module=/tmp/bunkerweb/deps/src/lua-nginx-module --add-dynamic-module=/tmp/bunkerweb/deps/src/ngx_brotli --add-dynamic-module=/tmp/bunkerweb/deps/src/ngx_devel_kit" >> "/tmp/bunkerweb/deps/src/nginx-${NGINX_VERSION}/configure-fix.sh"
|
||||
do_and_check_cmd chmod +x "/tmp/bunkerweb/deps/src/nginx-${NGINX_VERSION}/configure-fix.sh"
|
||||
CHANGE_DIR="/tmp/bunkerweb/deps/src/nginx-${NGINX_VERSION}" LUAJIT_LIB="/usr/share/bunkerweb/deps/lib -Wl,-rpath,/usr/share/bunkerweb/deps/lib" LUAJIT_INC="/usr/share/bunkerweb/deps/include/luajit-2.1" MODSECURITY_LIB="/usr/share/bunkerweb/deps/lib" MODSECURITY_INC="/usr/share/bunkerweb/deps/include" do_and_check_cmd ./configure-fix.sh
|
||||
CHANGE_DIR="/tmp/bunkerweb/deps/src/nginx-${NGINX_VERSION}" do_and_check_cmd make -j $NTASK modules
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
version: 2
|
||||
jobs:
|
||||
build:
|
||||
docker:
|
||||
- image: quay.io/3scale/s2i-openresty-centos7:luarocks-build
|
||||
working_directory: /opt/app-root/lua-resty-env
|
||||
steps:
|
||||
- checkout
|
||||
- run: luarocks make rockspecs/*.rockspec
|
||||
- run: luarocks build rockspecs/*.rockspec
|
||||
- run: luarocks install busted
|
||||
- run: bin/busted
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
engines:
|
||||
fixme:
|
||||
enabled: true
|
||||
luacheck:
|
||||
enabled: true
|
||||
channel: beta
|
||||
ratings:
|
||||
paths:
|
||||
- "**/*.lua"
|
||||
exclude_paths:
|
||||
- .idea
|
|
@ -0,0 +1,2 @@
|
|||
/lua-resty-env-*
|
||||
!*.rockspec
|
|
@ -0,0 +1,3 @@
|
|||
std = 'ngx_lua+lua52' -- lua52 has table.pack
|
||||
|
||||
files["spec"] = {std = "+busted"}
|
|
@ -0,0 +1,201 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,2 @@
|
|||
test:
|
||||
@resty -e "require('busted.runner')({ standalone = false })"
|
|
@ -0,0 +1,154 @@
|
|||
Name
|
||||
====
|
||||
|
||||
lua-resty-env - Lua cache for calls to `os.getenv`.
|
||||
|
||||
|
||||
Table of Contents
|
||||
=================
|
||||
|
||||
* [Name](#name)
|
||||
* [Status](#status)
|
||||
* [Description](#description)
|
||||
* [Synopsis](#synopsis)
|
||||
* [Methods](#methods)
|
||||
* [get](#get)
|
||||
* [set](#set)
|
||||
* [value](#value)
|
||||
* [enabled](#enabled)
|
||||
* [reset](#reset)
|
||||
* [Installation](#installation)
|
||||
* [TODO](#todo)
|
||||
* [Community](#community)
|
||||
* [Bugs and Patches](#bugs-and-patches)
|
||||
* [Author](#author)
|
||||
* [Copyright and License](#copyright-and-license)
|
||||
* [See Also](#see-also)
|
||||
|
||||
Status
|
||||
======
|
||||
|
||||
This library is considered production ready.
|
||||
|
||||
Description
|
||||
===========
|
||||
|
||||
This Lua library is a cache for calls to `os.getenv`.
|
||||
|
||||
This library acts as a mediator between other libraries and the environment variables.
|
||||
Variables can not only be get but also set.
|
||||
|
||||
Synopsis
|
||||
========
|
||||
|
||||
```lua
|
||||
|
||||
env SOME_VARIABLE;
|
||||
|
||||
http {
|
||||
server {
|
||||
location /test {
|
||||
content_by_lua_block {
|
||||
local resty_env = require 'resty.env'
|
||||
|
||||
ngx.say("SOME_VARIABLE: ", resty_env.get('SOME_VARIABLE'))
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
Methods
|
||||
=======
|
||||
|
||||
All the methods are expected to be called on the module without self.
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
get
|
||||
---
|
||||
`syntax: val = env.get(name)`
|
||||
|
||||
Returns environment value from the cache or uses `os.getenv` to get it.
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
set
|
||||
-------
|
||||
`syntax: prev = env.set(name, value)`
|
||||
|
||||
Sets the the `value` to the cache and returns the previous value in the cache.
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
list
|
||||
-------
|
||||
`syntax: table = env.list()`
|
||||
|
||||
Returns a table with all environment variables. Names are keys and values are values.
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
enabled
|
||||
----------
|
||||
`syntax: ok = env.enabled(name)`
|
||||
|
||||
Returns true if the environment variable has truthy value (`1`, `true`), false (`0`, `false`) or `nil`.
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
reset
|
||||
------------
|
||||
`syntax: env = env.reset()`
|
||||
|
||||
Resets the internal cache.
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
If you are using the OpenResty bundle (http://openresty.org ), then
|
||||
you can use [opm](https://github.com/openresty/opm#synopsis) to install this package.
|
||||
|
||||
```shell
|
||||
opm get 3scale/lua-resty-env
|
||||
```
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
Bugs and Patches
|
||||
================
|
||||
|
||||
Please report bugs or submit patches by
|
||||
|
||||
1. creating a ticket on the [GitHub Issue Tracker](http://github.com/3scale/lua-resty-env/issues),
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
Author
|
||||
======
|
||||
|
||||
Michal "mikz" Cichra <mcichra@redhat.com>, Red Hat Inc.
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
Copyright and License
|
||||
=====================
|
||||
|
||||
This module is licensed under the Apache License Version 2.0.
|
||||
|
||||
Copyright (C) 2016-2017, Red Hat Inc.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
See [LICENSE](LICENSE) for the full license.
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
See Also
|
||||
========
|
||||
* the APIcast API Gateway: https://github.com/3scale/apicast/#readme
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env resty
|
||||
|
||||
if ngx ~= nil then
|
||||
ngx.exit = function()end
|
||||
end
|
||||
|
||||
-- Busted command-line runner
|
||||
require 'busted.runner'({ standalone = false })
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
# distribution config for opm packaging
|
||||
name = lua-resty-env
|
||||
abstract = Cache for os.getenv calls
|
||||
author = Michal Cichra (mikz)
|
||||
is_original = yes
|
||||
license = apache2
|
||||
lib_dir = src
|
||||
doc_dir = .
|
||||
repo_link = https://github.com/3scale/lua-resty-env
|
||||
main_module = src/resty/env.lua
|
||||
requires = ngx_http_lua
|
|
@ -0,0 +1,21 @@
|
|||
package = "lua-resty-env"
|
||||
version = "0.3.0-1"
|
||||
source = {
|
||||
url = "https://github.com/3scale/lua-resty-env/archive/v0.3.0.tar.gz",
|
||||
md5 = "00c05a22173d0b06927118b85c98e029",
|
||||
dir = "lua-resty-env-0.3.0",
|
||||
}
|
||||
description = {
|
||||
summary = "lua-resty-env - Lua cache for calls to `os.getenv`.",
|
||||
detailed = "lua-resty-env - Lua cache for calls to `os.getenv`.",
|
||||
homepage = "https://github.com/3scale/lua-resty-env",
|
||||
license = "Apache License 2.0"
|
||||
}
|
||||
dependencies = {
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
["resty.env"] = "src/resty/env.lua"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package = "lua-resty-env"
|
||||
version = "scm-1"
|
||||
source = {
|
||||
url = "git+https://github.com/3scale/lua-resty-env.git"
|
||||
}
|
||||
description = {
|
||||
summary = "lua-resty-env - Lua cache for calls to `os.getenv`.",
|
||||
detailed = "lua-resty-env - Lua cache for calls to `os.getenv`.",
|
||||
homepage = "https://github.com/3scale/lua-resty-env",
|
||||
license = "Apache License 2.0"
|
||||
}
|
||||
dependencies = {
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
["resty.env"] = "src/resty/env.lua"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
local _M = require 'resty.env'
|
||||
|
||||
describe('env', function()
|
||||
local env
|
||||
before_each(function() env = _M.env end)
|
||||
after_each(function() _M.env = env end)
|
||||
|
||||
describe('.list', function()
|
||||
it('returns contents of the ENV variable', function()
|
||||
local list = _M.list()
|
||||
|
||||
assert.truthy(list.PATH)
|
||||
assert.truthy(list.HOME)
|
||||
assert.truthy(list.PWD)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('.get', function()
|
||||
|
||||
local path = os.getenv("PATH")
|
||||
|
||||
it('returns contents of the ENV variable', function()
|
||||
assert.equal(path, _M.get('PATH'))
|
||||
end)
|
||||
|
||||
it('caches the result', function()
|
||||
_M.get('PATH')
|
||||
|
||||
assert.equal(path, _M.env.PATH)
|
||||
end)
|
||||
|
||||
it('reads from the cache first', function()
|
||||
_M.env = { ['SOME_MISSING_ENV_VAR'] = 'somevalue' }
|
||||
|
||||
assert.equal('somevalue', _M.get("SOME_MISSING_ENV_VAR"))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('.value', function()
|
||||
it('returns false instead of empty value', function()
|
||||
_M.set('KEY', '')
|
||||
assert.equal(false, _M.value('KEY'))
|
||||
end)
|
||||
|
||||
it('returns the value if not emptu', function()
|
||||
_M.set('KEY', 'value')
|
||||
assert.equal('value', _M.value('KEY'))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('.set', function()
|
||||
it('saves value to the cache', function()
|
||||
_M.set('SOME_MISSING_KEY', 'val')
|
||||
|
||||
assert.equal('val', _M.env.SOME_MISSING_KEY)
|
||||
end)
|
||||
|
||||
it('calls setenv', function()
|
||||
local key = 'SOME_UNUSED_KEY'
|
||||
assert.falsy(os.getenv(key))
|
||||
_M.set(key, 'value')
|
||||
assert.equal('value', os.getenv(key))
|
||||
end)
|
||||
|
||||
it('converts the value to string', function()
|
||||
_M.set('NUMERIC_VALUE', 1234)
|
||||
|
||||
assert.equal('1234', _M.env.NUMERIC_VALUE)
|
||||
end)
|
||||
|
||||
it('works with nil', function()
|
||||
assert.truthy(_M.get('_'))
|
||||
|
||||
_M.set('_', nil)
|
||||
|
||||
assert.equal(nil, os.getenv('_'))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('.reset', function()
|
||||
it('cleans the cache', function()
|
||||
_M.env.SOMETHING_EMPTY = 'foo'
|
||||
|
||||
_M.reset()
|
||||
|
||||
assert.same(nil, _M.env.SOMETHING_EMPTY)
|
||||
end)
|
||||
end)
|
||||
end)
|
|
@ -0,0 +1,172 @@
|
|||
------------
|
||||
-- Resty ENV
|
||||
-- OpenResty module for working with ENV variables.
|
||||
--
|
||||
-- @module resty.env
|
||||
-- @author mikz
|
||||
-- @license Apache License Version 2.0
|
||||
|
||||
local _M = {
|
||||
_VERSION = '0.4.0'
|
||||
}
|
||||
|
||||
local tostring = tostring
|
||||
local sub = string.sub
|
||||
local find = string.find
|
||||
local pairs = pairs
|
||||
local getenv = os.getenv
|
||||
|
||||
local ffi = require('ffi')
|
||||
ffi.cdef([=[
|
||||
int setenv(const char*, const char*, int);
|
||||
int unsetenv(const char*);
|
||||
extern char **environ;
|
||||
]=])
|
||||
|
||||
local C = ffi.C
|
||||
|
||||
local function ffi_error()
|
||||
return C.strerror(ffi.errno())
|
||||
end
|
||||
|
||||
local function unsetenv(name)
|
||||
if C.unsetenv(name) == -1 then
|
||||
return nil, ffi_error()
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function setenv(name, value, overwrite)
|
||||
local overwrite_flag = overwrite and 1 or 0
|
||||
|
||||
if not value then
|
||||
return nil, 'missing value'
|
||||
end
|
||||
|
||||
if C.setenv(name, value, overwrite_flag) == -1 then
|
||||
return nil, C.strerror(ffi.errno())
|
||||
else
|
||||
return value
|
||||
end
|
||||
end
|
||||
|
||||
local function environ() -- return whole environment as table
|
||||
local env = C.environ
|
||||
if not env then return nil end
|
||||
local ret = {}
|
||||
local i = 0
|
||||
|
||||
while env[i] ~= nil do
|
||||
local e = ffi.string(env[i])
|
||||
local eq = find(e, '=')
|
||||
if eq then
|
||||
ret[sub(e, 1, eq - 1)] = sub(e, eq + 1)
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
for name, value in pairs(_M.env) do
|
||||
ret[name] = value
|
||||
end
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
local cached = {}
|
||||
|
||||
local function fetch(name)
|
||||
local value
|
||||
|
||||
if cached[name] then
|
||||
value = _M.env[name]
|
||||
else
|
||||
value = getenv(name)
|
||||
|
||||
ngx.log(ngx.DEBUG, 'env: ', name, ' = ', value)
|
||||
_M.env[name] = value
|
||||
|
||||
cached[name] = true
|
||||
end
|
||||
|
||||
return value
|
||||
end
|
||||
|
||||
--- Return a table with all environment variables.
|
||||
function _M.list()
|
||||
return environ()
|
||||
end
|
||||
|
||||
--- Return the raw value from ENV. Uses local cache.
|
||||
-- @tparam string name name of the environment variable
|
||||
function _M.get(name)
|
||||
return _M.env[name] or fetch(name)
|
||||
end
|
||||
|
||||
local value_mapping = {
|
||||
[''] = false
|
||||
}
|
||||
|
||||
--- Return value from ENV.
|
||||
--- Returns false if it is empty. Uses @{get} internally.
|
||||
-- @tparam string name name of the environment variable
|
||||
function _M.value(name)
|
||||
local value = _M.get(name)
|
||||
local mapped = value_mapping[value]
|
||||
|
||||
if mapped == nil then
|
||||
return value
|
||||
else
|
||||
return mapped
|
||||
end
|
||||
end
|
||||
|
||||
local env_mapping = {
|
||||
['true'] = true,
|
||||
['false'] = false,
|
||||
['1'] = true,
|
||||
['0'] = false,
|
||||
[''] = false
|
||||
}
|
||||
|
||||
--- Returns true/false from ENV variable.
|
||||
--- Converts 0 to false and 1 to true.
|
||||
-- @tparam string name name of the environment variable
|
||||
function _M.enabled(name)
|
||||
return env_mapping[_M.get(name)]
|
||||
end
|
||||
|
||||
--- Sets value to the local cache.
|
||||
-- @tparam string name name of the environment variable
|
||||
-- @tparam string value value to be cached
|
||||
-- @see resty.env.get
|
||||
function _M.set(name, value)
|
||||
local env = _M.env
|
||||
|
||||
local val = value and tostring(value)
|
||||
local ok, err
|
||||
|
||||
if val then
|
||||
ok, err = setenv(name, val, true)
|
||||
else
|
||||
ok, err = unsetenv(name)
|
||||
end
|
||||
|
||||
local previous = env[name]
|
||||
|
||||
if ok then
|
||||
env[name] = val
|
||||
cached[name] = nil
|
||||
end
|
||||
|
||||
return previous, err
|
||||
end
|
||||
|
||||
--- Reset local cache.
|
||||
function _M.reset()
|
||||
_M.env = {}
|
||||
cached = {}
|
||||
return _M
|
||||
end
|
||||
|
||||
return _M.reset()
|
|
@ -0,0 +1,4 @@
|
|||
tags
|
||||
cscope.*
|
||||
*~
|
||||
*.swp
|
|
@ -0,0 +1,13 @@
|
|||
Copyright (c) 2010-2018, Marcus Clyne
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -0,0 +1,254 @@
|
|||
Name
|
||||
====
|
||||
|
||||
Nginx Development Kit (NDK)
|
||||
|
||||
Table of Contents
|
||||
=================
|
||||
|
||||
* [Name](#name)
|
||||
* [Synopsis](#synopsis)
|
||||
* [Status](#status)
|
||||
* [Features](#features)
|
||||
* [Design](#design)
|
||||
* [modular](#modular)
|
||||
* [auto-generated & easily extensible](#auto-generated--easily-extensible)
|
||||
* [Usage for users](#usage-for-users)
|
||||
* [Building as a dynamic module](#building-as-a-dynamic-module)
|
||||
* [Usage for developers](#usage-for-developers)
|
||||
* [Warning: using NDK_ALL](#warning-using-ndk_all)
|
||||
* [Modules using NDK](#modules-using-ndk)
|
||||
* [TODO](#todo)
|
||||
* [License](#license)
|
||||
* [Contributing / Feedback](#contributing--feedback)
|
||||
* [Authors](#authors)
|
||||
* [Special Thanks](#special-thanks)
|
||||
|
||||
Synopsis
|
||||
========
|
||||
|
||||
The NDK is an Nginx module that is designed to extend the core functionality of the
|
||||
excellent Nginx webserver in a way that can be used as a basis of other Nginx modules.
|
||||
|
||||
It has functions and macros to deal with generic tasks that don't currently have
|
||||
generic code as part of the core distribution. The NDK itself adds few features
|
||||
that are seen from a user's point of view - it's just designed to help reduce the
|
||||
code that Nginx module developers need to write.
|
||||
|
||||
Nginx module developers wishing to use any of the features in the NDK should specify
|
||||
that the NDK is a dependency of their module, and that users will need to compile
|
||||
it as well when they compile their own modules. They will also need to declare in
|
||||
their own modules which features of the NDK they wish to use (explained below).
|
||||
|
||||
If you are not an Nginx module developer, then the only useful part of this project
|
||||
will be the 'usage for users' section below.
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
Status
|
||||
======
|
||||
|
||||
The NDK is now considered to be stable. It is already being used in quite a few third
|
||||
party modules (see list below).
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
Features
|
||||
========
|
||||
|
||||
* additional conf_set functions for regexes, complex/script values, paths...
|
||||
* macros to simplify tasks like checking for NULL values when doing ngx_array_push
|
||||
* patches to the main source code
|
||||
* ngx_auto_lib_core generic external library handler is included (see separate readme)
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
Design
|
||||
======
|
||||
|
||||
modular
|
||||
-------
|
||||
|
||||
The kit itself is designed in a modular way, so that only the required code is compiled.
|
||||
It's possible to add just a single NDK module, a few or all of them.
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
auto-generated & easily extensible
|
||||
----------------------------------
|
||||
|
||||
Many of the macros available in the NDK are auto-generated from simple configuration
|
||||
files. This makes creating similar macros for your own code very simple - it's usually
|
||||
just the case of adding an extra line to a config file and re-running the build script.
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
Usage for users
|
||||
===============
|
||||
|
||||
If another Nginx module you wish to use specifies that the NDK is a dependency, you
|
||||
will need to do the following :
|
||||
|
||||
1. download the source (https://github.com/simpl/ngx_devel_kit)
|
||||
2. unpack the source (tar -xzf $name)
|
||||
3. compile Nginx with the following extra option `--add-module=/path/to/ngx_devel_kit`.
|
||||
|
||||
e.g.
|
||||
|
||||
```bash
|
||||
./configure --add-module=/path/to/ngx_devel_kit \
|
||||
--add-module=/path/to/another/module
|
||||
```
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
Building as a dynamic module
|
||||
----------------------------
|
||||
|
||||
Starting from NGINX 1.9.11, you can also compile this module as a dynamic module, by using the `--add-dynamic-module=PATH` option instead of `--add-module=PATH` on the
|
||||
`./configure` command line above. And then you can explicitly load the module in your `nginx.conf` via the [load_module](http://nginx.org/en/docs/ngx_core_module.html#load_module)
|
||||
directive, for example,
|
||||
|
||||
```nginx
|
||||
load_module /path/to/modules/ndk_http_module.so;
|
||||
load_module /path/to/another/module.so;
|
||||
```
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
Usage for developers
|
||||
====================
|
||||
|
||||
To use the NDK in your own module, you need to add the following:
|
||||
|
||||
1. add this line to your module
|
||||
|
||||
```C
|
||||
#include <ndk.h>
|
||||
```
|
||||
|
||||
Note: since the NDK includes the following lines
|
||||
|
||||
```C
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_http.h>
|
||||
```
|
||||
|
||||
you can replace these with the single include above.
|
||||
2. add the following line in the config file for your module:
|
||||
|
||||
```bash
|
||||
have=NDK_[module_name] . auto/have
|
||||
```
|
||||
|
||||
for each NDK module that you wish to use (you need to include auto/have multiple
|
||||
times if you wish to use multiple NDK modules.
|
||||
|
||||
Note: the old method of setting
|
||||
|
||||
```config
|
||||
CFLAGS="$CFLAGS -DNDK_[module_name]"
|
||||
```
|
||||
|
||||
is now deprecated. It will still work, but results in unnecessary lines being
|
||||
displayed when compiling Nginx.
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
Warning: Using NDK_ALL
|
||||
----------------------
|
||||
|
||||
You can also set `NDK_ALL` to include all the NDK modules. This is primarily as
|
||||
a convenience in the early stages of development of another module. However,
|
||||
|
||||
DO NOT LEAVE `NDK_ALL` IN YOUR CONFIG FILE WHEN PUBLISHING
|
||||
|
||||
Although the NDK is fairly small now, it could in time become a large repository
|
||||
of code that would, if using NDK_ALL, result in considerably more code being compiled
|
||||
than is necessary.
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
Modules using NDK
|
||||
=================
|
||||
|
||||
The following 3rd-party modules make use of NDK.
|
||||
|
||||
* [ngx_http_lua_module](https://github.com/openresty/lua-nginx-module#readme)
|
||||
* [ngx_http_set_misc_module](https://github.com/openresty/set-misc-nginx-module#readme)
|
||||
* [ngx_http_encrypted_session_module](https://github.com/openresty/encrypted-session-nginx-module#readme)
|
||||
* [ngx_http_form_input_module](https://github.com/calio/form-input-nginx-module#readme)
|
||||
* [ngx_http_iconv_module](https://github.com/calio/iconv-nginx-module#readme)
|
||||
* [ngx_http_array_var_module](https://github.com/openresty/array-var-nginx-module#readme)
|
||||
|
||||
If you would like to add your module to this list, please let us know.
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
TODO
|
||||
====
|
||||
|
||||
* documentation for modules that don't already have it
|
||||
* additional phase-handler functions
|
||||
* generically testing for needing to add a handler
|
||||
* remove dependency of set_var on OpenSSL being compiled in
|
||||
* for backward compatability, add the ndk_macros
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
Copyright (c) 2010-2018, Marcus Clyne
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are
|
||||
permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of
|
||||
conditions and the following disclaimer in the documentation and/or other materials
|
||||
provided with the distribution.
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
to endorse or promote products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
Contributing / Feedback
|
||||
=======================
|
||||
|
||||
If you are an Nginx module developer, and have developed some functions that are
|
||||
generic in nature (or would be easily adapted to be so), then please send them to
|
||||
me at the address below, and I'll addmclyne to the kit.
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
Author
|
||||
======
|
||||
|
||||
[Marcus Clyne](https://github.com/mclyne)
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
|
||||
Special Thanks
|
||||
==============
|
||||
|
||||
A special thanks goes to [Yichun Zhang](https://github.com/agentzh) for helping to maintain
|
||||
this module.
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
|
@ -0,0 +1,394 @@
|
|||
Nginx Auto Lib Core
|
||||
===================
|
||||
|
||||
Nginx Auto Lib Core is a generic external library-handler that has been designed to
|
||||
facilitate the inclusion of external libraries in modules for the Nginx web server.
|
||||
It has been written both for the benefit of Nginx module developers and for the end
|
||||
users of those Nginx modules, and can provide a consistent, intelligent, flexible
|
||||
cross-platform way to include external libraries.
|
||||
|
||||
Any developers of Nginx modules are encouraged to use Auto Lib Core to handle library
|
||||
dependencies for their modules rather than writing their own custom handler from scratch.
|
||||
|
||||
Note : The latest version can be found [here](https://github.com/simplresty/ngx_auto_lib).
|
||||
|
||||
|
||||
Information for end users
|
||||
=========================
|
||||
|
||||
To include external libraries using Auto Lib to you may need or wish to export some
|
||||
variables before you run configure. e.g.
|
||||
|
||||
$ export MOZJS=/path/to/mozjs
|
||||
$ export MOZJS_SHARED=NO
|
||||
$ ./configure ...
|
||||
|
||||
In all cases below [PFX] should be replaced with the name of the library (e.g. MOZJS). The
|
||||
specific value for [PFX] should be mentioned in the README file for the module that
|
||||
uses Auto Lib Core.
|
||||
|
||||
|
||||
Search order for paths
|
||||
----------------------
|
||||
|
||||
(1) [PFX]_INC and [PFX]_LIB
|
||||
(2) [PFX] (source or install dir)
|
||||
(3) any dirs under [PFX]_BASE (see below)
|
||||
(4) any dirs under the parent directory of the Nginx source dir beginning with '[pfx]-'
|
||||
(5) standard system paths (including /usr/local, /usr, /opt/local, /opt, /usr/pkg)
|
||||
|
||||
If any of 1-3 are specified, then any set values will be searched, and the the Nginx
|
||||
source's parent directory and system paths are not searched unless [PFX]_SEARCH_[PLACE]
|
||||
variable is set to YES, where PLACE ::= PARENT | SYSTEM. e.g.
|
||||
|
||||
$ export OPENSSL_LIB=/path/to/openssl/lib
|
||||
$ export OPENSSL_INC=/path/to/openssl/inc
|
||||
$ ./configure
|
||||
|
||||
will search only in the lib and include paths specified, and
|
||||
|
||||
$ export OPENSSL_LIB=/path/to/openssl/lib
|
||||
$ export OPENSSL_INC=/path/to/openssl/inc
|
||||
$ export OPENSSL_BASE=/path/to/openssl/base
|
||||
$ export OPENSSL_SEARCH_PARENT=YES
|
||||
$ ./configure --with-openssl=/path/to/openssl
|
||||
|
||||
will search first in the lib & inc dirs specified, then in /path/to/openssl, then will
|
||||
look for directories in /path/to/openssl/base and then in the Nginx source parent
|
||||
directory, but will skip checking the system paths.
|
||||
|
||||
Note : apart from system paths, all dirs are checked as both source and install directories,
|
||||
so static versions of installed OpenSSL, PCRE, Zlib etc libraries can be used with Nginx
|
||||
if desired.
|
||||
|
||||
|
||||
Specifying a path to find a library
|
||||
-----------------------------------
|
||||
|
||||
If the version of a library you wish to include is in any of the standard paths (e.g.
|
||||
/usr/local, /usr ...), you will not need to specify a path to include the library.
|
||||
|
||||
If you do wish to specify a specific path, in most cases just specifying
|
||||
[PFX]=/path/to/library will be sufficient. e.g.
|
||||
|
||||
$ export MOZJS=/path/to/mozjs
|
||||
$ ./configure ...
|
||||
|
||||
The path can be either a source directory or an install directory. Auto Lib will search
|
||||
|
||||
|
||||
Searching under base paths
|
||||
--------------------------
|
||||
|
||||
Rather than specifying a specific path to find new libraries in non-standard locations,
|
||||
you may wish to specify a base path (or just let Auto Lib search the directory that the
|
||||
Nginx source is located in). This will then automatically find the most recent versions
|
||||
of libraries and check them before older versions.
|
||||
|
||||
e.g.
|
||||
|
||||
You have installations
|
||||
|
||||
/openssl/version/0.9.8m
|
||||
/openssl/version/1.0.0a
|
||||
...
|
||||
|
||||
$ export OPENSSL_BASE=/openssl/version
|
||||
$ ./configure ...
|
||||
|
||||
Any directories under /openssl/version will be searched IN REVERSE ORDER, i.e. most recent
|
||||
version first. Here /openssl/version/1.0.0a would be searched before /openssl/version/0.9.8m.
|
||||
|
||||
If [PFX]_BASE_SEARCH_PREFIX=YES, then only directories beginning with '[pfx]-' are searched.
|
||||
If [PFX]_BASE_SEARCH_PREFIX=something, then only directories beginning with 'something' are
|
||||
searched.
|
||||
|
||||
When searching under [PFX]_BASE no prefix is added to the search, but when searching under
|
||||
the directory that the Nginx source is located in, the prefix [pfx]- is automatically added.
|
||||
|
||||
Note : there is currently a minor bug (due to the implementation of the 'sort' command)
|
||||
means versions that include hyphens (e.g. 1.0.0-beta5) are checked before versions like
|
||||
1.0.0a. This will be fixed soon, and searching of -build folders before normal source ones
|
||||
will be added too.
|
||||
|
||||
|
||||
|
||||
Shared or static?
|
||||
-----------------
|
||||
|
||||
The default for most libraries is to look for shared libraries, though this can be overridden
|
||||
by the user by setting [PFX]_SHARED=NO.
|
||||
|
||||
In the near future the default action will be to look for shared libraries then to look
|
||||
for static libraries in each directory searched unless one of [PFX]_SHARED and/or
|
||||
[PFX]_STATIC = NO. If both are set to NO, then Auto Lib will not be used at all.
|
||||
|
||||
|
||||
|
||||
Variables that users can set to help find libraries
|
||||
---------------------------------------------------
|
||||
|
||||
[PFX] Location of dir where the library can be found (PATH, see below)
|
||||
[PFX]_INC Include dir for library headers (PATH)
|
||||
[PFX]_LIB Lib dir for library archive/shared objects (PATH)
|
||||
[PFX]_BASE Base dir under which to search for other dirs (PATH)
|
||||
[PFX]_SEARCH_LIB_INC Search in [PFX]_INC and [PFX]_LIB if set (YES|NO, def=YES)
|
||||
[PFX]_SEARCH_DIR Search [PFX] if set (YES|NO, def=YES)
|
||||
[PFX]_SEARCH_BASE Search under [PFX]_BASE if set (YES|NO, def=YES)
|
||||
[PFX]_SEARCH_PARENT Search under the dir that the Nginx source is in (YES|NO, see above)
|
||||
[PFX]_SEARCH_SYSTEM Search in standard system paths (YES|NO, see above)
|
||||
[PFX]_SHARED Use shared library rather than static (YES|NO, def=YES)
|
||||
[PFX]_SYSTEM_DIRS System dirs to search in (PATHS, space-separated, overrides the defaults)
|
||||
USE_[PFX] Whether or not to install the library (YES|NO, def=YES)
|
||||
|
||||
|
||||
Note : for libraries that have configure options (e.g. --with-openssl=/path), the [PFX]
|
||||
variable is set automatically by configure, so will not be used if exported.
|
||||
|
||||
|
||||
|
||||
Information for module developers
|
||||
=================================
|
||||
|
||||
How Auto Lib Core works
|
||||
-----------------------
|
||||
|
||||
Auto Lib Core works as an interface layer between the module and the auto/feature part of
|
||||
the Nginx source. This is the file that results in the 'checking for ...' lines that you
|
||||
see when you call ./configure.
|
||||
|
||||
auto/feature works by using a few key variables (see below) to generate some C code, trying
|
||||
to compile it to see if it works and optionally running the code. This output file is called
|
||||
autotest.c (located under the objs/ directory whilst configure is running, but is deleted
|
||||
after each call to auto/feature).
|
||||
|
||||
Normally, whenever an external library is required, a module developer will write a number
|
||||
of calls to auto/feature manually in their config files - e.g. to check under a range of
|
||||
different possible locations to find a library. Apart from being tedious, this is obviously
|
||||
potentially error-prone.
|
||||
|
||||
Auto Lib Core will automatically generate all the calls to auto/feature for you, and will
|
||||
take into account different operating systems etc in a consistent way, 'intelligent' way.
|
||||
|
||||
|
||||
Including Nginx Auto Lib Core with custom modules
|
||||
-------------------------------------------------
|
||||
|
||||
Option 1 :
|
||||
|
||||
- include ngx_auto_lib_core in the same directory that your module config file is
|
||||
located
|
||||
- add the following line to your config file
|
||||
|
||||
. $ngx_addon_dir/ngx_auto_lib_core
|
||||
|
||||
NOTE : if you want to include the file in a different directory to your config
|
||||
file, you will need to change both the include line in your config file AND
|
||||
the line in the ngx_auto_lib_core file that points to the file (it's the line that
|
||||
has $ngx_addon_dir/ngx_auto_lib_core in it)
|
||||
|
||||
Option 2 :
|
||||
|
||||
- make the Nginx Development Kit (github.com/simpl-it/ngx_devel_kit) a dependency
|
||||
for your module (Auto Lib Core is included automatically with it)
|
||||
|
||||
|
||||
Recommended way of including Auto Lib Core
|
||||
------------------------------------------
|
||||
|
||||
If the Nginx Development Kit (NDK) is already a dependency for your module, then you do
|
||||
not need to do anything - just follow the 'using Auto Lib Core' instructions below.
|
||||
|
||||
If the NDK is not a dependency for your module, then it is recommended to include a
|
||||
copy of ngx_auto_lib_core with your module, but to recommend to users of your module
|
||||
to include the NDK when compiling. If the module is not required for anything else, this
|
||||
will not make any difference to the Nginx binary that they compile, but will mean they
|
||||
will get the latest version of Auto Lib Core (which probably won't change much anyway,
|
||||
but you never know).
|
||||
|
||||
You will also probably want to include a copy of this readme file for Auto Lib Core
|
||||
(at least the user section), and mention what the relevant [PFX] you use for your module
|
||||
is in your module's readme file so that users will know what to write for any variables
|
||||
that they might use to control the search paths for libraries (see above user section).
|
||||
|
||||
|
||||
Using Auto Lib Core
|
||||
-------------------
|
||||
|
||||
To use Auto Lib Core, you should do the following in your config file for each
|
||||
external library that you want to include :
|
||||
|
||||
1 - Call ngx_auto_lib_init
|
||||
2 - Define any variables used for testing
|
||||
3 - Define any hooks (custom functions)
|
||||
4 - Call ngx_auto_lib_run
|
||||
|
||||
|
||||
Calling ngx_auto_lib_init() and ngx_auto_lib_run()
|
||||
--------------------------------------------------
|
||||
|
||||
You can pass either one or two variables to ngx_auto_lib_init(). The first is the name of
|
||||
the library as it will appear when running ./configure, the second is the prefix that is
|
||||
used for internal variables and looking for directory prefixes. If the second is not
|
||||
specified, it defaults to the first.
|
||||
|
||||
The init function resets all key variables and functions, so it must be called before
|
||||
setting any other variables or functions that are to be used as hooks (see the notes below).
|
||||
|
||||
ngx_auto_lib_run() should be called in the config files after all the variables and hooks
|
||||
have been defined. This will then run through all the tests to try to find the external
|
||||
library.
|
||||
|
||||
|
||||
Variables you can set in your config files
|
||||
------------------------------------------
|
||||
|
||||
All the variables that you set in Auto Lib Core are similar to the ones you set for
|
||||
including libraries in the normal way.
|
||||
|
||||
name description
|
||||
----------------------------------------------------------------------------------------
|
||||
|
||||
core variables (i.e. the ones in the core Nginx source)
|
||||
|
||||
ngx_feature_inc_path CFLAGS and include path info (including -I)
|
||||
ngx_feature_incs Include/define code inserted before main() in autotest.c
|
||||
ngx_feature_libs External libraries to add (see below)
|
||||
ngx_feature_path Space-separated include path
|
||||
ngx_feature_run Whether to run the autotest binary (default = no)
|
||||
ngx_feature_test C-code inserted inside main() in autotest.c
|
||||
|
||||
extended variables (only work in NALC) :
|
||||
|
||||
ngx_feature_add_libs Add libraries (but do not add include files)
|
||||
ngx_feature_add_path Add extra directories to include path
|
||||
ngx_feature_build_dirs Sub dirs that builds might be found
|
||||
ngx_feature_build_inc_dirs Sub dirs that include files might be found
|
||||
ngx_feature_build_lib_dirs Sub dirs that lib files might be found
|
||||
ngx_feature_check_macros_defined Lib required only if one of these macros is defined
|
||||
ngx_feature_check_macros_non_zero Lib required only if one of these macros is non-zero
|
||||
ngx_feature_defines Define these macros if the library is found
|
||||
ngx_feature_deps Deps to add (e.g. to CORE_DEPS) if the library is found
|
||||
ngx_feature_exit_if_not_found Quit configure if the library is not found
|
||||
ngx_feature_haves Set these macros to 1 if the library is found
|
||||
ngx_feature_inc_names Names for include files (not including the .h)
|
||||
ngx_feature_lib_files Add these files under the lib dir for static inclusions
|
||||
ngx_feature_lib_names Names for lib files (not including -l or .a)
|
||||
ngx_feature_modules Modules to add if the library is found
|
||||
ngx_feature_srcs Sources to add (e.g. to ADDON_SRCS) if the lib is found
|
||||
ngx_feature_shared If set to 'no', then only use static lib versions
|
||||
ngx_feature_test_libs Add these libs when testing, but not to the final binary
|
||||
ngx_feature_variables Set these variables if the library is found
|
||||
|
||||
standard variables that are completely over-written (i.e. they won't work with NALC) :
|
||||
|
||||
ngx_feature_name Message that is displayed after 'checking for' in configure
|
||||
|
||||
|
||||
Using these variables
|
||||
---------------------
|
||||
|
||||
You do not need to set most of these variables, since 'intelligent' guesses are made that
|
||||
will work for most cases. With the exception of ngx_feature_test, you should generally use
|
||||
the extended variables rather than the core ones, since sensible core variables will be
|
||||
automatically generated from them, and will work for both static and shared libraries.
|
||||
|
||||
|
||||
Variable defaults
|
||||
-----------------
|
||||
|
||||
ngx_feature_incs for i in $ngx_feature_inc_names { #include <$i.h> }
|
||||
ngx_feature_libs for l in $ngx_feature_lib_names { -l$l or $LIB/lib$l.a }
|
||||
+ $ngx_feature_add_libs
|
||||
ngx_feature_inc_names $ngx_feature_lib_names
|
||||
ngx_feature_lib_names $pfx
|
||||
pfx str_to_lower (if two variables are passed to ngx_auto_lib_init, then
|
||||
then $2, otherwise, $1)
|
||||
|
||||
The easiest way to understand how all the defaults work is probably to look at the source code
|
||||
of ngx_auto_lib_test_setup() and to look at the examples in the standard Nginx Auto Lib module
|
||||
which has code for OpenSSL, PCRE, Zlib, MD5 and SHA1.
|
||||
|
||||
|
||||
Hooks
|
||||
-----
|
||||
|
||||
To facilitate using Auto Lib Core in a flexible way, a number of 'hooks' have been
|
||||
placed in the testing cycle. These hooks are implemented as functions that you define
|
||||
in your config file which are called if required by the core library. In the core
|
||||
library they are left as empty functions that return either 0 or 1. Any functions
|
||||
you write will
|
||||
|
||||
Note : ngx_auto_lib_init() resets the variables and functions each time it is called, so
|
||||
you must DEFINE HOOKS AFTER YOU CALL ngx_auto_lib_init.
|
||||
|
||||
Note : an update on what hooks are available will be added later. To see what hooks are
|
||||
available, just look in the source code of ngx_auto_lib_core for any functions that just
|
||||
return 0 or 1.
|
||||
|
||||
See the MD5 and SHA1 libraries of Nginx Auto Lib module for examples.
|
||||
|
||||
|
||||
|
||||
Checking that a library is required
|
||||
-----------------------------------
|
||||
|
||||
Although in most cases Auto Lib Core will be used where external libraries are
|
||||
definitely required (for a module to work), this may not always be the case. In the
|
||||
standard Nginx Auto Lib module (github.com/simpl-it/ngx_auto_lib) - which is designed
|
||||
to improve the inclusion of OpenSSL, PCRE and Zlib libraries and increase compilation
|
||||
speed where possible - the libraries are not always required, so checks are made to
|
||||
see if it is necessary.
|
||||
|
||||
|
||||
|
||||
How Auto Lib Core checks if a library is required - ngx_auto_lib_check_require()
|
||||
------------------------------------------------------------------------------------
|
||||
|
||||
- search for USE_[PFX]=YES (it is set to YES by default for most modules)
|
||||
- search for any external libraries that have been included in the CORE_LIBS or ADDON_LIBS
|
||||
variables that use the same lib name as any set in ngx_feature_lib_names
|
||||
- search for any macros that have been defined either in the CFLAGS variable or using
|
||||
auto/have or auto/define as set in the ngx_feature_check_macros_defined and
|
||||
ngx_feature_ngx_macros_non_zero variables
|
||||
- any custom checks implemented by creating an ngx_auto_lib_check hook function (which
|
||||
should return 0 if the library is required and return 1 at the end if the module is
|
||||
not required)
|
||||
|
||||
|
||||
|
||||
Guaranteeing that the correct version of a shared library is linked at run time
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Sometimes users will want to use shared libraries that are in non-standard locations
|
||||
that the linker may have a problem in locating at run time - even if the correct
|
||||
linker path (-L/path/to/lib) is supplied when checking. To make sure that the linker
|
||||
can find the library at run time, and to make sure that the linker will use the correct
|
||||
version of a library if the library is also located in a standard directory, a run path
|
||||
is added to the linker flags (using -Wl,--rpath -Wl,/path/to/lib/dir). In most cases this
|
||||
will guarantee that the correct library is used when linking - though care should be taken
|
||||
by any users specifying specific paths for libraries that the correct version of the
|
||||
library has been linked at run time (e.g. using ldd etc).
|
||||
|
||||
As an additional check when running auto/feature, as well as the compilation of the
|
||||
autotest.c file, a check is made by ldd to see that the path of the shared library
|
||||
that the linker links to is the same as the one specified. This is done because
|
||||
|
||||
|
||||
To do
|
||||
-----
|
||||
|
||||
- Change how library paths are searched to include both shared and static libraries
|
||||
- Touch up documentation
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
BSD
|
||||
|
||||
|
||||
Copyright
|
||||
---------
|
||||
|
||||
[Marcus Clyne](https://github.com/mclyne) (c) 2010
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
array_create (a,pl,n,sz) a = %1%_array_create (pl,n,sz); if (a == NULL) %A%
|
||||
array_init (a,pl,n,sz) if (%1%_array_init (a,pl,n,sz) == %E%) %A%
|
||||
array_push (p,a) p = %1%_array_push (a); if (p == NULL) %A%
|
||||
array_push_clean (p,a) p = %1%_array_push (a); if (p == NULL) %A%; %2%_zerop (p)
|
||||
array_push_n (p,a,n) p = %1%_array_push_n (a,n); if (p == NULL) %A%
|
||||
array_push_n_clean (p,a,n) p = %1%_array_push_n (a,n); if (p == NULL) %A%; %2%_zeropn (p,n)
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
palloc (p,pl,sz) p = %1%_palloc (pl,sz); if (p == NULL) %A%
|
||||
pallocp (p,pl) %2%_pallocp (p,pl); if (p == NULL) %A%
|
||||
pallocpn (p,pl,n) %2%_pallocpn (p,pl,n); if (p == NULL) %A%
|
||||
pcalloc (p,pl,sz) p = %1%_pcalloc (pl,sz); if (p == NULL) %A%
|
||||
pcallocp (p,pl) %2%_pcallocp (p,pl); if (p == NULL) %A%
|
||||
pcallocpn (p,pl,n) %2%_pcallocpn (p,pl,n); if (p == NULL) %A%
|
||||
|
|
@ -0,0 +1,597 @@
|
|||
#! /bin/bash
|
||||
|
||||
cd `dirname $0`
|
||||
|
||||
if [ $# -eq 2 ];
|
||||
then
|
||||
if [ `expr $2 : /` -eq 1 ];
|
||||
then
|
||||
output_dir=$2
|
||||
else
|
||||
output_dir=$1/$2
|
||||
fi
|
||||
else
|
||||
output_dir=../objs
|
||||
fi
|
||||
|
||||
list_file=data/action_list
|
||||
types_file=data/action_types
|
||||
reps_file=data/action_replacements
|
||||
prefix_file=data/prefixes
|
||||
header_file=data/header_files
|
||||
optional_modules_file=data/modules_optional
|
||||
headers_file=data/headers
|
||||
module_dependencies_file=data/module_dependencies
|
||||
conf_macros_file=data/conf_macros
|
||||
conf_locs_file=data/conf_locs
|
||||
conf_args_file=data/conf_args
|
||||
|
||||
autogen_notice=text/autogen
|
||||
|
||||
actions_dir=actions
|
||||
srcs_dir=src
|
||||
include_prefix=
|
||||
file_prefix=ndk_
|
||||
auto_file_name=config
|
||||
auto_includes_name=includes
|
||||
|
||||
conf_merge_filename=conf_merge.h
|
||||
conf_cmd_basic_filename=conf_cmd_basic.h
|
||||
conf_cmd_extra_filename=conf_cmd_extra.h
|
||||
|
||||
|
||||
spacer=¬
|
||||
|
||||
sed_delete_empty_lines='t_NEL;d;:_NEL'
|
||||
|
||||
|
||||
function trim_lines {
|
||||
sed -e '/./,$!d' -e :a -e '/^\n*$/{$d;N;ba' -e '}'
|
||||
}
|
||||
|
||||
|
||||
function strtoupper {
|
||||
[ $# -eq 1 ] || return 1
|
||||
local _str _cu _cl _x
|
||||
_cu=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
|
||||
_cl=(a b c d e f g h i j k l m n o p q r s t u v w x y z)
|
||||
_str=$1
|
||||
for ((_x=0;_x<${#_cl[*]};_x++)); do
|
||||
_str=${_str//${_cl[$_x]}/${_cu[$_x]}}
|
||||
done
|
||||
echo $_str
|
||||
}
|
||||
|
||||
|
||||
function sed_pad_right {
|
||||
len=$1
|
||||
spacer=$2
|
||||
prefix=_PR$3
|
||||
|
||||
# returns a SED script that pads out (spaces) to the right to alignment $len
|
||||
# this script should be used inside a call to sed
|
||||
# NOTE : a spacer character $spacer should have already been written into the parsed string
|
||||
|
||||
echo "t${prefix}a;:${prefix}a;s/^[^$spacer]{$len}/&/;\
|
||||
t${prefix}b;s/^[^$spacer]*/& /;t${prefix}a;:${prefix}b;s/$spacer/ /"
|
||||
}
|
||||
|
||||
|
||||
function sed_pad_left {
|
||||
|
||||
len=$1
|
||||
spacer=$2
|
||||
prefix=_PL$3
|
||||
|
||||
# echo "t${prefix}a;:${prefix}a;s/^[^$spacer]{$len}/& /;t${prefix}a" # NOT CORRECT?
|
||||
}
|
||||
|
||||
|
||||
function add_notice {
|
||||
|
||||
echo > $1
|
||||
cat $autogen_notice | trim_lines >> $1
|
||||
echo >> $1
|
||||
echo >> $1
|
||||
}
|
||||
|
||||
function add_non_generated_content {
|
||||
|
||||
file=src/$1.h
|
||||
[ ! -f $file ] && return
|
||||
|
||||
echo "/* Non-generated macros */" >> $2
|
||||
echo >> $2
|
||||
|
||||
cat $file | trim_lines >> $2
|
||||
|
||||
echo >> $2
|
||||
echo >> $2
|
||||
}
|
||||
|
||||
|
||||
function add_action_macros {
|
||||
|
||||
list_file=$actions_dir/$1
|
||||
|
||||
[ ! -f $list_file ] && return
|
||||
|
||||
out=$2
|
||||
|
||||
|
||||
# alignment settings
|
||||
|
||||
align1=20
|
||||
align2=35
|
||||
align3=62
|
||||
base_shrink=12
|
||||
define="#define "
|
||||
|
||||
|
||||
|
||||
# base macros
|
||||
|
||||
echo "/* base action macro macros */" >> $out
|
||||
echo >> $out
|
||||
|
||||
cat $list_file | trim_lines | sed -r \
|
||||
-e "s/^[ ]*([a-zA-Z0-9_]+)([ ]*)\(([a-zA-Z0-9_,]+)\)([ ]*)(.*)/$define%2%_\1_ac(\3,ac)\2\4 {\5;}/" \
|
||||
-e "s/[ ]{$base_shrink}\{/\{/" \
|
||||
-e 's/%A%/ac/g' \
|
||||
>> $out
|
||||
|
||||
echo >> $out
|
||||
echo >> $out
|
||||
|
||||
|
||||
|
||||
# generated macros
|
||||
|
||||
echo "/* generated action macros */" >> $out
|
||||
echo >> $out
|
||||
|
||||
cat -s $list_file | while read list_line; do
|
||||
|
||||
[ "x`echo $list_line`" = 'x' ] && continue
|
||||
|
||||
cat $types_file | while read type_line; do
|
||||
|
||||
[ "x`echo $type_line`" = 'x' ] && continue
|
||||
|
||||
#ext=`echo $type_line | grep -E '^[a-zA-Z0-9_]+' | cut -d " " -f1`
|
||||
ext=`echo $type_line | sed -r 's/^([a-zA-Z0-9_]+).*/\1/'`
|
||||
params=`echo $type_line | sed -r 's/^[a-zA-Z0-9_]+[ ]*\((.*)\).*/\1/;ta;d;:a'`
|
||||
act=`echo $type_line | sed -r 's/^[a-zA-Z0-9_]+[ ]*(\(.*\))?(.*)/\2/'`
|
||||
[ "x$params" != "x" ] && params=",$params"
|
||||
|
||||
echo $list_line | sed -r \
|
||||
-e "s/^([a-zA-Z0-9_]+)[ ]*\(([a-zA-Z0-9_,]+)\).*/%2%_\1_$ext(\2$params)$spacer%2%_\1_ac$spacer(\2,$act)/" \
|
||||
-e 's/[ ]*,[ ]*/,/g' \
|
||||
-e "`sed_pad_right $align2 $spacer 1`" \
|
||||
-e "`sed_pad_right $align3 $spacer 2`" \
|
||||
-e "s/.*/$define&/" \
|
||||
>> $out
|
||||
done
|
||||
echo >> $out
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
function replace_prefixes {
|
||||
|
||||
temp=.temp
|
||||
|
||||
file=`cat $prefix_file`
|
||||
|
||||
prefix1=
|
||||
prefix2=
|
||||
|
||||
for prefix in $file ; do
|
||||
[ "x$prefix2" != "x" ] && echo "Too many prefixes in prefix file $prefix_file" && exit 1
|
||||
[ "x$prefix1" != "x" ] && prefix2=$prefix && continue
|
||||
prefix1=$prefix
|
||||
done
|
||||
|
||||
sed -r "s/%1%/$prefix1/g;s/%2%/$prefix2/g" < $1 > $temp
|
||||
|
||||
mv -f $temp $1
|
||||
}
|
||||
|
||||
|
||||
function replace_other_strings {
|
||||
|
||||
temp=.temp
|
||||
|
||||
cat $reps_file | while read line; do
|
||||
|
||||
rep1=
|
||||
rep2=
|
||||
|
||||
for rep in $line ; do
|
||||
[ "x$rep2" != "x" ] && echo "Too many replacments in replacements file $reps_file" && exit 1
|
||||
[ "x$rep1" != "x" ] && rep2=$rep && continue
|
||||
rep1=$rep
|
||||
done
|
||||
|
||||
sed -r "s/%$rep1%/$rep2/g" < $1 > $temp
|
||||
mv -f $temp $1
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
function generate_header_file {
|
||||
|
||||
name=$1
|
||||
out=$output_dir/$file_prefix$name.h
|
||||
|
||||
add_notice $out
|
||||
add_non_generated_content $name $out
|
||||
add_action_macros $name $out
|
||||
replace_prefixes $out
|
||||
replace_other_strings $out
|
||||
}
|
||||
|
||||
|
||||
function add_auto_include {
|
||||
echo "#include <${file_prefix}$2>" >> $1
|
||||
}
|
||||
|
||||
|
||||
function add_include {
|
||||
echo "#include <${include_prefix}${file_prefix}$2>" >> $1
|
||||
}
|
||||
|
||||
|
||||
function generate_non_optional_h_includes {
|
||||
|
||||
# TODO : split into auto-generated and non-auto-generated ones
|
||||
|
||||
echo "/* non-optional includes */" >> $1
|
||||
echo >> $1
|
||||
|
||||
for mod in `cat $headers_file | sort`; do
|
||||
|
||||
add_auto_include $1 $mod.h
|
||||
done
|
||||
|
||||
echo >> $1
|
||||
echo >> $1
|
||||
}
|
||||
|
||||
|
||||
function generate_include_all_includes {
|
||||
|
||||
echo "/* include all optional modules */" >> $1
|
||||
echo >> $1
|
||||
echo "#ifdef NDK_ALL" >> $1
|
||||
echo >> $1
|
||||
|
||||
modules=`cat $optional_modules_file | sed 's/*//g' | sort`
|
||||
|
||||
for mod in $modules; do
|
||||
def="NDK_`strtoupper $mod`"
|
||||
echo "#ifndef $def" >> $1
|
||||
echo "#define $def 1" >> $1
|
||||
echo "#endif" >> $1
|
||||
done
|
||||
|
||||
echo >> $1
|
||||
echo "#endif" >> $1
|
||||
echo >> $1
|
||||
echo >> $1
|
||||
}
|
||||
|
||||
|
||||
function generate_dependent_includes {
|
||||
|
||||
echo "/* module dependencies */" >> $1
|
||||
echo >> $1
|
||||
|
||||
cat $module_dependencies_file | while read line; do
|
||||
|
||||
first=1
|
||||
|
||||
for mod in $line; do
|
||||
|
||||
def="NDK_`strtoupper $mod`"
|
||||
|
||||
if [ $first = 1 ] ; then
|
||||
|
||||
echo "#ifdef $def" >> $1
|
||||
first=0
|
||||
else
|
||||
echo "#ifndef $def" >> $1
|
||||
echo "#define $def 1" >> $1
|
||||
echo "#endif" >> $1
|
||||
fi
|
||||
done
|
||||
|
||||
[ $first = 0 ] && echo "#endif" >> $1
|
||||
done
|
||||
|
||||
echo >> $1
|
||||
echo >> $1
|
||||
}
|
||||
|
||||
|
||||
|
||||
function generate_optional_h_includes {
|
||||
|
||||
echo "/* optional includes */" >> $1
|
||||
echo >> $1
|
||||
|
||||
for mod in $modules; do
|
||||
def="NDK_`strtoupper $mod`"
|
||||
echo "#if ($def)" >> $1
|
||||
add_include $1 $mod.h
|
||||
echo "#endif" >> $1
|
||||
done
|
||||
|
||||
echo >> $1
|
||||
echo >> $1
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function generate_conf_merge_macros_file {
|
||||
|
||||
file=$conf_merge_filename
|
||||
out_file=${file_prefix}$file
|
||||
out=$output_dir/$out_file
|
||||
|
||||
add_notice $out
|
||||
|
||||
echo "/* conf-merge-value macros */" >> $out
|
||||
echo >> $out
|
||||
|
||||
cat $srcs_dir/$file | trim_lines >> $out
|
||||
echo >> $out
|
||||
echo >> $out
|
||||
|
||||
echo "/* conf-merge-prop macros */" >> $out
|
||||
echo >> $out
|
||||
|
||||
echo "#define ndk_conf_merge_prop(prop,default)\\" >> $out
|
||||
echo " ndk_conf_merge_value\\" >> $out
|
||||
echo " (conf->prop, prev->prop, default)" >> $out
|
||||
echo >> $out
|
||||
|
||||
# loads macros, removes empty elements, sorts and translates to merge-prop macros
|
||||
|
||||
cat $conf_macros_file | sed -r 's/^[A-Z0-9_]+[ ]*[A-Z0-9_]+[ ]*([a-z0-9_]+).*$/\1/;ta;d;:a' \
|
||||
| sort | sed -r \
|
||||
's/(.*)/#define ndk_conf_merge_\1_prop(prop,default,...)\\\
|
||||
ndk_conf_merge_\1_value\\\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)\
|
||||
/' \
|
||||
>> $out
|
||||
|
||||
add_auto_include $1 $file
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function generate_conf_cmd_basic_file {
|
||||
|
||||
temp=.rep
|
||||
file=$conf_cmd_basic_filename
|
||||
out_file=${file_prefix}$file
|
||||
out=$output_dir/$out_file
|
||||
|
||||
align1=35
|
||||
|
||||
# initial text
|
||||
|
||||
add_notice $out
|
||||
|
||||
|
||||
# add ndk bitmasks
|
||||
|
||||
echo "/* conf cmd core values/bitmasks */" >> $out
|
||||
echo >> $out
|
||||
|
||||
|
||||
cat $conf_args_file | sort | trim_lines | sed -r \
|
||||
-e "s/^([A-Z0-9_]+)/${define}NDK_\1${spacer}NGX_\1/" \
|
||||
-e $sed_delete_empty_lines \
|
||||
-e "`sed_pad_right $align1 $spacer`" \
|
||||
>> $out
|
||||
|
||||
echo >> $out
|
||||
echo >> $out
|
||||
|
||||
|
||||
# add additional bitmasks stored in file
|
||||
|
||||
echo "/* conf cmd bitmasks */" >> $out
|
||||
echo >> $out
|
||||
|
||||
cat $srcs_dir/$conf_cmd_basic_filename | trim_lines >> $out
|
||||
|
||||
echo >> $out
|
||||
echo >> $out
|
||||
|
||||
echo "/* conf cmd basic macros */" >> $out
|
||||
echo >> $out
|
||||
|
||||
|
||||
# build replacement string
|
||||
|
||||
echo -n "s/^([A-Z0-9_]+)$/" > $temp
|
||||
|
||||
cat $conf_locs_file | sed \
|
||||
-r -e 's/^([A-Z0-9_]+) *([A-Z0-9_]+).*/#define NDK_\1_CONF_\\1\(name,func,off1,off2,post)\\\\\\\
|
||||
{ngx_string (name),\\\\\\\
|
||||
NGX_CONF_\\1|NDK_\1_CONF,\\\\\\\
|
||||
func, off1, off2, post},\\\
|
||||
\\/' -e $sed_delete_empty_lines \
|
||||
>> $temp
|
||||
|
||||
echo -n "/;$sed_delete_empty_lines" >> $temp
|
||||
|
||||
|
||||
# apply the replacement string to the
|
||||
|
||||
cat $conf_args_file | sort | trim_lines | sed -rf $temp >> $out
|
||||
rm -f $temp
|
||||
|
||||
add_auto_include $1 $file
|
||||
}
|
||||
|
||||
|
||||
|
||||
function generate_conf_cmd_extra_file {
|
||||
|
||||
temp=.rep
|
||||
file=$conf_cmd_extra_filename
|
||||
out=$output_dir/${file_prefix}$file
|
||||
|
||||
align1=35
|
||||
|
||||
# initial text
|
||||
|
||||
add_notice $out
|
||||
|
||||
echo "/* conf command macros */" >> $out
|
||||
echo >> $out
|
||||
|
||||
|
||||
# build replacement string
|
||||
|
||||
echo -n 's/^([A-Z0-9_]+)[ ]*([A-Z0-9_]+)[ ]*([a-z0-9_]+).*$/' > $temp
|
||||
|
||||
cat $conf_locs_file | sed \
|
||||
-r -e 's/^([A-Z0-9_]+)[ ]*([A-Z0-9_]+)[ ]*([a-zA-Z0-9_]+)/#define NDK_\1_CONF_\\1(name,p,post\)\\\\\\\
|
||||
NDK_\1_CONF_\\2\\\\\\\
|
||||
(name,\\\\\\\
|
||||
ndk_conf_set_\\3_slot,\\\\\\\
|
||||
NGX_\2_CONF_OFFSET,\\\\\\\
|
||||
offsetof (ndk_module_\3_conf_t, p),\\\\\\\
|
||||
post)\\\
|
||||
\\/' -e $sed_delete_empty_lines \
|
||||
>> $temp
|
||||
|
||||
echo -n "/;$sed_delete_empty_lines" >> $temp
|
||||
#echo -n ";`sed_pad_right 60 $spacer`" >> $temp
|
||||
|
||||
|
||||
# apply the replacement string to the
|
||||
|
||||
cat $conf_macros_file | sort | trim_lines | sed -rf $temp -e "`sed_pad_right 60 $spacer`" >> $out
|
||||
rm -f $temp
|
||||
|
||||
add_auto_include $1 $file
|
||||
}
|
||||
|
||||
|
||||
|
||||
function generate_auto_generated_h_includes {
|
||||
|
||||
echo "/* auto-generated headers */" >> $1
|
||||
echo >> $1
|
||||
|
||||
for name in `cat $header_file | sort` ; do
|
||||
|
||||
generate_header_file $name
|
||||
add_auto_include $1 $name.h
|
||||
done
|
||||
|
||||
generate_conf_merge_macros_file $1
|
||||
generate_conf_cmd_basic_file $1
|
||||
generate_conf_cmd_extra_file $1
|
||||
|
||||
echo >> $1
|
||||
echo >> $1
|
||||
}
|
||||
|
||||
|
||||
|
||||
function generate_optional_c_includes {
|
||||
|
||||
echo "/* optional includes */" >> $1
|
||||
echo >> $1
|
||||
|
||||
modules=`cat $optional_modules_file | sed 's/*//g' | sort`
|
||||
|
||||
for mod in $modules; do
|
||||
def="NDK_`strtoupper "$mod"`"
|
||||
echo "#if ($def)" >> $1
|
||||
add_include $1 $mod.c
|
||||
echo "#endif" >> $1
|
||||
done
|
||||
|
||||
echo >> $1
|
||||
echo >> $1
|
||||
}
|
||||
|
||||
|
||||
function generate_commands {
|
||||
|
||||
echo "/* module commands */" >> $1
|
||||
echo >> $1
|
||||
echo "static ngx_command_t ndk_http_commands[] = {" >> $1
|
||||
|
||||
cat $optional_modules_file | sort | while read line; do
|
||||
|
||||
cmds=`echo "$line" | grep -E '\*'`
|
||||
|
||||
[ "x$cmds" = "x" ] && continue
|
||||
|
||||
mod=`echo "$line" | grep -E '^[a-zA-Z0-9_]+' | cut -d " " -f1`
|
||||
up=`strtoupper $mod`
|
||||
def="NDK_$up"
|
||||
defcmd="NDK_${up}_CMDS"
|
||||
|
||||
echo "#if ($def)" >> $1
|
||||
echo "#define $defcmd 1" >> $1
|
||||
add_include $1 $mod.h
|
||||
echo "#undef $defcmd" >> $1
|
||||
echo "#endif" >> $1
|
||||
|
||||
done
|
||||
|
||||
echo -e " ngx_null_command\n};" >> $1
|
||||
}
|
||||
|
||||
|
||||
function generate_all_h_files {
|
||||
|
||||
out=$output_dir/${file_prefix}$auto_file_name.h
|
||||
|
||||
add_notice $out
|
||||
|
||||
generate_include_all_includes $out
|
||||
generate_dependent_includes $out
|
||||
|
||||
out=$output_dir/${file_prefix}$auto_includes_name.h
|
||||
|
||||
generate_optional_h_includes $out
|
||||
generate_non_optional_h_includes $out
|
||||
generate_auto_generated_h_includes $out $list
|
||||
}
|
||||
|
||||
|
||||
function generate_all_c_files {
|
||||
|
||||
out=$output_dir/${file_prefix}$auto_file_name.c
|
||||
|
||||
add_notice $out
|
||||
generate_optional_c_includes $out
|
||||
generate_commands $out
|
||||
}
|
||||
|
||||
|
||||
|
||||
function generate_all_files {
|
||||
|
||||
mkdir -p $output_dir
|
||||
rm -f $output_dir/*
|
||||
|
||||
generate_all_h_files
|
||||
generate_all_c_files
|
||||
}
|
||||
|
||||
generate_all_files
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
OK NGX_OK
|
||||
E NGX_ERROR
|
||||
CE NGX_CONF_ERROR
|
||||
COK NGX_CONF_OK
|
|
@ -0,0 +1,12 @@
|
|||
r0 return 0
|
||||
r1 return 1
|
||||
r_1 return -1
|
||||
rok return %OK%
|
||||
rce return %CE%
|
||||
rcok return %COK%
|
||||
re return %E%
|
||||
rn return NULL
|
||||
rse {ngx_script_error (e); return;}
|
||||
sce {ngx_script_configure_error (c); return;}
|
||||
g(_lb) goto _lb
|
||||
ge goto error
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
TAKE1
|
||||
TAKE2
|
||||
TAKE3
|
||||
TAKE4
|
||||
TAKE5
|
||||
TAKE6
|
||||
TAKE7
|
||||
TAKE8
|
||||
TAKE12
|
||||
TAKE13
|
||||
TAKE23
|
||||
TAKE123
|
||||
TAKE1234
|
||||
1MORE
|
||||
2MORE
|
||||
ANY
|
||||
FLAG
|
||||
BLOCK
|
||||
MULTI
|
||||
ARGS_NUMBER
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
HTTP_MAIN HTTP_MAIN main
|
||||
HTTP_SRV HTTP_SRV srv
|
||||
HTTP_SIF HTTP_SRV srv
|
||||
HTTP_LOC HTTP_LOC loc
|
||||
HTTP_LIF HTTP_LOC loc
|
||||
|
||||
HTTP_MAIN_SRV HTTP_SRV srv
|
||||
HTTP_MAIN_SIF HTTP_SRV srv
|
||||
HTTP_MAIN_LOC HTTP_LOC loc
|
||||
HTTP_MAIN_LIF HTTP_LOC loc
|
||||
|
||||
HTTP_SRV_LOC HTTP_LOC loc
|
||||
HTTP_SRV_LIF HTTP_LOC loc
|
||||
HTTP_SIF_LOC HTTP_LOC loc
|
||||
HTTP_SIF_LIF HTTP_LOC loc
|
||||
|
||||
HTTP_MAIN_SRV_LOC HTTP_LOC loc
|
||||
HTTP_MAIN_SRV_LIF HTTP_LOC loc
|
||||
HTTP_MAIN_SIF_LOC HTTP_LOC loc
|
||||
HTTP_MAIN_SRV_SIF_LOC HTTP_LOC loc
|
||||
HTTP HTTP_LOC loc
|
||||
HTTP_UPS HTTP_LOC loc
|
||||
HTTP_ANY HTTP_LOC loc
|
||||
ANY HTTP_LOC loc
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
BITMASK 1MORE bitmask
|
||||
BUFS TAKE1 bufs
|
||||
COMPLEX_KEYVAL TAKE2 http_complex_keyval
|
||||
COMPLEX_PATH TAKE1 http_complex_path
|
||||
COMPLEX_VALUE TAKE1 http_complex_value
|
||||
COMPLEX_VALUE_ARRAY 1MORE http_complex_value_array
|
||||
ENCODING TAKE1 encoding
|
||||
ENUM TAKE1 enum
|
||||
FALSE NOARGS false
|
||||
FULL_PATH TAKE1 full_path
|
||||
KEYVAL TAKE2 keyval
|
||||
KEYVAL1 TAKE2 keyval1
|
||||
MSEC TAKE1 msec
|
||||
NULL NOARGS null
|
||||
NUM TAKE1 num
|
||||
NUM64 TAKE1 num64
|
||||
NUM_FLAG TAKE1 num_flag
|
||||
ONOFF FLAG flag
|
||||
OFF TAKE1 off
|
||||
PATH TAKE1 split_path
|
||||
REXEX TAKE1 regex
|
||||
REGEX_CL TAKE1 regex_caseless
|
||||
REGEX_ARRAY 1MORE regex_array
|
||||
REGEX_ARRAY_CL 1MORE regex_array_caseless
|
||||
PTR NOARGS ptr
|
||||
SEC TAKE1 sec
|
||||
SEC_FLAG TAKE2 sec_flag
|
||||
SIZE TAKE1 size
|
||||
STR TAKE1 str
|
||||
STR_ARRAY 1MORE str_array_multi
|
||||
STR_ARRAY1 TAKE1 str_array
|
||||
TRUE NOARGS true
|
||||
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
MAIN
|
||||
SRV
|
||||
SIF
|
||||
LOC
|
||||
LIF
|
||||
|
||||
MAIN_SRV
|
||||
MAIN_SIF
|
||||
MAIN_LOC
|
||||
MAIN_LIF
|
||||
SRV_LOC
|
||||
SRV_LIF
|
||||
SIF_LOC
|
||||
SIF_LIF
|
||||
|
||||
MAIN_SRV_LOC
|
||||
MAIN_SRV_LIF
|
||||
MAIN_SIF_LOC
|
||||
MAIN_SIF_LIF
|
||||
ANY_MAIN
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
array
|
||||
palloc
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
http_headers
|
||||
log
|
||||
parse
|
||||
string_util
|
|
@ -0,0 +1,5 @@
|
|||
complex_path complex_value path
|
||||
conf_file string
|
||||
hash string
|
||||
set_var rewrite
|
||||
upstream_list http_create_main_conf
|
|
@ -0,0 +1,15 @@
|
|||
buf
|
||||
complex_path
|
||||
complex_value
|
||||
conf_file
|
||||
encoding
|
||||
hash
|
||||
http
|
||||
path
|
||||
process
|
||||
regex
|
||||
rewrite
|
||||
set_var
|
||||
string
|
||||
upstream_list *
|
||||
uri
|
|
@ -0,0 +1,2 @@
|
|||
ngx
|
||||
ndk
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
#define %2%_array_count(a) ((a)->nelts)
|
||||
#define %2%_array_get_first(a) ((a)->elts)
|
||||
#define %2%_array_get_index(a,n) ((void*) ((char*) (a)->elts + (a)->size * n))
|
||||
#define %2%_array_get_last(a) ((void*) ((char*) (a)->elts + (a)->size * ((a)->nelts - 1)))
|
||||
#define %2%_array_get_reverse_index(a,n) ((void*) ((char*) (a)->elts + (a)->size * ((a)->nelts - 1 - n)))
|
||||
#define %2%_array_push_clean(p,a) {p = %1%_array_push (a); %2%_zerop (p);}
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
/* TODO : finish this */
|
||||
|
||||
#define NDK_HTTP_MAIN_CONF NGX_HTTP_MAIN_CONF
|
||||
#define NDK_HTTP_SRV_CONF NGX_HTTP_SRV_CONF
|
||||
#define NDK_HTTP_SIF_CONF NGX_HTTP_SIF_CONF
|
||||
#define NDK_HTTP_LOC_CONF NGX_HTTP_LOC_CONF
|
||||
#define NDK_HTTP_LIF_CONF NGX_HTTP_LIF_CONF
|
||||
#define NDK_HTTP_UPS_CONF NGX_HTTP_UPS_CONF
|
||||
#define NDK_MAIN_CONF NGX_MAIN_CONF
|
||||
#define NDK_ANY_CONF NGX_ANY_CONF
|
||||
|
||||
|
||||
/* compound locations */
|
||||
|
||||
#define NDK_HTTP_MAIN_SRV_CONF NDK_HTTP_MAIN_CONF|NDK_HTTP_SRV_CONF
|
||||
#define NDK_HTTP_MAIN_SIF_CONF NDK_HTTP_MAIN_CONF|NDK_HTTP_SRV_SIF_CONF
|
||||
#define NDK_HTTP_MAIN_LOC_CONF NDK_HTTP_MAIN_CONF|NDK_HTTP_LOC_CONF
|
||||
#define NDK_HTTP_MAIN_LIF_CONF NDK_HTTP_MAIN_CONF|NDK_HTTP_LOC_LIF_CONF
|
||||
|
||||
#define NDK_HTTP_SRV_SIF_CONF NDK_HTTP_SRV_CONF|NDK_HTTP_SIF_CONF
|
||||
#define NDK_HTTP_SRV_LOC_CONF NDK_HTTP_SRV_CONF|NDK_HTTP_LOC_CONF
|
||||
#define NDK_HTTP_SRV_LOC_LIF_CONF NDK_HTTP_SRV_CONF|NDK_HTTP_LOC_LIF_CONF
|
||||
#define NDK_HTTP_SRV_SIF_LOC_CONF NDK_HTTP_SRV_SIF_CONF|NDK_HTTP_LOC_CONF
|
||||
#define NDK_HTTP_SRV_SIF_LOC_LIF_CONF NDK_HTTP_SRV_SIF_CONF|NDK_HTTP_LOC_LIF_CONF
|
||||
|
||||
#define NDK_HTTP_LOC_LIF_CONF NDK_HTTP_LOC_CONF|NDK_HTTP_LIF_CONF
|
||||
|
||||
#define NDK_HTTP_MAIN_SRV_LOC_CONF NDK_HTTP_MAIN_CONF|NDK_HTTP_SRV_LOC_CONF
|
||||
#define NDK_HTTP_MAIN_SRV_LIF_CONF NDK_HTTP_MAIN_CONF|NDK_HTTP_SRV_LIF_CONF
|
||||
#define NDK_HTTP_MAIN_SIF_LOC_CONF NDK_HTTP_MAIN_CONF|NDK_HTTP_SIF_LOC_CONF
|
||||
#define NDK_HTTP_MAIN_SRV_SIF_LOC_LIF_CONF NDK_HTTP_SRV_SIF_LOC_LIF_CONF|NDK_MAIN_CONF
|
||||
#define NDK_HTTP_CONF NDK_HTTP_MAIN_SRV_SIF_LOC_LIF_CONF
|
||||
#define NDK_HTTP_ANY_CONF NDK_HTTP_CONF|NDK_HTTP_UPS_CONF
|
||||
|
||||
|
||||
/* property offsets NOTE : ngx_module_main_conf_t etc should be defined in the module's .c file before the commands */
|
||||
|
||||
#define NDK_HTTP_MAIN_CONF_PROP(p) NGX_HTTP_MAIN_CONF_OFFSET, offsetof (ndk_module_main_conf_t, p)
|
||||
#define NDK_HTTP_SRV_CONF_PROP(p) NGX_HTTP_SRV_CONF_OFFSET, offsetof (ndk_module_srv_conf_t, p)
|
||||
#define NDK_HTTP_LOC_CONF_PROP(p) NGX_HTTP_LOC_CONF_OFFSET, offsetof (ndk_module_loc_conf_t, p)
|
||||
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
|
||||
/* TODO : check that all the main types have a corresponding merge function */
|
||||
|
||||
#define ndk_conf_merge_value ngx_conf_merge_value
|
||||
#define ndk_conf_merge_off_value ngx_conf_merge_off_value
|
||||
#define ndk_conf_merge_ptr_value ngx_conf_merge_ptr_value
|
||||
#define ndk_conf_merge_str_value ngx_conf_merge_str_value
|
||||
#define ndk_conf_merge_size_value ngx_conf_merge_size_value
|
||||
|
||||
|
||||
#define ndk_conf_merge_keyval_value(conf,prev,default) \
|
||||
\
|
||||
conf = prev ? prev : default;
|
||||
|
||||
#define ndk_conf_merge_str_array_value(conf,prev,val1,...) \
|
||||
\
|
||||
if (conf == NGX_CONF_UNSET_PTR) { \
|
||||
if (prev == NGX_CONF_UNSET_PTR) { \
|
||||
if (val1 == NULL) { \
|
||||
conf = NULL; \
|
||||
} else { \
|
||||
char * elts[] = {val1,##__VA_ARGS__}; \
|
||||
int n = sizeof(elts)/sizeof(char*); \
|
||||
\
|
||||
conf = ndk_str_array_create (cf->pool, elts, n); \
|
||||
\
|
||||
if (conf == NULL) \
|
||||
return NGX_CONF_ERROR; \
|
||||
} \
|
||||
} else { \
|
||||
conf = prev; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ndk_conf_merge_http_complex_value_value(conf,prev,default) \
|
||||
\
|
||||
if (!conf.str.len) { \
|
||||
if (prev.str.len) { \
|
||||
conf = prev; \
|
||||
} else { \
|
||||
conf.str.data = (u_char *) default; \
|
||||
conf.str.len = sizeof (default) - 1; \
|
||||
\
|
||||
if (ndk_http_complex_value_compile (cf, &conf)) \
|
||||
return NGX_CONF_ERROR; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ndk_conf_merge_http_complex_value_array_value(conf,prev,val1,...) \
|
||||
\
|
||||
if (conf == NGX_CONF_UNSET_PTR) { \
|
||||
if (prev == NGX_CONF_UNSET_PTR) { \
|
||||
if (val1 == NULL) \
|
||||
conf = NULL; \
|
||||
else { \
|
||||
char * elts[] = {val1,##__VA_ARGS__}; \
|
||||
int n = sizeof(elts)/sizeof(char*); \
|
||||
\
|
||||
conf = ndk_http_complex_value_array_create (cf, elts, n); \
|
||||
\
|
||||
if (conf == NULL) \
|
||||
return NGX_CONF_ERROR; \
|
||||
} \
|
||||
} else { \
|
||||
conf = prev; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ndk_conf_merge_http_complex_path_value(conf,prev,...) \
|
||||
ndk_conf_merge_http_complex_value_array_value (conf.a, prev.a, __VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_split_path_value(conf,prev,path) \
|
||||
\
|
||||
if (conf == NGX_CONF_UNSET_PTR) { \
|
||||
conf = (prev == NGX_CONF_UNSET_PTR ? \
|
||||
ndk_split_path_create_raw (cf, path) : prev); \
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
#define %2%_pallocp(p,pl) p = %1%_palloc (pl,sizeof(*p))
|
||||
#define %2%_pallocpn(p,pl,n) p = %1%_palloc (pl,sizeof(*p)*(n))
|
||||
|
||||
#define %2%_pcallocp(p,pl) p = %1%_pcalloc (pl,sizeof(*p))
|
||||
#define %2%_pcallocpn(p,pl,n) p = %1%_pcalloc (pl,sizeof(*p)*(n))
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
/*
|
||||
* 2010 (C) Marcus Clyne
|
||||
*
|
||||
* DO NOT EDIT THIS FILE MANUALLY
|
||||
* ------------------------------
|
||||
* This file has been generated automatically from scripts in the $base/auto dir and
|
||||
* data in the $base/auto/data dir. If you wish to edit the output of this file, then
|
||||
* you should edit these files instead.
|
||||
*
|
||||
*/
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
|
||||
###############
|
||||
## FUNCTIONS ##
|
||||
###############
|
||||
|
||||
# TODO : provide information about checking versions of sed etc
|
||||
# TODO : an optional patch function
|
||||
|
||||
ndk_generate_files() {
|
||||
echo "building Nginx Development Kit utility functions and macros ..."
|
||||
|
||||
autobuild="$ngx_addon_dir/auto/build"
|
||||
chmod +x $autobuild
|
||||
$autobuild `pwd` $NGX_OBJS/addon/ndk || exit 1
|
||||
}
|
||||
|
||||
ndk_get_nginx_version() {
|
||||
# We get the Nginx version number from the string form rather than
|
||||
# nginx_version because it is available in more (every?) version
|
||||
|
||||
cat src/core/nginx.h |
|
||||
grep '#define NGINX_VERSION' |
|
||||
sed -r \
|
||||
-e 's/[^0-9.]*([0-9.]+).*/\1/' \
|
||||
-e 's/([0-9]+\.[0-9]+\.)([0-9]{1})$/\100\2/' \
|
||||
-e 's/([0-9]+\.[0-9]+\.)([0-9]{2})$/\10\2/' \
|
||||
-e 's/\.//g' \
|
||||
-e 's/^0+(.*)/\1/'
|
||||
}
|
||||
|
||||
#####################
|
||||
## CONFIG SETTINGS ##
|
||||
#####################
|
||||
|
||||
ngx_addon_name=ngx_devel_kit
|
||||
ngx_objs_dirs="$ngx_addon_dir/objs $NGX_OBJS/addon/ndk"
|
||||
|
||||
NDK_SRCS="$ngx_addon_dir/src/ndk.c"
|
||||
NDK_DEPS="$ngx_addon_dir/src/ndk.h"
|
||||
NDK_INCS="$ngx_addon_dir/src $ngx_objs_dirs"
|
||||
|
||||
CORE_INCS="$CORE_INCS $ngx_objs_dirs"
|
||||
HTTP_INCS="$HTTP_INCS $ngx_addon_dir/src $ngx_objs_dir"
|
||||
|
||||
if test -n "$ngx_module_link"; then
|
||||
ngx_module_type=HTTP
|
||||
ngx_module_name="ndk_http_module"
|
||||
ngx_module_srcs="$NDK_SRCS"
|
||||
ngx_module_deps="$NDK_DEPS"
|
||||
ngx_module_incs="$NDK_INCS"
|
||||
|
||||
. auto/module
|
||||
else
|
||||
HTTP_MODULES="$HTTP_MODULES ndk_http_module"
|
||||
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $NDK_SRCS"
|
||||
NGX_ADDON_DEPS="$NGX_ADDON_SRCS $NDK_DEPS"
|
||||
fi
|
||||
|
||||
have=NDK . auto/have
|
||||
|
||||
##############
|
||||
## INCLUDES ##
|
||||
##############
|
||||
|
||||
. $ngx_addon_dir/ngx_auto_lib_core
|
|
@ -0,0 +1,63 @@
|
|||
|
||||
GENERAL NOTES
|
||||
-------------
|
||||
|
||||
These functions and macros have been provided as a tool for Nginx module developers. They have
|
||||
been created with four main purposes:
|
||||
|
||||
- to speed up code-writing
|
||||
- to reduce the code you have to read on file
|
||||
- to add additional generic functionality similar to exising Nginx functions
|
||||
- to reduce code errors
|
||||
|
||||
Most of the utility macros are just wrappers around commonly used code, especially checking for
|
||||
NULL and returning a value, zeroing data etc. The functions add things like extra conf_set_X_slot
|
||||
functions that don't exist in the standard Nginx distribution, but which might be useful in more
|
||||
than one module.
|
||||
|
||||
A consistent approach has been taken to creating the macros, so that in theory you should be able
|
||||
to 'know' the macro name from using the few rules below and your knowledge of the existing Nginx
|
||||
functions. As much as possible, the ordering of variables used within the underlying functions
|
||||
remain the same, to reduce the learning time. Also, a constent naming pattern has been used to
|
||||
make it easier to read the macros above.
|
||||
|
||||
Obviously not all programmers will want to use all or any of these macros, but they are provided
|
||||
as a tool for those who wish to use them.
|
||||
|
||||
If you have any comments about them, including any additions or errors please let me know at
|
||||
'eugaia at gmail dot com'. I don't promise to include all additions people send, but if they seem
|
||||
like they could be of use to multiple developers, I will.
|
||||
|
||||
|
||||
UTILITY MACRO PARAMS
|
||||
--------------------
|
||||
p pointer - used to set the result of a function to a pointer
|
||||
a array
|
||||
pl pool
|
||||
n multiplication factor - for allocating multiple pointers & pushing 'n' elts in arrays etc
|
||||
sz size
|
||||
l log
|
||||
rv return value
|
||||
|
||||
|
||||
|
||||
UTILITY MACRO FUNCTION SUFFIXES
|
||||
-------------------------------
|
||||
|
||||
- general
|
||||
|
||||
p p = [FUNCTION] ()
|
||||
_r [ if result of function is NULL | NGX_ERROR (as appropriate) ] return rv
|
||||
_rce rv = NGX_CONF_ERROR
|
||||
_re rv = NGX_ERROR
|
||||
_rn rv = NULL
|
||||
|
||||
- (p)(c)alloc functions
|
||||
|
||||
p p = [function] (pool, sizeof (*p))
|
||||
pn p = [function] (pool, sizeof (*p) * n)
|
||||
|
||||
|
||||
UTILITY MACRO PARAMS ORDER
|
||||
--------------------------
|
||||
p, pl|a, sz|n, l, rv
|
|
@ -0,0 +1,62 @@
|
|||
|
||||
Conf command macros
|
||||
-------------------
|
||||
|
||||
The build script generates a large number of macros for reducing the code required for command
|
||||
definitions.
|
||||
|
||||
There are basically three types of macros :
|
||||
|
||||
- combination bitmasks
|
||||
|
||||
e.g. NDK_HTTP_MAIN_SRV_CONF = (NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF)
|
||||
|
||||
- base command structures
|
||||
|
||||
e.g. NDK_HTTP_MAIN_CONF_TAKE1
|
||||
|
||||
- conf-set command structures
|
||||
|
||||
e.g. NDK_HTTP_CONF_STR
|
||||
|
||||
|
||||
Combination bitmasks
|
||||
--------------------
|
||||
|
||||
Basically combinations of existing bitmasks for locations, with general > specific order
|
||||
|
||||
NDK_HTTP_CONF = (NGX_HTTP_MAIN_CONF | NGX_HTTP_SVR_CONF | NGX_HTTP_SIF_CONF | NGX_HTTP_LOC_CONF | NGX_HTTP_LIF_CONF)
|
||||
|
||||
|
||||
Base command structures
|
||||
-----------------------
|
||||
|
||||
These macros are basically there as wrappers for the conf-set command structures, and but incorporate
|
||||
the bitmask element into the name of the macro.
|
||||
|
||||
|
||||
Conf-set command structures
|
||||
---------------------------
|
||||
|
||||
These macros simplify creating commands that use any of the build-in conf-set functions or any of those
|
||||
added by the NDK.
|
||||
|
||||
e.g. NGX_HTTP_MAIN_SRV_STR ("name", prop, NULL)
|
||||
|
||||
where prop is the name of the property that is a ngx_str_t. Whether this is in the loc conf, main conf
|
||||
or svr conf is generated automatically in by the macro.
|
||||
|
||||
NOTE : you need to set the following if they will be used (using macro definitions) :
|
||||
|
||||
ndk_module_main_conf_t
|
||||
ndk_module_srv_conf_t
|
||||
ndk_module_loc_conf_t
|
||||
|
||||
e.g
|
||||
|
||||
#define ndk_module_loc_conf_t ngx_http_my_module_loc_conf_t
|
||||
|
||||
|
||||
TODO
|
||||
----
|
||||
Much better documentation for this
|
|
@ -0,0 +1,124 @@
|
|||
|
||||
set var tools
|
||||
=============
|
||||
|
||||
OVERVIEW
|
||||
--------
|
||||
This collection of tools is designed to make it easier to set Nginx variables
|
||||
using a common interface. It works by plugging into and extending the features
|
||||
of the internal rewrite module, and operations performed by this module are
|
||||
therefore done at the rewrite phase of handling.
|
||||
|
||||
|
||||
ADVANTAGES OF USING THIS MODULE
|
||||
-------------------------------
|
||||
|
||||
- simple interface - you don't have to worry about lots of http script compiling
|
||||
- it plugs into the rewrite module, so setting (and getting) vars will happen
|
||||
in the order you expect based on how they appear in the configuration file
|
||||
- you do not have to worry about overriding the v->get_handler (useful if
|
||||
a variable of a specific name could be set in multiple different ways)
|
||||
|
||||
|
||||
WHEN TO USE THIS AND WHEN TO USE v->get_handler = my_func
|
||||
---------------------------------------------------------
|
||||
|
||||
- if you want a variable to always be generated using a specific function,
|
||||
and should not be over-ridden by 'set' functions (e.g. $request_uri,
|
||||
$document_root), then you should use v->get_handler
|
||||
|
||||
- if you want to allow a variable to be set using many possible methods,
|
||||
including using the 'set' directive, then this module provides an easy way
|
||||
for you to do so (if you use the v->get_handler method in this case, you may
|
||||
run into problems because the get_handler may over-ride previous uses of the
|
||||
set directive)
|
||||
|
||||
|
||||
USAGE
|
||||
-----
|
||||
|
||||
- decide on the type of function you'll need to write
|
||||
|
||||
type use when there are these requirements
|
||||
---- -------------------------------------
|
||||
NDK_SET_VAR_BASIC 0 variable values, no extra data
|
||||
NDK_SET_VAR_DATA 0 variable values, extra data
|
||||
NDK_SET_VAR_VALUE 1 variable value, no extra data
|
||||
NDK_SET_VAR_VALUE_DATA 1 variable value, extra data
|
||||
NDK_SET_VAR_MULTI_VALUE 2+ variable values, no extra data
|
||||
NDK_SET_VAR_MULTI_VALUE_DATA 2+ variable values, extra data
|
||||
NDK_SET_VAR_HASH the space needed for the result string
|
||||
value is known in advance (usually
|
||||
used in a hash function)
|
||||
|
||||
NOTE : if none of these generic calling types suit your needs, it is
|
||||
easy to extend the list of types in the .c file (and you if you let me know
|
||||
I'll add them to the list
|
||||
|
||||
|
||||
- define the filter function with the respective prototype
|
||||
|
||||
type prototype
|
||||
---- ---------
|
||||
NDK_SET_VAR_BASIC ndk_set_var_pt
|
||||
NDK_SET_VAR_DATA ndk_set_var_data_pt
|
||||
NDK_SET_VAR_VALUE ndk_set_var_value_pt
|
||||
NDK_SET_VAR_DATA_VALUE ndk_set_var_value_data_pt
|
||||
NDK_SET_VAR_MULTI_VALUE ndk_set_var_value_pt
|
||||
NDK_SET_VAR_MULTI_VALUE_DATA ndk_set_var_value_data_pt
|
||||
NDK_SET_VAR_HASH ndk_set_var_hash_pt
|
||||
|
||||
(See ngx_tools_module.h for the prototype definitions.)
|
||||
|
||||
Note : For the multi_value functions, the variable value pointer is to the
|
||||
first value (with the others being in an array following it)
|
||||
|
||||
|
||||
to use one of the default setup functions
|
||||
-----------------------------------------
|
||||
|
||||
- define one or multiple ngx_http_var_filter_t's at the global scope, setting :
|
||||
|
||||
type = (one of types above)
|
||||
func = function to call
|
||||
size = (for multi value) the number of variable values
|
||||
(for hash) length of buffer to allocate
|
||||
data = (for data functions) additional data (see note below)
|
||||
|
||||
- define a configuration directive (see in the .c file for examples), where the
|
||||
function is 'ngx_http_set_var' and the 'post' is a pointer your filter definition
|
||||
|
||||
|
||||
to setup in a customized way
|
||||
----------------------------
|
||||
|
||||
- define a configuration directive which has your own specific configuration function
|
||||
|
||||
- inside your config function, define one or several ngx_http_var_filter_t's like
|
||||
above, and call one of the ngx_http_set_var_..._core functions, passing the
|
||||
variable name and value pointers as appropriate - see examples section
|
||||
|
||||
Note : if you're passing extra data to the function, then you will probably want
|
||||
to use this second method and store the data either in the loc conf, or just
|
||||
allocate the space for it using one of the ngx_palloc functions.
|
||||
|
||||
If the values that will be used for processing are in the same order as in the
|
||||
config file and there aren't any additional values that are input, then you can
|
||||
just use the (ngx_str_t *) (cf->args->elts) + 1 as your base for the values or
|
||||
possibly not use the _core versions of the functions.
|
||||
|
||||
|
||||
That's it!
|
||||
|
||||
|
||||
FEEDBACK
|
||||
--------
|
||||
|
||||
If you have any comments (good/bad), or have found any bugs, please let me know at:
|
||||
ngx.eugaia AT gmail DOT com
|
||||
|
||||
|
||||
TODO
|
||||
----
|
||||
- add more documentation/examples
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
When tracking down some potential issues in the nginx constellation,
|
||||
we've found it useful to understand where particular error messages
|
||||
are coming from, since many of the same messages are repeated in
|
||||
various places. This patch will write the source file from which the
|
||||
message originated, the function name, and the line number if you're
|
||||
using GCC to compile nginx. Here's an example:
|
||||
|
||||
Old Output:
|
||||
2010/01/12 14:43:10 [notice] 67772#0: nginx/0.7.64
|
||||
2010/01/12 14:43:10 [notice] 67772#0: built by gcc 4.0.1 (Apple Inc. build 5490)
|
||||
2010/01/12 14:43:10 [notice] 67772#0: OS: Darwin 9.8.0
|
||||
2010/01/12 14:43:10 [notice] 67772#0: hw.ncpu: 2
|
||||
2010/01/12 14:43:10 [notice] 67772#0: net.inet.tcp.sendspace: 65536
|
||||
2010/01/12 14:43:10 [notice] 67772#0: kern.ipc.somaxconn: 128
|
||||
2010/01/12 14:43:10 [notice] 67772#0: getrlimit(RLIMIT_NOFILE):
|
||||
256:9223372036854775807
|
||||
2010/01/12 14:43:10 [notice] 67772#0: start worker processes
|
||||
2010/01/12 14:43:10 [notice] 67772#0: start worker process 67785
|
||||
2010/01/12 14:43:16 [notice] 67772#0: signal 20 (SIGCHLD) received
|
||||
|
||||
New Output:
|
||||
2010/01/14 16:35:09 [notice] 27241#0: src/os/unix/ngx_posix_init.c
|
||||
ngx_os_status( 80) nginx/0.7.64
|
||||
2010/01/14 16:35:09 [notice] 27241#0: src/os/unix/ngx_posix_init.c
|
||||
ngx_os_status( 83) built by gcc 4.0.1 (Apple Inc. build 5490)
|
||||
2010/01/14 16:35:09 [notice] 27241#0: src/os/unix/ngx_darwin_init.c
|
||||
ngx_os_specific_status( 153) OS: Darwin 9.8.0
|
||||
2010/01/14 16:35:09 [notice] 27241#0: src/os/unix/ngx_darwin_init.c
|
||||
ngx_os_specific_status( 166) hw.ncpu: 2
|
||||
2010/01/14 16:35:09 [notice] 27241#0: src/os/unix/ngx_darwin_init.c
|
||||
ngx_os_specific_status( 166) net.inet.tcp.sendspace: 65536
|
||||
2010/01/14 16:35:09 [notice] 27241#0: src/os/unix/ngx_darwin_init.c
|
||||
ngx_os_specific_status( 166) kern.ipc.somaxconn: 128
|
||||
2010/01/14 16:35:09 [notice] 27241#0: src/os/unix/ngx_posix_init.c
|
||||
ngx_os_status( 92) getrlimit(RLIMIT_NOFILE):
|
||||
2560:9223372036854775807
|
||||
2010/01/14 16:35:09 [notice] 27241#0: src/os/unix/ngx_process_cycle.c
|
||||
ngx_start_worker_processes( 337) start worker processes
|
||||
2010/01/14 16:35:09 [notice] 27241#0: src/os/unix/ngx_process.c
|
||||
ngx_spawn_process( 201) start worker process 27254
|
||||
2010/01/14 16:35:14 [notice] 27241#0: src/os/unix/ngx_process.c
|
||||
ngx_signal_handler( 420) signal 20 (SIGCHLD) received
|
||||
|
||||
Formatting the filename and function name fields into fixed-width
|
||||
fields would be nicer, however that would require further changes in
|
||||
src/core/ngx_string.c
|
||||
|
||||
(C) Brian Moran - bmoran@onehub.com (posted to nginx-devel mailing list on 15/01/10)
|
|
@ -0,0 +1,45 @@
|
|||
|
||||
NDK_UPSTREAM_LIST
|
||||
-----------------
|
||||
|
||||
This submodule provides a directive that creates a list of upstreams, with
|
||||
optional weighting. This list can then be used by other modules to hash over
|
||||
the upstreams however they choose.
|
||||
|
||||
|
||||
USAGE IN CONF FILE
|
||||
------------------
|
||||
|
||||
e.g. upstream_list name backend1 4:backend2 3:backend3;
|
||||
|
||||
|
||||
|
||||
USAGE WITH OTHER MODULES
|
||||
------------------------
|
||||
|
||||
Add a line like
|
||||
|
||||
CFLAGS="$CFLAGS -DNDK_UPSTREAM_LIST"
|
||||
|
||||
to the config file of your module.
|
||||
|
||||
|
||||
|
||||
INTEGRATING WITH YOUR MODULE
|
||||
----------------------------
|
||||
|
||||
The upstream lists are stored in the array given in the lists.h file, which is
|
||||
an array of ndk_upstream_list_t elts. The elts are currently all pointers to
|
||||
strings which have been distributed according to the weight - so if there are
|
||||
two backends, with weight 3 and 4 respectively, there will be 7 pointers in
|
||||
total with the first 3 pointing to the first backend and the last 4 to the
|
||||
second.
|
||||
|
||||
|
||||
|
||||
TODO
|
||||
----
|
||||
- replace strings with pointers to upstreams if they are available (and if
|
||||
this is possible)
|
||||
- add additional 'http://' to strings if necessary
|
||||
- improve this documentation
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
2010 (C) Marcus Clyne
|
||||
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
In this section there are a number of examples of the various features of the tools
|
||||
module. These have been given in the form of dummy modules, to make it easier to
|
||||
use as templates for your own module should you choose to do so.
|
||||
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
ngx_addon_name=ngx_http_set_var_examples_module
|
||||
HTTP_MODULES="$HTTP_MODULES ngx_http_set_var_examples_module"
|
||||
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_set_var_examples_module.c"
|
||||
have=NDK_SET_VAR . auto/have
|
|
@ -0,0 +1,136 @@
|
|||
|
||||
/*
|
||||
* 2010 (C) Marcus Clyne
|
||||
*/
|
||||
|
||||
|
||||
#include <ndk.h>
|
||||
|
||||
|
||||
static ngx_int_t ngx_http_set_var_concat2 (ngx_http_request_t *r, ngx_str_t *val, ngx_http_variable_value_t *v);
|
||||
static char * ngx_http_set_prepend_hello (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
|
||||
|
||||
static ndk_set_var_t ngx_http_var_set_concat2 = {
|
||||
NDK_SET_VAR_MULTI_VALUE,
|
||||
ngx_http_set_var_concat2,
|
||||
2,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
static ngx_command_t ngx_http_set_var_examples_commands[] = {
|
||||
{
|
||||
ngx_string ("set_concat2"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE3,
|
||||
ndk_set_var_multi_value,
|
||||
0,
|
||||
0,
|
||||
&ngx_http_var_set_concat2
|
||||
},
|
||||
{
|
||||
ngx_string ("set_prepend_hello"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
|
||||
ngx_http_set_prepend_hello,
|
||||
0,
|
||||
0,
|
||||
NULL
|
||||
},
|
||||
ngx_null_command
|
||||
};
|
||||
|
||||
|
||||
ngx_http_module_t ngx_http_set_var_examples_module_ctx = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
|
||||
ngx_module_t ngx_http_set_var_examples_module = {
|
||||
|
||||
NGX_MODULE_V1,
|
||||
&ngx_http_set_var_examples_module_ctx, // module context
|
||||
ngx_http_set_var_examples_commands, // module directives
|
||||
NGX_HTTP_MODULE, // module type
|
||||
NULL, // init master
|
||||
NULL, // init module
|
||||
NULL, // init process
|
||||
NULL, // init thread
|
||||
NULL, // exit thread
|
||||
NULL, // exit process
|
||||
NULL, // exit master
|
||||
NGX_MODULE_V1_PADDING
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
This function is called by both examples, takes two variable values and concatenates them
|
||||
to give a third string.
|
||||
*/
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_set_var_concat2 (ngx_http_request_t *r, ngx_str_t *val, ngx_http_variable_value_t *v)
|
||||
{
|
||||
size_t len;
|
||||
ngx_http_variable_value_t *v2;
|
||||
u_char *p;
|
||||
|
||||
v2 = v + 1;
|
||||
|
||||
len = v->len + v2->len;
|
||||
|
||||
/*
|
||||
* NDK provided abbreviation for the following code:
|
||||
*
|
||||
* p = ngx_palloc (r->pool, len);
|
||||
* if (p == NULL)
|
||||
* return NGX_ERROR;
|
||||
*
|
||||
* */
|
||||
ndk_palloc_re(p, r->pool, len);
|
||||
|
||||
val->data = p;
|
||||
val->len = len;
|
||||
|
||||
ngx_memzero (p, len);
|
||||
|
||||
p = ngx_cpymem (p, v->data, v->len);
|
||||
ngx_memcpy (p, v2->data, v2->len);
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
This function demonstrates using the 'core' function in a function that appends the word
|
||||
'hello_' to the beginning of a variable.
|
||||
|
||||
set $var world;
|
||||
set_prepend_hello $var $var;
|
||||
|
||||
If the arguments used in the variable value filter do not all come directly from the conf
|
||||
file, or are not given in the order
|
||||
|
||||
direcive $var_name val1 "val2 string $var" ...
|
||||
|
||||
then the _core functions should be used inside the function that is called when the directive
|
||||
is read.
|
||||
*/
|
||||
|
||||
static char *
|
||||
ngx_http_set_prepend_hello (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
ngx_str_t s[2], *var_name;
|
||||
ndk_set_var_t filter;
|
||||
|
||||
var_name = cf->args->elts;
|
||||
var_name++;
|
||||
|
||||
s[0].data = (u_char*) "hello_";
|
||||
s[0].len = 6;
|
||||
|
||||
s[1] = *(var_name + 1);
|
||||
|
||||
filter.type = NDK_SET_VAR_MULTI_VALUE;
|
||||
filter.func = ngx_http_set_var_concat2;
|
||||
filter.size = 2;
|
||||
|
||||
return ndk_set_var_multi_value_core (cf, var_name, (ngx_str_t *) s, &filter);
|
||||
}
|
||||
|
|
@ -0,0 +1,797 @@
|
|||
|
||||
## Directories to search for usable builds:
|
||||
##
|
||||
## - [$PFX]_INC and [$PFX]_LIB
|
||||
## - the dir specified by --with-[$pfx]=*
|
||||
## - each dir named [$pfx]-* under [$PFX]_BASE (descending order)
|
||||
## - each dir named [$pfx]-* under $ngx_src_dir/.. (descending order)
|
||||
## - system_paths (see below)
|
||||
##
|
||||
## Note : specifying [$PFX]_INC or [$PFX]_LIB prevents other dirs being tried
|
||||
## specifying --with-[$pfx]= prevents autodiscovery of dirs
|
||||
##
|
||||
## Note : if this file is not in the same directory as the config file, the value
|
||||
## for ngx_auto_lib_file should be changed to a relative path from that file
|
||||
## e.g. : $ngx_addon_dir/libs/ngx_auto_lib
|
||||
##
|
||||
## TODO : explain hooks
|
||||
|
||||
#############
|
||||
## VERSION ##
|
||||
#############
|
||||
|
||||
ngx_auto_lib_version=1001
|
||||
|
||||
if [ ! $ngx_auto_lib_file_version ] || [ $ngx_auto_lib_file_version -lt $ngx_auto_lib_version ]; then
|
||||
|
||||
if [ ! $ngx_addon_dir ]; then
|
||||
ngx_addon_dir=`cd $(dirname $0); pwd`
|
||||
fi
|
||||
|
||||
ngx_auto_lib_file="$ngx_addon_dir/ngx_auto_lib_core"
|
||||
ngx_auto_lib_file_version="$ngx_auto_lib_version"
|
||||
fi
|
||||
|
||||
###############
|
||||
## VARIABLES ##
|
||||
###############
|
||||
|
||||
v=
|
||||
v="$v inc_path"
|
||||
v="$v incs"
|
||||
v="$v libs"
|
||||
v="$v name"
|
||||
v="$v path"
|
||||
v="$v run"
|
||||
v="$v test"
|
||||
ev=
|
||||
ev="$ev add_libs"
|
||||
ev="$ev add_path"
|
||||
ev="$ev build_dirs"
|
||||
ev="$ev build_inc_dirs"
|
||||
ev="$ev build_lib_dirs"
|
||||
ev="$ev check_macros_defined"
|
||||
ev="$ev check_macros_non_zero"
|
||||
ev="$ev defines"
|
||||
ev="$ev deps"
|
||||
ev="$ev exit_if_not_found"
|
||||
ev="$ev haves"
|
||||
ev="$ev inc_names"
|
||||
ev="$ev lib_files"
|
||||
ev="$ev lib_names"
|
||||
ev="$ev libs_to_add"
|
||||
ev="$ev modules"
|
||||
ev="$ev srcs"
|
||||
ev="$ev shared"
|
||||
ev="$ev test_libs"
|
||||
ev="$ev variables"
|
||||
|
||||
ngx_feature_vars="$v"
|
||||
ngx_feature_extra_vars="$ev"
|
||||
ngx_feature_all_vars="$v $ev"
|
||||
|
||||
NGX_AUTO_LIB_DEFAULT_SYSTEM_DIRS='/usr/local /usr /opt/local /opt /usr/pkg'
|
||||
|
||||
####################
|
||||
## UTIL FUNCTIONS ##
|
||||
####################
|
||||
|
||||
to_upper() {
|
||||
echo "$@" | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
}
|
||||
|
||||
to_lower() {
|
||||
echo "$@" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'
|
||||
}
|
||||
|
||||
####################
|
||||
## INIT FUNCTIONS ##
|
||||
####################
|
||||
|
||||
ngx_auto_lib_init() {
|
||||
|
||||
. $ngx_auto_lib_file
|
||||
|
||||
ngx_auto_lib_init_latest $@
|
||||
}
|
||||
|
||||
ngx_auto_lib_init_latest() {
|
||||
|
||||
# set name and prefixes
|
||||
|
||||
if [ ! $1 ]; then
|
||||
echo "ngx_auto_lib_init() requires that a name be passed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ngx_auto_lib_name=$1
|
||||
ngx_auto_lib_module_name=$2
|
||||
|
||||
if [ $2 ]; then
|
||||
NGX_AUTO_LIB_PFX=`to_upper $2`
|
||||
else
|
||||
NGX_AUTO_LIB_PFX=`to_upper $1`
|
||||
fi
|
||||
|
||||
ngx_auto_lib_pfx=`to_lower $NGX_AUTO_LIB_PFX`
|
||||
|
||||
ngx_auto_lib_clean_feature_vars
|
||||
}
|
||||
|
||||
ngx_auto_lib_clean_feature_vars() {
|
||||
for var in $ngx_feature_all_vars; do
|
||||
eval ngx_feature_$var=
|
||||
done
|
||||
}
|
||||
|
||||
ngx_auto_lib_get_variables() {
|
||||
|
||||
local pfx=$ngx_auto_lib_pfx
|
||||
local PFX=$NGX_AUTO_LIB_PFX
|
||||
|
||||
eval NGX_AUTO_LIB_INC=\"\$${PFX}_INC\"
|
||||
eval NGX_AUTO_LIB_LIB=\"\$${PFX}_LIB\"
|
||||
eval NGX_AUTO_LIB_DIR=\"\$${PFX}\"
|
||||
eval NGX_AUTO_LIB_BASE=\"\$${PFX}_BASE\"
|
||||
eval NGX_AUTO_LIB_SEARCH_LIB_INC=\"\$${PFX}_SEARCH_LIB_INC\"
|
||||
eval NGX_AUTO_LIB_SEARCH_DIR=\"\$${PFX}_SEARCH_DIR\"
|
||||
eval NGX_AUTO_LIB_SEARCH_BASE=\"\$${PFX}_SEARCH_BASE\"
|
||||
eval NGX_AUTO_LIB_SEARCH_BASE_PREFIX=\"\$${PFX}_SEARCH_BASE_PREFIX\"
|
||||
eval NGX_AUTO_LIB_SEARCH_PARENT=\"\$${PFX}_SEARCH_PARENT\"
|
||||
eval NGX_AUTO_LIB_SEARCH_SYSTEM=\"\$${PFX}_SEARCH_SYSTEM\"
|
||||
eval NGX_AUTO_LIB_SHARED=\"\$${PFX}_SHARED\"
|
||||
eval NGX_AUTO_LIB_SYSTEM_DIRS=\"\$${PFX}_SYSTEM_DIR\"
|
||||
eval USE_NGX_AUTO_LIB=\"\$USE_${LIB}\"
|
||||
|
||||
if [ ! "$NGX_AUTO_LIB_DIR" ]; then
|
||||
NGX_AUTO_LIB_DIR=NONE
|
||||
fi
|
||||
|
||||
if [ ! "$USE_NGX_AUTO_LIB" ]; then
|
||||
if [ $ngx_feature_check_macros_defined -o $ngx_feature_check_macros_non_zero ]; then
|
||||
USE_NGX_AUTO_LIB=MAYBE
|
||||
elif [ "$ngx_feature_required" = no ]; then
|
||||
USE_NGX_AUTO_LIB=MAYBE
|
||||
else
|
||||
USE_NGX_AUTO_LIB=YES
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! "$NGX_AUTO_LIB_SYSTEM_DIRS" ]; then
|
||||
NGX_AUTO_LIB_SYSTEM_DIRS=$NGX_AUTO_LIB_DEFAULT_SYSTEM_DIRS
|
||||
fi
|
||||
|
||||
# TODO : add _STATIC, and do searches for both static and shared libs
|
||||
|
||||
if [ ! "$NGX_AUTO_LIB_SHARED" ]; then
|
||||
if [ "$ngx_feature_shared" = no ]; then
|
||||
NGX_AUTO_LIB_SHARED=NO
|
||||
else
|
||||
NGX_AUTO_LIB_SHARED=YES
|
||||
fi
|
||||
fi
|
||||
|
||||
NGX_AUTO_LIB_SEARCH_DEP=NO
|
||||
|
||||
# set default search methods
|
||||
# Note : these can be over-ridden by setting NGX_AUTO_LIB_SEARCH_[type]=YES|NO
|
||||
|
||||
local auto=y
|
||||
|
||||
if [ "$NGX_AUTO_LIB_INC" ] || [ "$NGX_AUTO_LIB_LIB" ]; then
|
||||
ngx_auto_lib_search LIB_INC YES
|
||||
auto=n
|
||||
fi
|
||||
|
||||
if [ "$NGX_AUTO_LIB_DIR" != NONE ]; then
|
||||
ngx_auto_lib_search DIR YES
|
||||
auto=n
|
||||
fi
|
||||
|
||||
if [ "$NGX_AUTO_LIB_BASE" ]; then
|
||||
ngx_auto_lib_search BASE YES
|
||||
auto=n
|
||||
fi
|
||||
|
||||
if [ $auto = y ]; then
|
||||
ngx_auto_lib_search PARENT YES
|
||||
ngx_auto_lib_search SYSTEM YES
|
||||
fi
|
||||
|
||||
ngx_auto_lib_search LIB_INC NO
|
||||
ngx_auto_lib_search DIR NO
|
||||
ngx_auto_lib_search BASE NO
|
||||
ngx_auto_lib_search PARENT NO
|
||||
ngx_auto_lib_search SYSTEM NO
|
||||
|
||||
if [ ! "$ngx_feature_lib_names" ]; then
|
||||
ngx_feature_lib_names=$pfx
|
||||
fi
|
||||
|
||||
if [ ! "$ngx_feature_inc_names" ]; then
|
||||
ngx_feature_inc_names=$ngx_feature_lib_names
|
||||
fi
|
||||
|
||||
if [ ! "$ngx_feature_exit_if_not_found" ]; then
|
||||
ngx_feature_exit_if_not_found=yes
|
||||
fi
|
||||
}
|
||||
|
||||
#######################
|
||||
## DEFAULT FUNCTIONS ##
|
||||
#######################
|
||||
|
||||
ngx_auto_lib_set_default() {
|
||||
|
||||
local suffix=
|
||||
if [ $1 ]; then
|
||||
suffix="_$1"
|
||||
fi
|
||||
|
||||
local def=$2
|
||||
local var="NGX_AUTO_LIB$suffix"
|
||||
|
||||
val=
|
||||
if [ ! `eval echo '$'$var` ]; then
|
||||
eval $var=\"$def\"
|
||||
fi
|
||||
|
||||
#eval echo "$var = \$$var"
|
||||
}
|
||||
|
||||
ngx_auto_lib_search() {
|
||||
ngx_auto_lib_set_default "SEARCH_$1" $2
|
||||
}
|
||||
|
||||
####################
|
||||
## SAVE FUNCTIONS ##
|
||||
####################
|
||||
|
||||
ngx_auto_lib_save_vars() {
|
||||
OLD_CORE_DEPS=$CORE_DEPS
|
||||
OLD_CORE_INCS=$CORE_INCS
|
||||
OLD_CORE_LIBS=$CORE_LIBS
|
||||
OLD_CORE_SRCS=$CORE_SRCS
|
||||
OLD_LINK_DEPS=$LINK_DEPS
|
||||
|
||||
CORE_DEPS=
|
||||
CORE_INCS=
|
||||
CORE_LIBS=
|
||||
CORE_SRCS=
|
||||
LINK_DEPS=
|
||||
}
|
||||
|
||||
ngx_auto_lib_reset_vars() {
|
||||
CORE_DEPS=$OLD_CORE_DEPS
|
||||
CORE_INCS=$OLD_CORE_INCS
|
||||
CORE_LIBS=$OLD_CORE_LIBS
|
||||
CORE_SRCS=$OLD_CORE_SRCS
|
||||
LINK_DEPS=$OLD_LINK_DEPS
|
||||
}
|
||||
|
||||
ngx_auto_lib_save_feature_vars() {
|
||||
for var in $ngx_feature_all_vars; do
|
||||
eval main_ngx_feature_$var=\"\$ngx_feature_$var\"
|
||||
done
|
||||
}
|
||||
|
||||
ngx_auto_lib_reset_feature_vars() {
|
||||
for var in $ngx_feature_all_vars; do
|
||||
eval ngx_feature_$var=\"\$main_ngx_feature_$var\"
|
||||
done
|
||||
}
|
||||
|
||||
########################
|
||||
## CHECKING FUNCTIONS ##
|
||||
########################
|
||||
|
||||
ngx_auto_lib_check_auto_config() {
|
||||
|
||||
ngx_auto_lib_save_feature_vars
|
||||
ngx_auto_lib_clean_feature_vars
|
||||
|
||||
ngx_feature=$1
|
||||
ngx_feature_inc_path="`echo $CFLAGS | tr ' ' '\n' | grep -- -D | tr '\n' ' '`"
|
||||
ngx_feature_incs="#include <$NGX_AUTO_CONFIG_H>"
|
||||
ngx_feature_libs=
|
||||
ngx_feature_path=`pwd`
|
||||
ngx_feature_run=no
|
||||
ngx_feature_test=$2
|
||||
|
||||
#ngx_auto_lib_print_feature_vars
|
||||
|
||||
. auto/feature
|
||||
|
||||
if [ $ngx_found = yes ]; then
|
||||
rv=0
|
||||
else
|
||||
rv=1
|
||||
fi
|
||||
|
||||
ngx_auto_lib_reset_feature_vars
|
||||
|
||||
return $rv
|
||||
}
|
||||
|
||||
ngx_auto_lib_check_macro_defined() {
|
||||
|
||||
for m in $@; do
|
||||
ngx_auto_lib_check_auto_config "$m" "
|
||||
#ifndef $m
|
||||
rubbish
|
||||
#endif" && return 0
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
ngx_auto_lib_check_macro_non_zero() {
|
||||
|
||||
for m in $@; do
|
||||
ngx_auto_lib_check_auto_config "$m" "
|
||||
#if !($m)
|
||||
rubbish
|
||||
#endif" && return 0
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
ngx_auto_lib_check_require() {
|
||||
|
||||
if [ $USE_NGX_AUTO_LIB = YES ]; then
|
||||
return 0
|
||||
elif [ $USE_NGX_AUTO_LIB = NO ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
||||
# check if the libraries are required elsewhere
|
||||
|
||||
for l in $ngx_feature_lib_names; do
|
||||
[ ! "`echo $CORE_LIBS $ADDON_LIBS | grep -w -- -l$l`" ] && return 0
|
||||
done
|
||||
|
||||
|
||||
|
||||
# check that any required macros are set
|
||||
|
||||
local d=$ngx_feature_check_macros_defined
|
||||
local nz=$ngx_feature_check_macros_non_zero
|
||||
|
||||
if [ "$d" ] || [ "$nz" ]; then
|
||||
|
||||
ngx_auto_lib_check_macro_defined $d && return 0
|
||||
ngx_auto_lib_check_macro_non_zero $nz && return 0
|
||||
fi
|
||||
|
||||
|
||||
ngx_auto_lib_check
|
||||
}
|
||||
|
||||
ngx_auto_lib_check() {
|
||||
return 1
|
||||
}
|
||||
|
||||
##################################
|
||||
## TEST PHASE HANDLER FUNCTIONS ##
|
||||
##################################
|
||||
|
||||
ngx_auto_lib_test() {
|
||||
ngx_auto_lib_test_pre_setup "$@"
|
||||
ngx_auto_lib_test_setup "$@"
|
||||
ngx_auto_lib_test_post_setup "$@"
|
||||
ngx_auto_lib_test_feature
|
||||
}
|
||||
|
||||
ngx_auto_lib_test_pre_setup() {
|
||||
return 0
|
||||
}
|
||||
|
||||
ngx_auto_lib_test_setup() {
|
||||
|
||||
local INC=$1
|
||||
local LIB=$2
|
||||
|
||||
ngx_auto_lib_inc_dir=$INC
|
||||
ngx_auto_lib_lib_dir=$LIB
|
||||
|
||||
ngx_auto_lib_reset_feature_vars
|
||||
|
||||
if [ ! "$ngx_feature_path" ]; then
|
||||
ngx_feature_path="$INC"
|
||||
fi
|
||||
|
||||
ngx_feature_path="$ngx_feature_path $ngx_feature_add_path"
|
||||
|
||||
for sfx in $ngx_feature_path_suffixes; do
|
||||
ngx_feature_path="$ngx_feature_path $INC/$sfx"
|
||||
done
|
||||
|
||||
|
||||
local inc=
|
||||
local lib=
|
||||
local incs="$ngx_feature_inc_names"
|
||||
local libs="$ngx_feature_lib_names"
|
||||
local lib_files="$ngx_feature_lib_files"
|
||||
|
||||
for inc in $incs; do
|
||||
ngx_feature_incs="$ngx_feature_incs
|
||||
#include <$inc.h>"
|
||||
done
|
||||
|
||||
|
||||
if [ ! "$ngx_feature_libs" ]; then
|
||||
|
||||
if [ $NGX_AUTO_LIB_SHARED = YES ]; then
|
||||
if [ $NGX_RPATH = YES ]; then
|
||||
ngx_feature_libs="-R$LIB"
|
||||
fi
|
||||
ngx_feature_libs="$ngx_feature_libs -L$LIB"
|
||||
|
||||
for lib in $libs; do
|
||||
ngx_feature_libs="$ngx_feature_libs -l$lib"
|
||||
done
|
||||
|
||||
# TODO : only add --rpath when the path is not a standard system path - warn if /usr
|
||||
|
||||
ngx_feature_libs="$ngx_feature_libs -Wl,--rpath -Wl,$LIB"
|
||||
|
||||
else
|
||||
|
||||
for lib in $lib_files; do
|
||||
ngx_feature_libs="$ngx_feature_libs $LIB/$lib"
|
||||
done
|
||||
|
||||
for lib in $libs; do
|
||||
ngx_feature_libs="$ngx_feature_libs $LIB/lib$lib.a"
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! $ngx_feature_run ]; then
|
||||
ngx_feature_run=no
|
||||
fi
|
||||
|
||||
if [ $NGX_AUTO_LIB_SHARED = YES ]; then
|
||||
|
||||
# Add a test to be called in auto/feature after compilation that will check
|
||||
# whether any libraries that are linked are in fact using the path provided to
|
||||
# link libraries rather than a standard path. Note : this test will work on
|
||||
# all linked shared objects, even if supplied directly by setting
|
||||
# $ngx_feature_libs instead of usign $ngx_feature_lib_names
|
||||
|
||||
# TODO : allow for some libraries to not be checked here if desired - if part of system paths
|
||||
|
||||
libs="`echo $ngx_feature_libs | tr ' ' '\n' | grep -- -l | sed 's|-l||g'`"
|
||||
|
||||
local test="
|
||||
for l in $libs; do
|
||||
o="'\`ldd '$NGX_AUTOTEST' | grep '$LIB'/lib\$l\\.so\`;
|
||||
if [ ! \"\$o\" ]; then
|
||||
chmod -x $NGX_AUTOTEST;
|
||||
echo Linker does not link to correct version
|
||||
else
|
||||
chmod +x $NGX_AUTOTEST;
|
||||
fi
|
||||
done'
|
||||
test="`echo "$test" | tr '\n' ' '`"
|
||||
|
||||
ngx_feature_test_libs="$ngx_feature_test_libs; $test"
|
||||
fi
|
||||
|
||||
ngx_feature_libs="$ngx_feature_libs $ngx_feature_add_libs"
|
||||
ngx_feature_libs_to_add="$ngx_feature_libs"
|
||||
ngx_feature_libs="$ngx_feature_libs $ngx_feature_test_libs"
|
||||
ngx_feature="$ngx_auto_lib_name library $ngx_feature"
|
||||
}
|
||||
|
||||
ngx_auto_lib_test_post_setup() {
|
||||
return 0
|
||||
}
|
||||
|
||||
ngx_auto_lib_test_feature() {
|
||||
#ngx_auto_lib_print_feature_vars
|
||||
. auto/feature
|
||||
[ $ngx_found = yes ] && return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
########################
|
||||
## TEST DIR FUNCTIONS ##
|
||||
########################
|
||||
|
||||
ngx_auto_lib_test_dir_pair() {
|
||||
ngx_auto_lib_test_inc_dir=$1
|
||||
ngx_auto_lib_test_lib_dir=$2
|
||||
|
||||
if [ $1 = $2 ]; then
|
||||
ngx_feature="in $1$3"
|
||||
else
|
||||
ngx_feature="in $1 and $2$3"
|
||||
fi
|
||||
ngx_auto_lib_test "$1" "$2" "$3"
|
||||
}
|
||||
|
||||
ngx_auto_lib_test_dir_pairs() {
|
||||
ngx_auto_lib_test_dir_pair "$1/include" "$2/lib" "$3" && return 0
|
||||
ngx_auto_lib_test_dir_pair "$1" "$2" "$3" && return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
ngx_auto_lib_test_dirs() {
|
||||
|
||||
local msg="$1"
|
||||
local bdir idir ldir
|
||||
|
||||
local bdirs=$ngx_feature_build_dirs
|
||||
local idirs=$ngx_feature_build_inc_dirs
|
||||
local ldirs=$ngx_feature_build_lib_dirs
|
||||
|
||||
shift
|
||||
|
||||
for dir in "$@"; do
|
||||
ngx_auto_lib_test_dir=$dir
|
||||
|
||||
for ldir in $ldirs; do
|
||||
for idir in $idirs; do
|
||||
ngx_auto_lib_test_dir_pair "$dir/$idir" "$dir/$ldir" "$msg" && return 0
|
||||
done
|
||||
done
|
||||
|
||||
for ldir in $ldirs; do
|
||||
ngx_auto_lib_test_dir_pair "$dir" "$dir/$ldir" "$msg" && return 0
|
||||
done
|
||||
|
||||
for idir in $idirs; do
|
||||
ngx_auto_lib_test_dir_pair "$dir/$idir" "$dir" "$msg" && return 0
|
||||
done
|
||||
|
||||
for bdir in $bdirs; do
|
||||
ngx_auto_lib_test_dir_pairs "$dir/$bdir" "$dir/$bdir" "$msg" && return 0
|
||||
done
|
||||
|
||||
ngx_auto_lib_test_dir_pairs "$dir" "$dir" "$msg" && return 0
|
||||
ngx_auto_lib_test_dir=
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
ngx_auto_lib_test_install_dirs() {
|
||||
|
||||
local msg="$1"
|
||||
local dir=
|
||||
|
||||
shift
|
||||
|
||||
for dir in "$@"; do
|
||||
ngx_auto_lib_test_dir=$dir
|
||||
ngx_auto_lib_test_dir_pair "$dir/include" "$dir/lib" "$msg" && return 0
|
||||
ngx_auto_lib_test_dir=
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
ngx_auto_lib_run_tests() {
|
||||
|
||||
local name="$ngx_auto_lib_name"
|
||||
local pfx="$ngx_auto_lib_pfx"
|
||||
local PFX="$NGX_AUTO_LIB_PFX"
|
||||
local INC="$NGX_AUTO_LIB_INC"
|
||||
local LIB="$NGX_AUTO_LIB_LIB"
|
||||
local DIR="$NGX_AUTO_LIB_DIR"
|
||||
local BASE="$NGX_AUTO_LIB_BASE"
|
||||
local MSG="$NGX_AUTO_LIB_MSG"
|
||||
|
||||
|
||||
ngx_found=no
|
||||
|
||||
|
||||
# dependency
|
||||
|
||||
if [ $NGX_AUTO_LIB_SEARCH_DEP = YES ]; then
|
||||
ngx_auto_lib_test_dir_pair "$INC" "$LIB" "$MSG"
|
||||
return $?
|
||||
fi
|
||||
|
||||
|
||||
# lib and include dirs set explicitly (e.g. $OPENSSL_INC, $OPENSSL_LIB)
|
||||
|
||||
if [ $NGX_AUTO_LIB_SEARCH_LIB_INC = YES ]; then
|
||||
ngx_auto_lib_test_dir_pair "$INC" "$LIB" " (specified by \$${PFX}_INC and \$${PFX}_LIB)" && return 0
|
||||
fi
|
||||
|
||||
|
||||
# path specified by ${PFX} (e.g. $OPENSSL, $PCRE)
|
||||
# Note : these will be set automatically by configure for OpenSSL, PCRE, Zlib etc
|
||||
# TODO : change to searching more than one path
|
||||
|
||||
if [ $NGX_AUTO_LIB_SEARCH_DIR = YES ] && [ $DIR != NONE ]; then
|
||||
ngx_auto_lib_test_dirs " (specified by \$${PFX})" $DIR && return 0
|
||||
fi
|
||||
|
||||
|
||||
# directories beginning with '$pfx-' that are in $NGX_AUTO_LIB_BASE (e.g. $OPENSSL_BASE)
|
||||
|
||||
if [ $NGX_AUTO_LIB_SEARCH_BASE = YES ] && [ $BASE ]; then
|
||||
|
||||
p=$NGX_AUTO_LIB_SEARCH_BASE_PREFIX
|
||||
|
||||
if [ "$p" = YES ]; then
|
||||
p="!ame $pfx-*"
|
||||
elif [ "$p" ]; then
|
||||
p="!ame $p*"
|
||||
fi
|
||||
|
||||
ngx_auto_lib_test_dirs " (found under \$${PFX}_BASE)" \
|
||||
`find $BASE/* -maxdepth 0 -type d $p 2> /dev/null | sort -r` && return 0
|
||||
fi
|
||||
|
||||
|
||||
# directories beginning with '$pfx-' that are in the same directory as the Nginx source
|
||||
|
||||
if [ $NGX_AUTO_LIB_SEARCH_PARENT = YES ]; then
|
||||
local src_dir=`cd ..; pwd`
|
||||
ngx_auto_lib_test_dirs " (found under Nginx source parent dir)" \
|
||||
`find $src_dir/* -maxdepth 0 -type d !ame $pfx-* 2> /dev/null | sort -r` && return 0
|
||||
fi
|
||||
|
||||
|
||||
# system folders
|
||||
|
||||
if [ $NGX_AUTO_LIB_SEARCH_SYSTEM = YES ]; then
|
||||
ngx_auto_lib_test_install_dirs "" $NGX_AUTO_LIB_SYSTEM_DIRS && return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
#######################
|
||||
## HANDLER FUNCTIONS ##
|
||||
#######################
|
||||
|
||||
ngx_auto_lib_run() {
|
||||
ngx_auto_lib_get_variables
|
||||
eval AUTO_$NGX_AUTO_LIB_PFX=NO
|
||||
|
||||
ngx_auto_lib_check_require || return
|
||||
ngx_auto_lib_setup || return
|
||||
ngx_auto_lib_save_feature_vars
|
||||
ngx_auto_lib_run_tests
|
||||
ngx_auto_lib_post_tests || return
|
||||
ngx_auto_lib_finalize
|
||||
}
|
||||
|
||||
ngx_auto_lib_print_feature_vars() {
|
||||
echo ----------------------------
|
||||
for var in $ngx_feature_vars; do
|
||||
eval "echo ngx_feature_$var = \$ngx_feature_$var"
|
||||
done
|
||||
echo ----------------------------
|
||||
}
|
||||
|
||||
ngx_auto_lib_setup() {
|
||||
return 0
|
||||
}
|
||||
|
||||
ngx_auto_lib_post_tests() {
|
||||
return 0
|
||||
}
|
||||
|
||||
#############################
|
||||
## SET VARIABLES FUNCTIONS ##
|
||||
#############################
|
||||
|
||||
# TODO : add HTTP/ADDON settings too
|
||||
|
||||
ngx_auto_lib_set_core_variables() {
|
||||
# TODO : don't add includes / libs more than once
|
||||
|
||||
eval CORE_DEPS=\"$CORE_DEPS $ngx_feature_deps\"
|
||||
eval CORE_INCS=\"$CORE_INCS $ngx_feature_path\"
|
||||
eval CORE_LIBS=\"$CORE_LIBS $ngx_feature_libs_to_add\"
|
||||
eval CORE_SRCS=\"$CORE_SRCS $ngx_feature_srcs\"
|
||||
}
|
||||
|
||||
ngx_auto_lib_set_generic_variables() {
|
||||
local INC=$ngx_auto_lib_test_inc_dir
|
||||
local LIB=$ngx_auto_lib_test_lib_dir
|
||||
|
||||
modules="$modules $ngx_feature_modules"
|
||||
|
||||
for have in $ngx_feature_haves; do
|
||||
. auto/have
|
||||
done
|
||||
|
||||
set - $ngx_feature_defines
|
||||
|
||||
while [ $1 ]; do
|
||||
have=$1
|
||||
value=$2
|
||||
. auto/define
|
||||
done
|
||||
|
||||
local PFX=$NGX_AUTO_LIB_PFX
|
||||
|
||||
eval USE_$PFX=NO
|
||||
|
||||
if [ $ngx_auto_lib_test_dir ]; then
|
||||
eval $PFX=$ngx_auto_lib_test_dir
|
||||
else
|
||||
eval $PFX=$ngx_auto_lib_lib_dir
|
||||
fi
|
||||
|
||||
if [ $NGX_AUTO_LIB_SHARED != YES ]; then
|
||||
for l in $ngx_feature_lib_names; do
|
||||
CORE_LIBS=`echo $CORE_LIBS | sed 's|-\<l$l\>||g'`
|
||||
ADDON_LIBS=`echo $ADDON_LIBS | sed 's|-\<l$l\>||g'`
|
||||
done
|
||||
fi
|
||||
|
||||
eval ${PFX}_INC=$INC
|
||||
eval ${PFX}_LIB=$LIB
|
||||
eval ${PFX}_SHARED=$NGX_AUTO_LIB_SHARED
|
||||
eval AUTO_$PFX=YES
|
||||
}
|
||||
|
||||
ngx_auto_lib_set_custom_variables() {
|
||||
return 0
|
||||
}
|
||||
|
||||
########################
|
||||
## FINALIZE FUNCTIONS ##
|
||||
########################
|
||||
|
||||
ngx_auto_lib_finalize() {
|
||||
ngx_auto_lib_finalize_core
|
||||
}
|
||||
|
||||
ngx_auto_lib_finalize_core() {
|
||||
|
||||
if [ $ngx_found = yes ]; then
|
||||
|
||||
ngx_auto_lib_set_core_variables
|
||||
ngx_auto_lib_set_generic_variables
|
||||
|
||||
if [ "$ngx_feature_variables" ]; then
|
||||
eval $ngx_feature_variables
|
||||
fi
|
||||
|
||||
ngx_auto_lib_set_custom_variables
|
||||
|
||||
elif [ $ngx_feature_exit_if_not_found = yes ]; then
|
||||
|
||||
if [ $ngx_auto_lib_module_name ]; then
|
||||
module_txt=" by the $ngx_auto_lib_module_name module"
|
||||
else
|
||||
module_text=
|
||||
fi
|
||||
|
||||
lib=$ngx_auto_lib_name
|
||||
pfx=$ngx_auto_lib_pfx
|
||||
PFX=$NGX_AUTO_LIB_PFX
|
||||
|
||||
cat << END
|
||||
|
||||
$0: error: the $lib library is required$module_txt, but cannot
|
||||
be found using the current configuration. In order for the compilation to succeed,
|
||||
you will need to install the library using your system's package installer or point
|
||||
the configure script to the library using one of the following variables :
|
||||
|
||||
to define a dir to find $pfx library (source or install dir) $PFX
|
||||
to define $pfx lib and include dirs separately ${PFX}_LIB & ${PFX}_INC
|
||||
to define a base dir to search for dirs beginning with $pfx- ${PFX}_BASE
|
||||
|
||||
e.g.
|
||||
|
||||
$ export ${PFX}_LIB=/path/to/library/lib
|
||||
$ export ${PFX}_LIB=/path/to/library/include
|
||||
$ $0 ...
|
||||
|
||||
END
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
Changelog
|
||||
---------
|
||||
|
||||
0.1 feature : set_var functions
|
||||
0.1.1 feature : upstream_list directive and functions
|
||||
0.2 feature : conf merge functions
|
||||
feature : conf command macros
|
||||
feature : 'action' macros
|
||||
0.2.1 bugfix : ndk_map_uri_to_path_add_suffix
|
||||
0.2.2 feature : regex conf functions
|
||||
0.2.3 feature : version number
|
||||
0.2.4 change : the auto/build script is now executed automatically on compilation
|
||||
0.2.9 feature : ngx_auto_lib included with source
|
||||
0.2.11 bugfix : hash functions did not display properly
|
||||
0.2.12 feature : patches for rewrite functions and rewrite phase handler
|
||||
0.2.13 change : revert to old behaviour rewrite functions
|
||||
change : pre-generated config and macro files now provided
|
|
@ -0,0 +1,24 @@
|
|||
Copyright (c) 2010, Marcus Clyne, Simpl (simpl.it)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the organization (Simpl) nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL MARCUS CLYNE OR SIMPL BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -0,0 +1,113 @@
|
|||
|
||||
/*
|
||||
* 2010 (C) Marcus Clyne
|
||||
*
|
||||
* DO NOT EDIT THIS FILE MANUALLY
|
||||
* ------------------------------
|
||||
* This file has been generated automatically from scripts in the $base/auto dir and
|
||||
* data in the $base/auto/data dir. If you wish to edit the output of this file, then
|
||||
* you should edit these files instead.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* Non-generated macros */
|
||||
|
||||
#define ndk_array_count(a) ((a)->nelts)
|
||||
#define ndk_array_get_first(a) ((a)->elts)
|
||||
#define ndk_array_get_index(a,n) ((void*) ((char*) (a)->elts + (a)->size * n))
|
||||
#define ndk_array_get_last(a) ((void*) ((char*) (a)->elts + (a)->size * ((a)->nelts - 1)))
|
||||
#define ndk_array_get_reverse_index(a,n) ((void*) ((char*) (a)->elts + (a)->size * ((a)->nelts - 1 - n)))
|
||||
#define ndk_array_push_clean(p,a) {p = ngx_array_push (a); ndk_zerop (p);}
|
||||
|
||||
|
||||
/* base action macro macros */
|
||||
|
||||
#define ndk_array_create_ac(a,pl,n,sz,ac) {a = ngx_array_create (pl,n,sz); if (a == NULL) ac;}
|
||||
#define ndk_array_init_ac(a,pl,n,sz,ac) {if (ngx_array_init (a,pl,n,sz) == NGX_ERROR) ac;}
|
||||
#define ndk_array_push_ac(p,a,ac) {p = ngx_array_push (a); if (p == NULL) ac;}
|
||||
#define ndk_array_push_clean_ac(p,a,ac) {p = ngx_array_push (a); if (p == NULL) ac; ndk_zerop (p);}
|
||||
#define ndk_array_push_n_ac(p,a,n,ac) {p = ngx_array_push_n (a,n); if (p == NULL) ac;}
|
||||
#define ndk_array_push_n_clean_ac(p,a,n,ac) {p = ngx_array_push_n (a,n); if (p == NULL) ac; ndk_zeropn (p,n);}
|
||||
|
||||
|
||||
/* generated action macros */
|
||||
|
||||
#define ndk_array_create_r0(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,return 0)
|
||||
#define ndk_array_create_r1(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,return 1)
|
||||
#define ndk_array_create_r_1(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,return -1)
|
||||
#define ndk_array_create_rok(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,return NGX_OK)
|
||||
#define ndk_array_create_rce(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,return NGX_CONF_ERROR)
|
||||
#define ndk_array_create_rcok(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,return NGX_CONF_OK)
|
||||
#define ndk_array_create_re(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,return NGX_ERROR)
|
||||
#define ndk_array_create_rn(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,return NULL)
|
||||
#define ndk_array_create_rse(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,{ngx_script_error (e); return;})
|
||||
#define ndk_array_create_sce(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,{ngx_script_configure_error (c); return;})
|
||||
#define ndk_array_create_g(a,pl,n,sz,_lb) ndk_array_create_ac (a,pl,n,sz,goto _lb)
|
||||
#define ndk_array_create_ge(a,pl,n,sz) ndk_array_create_ac (a,pl,n,sz,goto error)
|
||||
|
||||
#define ndk_array_init_r0(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,return 0)
|
||||
#define ndk_array_init_r1(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,return 1)
|
||||
#define ndk_array_init_r_1(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,return -1)
|
||||
#define ndk_array_init_rok(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,return NGX_OK)
|
||||
#define ndk_array_init_rce(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,return NGX_CONF_ERROR)
|
||||
#define ndk_array_init_rcok(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,return NGX_CONF_OK)
|
||||
#define ndk_array_init_re(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,return NGX_ERROR)
|
||||
#define ndk_array_init_rn(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,return NULL)
|
||||
#define ndk_array_init_rse(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,{ngx_script_error (e); return;})
|
||||
#define ndk_array_init_sce(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,{ngx_script_configure_error (c); return;})
|
||||
#define ndk_array_init_g(a,pl,n,sz,_lb) ndk_array_init_ac (a,pl,n,sz,goto _lb)
|
||||
#define ndk_array_init_ge(a,pl,n,sz) ndk_array_init_ac (a,pl,n,sz,goto error)
|
||||
|
||||
#define ndk_array_push_r0(p,a) ndk_array_push_ac (p,a,return 0)
|
||||
#define ndk_array_push_r1(p,a) ndk_array_push_ac (p,a,return 1)
|
||||
#define ndk_array_push_r_1(p,a) ndk_array_push_ac (p,a,return -1)
|
||||
#define ndk_array_push_rok(p,a) ndk_array_push_ac (p,a,return NGX_OK)
|
||||
#define ndk_array_push_rce(p,a) ndk_array_push_ac (p,a,return NGX_CONF_ERROR)
|
||||
#define ndk_array_push_rcok(p,a) ndk_array_push_ac (p,a,return NGX_CONF_OK)
|
||||
#define ndk_array_push_re(p,a) ndk_array_push_ac (p,a,return NGX_ERROR)
|
||||
#define ndk_array_push_rn(p,a) ndk_array_push_ac (p,a,return NULL)
|
||||
#define ndk_array_push_rse(p,a) ndk_array_push_ac (p,a,{ngx_script_error (e); return;})
|
||||
#define ndk_array_push_sce(p,a) ndk_array_push_ac (p,a,{ngx_script_configure_error (c); return;})
|
||||
#define ndk_array_push_g(p,a,_lb) ndk_array_push_ac (p,a,goto _lb)
|
||||
#define ndk_array_push_ge(p,a) ndk_array_push_ac (p,a,goto error)
|
||||
|
||||
#define ndk_array_push_clean_r0(p,a) ndk_array_push_clean_ac (p,a,return 0)
|
||||
#define ndk_array_push_clean_r1(p,a) ndk_array_push_clean_ac (p,a,return 1)
|
||||
#define ndk_array_push_clean_r_1(p,a) ndk_array_push_clean_ac (p,a,return -1)
|
||||
#define ndk_array_push_clean_rok(p,a) ndk_array_push_clean_ac (p,a,return NGX_OK)
|
||||
#define ndk_array_push_clean_rce(p,a) ndk_array_push_clean_ac (p,a,return NGX_CONF_ERROR)
|
||||
#define ndk_array_push_clean_rcok(p,a) ndk_array_push_clean_ac (p,a,return NGX_CONF_OK)
|
||||
#define ndk_array_push_clean_re(p,a) ndk_array_push_clean_ac (p,a,return NGX_ERROR)
|
||||
#define ndk_array_push_clean_rn(p,a) ndk_array_push_clean_ac (p,a,return NULL)
|
||||
#define ndk_array_push_clean_rse(p,a) ndk_array_push_clean_ac (p,a,{ngx_script_error (e); return;})
|
||||
#define ndk_array_push_clean_sce(p,a) ndk_array_push_clean_ac (p,a,{ngx_script_configure_error (c); return;})
|
||||
#define ndk_array_push_clean_g(p,a,_lb) ndk_array_push_clean_ac (p,a,goto _lb)
|
||||
#define ndk_array_push_clean_ge(p,a) ndk_array_push_clean_ac (p,a,goto error)
|
||||
|
||||
#define ndk_array_push_n_r0(p,a,n) ndk_array_push_n_ac (p,a,n,return 0)
|
||||
#define ndk_array_push_n_r1(p,a,n) ndk_array_push_n_ac (p,a,n,return 1)
|
||||
#define ndk_array_push_n_r_1(p,a,n) ndk_array_push_n_ac (p,a,n,return -1)
|
||||
#define ndk_array_push_n_rok(p,a,n) ndk_array_push_n_ac (p,a,n,return NGX_OK)
|
||||
#define ndk_array_push_n_rce(p,a,n) ndk_array_push_n_ac (p,a,n,return NGX_CONF_ERROR)
|
||||
#define ndk_array_push_n_rcok(p,a,n) ndk_array_push_n_ac (p,a,n,return NGX_CONF_OK)
|
||||
#define ndk_array_push_n_re(p,a,n) ndk_array_push_n_ac (p,a,n,return NGX_ERROR)
|
||||
#define ndk_array_push_n_rn(p,a,n) ndk_array_push_n_ac (p,a,n,return NULL)
|
||||
#define ndk_array_push_n_rse(p,a,n) ndk_array_push_n_ac (p,a,n,{ngx_script_error (e); return;})
|
||||
#define ndk_array_push_n_sce(p,a,n) ndk_array_push_n_ac (p,a,n,{ngx_script_configure_error (c); return;})
|
||||
#define ndk_array_push_n_g(p,a,n,_lb) ndk_array_push_n_ac (p,a,n,goto _lb)
|
||||
#define ndk_array_push_n_ge(p,a,n) ndk_array_push_n_ac (p,a,n,goto error)
|
||||
|
||||
#define ndk_array_push_n_clean_r0(p,a,n) ndk_array_push_n_clean_ac (p,a,n,return 0)
|
||||
#define ndk_array_push_n_clean_r1(p,a,n) ndk_array_push_n_clean_ac (p,a,n,return 1)
|
||||
#define ndk_array_push_n_clean_r_1(p,a,n) ndk_array_push_n_clean_ac (p,a,n,return -1)
|
||||
#define ndk_array_push_n_clean_rok(p,a,n) ndk_array_push_n_clean_ac (p,a,n,return NGX_OK)
|
||||
#define ndk_array_push_n_clean_rce(p,a,n) ndk_array_push_n_clean_ac (p,a,n,return NGX_CONF_ERROR)
|
||||
#define ndk_array_push_n_clean_rcok(p,a,n) ndk_array_push_n_clean_ac (p,a,n,return NGX_CONF_OK)
|
||||
#define ndk_array_push_n_clean_re(p,a,n) ndk_array_push_n_clean_ac (p,a,n,return NGX_ERROR)
|
||||
#define ndk_array_push_n_clean_rn(p,a,n) ndk_array_push_n_clean_ac (p,a,n,return NULL)
|
||||
#define ndk_array_push_n_clean_rse(p,a,n) ndk_array_push_n_clean_ac (p,a,n,{ngx_script_error (e); return;})
|
||||
#define ndk_array_push_n_clean_sce(p,a,n) ndk_array_push_n_clean_ac (p,a,n,{ngx_script_configure_error (c); return;})
|
||||
#define ndk_array_push_n_clean_g(p,a,n,_lb) ndk_array_push_n_clean_ac (p,a,n,goto _lb)
|
||||
#define ndk_array_push_n_clean_ge(p,a,n) ndk_array_push_n_clean_ac (p,a,n,goto error)
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,227 @@
|
|||
|
||||
/*
|
||||
* 2010 (C) Marcus Clyne
|
||||
*
|
||||
* DO NOT EDIT THIS FILE MANUALLY
|
||||
* ------------------------------
|
||||
* This file has been generated automatically from scripts in the $base/auto dir and
|
||||
* data in the $base/auto/data dir. If you wish to edit the output of this file, then
|
||||
* you should edit these files instead.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* conf-merge-value macros */
|
||||
|
||||
/* TODO : check that all the main types have a corresponding merge function */
|
||||
|
||||
#define ndk_conf_merge_value ngx_conf_merge_value
|
||||
#define ndk_conf_merge_off_value ngx_conf_merge_off_value
|
||||
#define ndk_conf_merge_ptr_value ngx_conf_merge_ptr_value
|
||||
#define ndk_conf_merge_str_value ngx_conf_merge_str_value
|
||||
#define ndk_conf_merge_size_value ngx_conf_merge_size_value
|
||||
|
||||
|
||||
#define ndk_conf_merge_keyval_value(conf,prev,default) \
|
||||
\
|
||||
conf = prev ? prev : default;
|
||||
|
||||
#define ndk_conf_merge_str_array_value(conf,prev,val1,...) \
|
||||
\
|
||||
if (conf == NGX_CONF_UNSET_PTR) { \
|
||||
if (prev == NGX_CONF_UNSET_PTR) { \
|
||||
if (val1 == NULL) { \
|
||||
conf = NULL; \
|
||||
} else { \
|
||||
char * elts[] = {val1,##__VA_ARGS__}; \
|
||||
int n = sizeof(elts)/sizeof(char*); \
|
||||
\
|
||||
conf = ndk_str_array_create (cf->pool, elts, n); \
|
||||
\
|
||||
if (conf == NULL) \
|
||||
return NGX_CONF_ERROR; \
|
||||
} \
|
||||
} else { \
|
||||
conf = prev; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ndk_conf_merge_http_complex_value_value(conf,prev,default) \
|
||||
\
|
||||
if (!conf.str.len) { \
|
||||
if (prev.str.len) { \
|
||||
conf = prev; \
|
||||
} else { \
|
||||
conf.str.data = (u_char *) default; \
|
||||
conf.str.len = sizeof (default) - 1; \
|
||||
\
|
||||
if (ndk_http_complex_value_compile (cf, &conf)) \
|
||||
return NGX_CONF_ERROR; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ndk_conf_merge_http_complex_value_array_value(conf,prev,val1,...) \
|
||||
\
|
||||
if (conf == NGX_CONF_UNSET_PTR) { \
|
||||
if (prev == NGX_CONF_UNSET_PTR) { \
|
||||
if (val1 == NULL) \
|
||||
conf = NULL; \
|
||||
else { \
|
||||
char * elts[] = {val1,##__VA_ARGS__}; \
|
||||
int n = sizeof(elts)/sizeof(char*); \
|
||||
\
|
||||
conf = ndk_http_complex_value_array_create (cf, elts, n); \
|
||||
\
|
||||
if (conf == NULL) \
|
||||
return NGX_CONF_ERROR; \
|
||||
} \
|
||||
} else { \
|
||||
conf = prev; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ndk_conf_merge_http_complex_path_value(conf,prev,...) \
|
||||
ndk_conf_merge_http_complex_value_array_value (conf.a, prev.a, __VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_split_path_value(conf,prev,path) \
|
||||
\
|
||||
if (conf == NGX_CONF_UNSET_PTR) { \
|
||||
conf = (prev == NGX_CONF_UNSET_PTR ? \
|
||||
ndk_split_path_create_raw (cf, path) : prev); \
|
||||
}
|
||||
|
||||
|
||||
/* conf-merge-prop macros */
|
||||
|
||||
#define ndk_conf_merge_prop(prop,default)\
|
||||
ndk_conf_merge_value\
|
||||
(conf->prop, prev->prop, default)
|
||||
|
||||
#define ndk_conf_merge_bitmask_prop(prop,default,...)\
|
||||
ndk_conf_merge_bitmask_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_bufs_prop(prop,default,...)\
|
||||
ndk_conf_merge_bufs_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_encoding_prop(prop,default,...)\
|
||||
ndk_conf_merge_encoding_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_enum_prop(prop,default,...)\
|
||||
ndk_conf_merge_enum_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_false_prop(prop,default,...)\
|
||||
ndk_conf_merge_false_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_flag_prop(prop,default,...)\
|
||||
ndk_conf_merge_flag_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_full_path_prop(prop,default,...)\
|
||||
ndk_conf_merge_full_path_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_http_complex_keyval_prop(prop,default,...)\
|
||||
ndk_conf_merge_http_complex_keyval_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_http_complex_path_prop(prop,default,...)\
|
||||
ndk_conf_merge_http_complex_path_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_http_complex_value_prop(prop,default,...)\
|
||||
ndk_conf_merge_http_complex_value_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_http_complex_value_array_prop(prop,default,...)\
|
||||
ndk_conf_merge_http_complex_value_array_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_keyval_prop(prop,default,...)\
|
||||
ndk_conf_merge_keyval_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_keyval1_prop(prop,default,...)\
|
||||
ndk_conf_merge_keyval1_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_msec_prop(prop,default,...)\
|
||||
ndk_conf_merge_msec_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_null_prop(prop,default,...)\
|
||||
ndk_conf_merge_null_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_num_prop(prop,default,...)\
|
||||
ndk_conf_merge_num_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_num64_prop(prop,default,...)\
|
||||
ndk_conf_merge_num64_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_num_flag_prop(prop,default,...)\
|
||||
ndk_conf_merge_num_flag_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_off_prop(prop,default,...)\
|
||||
ndk_conf_merge_off_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_ptr_prop(prop,default,...)\
|
||||
ndk_conf_merge_ptr_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_regex_prop(prop,default,...)\
|
||||
ndk_conf_merge_regex_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_regex_array_prop(prop,default,...)\
|
||||
ndk_conf_merge_regex_array_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_regex_array_caseless_prop(prop,default,...)\
|
||||
ndk_conf_merge_regex_array_caseless_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_regex_caseless_prop(prop,default,...)\
|
||||
ndk_conf_merge_regex_caseless_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_sec_prop(prop,default,...)\
|
||||
ndk_conf_merge_sec_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_sec_flag_prop(prop,default,...)\
|
||||
ndk_conf_merge_sec_flag_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_size_prop(prop,default,...)\
|
||||
ndk_conf_merge_size_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_split_path_prop(prop,default,...)\
|
||||
ndk_conf_merge_split_path_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_str_prop(prop,default,...)\
|
||||
ndk_conf_merge_str_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_str_array_prop(prop,default,...)\
|
||||
ndk_conf_merge_str_array_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_str_array_multi_prop(prop,default,...)\
|
||||
ndk_conf_merge_str_array_multi_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
||||
#define ndk_conf_merge_true_prop(prop,default,...)\
|
||||
ndk_conf_merge_true_value\
|
||||
(conf->prop, prev->prop, default,##__VA_ARGS__)
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
|
||||
/*
|
||||
* 2010 (C) Marcus Clyne
|
||||
*
|
||||
* DO NOT EDIT THIS FILE MANUALLY
|
||||
* ------------------------------
|
||||
* This file has been generated automatically from scripts in the $base/auto dir and
|
||||
* data in the $base/auto/data dir. If you wish to edit the output of this file, then
|
||||
* you should edit these files instead.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* optional includes */
|
||||
|
||||
#if (NDK_BUF)
|
||||
#include <ndk_buf.c>
|
||||
#endif
|
||||
#if (NDK_COMPLEX_PATH)
|
||||
#include <ndk_complex_path.c>
|
||||
#endif
|
||||
#if (NDK_COMPLEX_VALUE)
|
||||
#include <ndk_complex_value.c>
|
||||
#endif
|
||||
#if (NDK_CONF_FILE)
|
||||
#include <ndk_conf_file.c>
|
||||
#endif
|
||||
#if (NDK_ENCODING)
|
||||
#include <ndk_encoding.c>
|
||||
#endif
|
||||
#if (NDK_HASH)
|
||||
#include <ndk_hash.c>
|
||||
#endif
|
||||
#if (NDK_HTTP)
|
||||
#include <ndk_http.c>
|
||||
#endif
|
||||
#if (NDK_PATH)
|
||||
#include <ndk_path.c>
|
||||
#endif
|
||||
#if (NDK_PROCESS)
|
||||
#include <ndk_process.c>
|
||||
#endif
|
||||
#if (NDK_REGEX)
|
||||
#include <ndk_regex.c>
|
||||
#endif
|
||||
#if (NDK_REWRITE)
|
||||
#include <ndk_rewrite.c>
|
||||
#endif
|
||||
#if (NDK_SET_VAR)
|
||||
#include <ndk_set_var.c>
|
||||
#endif
|
||||
#if (NDK_STRING)
|
||||
#include <ndk_string.c>
|
||||
#endif
|
||||
#if (NDK_UPSTREAM_LIST)
|
||||
#include <ndk_upstream_list.c>
|
||||
#endif
|
||||
#if (NDK_URI)
|
||||
#include <ndk_uri.c>
|
||||
#endif
|
||||
|
||||
|
||||
/* module commands */
|
||||
|
||||
static ngx_command_t ndk_http_commands[] = {
|
||||
#if (NDK_UPSTREAM_LIST)
|
||||
#define NDK_UPSTREAM_LIST_CMDS 1
|
||||
#include <ndk_upstream_list.h>
|
||||
#undef NDK_UPSTREAM_LIST_CMDS
|
||||
#endif
|
||||
ngx_null_command
|
||||
};
|
|
@ -0,0 +1,98 @@
|
|||
|
||||
/*
|
||||
* 2010 (C) Marcus Clyne
|
||||
*
|
||||
* DO NOT EDIT THIS FILE MANUALLY
|
||||
* ------------------------------
|
||||
* This file has been generated automatically from scripts in the $base/auto dir and
|
||||
* data in the $base/auto/data dir. If you wish to edit the output of this file, then
|
||||
* you should edit these files instead.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* include all optional modules */
|
||||
|
||||
#ifdef NDK_ALL
|
||||
|
||||
#ifndef NDK_BUF
|
||||
#define NDK_BUF 1
|
||||
#endif
|
||||
#ifndef NDK_COMPLEX_PATH
|
||||
#define NDK_COMPLEX_PATH 1
|
||||
#endif
|
||||
#ifndef NDK_COMPLEX_VALUE
|
||||
#define NDK_COMPLEX_VALUE 1
|
||||
#endif
|
||||
#ifndef NDK_CONF_FILE
|
||||
#define NDK_CONF_FILE 1
|
||||
#endif
|
||||
#ifndef NDK_ENCODING
|
||||
#define NDK_ENCODING 1
|
||||
#endif
|
||||
#ifndef NDK_HASH
|
||||
#define NDK_HASH 1
|
||||
#endif
|
||||
#ifndef NDK_HTTP
|
||||
#define NDK_HTTP 1
|
||||
#endif
|
||||
#ifndef NDK_PATH
|
||||
#define NDK_PATH 1
|
||||
#endif
|
||||
#ifndef NDK_PROCESS
|
||||
#define NDK_PROCESS 1
|
||||
#endif
|
||||
#ifndef NDK_REGEX
|
||||
#define NDK_REGEX 1
|
||||
#endif
|
||||
#ifndef NDK_REWRITE
|
||||
#define NDK_REWRITE 1
|
||||
#endif
|
||||
#ifndef NDK_SET_VAR
|
||||
#define NDK_SET_VAR 1
|
||||
#endif
|
||||
#ifndef NDK_STRING
|
||||
#define NDK_STRING 1
|
||||
#endif
|
||||
#ifndef NDK_UPSTREAM_LIST
|
||||
#define NDK_UPSTREAM_LIST 1
|
||||
#endif
|
||||
#ifndef NDK_URI
|
||||
#define NDK_URI 1
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* module dependencies */
|
||||
|
||||
#ifdef NDK_COMPLEX_PATH
|
||||
#ifndef NDK_COMPLEX_VALUE
|
||||
#define NDK_COMPLEX_VALUE 1
|
||||
#endif
|
||||
#ifndef NDK_PATH
|
||||
#define NDK_PATH 1
|
||||
#endif
|
||||
#endif
|
||||
#ifdef NDK_CONF_FILE
|
||||
#ifndef NDK_STRING
|
||||
#define NDK_STRING 1
|
||||
#endif
|
||||
#endif
|
||||
#ifdef NDK_HASH
|
||||
#ifndef NDK_STRING
|
||||
#define NDK_STRING 1
|
||||
#endif
|
||||
#endif
|
||||
#ifdef NDK_SET_VAR
|
||||
#ifndef NDK_REWRITE
|
||||
#define NDK_REWRITE 1
|
||||
#endif
|
||||
#endif
|
||||
#ifdef NDK_UPSTREAM_LIST
|
||||
#ifndef NDK_HTTP_CREATE_MAIN_CONF
|
||||
#define NDK_HTTP_CREATE_MAIN_CONF 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
/* optional includes */
|
||||
|
||||
#if (NDK_BUF)
|
||||
#include <ndk_buf.h>
|
||||
#endif
|
||||
#if (NDK_COMPLEX_PATH)
|
||||
#include <ndk_complex_path.h>
|
||||
#endif
|
||||
#if (NDK_COMPLEX_VALUE)
|
||||
#include <ndk_complex_value.h>
|
||||
#endif
|
||||
#if (NDK_CONF_FILE)
|
||||
#include <ndk_conf_file.h>
|
||||
#endif
|
||||
#if (NDK_ENCODING)
|
||||
#include <ndk_encoding.h>
|
||||
#endif
|
||||
#if (NDK_HASH)
|
||||
#include <ndk_hash.h>
|
||||
#endif
|
||||
#if (NDK_HTTP)
|
||||
#include <ndk_http.h>
|
||||
#endif
|
||||
#if (NDK_PATH)
|
||||
#include <ndk_path.h>
|
||||
#endif
|
||||
#if (NDK_PROCESS)
|
||||
#include <ndk_process.h>
|
||||
#endif
|
||||
#if (NDK_REGEX)
|
||||
#include <ndk_regex.h>
|
||||
#endif
|
||||
#if (NDK_REWRITE)
|
||||
#include <ndk_rewrite.h>
|
||||
#endif
|
||||
#if (NDK_SET_VAR)
|
||||
#include <ndk_set_var.h>
|
||||
#endif
|
||||
#if (NDK_STRING)
|
||||
#include <ndk_string.h>
|
||||
#endif
|
||||
#if (NDK_UPSTREAM_LIST)
|
||||
#include <ndk_upstream_list.h>
|
||||
#endif
|
||||
#if (NDK_URI)
|
||||
#include <ndk_uri.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* non-optional includes */
|
||||
|
||||
#include <ndk_http_headers.h>
|
||||
#include <ndk_log.h>
|
||||
#include <ndk_parse.h>
|
||||
#include <ndk_string_util.h>
|
||||
|
||||
|
||||
/* auto-generated headers */
|
||||
|
||||
#include <ndk_array.h>
|
||||
#include <ndk_palloc.h>
|
||||
#include <ndk_conf_merge.h>
|
||||
#include <ndk_conf_cmd_basic.h>
|
||||
#include <ndk_conf_cmd_extra.h>
|
||||
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
|
||||
/*
|
||||
* 2010 (C) Marcus Clyne
|
||||
*
|
||||
* DO NOT EDIT THIS FILE MANUALLY
|
||||
* ------------------------------
|
||||
* This file has been generated automatically from scripts in the $base/auto dir and
|
||||
* data in the $base/auto/data dir. If you wish to edit the output of this file, then
|
||||
* you should edit these files instead.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* Non-generated macros */
|
||||
|
||||
#define ndk_pallocp(p,pl) p = ngx_palloc (pl,sizeof(*p))
|
||||
#define ndk_pallocpn(p,pl,n) p = ngx_palloc (pl,sizeof(*p)*(n))
|
||||
|
||||
#define ndk_pcallocp(p,pl) p = ngx_pcalloc (pl,sizeof(*p))
|
||||
#define ndk_pcallocpn(p,pl,n) p = ngx_pcalloc (pl,sizeof(*p)*(n))
|
||||
|
||||
|
||||
/* base action macro macros */
|
||||
|
||||
#define ndk_palloc_ac(p,pl,sz,ac) {p = ngx_palloc (pl,sz); if (p == NULL) ac;}
|
||||
#define ndk_pallocp_ac(p,pl,ac) {ndk_pallocp (p,pl); if (p == NULL) ac;}
|
||||
#define ndk_pallocpn_ac(p,pl,n,ac) {ndk_pallocpn (p,pl,n); if (p == NULL) ac;}
|
||||
#define ndk_pcalloc_ac(p,pl,sz,ac) {p = ngx_pcalloc (pl,sz); if (p == NULL) ac;}
|
||||
#define ndk_pcallocp_ac(p,pl,ac) {ndk_pcallocp (p,pl); if (p == NULL) ac;}
|
||||
#define ndk_pcallocpn_ac(p,pl,n,ac) {ndk_pcallocpn (p,pl,n); if (p == NULL) ac;}
|
||||
|
||||
|
||||
/* generated action macros */
|
||||
|
||||
#define ndk_palloc_r0(p,pl,sz) ndk_palloc_ac (p,pl,sz,return 0)
|
||||
#define ndk_palloc_r1(p,pl,sz) ndk_palloc_ac (p,pl,sz,return 1)
|
||||
#define ndk_palloc_r_1(p,pl,sz) ndk_palloc_ac (p,pl,sz,return -1)
|
||||
#define ndk_palloc_rok(p,pl,sz) ndk_palloc_ac (p,pl,sz,return NGX_OK)
|
||||
#define ndk_palloc_rce(p,pl,sz) ndk_palloc_ac (p,pl,sz,return NGX_CONF_ERROR)
|
||||
#define ndk_palloc_rcok(p,pl,sz) ndk_palloc_ac (p,pl,sz,return NGX_CONF_OK)
|
||||
#define ndk_palloc_re(p,pl,sz) ndk_palloc_ac (p,pl,sz,return NGX_ERROR)
|
||||
#define ndk_palloc_rn(p,pl,sz) ndk_palloc_ac (p,pl,sz,return NULL)
|
||||
#define ndk_palloc_rse(p,pl,sz) ndk_palloc_ac (p,pl,sz,{ngx_script_error (e); return;})
|
||||
#define ndk_palloc_sce(p,pl,sz) ndk_palloc_ac (p,pl,sz,{ngx_script_configure_error (c); return;})
|
||||
#define ndk_palloc_g(p,pl,sz,_lb) ndk_palloc_ac (p,pl,sz,goto _lb)
|
||||
#define ndk_palloc_ge(p,pl,sz) ndk_palloc_ac (p,pl,sz,goto error)
|
||||
|
||||
#define ndk_pallocp_r0(p,pl) ndk_pallocp_ac (p,pl,return 0)
|
||||
#define ndk_pallocp_r1(p,pl) ndk_pallocp_ac (p,pl,return 1)
|
||||
#define ndk_pallocp_r_1(p,pl) ndk_pallocp_ac (p,pl,return -1)
|
||||
#define ndk_pallocp_rok(p,pl) ndk_pallocp_ac (p,pl,return NGX_OK)
|
||||
#define ndk_pallocp_rce(p,pl) ndk_pallocp_ac (p,pl,return NGX_CONF_ERROR)
|
||||
#define ndk_pallocp_rcok(p,pl) ndk_pallocp_ac (p,pl,return NGX_CONF_OK)
|
||||
#define ndk_pallocp_re(p,pl) ndk_pallocp_ac (p,pl,return NGX_ERROR)
|
||||
#define ndk_pallocp_rn(p,pl) ndk_pallocp_ac (p,pl,return NULL)
|
||||
#define ndk_pallocp_rse(p,pl) ndk_pallocp_ac (p,pl,{ngx_script_error (e); return;})
|
||||
#define ndk_pallocp_sce(p,pl) ndk_pallocp_ac (p,pl,{ngx_script_configure_error (c); return;})
|
||||
#define ndk_pallocp_g(p,pl,_lb) ndk_pallocp_ac (p,pl,goto _lb)
|
||||
#define ndk_pallocp_ge(p,pl) ndk_pallocp_ac (p,pl,goto error)
|
||||
|
||||
#define ndk_pallocpn_r0(p,pl,n) ndk_pallocpn_ac (p,pl,n,return 0)
|
||||
#define ndk_pallocpn_r1(p,pl,n) ndk_pallocpn_ac (p,pl,n,return 1)
|
||||
#define ndk_pallocpn_r_1(p,pl,n) ndk_pallocpn_ac (p,pl,n,return -1)
|
||||
#define ndk_pallocpn_rok(p,pl,n) ndk_pallocpn_ac (p,pl,n,return NGX_OK)
|
||||
#define ndk_pallocpn_rce(p,pl,n) ndk_pallocpn_ac (p,pl,n,return NGX_CONF_ERROR)
|
||||
#define ndk_pallocpn_rcok(p,pl,n) ndk_pallocpn_ac (p,pl,n,return NGX_CONF_OK)
|
||||
#define ndk_pallocpn_re(p,pl,n) ndk_pallocpn_ac (p,pl,n,return NGX_ERROR)
|
||||
#define ndk_pallocpn_rn(p,pl,n) ndk_pallocpn_ac (p,pl,n,return NULL)
|
||||
#define ndk_pallocpn_rse(p,pl,n) ndk_pallocpn_ac (p,pl,n,{ngx_script_error (e); return;})
|
||||
#define ndk_pallocpn_sce(p,pl,n) ndk_pallocpn_ac (p,pl,n,{ngx_script_configure_error (c); return;})
|
||||
#define ndk_pallocpn_g(p,pl,n,_lb) ndk_pallocpn_ac (p,pl,n,goto _lb)
|
||||
#define ndk_pallocpn_ge(p,pl,n) ndk_pallocpn_ac (p,pl,n,goto error)
|
||||
|
||||
#define ndk_pcalloc_r0(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,return 0)
|
||||
#define ndk_pcalloc_r1(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,return 1)
|
||||
#define ndk_pcalloc_r_1(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,return -1)
|
||||
#define ndk_pcalloc_rok(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,return NGX_OK)
|
||||
#define ndk_pcalloc_rce(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,return NGX_CONF_ERROR)
|
||||
#define ndk_pcalloc_rcok(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,return NGX_CONF_OK)
|
||||
#define ndk_pcalloc_re(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,return NGX_ERROR)
|
||||
#define ndk_pcalloc_rn(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,return NULL)
|
||||
#define ndk_pcalloc_rse(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,{ngx_script_error (e); return;})
|
||||
#define ndk_pcalloc_sce(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,{ngx_script_configure_error (c); return;})
|
||||
#define ndk_pcalloc_g(p,pl,sz,_lb) ndk_pcalloc_ac (p,pl,sz,goto _lb)
|
||||
#define ndk_pcalloc_ge(p,pl,sz) ndk_pcalloc_ac (p,pl,sz,goto error)
|
||||
|
||||
#define ndk_pcallocp_r0(p,pl) ndk_pcallocp_ac (p,pl,return 0)
|
||||
#define ndk_pcallocp_r1(p,pl) ndk_pcallocp_ac (p,pl,return 1)
|
||||
#define ndk_pcallocp_r_1(p,pl) ndk_pcallocp_ac (p,pl,return -1)
|
||||
#define ndk_pcallocp_rok(p,pl) ndk_pcallocp_ac (p,pl,return NGX_OK)
|
||||
#define ndk_pcallocp_rce(p,pl) ndk_pcallocp_ac (p,pl,return NGX_CONF_ERROR)
|
||||
#define ndk_pcallocp_rcok(p,pl) ndk_pcallocp_ac (p,pl,return NGX_CONF_OK)
|
||||
#define ndk_pcallocp_re(p,pl) ndk_pcallocp_ac (p,pl,return NGX_ERROR)
|
||||
#define ndk_pcallocp_rn(p,pl) ndk_pcallocp_ac (p,pl,return NULL)
|
||||
#define ndk_pcallocp_rse(p,pl) ndk_pcallocp_ac (p,pl,{ngx_script_error (e); return;})
|
||||
#define ndk_pcallocp_sce(p,pl) ndk_pcallocp_ac (p,pl,{ngx_script_configure_error (c); return;})
|
||||
#define ndk_pcallocp_g(p,pl,_lb) ndk_pcallocp_ac (p,pl,goto _lb)
|
||||
#define ndk_pcallocp_ge(p,pl) ndk_pcallocp_ac (p,pl,goto error)
|
||||
|
||||
#define ndk_pcallocpn_r0(p,pl,n) ndk_pcallocpn_ac (p,pl,n,return 0)
|
||||
#define ndk_pcallocpn_r1(p,pl,n) ndk_pcallocpn_ac (p,pl,n,return 1)
|
||||
#define ndk_pcallocpn_r_1(p,pl,n) ndk_pcallocpn_ac (p,pl,n,return -1)
|
||||
#define ndk_pcallocpn_rok(p,pl,n) ndk_pcallocpn_ac (p,pl,n,return NGX_OK)
|
||||
#define ndk_pcallocpn_rce(p,pl,n) ndk_pcallocpn_ac (p,pl,n,return NGX_CONF_ERROR)
|
||||
#define ndk_pcallocpn_rcok(p,pl,n) ndk_pcallocpn_ac (p,pl,n,return NGX_CONF_OK)
|
||||
#define ndk_pcallocpn_re(p,pl,n) ndk_pcallocpn_ac (p,pl,n,return NGX_ERROR)
|
||||
#define ndk_pcallocpn_rn(p,pl,n) ndk_pcallocpn_ac (p,pl,n,return NULL)
|
||||
#define ndk_pcallocpn_rse(p,pl,n) ndk_pcallocpn_ac (p,pl,n,{ngx_script_error (e); return;})
|
||||
#define ndk_pcallocpn_sce(p,pl,n) ndk_pcallocpn_ac (p,pl,n,{ngx_script_configure_error (c); return;})
|
||||
#define ndk_pcallocpn_g(p,pl,n,_lb) ndk_pcallocpn_ac (p,pl,n,goto _lb)
|
||||
#define ndk_pcallocpn_ge(p,pl,n) ndk_pcallocpn_ac (p,pl,n,goto error)
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
diff -pNr a/src/core/ngx_config.h b/src/core/ngx_config.h
|
||||
*** a/src/core/ngx_config.h 2008-09-19 13:47:13.000000000 +0100
|
||||
--- b/src/core/ngx_config.h 2010-10-09 17:14:13.000000000 +0100
|
||||
*************** typedef intptr_t ngx_flag_t;
|
||||
*** 127,131 ****
|
||||
#define NGX_MAX_UINT32_VALUE (uint32_t) 0xffffffff
|
||||
#endif
|
||||
|
||||
!
|
||||
#endif /* _NGX_CONFIG_H_INCLUDED_ */
|
||||
--- 127,131 ----
|
||||
#define NGX_MAX_UINT32_VALUE (uint32_t) 0xffffffff
|
||||
#endif
|
||||
|
||||
! #include <ndk_config.h>
|
||||
#endif /* _NGX_CONFIG_H_INCLUDED_ */
|
|
@ -0,0 +1,291 @@
|
|||
diff -rNp a/src/http/modules/ngx_http_rewrite_module.c b/src/http/modules/ngx_http_rewrite_module.c
|
||||
*** a/src/http/modules/ngx_http_rewrite_module.c 2010-06-18 16:15:20.000000000 +0100
|
||||
--- b/src/http/modules/ngx_http_rewrite_module.c 2010-10-09 14:47:10.000000000 +0100
|
||||
***************
|
||||
*** 8,14 ****
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_http.h>
|
||||
|
||||
!
|
||||
typedef struct {
|
||||
ngx_array_t *codes; /* uintptr_t */
|
||||
|
||||
--- 8,14 ----
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_http.h>
|
||||
|
||||
! #if !(NDK_EXPOSE_REWRITE_FUNCTIONS)
|
||||
typedef struct {
|
||||
ngx_array_t *codes; /* uintptr_t */
|
||||
|
||||
*************** typedef struct {
|
||||
*** 17,23 ****
|
||||
ngx_flag_t log;
|
||||
ngx_flag_t uninitialized_variable_warn;
|
||||
} ngx_http_rewrite_loc_conf_t;
|
||||
!
|
||||
|
||||
static void *ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf);
|
||||
static char *ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf,
|
||||
--- 17,23 ----
|
||||
ngx_flag_t log;
|
||||
ngx_flag_t uninitialized_variable_warn;
|
||||
} ngx_http_rewrite_loc_conf_t;
|
||||
! #endif
|
||||
|
||||
static void *ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf);
|
||||
static char *ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf,
|
||||
*************** static char *ngx_http_rewrite_return(ngx
|
||||
*** 28,44 ****
|
||||
void *conf);
|
||||
static char *ngx_http_rewrite_break(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_set(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf);
|
||||
static char * ngx_http_rewrite_value(ngx_conf_t *cf,
|
||||
ngx_http_rewrite_loc_conf_t *lcf, ngx_str_t *value);
|
||||
!
|
||||
|
||||
static ngx_command_t ngx_http_rewrite_commands[] = {
|
||||
|
||||
--- 28,47 ----
|
||||
void *conf);
|
||||
static char *ngx_http_rewrite_break(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf);
|
||||
+ #if !(NDK_EXPOSE_REWRITE_FUNCTIONS)
|
||||
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);
|
||||
+ #endif
|
||||
static char *ngx_http_rewrite_set(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf);
|
||||
+ #if !(NDK_EXPOSE_REWRITE_FUNCTIONS)
|
||||
static char * ngx_http_rewrite_value(ngx_conf_t *cf,
|
||||
ngx_http_rewrite_loc_conf_t *lcf, ngx_str_t *value);
|
||||
! #endif
|
||||
|
||||
static ngx_command_t ngx_http_rewrite_commands[] = {
|
||||
|
||||
*************** ngx_http_rewrite_handler(ngx_http_reques
|
||||
*** 178,185 ****
|
||||
return r->err_status;
|
||||
}
|
||||
|
||||
!
|
||||
! static ngx_int_t
|
||||
ngx_http_rewrite_var(ngx_http_request_t *r, ngx_http_variable_value_t *v,
|
||||
uintptr_t data)
|
||||
{
|
||||
--- 181,190 ----
|
||||
return r->err_status;
|
||||
}
|
||||
|
||||
! #if !(NDK_EXPOSE_REWRITE_FUNCTIONS)
|
||||
! static
|
||||
! #endif
|
||||
! ngx_int_t
|
||||
ngx_http_rewrite_var(ngx_http_request_t *r, ngx_http_variable_value_t *v,
|
||||
uintptr_t data)
|
||||
{
|
||||
*************** ngx_http_rewrite_break(ngx_conf_t *cf, n
|
||||
*** 511,517 ****
|
||||
}
|
||||
|
||||
|
||||
! static char *
|
||||
ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
ngx_http_rewrite_loc_conf_t *lcf = conf;
|
||||
--- 516,525 ----
|
||||
}
|
||||
|
||||
|
||||
! #if !(NDK_EXPOSE_REWRITE_FUNCTIONS)
|
||||
! static
|
||||
! #endif
|
||||
! char *
|
||||
ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
ngx_http_rewrite_loc_conf_t *lcf = conf;
|
||||
*************** ngx_http_rewrite_if(ngx_conf_t *cf, ngx_
|
||||
*** 627,633 ****
|
||||
}
|
||||
|
||||
|
||||
! static char *
|
||||
ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
|
||||
{
|
||||
u_char *p;
|
||||
--- 635,644 ----
|
||||
}
|
||||
|
||||
|
||||
! #if !(NDK_EXPOSE_REWRITE_FUNCTIONS)
|
||||
! static
|
||||
! #endif
|
||||
! char *
|
||||
ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
|
||||
{
|
||||
u_char *p;
|
||||
*************** ngx_http_rewrite_if_condition(ngx_conf_t
|
||||
*** 847,853 ****
|
||||
}
|
||||
|
||||
|
||||
! static char *
|
||||
ngx_http_rewrite_variable(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf,
|
||||
ngx_str_t *value)
|
||||
{
|
||||
--- 858,867 ----
|
||||
}
|
||||
|
||||
|
||||
! #if !(NDK_EXPOSE_REWRITE_FUNCTIONS)
|
||||
! static
|
||||
! #endif
|
||||
! char *
|
||||
ngx_http_rewrite_variable(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf,
|
||||
ngx_str_t *value)
|
||||
{
|
||||
*************** ngx_http_rewrite_set(ngx_conf_t *cf, ngx
|
||||
*** 948,954 ****
|
||||
}
|
||||
|
||||
|
||||
! static char *
|
||||
ngx_http_rewrite_value(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf,
|
||||
ngx_str_t *value)
|
||||
{
|
||||
--- 962,971 ----
|
||||
}
|
||||
|
||||
|
||||
! #if !(NDK_EXPOSE_REWRITE_FUNCTIONS)
|
||||
! static
|
||||
! #endif
|
||||
! char *
|
||||
ngx_http_rewrite_value(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf,
|
||||
ngx_str_t *value)
|
||||
{
|
||||
diff -rNp a/src/http/modules/ngx_http_rewrite_module.h b/src/http/modules/ngx_http_rewrite_module.h
|
||||
*** a/src/http/modules/ngx_http_rewrite_module.h 1970-01-01 01:00:00.000000000 +0100
|
||||
--- b/src/http/modules/ngx_http_rewrite_module.h 2010-10-09 14:38:04.000000000 +0100
|
||||
***************
|
||||
*** 0 ****
|
||||
--- 1,47 ----
|
||||
+
|
||||
+ /*
|
||||
+ * Copyright (C) Marcus Clyne
|
||||
+ *
|
||||
+ * Note : this file has been created by the Nginx Development Kit using
|
||||
+ * some code from ngx_http_rewrite_module.c
|
||||
+ */
|
||||
+
|
||||
+ #if (NDK_EXPOSE_REWRITE_FUNCTIONS)
|
||||
+
|
||||
+ #ifndef _NGX_HTTP_REWRITE_H_INCLUDED_
|
||||
+ #define _NGX_HTTP_REWRITE_H_INCLUDED_
|
||||
+
|
||||
+ #include <ngx_config.h>
|
||||
+ #include <ngx_core.h>
|
||||
+ #include <ngx_http.h>
|
||||
+
|
||||
+
|
||||
+ extern ngx_module_t ngx_http_rewrite_module;
|
||||
+
|
||||
+
|
||||
+ typedef struct {
|
||||
+ ngx_array_t *codes; /* uintptr_t */
|
||||
+
|
||||
+ ngx_uint_t stack_size;
|
||||
+
|
||||
+ ngx_flag_t log;
|
||||
+ ngx_flag_t uninitialized_variable_warn;
|
||||
+ } ngx_http_rewrite_loc_conf_t;
|
||||
+
|
||||
+
|
||||
+ char *
|
||||
+ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
+ char *
|
||||
+ ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf);
|
||||
+ char *
|
||||
+ ngx_http_rewrite_variable(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf,
|
||||
+ ngx_str_t *value);
|
||||
+ char *
|
||||
+ ngx_http_rewrite_value(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf,
|
||||
+ ngx_str_t *value);
|
||||
+ ngx_int_t
|
||||
+ ngx_http_rewrite_var(ngx_http_request_t *r, ngx_http_variable_value_t *v,
|
||||
+ uintptr_t data);
|
||||
+
|
||||
+ #endif
|
||||
+ #endif
|
||||
diff -rNp a/src/http/ngx_http.h b/src/http/ngx_http.h
|
||||
*** a/src/http/ngx_http.h 2010-06-15 16:13:34.000000000 +0100
|
||||
--- b/src/http/ngx_http.h 2010-10-09 14:25:56.000000000 +0100
|
||||
*************** typedef u_char *(*ngx_http_log_handler_p
|
||||
*** 43,48 ****
|
||||
--- 43,52 ----
|
||||
#include <ngx_http_ssl_module.h>
|
||||
#endif
|
||||
|
||||
+ #if (NDK_EXPOSE_REWRITE_FUNCTIONS)
|
||||
+ #include <ngx_http_rewrite_module.h>
|
||||
+ #endif
|
||||
+
|
||||
|
||||
struct ngx_http_log_ctx_s {
|
||||
ngx_connection_t *connection;
|
||||
diff -rNp a/src/http/ngx_http_script.c b/src/http/ngx_http_script.c
|
||||
*** a/src/http/ngx_http_script.c 2010-09-13 13:44:43.000000000 +0100
|
||||
--- b/src/http/ngx_http_script.c 2010-10-09 14:36:10.000000000 +0100
|
||||
*************** static size_t ngx_http_script_full_name_
|
||||
*** 26,35 ****
|
||||
--- 26,43 ----
|
||||
static void ngx_http_script_full_name_code(ngx_http_script_engine_t *e);
|
||||
|
||||
|
||||
+ #if (NDK_EXPOSE_REWRITE_FUNCTIONS)
|
||||
+
|
||||
+ uintptr_t ngx_http_script_exit_code = (uintptr_t) NULL;
|
||||
+
|
||||
+ #else
|
||||
+
|
||||
#define ngx_http_script_exit (u_char *) &ngx_http_script_exit_code
|
||||
|
||||
static uintptr_t ngx_http_script_exit_code = (uintptr_t) NULL;
|
||||
|
||||
+ #endif
|
||||
+
|
||||
|
||||
void
|
||||
ngx_http_script_flush_complex_value(ngx_http_request_t *r,
|
||||
diff -rNp a/src/http/ngx_http_script.h b/src/http/ngx_http_script.h
|
||||
*** a/src/http/ngx_http_script.h 2010-09-13 13:44:43.000000000 +0100
|
||||
--- b/src/http/ngx_http_script.h 2010-10-09 14:33:40.000000000 +0100
|
||||
***************
|
||||
*** 12,17 ****
|
||||
--- 12,25 ----
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_http.h>
|
||||
|
||||
+ #if (NDK_EXPOSE_REWRITE_FUNCTIONS)
|
||||
+
|
||||
+ #define ngx_http_script_exit (u_char *) &ngx_http_script_exit_code
|
||||
+
|
||||
+ extern uintptr_t ngx_http_script_exit_code;
|
||||
+
|
||||
+ #endif
|
||||
+
|
||||
|
||||
typedef struct {
|
||||
u_char *ip;
|
|
@ -0,0 +1,19 @@
|
|||
diff -p -r a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
|
||||
*** a/src/http/ngx_http_core_module.c 2010-09-27 12:48:12.000000000 +0100
|
||||
--- b/src/http/ngx_http_core_module.c 2010-10-09 13:44:09.000000000 +0100
|
||||
*************** ngx_http_core_rewrite_phase(ngx_http_req
|
||||
*** 910,915 ****
|
||||
--- 910,922 ----
|
||||
return NGX_AGAIN;
|
||||
}
|
||||
|
||||
+ #if defined(nginx_version) && nginx_version >= 8042 && (NDK_REWRITE_PHASE)
|
||||
+
|
||||
+ if (rc == NGX_AGAIN || rc == NGX_DONE) {
|
||||
+ return NGX_OK;
|
||||
+ }
|
||||
+
|
||||
+ #endif
|
||||
/* rc == NGX_OK || rc == NGX_ERROR || rc == NGX_HTTP_... */
|
||||
|
||||
ngx_http_finalize_request(r, rc);
|
|
@ -0,0 +1,117 @@
|
|||
/* crypto/md5/md5.h */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#ifndef HEADER_MD5_H
|
||||
#define HEADER_MD5_H
|
||||
|
||||
#include <openssl/e_os2.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef OPENSSL_NO_MD5
|
||||
#error MD5 is disabled.
|
||||
#endif
|
||||
|
||||
/*
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
* ! MD5_LONG has to be at least 32 bits wide. If it's wider, then !
|
||||
* ! MD5_LONG_LOG2 has to be defined along. !
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
*/
|
||||
|
||||
#if defined(__LP32__)
|
||||
#define MD5_LONG unsigned long
|
||||
#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
|
||||
#define MD5_LONG unsigned long
|
||||
#define MD5_LONG_LOG2 3
|
||||
/*
|
||||
* _CRAY note. I could declare short, but I have no idea what impact
|
||||
* does it have on performance on none-T3E machines. I could declare
|
||||
* int, but at least on C90 sizeof(int) can be chosen at compile time.
|
||||
* So I've chosen long...
|
||||
* <appro@fy.chalmers.se>
|
||||
*/
|
||||
#else
|
||||
#define MD5_LONG unsigned int
|
||||
#endif
|
||||
|
||||
#define MD5_CBLOCK 64
|
||||
#define MD5_LBLOCK (MD5_CBLOCK/4)
|
||||
#define MD5_DIGEST_LENGTH 16
|
||||
|
||||
typedef struct MD5state_st
|
||||
{
|
||||
MD5_LONG A,B,C,D;
|
||||
MD5_LONG Nl,Nh;
|
||||
MD5_LONG data[MD5_LBLOCK];
|
||||
unsigned int num;
|
||||
} MD5_CTX;
|
||||
|
||||
int MD5_Init(MD5_CTX *c);
|
||||
int MD5_Update(MD5_CTX *c, const void *data, size_t len);
|
||||
int MD5_Final(unsigned char *md, MD5_CTX *c);
|
||||
unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md);
|
||||
void MD5_Transform(MD5_CTX *c, const unsigned char *b);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,77 @@
|
|||
|
||||
|
||||
#ifndef MURMURHASH2_C
|
||||
#define MURMURHASH2_C
|
||||
|
||||
#define MURMURHASH2_DIGEST_LENGTH 4
|
||||
|
||||
/*
|
||||
* -----------------------------------------------------------------------------
|
||||
* MurmurHash2, by Austin Appleby
|
||||
|
||||
* Note - This code makes a few assumptions about how your machine behaves -
|
||||
|
||||
* 1. We can read a 4-byte value from any address without crashing
|
||||
* 2. sizeof(int) == 4
|
||||
|
||||
* And it has a few limitations -
|
||||
|
||||
* 1. It will not work incrementally.
|
||||
* 2. It will not produce the same results on little-endian and big-endian
|
||||
* machines.
|
||||
*/
|
||||
|
||||
unsigned int MurmurHash2 ( const void * key, int len, unsigned int seed )
|
||||
{
|
||||
/*
|
||||
* 'm' and 'r' are mixing constants generated offline.
|
||||
* They're not really 'magic', they just happen to work well.
|
||||
*/
|
||||
|
||||
const unsigned int m = 0x5bd1e995;
|
||||
const int r = 24;
|
||||
|
||||
/* Initialize the hash to a 'random' value */
|
||||
|
||||
unsigned int h = seed ^ len;
|
||||
|
||||
/* Mix 4 bytes at a time into the hash */
|
||||
|
||||
const unsigned char * data = (const unsigned char *)key;
|
||||
|
||||
while(len >= 4)
|
||||
{
|
||||
unsigned int k = *(unsigned int *)data;
|
||||
|
||||
k *= m;
|
||||
k ^= k >> r;
|
||||
k *= m;
|
||||
|
||||
h *= m;
|
||||
h ^= k;
|
||||
|
||||
data += 4;
|
||||
len -= 4;
|
||||
}
|
||||
|
||||
/* Handle the last few bytes of the input array */
|
||||
|
||||
switch(len)
|
||||
{
|
||||
case 3: h ^= data[2] << 16;
|
||||
case 2: h ^= data[1] << 8;
|
||||
case 1: h ^= data[0];
|
||||
h *= m;
|
||||
};
|
||||
|
||||
/* Do a few final mixes of the hash to ensure the last few
|
||||
* bytes are well-incorporated. */
|
||||
|
||||
h ^= h >> 13;
|
||||
h *= m;
|
||||
h ^= h >> 15;
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,200 @@
|
|||
/* crypto/sha/sha.h */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#ifndef HEADER_SHA_H
|
||||
#define HEADER_SHA_H
|
||||
|
||||
#include <openssl/e_os2.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1))
|
||||
#error SHA is disabled.
|
||||
#endif
|
||||
|
||||
#if defined(OPENSSL_FIPS)
|
||||
#define FIPS_SHA_SIZE_T size_t
|
||||
#endif
|
||||
|
||||
/*
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
* ! SHA_LONG has to be at least 32 bits wide. If it's wider, then !
|
||||
* ! SHA_LONG_LOG2 has to be defined along. !
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
*/
|
||||
|
||||
#if defined(__LP32__)
|
||||
#define SHA_LONG unsigned long
|
||||
#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
|
||||
#define SHA_LONG unsigned long
|
||||
#define SHA_LONG_LOG2 3
|
||||
#else
|
||||
#define SHA_LONG unsigned int
|
||||
#endif
|
||||
|
||||
#define SHA_LBLOCK 16
|
||||
#define SHA_CBLOCK (SHA_LBLOCK*4) /* SHA treats input data as a
|
||||
* contiguous array of 32 bit
|
||||
* wide big-endian values. */
|
||||
#define SHA_LAST_BLOCK (SHA_CBLOCK-8)
|
||||
#define SHA_DIGEST_LENGTH 20
|
||||
|
||||
typedef struct SHAstate_st
|
||||
{
|
||||
SHA_LONG h0,h1,h2,h3,h4;
|
||||
SHA_LONG Nl,Nh;
|
||||
SHA_LONG data[SHA_LBLOCK];
|
||||
unsigned int num;
|
||||
} SHA_CTX;
|
||||
|
||||
#ifndef OPENSSL_NO_SHA0
|
||||
int SHA_Init(SHA_CTX *c);
|
||||
int SHA_Update(SHA_CTX *c, const void *data, size_t len);
|
||||
int SHA_Final(unsigned char *md, SHA_CTX *c);
|
||||
unsigned char *SHA(const unsigned char *d, size_t n, unsigned char *md);
|
||||
void SHA_Transform(SHA_CTX *c, const unsigned char *data);
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_SHA1
|
||||
int SHA1_Init(SHA_CTX *c);
|
||||
int SHA1_Update(SHA_CTX *c, const void *data, size_t len);
|
||||
int SHA1_Final(unsigned char *md, SHA_CTX *c);
|
||||
unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md);
|
||||
void SHA1_Transform(SHA_CTX *c, const unsigned char *data);
|
||||
#endif
|
||||
|
||||
#define SHA256_CBLOCK (SHA_LBLOCK*4) /* SHA-256 treats input data as a
|
||||
* contiguous array of 32 bit
|
||||
* wide big-endian values. */
|
||||
#define SHA224_DIGEST_LENGTH 28
|
||||
#define SHA256_DIGEST_LENGTH 32
|
||||
|
||||
typedef struct SHA256state_st
|
||||
{
|
||||
SHA_LONG h[8];
|
||||
SHA_LONG Nl,Nh;
|
||||
SHA_LONG data[SHA_LBLOCK];
|
||||
unsigned int num,md_len;
|
||||
} SHA256_CTX;
|
||||
|
||||
#ifndef OPENSSL_NO_SHA256
|
||||
int SHA224_Init(SHA256_CTX *c);
|
||||
int SHA224_Update(SHA256_CTX *c, const void *data, size_t len);
|
||||
int SHA224_Final(unsigned char *md, SHA256_CTX *c);
|
||||
unsigned char *SHA224(const unsigned char *d, size_t n,unsigned char *md);
|
||||
int SHA256_Init(SHA256_CTX *c);
|
||||
int SHA256_Update(SHA256_CTX *c, const void *data, size_t len);
|
||||
int SHA256_Final(unsigned char *md, SHA256_CTX *c);
|
||||
unsigned char *SHA256(const unsigned char *d, size_t n,unsigned char *md);
|
||||
void SHA256_Transform(SHA256_CTX *c, const unsigned char *data);
|
||||
#endif
|
||||
|
||||
#define SHA384_DIGEST_LENGTH 48
|
||||
#define SHA512_DIGEST_LENGTH 64
|
||||
|
||||
#ifndef OPENSSL_NO_SHA512
|
||||
/*
|
||||
* Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64
|
||||
* being exactly 64-bit wide. See Implementation Notes in sha512.c
|
||||
* for further details.
|
||||
*/
|
||||
#define SHA512_CBLOCK (SHA_LBLOCK*8) /* SHA-512 treats input data as a
|
||||
* contiguous array of 64 bit
|
||||
* wide big-endian values. */
|
||||
#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
|
||||
#define SHA_LONG64 unsigned __int64
|
||||
#define U64(C) C##UI64
|
||||
#elif defined(__arch64__)
|
||||
#define SHA_LONG64 unsigned long
|
||||
#define U64(C) C##UL
|
||||
#else
|
||||
#define SHA_LONG64 unsigned long long
|
||||
#define U64(C) C##ULL
|
||||
#endif
|
||||
|
||||
typedef struct SHA512state_st
|
||||
{
|
||||
SHA_LONG64 h[8];
|
||||
SHA_LONG64 Nl,Nh;
|
||||
union {
|
||||
SHA_LONG64 d[SHA_LBLOCK];
|
||||
unsigned char p[SHA512_CBLOCK];
|
||||
} u;
|
||||
unsigned int num,md_len;
|
||||
} SHA512_CTX;
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_SHA512
|
||||
int SHA384_Init(SHA512_CTX *c);
|
||||
int SHA384_Update(SHA512_CTX *c, const void *data, size_t len);
|
||||
int SHA384_Final(unsigned char *md, SHA512_CTX *c);
|
||||
unsigned char *SHA384(const unsigned char *d, size_t n,unsigned char *md);
|
||||
int SHA512_Init(SHA512_CTX *c);
|
||||
int SHA512_Update(SHA512_CTX *c, const void *data, size_t len);
|
||||
int SHA512_Final(unsigned char *md, SHA512_CTX *c);
|
||||
unsigned char *SHA512(const unsigned char *d, size_t n,unsigned char *md);
|
||||
void SHA512_Transform(SHA512_CTX *c, const unsigned char *data);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,155 @@
|
|||
|
||||
/*
|
||||
* 2010 (C) Marcus Clyne
|
||||
*/
|
||||
|
||||
#include <ndk.h>
|
||||
|
||||
#include <ndk_config.c>
|
||||
|
||||
|
||||
#if (NDK_HTTP_PRE_CONFIG)
|
||||
static ngx_int_t ndk_http_preconfiguration (ngx_conf_t *cf);
|
||||
#endif
|
||||
#if (NDK_HTTP_POST_CONFIG)
|
||||
static ngx_int_t ndk_http_postconfiguration (ngx_conf_t *cf);
|
||||
#endif
|
||||
#if (NDK_HTTP_CREATE_MAIN_CONF)
|
||||
static void * ndk_http_create_main_conf (ngx_conf_t *cf);
|
||||
#endif
|
||||
#if (NDK_HTTP_INIT_MAIN_CONF)
|
||||
static char * ndk_http_init_main_conf (ngx_conf_t *cf, void *conf);
|
||||
#endif
|
||||
#if (NDK_HTTP_CREATE_SRV_CONF)
|
||||
static void * ndk_http_create_srv_conf (ngx_conf_t *cf);
|
||||
#endif
|
||||
#if (NDK_HTTP_MERGE_SRV_CONF)
|
||||
static char * ndk_http_merge_srv_conf (ngx_conf_t *cf, void *parent, void *child);
|
||||
#endif
|
||||
#if (NDK_HTTP_CREATE_LOC_CONF)
|
||||
static void * ndk_http_create_loc_conf (ngx_conf_t *cf);
|
||||
#endif
|
||||
#if (NDK_HTTP_MERGE_LOC_CONF)
|
||||
static char * ndk_http_merge_loc_conf (ngx_conf_t *cf, void *parent, void *child);
|
||||
#endif
|
||||
|
||||
|
||||
#if (NDK_HTTP_INIT_MASTER)
|
||||
static ngx_int_t ndk_http_init_master (ngx_log_t *log);
|
||||
#endif
|
||||
#if (NDK_HTTP_INIT_MODULE)
|
||||
static ngx_int_t ndk_http_init_module (ngx_cycle_t *cycle);
|
||||
#endif
|
||||
#if (NDK_HTTP_INIT_PROCESS)
|
||||
static ngx_int_t ndk_http_init_process (ngx_cycle_t *cycle);
|
||||
#endif
|
||||
#if (NDK_HTTP_EXIT_PROCESS)
|
||||
static void ndk_http_exit_process (ngx_cycle_t *cycle);
|
||||
#endif
|
||||
#if (NDK_HTTP_EXIT_MASTER)
|
||||
static void ndk_http_exit_master (ngx_cycle_t *cycle);
|
||||
#endif
|
||||
|
||||
|
||||
ngx_http_module_t ndk_http_module_ctx = {
|
||||
|
||||
#if (NDK_HTTP_PRE_CONFIG)
|
||||
ndk_http_preconfiguration,
|
||||
#else
|
||||
NULL,
|
||||
#endif
|
||||
#if (NDK_HTTP_POST_CONFIG)
|
||||
ndk_http_postconfiguration,
|
||||
#else
|
||||
NULL,
|
||||
#endif
|
||||
|
||||
#if (NDK_HTTP_CREATE_MAIN_CONF)
|
||||
ndk_http_create_main_conf,
|
||||
#else
|
||||
NULL,
|
||||
#endif
|
||||
#if (NDK_HTTP_INIT_MAIN_CONF)
|
||||
ndk_http_merge_main_conf,
|
||||
#else
|
||||
NULL,
|
||||
#endif
|
||||
|
||||
#if (NDK_HTTP_CREATE_SVR_CONF)
|
||||
ndk_http_create_srv_conf,
|
||||
#else
|
||||
NULL,
|
||||
#endif
|
||||
#if (NDK_HTTP_MERGE_SVR_CONF)
|
||||
ndk_http_merge_srv_conf,
|
||||
#else
|
||||
NULL,
|
||||
#endif
|
||||
|
||||
#if (NDK_HTTP_CREATE_LOC_CONF)
|
||||
ndk_http_create_loc_conf,
|
||||
#else
|
||||
NULL,
|
||||
#endif
|
||||
#if (NDK_HTTP_MERGE_LOC_CONF)
|
||||
ndk_http_merge_loc_conf,
|
||||
#else
|
||||
NULL,
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
ngx_module_t ndk_http_module = {
|
||||
|
||||
NGX_MODULE_V1,
|
||||
&ndk_http_module_ctx, /* module context */
|
||||
ndk_http_commands, /* module directives */
|
||||
NGX_HTTP_MODULE, /* module type */
|
||||
|
||||
#if (NDK_HTTP_INIT_MASTER)
|
||||
ndk_http_init_master,
|
||||
#else
|
||||
NULL,
|
||||
#endif
|
||||
|
||||
#if (NDK_HTTP_INIT_MODULE)
|
||||
ndk_http_init_module,
|
||||
#else
|
||||
NULL,
|
||||
#endif
|
||||
#if (NDK_HTTP_INIT_PROCESS)
|
||||
ndk_http_init_process,
|
||||
#else
|
||||
NULL,
|
||||
#endif
|
||||
|
||||
NULL, /* init thread */
|
||||
NULL, /* exit thread */
|
||||
|
||||
#if (NDK_HTTP_EXIT_PROCESS)
|
||||
ndk_http_exit_process,
|
||||
#else
|
||||
NULL,
|
||||
#endif
|
||||
#if (NDK_HTTP_EXIT_MASTER)
|
||||
ndk_http_exit_master,
|
||||
#else
|
||||
NULL,
|
||||
#endif
|
||||
NGX_MODULE_V1_PADDING
|
||||
};
|
||||
|
||||
|
||||
|
||||
#if (NDK_HTTP_CREATE_MAIN_CONF)
|
||||
static void *
|
||||
ndk_http_create_main_conf (ngx_conf_t *cf)
|
||||
{
|
||||
ndk_http_main_conf_t *mcf;
|
||||
|
||||
ndk_pcallocp_rce (mcf, cf->pool);
|
||||
|
||||
return mcf;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
|
||||
/*
|
||||
* 2010 (C) Marcus Clyne
|
||||
*/
|
||||
|
||||
|
||||
#ifndef NDK_H
|
||||
#define NDK_H
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_http.h>
|
||||
|
||||
|
||||
#define ndk_version 2015
|
||||
#define NDK_VERSION "0.2.15"
|
||||
|
||||
|
||||
#if (NGX_DEBUG)
|
||||
#ifndef NDK_DEBUG
|
||||
#define NDK_DEBUG 1
|
||||
#endif
|
||||
#else
|
||||
#ifndef NDK_DEBUG
|
||||
#define NDK_DEBUG 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if !(NDK)
|
||||
#error At least one module requires the Nginx Development Kit to be compiled with \
|
||||
the source (add --with-module=/path/to/devel/kit/src to configure command)
|
||||
#endif
|
||||
|
||||
#include <ndk_config.h>
|
||||
|
||||
|
||||
#if (NDK_HTTP_CREATE_MAIN_CONF)
|
||||
|
||||
#define ndk_http_conf_get_main_conf(cf) ngx_http_conf_get_module_main_conf (cf, ndk_http_module)
|
||||
#define ndk_http_get_main_conf(r) ngx_http_get_module_main_conf (r, ndk_http_module)
|
||||
|
||||
typedef struct {
|
||||
#if (NDK_UPSTREAM_LIST)
|
||||
ngx_array_t *upstreams;
|
||||
#endif
|
||||
} ndk_http_main_conf_t;
|
||||
|
||||
#endif /* NDK_HTTP_CREATE_MAIN_CONF */
|
||||
|
||||
#include <ndk_includes.h>
|
||||
|
||||
|
||||
extern ngx_module_t ndk_http_module;
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
ngx_int_t
|
||||
ndk_copy_chain_to_str (ngx_pool_t *pool, ngx_chain_t *in, ngx_str_t *str)
|
||||
{
|
||||
ngx_chain_t *cl;
|
||||
size_t len;
|
||||
u_char *p;
|
||||
ngx_buf_t *b;
|
||||
|
||||
len = 0;
|
||||
for (cl = in; cl; cl = cl->next)
|
||||
len += ngx_buf_size (cl->buf);
|
||||
|
||||
ndk_palloc_re (p, pool, len + 1);
|
||||
|
||||
str->data = p;
|
||||
str->len = len;
|
||||
|
||||
for (cl = in; cl; cl = cl->next) {
|
||||
|
||||
b = cl->buf;
|
||||
|
||||
if (ngx_buf_in_memory (b)) {
|
||||
p = ngx_cpymem (p, b->pos, b->last - b->pos);
|
||||
}
|
||||
}
|
||||
|
||||
*p = '\0';
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
ndk_copy_chain_to_charp (ngx_pool_t *pool, ngx_chain_t *in)
|
||||
{
|
||||
ngx_str_t str;
|
||||
|
||||
if (ndk_copy_chain_to_str (pool, in, &str) != NGX_OK)
|
||||
return NULL;
|
||||
|
||||
return (char *) str.data;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
|
||||
ngx_int_t ndk_copy_chain_to_str (ngx_pool_t *pool, ngx_chain_t *in, ngx_str_t *str);
|
||||
char * ndk_copy_chain_to_charp (ngx_pool_t *pool, ngx_chain_t *in);
|
||||
|
|
@ -0,0 +1,129 @@
|
|||
|
||||
|
||||
ndk_http_complex_path_value_t ndk_empty_http_complex_path_value = {{0,NULL},0};
|
||||
|
||||
|
||||
ngx_int_t
|
||||
ndk_http_complex_path_value_compile (ngx_conf_t *cf, ngx_http_complex_value_t *cv, ngx_str_t *value, ngx_uint_t prefix)
|
||||
{
|
||||
ngx_http_compile_complex_value_t ccv;
|
||||
|
||||
ngx_memzero (&ccv, sizeof(ngx_http_compile_complex_value_t));
|
||||
|
||||
ccv.cf = cf;
|
||||
ccv.value = value;
|
||||
ccv.complex_value = cv;
|
||||
|
||||
switch (prefix) {
|
||||
|
||||
case 1 :
|
||||
ccv.root_prefix = 1;
|
||||
break;
|
||||
|
||||
case 2 :
|
||||
ccv.conf_prefix = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
ndk_path_to_dir_safe (value, 1, 0);
|
||||
|
||||
if (!value->len)
|
||||
return NGX_OK;
|
||||
|
||||
return ngx_http_compile_complex_value (&ccv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ngx_array_t *
|
||||
ndk_http_complex_path_create_compile (ngx_conf_t *cf, ngx_str_t *path, ngx_uint_t prefix)
|
||||
{
|
||||
ndk_http_complex_path_elt_t *cpe;
|
||||
ngx_array_t *a;
|
||||
ngx_int_t n;
|
||||
u_char *m, *s, *e;
|
||||
ngx_str_t value;
|
||||
|
||||
n = ndk_strcntc (path, ':') + 1;
|
||||
|
||||
a = ngx_array_create (cf->pool, n, sizeof (ndk_http_complex_path_elt_t));
|
||||
if (a == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
s = path->data;
|
||||
e = s + path->len;
|
||||
|
||||
|
||||
while (s < e) {
|
||||
|
||||
m = s;
|
||||
|
||||
while (m < e && *m != ':') m++;
|
||||
|
||||
if (m == s) {
|
||||
s = m+1;
|
||||
continue;
|
||||
}
|
||||
|
||||
cpe = ngx_array_push (a);
|
||||
if (cpe == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (*s == '#') {
|
||||
s++;
|
||||
cpe->dynamic = 1;
|
||||
} else {
|
||||
cpe->dynamic = 0;
|
||||
}
|
||||
|
||||
value.data = s;
|
||||
value.len = m - s;
|
||||
|
||||
if (ndk_http_complex_path_value_compile (cf, &cpe->val, &value, prefix) == NGX_ERROR)
|
||||
return NULL;
|
||||
|
||||
s = m+1;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_http_complex_path_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
ngx_str_t *path;
|
||||
ngx_array_t *a;
|
||||
ngx_conf_post_t *post;
|
||||
ndk_http_complex_path_t *cp;
|
||||
|
||||
cp = (ndk_http_complex_path_t *) (p + cmd->offset);
|
||||
|
||||
if (cp->a != NGX_CONF_UNSET_PTR) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
path = cf->args->elts;
|
||||
path++;
|
||||
|
||||
cp->a = ndk_http_complex_path_create_compile (cf, path, cp->prefix);
|
||||
if (cp->a == NULL)
|
||||
/* TODO : log */
|
||||
return NGX_CONF_ERROR;
|
||||
|
||||
if (cmd->post) {
|
||||
post = cmd->post;
|
||||
return post->post_handler (cf, post, a);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
|
||||
typedef struct {
|
||||
ngx_array_t *a;
|
||||
ngx_uint_t prefix;
|
||||
} ndk_http_complex_path_t;
|
||||
|
||||
typedef struct {
|
||||
ngx_http_complex_value_t val;
|
||||
ngx_flag_t dynamic;
|
||||
} ndk_http_complex_path_elt_t;
|
||||
|
||||
typedef struct {
|
||||
ngx_str_t val;
|
||||
ngx_flag_t dynamic;
|
||||
} ndk_http_complex_path_value_t;
|
||||
|
||||
typedef struct {
|
||||
ndk_http_complex_path_value_t *elts;
|
||||
ngx_uint_t nelts;
|
||||
} ndk_http_complex_path_values_t;
|
||||
|
||||
|
||||
extern ndk_http_complex_path_value_t ndk_empty_http_complex_path_value;
|
||||
|
||||
|
||||
ngx_array_t * ndk_http_complex_path_create_compile (ngx_conf_t *cf, ngx_str_t *path, ngx_uint_t prefix);
|
||||
ngx_int_t ndk_http_complex_path_value_compile (ngx_conf_t *cf, ngx_http_complex_value_t *cv,
|
||||
ngx_str_t *value, ngx_uint_t prefix);
|
||||
char * ndk_conf_set_http_complex_path_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
|
@ -0,0 +1,192 @@
|
|||
|
||||
|
||||
|
||||
ngx_int_t
|
||||
ndk_http_complex_value_compile (ngx_conf_t *cf, ngx_http_complex_value_t *cv, ngx_str_t *value)
|
||||
{
|
||||
ngx_http_compile_complex_value_t ccv;
|
||||
|
||||
ngx_memzero (&ccv, sizeof(ngx_http_compile_complex_value_t));
|
||||
|
||||
ccv.cf = cf;
|
||||
ccv.value = value;
|
||||
ccv.complex_value = cv;
|
||||
|
||||
return ngx_http_compile_complex_value (&ccv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ngx_array_t *
|
||||
ndk_http_complex_value_array_create (ngx_conf_t *cf, char **s, ngx_int_t n)
|
||||
{
|
||||
ngx_int_t i;
|
||||
ngx_http_complex_value_t *cv;
|
||||
ngx_array_t *a;
|
||||
ngx_str_t value;
|
||||
|
||||
a = ngx_array_create (cf->pool, n, sizeof (ngx_http_complex_value_t));
|
||||
if (a == NULL)
|
||||
return NULL;
|
||||
|
||||
|
||||
for (i=0; i<n; i++, s++) {
|
||||
|
||||
cv = ngx_array_push (a);
|
||||
|
||||
value.data = (u_char *) *s;
|
||||
value.len = strlen (*s);
|
||||
|
||||
if (ndk_http_complex_value_compile (cf, cv, &value))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ngx_int_t
|
||||
ndk_http_complex_value_array_compile (ngx_conf_t *cf, ngx_array_t *a)
|
||||
{
|
||||
ngx_uint_t i;
|
||||
ngx_http_complex_value_t *cv;
|
||||
|
||||
if (a == NULL || a == NGX_CONF_UNSET_PTR) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
cv = a->elts;
|
||||
|
||||
for (i=0; i<a->nelts; i++, cv++) {
|
||||
|
||||
if (ndk_http_complex_value_compile (cf, cv, &cv->value))
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_http_complex_value_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
ngx_http_complex_value_t *cv;
|
||||
ngx_str_t *value;
|
||||
ngx_conf_post_t *post;
|
||||
|
||||
cv = (ngx_http_complex_value_t *) (p + cmd->offset);
|
||||
|
||||
if (cv->value.data) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
if (ndk_http_complex_value_compile (cf, cv, value + 1))
|
||||
return NGX_CONF_ERROR;
|
||||
|
||||
if (cmd->post) {
|
||||
post = cmd->post;
|
||||
return post->post_handler (cf, post, cv);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_http_complex_value_array_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
ngx_str_t *value;
|
||||
ngx_http_complex_value_t *cv;
|
||||
ngx_array_t **a;
|
||||
ngx_conf_post_t *post;
|
||||
ngx_uint_t i, alloc;
|
||||
|
||||
a = (ngx_array_t **) (p + cmd->offset);
|
||||
|
||||
if (*a == NULL || *a == NGX_CONF_UNSET_PTR) {
|
||||
|
||||
alloc = cf->args->nelts > 4 ? cf->args->nelts : 4;
|
||||
|
||||
*a = ngx_array_create (cf->pool, alloc, sizeof (ngx_http_complex_value_t));
|
||||
if (*a == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
for (i=1; i<cf->args->nelts; i++) {
|
||||
|
||||
cv = ngx_array_push (*a);
|
||||
if (cv == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
if (ndk_http_complex_value_compile (cf, cv, &value[i]) == NGX_ERROR)
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
|
||||
if (cmd->post) {
|
||||
post = cmd->post;
|
||||
return post->post_handler (cf, post, a);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_http_complex_keyval_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
ngx_str_t *value;
|
||||
ndk_http_complex_keyval_t *ckv;
|
||||
ngx_array_t **a;
|
||||
ngx_conf_post_t *post;
|
||||
ngx_int_t alloc;
|
||||
|
||||
a = (ngx_array_t **) (p + cmd->offset);
|
||||
|
||||
if (*a == NULL || *a == NGX_CONF_UNSET_PTR) {
|
||||
|
||||
alloc = cf->args->nelts > 4 ? cf->args->nelts : 4;
|
||||
|
||||
*a = ngx_array_create (cf->pool, alloc, sizeof (ndk_http_complex_keyval_t));
|
||||
if (*a == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
ckv = ngx_array_push (*a);
|
||||
if (ckv == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
ckv->key = value[1];
|
||||
|
||||
if (ndk_http_complex_value_compile (cf, &ckv->value, &value[2]) == NGX_ERROR)
|
||||
return NGX_CONF_ERROR;
|
||||
|
||||
if (cmd->post) {
|
||||
post = cmd->post;
|
||||
return post->post_handler (cf, post, a);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
/* TODO : complex keyval1 */
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
|
||||
typedef struct {
|
||||
ngx_str_t key;
|
||||
ngx_http_complex_value_t value;
|
||||
} ndk_http_complex_keyval_t;
|
||||
|
||||
|
||||
|
||||
/* create/compile functions */
|
||||
|
||||
ngx_int_t ndk_http_complex_value_compile (ngx_conf_t *cf, ngx_http_complex_value_t *cv, ngx_str_t *value);
|
||||
ngx_array_t * ndk_http_complex_value_array_create (ngx_conf_t *cf, char **s, ngx_int_t n);
|
||||
ngx_int_t ndk_http_complex_value_array_compile (ngx_conf_t *cf, ngx_array_t *a);
|
||||
|
||||
|
||||
/* conf set slot functions */
|
||||
|
||||
char * ndk_conf_set_http_complex_keyval_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
char * ndk_conf_set_http_complex_value_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
char * ndk_conf_set_http_complex_value_array_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
|
@ -0,0 +1,396 @@
|
|||
|
||||
|
||||
/* NOTE : you will find other conf_set functions in the following files :
|
||||
*
|
||||
* complex_value.c
|
||||
* encoding.c
|
||||
* path.c
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_true_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
ngx_flag_t *fp;
|
||||
ngx_conf_post_t *post;
|
||||
|
||||
fp = (ngx_flag_t*) (p + cmd->offset);
|
||||
|
||||
if (*fp != NGX_CONF_UNSET) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
*fp = 1;
|
||||
|
||||
if (cmd->post) {
|
||||
post = cmd->post;
|
||||
return post->post_handler (cf, post, fp);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_false_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
ngx_flag_t *fp;
|
||||
ngx_conf_post_t *post;
|
||||
|
||||
fp = (ngx_flag_t*) (p + cmd->offset);
|
||||
|
||||
if (*fp != NGX_CONF_UNSET) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
*fp = 0;
|
||||
|
||||
if (cmd->post) {
|
||||
post = cmd->post;
|
||||
return post->post_handler (cf, post, fp);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_ptr_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
void **ptr;
|
||||
|
||||
ptr = (void**) (p + cmd->offset);
|
||||
|
||||
if (*ptr != NGX_CONF_UNSET_PTR) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
*ptr = cmd->post;
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_null_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
void **pp;
|
||||
ngx_conf_post_t *post;
|
||||
|
||||
pp = (void **) (p + cmd->offset);
|
||||
|
||||
if (*pp != NGX_CONF_UNSET_PTR) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
*pp = NULL;
|
||||
|
||||
if (cmd->post) {
|
||||
post = cmd->post;
|
||||
return post->post_handler (cf, post, pp);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_num64_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
int64_t *np;
|
||||
ngx_str_t *value;
|
||||
ngx_conf_post_t *post;
|
||||
|
||||
|
||||
np = (int64_t *) (p + cmd->offset);
|
||||
|
||||
if (*np != NGX_CONF_UNSET) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
value = cf->args->elts;
|
||||
*np = ndk_atoi64 (value[1].data, value[1].len);
|
||||
if (*np == NGX_ERROR) {
|
||||
return "invalid number";
|
||||
}
|
||||
|
||||
if (cmd->post) {
|
||||
post = cmd->post;
|
||||
return post->post_handler(cf, post, np);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_str_array_multi_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
ngx_str_t *value, *s;
|
||||
ngx_array_t **a;
|
||||
ngx_conf_post_t *post;
|
||||
ngx_uint_t i;
|
||||
|
||||
a = (ngx_array_t **) (p + cmd->offset);
|
||||
|
||||
if (*a == NGX_CONF_UNSET_PTR) {
|
||||
*a = ngx_array_create(cf->pool, 4, sizeof(ngx_str_t));
|
||||
if (*a == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
s = NULL;
|
||||
|
||||
for (i=cf->args->nelts-1; i; i--) {
|
||||
|
||||
s = ngx_array_push(*a);
|
||||
if (s == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
*s = value[i];
|
||||
}
|
||||
|
||||
if (cmd->post) {
|
||||
post = cmd->post;
|
||||
return post->post_handler(cf, post, s);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_keyval1_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
ngx_str_t *value;
|
||||
ngx_keyval_t *kv;
|
||||
ngx_conf_post_t *post;
|
||||
|
||||
kv = (ngx_keyval_t *) (p + cmd->offset);
|
||||
|
||||
if (kv->key.data)
|
||||
return "is duplicate";
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
kv->key = value[1];
|
||||
kv->value = value[2];
|
||||
|
||||
if (cmd->post) {
|
||||
post = cmd->post;
|
||||
return post->post_handler (cf, post, kv);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_num_flag_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
ngx_int_t *np;
|
||||
ngx_str_t *value;
|
||||
ngx_conf_post_t *post;
|
||||
|
||||
np = (ngx_int_t *) (p + cmd->offset);
|
||||
|
||||
if (*np != NGX_CONF_UNSET) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
if (ngx_strcasecmp (value[1].data, (u_char *) "on") == 0) {
|
||||
*np = NDK_CONF_SET_TRUE;
|
||||
|
||||
} else if (ngx_strcasecmp (value[1].data, (u_char *) "off") == 0) {
|
||||
*np = NDK_CONF_SET_FALSE;
|
||||
|
||||
} else {
|
||||
*np = ngx_atoi (value[1].data, value[1].len);
|
||||
if (*np == NGX_ERROR) {
|
||||
return "invalid number and not 'on'/'off'";
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd->post) {
|
||||
post = cmd->post;
|
||||
return post->post_handler (cf, post, np);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_sec_flag_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
time_t *tp;
|
||||
ngx_str_t *value;
|
||||
ngx_conf_post_t *post;
|
||||
|
||||
tp = (time_t *) (p + cmd->offset);
|
||||
|
||||
if (*tp != NGX_CONF_UNSET) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
if (ngx_strcasecmp (value[1].data, (u_char *) "on") == 0) {
|
||||
*tp = NDK_CONF_SET_TRUE;
|
||||
|
||||
} else if (ngx_strcasecmp (value[1].data, (u_char *) "off") == 0) {
|
||||
*tp = NDK_CONF_SET_FALSE;
|
||||
|
||||
} else {
|
||||
*tp = ngx_parse_time (&value[1], 1);
|
||||
if (*tp == NGX_ERROR) {
|
||||
return "has an invalid time and not 'on'/'off'";
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd->post) {
|
||||
post = cmd->post;
|
||||
return post->post_handler (cf, post, tp);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ngx_http_conf_ctx_t *
|
||||
ndk_conf_create_http_location (ngx_conf_t *cf)
|
||||
{
|
||||
ngx_http_conf_ctx_t *ctx, *pctx;
|
||||
void *mconf;
|
||||
ngx_http_core_loc_conf_t *clcf, *pclcf;
|
||||
ngx_uint_t i;
|
||||
ngx_http_module_t *module;
|
||||
|
||||
ndk_pcallocp_rce (ctx, cf->pool);
|
||||
|
||||
pctx = cf->ctx;
|
||||
ctx->main_conf = pctx->main_conf;
|
||||
ctx->srv_conf = pctx->srv_conf;
|
||||
|
||||
ndk_pcalloc_rce (ctx->loc_conf, cf->pool, sizeof(void *) * ngx_http_max_module);
|
||||
|
||||
|
||||
for (i = 0; ngx_modules[i]; i++) {
|
||||
if (ngx_modules[i]->type != NGX_HTTP_MODULE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
module = ngx_modules[i]->ctx;
|
||||
|
||||
if (module->create_loc_conf) {
|
||||
|
||||
mconf = module->create_loc_conf(cf);
|
||||
if (mconf == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
ctx->loc_conf[ngx_modules[i]->ctx_index] = mconf;
|
||||
}
|
||||
}
|
||||
|
||||
pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
|
||||
|
||||
clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
|
||||
clcf->loc_conf = ctx->loc_conf;
|
||||
clcf->name = pclcf->name;
|
||||
clcf->noname = 1;
|
||||
|
||||
if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
ngx_http_conf_ctx_t *
|
||||
ngx_conf_create_http_named_location (ngx_conf_t *cf, ngx_str_t *name)
|
||||
{
|
||||
ngx_http_conf_ctx_t *ctx;
|
||||
ngx_http_core_loc_conf_t *clcf;
|
||||
|
||||
ctx = ndk_conf_create_http_location (cf);
|
||||
if (ctx == NGX_CONF_ERROR)
|
||||
return NGX_CONF_ERROR;
|
||||
|
||||
clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
|
||||
|
||||
/* in case the developer forgets to add '@' at the beginning of the named location */
|
||||
|
||||
if (name->data[0] != '@' && ndk_catstrf (cf->pool, name, "sS", "@", name) == NULL)
|
||||
return NGX_CONF_ERROR;
|
||||
|
||||
clcf->name = *name; /* TODO : copy? */
|
||||
clcf->noname = 0;
|
||||
clcf->named = 1;
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
ngx_int_t
|
||||
ndk_replace_command (ngx_command_t *new_cmd, ngx_uint_t module_type)
|
||||
{
|
||||
ngx_uint_t i;
|
||||
ngx_command_t *cmd;
|
||||
|
||||
for (i = 0; ngx_modules[i]; i++) {
|
||||
|
||||
if (ngx_modules[i]->type != module_type)
|
||||
continue;
|
||||
|
||||
cmd = ngx_modules[i]->commands;
|
||||
if (cmd == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for ( /* void */ ; cmd->name.len; cmd++) {
|
||||
|
||||
if (ndk_cmpstr (&new_cmd->name, &cmd->name) == 0) {
|
||||
|
||||
ndk_memcpyp (cmd, new_cmd);
|
||||
return NGX_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NGX_DECLINED;
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
|
||||
|
||||
/* conf set functions */
|
||||
|
||||
char * ndk_conf_set_true_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
char * ndk_conf_set_false_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
char * ndk_conf_set_full_path_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
char * ndk_conf_set_ptr_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
char * ndk_conf_set_null_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
char * ndk_conf_set_str_array_multi_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
char * ndk_conf_set_keyval1_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
char * ndk_conf_set_num_flag (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
char * ndk_conf_set_num64_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
char * ndk_conf_set_sec_flag_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
|
||||
ngx_http_conf_ctx_t * ndk_conf_create_http_location (ngx_conf_t *cf);
|
||||
ngx_http_conf_ctx_t * ngx_conf_create_http_named_location (ngx_conf_t *cf, ngx_str_t *name);
|
||||
|
||||
ngx_int_t ndk_replace_command (ngx_command_t *new_cmd, ngx_uint_t module_type);
|
||||
|
||||
|
||||
/* values for conf_set_xxx_flag */
|
||||
|
||||
#define NDK_CONF_SET_TRUE -2
|
||||
#define NDK_CONF_SET_FALSE -3
|
||||
|
||||
|
||||
/* wrappers for utility macros */
|
||||
|
||||
#define ndk_conf_set_bitmask_slot ngx_conf_set_bitmask_slot
|
||||
#define ndk_conf_set_bufs_slot ngx_conf_set_bufs_slot
|
||||
#define ndk_conf_set_enum_slot ngx_conf_set_enum_slot
|
||||
#define ndk_conf_set_flag_slot ngx_conf_set_flag_slot
|
||||
#define ndk_conf_set_keyval_slot ngx_conf_set_keyval_slot
|
||||
#define ndk_conf_set_msec_slot ngx_conf_set_msec_slot
|
||||
#define ndk_conf_set_num_slot ngx_conf_set_num_slot
|
||||
#define ndk_conf_set_off_slot ngx_conf_set_off_slot
|
||||
#define ndk_conf_set_sec_slot ngx_conf_set_sec_slot
|
||||
#define ndk_conf_set_size_slot ngx_conf_set_size_slot
|
||||
#define ndk_conf_set_str_slot ngx_conf_set_str_slot
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
|
||||
#if (NGX_DEBUG)
|
||||
|
||||
void
|
||||
ndk_debug_helper (const char *func, const char *fmt, ...)
|
||||
{
|
||||
size_t len, flen, tlen;
|
||||
char *s, *p, *e;
|
||||
|
||||
/* check to see if the format is empty */
|
||||
|
||||
flen = strlen (fmt);
|
||||
|
||||
/* build func name */
|
||||
|
||||
len = strlen (func);
|
||||
|
||||
if (flen == 0)
|
||||
tlen = len + 1;
|
||||
else
|
||||
|
||||
char func_name [len + flen + 1];
|
||||
|
||||
s = func_name;
|
||||
e = s + len;
|
||||
|
||||
memcpy (s, func, len);
|
||||
|
||||
/* remove initial ngx_ */
|
||||
|
||||
if (strncmp (s, "ngx_", 4) == 0)
|
||||
s += 4;
|
||||
|
||||
/* replace '_' with ' ' */
|
||||
|
||||
for (p=s; p<e; p++) {
|
||||
if (*p == '_')
|
||||
*p = ' ';
|
||||
}
|
||||
|
||||
vfprintf (stderr, const char *format, va_list ap)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ndk_debug_request_helper (const char *func, ngx_http_request_t *r)
|
||||
{
|
||||
ngx_http_posted_request_t *pr;
|
||||
|
||||
/* TODO : improve the format */
|
||||
|
||||
fprintf (stderr, "%s %.*s %.*s?%.*s c:%d m:%p r:%p ar:%p pr:%p",
|
||||
func,
|
||||
(int) r->method_name.len, r->method_name.data,
|
||||
(int) r->uri.len, r->uri.data,
|
||||
(int) r->args.len, r->args.data,
|
||||
0/*(int) r->main->count*/, r->main,
|
||||
r, r->connection->data, r->parent);
|
||||
|
||||
if (r->posted_requests) {
|
||||
fprintf(stderr, " posted:");
|
||||
|
||||
for (pr = r->posted_requests; pr; pr = pr->next) {
|
||||
fprintf (stderr, "%p,", pr);
|
||||
}
|
||||
}
|
||||
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,171 @@
|
|||
#ifndef NDK_DEBUG_H
|
||||
#define NDK_DEBUG_H
|
||||
|
||||
|
||||
/* TODO : use the Nginx printf function */
|
||||
|
||||
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_http.h>
|
||||
|
||||
/* TODO
|
||||
- andk_debug variety of debugging formats
|
||||
- global include file for all debugging - can pass declaration to cflags for the option
|
||||
*/
|
||||
|
||||
|
||||
#if (NDK_DEBUG)
|
||||
|
||||
#if (NGX_HAVE_VARIADIC_MACROS)
|
||||
|
||||
#define ndk_debug(...) ndk_debug_helper (__func__,__VA_ARGS__)
|
||||
|
||||
#define ndk_debug_helper(func,...) \
|
||||
fprintf(stderr, "%-60s", func); \
|
||||
fprintf(stderr, (const char *)__VA_ARGS__); \
|
||||
fprintf(stderr,"\n");
|
||||
/*fprintf(stderr, " at %s line %d.\n", __FILE__, __LINE__)*/
|
||||
|
||||
#else
|
||||
|
||||
/* NOTE : these includes might not be necessary since they're probably included with the core */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
static void ndk_debug (const char * fmt, ...) {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if NDK_DEBUG > 1
|
||||
|
||||
#define ndk_debug_request() ndk_debug_request_helper(r, __func__)
|
||||
|
||||
static ngx_inline void
|
||||
ndk_debug_request_helper (ngx_http_request_t *r, const char *func)
|
||||
{
|
||||
ngx_http_posted_request_t *pr;
|
||||
|
||||
/* TODO : improve the format */
|
||||
|
||||
fprintf (stderr, "%s %.*s %.*s?%.*s c:%d m:%p r:%p ar:%p pr:%p",
|
||||
func,
|
||||
(int) r->method_name.len, r->method_name.data,
|
||||
(int) r->uri.len, r->uri.data,
|
||||
(int) r->args.len, r->args.data,
|
||||
0/*(int) r->main->count*/, r->main,
|
||||
r, r->connection->data, r->parent);
|
||||
|
||||
if (r->posted_requests) {
|
||||
fprintf(stderr, " posted:");
|
||||
|
||||
for (pr = r->posted_requests; pr; pr = pr->next) {
|
||||
fprintf (stderr, "%p,", pr);
|
||||
}
|
||||
}
|
||||
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#define ndk_debug_request()
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
static ngx_inline void
|
||||
ndk_debug_print_posted_requests (ngx_http_request_t *r)
|
||||
{
|
||||
ngx_http_posted_request_t *pr;
|
||||
|
||||
ndk_request_log_debug_http (r, "ndk debug - http posted requests");
|
||||
|
||||
for (pr = r->main->posted_requests; pr; pr = pr->next) {
|
||||
|
||||
if (!pr->request)
|
||||
continue;
|
||||
|
||||
ndk_request_log_debug_http (r, "ndk debug - http posted request:%V", &pr->request->uri);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define ndk_debug_http_conf_location(cf) ndk_debug_http_conf_location_helper (cf, __func__)
|
||||
|
||||
static ngx_inline void
|
||||
ndk_debug_http_conf_location_helper (ngx_conf_t *cf, const char *func)
|
||||
{
|
||||
ngx_http_core_loc_conf_t *lcf;
|
||||
|
||||
lcf = ngx_http_conf_get_module_loc_conf (cf, ngx_http_core_module);
|
||||
|
||||
ndk_debug_helper (func, "[%s]", lcf->name.data);
|
||||
}
|
||||
|
||||
/*
|
||||
static void
|
||||
ndk_debug_log_chain (ngx_log_t *log, ngx_chain_t *cl)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
#else
|
||||
|
||||
#if (NGX_HAVE_VARIADIC_MACROS)
|
||||
|
||||
#define ndk_debug(...)
|
||||
#define ndk_debug_request()
|
||||
|
||||
#else
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
static void ndk_debug (const char * fmt, ...) {
|
||||
}
|
||||
|
||||
static void ndk_debug_request() {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#define ndk_debug_http_conf_location(cf)
|
||||
|
||||
#endif
|
||||
|
||||
#if (NDK_DEBUG)
|
||||
|
||||
#define ndk_debug_check_read_event_handler(r) \
|
||||
\
|
||||
ndk_debug("r->read_event_handler = %s", \
|
||||
r->read_event_handler == ngx_http_block_reading ? \
|
||||
"ngx_http_block_reading" : \
|
||||
r->read_event_handler == ngx_http_test_reading ? \
|
||||
"ngx_http_test_reading" : \
|
||||
r->read_event_handler == ngx_http_request_empty_handler ? \
|
||||
"ngx_http_request_empty_handler" : "UNKNOWN")
|
||||
|
||||
#define ndk_debug_check_write_event_handler(r) \
|
||||
\
|
||||
ndk_debug ("r->write_event_handler = %s", \
|
||||
r->write_event_handler == ngx_http_handler ? \
|
||||
"ngx_http_handler" : \
|
||||
r->write_event_handler == ngx_http_core_run_phases ? \
|
||||
"ngx_http_core_run_phases" : \
|
||||
r->write_event_handler == ngx_http_request_empty_handler ? \
|
||||
"ngx_http_request_empty_handler" : "UNKNOWN")
|
||||
|
||||
#else
|
||||
|
||||
#define ndk_debug_check_read_event_handler(r)
|
||||
#define ndk_debug_check_write_event_handler(r)
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* NDK_DEBUG_H */
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_encoding_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
ndk_encoding_t *ep;
|
||||
ngx_str_t *value;
|
||||
size_t len;
|
||||
iconv_t ic;
|
||||
|
||||
ep = (ndk_encoding_t *) (p + cmd->offset);
|
||||
if (ep->from && ep->to)
|
||||
return "is duplicate";
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
|
||||
if (ep->from) {
|
||||
|
||||
ep->to = (char *) value[1].data;
|
||||
len = strlen (ep->from);
|
||||
|
||||
} else if (ep->to) {
|
||||
|
||||
ep->from = (char *) value[1].data;
|
||||
len = strlen (ep->to);
|
||||
|
||||
} else {
|
||||
return "has no base encoding";
|
||||
}
|
||||
|
||||
|
||||
if (len == value[1].len && !strncasecmp (ep->to, ep->from, len)) {
|
||||
|
||||
ngx_log_error (NGX_LOG_WARN, cf->log, 0,
|
||||
"\"%V\" '%V' encoding is ignored (no conversion)", &value[0], &value[1]);
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
ic = iconv_open (ep->to, ep->from);
|
||||
if (ic == (iconv_t)-1)
|
||||
return "has an invalid encoding";
|
||||
|
||||
|
||||
if (iconv_close (ic)) {
|
||||
ngx_log_error (NGX_LOG_EMERG, cf->log, errno, "iconv_close()");
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
|
||||
#include <iconv.h>
|
||||
|
||||
typedef struct {
|
||||
char *from;
|
||||
char *to;
|
||||
} ndk_encoding_t;
|
||||
|
||||
|
||||
char * ndk_conf_set_encoding_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
|
||||
#include <ndk_hash.h>
|
||||
|
||||
|
||||
|
||||
/* openssl hashes */
|
||||
|
||||
#define NDK_OPENSSL_HASH(type,ctxt_type,upper) \
|
||||
u_char md [ctxt_type ## _DIGEST_LENGTH]; \
|
||||
ctxt_type ##_CTX c; \
|
||||
\
|
||||
type ## _Init (&c); \
|
||||
type ## _Update (&c, data, len); \
|
||||
type ## _Final (md, &c); \
|
||||
\
|
||||
ndk_hex_dump (p, (u_char *) md, ctxt_type ## _DIGEST_LENGTH); \
|
||||
if (upper) { \
|
||||
ndk_strtoupper (p, (ctxt_type ## _DIGEST_LENGTH) *2); \
|
||||
}
|
||||
|
||||
|
||||
#ifdef NDK_MD5
|
||||
|
||||
void
|
||||
ndk_md5_hash (u_char *p, char *data, size_t len)
|
||||
{
|
||||
NDK_OPENSSL_HASH (MD5, MD5, 0);
|
||||
}
|
||||
|
||||
void
|
||||
ndk_md5_hash_upper (u_char *p, char *data, size_t len)
|
||||
{
|
||||
NDK_OPENSSL_HASH (MD5, MD5, 1);
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifdef NDK_SHA1
|
||||
|
||||
void
|
||||
ndk_sha1_hash (u_char *p, char *data, size_t len)
|
||||
{
|
||||
NDK_OPENSSL_HASH (SHA1, SHA, 0);
|
||||
}
|
||||
|
||||
void
|
||||
ndk_sha1_hash_upper (u_char *p, char *data, size_t len)
|
||||
{
|
||||
NDK_OPENSSL_HASH (SHA1, SHA, 1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* non-openssl hashes */
|
||||
|
||||
#ifdef NDK_MURMUR2
|
||||
|
||||
#include "hash/murmurhash2.c"
|
||||
|
||||
void
|
||||
ndk_murmur2_hash (u_char *p, char *data, size_t len)
|
||||
{
|
||||
uint32_t hash;
|
||||
|
||||
hash = MurmurHash2 (data, len, 47);
|
||||
|
||||
ndk_hex_dump (p, (u_char*) &hash, 4);
|
||||
}
|
||||
|
||||
void
|
||||
ndk_murmur2_hash_upper (u_char *p, char *data, size_t len)
|
||||
{
|
||||
uint32_t hash;
|
||||
|
||||
hash = MurmurHash2 (data, len, 47);
|
||||
|
||||
ndk_hex_dump (p, (u_char*) &hash, 4);
|
||||
ndk_strtoupper (p, 8);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,45 @@
|
|||
|
||||
#ifndef NDK_HASH_H
|
||||
#define NDK_HASH_H
|
||||
|
||||
#ifdef NDK_HASH_ALL
|
||||
|
||||
#ifndef NDK_MD5
|
||||
#define NDK_MD5
|
||||
#endif
|
||||
|
||||
#ifndef NDK_MURMUR2
|
||||
#define NDK_MURMUR2
|
||||
#endif
|
||||
|
||||
#ifndef NDK_SHA1
|
||||
#define NDK_SHA1
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
typedef void (*ndk_hash_pt) (u_char *p, char *data, size_t len);
|
||||
|
||||
|
||||
#ifdef NDK_MD5
|
||||
#include <ngx_md5.h>
|
||||
void ndk_md5_hash (u_char *p, char *data, size_t len);
|
||||
void ndk_md5_hash_upper (u_char *p, char *data, size_t len);
|
||||
#endif
|
||||
|
||||
#ifdef NDK_MURMUR2
|
||||
#define MURMURHASH2_DIGEST_LENGTH 4
|
||||
void ndk_murmur2_hash (u_char *p, char *data, size_t len);
|
||||
void ndk_murmur2_hash_upper (u_char *p, char *data, size_t len);
|
||||
#endif
|
||||
|
||||
#ifdef NDK_SHA1
|
||||
#include <ngx_sha1.h>
|
||||
void ndk_sha1_hash (u_char *p, char *data, size_t len);
|
||||
void ndk_sha1_hash_upper (u_char *p, char *data, size_t len);
|
||||
#endif
|
||||
|
||||
#endif /* NDK_HASH_H */
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
|
||||
ngx_uint_t
|
||||
ndk_http_count_phase_handlers (ngx_http_core_main_conf_t *cmcf)
|
||||
{
|
||||
ngx_http_phase_handler_t *ph;
|
||||
ngx_uint_t i;
|
||||
|
||||
ph = cmcf->phase_engine.handlers;
|
||||
|
||||
for (i=0; ph[i].checker; i++) /* void */;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
ngx_uint_t
|
||||
ndk_http_parse_request_method (ngx_str_t *m)
|
||||
{
|
||||
switch (m->len) {
|
||||
|
||||
case 3:
|
||||
|
||||
#if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED)
|
||||
{
|
||||
u_char t[4];
|
||||
|
||||
ngx_memcpy (t, m->data, 3);
|
||||
t[3] = ' ';
|
||||
|
||||
if (ndk_str3_cmp (t, 'G', 'E', 'T', ' ')) {
|
||||
return NGX_HTTP_GET;
|
||||
}
|
||||
|
||||
if (ndk_str3_cmp (t, 'P', 'U', 'T', ' ')) {
|
||||
return NGX_HTTP_PUT;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
if (ndk_str3_cmp (m->data, 'G', 'E', 'T', ' ')) {
|
||||
return NGX_HTTP_GET;
|
||||
}
|
||||
|
||||
if (ndk_str3_cmp (m->data, 'P', 'U', 'T', ' ')) {
|
||||
return NGX_HTTP_PUT;
|
||||
}
|
||||
|
||||
#endif
|
||||
break;
|
||||
|
||||
case 4:
|
||||
|
||||
if (m->data[1] == 'O') {
|
||||
|
||||
if (ndk_str3Ocmp (m->data, 'P', 'O', 'S', 'T')) {
|
||||
return NGX_HTTP_POST;
|
||||
}
|
||||
|
||||
if (ndk_str3Ocmp (m->data, 'C', 'O', 'P', 'Y')) {
|
||||
return NGX_HTTP_COPY;
|
||||
}
|
||||
|
||||
if (ndk_str3Ocmp (m->data, 'M', 'O', 'V', 'E')) {
|
||||
return NGX_HTTP_MOVE;
|
||||
}
|
||||
|
||||
if (ndk_str3Ocmp (m->data, 'L', 'O', 'C', 'K')) {
|
||||
return NGX_HTTP_LOCK;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (ndk_str4cmp (m->data, 'H', 'E', 'A', 'D')) {
|
||||
return NGX_HTTP_HEAD;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 5:
|
||||
|
||||
if (ndk_str5cmp (m->data, 'M', 'K', 'C', 'O', 'L')) {
|
||||
return NGX_HTTP_MKCOL;
|
||||
}
|
||||
|
||||
if (ndk_str5cmp (m->data, 'P', 'A', 'T', 'C', 'H')) {
|
||||
return NGX_HTTP_PATCH;
|
||||
}
|
||||
|
||||
if (ndk_str5cmp (m->data, 'T', 'R', 'A', 'C', 'E')) {
|
||||
return NGX_HTTP_TRACE;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 6:
|
||||
|
||||
if (ndk_str6cmp (m->data, 'D', 'E', 'L', 'E', 'T', 'E')) {
|
||||
return NGX_HTTP_DELETE;
|
||||
}
|
||||
|
||||
if (ndk_str6cmp (m->data, 'U', 'N', 'L', 'O', 'C', 'K')) {
|
||||
return NGX_HTTP_UNLOCK;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 7:
|
||||
|
||||
if (ndk_str7_cmp (m->data, 'O', 'P', 'T', 'I', 'O', 'N', 'S', ' '))
|
||||
{
|
||||
return NGX_HTTP_OPTIONS;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 8:
|
||||
|
||||
if (ndk_str8cmp (m->data, 'P', 'R', 'O', 'P', 'F', 'I', 'N', 'D'))
|
||||
{
|
||||
return NGX_HTTP_PROPFIND;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 9:
|
||||
|
||||
if (ndk_str9cmp (m->data, 'P', 'R', 'O', 'P', 'P', 'A', 'T', 'C', 'H'))
|
||||
{
|
||||
return NGX_HTTP_PROPPATCH;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
ngx_uint_t ndk_http_count_phase_handlers (ngx_http_core_main_conf_t *cmcf);
|
||||
ngx_uint_t ndk_http_parse_request_method (ngx_str_t *m);
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
|
||||
/* TODO : organize and add */
|
||||
/* TODO : check - should it be r->main? */
|
||||
|
||||
#define ndk_http_uri(r) (r)->uri
|
||||
#define ndk_http_request_uri(r) (r)->unparsed_uri
|
||||
|
||||
#define ndk_http_header_in(r,name) ((r)->headers_in.name ? &(r)->headers_in.name->value : NULL)
|
||||
#define ndk_http_header_out(r,name) ((r)->headers_out.name ? &(r)->headers_out.name->value : NULL)
|
||||
|
||||
#define ndk_http_host_header(r) ndk_http_header_in (r, host)
|
||||
#define ndk_http_connection_header(r) ndk_http_header_in (r, connection)
|
||||
#define ndk_http_if_modified_since_header(r) ndk_http_header_in (r, if_modified_since)
|
||||
#define ndk_http_user_agent_header(r) ndk_http_header_in (r, user_agent)
|
||||
#define ndk_http_referer_header(r) ndk_http_header_in (r, referer)
|
||||
#define ndk_http_content_length_header(r) ndk_http_header_in (r, content_length)
|
||||
#define ndk_http_content_type_header(r) ndk_http_header_in (r, content_type)
|
||||
#define ndk_http_range_header(r) ndk_http_header_in (r, range)
|
||||
#define ndk_http_if_range_header(r) ndk_http_header_in (r, if_range)
|
||||
#define ndk_http_transfer_encoding_header(r) ndk_http_header_in (r, transfer_encoding)
|
||||
#define ndk_http_expect_header(r) ndk_http_header_in (r, expect)
|
||||
#define ndk_http_accept_encoding_header(r) ndk_http_header_in (r, accept_encoding)
|
||||
#define ndk_http_via_header(r) ndk_http_header_in (r, via)
|
||||
#define ndk_http_authorization_header(r) ndk_http_header_in (r, authorization)
|
||||
#define ndk_http_keep_alive_header(r) ndk_http_header_in (r, keep_alive)
|
||||
#define ndk_http_x_forwarded_for_header(r) ndk_http_header_in (r, x_forwarded_for)
|
||||
#define ndk_http_x_real_ip_header(r) ndk_http_header_in (r, x_real_ip)
|
||||
#define ndk_http_accept_header(r) ndk_http_header_in (r, accept)
|
||||
#define ndk_http_accept_language_header(r) ndk_http_header_in (r, accept_language)
|
||||
#define ndk_http_depth_header(r) ndk_http_header_in (r, depth)
|
||||
#define ndk_http_destination_header(r) ndk_http_header_in (r, destination)
|
||||
#define ndk_http_overwrite_header(r) ndk_http_header_in (r, overwrite)
|
||||
#define ndk_http_date_header(r) ndk_http_header_in (r, date)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
|
||||
/* TODO : the required functions if the compiler does not have variadic macros */
|
|
@ -0,0 +1,165 @@
|
|||
|
||||
/* TODO : fix the conf_log macros */
|
||||
|
||||
#define NGX_LOG_DEBUG_SCRIPT NGX_LOG_DEBUG_HTTP /* TODO : add new section to log/conf directives */
|
||||
|
||||
#define ndk_conf_to_log(cf) ((cf)->log)
|
||||
|
||||
#ifndef ndk_request_to_log
|
||||
#define ndk_request_to_log(r) ((r)->connection->log)
|
||||
#endif
|
||||
|
||||
|
||||
/*********************************/
|
||||
|
||||
#if (NGX_HAVE_C99_VARIADIC_MACROS)
|
||||
|
||||
#define ndk_log_stderr(log,...) ngx_log_error (NGX_LOG_STDERR, log, 0, __VA_ARGS__)
|
||||
#define ndk_log_emerg(log,...) ngx_log_error (NGX_LOG_EMERG, log, 0, __VA_ARGS__)
|
||||
#define ndk_log_alert(log,...) ngx_log_error (NGX_LOG_ALERT, log, 0, __VA_ARGS__)
|
||||
#define ndk_log_crit(log,...) ngx_log_error (NGX_LOG_CRIT, log, 0, __VA_ARGS__)
|
||||
#define ndk_log_err(log,...) ngx_log_error (NGX_LOG_ERR, log, 0, __VA_ARGS__)
|
||||
#define ndk_log_warning(log,...) ngx_log_error (NGX_LOG_WARN, log, 0, __VA_ARGS__)
|
||||
#define ndk_log_notice(log,...) ngx_log_error (NGX_LOG_NOTICE, log, 0, __VA_ARGS__)
|
||||
#define ndk_log_info(log,...) ngx_log_error (NGX_LOG_INFO, log, 0, __VA_ARGS__)
|
||||
|
||||
#define ndk_conf_log_stderr(cf,...) ngx_conf_log_error (NGX_LOG_STDERR, cf, 0, __VA_ARGS__)
|
||||
#define ndk_conf_log_emerg(cf,...) ngx_conf_log_error (NGX_LOG_EMERG, cf, 0, __VA_ARGS__)
|
||||
#define ndk_conf_log_alert(cf,...) ngx_conf_log_error (NGX_LOG_ALERT, cf, 0, __VA_ARGS__)
|
||||
#define ndk_conf_log_crit(cf,...) ngx_conf_log_error (NGX_LOG_CRIT, cf, 0, __VA_ARGS__)
|
||||
#define ndk_conf_log_err(cf,...) ngx_conf_log_error (NGX_LOG_ERR, cf, 0, __VA_ARGS__)
|
||||
#define ndk_conf_log_warning(cf,...) ngx_conf_log_error (NGX_LOG_WARN, cf, 0, __VA_ARGS__)
|
||||
#define ndk_conf_log_notice(cf,...) ngx_conf_log_error (NGX_LOG_NOTICE, cf, 0, __VA_ARGS__)
|
||||
#define ndk_conf_log_info(cf,...) ngx_conf_log_error (NGX_LOG_INFO, cf, 0, __VA_ARGS__)
|
||||
|
||||
#define ndk_request_log_stderr(r,...) ndk_log_stderr (ndk_request_to_log(r), __VA_ARGS__)
|
||||
#define ndk_request_log_emerg(r,...) ndk_log_emerg (ndk_request_to_log(r), __VA_ARGS__)
|
||||
#define ndk_request_log_alert(r,...) ndk_log_alert (ndk_request_to_log(r), __VA_ARGS__)
|
||||
#define ndk_request_log_crit(r,...) ndk_log_crit (ndk_request_to_log(r), __VA_ARGS__)
|
||||
#define ndk_request_log_err(r,...) ndk_log_err (ndk_request_to_log(r), __VA_ARGS__)
|
||||
#define ndk_request_log_warning(r,...) ndk_log_warning (ndk_request_to_log(r), __VA_ARGS__)
|
||||
#define ndk_request_log_notice(r,...) ndk_log_notice (ndk_request_to_log(r), __VA_ARGS__)
|
||||
#define ndk_request_log_info(r,...) ndk_log_info (ndk_request_to_log(r), __VA_ARGS__)
|
||||
|
||||
|
||||
#if (NGX_DEBUG)
|
||||
|
||||
#define ndk_log_debug_core(log,...) ngx_log_debug (NGX_LOG_DEBUG_CORE, log, 0, __VA_ARGS__)
|
||||
#define ndk_log_debug_alloc(log,...) ngx_log_debug (NGX_LOG_DEBUG_ALLOC, log, 0, __VA_ARGS__)
|
||||
#define ndk_log_debug_mutex(log,...) ngx_log_debug (NGX_LOG_DEBUG_MUTEX, log, 0, __VA_ARGS__)
|
||||
#define ndk_log_debug_event(log,...) ngx_log_debug (NGX_LOG_DEBUG_EVENT, log, 0, __VA_ARGS__)
|
||||
#define ndk_log_debug_http(log,...) ngx_log_debug (NGX_LOG_DEBUG_HTTP, log, 0, __VA_ARGS__)
|
||||
#define ndk_log_debug_mail(log,...) ngx_log_debug (NGX_LOG_DEBUG_MAIL, log, 0, __VA_ARGS__)
|
||||
#define ndk_log_debug_mysql(log,...) ngx_log_debug (NGX_LOG_DEBUG_MYSQL, log, 0, __VA_ARGS__)
|
||||
|
||||
#define ndk_conf_log_debug_core(r,...) ndk_log_debug_core (ndk_conf_to_log(r), __VA_ARGS__)
|
||||
#define ndk_conf_log_debug_alloc(r,...) ndk_log_debug_alloc (ndk_conf_to_log(r), __VA_ARGS__)
|
||||
#define ndk_conf_log_debug_mutex(r,...) ndk_log_debug_mutex (ndk_conf_to_log(r), __VA_ARGS__)
|
||||
#define ndk_conf_log_debug_event(r,...) ndk_log_debug_event (ndk_conf_to_log(r), __VA_ARGS__)
|
||||
#define ndk_conf_log_debug_http(r,...) ndk_log_debug_http (ndk_conf_to_log(r), __VA_ARGS__)
|
||||
#define ndk_conf_log_debug_mail(r,...) ndk_log_debug_mail (ndk_conf_to_log(r), __VA_ARGS__)
|
||||
#define ndk_conf_log_debug_mysql(r,...) ndk_log_debug_mysql (ndk_conf_to_log(r), __VA_ARGS__)
|
||||
|
||||
#define ndk_request_log_debug_core(r,...) ndk_log_debug_core (ndk_request_to_log(r), __VA_ARGS__)
|
||||
#define ndk_request_log_debug_alloc(r,...) ndk_log_debug_alloc (ndk_request_to_log(r), __VA_ARGS__)
|
||||
#define ndk_request_log_debug_mutex(r,...) ndk_log_debug_mutex (ndk_request_to_log(r), __VA_ARGS__)
|
||||
#define ndk_request_log_debug_event(r,...) ndk_log_debug_event (ndk_request_to_log(r), __VA_ARGS__)
|
||||
#define ndk_request_log_debug_http(r,...) ndk_log_debug_http (ndk_request_to_log(r), __VA_ARGS__)
|
||||
#define ndk_request_log_debug_mail(r,...) ndk_log_debug_mail (ndk_request_to_log(r), __VA_ARGS__)
|
||||
#define ndk_request_log_debug_mysql(r,...) ndk_log_debug_mysql (ndk_request_to_log(r), __VA_ARGS__)
|
||||
|
||||
#else
|
||||
|
||||
#define ndk_log_debug_core(log,...)
|
||||
#define ndk_log_debug_alloc(log,...)
|
||||
#define ndk_log_debug_mutex(log,...)
|
||||
#define ndk_log_debug_event(log,...)
|
||||
#define ndk_log_debug_http(log,...)
|
||||
#define ndk_log_debug_mail(log,...)
|
||||
#define ndk_log_debug_mysql(log,...)
|
||||
|
||||
#define ndk_conf_log_debug_core(r,...)
|
||||
#define ndk_conf_log_debug_alloc(r,...)
|
||||
#define ndk_conf_log_debug_mutex(r,...)
|
||||
#define ndk_conf_log_debug_event(r,...)
|
||||
#define ndk_conf_log_debug_http(r,...)
|
||||
#define ndk_conf_log_debug_mail(r,...)
|
||||
#define ndk_conf_log_debug_mysql(r,...)
|
||||
|
||||
#define ndk_request_log_debug_core(r,...)
|
||||
#define ndk_request_log_debug_alloc(r,...)
|
||||
#define ndk_request_log_debug_mutex(r,...)
|
||||
#define ndk_request_log_debug_event(r,...)
|
||||
#define ndk_request_log_debug_http(r,...)
|
||||
#define ndk_request_log_debug_mail(r,...)
|
||||
#define ndk_request_log_debug_mysql(r,...)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*********************************/
|
||||
|
||||
#elif (NGX_HAVE_GCC_VARIADIC_MACROS)
|
||||
|
||||
#define ndk_log_stderr(log,args...) ngx_log_error (NGX_LOG_STDERR, log, 0, args)
|
||||
#define ndk_log_emerg(log,args...) ngx_log_error (NGX_LOG_EMERG, log, 0, args)
|
||||
#define ndk_log_alert(log,args...) ngx_log_error (NGX_LOG_ALERT, log, 0, args)
|
||||
#define ndk_log_crit(log,args...) ngx_log_error (NGX_LOG_CRIT, log, 0, args)
|
||||
#define ndk_log_err(log,args...) ngx_log_error (NGX_LOG_ERR, log, 0, args)
|
||||
#define ndk_log_warning(log,args...) ngx_log_error (NGX_LOG_WARN, log, 0, args)
|
||||
#define ndk_log_notice(log,args...) ngx_log_error (NGX_LOG_NOTICE, log, 0, args)
|
||||
#define ndk_log_info(log,args...) ngx_log_error (NGX_LOG_INFO, log, 0, args)
|
||||
|
||||
#define ndk_log_debug_core(log,args...) ngx_log_debug (NGX_LOG_DEBUG_CORE, log, 0, args)
|
||||
#define ndk_log_debug_alloc(log,args...) ngx_log_debug (NGX_LOG_DEBUG_ALLOC, log, 0, args)
|
||||
#define ndk_log_debug_mutex(log,args...) ngx_log_debug (NGX_LOG_DEBUG_MUTEX, log, 0, args)
|
||||
#define ndk_log_debug_event(log,args...) ngx_log_debug (NGX_LOG_DEBUG_EVENT, log, 0, args)
|
||||
#define ndk_log_debug_http(log,args...) ngx_log_debug (NGX_LOG_DEBUG_HTTP, log, 0, args)
|
||||
#define ndk_log_debug_mail(log,args...) ngx_log_debug (NGX_LOG_DEBUG_MAIL, log, 0, args)
|
||||
#define ndk_log_debug_mysql(log,args...) ngx_log_debug (NGX_LOG_DEBUG_MYSQL, log, 0, args)
|
||||
#define ndk_log_debug_script(log,args...) ngx_log_debug (NGX_LOG_DEBUG_SCRIPT, log, 0, args)
|
||||
|
||||
#define ndk_conf_log_stderr(cf,args...) ngx_conf_log_error (NGX_LOG_STDERR, cf, 0, args)
|
||||
#define ndk_conf_log_emerg(cf,args...) ngx_conf_log_error (NGX_LOG_EMERG, cf, 0, args)
|
||||
#define ndk_conf_log_alert(cf,args...) ngx_conf_log_error (NGX_LOG_ALERT, cf, 0, args)
|
||||
#define ndk_conf_log_crit(cf,args...) ngx_conf_log_error (NGX_LOG_CRIT, cf, 0, args)
|
||||
#define ndk_conf_log_err(cf,args...) ngx_conf_log_error (NGX_LOG_ERR, cf, 0, args)
|
||||
#define ndk_conf_log_warning(cf,args...) ngx_conf_log_error (NGX_LOG_WARN, cf, 0, args)
|
||||
#define ndk_conf_log_notice(cf,args...) ngx_conf_log_error (NGX_LOG_NOTICE, cf, 0, args)
|
||||
#define ndk_conf_log_info(cf,args...) ngx_conf_log_error (NGX_LOG_INFO, cf, 0, args)
|
||||
|
||||
#define ndk_conf_log_debug_core(r,args...) ndk_log_debug_core (ndk_conf_to_log(r), args)
|
||||
#define ndk_conf_log_debug_alloc(r,args...) ndk_log_debug_alloc (ndk_conf_to_log(r), args)
|
||||
#define ndk_conf_log_debug_mutex(r,args...) ndk_log_debug_mutex (ndk_conf_to_log(r), args)
|
||||
#define ndk_conf_log_debug_event(r,args...) ndk_log_debug_event (ndk_conf_to_log(r), args)
|
||||
#define ndk_conf_log_debug_http(r,args...) ndk_log_debug_http (ndk_conf_to_log(r), args)
|
||||
#define ndk_conf_log_debug_mail(r,args...) ndk_log_debug_mail (ndk_conf_to_log(r), args)
|
||||
#define ndk_conf_log_debug_mysql(r,args...) ndk_log_debug_mysql (ndk_conf_to_log(r), args)
|
||||
#define ndk_conf_log_debug_script(r,args...) ndk_log_debug_script (ndk_conf_to_log(r), args)
|
||||
|
||||
#define ndk_request_log_stderr(r,args...) ndk_log_stderr (ndk_request_to_log(r), args)
|
||||
#define ndk_request_log_emerg(r,args...) ndk_log_emerg (ndk_request_to_log(r), args)
|
||||
#define ndk_request_log_alert(r,args...) ndk_log_alert (ndk_request_to_log(r), args)
|
||||
#define ndk_request_log_crit(r,args...) ndk_log_crit (ndk_request_to_log(r), args)
|
||||
#define ndk_request_log_err(r,args...) ndk_log_err (ndk_request_to_log(r), args)
|
||||
#define ndk_request_log_warning(r,args...) ndk_log_warning (ndk_request_to_log(r), args)
|
||||
#define ndk_request_log_notice(r,args...) ndk_log_notice (ndk_request_to_log(r), args)
|
||||
#define ndk_request_log_info(r,args...) ndk_log_info (ndk_request_to_log(r), args)
|
||||
|
||||
#define ndk_request_log_debug_core(r,args...) ndk_log_debug_core (ndk_request_to_log(r), args)
|
||||
#define ndk_request_log_debug_alloc(r,args...) ndk_log_debug_alloc (ndk_request_to_log(r), args)
|
||||
#define ndk_request_log_debug_mutex(r,args...) ndk_log_debug_mutex (ndk_request_to_log(r), args)
|
||||
#define ndk_request_log_debug_event(r,args...) ndk_log_debug_event (ndk_request_to_log(r), args)
|
||||
#define ndk_request_log_debug_http(r,args...) ndk_log_debug_http (ndk_request_to_log(r), args)
|
||||
#define ndk_request_log_debug_mail(r,args...) ndk_log_debug_mail (ndk_request_to_log(r), args)
|
||||
#define ndk_request_log_debug_mysql(r,args...) ndk_log_debug_mysql (ndk_request_to_log(r), args)
|
||||
#define ndk_request_log_debug_script(r,args...) ndk_log_debug_script (ndk_request_to_log(r), args)
|
||||
|
||||
/*********************************/
|
||||
|
||||
#else /* NO VARIADIC MACROS */
|
||||
|
||||
/* #warning does not work on Windows */
|
||||
#pragma message("Nginx Devel Kit logging without variadic macros not yet implemented")
|
||||
|
||||
#endif /* VARIADIC MACROS */
|
|
@ -0,0 +1,67 @@
|
|||
|
||||
|
||||
|
||||
#if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED)
|
||||
|
||||
#define ndk_str3_cmp(m, c0, c1, c2, c3) \
|
||||
*(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0)
|
||||
|
||||
#define ndk_str3Ocmp(m, c0, c1, c2, c3) \
|
||||
*(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0)
|
||||
|
||||
#define ndk_str4cmp(m, c0, c1, c2, c3) \
|
||||
*(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0)
|
||||
|
||||
#define ndk_str5cmp(m, c0, c1, c2, c3, c4) \
|
||||
*(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0) \
|
||||
&& m[4] == c4
|
||||
|
||||
#define ndk_str6cmp(m, c0, c1, c2, c3, c4, c5) \
|
||||
*(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0) \
|
||||
&& (((uint32_t *) m)[1] & 0xffff) == ((c5 << 8) | c4)
|
||||
|
||||
#define ndk_str7_cmp(m, c0, c1, c2, c3, c4, c5, c6, c7) \
|
||||
*(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0) \
|
||||
&& ((uint32_t *) m)[1] == ((c7 << 24) | (c6 << 16) | (c5 << 8) | c4)
|
||||
|
||||
#define ndk_str8cmp(m, c0, c1, c2, c3, c4, c5, c6, c7) \
|
||||
*(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0) \
|
||||
&& ((uint32_t *) m)[1] == ((c7 << 24) | (c6 << 16) | (c5 << 8) | c4)
|
||||
|
||||
#define ndk_str9cmp(m, c0, c1, c2, c3, c4, c5, c6, c7, c8) \
|
||||
*(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0) \
|
||||
&& ((uint32_t *) m)[1] == ((c7 << 24) | (c6 << 16) | (c5 << 8) | c4) \
|
||||
&& m[8] == c8
|
||||
|
||||
#else /* !(NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED) */
|
||||
|
||||
#define ndk_str3_cmp(m, c0, c1, c2, c3) \
|
||||
m[0] == c0 && m[1] == c1 && m[2] == c2
|
||||
|
||||
#define ndk_str3Ocmp(m, c0, c1, c2, c3) \
|
||||
m[0] == c0 && m[2] == c2 && m[3] == c3
|
||||
|
||||
#define ndk_str4cmp(m, c0, c1, c2, c3) \
|
||||
m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3
|
||||
|
||||
#define ndk_str5cmp(m, c0, c1, c2, c3, c4) \
|
||||
m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3 && m[4] == c4
|
||||
|
||||
#define ndk_str6cmp(m, c0, c1, c2, c3, c4, c5) \
|
||||
m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3 \
|
||||
&& m[4] == c4 && m[5] == c5
|
||||
|
||||
#define ndk_str7_cmp(m, c0, c1, c2, c3, c4, c5, c6, c7) \
|
||||
m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3 \
|
||||
&& m[4] == c4 && m[5] == c5 && m[6] == c6
|
||||
|
||||
#define ndk_str8cmp(m, c0, c1, c2, c3, c4, c5, c6, c7) \
|
||||
m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3 \
|
||||
&& m[4] == c4 && m[5] == c5 && m[6] == c6 && m[7] == c7
|
||||
|
||||
#define ndk_str9cmp(m, c0, c1, c2, c3, c4, c5, c6, c7, c8) \
|
||||
m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3 \
|
||||
&& m[4] == c4 && m[5] == c5 && m[6] == c6 && m[7] == c7 && m[8] == c8
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,583 @@
|
|||
|
||||
|
||||
|
||||
/* This function cleans a path to its most basic form, performing the following transformations :
|
||||
*
|
||||
* - ./ -> [empty]
|
||||
* - // -> /
|
||||
* - /base/parent/../ -> /base/
|
||||
*
|
||||
* If possible, it leaves the original string in place and does not copy characters, otherwise
|
||||
* characters are copied.
|
||||
*/
|
||||
|
||||
void
|
||||
ndk_clean_path (ngx_str_t *path, ngx_uint_t complex, size_t off)
|
||||
{
|
||||
u_char *s, *p, *m, *e, c, *l;
|
||||
ngx_uint_t root;
|
||||
|
||||
if (path->len == 1) {
|
||||
|
||||
if (path->data[0] == '.') {
|
||||
path->len = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* strip initial './' */
|
||||
|
||||
s = path->data;
|
||||
e = s + path->len;
|
||||
|
||||
if (off) {
|
||||
p = s + off;
|
||||
goto check_basic;
|
||||
}
|
||||
|
||||
if (*s == '/')
|
||||
root = 1;
|
||||
else
|
||||
root = 0;
|
||||
|
||||
while (s < e) {
|
||||
|
||||
switch (*s) {
|
||||
|
||||
case '/' :
|
||||
|
||||
/* '//' => '/' */
|
||||
|
||||
s++;
|
||||
continue;
|
||||
|
||||
case '.' :
|
||||
|
||||
if (s == e-1) {
|
||||
|
||||
if (root) {
|
||||
path->data[0] = '/';
|
||||
path->len = 1;
|
||||
} else {
|
||||
path->len = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* './' => '' */
|
||||
|
||||
if (s[1] == '/') {
|
||||
|
||||
s += 2;
|
||||
|
||||
if (s == e) {
|
||||
|
||||
path->len = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (root && *s != '/') {
|
||||
s--;
|
||||
}
|
||||
|
||||
p = s;
|
||||
|
||||
check_basic :
|
||||
|
||||
for ( ; p<e; p++) {
|
||||
|
||||
if (*p == '/') {
|
||||
|
||||
new_dir_first :
|
||||
|
||||
if (e - p == 1)
|
||||
break;
|
||||
|
||||
switch (p[1]) {
|
||||
|
||||
case '/' :
|
||||
|
||||
/* '//' => '/' */
|
||||
|
||||
m = p + 2;
|
||||
goto copy;
|
||||
|
||||
case '.' :
|
||||
|
||||
if (e - p == 2)
|
||||
break;
|
||||
|
||||
switch (p[2]) {
|
||||
|
||||
case '/' :
|
||||
|
||||
/* './' => '' */
|
||||
|
||||
m = p + 2;
|
||||
goto copy;
|
||||
|
||||
case '.' :
|
||||
|
||||
if (e - p == 3 || p[3] == '/') {
|
||||
|
||||
if (p == s) {
|
||||
|
||||
s += 3;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (p - s >= 2) {
|
||||
|
||||
if (p[-1] == '.' && p[-2] == '.') {
|
||||
|
||||
if (p - s == 2 || p[-3] == '/') { /* = '../../' */
|
||||
|
||||
p += 2; /* 3? */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m = p + 4;
|
||||
|
||||
if (complex) {
|
||||
|
||||
for (p--; p >= s; p--) {
|
||||
|
||||
switch (*p) {
|
||||
|
||||
case '/' :
|
||||
goto copy;
|
||||
|
||||
case '$' :
|
||||
|
||||
p = m - 1;
|
||||
|
||||
if (m == e)
|
||||
goto end_basic;
|
||||
|
||||
goto new_dir_first;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
for (p--; p > s; p--) {
|
||||
|
||||
/* '/path/folder/../' => '/path/' */
|
||||
|
||||
if (*p == '/')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
goto copy;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end_basic :
|
||||
|
||||
path->data = s;
|
||||
path->len = p - s;
|
||||
|
||||
return;
|
||||
|
||||
copy :
|
||||
|
||||
p++;
|
||||
|
||||
if (m < e)
|
||||
goto new_dir;
|
||||
|
||||
while (m < e) {
|
||||
|
||||
c = *m;
|
||||
*p = c;
|
||||
p++;
|
||||
|
||||
if (c == '/') {
|
||||
|
||||
m++;
|
||||
|
||||
new_dir :
|
||||
|
||||
for ( ; m<e; m++) {
|
||||
|
||||
c = *m;
|
||||
if (c != '/')
|
||||
break;
|
||||
}
|
||||
|
||||
if (m == e)
|
||||
break;
|
||||
|
||||
if (c == '.') {
|
||||
|
||||
if (e - m == 1)
|
||||
break;
|
||||
|
||||
switch (m[1]) {
|
||||
|
||||
case '/' :
|
||||
|
||||
/* './' => '' */
|
||||
|
||||
m += 2;
|
||||
if (m == e)
|
||||
break;
|
||||
|
||||
goto new_dir;
|
||||
|
||||
case '.' :
|
||||
|
||||
if (e - m == 2 || m[2] == '/') {
|
||||
|
||||
if (m - s >= 3) { /* NOTE : this is one higher than above because m has moved on 1 */
|
||||
|
||||
if (p[-2] == '.' && p[-3] == '.') {
|
||||
|
||||
if (m - s == 3 || p[-4] == '/') { /* = '../../' */
|
||||
|
||||
p[0] = '.';
|
||||
p[1] = '.';
|
||||
p[2] = '/';
|
||||
p += 3;
|
||||
m += 3;
|
||||
goto new_dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (complex) {
|
||||
|
||||
l = p;
|
||||
|
||||
for (p -= 2; p >= s; p--) {
|
||||
|
||||
switch (*p) {
|
||||
|
||||
case '/' :
|
||||
break;
|
||||
|
||||
case '$' :
|
||||
|
||||
l[0] = '.';
|
||||
l[1] = '.';
|
||||
l[2] = '/';
|
||||
p = l + 4;
|
||||
break;
|
||||
|
||||
default :
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
m += 3;
|
||||
if (m == e)
|
||||
goto end;
|
||||
|
||||
goto new_dir;
|
||||
|
||||
} else {
|
||||
|
||||
for (p -= 2; p > s; p--) {
|
||||
|
||||
/* '/path/folder/../' => '/path/' */
|
||||
|
||||
if (*p == '/')
|
||||
break;
|
||||
}
|
||||
|
||||
m += 3;
|
||||
if (m == e)
|
||||
goto end;
|
||||
|
||||
goto new_dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
m++;
|
||||
}
|
||||
}
|
||||
|
||||
end :
|
||||
|
||||
path->data = s;
|
||||
path->len = p - s;
|
||||
}
|
||||
|
||||
|
||||
/* This function converts a path to its directory version, and assumes that there is always space
|
||||
* to allocatate an extra character on the end (which is only true if the provided strings always
|
||||
* have NULL's at the end (hence the 'safe').
|
||||
*/
|
||||
|
||||
void
|
||||
ndk_path_to_dir_safe (ngx_str_t *path, ngx_uint_t complex, size_t off)
|
||||
{
|
||||
size_t len;
|
||||
u_char *p, *m;
|
||||
|
||||
ndk_clean_path (path, complex, off);
|
||||
|
||||
len = path->len;
|
||||
if (!len)
|
||||
return;
|
||||
|
||||
p = path->data;
|
||||
m = p + len - 1;
|
||||
|
||||
if (*m != '/') {
|
||||
|
||||
p [len] = '/';
|
||||
path->len++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Divides a path given by path/to/path1:path/to/path2 into separate strings and returns an
|
||||
* array of these strings.
|
||||
*/
|
||||
|
||||
ngx_array_t *
|
||||
ndk_split_path_create (ngx_conf_t *cf, ngx_str_t *path)
|
||||
{
|
||||
ngx_str_t *str;
|
||||
int n;
|
||||
u_char *m, *s, *e;
|
||||
ngx_array_t *a;
|
||||
|
||||
if (path == NULL)
|
||||
return NULL;
|
||||
|
||||
n = ndk_strcntc (path, ':');
|
||||
|
||||
a = ngx_array_create (cf->pool, n + 1, sizeof (ngx_str_t));
|
||||
if (a == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
s = path->data;
|
||||
e = s + path->len;
|
||||
|
||||
while (s < e) {
|
||||
|
||||
m = s;
|
||||
|
||||
while (m < e && *m != ':') m++;
|
||||
|
||||
if (m == s) {
|
||||
s = m+1;
|
||||
continue;
|
||||
}
|
||||
|
||||
str = ngx_array_push (a);
|
||||
if (str == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
str->data = s;
|
||||
str->len = m - s;
|
||||
|
||||
if (ngx_conf_full_name (cf->cycle, str, 0) == NGX_ERROR)
|
||||
return NULL;
|
||||
|
||||
s = m+1;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ngx_array_t *
|
||||
ndk_split_path_create_raw (ngx_conf_t *cf, char *path)
|
||||
{
|
||||
ngx_str_t *str;
|
||||
int n;
|
||||
char *m, *s;
|
||||
ngx_array_t *a;
|
||||
|
||||
if (path == NULL)
|
||||
return NULL;
|
||||
|
||||
n = ndk_strccnt (path, ':');
|
||||
|
||||
a = ngx_array_create (cf->pool, n + 1, sizeof (ngx_str_t));
|
||||
if (a == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
s = path;
|
||||
|
||||
|
||||
while (*s != '\0') {
|
||||
|
||||
m = s;
|
||||
|
||||
while (*m != '\0' && *m != ':') m++;
|
||||
|
||||
if (m == s) {
|
||||
s = m+1;
|
||||
continue;
|
||||
}
|
||||
|
||||
str = ngx_array_push (a);
|
||||
if (str == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
str->data = (u_char *) s;
|
||||
str->len = m - s;
|
||||
|
||||
if (ngx_conf_full_name (cf->cycle, str, 0) == NGX_ERROR)
|
||||
return NULL;
|
||||
|
||||
if (*m == '\0')
|
||||
break;
|
||||
|
||||
s = m+1;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_full_path_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
ngx_str_t *path, *value;
|
||||
ngx_conf_post_t *post;
|
||||
|
||||
path = (ngx_str_t *) (p + cmd->offset);
|
||||
|
||||
if (path->data) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
*path = value[1];
|
||||
|
||||
if (ngx_conf_full_name (cf->cycle, path, 0) == NGX_ERROR)
|
||||
return NGX_CONF_ERROR;
|
||||
|
||||
if (cmd->post) {
|
||||
post = cmd->post;
|
||||
return post->post_handler(cf, post, path);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_split_path_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
/* TODO : change to use the path func above */
|
||||
|
||||
char *p = conf;
|
||||
|
||||
ngx_str_t *value, *str;
|
||||
ngx_array_t **a;
|
||||
ngx_conf_post_t *post;
|
||||
int n;
|
||||
u_char *m, *s, *e;
|
||||
|
||||
a = (ngx_array_t **) (p + cmd->offset);
|
||||
|
||||
if (*a != NGX_CONF_UNSET_PTR) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
value = cf->args->elts;
|
||||
value++;
|
||||
|
||||
n = ndk_strcntc (value, ':') + 1;
|
||||
|
||||
*a = ngx_array_create (cf->pool, n, sizeof (ngx_str_t));
|
||||
if (*a == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
s = value->data;
|
||||
e = s + value->len;
|
||||
|
||||
while (s < e) {
|
||||
|
||||
m = s;
|
||||
|
||||
while (m < e && *m != ':') m++;
|
||||
|
||||
if (m == s) {
|
||||
s = m+1;
|
||||
continue;
|
||||
}
|
||||
|
||||
str = ngx_array_push (*a);
|
||||
if (str == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
str->data = s;
|
||||
str->len = m - s;
|
||||
|
||||
if (ngx_conf_full_name (cf->cycle, str, 0) == NGX_ERROR)
|
||||
return NGX_CONF_ERROR;
|
||||
|
||||
s = m+1;
|
||||
}
|
||||
|
||||
|
||||
if (cmd->post) {
|
||||
post = cmd->post;
|
||||
return post->post_handler (cf, post, a);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_full_path (ngx_conf_t *cf, void *data, ngx_str_t *path)
|
||||
{
|
||||
if (ngx_conf_full_name (cf->cycle, path, 0) == NGX_ERROR)
|
||||
return NGX_CONF_ERROR;
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_full_conf_path (ngx_conf_t *cf, void *data, ngx_str_t *path)
|
||||
{
|
||||
if (ngx_conf_full_name (cf->cycle, path, 1) == NGX_ERROR)
|
||||
return NGX_CONF_ERROR;
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
|
||||
/* path conversion functions */
|
||||
|
||||
void ndk_clean_path (ngx_str_t *path, ngx_uint_t complex, size_t off);
|
||||
void ndk_path_to_dir_safe (ngx_str_t *path, ngx_uint_t complex, size_t off);
|
||||
|
||||
/* path create functions */
|
||||
|
||||
ngx_array_t * ndk_split_path_create (ngx_conf_t *cf, ngx_str_t *path);
|
||||
ngx_array_t * ndk_split_path_create_raw (ngx_conf_t *cf, char *path);
|
||||
|
||||
/* conf set functions */
|
||||
|
||||
char * ndk_conf_set_full_path_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
char * ndk_conf_set_split_path_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
|
||||
/* conf set post functions */
|
||||
|
||||
char * ndk_conf_set_full_path (ngx_conf_t *cf, void *data, ngx_str_t *path);
|
||||
char * ndk_conf_set_full_conf_path (ngx_conf_t *cf, void *data, ngx_str_t *path);
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
ngx_int_t
|
||||
ndk_init_signals (ngx_signal_t *sig, ngx_log_t *log)
|
||||
{
|
||||
struct sigaction sa;
|
||||
|
||||
for ( ; sig->signo != 0; sig++) {
|
||||
ndk_zerov (sa);
|
||||
sa.sa_handler = sig->handler;
|
||||
sigemptyset (&sa.sa_mask);
|
||||
|
||||
if (sigaction (sig->signo, &sa, NULL) == -1) {
|
||||
ngx_log_error (NGX_LOG_EMERG, log, ngx_errno,
|
||||
"sigaction(%s) failed", sig->signame);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
|
||||
typedef struct {
|
||||
int signo;
|
||||
char *signame;
|
||||
char *name;
|
||||
void (*handler)(int signo);
|
||||
} ngx_signal_t;
|
||||
|
||||
|
||||
ngx_int_t ndk_init_signals (ngx_signal_t *sig, ngx_log_t *log);
|
||||
|
|
@ -0,0 +1,215 @@
|
|||
|
||||
|
||||
char *
|
||||
ndk_conf_set_regex_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
ngx_str_t *value;
|
||||
ngx_conf_post_t *post;
|
||||
ngx_regex_elt_t *re;
|
||||
ngx_regex_compile_t rc;
|
||||
u_char errstr[NGX_MAX_CONF_ERRSTR];
|
||||
|
||||
re = (ngx_regex_elt_t *) (p + cmd->offset);
|
||||
|
||||
if (re->name) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
value = cf->args->elts;
|
||||
value++;
|
||||
|
||||
ndk_zerov (rc);
|
||||
|
||||
rc.pool = cf->pool;
|
||||
rc.err.len = NGX_MAX_CONF_ERRSTR;
|
||||
rc.err.data = errstr;
|
||||
rc.pattern = *value;
|
||||
|
||||
if (ngx_regex_compile(&rc) != NGX_OK) {
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
re->regex = rc.regex;
|
||||
re->name = value->data;
|
||||
|
||||
if (cmd->post) {
|
||||
post = cmd->post;
|
||||
return post->post_handler (cf, post, re);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_regex_caseless_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
ngx_str_t *value;
|
||||
ngx_conf_post_t *post;
|
||||
ngx_regex_elt_t *re;
|
||||
ngx_regex_compile_t rc;
|
||||
u_char errstr[NGX_MAX_CONF_ERRSTR];
|
||||
|
||||
re = (ngx_regex_elt_t *) (p + cmd->offset);
|
||||
|
||||
if (re->name) {
|
||||
return "is duplicate";
|
||||
}
|
||||
|
||||
value = cf->args->elts;
|
||||
value++;
|
||||
|
||||
ndk_zerov (rc);
|
||||
|
||||
rc.pool = cf->pool;
|
||||
rc.err.len = NGX_MAX_CONF_ERRSTR;
|
||||
rc.err.data = errstr;
|
||||
rc.pattern = *value;
|
||||
rc.options = NGX_REGEX_CASELESS;
|
||||
|
||||
if (ngx_regex_compile(&rc) != NGX_OK) {
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
re->regex = rc.regex;
|
||||
re->name = value->data;
|
||||
|
||||
if (cmd->post) {
|
||||
post = cmd->post;
|
||||
return post->post_handler (cf, post, re);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_regex_array_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
ngx_str_t *value;
|
||||
ngx_conf_post_t *post;
|
||||
ngx_array_t **a;
|
||||
ngx_regex_elt_t *re;
|
||||
ngx_regex_compile_t rc;
|
||||
ngx_uint_t i, n = 0;
|
||||
u_char errstr[NGX_MAX_CONF_ERRSTR];
|
||||
|
||||
a = (ngx_array_t **) (p + cmd->offset);
|
||||
|
||||
if (*a != NGX_CONF_UNSET_PTR) {
|
||||
|
||||
n = cf->args->nelts > 4 ? cf->args->nelts : 4;
|
||||
|
||||
*a = ngx_array_create (cf->pool, n, sizeof (ngx_regex_elt_t));
|
||||
if (*a == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
ndk_zerov (rc);
|
||||
|
||||
rc.pool = cf->pool;
|
||||
rc.err.len = NGX_MAX_CONF_ERRSTR;
|
||||
rc.err.data = errstr;
|
||||
|
||||
value = cf->args->elts;
|
||||
value++;
|
||||
|
||||
for (i=0; i<n; i++, value++) {
|
||||
|
||||
re = ngx_array_push (*a);
|
||||
if (re == NULL)
|
||||
return NGX_CONF_ERROR;
|
||||
|
||||
rc.pattern = *value;
|
||||
|
||||
if (ngx_regex_compile(&rc) != NGX_OK) {
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
re->regex = rc.regex;
|
||||
re->name = value->data;
|
||||
}
|
||||
|
||||
|
||||
if (cmd->post) {
|
||||
post = cmd->post;
|
||||
return post->post_handler (cf, post, a);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *
|
||||
ndk_conf_set_regex_array_caseless_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *p = conf;
|
||||
|
||||
ngx_str_t *value;
|
||||
ngx_conf_post_t *post;
|
||||
ngx_array_t **a;
|
||||
ngx_regex_elt_t *re;
|
||||
ngx_regex_compile_t rc;
|
||||
ngx_uint_t i, n = 0;
|
||||
u_char errstr[NGX_MAX_CONF_ERRSTR];
|
||||
|
||||
a = (ngx_array_t **) (p + cmd->offset);
|
||||
|
||||
if (*a != NGX_CONF_UNSET_PTR) {
|
||||
|
||||
n = cf->args->nelts > 4 ? cf->args->nelts : 4;
|
||||
|
||||
*a = ngx_array_create (cf->pool, n, sizeof (ngx_regex_elt_t));
|
||||
if (*a == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
ndk_zerov (rc);
|
||||
|
||||
rc.pool = cf->pool;
|
||||
rc.err.len = NGX_MAX_CONF_ERRSTR;
|
||||
rc.err.data = errstr;
|
||||
|
||||
value = cf->args->elts;
|
||||
value++;
|
||||
|
||||
for (i=0; i<n; i++, value++) {
|
||||
|
||||
re = ngx_array_push (*a);
|
||||
if (re == NULL)
|
||||
return NGX_CONF_ERROR;
|
||||
|
||||
rc.pattern = *value;
|
||||
rc.options = NGX_REGEX_CASELESS;
|
||||
|
||||
if (ngx_regex_compile(&rc) != NGX_OK) {
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
re->regex = rc.regex;
|
||||
re->name = value->data;
|
||||
}
|
||||
|
||||
|
||||
if (cmd->post) {
|
||||
post = cmd->post;
|
||||
return post->post_handler (cf, post, a);
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
|
||||
char * ndk_conf_set_regex_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
char * ndk_conf_set_regex_caseless_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
char * ndk_conf_set_regex_array_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
char * ndk_conf_set_regex_array_caseless_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue