From 2b807bc625b6008922a52688806972dc5d808d3e Mon Sep 17 00:00:00 2001 From: Giacomo Sanchietti Date: Thu, 5 Feb 2026 08:20:13 +0100 Subject: [PATCH 1/2] chore: revert nginx fork Let's stick to upstream nginx to be sure to gather latest security patches. --- config/ns-reverse-proxy.conf | 1 + packages/nginx/Config_ssl.in | 208 -- packages/nginx/Makefile | 511 ----- .../files-luci-support/60_nginx-luci-support | 47 - .../nginx/files-luci-support/luci.locations | 17 - packages/nginx/files/nginx.init | 115 - .../100-drop-libxslt-dep.patch | 14 - .../001-feature_support_pcre2.patch | 389 ---- .../001-feature_support_pcre2.patch | 2009 ----------------- .../nginx-mod-lua/100-no_by_lua_block.patch | 250 -- ...don-t-include-pcre.h-with-PCRE2-used.patch | 27 - .../patches/nginx-mod-rtmp/100-bigedian.patch | 1521 ------------- .../patches/nginx/101-feature_test_fix.patch | 116 - .../patches/nginx/102-sizeof_test_fix.patch | 27 - .../nginx/patches/nginx/103-sys_nerr.patch | 12 - .../patches/nginx/104-endianness_fix.patch | 19 - packages/nginx/patches/nginx/200-config.patch | 18 - .../nginx/201-ignore-invalid-options.patch | 12 - packages/ns-reverse-proxy/Makefile | 43 + .../{nginx => ns-reverse-proxy}/README.md | 15 +- .../files/nginx-proxy-gen | 3 + .../ns-reverse-proxy/files/ns-reverse-proxy | 30 + 22 files changed, 83 insertions(+), 5321 deletions(-) create mode 100644 config/ns-reverse-proxy.conf delete mode 100644 packages/nginx/Config_ssl.in delete mode 100644 packages/nginx/Makefile delete mode 100644 packages/nginx/files-luci-support/60_nginx-luci-support delete mode 100644 packages/nginx/files-luci-support/luci.locations delete mode 100644 packages/nginx/files/nginx.init delete mode 100644 packages/nginx/patches/nginx-mod-dav-ext/100-drop-libxslt-dep.patch delete mode 100644 packages/nginx/patches/nginx-mod-lua-resty-core/001-feature_support_pcre2.patch delete mode 100644 packages/nginx/patches/nginx-mod-lua/001-feature_support_pcre2.patch delete mode 100644 packages/nginx/patches/nginx-mod-lua/100-no_by_lua_block.patch delete mode 100644 packages/nginx/patches/nginx-mod-lua/101-bugfix-don-t-include-pcre.h-with-PCRE2-used.patch delete mode 100644 packages/nginx/patches/nginx-mod-rtmp/100-bigedian.patch delete mode 100644 packages/nginx/patches/nginx/101-feature_test_fix.patch delete mode 100644 packages/nginx/patches/nginx/102-sizeof_test_fix.patch delete mode 100644 packages/nginx/patches/nginx/103-sys_nerr.patch delete mode 100644 packages/nginx/patches/nginx/104-endianness_fix.patch delete mode 100644 packages/nginx/patches/nginx/200-config.patch delete mode 100644 packages/nginx/patches/nginx/201-ignore-invalid-options.patch create mode 100644 packages/ns-reverse-proxy/Makefile rename packages/{nginx => ns-reverse-proxy}/README.md (91%) rename packages/{nginx => ns-reverse-proxy}/files/nginx-proxy-gen (95%) create mode 100755 packages/ns-reverse-proxy/files/ns-reverse-proxy diff --git a/config/ns-reverse-proxy.conf b/config/ns-reverse-proxy.conf new file mode 100644 index 000000000..597c28a06 --- /dev/null +++ b/config/ns-reverse-proxy.conf @@ -0,0 +1 @@ +CONFIG_PACKAGE_ns-reverse-proxy=y diff --git a/packages/nginx/Config_ssl.in b/packages/nginx/Config_ssl.in deleted file mode 100644 index b02166f36..000000000 --- a/packages/nginx/Config_ssl.in +++ /dev/null @@ -1,208 +0,0 @@ -# -# Copyright (C) 2010-2016 OpenWrt.org -# -# This is free software, licensed under the GNU General Public License v2. -# See /LICENSE for more information. -# - -menu "Configuration" - depends on PACKAGE_nginx-ssl - -config NGINX_DAV - bool - prompt "Enable WebDAV module" - help - Enable the HTTP and WebDAV methods PUT, DELETE, MKCOL, COPY and MOVE. - default n - -config NGINX_FLV - bool - prompt "Enable FLV module" - help - Provides the ability to seek within FLV (Flash) files using time-based offsets. - default n - -config NGINX_STUB_STATUS - bool - prompt "Enable stub status module" - help - Enable the stub status module which gives some status from the server. - default n - -config NGINX_HTTP_CHARSET - bool - prompt "Enable HTTP charset module" - default y - -config NGINX_HTTP_GZIP - bool - prompt "Enable HTTP gzip module" - default y - -config NGINX_HTTP_GZIP_STATIC - bool - prompt "Enable HTTP gzip static module" - default y - -config NGINX_HTTP_SSI - bool - prompt "Enable HTTP ssi module" - default y - -config NGINX_HTTP_USERID - bool - prompt "Enable HTTP userid module" - default y - -config NGINX_HTTP_ACCESS - bool - prompt "Enable HTTP access module" - default y - -config NGINX_HTTP_AUTH_BASIC - bool - prompt "Enable HTTP auth basic" - default y - -config NGINX_HTTP_AUTH_REQUEST - bool - prompt "Enable HTTP auth request module" - default n - -config NGINX_HTTP_AUTOINDEX - bool - prompt "Enable HTTP autoindex module" - default y - -config NGINX_HTTP_GEO - bool - prompt "Enable HTTP geo module" - default y - -config NGINX_HTTP_MAP - bool - prompt "Enable HTTP map module" - default y - -config NGINX_HTTP_SPLIT_CLIENTS - bool - prompt "Enable HTTP split clients" - default y - -config NGINX_HTTP_REFERER - bool - prompt "Enable HTTP referer module" - default y - -config NGINX_HTTP_REWRITE - bool - prompt "Enable HTTP rewrite module" - select NGINX_PCRE - default y - -config NGINX_HTTP_PROXY - bool - prompt "Enable HTTP proxy module" - default y - -config NGINX_HTTP_FASTCGI - bool - prompt "Enable HTTP fastcgi module" - default y - -config NGINX_HTTP_UWSGI - bool - prompt "Enable HTTP uwsgi module" - default y - -config NGINX_HTTP_SCGI - bool - prompt "Enable HTTP scgi module" - default y - -config NGINX_HTTP_MEMCACHED - bool - prompt "Enable HTTP memcached module" - default y - -config NGINX_HTTP_LIMIT_CONN - bool - prompt "Enable HTTP limit conn" - default y - -config NGINX_HTTP_LIMIT_REQ - bool - prompt "Enable HTTP limit req" - default y - -config NGINX_HTTP_EMPTY_GIF - bool - prompt "Enable HTTP empty gif" - default y - -config NGINX_HTTP_BROWSER - bool - prompt "Enable HTTP browser module" - default y - -config NGINX_HTTP_UPSTREAM_HASH - bool - prompt "Enable HTTP hash module" - default y - -config NGINX_HTTP_UPSTREAM_IP_HASH - bool - prompt "Enable HTTP IP hash module" - default y - -config NGINX_HTTP_UPSTREAM_LEAST_CONN - bool - prompt "Enable HTTP least conn module" - default y - -config NGINX_HTTP_UPSTREAM_KEEPALIVE - bool - prompt "Enable HTTP keepalive module" - default y - -config NGINX_HTTP_CACHE - bool - prompt "Enable HTTP cache" - default y - -config NGINX_HTTP_V2 - bool - prompt "Enable HTTP_V2 module" - default y - -config NGINX_HTTP_QUIC - bool - prompt "Enable QUIC support" - default n - -config NGINX_PCRE - bool - prompt "Enable PCRE library usage" - default y - -config NGINX_HTTP_REAL_IP - bool - prompt "Enable HTTP real ip module" - default n - -config NGINX_HTTP_SECURE_LINK - bool - prompt "Enable HTTP secure link module" - default n - -config NGINX_HTTP_SUB - bool - prompt "Enable HTTP sub module" - default n - -config NGINX_STREAM_REAL_IP - bool - prompt "Enable STREAM real ip module" - default n - -endmenu diff --git a/packages/nginx/Makefile b/packages/nginx/Makefile deleted file mode 100644 index deb5156ba..000000000 --- a/packages/nginx/Makefile +++ /dev/null @@ -1,511 +0,0 @@ -# -# Copyright (C) 2012-2016 OpenWrt.org -# -# This is free software, licensed under the GNU General Public License v2. -# See /LICENSE for more information. -# - -include $(TOPDIR)/rules.mk - -PKG_NAME:=nginx -PKG_VERSION:=1.25.2 -PKG_RELEASE:=2 - -PKG_SOURCE:=nginx-$(PKG_VERSION).tar.gz -PKG_SOURCE_URL:=https://nginx.org/download/ -PKG_HASH:=05dd6d9356d66a74e61035f2a42162f8c754c97cf1ba64e7a801ba158d6c0711 - -PKG_MAINTAINER:=Thomas Heil \ - Christian Marangi -PKG_LICENSE:=2-clause BSD-like license -PKG_CPE_ID:=cpe:/a:nginx:nginx - -PKG_FIXUP:=autoreconf -PKG_BUILD_PARALLEL:=1 -PKG_INSTALL:=1 -PKG_BUILD_FLAGS:=gc-sections - -# 3rd-party modules -PKG_MOD_EXTRA := \ - geoip2 \ - lua \ - lua-resty-core \ - lua-resty-lrucache \ - rtmp \ - dav-ext \ - naxsi \ - brotli \ - headers-more \ - ts \ - ubus -# official and 3rd-party modules -PKG_MOD_ALL := \ - $(PKG_MOD_EXTRA) \ - stream -PKG_MOD_PATCHED := $(shell find patches -mindepth 1 -maxdepth 1 -type d -name 'nginx-mod-*' | sed -E 's,^patches/nginx-mod-,,') - -PKG_CONFIG_DEPENDS := \ - CONFIG_NGINX_DAV \ - CONFIG_NGINX_FLV \ - CONFIG_NGINX_STUB_STATUS \ - CONFIG_NGINX_HTTP_CHARSET \ - CONFIG_NGINX_HTTP_GZIP \ - CONFIG_NGINX_HTTP_GZIP_STATIC \ - CONFIG_NGINX_HTTP_SSI \ - CONFIG_NGINX_HTTP_USERID \ - CONFIG_NGINX_HTTP_ACCESS \ - CONFIG_NGINX_HTTP_AUTH_BASIC \ - CONFIG_NGINX_HTTP_AUTH_REQUEST \ - CONFIG_NGINX_HTTP_AUTOINDEX \ - CONFIG_NGINX_HTTP_GEO \ - CONFIG_NGINX_HTTP_MAP \ - CONFIG_NGINX_HTTP_SPLIT_CLIENTS \ - CONFIG_NGINX_HTTP_REFERER \ - CONFIG_NGINX_HTTP_REWRITE \ - CONFIG_NGINX_HTTP_PROXY \ - CONFIG_NGINX_HTTP_FASTCGI \ - CONFIG_NGINX_HTTP_UWSGI \ - CONFIG_NGINX_HTTP_SCGI \ - CONFIG_NGINX_HTTP_MEMCACHED \ - CONFIG_NGINX_HTTP_LIMIT_CONN \ - CONFIG_NGINX_HTTP_LIMIT_REQ \ - CONFIG_NGINX_HTTP_EMPTY_GIF \ - CONFIG_NGINX_HTTP_BROWSER \ - CONFIG_NGINX_HTTP_UPSTREAM_HASH \ - CONFIG_NGINX_HTTP_UPSTREAM_IP_HASH \ - CONFIG_NGINX_HTTP_UPSTREAM_LEAST_CONN \ - CONFIG_NGINX_HTTP_UPSTREAM_KEEPALIVE \ - CONFIG_NGINX_HTTP_UPSTREAM_ZONE \ - CONFIG_NGINX_HTTP_CACHE \ - CONFIG_NGINX_HTTP_V2 \ - CONFIG_NGINX_HTTP_QUIC \ - CONFIG_NGINX_PCRE \ - CONFIG_NGINX_HTTP_REAL_IP \ - CONFIG_NGINX_HTTP_SECURE_LINK \ - CONFIG_NGINX_STREAM_REAL_IP \ - CONFIG_OPENSSL_ENGINE \ - CONFIG_OPENSSL_WITH_NPN \ - $(foreach m,$(PKG_MOD_EXTRA),CONFIG_PACKAGE_$(m)) - -include $(INCLUDE_DIR)/package.mk -include $(INCLUDE_DIR)/nls.mk - -define Package/nginx/default - SECTION:=net - CATEGORY:=Network - SUBMENU:=Web Servers/Proxies - TITLE:=Nginx web server - URL:=http://nginx.org/ - DEPENDS:=+libopenssl +libpthread - # TODO: add PROVIDES when removing nginx - # PROVIDES:=nginx -endef - -define Package/nginx/description - nginx is an HTTP and reverse proxy server, as well as a mail proxy server, \ - written by Igor Sysoev. -endef - -define Package/nginx/conffiles -/etc/nginx/ -endef - -define Package/nginx-ssl - $(Package/nginx/default) - TITLE += with SSL support - VARIANT:=ssl - DEPENDS+= +NGINX_PCRE:libpcre2 \ - +NGINX_PCRE:nginx-ssl-util +!NGINX_PCRE:nginx-ssl-util-nopcre \ - +NGINX_HTTP_GZIP:zlib +NGINX_DAV:libxml2 - EXTRA_DEPENDS:=nginx-ssl-util$(if $(CONFIG_NGINX_PCRE),,-nopcre) (>=1.5-1) (<2) - CONFLICTS:=nginx-full -endef - -Package/nginx-ssl/description = $(Package/nginx/description) \ - This variant is compiled with SSL support enabled. To enable additional module \ - select them in the nginx default configuration menu. - -define Package/nginx-ssl/config - source "$(SOURCE)/Config_ssl.in" -endef - -Package/nginx-ssl/conffiles = $(Package/nginx/conffiles) - -IsEnabled = $(or $(filter full,$(BUILD_VARIANT)),$(CONFIG_$(1))) -IsDisabled = $(if $(call IsEnabled,$(1)),,1) - -config_files := mime.types \ - $(if $(call IsEnabled,NGINX_HTTP_CHARSET),koi-utf koi-win win-utf) \ - $(if $(call IsEnabled,NGINX_HTTP_FASTCGI),fastcgi_params) \ - $(if $(call IsEnabled,NGINX_HTTP_UWSGI),uwsgi_params) \ - $(if $(call IsEnabled,NGINX_HTTP_SCGI),scgi_params) - -define Package/nginx-ssl/install - $(INSTALL_DIR) $(1)/usr/sbin - $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/nginx $(1)/usr/sbin/ - $(INSTALL_BIN) ./files/nginx-proxy-gen $(1)/usr/sbin - $(INSTALL_DIR) $(1)/etc/nginx/module.d - $(INSTALL_DIR) $(1)/etc/nginx/conf.d - $(INSTALL_DATA) $(addprefix $(PKG_INSTALL_DIR)/etc/nginx/,$(config_files)) $(1)/etc/nginx/ - $(INSTALL_DIR) $(1)/etc/init.d - $(INSTALL_BIN) ./files/nginx.init $(1)/etc/init.d/nginx -endef - -define Package/nginx-ssl/prerm -#!/bin/sh -[ -z "$${IPKG_INSTROOT}" ] || exit 0 -[ "$${PKG_UPGRADE}" = "1" ] && exit 0 -eval $$(/usr/bin/nginx-util get_env) -[ "$$(uci get "nginx.$${LAN_NAME}.$${MANAGE_SSL}")" = "self-signed" ] || exit 0 -rm -f "$$(uci get "nginx.$${LAN_NAME}.ssl_certificate")" -rm -f "$$(uci get "nginx.$${LAN_NAME}.ssl_certificate_key")" -exit 0 -endef - -define Package/nginx-full - $(Package/nginx/default) - TITLE += with ALL config selected - DEPENDS+=+libpcre2 +nginx-ssl-util +zlib +libxml2 - EXTRA_DEPENDS:=nginx-ssl-util (>=1.5-1) (<2) - VARIANT:=full - PROVIDES += nginx-ssl -endef - -Package/nginx-full/description = $(Package/nginx/description) \ - This variant is compiled with ALL config selected. - -Package/nginx-full/install = $(Package/nginx-ssl/install) - -Package/nginx-full/prerm = $(Package/nginx-ssl/prerm) - -Package/nginx-full/conffiles = $(Package/nginx/conffiles) - -define Package/nginx-mod-luci - TITLE:=Nginx on LuCI - SECTION:=net - CATEGORY:=Network - SUBMENU:=Web Servers/Proxies - TITLE:=Support file for Nginx - URL:=http://nginx.org/ - DEPENDS:=+uwsgi +uwsgi-luci-support +nginx-ssl +nginx-mod-ubus - # TODO: add PROVIDES when removing nginx-mod-luci-ssl - # PROVIDES:=nginx-mod-luci-ssl -endef - -define Package/nginx-mod-luci/description - Support file for LuCI in nginx. Include custom nginx configuration, autostart script for uwsgi. -endef - -define Package/nginx-mod-luci/install - $(INSTALL_DIR) $(1)/etc/nginx/conf.d - $(INSTALL_CONF) ./files-luci-support/luci.locations $(1)/etc/nginx/conf.d/ - $(INSTALL_DIR) $(1)/etc/uci-defaults - $(INSTALL_BIN) ./files-luci-support/60_nginx-luci-support $(1)/etc/uci-defaults/60_nginx-luci-support -endef - -define Download/nginx-mod-geoip2 - VERSION:=1cabd8a1f68ea3998f94e9f3504431970f848fbf - URL:=https://github.com/leev/ngx_http_geoip2_module.git - MIRROR_HASH:=b4bd8517f6595f28e9cea5370045df476e0f7fa9ca3611d71ba85c518f1a7eda - PROTO:=git -endef - -define Package/nginx-mod-lua-resty-lrucache - $(call Package/nginx/default) - DEPENDS:=@HAS_LUAJIT_ARCH +luajit2 - TITLE:=Nginx Lua OpenResty lrucache module -endef - -define Package/nginx-mod-lua-resty-core - $(call Package/nginx/default) - DEPENDS:=+nginx-mod-lua-resty-lrucache - TITLE:=Nginx Lua OpenResty core module -endef - -define Package/nginx-mod-lua-resty-lrucache/install - $(INSTALL_DIR) $(1)/usr/lib/lua/resty/lrucache - $(INSTALL_BIN) $(PKG_BUILD_DIR)/nginx-mod-lua-resty-lrucache/lib/resty/*.lua $(1)/usr/lib/lua/resty - $(INSTALL_BIN) $(PKG_BUILD_DIR)/nginx-mod-lua-resty-lrucache/lib/resty/lrucache/*.lua $(1)/usr/lib/lua/resty/lrucache -endef - -define Package/nginx-mod-lua-resty-core/install - $(INSTALL_DIR) $(1)/usr/lib/lua/ngx/ssl - $(INSTALL_DIR) $(1)/usr/lib/lua/resty/core - $(INSTALL_BIN) $(PKG_BUILD_DIR)/nginx-mod-lua-resty-core/lib/ngx/*.lua $(1)/usr/lib/lua/ngx - $(INSTALL_BIN) $(PKG_BUILD_DIR)/nginx-mod-lua-resty-core/lib/ngx/ssl/*.lua $(1)/usr/lib/lua/ngx/ssl - $(INSTALL_BIN) $(PKG_BUILD_DIR)/nginx-mod-lua-resty-core/lib/resty/*.lua $(1)/usr/lib/lua/resty - $(INSTALL_BIN) $(PKG_BUILD_DIR)/nginx-mod-lua-resty-core/lib/resty/core/*.lua $(1)/usr/lib/lua/resty/core -endef - -define Download/nginx-mod-headers-more - VERSION:=bea1be3bbf6af28f6aa8cf0c01c07ee1637e2bd0 - URL:=https://github.com/openresty/headers-more-nginx-module.git - MIRROR_HASH:=3617bbf7a935208a1d8d5f86a8f9b770f6987e4d2b5663a9ab1b777217e3066b - PROTO:=git -endef - - -define Download/nginx-mod-brotli - VERSION:=25f86f0bac1101b6512135eac5f93c49c63609e3 - URL:=https://github.com/google/ngx_brotli.git - MIRROR_HASH:=c85cdcfd76703c95aa4204ee4c2e619aa5b075cac18f428202f65552104add3b - PROTO:=git -endef - -define Download/nginx-mod-rtmp - VERSION:=f0ea62342a4eca504b311cd5df910d026c3ea4cf - URL:=https://github.com/ut0mt8/nginx-rtmp-module.git - MIRROR_HASH:=d3f58066f0f858ed79f7f2b0c9b89de2ccc512c94ab3d0625f6dcff3df0b72c1 - PROTO:=git -endef - -define Download/nginx-mod-ts - VERSION:=ef2f874d95cc75747eb625a292524a702aefb0fd - URL:=https://github.com/arut/nginx-ts-module.git - MIRROR_HASH:=73938950bb286d40d9e54b0994d1a63827340c1156c72eb04d7041b25b20ec18 - PROTO:=git -endef - -define Download/nginx-mod-naxsi - VERSION:=d714f1636ea49a9a9f4f06dba14aee003e970834 - URL:=https://github.com/nbs-system/naxsi.git - MIRROR_HASH:=bd006686721a68d43f052f0a4f00e9ff99fb2abfbc4dcf8194a3562fe4e5c08b - PROTO:=git -endef - -define Download/nginx-mod-lua - VERSION:=c89469e920713d17d703a5f3736c9335edac22bf - URL:=https://github.com/openresty/lua-nginx-module.git - MIRROR_HASH:=dd66465f65c094a1ddfff2035bff4da870b7c6b7e033d307a9806a6df290a1a5 - PROTO:=git -endef - -define Download/nginx-mod-lua-resty-core - VERSION:=2e2b2adaa61719972fe4275fa4c3585daa0dcd84 - URL:=https://github.com/openresty/lua-resty-core.git - MIRROR_HASH:=4bfc267fd027161f88fcbeacce38e6bd13ba894a581c2d6dfe78ee270b1a473c - PROTO:=git -endef - -define Download/nginx-mod-lua-resty-lrucache - VERSION:=52f5d00403c8b7aa8a4d4f3779681976b10a18c1 - URL:=https://github.com/openresty/lua-resty-lrucache.git - MIRROR_HASH:=618a972574b6b1db1eebf4046d9a471ac03ec092bb825136ba975928d4af2351 - PROTO:=git -endef - -define Download/nginx-mod-dav-ext - VERSION:=f5e30888a256136d9c550bf1ada77d6ea78a48af - URL:=https://github.com/arut/nginx-dav-ext-module.git - MIRROR_HASH:=70bb4c3907f4b783605500ba494e907aede11f8505702e370012abb3c177dc5b - PROTO:=git -endef - -define Download/nginx-mod-ubus - VERSION:=b2d7260dcb428b2fb65540edb28d7538602b4a26 - URL:=https://github.com/Ansuel/nginx-ubus-module.git - MIRROR_HASH:=472cef416d25effcac66c85417ab6596e634a7a64d45b709bb090892d567553c - PROTO:=git -endef - -define Module/Download - define Download/nginx-mod-$(1) += - - SUBDIR:=nginx-mod-$(1) - FILE:=nginx-mod-$(1)-$$$$(VERSION).tar.xz - endef -endef -$(foreach m,$(PKG_MOD_EXTRA),$(eval $(call Module/Download,$(m)))) - -define Module/nginx-mod-naxsi/install - $(INSTALL_DIR) $(1)/etc/nginx - $(INSTALL_CONF) $(PKG_BUILD_DIR)/nginx-mod-naxsi/naxsi_config/naxsi_core.rules $(1)/etc/nginx -endef - -define Quilt/Refresh/Package - $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(PATCH_DIR)/nginx,nginx/) - $(foreach m,$(PKG_MOD_PATCHED), - $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(PATCH_DIR)/nginx-mod-$(m),nginx-mod-$(m)/) - ) -endef - -define Build/Patch - $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches) - $(call PatchDir,$(PKG_BUILD_DIR),$(PATCH_DIR)/nginx,nginx/) - $(foreach m,$(PKG_MOD_PATCHED),$(if $(or $(CONFIG_PACKAGE_nginx-mod-$(m)),$(QUILT)), - $(call PatchDir,$(PKG_BUILD_DIR),$(PATCH_DIR)/nginx-mod-$(m),nginx-mod-$(m)/) - )) - $(if $(QUILT),touch $(PKG_BUILD_DIR)/.quilt_used) -endef - -define Module/Build/Prepare - $(eval $(call Download,nginx-mod-$(1))) - $(eval $(Download/nginx-mod-$(1))) - mkdir -p $(PKG_BUILD_DIR)/nginx-mod-$(1) - xzcat $(DL_DIR)/$(FILE) | tar -C $(PKG_BUILD_DIR)/nginx-mod-$(1) $(TAR_OPTIONS) --strip-components 1 -endef - -define Build/Prepare - rm -rf $(PKG_BUILD_DIR) - mkdir -p $(PKG_BUILD_DIR) - $(PKG_UNPACK) - - $(foreach m,$(filter-out $(PKG_MOD_PATCHED),$(PKG_MOD_EXTRA)),$(if $(CONFIG_PACKAGE_nginx-mod-$(m)), - $(call Module/Build/Prepare,$(m)) - )) - $(foreach m,$(PKG_MOD_PATCHED),$(if $(or $(CONFIG_PACKAGE_nginx-mod-$(m)),$(QUILT)), - $(call Module/Build/Prepare,$(m)) - )) - $(Build/Patch) -endef - -# $(1) module name -# $(2) module additional dependency -# $(3) module so name (stripped of the finaly _module.so) -# $(4) module description -define BuildModule - define Package/nginx-mod-$(1) - $(call Package/nginx/default) - DEPENDS:=+nginx-ssl $(2) - TITLE:=Nginx $(1) module - endef - - define Package/nginx-mod-$(1)/description - $(strip $(4)) - endef - - define Package/nginx-mod-$(1)/install - $(INSTALL_DIR) $$(1)/usr/lib/nginx/modules - $(foreach m,$(3), - $(CP) $$(PKG_INSTALL_DIR)/usr/lib/nginx/modules/$(m)_module.so $$(1)/usr/lib/nginx/modules - ) - $(call Module/nginx-mod-$(1)/install,$$(1)) - endef - - $$(eval $$(call BuildPackage,nginx-mod-$(1))) -endef - -TARGET_CFLAGS += -DNGX_LUA_NO_BY_LUA_BLOCK - -ifneq ($(CONFIG_PACKAGE_nginx-mod-lua),) - CONFIGURE_VARS += LUAJIT_INC=$(STAGING_DIR)/usr/include/luajit-* \ - LUAJIT_LIB=$(STAGING_DIR)/usr/lib -endif - -CONFIGURE_VARS += CONFIG_BIG_ENDIAN=$(CONFIG_BIG_ENDIAN) - -CONFIGURE_ARGS += \ - --crossbuild=Linux::$(ARCH) \ - --prefix=/usr \ - --conf-path=/etc/nginx/nginx.conf \ - --modules-path=/usr/lib/nginx/modules \ - --error-log-path=stderr \ - --pid-path=/var/run/nginx.pid \ - --lock-path=/var/lock/nginx.lock \ - --http-log-path=/var/log/nginx/access.log \ - --http-client-body-temp-path=/var/lib/nginx/body \ - --http-proxy-temp-path=/var/lib/nginx/proxy \ - --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \ - --with-cc="$(TARGET_CC)" \ - --with-cc-opt="$(TARGET_CPPFLAGS) $(TARGET_CFLAGS)" \ - --with-ld-opt="$(TARGET_LDFLAGS)" \ - --without-http_upstream_zone_module \ - --with-compat \ - --with-http_ssl_module \ - $(if $(call IsDisabled,NGINX_HTTP_CACHE),--without-http-cache) \ - $(if $(call IsDisabled,NGINX_PCRE),--without-pcre) \ - $(if $(call IsDisabled,NGINX_HTTP_CHARSET),--without-http_charset_module) \ - $(if $(call IsDisabled,NGINX_HTTP_GZIP),--without-http_gzip_module) \ - $(if $(call IsDisabled,NGINX_HTTP_SSI),--without-http_ssi_module) \ - $(if $(call IsDisabled,NGINX_HTTP_USERID),--without-http_userid_module) \ - $(if $(call IsDisabled,NGINX_HTTP_ACCESS),--without-http_access_module) \ - $(if $(call IsDisabled,NGINX_HTTP_AUTH_BASIC),--without-http_auth_basic_module) \ - $(if $(call IsDisabled,NGINX_HTTP_AUTOINDEX),--without-http_autoindex_module) \ - $(if $(call IsDisabled,NGINX_HTTP_GEO),--without-http_geo_module) \ - $(if $(call IsDisabled,NGINX_HTTP_MAP),--without-http_map_module) \ - $(if $(call IsDisabled,NGINX_HTTP_SPLIT_CLIENTS),--without-http_split_clients_module) \ - $(if $(call IsDisabled,NGINX_HTTP_REFERER),--without-http_referer_module) \ - $(if $(call IsDisabled,NGINX_HTTP_REWRITE),--without-http_rewrite_module) \ - $(if $(call IsDisabled,NGINX_HTTP_PROXY),--without-http_proxy_module) \ - $(if $(call IsDisabled,NGINX_HTTP_FASTCGI),--without-http_fastcgi_module) \ - $(if $(call IsDisabled,NGINX_HTTP_UWSGI),--without-http_uwsgi_module) \ - $(if $(call IsDisabled,NGINX_HTTP_SCGI),--without-http_scgi_module) \ - $(if $(call IsDisabled,NGINX_HTTP_MEMCACHED),--without-http_memcached_module) \ - $(if $(call IsDisabled,NGINX_HTTP_LIMIT_CONN),--without-http_limit_conn_module) \ - $(if $(call IsDisabled,NGINX_HTTP_LIMIT_REQ),--without-http_limit_req_module) \ - $(if $(call IsDisabled,NGINX_HTTP_EMPTY_GIF),--without-http_empty_gif_module) \ - $(if $(call IsDisabled,NGINX_HTTP_BROWSER),--without-http_browser_module) \ - $(if $(call IsDisabled,NGINX_HTTP_UPSTREAM_HASH),--without-http_upstream_hash_module) \ - $(if $(call IsDisabled,NGINX_HTTP_UPSTREAM_IP_HASH),--without-http_upstream_ip_hash_module) \ - $(if $(call IsDisabled,NGINX_HTTP_UPSTREAM_LEAST_CONN),--without-http_upstream_least_conn_module) \ - $(if $(call IsDisabled,NGINX_HTTP_UPSTREAM_KEEPALIVE),--without-http_upstream_keepalive_module) \ - $(if $(call IsEnabled,IPV6),--with-ipv6) \ - $(if $(call IsEnabled,NGINX_HTTP_GZIP_STATIC),--with-http_gzip_static_module) \ - $(if $(call IsEnabled,NGINX_STUB_STATUS),--with-http_stub_status_module) \ - $(if $(call IsEnabled,NGINX_FLV),--with-http_flv_module) \ - $(if $(call IsEnabled,NGINX_DAV),--with-http_dav_module) \ - $(if $(call IsEnabled,NGINX_HTTP_AUTH_REQUEST),--with-http_auth_request_module) \ - $(if $(call IsEnabled,NGINX_HTTP_QUIC),--with-http_v3_module) \ - $(if $(call IsEnabled,NGINX_HTTP_V2),--with-http_v2_module) \ - $(if $(call IsEnabled,NGINX_HTTP_REAL_IP),--with-http_realip_module) \ - $(if $(call IsEnabled,NGINX_HTTP_SECURE_LINK),--with-http_secure_link_module) \ - $(if $(call IsEnabled,NGINX_HTTP_SUB),--with-http_sub_module) \ - $(if $(CONFIG_PACKAGE_nginx-mod-stream),--with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module) \ - $(if $(call IsEnabled,NGINX_STREAM_REAL_IP),--with-stream_realip_module) \ - $(if $(CONFIG_PACKAGE_nginx-mod-naxsi),--add-dynamic-module=$(PKG_BUILD_DIR)/nginx-mod-naxsi/naxsi_src) \ - $(foreach m,$(filter-out lua-resty-core lua-resty-lrucache naxsi,$(PKG_MOD_EXTRA)), \ - $(if $(CONFIG_PACKAGE_nginx-mod-$(m)),--add-dynamic-module=$(PKG_BUILD_DIR)/nginx-mod-$(m))) - -$(eval $(call BuildPackage,nginx-ssl)) -$(eval $(call BuildPackage,nginx-full)) -$(eval $(call BuildPackage,nginx-mod-luci)) -$(eval $(call BuildPackage,nginx-mod-lua-resty-lrucache)) -$(eval $(call BuildPackage,nginx-mod-lua-resty-core)) -$(eval $(call BuildModule,stream,+@NGINX_STREAM_CORE_MODULE, \ - ngx_stream, Add support for NGINX request streaming.)) -$(eval $(call BuildModule,lua,+nginx-mod-lua-resty-core,ngx_http_lua, \ - Enable Lua module (luajit2 based, OpenResty patches))) -$(eval $(call BuildModule,ubus,+libubus +libjson-c +libblobmsg-json +@NGINX_UBUS, \ - ngx_http_ubus,Enable UBUS api support directly from the server.)) -$(eval $(call BuildModule,dav-ext,+@NGINX_DAV +libxml2,ngx_http_dav_ext, \ - Enable the WebDAV methods PROPFIND OPTIONS LOCK UNLOCK.)) -$(eval $(call BuildModule,headers-more,,ngx_http_headers_more_filter, \ - Set and clear input and output headers...more than "add"!)) -$(eval $(call BuildModule,rtmp,,ngx_rtmp, \ - Add support for NGINX-based Media Streaming Server module. DASH enhanced)) -$(eval $(call BuildModule,ts,,ngx_http_ts, \ - Add support for MPEG-TS Live Module module.)) -$(eval $(call BuildModule,brotli,,ngx_http_brotli_filter ngx_http_brotli_static, \ - Add support for brotli compression module.)) -$(eval $(call BuildModule,naxsi,,ngx_http_naxsi, \ - Enable NAXSI module.)) -$(eval $(call BuildModule,geoip2,+@NGINX_STREAM_CORE_MODULE +libmaxminddb,ngx_http_geoip2 ngx_stream_geoip2, \ - Enable MaxMind GeoIP2 module.)) - -# TODO: remove after a transition period (together with pkg nginx-util): -# It is for smoothly substituting nginx and nginx-mod-luci-ssl (by nginx-ssl -# respectively nginx-mod-luci). Add above commented PROVIDES when removing. - -define Package/nginx - TITLE:=Dummy package for transition when upgrading. - DEPENDS:=+nginx-ssl - PKGARCH:=all -endef - -define Package/nginx/install - $(INSTALL_DIR) $(1)/usr/bin -endef - -$(eval $(call BuildPackage,nginx)) - -define Package/nginx-mod-luci-ssl - TITLE:=Dummy package for transition when upgrading. - DEPENDS:=+nginx-mod-luci - PKGARCH:=all -endef - -define Package/nginx-mod-luci-ssl/install - $(INSTALL_DIR) $(1)/usr/bin -endef - -$(eval $(call BuildPackage,nginx-mod-luci-ssl)) diff --git a/packages/nginx/files-luci-support/60_nginx-luci-support b/packages/nginx/files-luci-support/60_nginx-luci-support deleted file mode 100644 index 22deb97a3..000000000 --- a/packages/nginx/files-luci-support/60_nginx-luci-support +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/sh - -if nginx -V 2>&1 | grep -q ubus && [ -f /usr/lib/nginx/modules/ngx_http_ubus_module.so ]; then - if [ -z "$(cat /etc/nginx/conf.d/luci.locations | grep ubus)" ]; then - cat <> /etc/nginx/conf.d/luci.locations - -location /ubus { - ubus_interpreter; - ubus_socket_path /var/run/ubus/ubus.sock; - ubus_parallel_req 2; -} -EOT - fi - - if [ ! -f "/etc/nginx/module.d/luci.module" ]; then - cat <> /etc/nginx/module.d/luci.module -load_module /usr/lib/nginx/modules/ngx_http_ubus_module.so; -EOT - fi -fi - -grep -q /var/run/ubus.sock /etc/nginx/conf.d/luci.locations && - sed -i 's#/var/run/ubus.sock#/var/run/ubus/ubus.sock#' /etc/nginx/conf.d/luci.locations - -if [ -x /etc/init.d/uhttpd ]; then - /etc/init.d/uhttpd disable - if [ -n "$(pgrep uhttpd)" ]; then - /etc/init.d/uhttpd stop - fi -fi - -/etc/init.d/nginx enable -if [ -n "$(pgrep nginx)" ]; then - /etc/init.d/nginx restart -else - /etc/init.d/nginx start -fi - -/etc/init.d/uwsgi enable -if [ -n "$(pgrep uwsgi)" ]; then - /etc/init.d/uwsgi restart -else - /etc/init.d/uwsgi start -fi - - -exit 0 diff --git a/packages/nginx/files-luci-support/luci.locations b/packages/nginx/files-luci-support/luci.locations deleted file mode 100644 index 374ee5d9f..000000000 --- a/packages/nginx/files-luci-support/luci.locations +++ /dev/null @@ -1,17 +0,0 @@ -location /cgi-bin/luci { - index index.html; - include uwsgi_params; - uwsgi_param SERVER_ADDR $server_addr; - uwsgi_modifier1 9; - uwsgi_pass unix:////var/run/luci-webui.socket; -} -location ~ /cgi-bin/cgi-(backup|download|upload|exec) { - include uwsgi_params; - uwsgi_param SERVER_ADDR $server_addr; - uwsgi_modifier1 9; - uwsgi_pass unix:////var/run/luci-cgi_io.socket; -} - -location /luci-static { - error_log stderr crit; -} diff --git a/packages/nginx/files/nginx.init b/packages/nginx/files/nginx.init deleted file mode 100644 index 11614ec65..000000000 --- a/packages/nginx/files/nginx.init +++ /dev/null @@ -1,115 +0,0 @@ -#!/bin/sh /etc/rc.common -# Copyright (C) 2015 OpenWrt.org - -START=80 - -USE_PROCD=1 - -G_OPTS="daemon off;" - -NGINX_UTIL="/usr/bin/nginx-util" -UCI_CONF_TEMPLATE="/etc/nginx/uci.conf.template" -LATEST_UCI_CONF_VERSION="1.2" - -eval $("${NGINX_UTIL}" get_env) - -CONF="" - -nginx_check_luci_template() { - UCI_CONF_VERSION="$(sed -nr 's/# UCI_CONF_VERSION=(.*)/\1/p' $UCI_CONF_TEMPLATE)" - - # No need to migrate already latest version - if [ "$UCI_CONF_VERSION" = "$LATEST_UCI_CONF_VERSION" ]; then - return - fi - - # Fix wrong entry for the module.d include - if [ "$UCI_CONF_VERSION" = "1.1" ]; then - # Remove any entry - sed -i '/^include module\.d\/\*\.module;/d' $UCI_CONF_TEMPLATE - # Put the include before events {} - sed -i 's/events {/include module.d\/*.module;\n\nevents {/' $UCI_CONF_TEMPLATE - fi - - if [ "$UCI_CONF_VERSION" != "$LATEST_UCI_CONF_VERSION" ]; then - sed -i "s/# UCI_CONF_VERSION=.*/# UCI_CONF_VERSION=$LATEST_UCI_CONF_VERSION/" $UCI_CONF_TEMPLATE - fi - - if [ -z "$UCI_CONF_VERSION" ]; then - # Handle funny case with template with the include module but no version - if ! grep -q -e '^include module\.d/\*\.module;$' $UCI_CONF_TEMPLATE; then - sed -i 's/events {/include module.d\/*.module;\n\nevents {/' $UCI_CONF_TEMPLATE - fi - echo "" >> $UCI_CONF_TEMPLATE - echo "# UCI_CONF_VERSION=1.2" >> $UCI_CONF_TEMPLATE - fi -} - -nginx_init() { - [ -z "${CONF}" ] || return # already called. - - [ -d /var/log/nginx ] || mkdir -p /var/log/nginx - [ -d /var/lib/nginx ] || mkdir -p /var/lib/nginx - - rm -f "$(readlink "${UCI_CONF}")" - ${NGINX_UTIL} init_lan - /usr/sbin/nginx-proxy-gen - - if [ -f $UCI_CONF_TEMPLATE ]; then - nginx_check_luci_template - fi - - if [ -e "${UCI_CONF}" ] - then CONF="${UCI_CONF}" - else CONF="${NGINX_CONF}" - fi - - local message - message="$(/usr/sbin/nginx -t -c "${CONF}" -g "${G_OPTS}" 2>&1)" || - { - echo -e "${message}" | logger -t "nginx_init" -p "daemon.err" - logger -s -t "nginx_init" -p "daemon.err" "NOT using conf file!" - echo "show config to be used by: nginx -T -c '${CONF}'" >&2 - exit 1 - } - - logger -t "nginx_init" -p "daemon.info" "using ${CONF} (the test is ok)" -} - - -start_service() { - nginx_init - - procd_open_instance - procd_set_param command /usr/sbin/nginx -c "${CONF}" -g "${G_OPTS}" - procd_set_param stdout 1 - procd_set_param stderr 1 - procd_set_param file "${CONF}" "${CONF_DIR}*.crt" "${CONF_DIR}*.key" \ - "${CONF_DIR}*.conf" "${CONF_DIR}*.locations" - procd_set_param respawn - procd_close_instance -} - - -reload_service() { - nginx_init - - if [ "$(cat "/proc/$(cat "/var/run/nginx.pid")/cmdline")" = \ - "nginx: master process /usr/sbin/nginx -c ${CONF} -g ${G_OPTS}" ] - then procd_send_signal nginx - else restart - fi -} - - -service_triggers() { - procd_add_raw_trigger acme.renew 5000 /etc/init.d/nginx reload - procd_add_reload_trigger nginx -} - - -extra_command "relog" "Reopen log files (without reloading)" -relog() { - [ -d /var/log/nginx ] || mkdir -p /var/log/nginx - procd_send_signal nginx '*' USR1 -} diff --git a/packages/nginx/patches/nginx-mod-dav-ext/100-drop-libxslt-dep.patch b/packages/nginx/patches/nginx-mod-dav-ext/100-drop-libxslt-dep.patch deleted file mode 100644 index 689898d2f..000000000 --- a/packages/nginx/patches/nginx-mod-dav-ext/100-drop-libxslt-dep.patch +++ /dev/null @@ -1,14 +0,0 @@ ---- a/nginx-mod-dav-ext/config -+++ b/nginx-mod-dav-ext/config -@@ -8,9 +8,8 @@ ngx_module_name=ngx_http_dav_ext_module - # building nginx with the xslt module, in which case libxslt will - # be linked anyway. In other cases libxslt is just redundant. - # If that's a big deal, libxml2 can be linked directly: --# ngx_module_libs=-lxml2 -- --ngx_module_libs=LIBXSLT -+ngx_module_libs=-lxml2 -+ngx_module_incs=$(pkg-config --cflags-only-I libxml-2.0 | sed 's/^-I//') - - ngx_module_srcs="$ngx_addon_dir/ngx_http_dav_ext_module.c" - diff --git a/packages/nginx/patches/nginx-mod-lua-resty-core/001-feature_support_pcre2.patch b/packages/nginx/patches/nginx-mod-lua-resty-core/001-feature_support_pcre2.patch deleted file mode 100644 index a6b1c58e7..000000000 --- a/packages/nginx/patches/nginx-mod-lua-resty-core/001-feature_support_pcre2.patch +++ /dev/null @@ -1,389 +0,0 @@ -From f72675beb5835b4ac31d7476de1580be767209d8 Mon Sep 17 00:00:00 2001 -From: swananan -Date: Thu, 31 Aug 2023 00:12:07 +0800 -Subject: [PATCH] feature: support pcre2 - ---- - .travis.yml | 26 +++++++++++++----------- - lib/resty/core/regex.lua | 43 ++++++++++++++++++++++++++++++---------- - t/re-base.t | 25 +++++++++++++++++------ - t/re-gmatch.t | 10 +++++++--- - t/re-match.t | 7 +++++-- - t/re-opt.t | 9 +++++++-- - t/stream/re-base.t | 27 +++++++++++++++++++------ - t/stream/re-gmatch.t | 10 +++++++--- - t/stream/re-match.t | 7 +++++-- - t/stream/re-opt.t | 9 +++++++-- - 10 files changed, 125 insertions(+), 48 deletions(-) - ---- a/nginx-mod-lua-resty-core/.travis.yml -+++ b/nginx-mod-lua-resty-core/.travis.yml -@@ -34,9 +34,13 @@ env: - - LUA_INCLUDE_DIR=$LUAJIT_INC - - LUA_CMODULE_DIR=/lib - - PCRE_VER=8.45 -+ - PCRE2_VER=10.37 - - PCRE_PREFIX=/opt/pcre -+ - PCRE2_PREFIX=/opt/pcre2 - - PCRE_LIB=$PCRE_PREFIX/lib -+ - PCRE2_LIB=$PCRE2_PREFIX/lib - - PCRE_INC=$PCRE_PREFIX/include -+ - PCRE2_INC=$PCRE2_PREFIX/include - - OPENSSL_PREFIX=/opt/ssl - - OPENSSL_LIB=$OPENSSL_PREFIX/lib - - OPENSSL_INC=$OPENSSL_PREFIX/include -@@ -45,7 +49,7 @@ env: - - TEST_NGINX_RANDOMIZE=1 - - LUACHECK_VER=0.21.1 - matrix: -- - NGINX_VERSION=1.25.1 OPENSSL_VER=1.1.1u OPENSSL_PATCH_VER=1.1.1f -+ - NGINX_VERSION=1.25.1 OPENSSL_VER=1.1.1u OPENSSL_PATCH_VER=1.1.1f USE_PCRE2=Y - - NGINX_VERSION=1.21.4 OPENSSL_VER=1.1.1u OPENSSL_PATCH_VER=1.1.1f - - services: -@@ -61,11 +65,12 @@ before_install: - install: - - if [ ! -d download-cache ]; then mkdir download-cache; fi - - if [ ! -f download-cache/openssl-$OPENSSL_VER.tar.gz ]; then wget -P download-cache https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz || wget -P download-cache https://www.openssl.org/source/old/${OPENSSL_VER//[a-z]/}/openssl-$OPENSSL_VER.tar.gz; fi -- - if [ ! -f download-cache/pcre-$PCRE_VER.tar.gz ]; then wget -P download-cache http://ftp.cs.stanford.edu/pub/exim/pcre/pcre-$PCRE_VER.tar.gz; fi -+ - if [ "$USE_PCRE2" != "Y" ] && [ ! -f download-cache/pcre-$PCRE_VER.tar.gz ]; then wget -P download-cache http://ftp.cs.stanford.edu/pub/exim/pcre/pcre-$PCRE_VER.tar.gz; fi -+ - if [ "$USE_PCRE2" = "Y" ] && [ ! -f download-cache/pcre2-$PCRE2_VER.tar.gz ]; then wget -P download-cache https://downloads.sourceforge.net/project/pcre/pcre2/${PCRE2_VER}/pcre2-${PCRE2_VER}.tar.gz; fi - - git clone https://github.com/openresty/openresty.git ../openresty - - git clone https://github.com/openresty/openresty-devel-utils.git - - git clone https://github.com/simpl/ngx_devel_kit.git ../ndk-nginx-module -- - git clone https://github.com/openresty/lua-nginx-module.git ../lua-nginx-module -+ - git clone https://github.com/swananan/lua-nginx-module.git -b support_pcre2 ../lua-nginx-module - - git clone https://github.com/openresty/no-pool-nginx.git ../no-pool-nginx - - git clone https://github.com/openresty/echo-nginx-module.git ../echo-nginx-module - - git clone https://github.com/openresty/lua-resty-lrucache.git -@@ -73,8 +78,8 @@ install: - - git clone -b v2.1-agentzh https://github.com/openresty/luajit2.git luajit2 - - git clone https://github.com/openresty/set-misc-nginx-module.git ../set-misc-nginx-module - - git clone https://github.com/openresty/mockeagain.git -- - git clone https://github.com/openresty/test-nginx.git -- - git clone https://github.com/openresty/stream-lua-nginx-module.git ../stream-lua-nginx-module -+ - git clone https://github.com/swananan/test-nginx.git -b support_pcre2 -+ - git clone https://github.com/swananan/stream-lua-nginx-module.git -b support_pcre2 ../stream-lua-nginx-module - - script: - - cd luajit2/ -@@ -89,12 +94,8 @@ script: - - make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1) - - sudo make PATH=$PATH install_sw > build.log 2>&1 || (cat build.log && exit 1) - - cd ../mockeagain/ && make CC=$CC -j$JOBS && cd .. -- - tar zxf download-cache/pcre-$PCRE_VER.tar.gz -- - cd pcre-$PCRE_VER/ -- - ./configure --prefix=$PCRE_PREFIX --enable-jit --enable-utf --enable-unicode-properties > build.log 2>&1 || (cat build.log && exit 1) -- - make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1) -- - sudo PATH=$PATH make install > build.log 2>&1 || (cat build.log && exit 1) -- - cd .. -+ - if [ "$USE_PCRE2" != "Y" ]; then tar zxf download-cache/pcre-$PCRE_VER.tar.gz; cd pcre-$PCRE_VER/; ./configure --prefix=$PCRE_PREFIX --enable-jit --enable-utf --enable-unicode-properties > build.log 2>&1 || (cat build.log && exit 1); make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1); sudo PATH=$PATH make install > build.log 2>&1 || (cat build.log && exit 1); cd ..; fi -+ - if [ "$USE_PCRE2" = "Y" ]; then tar zxf download-cache/pcre2-$PCRE2_VER.tar.gz; cd pcre2-$PCRE2_VER/; ./configure --prefix=$PCRE2_PREFIX --enable-jit --enable-utf > build.log 2>&1 || (cat build.log && exit 1); make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1); sudo PATH=$PATH make install > build.log 2>&1 || (cat build.log && exit 1); cd ..; fi - - export PATH=$PWD/work/nginx/sbin:$PWD/openresty-devel-utils:$PATH - - export LD_PRELOAD=$PWD/mockeagain/mockeagain.so - - export LD_LIBRARY_PATH=$PWD/mockeagain:$LD_LIBRARY_PATH -@@ -104,7 +105,8 @@ script: - - export disable_pcre2=--without-pcre2 - - answer=`util/ver-ge "$NGINX_VERSION" 1.25.1` - - if [ "$OPENSSL_VER" = "1.1.0l" ] || [ "$answer" = "N" ]; then add_http3_module=""; fi -- - if [ "$answer" = "N" ]; then disable_pcre2=""; fi -+ - if [ "$answer" = "N" ] || [ "$USE_PCRE2" = "Y" ]; then disable_pcre2=""; fi -+ - if [ "$USE_PCRE2" = "Y" ]; then PCRE_INC=$PCRE2_INC; PCRE_LIB=$PCRE2_LIB; fi - - ngx-build $NGINX_VERSION --with-ipv6 $disable_pcre2 $add_http3_module --with-http_realip_module --with-http_ssl_module --with-pcre-jit --with-cc-opt="-I$OPENSSL_INC -I$PCRE_INC" --with-ld-opt="-L$OPENSSL_LIB -Wl,-rpath,$OPENSSL_LIB -L$PCRE_LIB -Wl,-rpath,$PCRE_LIB" --add-module=../ndk-nginx-module --add-module=../echo-nginx-module --add-module=../set-misc-nginx-module --add-module=../headers-more-nginx-module --add-module=../lua-nginx-module --with-debug --with-stream_ssl_module --with-stream --with-ipv6 --add-module=../stream-lua-nginx-module > build.log 2>&1 || (cat build.log && exit 1) - - nginx -V - - ldd `which nginx`|grep -E 'luajit|ssl|pcre' ---- a/nginx-mod-lua-resty-core/lib/resty/core/regex.lua -+++ b/nginx-mod-lua-resty-core/lib/resty/core/regex.lua -@@ -82,7 +82,7 @@ if not pcall(function() pcre_ver = ffi_s - end - - --local MAX_ERR_MSG_LEN = 128 -+local MAX_ERR_MSG_LEN = 256 - - - local FLAG_COMPILE_ONCE = 0x01 -@@ -102,6 +102,7 @@ local PCRE_DUPNAMES = 0x0080000 - local PCRE_JAVASCRIPT_COMPAT = 0x2000000 - - -+-- PCRE2_ERROR_NOMATCH uses the same value - local PCRE_ERROR_NOMATCH = -1 - - -@@ -135,22 +136,44 @@ local ngx_lua_ffi_script_eval_data - -- TODO: improve this workaround when PCRE allows for unspecifying the MAP_JIT - -- option. - local no_jit_in_init -+local pcre_ver_num - --if jit.os == "OSX" then -- local maj, min = string.match(pcre_ver, "^(%d+)%.(%d+)") -- if maj and min then -- local pcre_ver_num = tonumber(maj .. min) -- -- if pcre_ver_num >= 843 then -- no_jit_in_init = true -- end -+local maj, min = string.match(pcre_ver, "^(%d+)%.(%d+)") -+if maj and min then -+ pcre_ver_num = tonumber(maj .. min) -+end - -- else -+if jit.os == "OSX" then -+ if pcre_ver_num == nil then - -- assume this version is faulty as well - no_jit_in_init = true -+ -+ -- PCRE2 is also subject to this issue on macOS -+ elseif pcre_ver_num >= 843 then -+ no_jit_in_init = true - end - end - -+-- pcre2 -+if pcre_ver_num > 845 then -+ -- option -+ PCRE_CASELESS = 0x00000008 -+ PCRE_MULTILINE = 0x00000400 -+ PCRE_DOTALL = 0x00000020 -+ PCRE_EXTENDED = 0x00000080 -+ PCRE_ANCHORED = 0x80000000 -+ PCRE_UTF8 = 0x00080000 -+ PCRE_DUPNAMES = 0x00000040 -+ -- In the pcre2, The PCRE_JAVASCRIPT_COMPAT option has been split into -+ -- independent functional options PCRE2_ALT_BSUX, PCRE2_ALLOW_EMPTY_CLASS, -+ -- and PCRE2_MATCH_UNSET_BACKREF. -+ local PCRE2_ALT_BSUX = 0x00000002 -+ local PCRE2_ALLOW_EMPTY_CLASS = 0x00000001 -+ local PCRE2_MATCH_UNSET_BACKREF = 0x00000200 -+ PCRE_JAVASCRIPT_COMPAT = bor(PCRE2_ALT_BSUX, PCRE2_ALLOW_EMPTY_CLASS) -+ PCRE_JAVASCRIPT_COMPAT = bor(PCRE2_MATCH_UNSET_BACKREF, -+ PCRE_JAVASCRIPT_COMPAT) -+end - - if subsystem == 'http' then - ffi.cdef[[ ---- a/nginx-mod-lua-resty-core/t/re-base.t -+++ b/nginx-mod-lua-resty-core/t/re-base.t -@@ -26,8 +26,11 @@ __DATA__ - } - --- request - GET /re ----- response_body --error: pcre_compile() failed: missing ) in "(abc" -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n" -+: -+"error: pcre_compile() failed: missing ) in \"(abc\"\n" - --- no_error_log - [error] - -@@ -63,8 +66,11 @@ error: pcre_compile() failed: missing ) - } - --- request - GET /t ----- response_body_like chop --error: pcre_exec\(\) failed: -10 -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre_exec\(\) failed: -4\n" -+: -+"error: pcre_exec\(\) failed: -10\n" - - --- no_error_log - [error] -@@ -128,6 +134,7 @@ probe process("$LIBPCRE_PATH").function( - printf("exec opts: %x\n", $options) - } - -+# TODO: PCRE2 use different option values from PCRE - --- stap_out - compile opts: 800 - exec opts: 0 -@@ -172,8 +179,14 @@ end - - --- request - GET /re ----- response_body --error: pcre_exec() failed: -8 -+--- response_body eval -+# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE, -+# but PCRE2 replaces this with pcre2_set_match_limit interface, -+# which has different effects. -+$Test::Nginx::Util::PcreVersion == 2 ? -+"failed to match\n" -+: -+"error: pcre_exec() failed: -8\n" - - - ---- a/nginx-mod-lua-resty-core/t/re-gmatch.t -+++ b/nginx-mod-lua-resty-core/t/re-gmatch.t -@@ -446,9 +446,13 @@ matched: nil - } - --- request - GET /re ----- response_body --error: pcre_exec() failed: -10 --not matched -+--- response_body eval -+# PCRE2_ERROR_UTF8_ERR2 (-4) -+# PCRE_ERROR_BADUTF8 (-10) -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre_exec\(\) failed: -4\nnot matched\n" -+: -+"error: pcre_exec\(\) failed: -10\nnot matched\n" - --- no_error_log - [error] - ---- a/nginx-mod-lua-resty-core/t/re-match.t -+++ b/nginx-mod-lua-resty-core/t/re-match.t -@@ -306,8 +306,11 @@ NYI - } - --- request - GET /re ----- response_body_like chop --error: pcre_compile\(\) failed: two named subpatterns have the same name -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile\(\) failed: two named subpatterns have the same name \(PCRE2_DUPNAMES not set\) in \"\(\?[a-z])\(\?[a-z]+\), [0-9]+\" at \"[a-z]+\), [0-9]+\"\n" -+: -+"error: pcre_compile\(\) failed: two named subpatterns have the same name in \"\(\?[a-z])\(\?[a-z]+\), [0-9]+\" at \">[a-z]+\), [0-9]+\"\n" - - --- error_log eval - qr/\[TRACE\s+\d+/ ---- a/nginx-mod-lua-resty-core/t/re-opt.t -+++ b/nginx-mod-lua-resty-core/t/re-opt.t -@@ -39,8 +39,13 @@ __DATA__ - } - --- request - GET /re ----- response_body --error: pcre_exec() failed: -27 -+--- response_body eval -+# PCRE2_ERROR_JIT_STACKLIMIT (-46) -+# PCRE_ERROR_JIT_STACKLIMIT (-27) -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre_exec\(\) failed: -46\n" -+: -+"error: pcre_exec\(\) failed: -27\n" - --- no_error_log - [error] - --- timeout: 10 ---- a/nginx-mod-lua-resty-core/t/stream/re-base.t -+++ b/nginx-mod-lua-resty-core/t/stream/re-base.t -@@ -22,8 +22,11 @@ __DATA__ - ngx.say("error: ", err) - end - } ----- stream_response --error: pcre_compile() failed: missing ) in "(abc" -+--- stream_response eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n" -+: -+"error: pcre_compile() failed: missing ) in \"(abc\"\n" - --- no_error_log - [error] - -@@ -55,12 +58,17 @@ error: pcre_compile() failed: missing ) - ngx.say("not matched") - end - } ----- stream_response_like chop --error: pcre_exec\(\) failed: -10 -+--- stream_response eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre_exec\(\) failed: -4\n" -+: -+"error: pcre_exec\(\) failed: -10\n" - - --- no_error_log - [error] - -+--- ONLY -+ - - - === TEST 3: UTF-8 mode without UTF-8 sequence checks -@@ -114,6 +122,7 @@ probe process("$LIBPCRE_PATH").function( - printf("exec opts: %x\n", $options) - } - -+# TODO: PCRE2 use different option values from PCRE - --- stap_out - compile opts: 800 - exec opts: 0 -@@ -152,8 +161,14 @@ if not res then - return - end - ----- stream_response --error: pcre_exec() failed: -8 -+--- stream_response eval -+# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE, -+# but PCRE2 replaces this with pcre2_set_match_limit interface, -+# which has different effects. -+$Test::Nginx::Util::PcreVersion == 2 ? -+"failed to match\n" -+: -+"error: pcre_exec() failed: -8\n" - - - ---- a/nginx-mod-lua-resty-core/t/stream/re-gmatch.t -+++ b/nginx-mod-lua-resty-core/t/stream/re-gmatch.t -@@ -394,9 +394,13 @@ matched: nil - ngx.say("not matched") - end - } ----- stream_response --error: pcre_exec() failed: -10 --not matched -+--- stream_response eval -+# PCRE2_ERROR_UTF8_ERR2 (-4) -+# PCRE_ERROR_BADUTF8 (-10) -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre_exec\(\) failed: -4\nnot matched\n" -+: -+"error: pcre_exec\(\) failed: -10\nnot matched\n" - --- no_error_log - [error] - ---- a/nginx-mod-lua-resty-core/t/stream/re-match.t -+++ b/nginx-mod-lua-resty-core/t/stream/re-match.t -@@ -268,8 +268,11 @@ NYI - ngx.say("not matched!") - end - } ----- stream_response_like chop --error: pcre_compile\(\) failed: two named subpatterns have the same name -+--- stream_response eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile\(\) failed: two named subpatterns have the same name \(PCRE2_DUPNAMES not set\) in \"\(\?[a-z])\(\?[a-z]+\), [0-9]+\" at \"[a-z]+\), [0-9]+\"\n" -+: -+"error: pcre_compile\(\) failed: two named subpatterns have the same name in \"\(\?[a-z])\(\?[a-z]+\), [0-9]+\" at \">[a-z]+\), [0-9]+\"\n" - - --- error_log eval - qr/\[TRACE\s+\d+/ ---- a/nginx-mod-lua-resty-core/t/stream/re-opt.t -+++ b/nginx-mod-lua-resty-core/t/stream/re-opt.t -@@ -36,8 +36,13 @@ __DATA__ - ngx.say("not matched!") - end - } ----- stream_response --error: pcre_exec() failed: -27 -+--- stream_response eval -+# PCRE2_ERROR_JIT_STACKLIMIT (-46) -+# PCRE_ERROR_JIT_STACKLIMIT (-27) -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre_exec\(\) failed: -46\n" -+: -+"error: pcre_exec\(\) failed: -27\n" - --- no_error_log - [error] - --- timeout: 10 diff --git a/packages/nginx/patches/nginx-mod-lua/001-feature_support_pcre2.patch b/packages/nginx/patches/nginx-mod-lua/001-feature_support_pcre2.patch deleted file mode 100644 index b789984aa..000000000 --- a/packages/nginx/patches/nginx-mod-lua/001-feature_support_pcre2.patch +++ /dev/null @@ -1,2009 +0,0 @@ -From 26b48c5a9d1b35990064ddcd686f587c663b6048 Mon Sep 17 00:00:00 2001 -From: swananan -Date: Tue, 5 Sep 2023 18:42:20 +0800 -Subject: [PATCH 1/4] feature: support pcre2 - ---- - .travis.yml | 23 +- - src/ngx_http_lua_common.h | 10 +- - src/ngx_http_lua_module.c | 14 + - src/ngx_http_lua_pcrefix.c | 89 +++++- - src/ngx_http_lua_pcrefix.h | 9 +- - src/ngx_http_lua_regex.c | 538 +++++++++++++++++++++++++++++++------ - t/028-req-header.t | 1 - - t/034-match.t | 32 ++- - t/035-gmatch.t | 24 +- - t/036-sub.t | 24 +- - t/037-gsub.t | 17 +- - t/038-match-o.t | 7 +- - t/047-match-jit.t | 18 +- - t/049-gmatch-jit.t | 7 +- - t/050-gmatch-dfa.t | 7 +- - t/051-sub-jit.t | 14 +- - t/052-sub-dfa.t | 14 +- - t/053-gsub-jit.t | 14 +- - t/054-gsub-dfa.t | 14 +- - t/120-re-find.t | 25 +- - util/build-with-dd.sh | 6 +- - util/build-without-ssl.sh | 6 +- - util/build.sh | 6 +- - 23 files changed, 764 insertions(+), 155 deletions(-) - ---- a/nginx-mod-lua/.travis.yml -+++ b/nginx-mod-lua/.travis.yml -@@ -38,9 +38,13 @@ env: - - LUAJIT_INC=$LUAJIT_PREFIX/include/luajit-2.1 - - LUA_INCLUDE_DIR=$LUAJIT_INC - - PCRE_VER=8.45 -+ - PCRE2_VER=10.37 - - PCRE_PREFIX=/opt/pcre -+ - PCRE2_PREFIX=/opt/pcre2 - - PCRE_LIB=$PCRE_PREFIX/lib -+ - PCRE2_LIB=$PCRE2_PREFIX/lib - - PCRE_INC=$PCRE_PREFIX/include -+ - PCRE2_INC=$PCRE2_PREFIX/include - - OPENSSL_PREFIX=/opt/ssl - - OPENSSL_LIB=$OPENSSL_PREFIX/lib - - OPENSSL_INC=$OPENSSL_PREFIX/include -@@ -55,7 +59,7 @@ env: - - NGINX_VERSION=1.21.4 OPENSSL_VER=1.1.0l OPENSSL_PATCH_VER=1.1.0d - - NGINX_VERSION=1.21.4 OPENSSL_VER=1.1.1s OPENSSL_PATCH_VER=1.1.1f - - NGINX_VERSION=1.25.1 OPENSSL_VER=1.1.0l OPENSSL_PATCH_VER=1.1.0d -- - NGINX_VERSION=1.25.1 OPENSSL_VER=1.1.1s OPENSSL_PATCH_VER=1.1.1f -+ - NGINX_VERSION=1.25.1 OPENSSL_VER=1.1.1s OPENSSL_PATCH_VER=1.1.1f USE_PCRE2=Y - - services: - - memcached -@@ -71,9 +75,10 @@ before_install: - - pyenv global 2.7 - install: - - if [ ! -f download-cache/drizzle7-$DRIZZLE_VER.tar.gz ]; then wget -P download-cache http://openresty.org/download/drizzle7-$DRIZZLE_VER.tar.gz; fi -- - if [ ! -f download-cache/pcre-$PCRE_VER.tar.gz ]; then wget -P download-cache https://downloads.sourceforge.net/project/pcre/pcre/${PCRE_VER}/pcre-${PCRE_VER}.tar.gz; fi -+ - if [ "$USE_PCRE2" != "Y" ] && [ ! -f download-cache/pcre-$PCRE_VER.tar.gz ]; then wget -P download-cache https://downloads.sourceforge.net/project/pcre/pcre/${PCRE_VER}/pcre-${PCRE_VER}.tar.gz; fi -+ - if [ "$USE_PCRE2" = "Y" ] && [ ! -f download-cache/pcre2-$PCRE2_VER.tar.gz ]; then wget -P download-cache https://downloads.sourceforge.net/project/pcre/pcre2/${PCRE2_VER}/pcre2-${PCRE2_VER}.tar.gz; fi - - if [ ! -f download-cache/openssl-$OPENSSL_VER.tar.gz ]; then wget -P download-cache https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz || wget -P download-cache https://www.openssl.org/source/old/${OPENSSL_VER//[a-z]/}/openssl-$OPENSSL_VER.tar.gz; fi -- - git clone https://github.com/openresty/test-nginx.git -+ - git clone https://github.com/swananan/test-nginx.git -b support_pcre2 - - git clone https://github.com/openresty/openresty.git ../openresty - - git clone https://github.com/openresty/no-pool-nginx.git ../no-pool-nginx - - git clone https://github.com/openresty/openresty-devel-utils.git -@@ -91,12 +96,12 @@ install: - - git clone https://github.com/openresty/rds-json-nginx-module.git ../rds-json-nginx-module - - git clone https://github.com/openresty/srcache-nginx-module.git ../srcache-nginx-module - - git clone https://github.com/openresty/redis2-nginx-module.git ../redis2-nginx-module -- - git clone https://github.com/openresty/lua-resty-core.git ../lua-resty-core -+ - git clone https://github.com/swananan/lua-resty-core.git -b support_pcre2 ../lua-resty-core - - git clone https://github.com/openresty/lua-resty-lrucache.git ../lua-resty-lrucache - - git clone https://github.com/openresty/lua-resty-mysql.git ../lua-resty-mysql - - git clone https://github.com/spacewander/lua-resty-rsa.git ../lua-resty-rsa - - git clone https://github.com/openresty/lua-resty-string.git ../lua-resty-string -- - git clone https://github.com/openresty/stream-lua-nginx-module.git ../stream-lua-nginx-module -+ - git clone https://github.com/swananan/stream-lua-nginx-module.git -b support_pcre2 ../stream-lua-nginx-module - - git clone -b v2.1-agentzh https://github.com/openresty/luajit2.git luajit2 - - before_script: -@@ -121,12 +126,8 @@ script: - - sudo make install-libdrizzle-1.0 > build.log 2>&1 || (cat build.log && exit 1) - - cd ../mockeagain/ && make CC=$CC -j$JOBS && cd .. - - cd lua-cjson/ && make -j$JOBS && sudo make install && cd .. -- - tar zxf download-cache/pcre-$PCRE_VER.tar.gz -- - cd pcre-$PCRE_VER/ -- - ./configure --prefix=$PCRE_PREFIX --enable-jit --enable-utf --enable-unicode-properties > build.log 2>&1 || (cat build.log && exit 1) -- - make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1) -- - sudo PATH=$PATH make install > build.log 2>&1 || (cat build.log && exit 1) -- - cd .. -+ - if [ "$USE_PCRE2" != "Y" ]; then tar zxf download-cache/pcre-$PCRE_VER.tar.gz; cd pcre-$PCRE_VER/; ./configure --prefix=$PCRE_PREFIX --enable-jit --enable-utf --enable-unicode-properties > build.log 2>&1 || (cat build.log && exit 1); make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1); sudo PATH=$PATH make install > build.log 2>&1 || (cat build.log && exit 1); cd ..; fi -+ - if [ "$USE_PCRE2" = "Y" ]; then tar zxf download-cache/pcre2-$PCRE2_VER.tar.gz; cd pcre2-$PCRE2_VER/; ./configure --prefix=$PCRE2_PREFIX --enable-jit --enable-utf > build.log 2>&1 || (cat build.log && exit 1); make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1); sudo PATH=$PATH make install > build.log 2>&1 || (cat build.log && exit 1); cd ..; fi - - tar zxf download-cache/openssl-$OPENSSL_VER.tar.gz - - cd openssl-$OPENSSL_VER/ - - patch -p1 < ../../openresty/patches/openssl-$OPENSSL_PATCH_VER-sess_set_get_cb_yield.patch ---- a/nginx-mod-lua/src/ngx_http_lua_common.h -+++ b/nginx-mod-lua/src/ngx_http_lua_common.h -@@ -63,6 +63,10 @@ typedef struct { - # endif - #endif - -+#if (NGX_PCRE2) -+# define LUA_HAVE_PCRE_JIT 1 -+#endif -+ - - #if (nginx_version < 1006000) - # error at least nginx 1.6.0 is required but found an older version -@@ -217,11 +221,13 @@ struct ngx_http_lua_main_conf_s { - - ngx_hash_t builtin_headers_out; - --#if (NGX_PCRE) -+#if (NGX_PCRE || NGX_PCRE2) - ngx_int_t regex_cache_entries; - ngx_int_t regex_cache_max_entries; - ngx_int_t regex_match_limit; --# if (LUA_HAVE_PCRE_JIT) -+#if (NGX_PCRE2) -+ pcre2_jit_stack *jit_stack; -+#elif (LUA_HAVE_PCRE_JIT) - pcre_jit_stack *jit_stack; - # endif - #endif ---- a/nginx-mod-lua/src/ngx_http_lua_module.c -+++ b/nginx-mod-lua/src/ngx_http_lua_module.c -@@ -59,6 +59,9 @@ static char *ngx_http_lua_ssl_conf_comma - #endif - static char *ngx_http_lua_malloc_trim(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); -+#if (NGX_PCRE2) -+extern void ngx_http_lua_regex_cleanup(void *data); -+#endif - - - static ngx_conf_post_t ngx_http_lua_lowat_post = -@@ -855,6 +858,17 @@ ngx_http_lua_init(ngx_conf_t *cf) - cln->data = lmcf; - cln->handler = ngx_http_lua_sema_mm_cleanup; - -+#if (NGX_PCRE2) -+ /* add the cleanup of pcre2 regex */ -+ cln = ngx_pool_cleanup_add(cf->pool, 0); -+ if (cln == NULL) { -+ return NGX_ERROR; -+ } -+ -+ cln->data = lmcf; -+ cln->handler = ngx_http_lua_regex_cleanup; -+#endif -+ - #ifdef HAVE_NGX_LUA_PIPE - ngx_http_lua_pipe_init(); - #endif ---- a/nginx-mod-lua/src/ngx_http_lua_pcrefix.c -+++ b/nginx-mod-lua/src/ngx_http_lua_pcrefix.c -@@ -14,19 +14,65 @@ - #include "ngx_http_lua_pcrefix.h" - #include "stdio.h" - --#if (NGX_PCRE) -+#if (NGX_PCRE || NGX_PCRE2) - - static ngx_pool_t *ngx_http_lua_pcre_pool = NULL; - -+ -+#if (NGX_PCRE2) -+static ngx_uint_t ngx_regex_direct_alloc; -+#else - static void *(*old_pcre_malloc)(size_t); - static void (*old_pcre_free)(void *ptr); -+#endif - - - /* XXX: work-around to nginx regex subsystem, must init a memory pool - * to use PCRE functions. As PCRE still has memory-leaking problems, - * and nginx overwrote pcre_malloc/free hooks with its own static - * functions, so nobody else can reuse nginx regex subsystem... */ --static void * -+#if (NGX_PCRE2) -+ -+void * -+ngx_http_lua_pcre_malloc(size_t size, void *data) -+{ -+ dd("lua pcre pool is %p", ngx_http_lua_pcre_pool); -+ -+ if (ngx_http_lua_pcre_pool) { -+ return ngx_palloc(ngx_http_lua_pcre_pool, size); -+ } -+ -+ if (ngx_regex_direct_alloc) { -+ return ngx_alloc(size, ngx_cycle->log); -+ } -+ -+ fprintf(stderr, "error: lua pcre malloc failed due to empty pcre pool"); -+ -+ return NULL; -+} -+ -+ -+void -+ngx_http_lua_pcre_free(void *ptr, void *data) -+{ -+ dd("lua pcre pool is %p", ngx_http_lua_pcre_pool); -+ -+ if (ngx_http_lua_pcre_pool) { -+ ngx_pfree(ngx_http_lua_pcre_pool, ptr); -+ return; -+ } -+ -+ if (ngx_regex_direct_alloc) { -+ ngx_free(ptr); -+ return; -+ } -+ -+ fprintf(stderr, "error: lua pcre free failed due to empty pcre pool"); -+} -+ -+#else -+ -+void * - ngx_http_lua_pcre_malloc(size_t size) - { - dd("lua pcre pool is %p", ngx_http_lua_pcre_pool); -@@ -54,6 +100,41 @@ ngx_http_lua_pcre_free(void *ptr) - fprintf(stderr, "error: lua pcre free failed due to empty pcre pool"); - } - -+#endif -+ -+ -+#if (NGX_PCRE2) -+ -+ngx_pool_t * -+ngx_http_lua_pcre_malloc_init(ngx_pool_t *pool) -+{ -+ ngx_pool_t *old_pool; -+ -+ dd("lua pcre pool was %p", ngx_http_lua_pcre_pool); -+ -+ ngx_regex_direct_alloc = (pool == NULL) ? 1 : 0; -+ -+ old_pool = ngx_http_lua_pcre_pool; -+ ngx_http_lua_pcre_pool = pool; -+ -+ dd("lua pcre pool is %p", ngx_http_lua_pcre_pool); -+ -+ return old_pool; -+} -+ -+ -+void -+ngx_http_lua_pcre_malloc_done(ngx_pool_t *old_pool) -+{ -+ dd("lua pcre pool was %p", ngx_http_lua_pcre_pool); -+ -+ ngx_http_lua_pcre_pool = old_pool; -+ ngx_regex_direct_alloc = 0; -+ -+ dd("lua pcre pool is %p", ngx_http_lua_pcre_pool); -+} -+ -+#else - - ngx_pool_t * - ngx_http_lua_pcre_malloc_init(ngx_pool_t *pool) -@@ -101,6 +182,7 @@ ngx_http_lua_pcre_malloc_done(ngx_pool_t - } - } - --#endif /* NGX_PCRE */ -+#endif -+#endif /* NGX_PCRE || NGX_PCRE2 */ - - /* vi:set ft=c ts=4 sw=4 et fdm=marker: */ ---- a/nginx-mod-lua/src/ngx_http_lua_pcrefix.h -+++ b/nginx-mod-lua/src/ngx_http_lua_pcrefix.h -@@ -12,9 +12,16 @@ - #include "ngx_http_lua_common.h" - - --#if (NGX_PCRE) -+#if (NGX_PCRE || NGX_PCRE2) -+ - ngx_pool_t *ngx_http_lua_pcre_malloc_init(ngx_pool_t *pool); - void ngx_http_lua_pcre_malloc_done(ngx_pool_t *old_pool); -+ -+#if NGX_PCRE2 -+void *ngx_http_lua_pcre_malloc(size_t size, void *data); -+void ngx_http_lua_pcre_free(void *ptr, void *data); -+#endif -+ - #endif - - ---- a/nginx-mod-lua/src/ngx_http_lua_regex.c -+++ b/nginx-mod-lua/src/ngx_http_lua_regex.c -@@ -9,21 +9,31 @@ - #endif - #include "ddebug.h" - -- --#if (NGX_PCRE) -+#if (NGX_PCRE || NGX_PCRE2) - - #include "ngx_http_lua_pcrefix.h" - #include "ngx_http_lua_script.h" - #include "ngx_http_lua_util.h" - - --#if (PCRE_MAJOR >= 6) -+#if (PCRE_MAJOR >= 6 || NGX_PCRE2) - # define LUA_HAVE_PCRE_DFA 1 - #else - # define LUA_HAVE_PCRE_DFA 0 - #endif - - -+#if (NGX_PCRE2) -+static pcre2_compile_context *ngx_regex_compile_context; -+static pcre2_match_context *ngx_regex_match_context; -+static pcre2_match_data *ngx_regex_match_data; -+static ngx_uint_t ngx_regex_match_data_size = 0; -+ -+#define PCRE2_VERSION_SIZE 64 -+static char ngx_pcre2_version[PCRE2_VERSION_SIZE]; -+#endif -+ -+ - #define NGX_LUA_RE_MODE_DFA (1<<1) - #define NGX_LUA_RE_MODE_JIT (1<<2) - #define NGX_LUA_RE_NO_UTF8_CHECK (1<<4) -@@ -42,8 +52,17 @@ typedef struct { - int ncaptures; - int *captures; - -+#if (NGX_PCRE2) -+ pcre2_code *regex; -+ /* -+ * pcre2 doesn't use pcre_extra any more, -+ * just for keeping same memory layout in the lua ffi cdef -+ */ -+ void *regex_sd; -+#else - pcre *regex; - pcre_extra *regex_sd; -+#endif - - ngx_http_lua_complex_value_t *replace; - -@@ -57,7 +76,11 @@ typedef struct { - ngx_pool_t *pool; - ngx_int_t options; - -+#if (NGX_PCRE2) -+ pcre2_code *regex; -+#else - pcre *regex; -+#endif - int captures; - ngx_str_t err; - } ngx_http_lua_regex_compile_t; -@@ -65,8 +88,12 @@ typedef struct { - - typedef struct { - ngx_http_request_t *request; -+#if (NGX_PCRE2) -+ pcre2_code *regex; -+#else - pcre *regex; - pcre_extra *regex_sd; -+#endif - int ncaptures; - int *captures; - int captures_len; -@@ -74,8 +101,6 @@ typedef struct { - } ngx_http_lua_regex_ctx_t; - - --static void ngx_http_lua_regex_free_study_data(ngx_pool_t *pool, -- pcre_extra *sd); - static ngx_int_t ngx_http_lua_regex_compile(ngx_http_lua_regex_compile_t *rc); - - -@@ -91,21 +116,155 @@ static ngx_int_t ngx_http_lua_regex_comp - - - static void --ngx_http_lua_regex_free_study_data(ngx_pool_t *pool, pcre_extra *sd) -+ngx_http_lua_regex_free_study_data(ngx_pool_t *pool, ngx_http_lua_regex_t *re) - { -- ngx_pool_t *old_pool; -+ ngx_pool_t *old_pool; - -- old_pool = ngx_http_lua_pcre_malloc_init(pool); -+#if (NGX_PCRE2) -+ if (re && re->regex) { -+ old_pool = ngx_http_lua_pcre_malloc_init(pool); -+ -+ pcre2_code_free(re->regex); -+ -+ ngx_http_lua_pcre_malloc_done(old_pool); - -+ re->regex = NULL; -+ } -+#else -+ if (re && re->regex_sd) { -+ old_pool = ngx_http_lua_pcre_malloc_init(pool); - #if LUA_HAVE_PCRE_JIT -- pcre_free_study(sd); -+ pcre_free_study(re->regex_sd); - #else -- pcre_free(sd); -+ pcre_free(re->regex_sd); -+#endif -+ ngx_http_lua_pcre_malloc_done(old_pool); -+ -+ re->regex_sd = NULL; -+ } - #endif -+} -+ -+ -+#if (NGX_PCRE2) -+static ngx_int_t -+ngx_http_lua_regex_compile(ngx_http_lua_regex_compile_t *rc) -+{ -+ int n, errcode; -+ char *p; -+ size_t erroff; -+ u_char errstr[128]; -+ pcre2_code *re; -+ ngx_pool_t *old_pool; -+ pcre2_general_context *gctx; -+ pcre2_compile_context *cctx; -+ -+ ngx_http_lua_main_conf_t *lmcf; -+ -+ if (ngx_regex_compile_context == NULL) { -+ /* -+ * Allocate a compile context if not yet allocated. This uses -+ * direct allocations from heap, so the result can be cached -+ * even at runtime. -+ */ -+ -+ old_pool = ngx_http_lua_pcre_malloc_init(NULL); -+ -+ gctx = pcre2_general_context_create(ngx_http_lua_pcre_malloc, -+ ngx_http_lua_pcre_free, -+ NULL); -+ if (gctx == NULL) { -+ ngx_http_lua_pcre_malloc_done(old_pool); -+ goto nomem; -+ } -+ -+ cctx = pcre2_compile_context_create(gctx); -+ if (cctx == NULL) { -+ pcre2_general_context_free(gctx); -+ ngx_http_lua_pcre_malloc_done(old_pool); -+ goto nomem; -+ } -+ -+ ngx_regex_compile_context = cctx; -+ -+ ngx_regex_match_context = pcre2_match_context_create(gctx); -+ if (ngx_regex_match_context == NULL) { -+ pcre2_general_context_free(gctx); -+ ngx_http_lua_pcre_malloc_done(old_pool); -+ goto nomem; -+ } -+ -+ lmcf = ngx_http_cycle_get_module_main_conf(ngx_cycle, -+ ngx_http_lua_module); -+ if (lmcf && lmcf->regex_match_limit > 0) { -+ pcre2_set_match_limit(ngx_regex_match_context, -+ lmcf->regex_match_limit); -+ } -+ -+ pcre2_general_context_free(gctx); -+ ngx_http_lua_pcre_malloc_done(old_pool); -+ } -+ -+ old_pool = ngx_http_lua_pcre_malloc_init(rc->pool); -+ -+ re = pcre2_compile(rc->pattern.data, -+ rc->pattern.len, rc->options, -+ &errcode, &erroff, ngx_regex_compile_context); - - ngx_http_lua_pcre_malloc_done(old_pool); -+ -+ if (re == NULL) { -+ pcre2_get_error_message(errcode, errstr, 128); -+ -+ if ((size_t) erroff == rc->pattern.len) { -+ rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, -+ "pcre2_compile() failed: %s in \"%V\"", -+ errstr, &rc->pattern) -+ - rc->err.data; -+ -+ } else { -+ rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, -+ "pcre2_compile() failed: %s in " -+ "\"%V\" at \"%s\"", errstr, &rc->pattern, -+ rc->pattern.data + erroff) -+ - rc->err.data; -+ } -+ -+ return NGX_ERROR; -+ } -+ -+ rc->regex = re; -+ -+ n = pcre2_pattern_info(re, PCRE2_INFO_CAPTURECOUNT, &rc->captures); -+ if (n < 0) { -+ p = "pcre2_pattern_info(\"%V\", PCRE_INFO_CAPTURECOUNT) failed: %d"; -+ goto failed; -+ } -+ -+#if (NGX_DEBUG) -+ ngx_log_debug3(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, -+ "pcre2_compile: pattern[%V], options 0x%08Xd, ncaptures %d", -+ &rc->pattern, rc->options, rc->captures); -+#endif -+ -+ return NGX_OK; -+ -+failed: -+ -+ rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, p, &rc->pattern, n) -+ - rc->err.data; -+ return NGX_ERROR; -+ -+nomem: -+ -+ rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, -+ "regex \"%V\" compilation failed: no memory", -+ &rc->pattern) -+ - rc->err.data; -+ return NGX_ERROR; - } - -+#else - - static ngx_int_t - ngx_http_lua_regex_compile(ngx_http_lua_regex_compile_t *rc) -@@ -159,13 +318,14 @@ failed: - - rc->err.data; - return NGX_OK; - } -+#endif - - - ngx_int_t - ngx_http_lua_ffi_set_jit_stack_size(int size, u_char *errstr, - size_t *errstr_size) - { --#if LUA_HAVE_PCRE_JIT -+#if (NGX_PCRE2 || LUA_HAVE_PCRE_JIT) - - ngx_http_lua_main_conf_t *lmcf; - ngx_pool_t *pool, *old_pool; -@@ -186,15 +346,24 @@ ngx_http_lua_ffi_set_jit_stack_size(int - if (lmcf->jit_stack) { - old_pool = ngx_http_lua_pcre_malloc_init(pool); - -+#if (NGX_PCRE2) -+ pcre2_jit_stack_free(lmcf->jit_stack); -+#else - pcre_jit_stack_free(lmcf->jit_stack); -+#endif - - ngx_http_lua_pcre_malloc_done(old_pool); - } - - old_pool = ngx_http_lua_pcre_malloc_init(pool); - -+#if (NGX_PCRE2) -+ lmcf->jit_stack = pcre2_jit_stack_create(NGX_LUA_RE_MIN_JIT_STACK_SIZE, -+ size, NULL); -+#else - lmcf->jit_stack = pcre_jit_stack_alloc(NGX_LUA_RE_MIN_JIT_STACK_SIZE, - size); -+#endif - - ngx_http_lua_pcre_malloc_done(old_pool); - -@@ -214,8 +383,148 @@ ngx_http_lua_ffi_set_jit_stack_size(int - - errstr; - return NGX_ERROR; - -+#endif -+} -+ -+ -+#if (NGX_PCRE2) -+static void -+ngx_http_lua_regex_jit_compile(ngx_http_lua_regex_t *re, int flags, -+ ngx_pool_t *pool, ngx_http_lua_main_conf_t *lmcf, -+ ngx_http_lua_regex_compile_t *re_comp) -+{ -+ ngx_int_t ret; -+ ngx_pool_t *old_pool; -+ -+ if (flags & NGX_LUA_RE_MODE_JIT) { -+ old_pool = ngx_http_lua_pcre_malloc_init(pool); -+ ret = pcre2_jit_compile(re_comp->regex, PCRE2_JIT_COMPLETE); -+ -+ if (ret != 0) { -+ ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, 0, -+ "pcre2_jit_compile() failed: %d in \"%V\", " -+ "ignored", -+ ret, &re_comp->pattern); -+ -+#if (NGX_DEBUG) -+ -+ } else { -+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, -+ "pcre2 JIT compiled successfully"); -+# endif /* !(NGX_DEBUG) */ -+ } -+ -+ ngx_http_lua_pcre_malloc_done(old_pool); -+ -+ } -+ -+ if (lmcf && lmcf->jit_stack) { -+ pcre2_jit_stack_assign(ngx_regex_match_context, NULL, -+ lmcf->jit_stack); -+ } -+ -+ return; -+} -+ -+#else -+ -+static void -+ngx_http_lua_regex_jit_compile(ngx_http_lua_regex_t *re, int flags, -+ ngx_pool_t *pool, ngx_http_lua_main_conf_t *lmcf, -+ ngx_http_lua_regex_compile_t *re_comp) -+{ -+ const char *msg; -+ pcre_extra *sd = NULL; -+ ngx_pool_t *old_pool; -+ -+ -+#if (LUA_HAVE_PCRE_JIT) -+ if (flags & NGX_LUA_RE_MODE_JIT) { -+ old_pool = ngx_http_lua_pcre_malloc_init(pool); -+ sd = pcre_study(re_comp->regex, PCRE_STUDY_JIT_COMPILE, &msg); -+ ngx_http_lua_pcre_malloc_done(old_pool); -+ -+# if (NGX_DEBUG) -+ if (msg != NULL) { -+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, -+ "pcre study failed with PCRE_STUDY_JIT_COMPILE: " -+ "%s (%p)", msg, sd); -+ } -+ -+ if (sd != NULL) { -+ int jitted; -+ -+ old_pool = ngx_http_lua_pcre_malloc_init(pool); -+ -+ pcre_fullinfo(re_comp->regex, sd, PCRE_INFO_JIT, &jitted); -+ -+ ngx_http_lua_pcre_malloc_done(old_pool); -+ -+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, -+ "pcre JIT compiling result: %d", jitted); -+ } -+# endif /* !(NGX_DEBUG) */ -+ -+ } else { -+ old_pool = ngx_http_lua_pcre_malloc_init(pool); -+ sd = pcre_study(re_comp->regex, 0, &msg); -+ ngx_http_lua_pcre_malloc_done(old_pool); -+ } -+ -+ if (sd && lmcf && lmcf->jit_stack) { -+ pcre_assign_jit_stack(sd, NULL, lmcf->jit_stack); -+ } -+ -+ if (sd -+ && lmcf && lmcf->regex_match_limit > 0 -+ && !(flags & NGX_LUA_RE_MODE_DFA)) -+ { -+ sd->flags |= PCRE_EXTRA_MATCH_LIMIT; -+ sd->match_limit = lmcf->regex_match_limit; -+ } -+ - #endif /* LUA_HAVE_PCRE_JIT */ -+ -+ re->regex_sd = sd; -+} -+#endif -+ -+ -+#if (NGX_PCRE2) -+void -+ngx_http_lua_regex_cleanup(void *data) -+{ -+ ngx_pool_t *old_pool; -+ ngx_http_lua_main_conf_t *lmcf; -+ -+ lmcf = data; -+ -+ if (ngx_regex_compile_context) { -+ old_pool = ngx_http_lua_pcre_malloc_init(NULL); -+ pcre2_compile_context_free(ngx_regex_compile_context); -+ ngx_regex_compile_context = NULL; -+ ngx_http_lua_pcre_malloc_done(old_pool); -+ } -+ -+ if (lmcf && lmcf->jit_stack) { -+ old_pool = ngx_http_lua_pcre_malloc_init(NULL); -+ -+ pcre2_jit_stack_free(lmcf->jit_stack); -+ lmcf->jit_stack = NULL; -+ -+ ngx_http_lua_pcre_malloc_done(old_pool); -+ } -+ -+ if (ngx_regex_match_data) { -+ old_pool = ngx_http_lua_pcre_malloc_init(NULL); -+ pcre2_match_data_free(ngx_regex_match_data); -+ ngx_regex_match_data = NULL; -+ ngx_regex_match_data_size = 0; -+ ngx_http_lua_pcre_malloc_done(old_pool); -+ } -+ - } -+#endif - - - ngx_http_lua_regex_t * -@@ -228,8 +537,7 @@ ngx_http_lua_ffi_compile_regex(const uns - ngx_int_t rc; - const char *msg; - ngx_pool_t *pool, *old_pool; -- pcre_extra *sd = NULL; -- ngx_http_lua_regex_t *re; -+ ngx_http_lua_regex_t *re = NULL; - - ngx_http_lua_main_conf_t *lmcf; - ngx_http_lua_regex_compile_t re_comp; -@@ -251,6 +559,8 @@ ngx_http_lua_ffi_compile_regex(const uns - } - - re->pool = pool; -+ re->regex = NULL; -+ re->regex_sd = NULL; - - re_comp.options = pcre_opts; - re_comp.pattern.data = (u_char *) pat; -@@ -274,54 +584,7 @@ ngx_http_lua_ffi_compile_regex(const uns - - ngx_http_lua_assert(lmcf != NULL); - --#if (LUA_HAVE_PCRE_JIT) -- -- if (flags & NGX_LUA_RE_MODE_JIT) { -- -- old_pool = ngx_http_lua_pcre_malloc_init(pool); -- sd = pcre_study(re_comp.regex, PCRE_STUDY_JIT_COMPILE, &msg); -- ngx_http_lua_pcre_malloc_done(old_pool); -- --# if (NGX_DEBUG) -- if (msg != NULL) { -- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, -- "pcre study failed with PCRE_STUDY_JIT_COMPILE: " -- "%s (%p)", msg, sd); -- } -- -- if (sd != NULL) { -- int jitted; -- -- old_pool = ngx_http_lua_pcre_malloc_init(pool); -- -- pcre_fullinfo(re_comp.regex, sd, PCRE_INFO_JIT, &jitted); -- -- ngx_http_lua_pcre_malloc_done(old_pool); -- -- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, -- "pcre JIT compiling result: %d", jitted); -- } --# endif /* !(NGX_DEBUG) */ -- -- } else { -- old_pool = ngx_http_lua_pcre_malloc_init(pool); -- sd = pcre_study(re_comp.regex, 0, &msg); -- ngx_http_lua_pcre_malloc_done(old_pool); -- } -- -- if (sd && lmcf->jit_stack) { -- pcre_assign_jit_stack(sd, NULL, lmcf->jit_stack); -- } -- --#endif /* LUA_HAVE_PCRE_JIT */ -- -- if (sd -- && lmcf && lmcf->regex_match_limit > 0 -- && !(flags & NGX_LUA_RE_MODE_DFA)) -- { -- sd->flags |= PCRE_EXTRA_MATCH_LIMIT; -- sd->match_limit = lmcf->regex_match_limit; -- } -+ ngx_http_lua_regex_jit_compile(re, flags, pool, lmcf, &re_comp); - - if (flags & NGX_LUA_RE_MODE_DFA) { - ovecsize = 2; -@@ -339,6 +602,31 @@ ngx_http_lua_ffi_compile_regex(const uns - goto error; - } - -+#if (NGX_PCRE2) -+ if (pcre2_pattern_info(re_comp.regex, PCRE2_INFO_NAMECOUNT, -+ &re->name_count) < 0) -+ { -+ msg = "cannot acquire named subpattern count"; -+ goto error; -+ } -+ -+ if (re->name_count > 0) { -+ if (pcre2_pattern_info(re_comp.regex, PCRE2_INFO_NAMEENTRYSIZE, -+ &re->name_entry_size) != 0) -+ { -+ msg = "cannot acquire named subpattern entry size"; -+ goto error; -+ } -+ -+ if (pcre2_pattern_info(re_comp.regex, PCRE2_INFO_NAMETABLE, -+ &re->name_table) != 0) -+ { -+ msg = "cannot acquire named subpattern table"; -+ goto error; -+ } -+ } -+ -+#else - if (pcre_fullinfo(re_comp.regex, NULL, PCRE_INFO_NAMECOUNT, - &re->name_count) != 0) - { -@@ -361,9 +649,9 @@ ngx_http_lua_ffi_compile_regex(const uns - goto error; - } - } -+#endif - - re->regex = re_comp.regex; -- re->regex_sd = sd; - re->ncaptures = re_comp.captures; - re->captures = cap; - re->replace = NULL; -@@ -379,9 +667,7 @@ error: - p = ngx_snprintf(errstr, errstr_size - 1, "%s", msg); - *p = '\0'; - -- if (sd) { -- ngx_http_lua_regex_free_study_data(pool, sd); -- } -+ ngx_http_lua_regex_free_study_data(pool, re); - - if (pool) { - ngx_destroy_pool(pool); -@@ -391,6 +677,103 @@ error: - } - - -+#if (NGX_PCRE2) -+int -+ngx_http_lua_ffi_exec_regex(ngx_http_lua_regex_t *re, int flags, -+ const u_char *s, size_t len, int pos) -+{ -+ int rc, exec_opts = 0; -+ size_t *ov; -+ ngx_uint_t ovecsize, n, i; -+ ngx_pool_t *old_pool; -+ -+ if (flags & NGX_LUA_RE_MODE_DFA) { -+ ovecsize = 2; -+ re->ncaptures = 0; -+ -+ } else { -+ ovecsize = (re->ncaptures + 1) * 3; -+ } -+ -+ old_pool = ngx_http_lua_pcre_malloc_init(NULL); -+ -+ if (ngx_regex_match_data == NULL -+ || ovecsize > ngx_regex_match_data_size) -+ { -+ /* -+ * Allocate a match data if not yet allocated or smaller than -+ * needed. -+ */ -+ -+ if (ngx_regex_match_data) { -+ pcre2_match_data_free(ngx_regex_match_data); -+ } -+ -+ ngx_regex_match_data_size = ovecsize; -+ ngx_regex_match_data = pcre2_match_data_create(ovecsize / 3, NULL); -+ -+ if (ngx_regex_match_data == NULL) { -+ rc = PCRE2_ERROR_NOMEMORY; -+ goto failed; -+ } -+ } -+ -+ if (flags & NGX_LUA_RE_NO_UTF8_CHECK) { -+ exec_opts = PCRE2_NO_UTF_CHECK; -+ -+ } else { -+ exec_opts = 0; -+ } -+ -+ if (flags & NGX_LUA_RE_MODE_DFA) { -+ int ws[NGX_LUA_RE_DFA_MODE_WORKSPACE_COUNT]; -+ rc = pcre2_dfa_match(re->regex, s, len, pos, exec_opts, -+ ngx_regex_match_data, ngx_regex_match_context, -+ ws, sizeof(ws) / sizeof(ws[0])); -+ -+ -+ } else { -+ rc = pcre2_match(re->regex, s, len, pos, exec_opts, -+ ngx_regex_match_data, ngx_regex_match_context); -+ } -+ -+ if (rc < 0) { -+#if (NGX_DEBUG) -+ ngx_log_debug4(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, -+ "pcre2_match failed: flags 0x%05Xd, options 0x%08Xd, " -+ "rc %d, ovecsize %ui", flags, exec_opts, rc, ovecsize); -+#endif -+ -+ goto failed; -+ } -+ -+ n = pcre2_get_ovector_count(ngx_regex_match_data); -+ ov = pcre2_get_ovector_pointer(ngx_regex_match_data); -+ -+#if (NGX_DEBUG) -+ ngx_log_debug5(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, -+ "pcre2_match: flags 0x%05Xd, options 0x%08Xd, rc %d, " -+ "n %ui, ovecsize %ui", flags, exec_opts, rc, n, ovecsize); -+#endif -+ -+ if (!(flags & NGX_LUA_RE_MODE_DFA) && n > ovecsize / 3) { -+ n = ovecsize / 3; -+ } -+ -+ for (i = 0; i < n; i++) { -+ re->captures[i * 2] = ov[i * 2]; -+ re->captures[i * 2 + 1] = ov[i * 2 + 1]; -+ } -+ -+failed: -+ -+ ngx_http_lua_pcre_malloc_done(old_pool); -+ -+ return rc; -+} -+ -+#else -+ - int - ngx_http_lua_ffi_exec_regex(ngx_http_lua_regex_t *re, int flags, - const u_char *s, size_t len, int pos) -@@ -427,7 +810,8 @@ ngx_http_lua_ffi_exec_regex(ngx_http_lua - int ws[NGX_LUA_RE_DFA_MODE_WORKSPACE_COUNT]; - rc = ngx_http_lua_regex_dfa_exec(re->regex, sd, &subj, - (int) pos, cap, ovecsize, ws, -- sizeof(ws)/sizeof(ws[0]), exec_opts); -+ sizeof(ws) / sizeof(ws[0]), -+ exec_opts); - - #else - -@@ -443,28 +827,19 @@ ngx_http_lua_ffi_exec_regex(ngx_http_lua - return rc; - } - -+#endif -+ - - void - ngx_http_lua_ffi_destroy_regex(ngx_http_lua_regex_t *re) - { -- ngx_pool_t *old_pool; -- - dd("destroy regex called"); - - if (re == NULL || re->pool == NULL) { - return; - } - -- if (re->regex_sd) { -- old_pool = ngx_http_lua_pcre_malloc_init(re->pool); --#if LUA_HAVE_PCRE_JIT -- pcre_free_study(re->regex_sd); --#else -- pcre_free(re->regex_sd); --#endif -- ngx_http_lua_pcre_malloc_done(old_pool); -- re->regex_sd = NULL; -- } -+ ngx_http_lua_regex_free_study_data(re->pool, re); - - ngx_destroy_pool(re->pool); - } -@@ -592,11 +967,17 @@ ngx_http_lua_ffi_max_regex_cache_size(vo - const char * - ngx_http_lua_ffi_pcre_version(void) - { -+#if (NGX_PCRE2) -+ pcre2_config(PCRE2_CONFIG_VERSION, ngx_pcre2_version); -+ -+ return ngx_pcre2_version; -+#else - return pcre_version(); -+#endif - } - - --#endif /* NGX_PCRE */ -+#endif /* NGX_PCRE || NGX_PCRE2 */ - - - /* vi:set ft=c ts=4 sw=4 et fdm=marker: */ ---- a/nginx-mod-lua/t/028-req-header.t -+++ b/nginx-mod-lua/t/028-req-header.t -@@ -275,7 +275,6 @@ Content-Type: - GET /bar - --- response_body eval - # Since nginx version 1.23.0, nginx combines same $http_* variable together --# wtf - $Test::Nginx::Util::NginxVersion >= 1.023000 ? - - "Foo: a, b\n" ---- a/nginx-mod-lua/t/034-match.t -+++ b/nginx-mod-lua/t/034-match.t -@@ -361,8 +361,11 @@ he - } - --- request - GET /re ----- response_body --error: pcre_compile() failed: missing ) in "(abc" -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n" -+: -+"error: pcre_compile() failed: missing ) in \"(abc\"\n" - --- no_error_log - [error] - -@@ -648,8 +651,12 @@ regex: (?:>[\w\s]*) - } - --- request - GET /re ----- response_body --error: pcre_compile() failed: missing ) in "([0-9]+" -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile\(\) failed: missing closing parenthesis in \"\([0-9]+\"\n" -+: -+"error: pcre_compile\(\) failed: missing \) in \"\([0-9]+\"\n" -+ - - --- no_error_log - [error] -@@ -939,8 +946,11 @@ nil - } - --- request - GET /t ----- response_body_like chop --^error: pcre_exec\(\) failed: -10$ -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre_exec\(\) failed: -4\n" -+: -+"error: pcre_exec\(\) failed: -10\n" - - --- no_error_log - [error] -@@ -1050,8 +1060,14 @@ end - - --- request - GET /re ----- response_body --error: pcre_exec() failed: -8 -+--- response_body eval -+# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE, -+# but PCRE2 replaces this with pcre2_set_match_limit interface, -+# which has different effects. -+$Test::Nginx::Util::PcreVersion == 2 ? -+"failed to match\n" -+: -+"error: pcre_exec() failed: -8\n" - - - ---- a/nginx-mod-lua/t/035-gmatch.t -+++ b/nginx-mod-lua/t/035-gmatch.t -@@ -698,8 +698,11 @@ not matched! - } - --- request - GET /re ----- response_body --error: pcre_compile() failed: missing ) in "(abc" -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n" -+: -+"error: pcre_compile() failed: missing ) in \"(abc\"\n" - --- no_error_log - [error] - -@@ -735,8 +738,11 @@ error: pcre_compile() failed: missing ) - } - --- request - GET /t ----- response_body_like chop --error: pcre_exec\(\) failed: -10 -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre_exec\(\) failed: -4\n" -+: -+"error: pcre_exec\(\) failed: -10\n" - - --- no_error_log - [error] -@@ -854,8 +860,14 @@ end - - --- request - GET /re ----- response_body --error: pcre_exec() failed: -8 -+--- response_body eval -+# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE, -+# but PCRE2 replaces this with pcre2_set_match_limit interface, -+# which has different effects. -+$Test::Nginx::Util::PcreVersion == 2 ? -+"failed to match\n" -+: -+"error: pcre_exec() failed: -8\n" - - - ---- a/nginx-mod-lua/t/036-sub.t -+++ b/nginx-mod-lua/t/036-sub.t -@@ -480,8 +480,11 @@ a [b c] [b] [c] [] [] d - } - --- request - GET /re ----- response_body --error: pcre_compile() failed: missing ) in "(abc" -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n" -+: -+"error: pcre_compile() failed: missing ) in \"(abc\"\n" - --- no_error_log - [error] - -@@ -506,8 +509,11 @@ error: pcre_compile() failed: missing ) - } - --- request - GET /t ----- response_body_like chop --error: pcre_exec\(\) failed: -10 -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre_exec\(\) failed: -4\n" -+: -+"error: pcre_exec\(\) failed: -10\n" - - --- no_error_log - [error] -@@ -610,8 +616,14 @@ ngx.say("sub: ", cnt) - - --- request - GET /re ----- response_body --error: pcre_exec() failed: -8 -+--- response_body eval -+# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE, -+# but PCRE2 replaces this with pcre2_set_match_limit interface, -+# which has different effects. -+$Test::Nginx::Util::PcreVersion == 2 ? -+"sub: 0\n" -+: -+"error: pcre_exec() failed: -8\n" - - - ---- a/nginx-mod-lua/t/037-gsub.t -+++ b/nginx-mod-lua/t/037-gsub.t -@@ -423,8 +423,11 @@ n: 1 - } - --- request - GET /t ----- response_body_like chop --error: pcre_exec\(\) failed: -10 -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre_exec\(\) failed: -4\n" -+: -+"error: pcre_exec\(\) failed: -10\n" - - --- no_error_log - [error] -@@ -531,8 +534,14 @@ ngx.say("gsub: ", cnt) - - --- request - GET /re ----- response_body --error: pcre_exec() failed: -8 -+--- response_body eval -+# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE, -+# but PCRE2 replaces this with pcre2_set_match_limit interface, -+# which has different effects. -+$Test::Nginx::Util::PcreVersion == 2 ? -+"gsub: 0\n" -+: -+"error: pcre_exec() failed: -8\n" - - - ---- a/nginx-mod-lua/t/038-match-o.t -+++ b/nginx-mod-lua/t/038-match-o.t -@@ -336,8 +336,11 @@ he - } - --- request - GET /re ----- response_body --error: pcre_compile() failed: missing ) in "(abc" -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n" -+: -+"error: pcre_compile() failed: missing ) in \"(abc\"\n" - --- no_error_log - [error] - ---- a/nginx-mod-lua/t/047-match-jit.t -+++ b/nginx-mod-lua/t/047-match-jit.t -@@ -32,8 +32,11 @@ __DATA__ - GET /re - --- response_body - 1234 ----- error_log --pcre JIT compiling result: 1 -+--- error_log eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully\n" -+: -+"pcre JIT compiling result: 1\n" - - - -@@ -53,8 +56,11 @@ pcre JIT compiling result: 1 - GET /re - --- response_body - not matched! ----- error_log --pcre JIT compiling result: 1 -+--- error_log eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully\n" -+: -+"pcre JIT compiling result: 1\n" - - - -@@ -76,9 +82,15 @@ pcre JIT compiling result: 1 - 1234 - - --- grep_error_log eval --qr/pcre JIT compiling result: \d+/ -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully" -+: -+"pcre JIT compiling result: 1" - - --- grep_error_log_out eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+["pcre2 JIT compiled successfully\n", ""] -+: - ["pcre JIT compiling result: 1\n", ""] - - -@@ -101,9 +113,15 @@ qr/pcre JIT compiling result: \d+/ - not matched! - - --- grep_error_log eval --qr/pcre JIT compiling result: \d+/ -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully" -+: -+"pcre JIT compiling result: 1" - - --- grep_error_log_out eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+["pcre2 JIT compiled successfully\n", ""] -+: - ["pcre JIT compiling result: 1\n", ""] - - -@@ -128,8 +146,11 @@ qr/pcre JIT compiling result: \d+/ - } - --- request - GET /re ----- response_body --error: pcre_compile() failed: missing ) in "(abc" -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n" -+: -+"error: pcre_compile() failed: missing ) in \"(abc\"\n" - --- no_error_log - [error] - -@@ -170,8 +191,15 @@ end - - --- request - GET /re ----- response_body --error: pcre_exec() failed: -8 -+--- response_body eval -+# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE, -+# but PCRE2 replaces this with pcre2_set_match_limit interface, -+# which has different effects. -+$Test::Nginx::Util::PcreVersion == 2 ? -+# PCRE2_ERROR_MATCHLIMIT (-47) -+"error: pcre_exec() failed: -47\n" -+: -+"error: pcre_exec() failed: -8\n" - - - ---- a/nginx-mod-lua/t/049-gmatch-jit.t -+++ b/nginx-mod-lua/t/049-gmatch-jit.t -@@ -34,8 +34,11 @@ __DATA__ - --- response_body - hello - world ----- error_log --pcre JIT compiling result: 1 -+--- error_log eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully\n" -+: -+"pcre JIT compiling result: 1\n" - - - -@@ -60,8 +63,11 @@ pcre JIT compiling result: 1 - nil - nil - nil ----- error_log --pcre JIT compiling result: 1 -+--- error_log eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully\n" -+: -+"pcre JIT compiling result: 1\n" - - - -@@ -77,8 +83,11 @@ pcre JIT compiling result: 1 - GET /re - --- response_body - done ----- error_log --pcre JIT compiling result: 1 -+--- error_log eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully\n" -+: -+"pcre JIT compiling result: 1\n" - - - -@@ -99,8 +108,11 @@ pcre JIT compiling result: 1 - GET /re - --- response_body - hello ----- error_log --pcre JIT compiling result: 1 -+--- error_log eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully\n" -+: -+"pcre JIT compiling result: 1\n" - - - -@@ -124,9 +136,15 @@ hello - world - - --- grep_error_log eval --qr/pcre JIT compiling result: \d+/ -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully" -+: -+"pcre JIT compiling result: 1" - - --- grep_error_log_out eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+["pcre2 JIT compiled successfully\n", ""] -+: - ["pcre JIT compiling result: 1\n", ""] - - -@@ -154,9 +172,15 @@ nil - nil - - --- grep_error_log eval --qr/pcre JIT compiling result: \d+/ -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully" -+: -+"pcre JIT compiling result: 1" - - --- grep_error_log_out eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+["pcre2 JIT compiled successfully\n", ""] -+: - ["pcre JIT compiling result: 1\n", ""] - - -@@ -175,9 +199,15 @@ qr/pcre JIT compiling result: \d+/ - done - - --- grep_error_log eval --qr/pcre JIT compiling result: \d+/ -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully" -+: -+"pcre JIT compiling result: 1" - - --- grep_error_log_out eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+["pcre2 JIT compiled successfully\n", ""] -+: - ["pcre JIT compiling result: 1\n", ""] - - -@@ -201,9 +231,15 @@ qr/pcre JIT compiling result: \d+/ - hello - - --- grep_error_log eval --qr/pcre JIT compiling result: \d+/ -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully" -+: -+"pcre JIT compiling result: 1" - - --- grep_error_log_out eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+["pcre2 JIT compiled successfully\n", ""] -+: - ["pcre JIT compiling result: 1\n", ""] - - -@@ -222,7 +258,10 @@ qr/pcre JIT compiling result: \d+/ - } - --- request - GET /re ----- response_body --error: pcre_compile() failed: missing ) in "(abc" -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n" -+: -+"error: pcre_compile() failed: missing ) in \"(abc\"\n" - --- no_error_log - [error] ---- a/nginx-mod-lua/t/050-gmatch-dfa.t -+++ b/nginx-mod-lua/t/050-gmatch-dfa.t -@@ -214,8 +214,11 @@ hello - } - --- request - GET /re ----- response_body --error: pcre_compile() failed: missing ) in "(abc" -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n" -+: -+"error: pcre_compile() failed: missing ) in \"(abc\"\n" - --- no_error_log - [error] - ---- a/nginx-mod-lua/t/051-sub-jit.t -+++ b/nginx-mod-lua/t/051-sub-jit.t -@@ -32,8 +32,11 @@ __DATA__ - GET /re - --- response_body - hello, world 5678: 1 ----- error_log --pcre JIT compiling result: 1 -+--- error_log eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully\n" -+: -+"pcre JIT compiling result: 1\n" - - - -@@ -53,8 +56,11 @@ pcre JIT compiling result: 1 - GET /re - --- response_body - hello, world: 0 ----- error_log --pcre JIT compiling result: 1 -+--- error_log eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully\n" -+: -+"pcre JIT compiling result: 1\n" - - - -@@ -76,9 +82,15 @@ pcre JIT compiling result: 1 - hello, world 5678: 1 - - --- grep_error_log eval --qr/pcre JIT compiling result: \d+/ -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully" -+: -+"pcre JIT compiling result: 1" - - --- grep_error_log_out eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+["pcre2 JIT compiled successfully\n", ""] -+: - ["pcre JIT compiling result: 1\n", ""] - - -@@ -101,9 +113,15 @@ qr/pcre JIT compiling result: \d+/ - hello, world: 0 - - --- grep_error_log eval --qr/pcre JIT compiling result: \d+/ -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully" -+: -+"pcre JIT compiling result: 1" - - --- grep_error_log_out eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+["pcre2 JIT compiled successfully\n", ""] -+: - ["pcre JIT compiling result: 1\n", ""] - - -@@ -122,8 +140,11 @@ qr/pcre JIT compiling result: \d+/ - } - --- request - GET /re ----- response_body --error: pcre_compile() failed: missing ) in "(abc" -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n" -+: -+"error: pcre_compile() failed: missing ) in \"(abc\"\n" - --- no_error_log - [error] - -@@ -143,7 +164,10 @@ error: pcre_compile() failed: missing ) - } - --- request - GET /re ----- response_body --error: pcre_compile() failed: missing ) in "(abc" -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n" -+: -+"error: pcre_compile() failed: missing ) in \"(abc\"\n" - --- no_error_log - [error] ---- a/nginx-mod-lua/t/052-sub-dfa.t -+++ b/nginx-mod-lua/t/052-sub-dfa.t -@@ -107,8 +107,11 @@ hello, world: 0 - } - --- request - GET /re ----- response_body --error: pcre_compile() failed: missing ) in "(abc" -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n" -+: -+"error: pcre_compile() failed: missing ) in \"(abc\"\n" - --- no_error_log - [error] - -@@ -129,8 +132,11 @@ error: pcre_compile() failed: missing ) - } - --- request - GET /re ----- response_body --error: pcre_compile() failed: missing ) in "(abc" -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n" -+: -+"error: pcre_compile() failed: missing ) in \"(abc\"\n" - --- no_error_log - [error] - ---- a/nginx-mod-lua/t/053-gsub-jit.t -+++ b/nginx-mod-lua/t/053-gsub-jit.t -@@ -32,8 +32,11 @@ __DATA__ - GET /re - --- response_body - hello, world world: 2 ----- error_log --pcre JIT compiling result: 1 -+--- error_log eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully\n" -+: -+"pcre JIT compiling result: 1\n" - - - -@@ -53,8 +56,11 @@ pcre JIT compiling result: 1 - GET /re - --- response_body - hello, world: 0 ----- error_log --pcre JIT compiling result: 1 -+--- error_log eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully\n" -+: -+"pcre JIT compiling result: 1\n" - - - -@@ -76,9 +82,15 @@ pcre JIT compiling result: 1 - hello, world world: 2 - - --- grep_error_log eval --qr/pcre JIT compiling result: \d+/ -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully" -+: -+"pcre JIT compiling result: 1" - - --- grep_error_log_out eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+["pcre2 JIT compiled successfully\n", ""] -+: - ["pcre JIT compiling result: 1\n", ""] - - -@@ -101,9 +113,15 @@ qr/pcre JIT compiling result: \d+/ - hello, world: 0 - - --- grep_error_log eval --qr/pcre JIT compiling result: \d+/ -+$Test::Nginx::Util::PcreVersion == 2 ? -+"pcre2 JIT compiled successfully" -+: -+"pcre JIT compiling result: 1" - - --- grep_error_log_out eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+["pcre2 JIT compiled successfully\n", ""] -+: - ["pcre JIT compiling result: 1\n", ""] - - -@@ -122,8 +140,11 @@ qr/pcre JIT compiling result: \d+/ - } - --- request - GET /re ----- response_body --error: pcre_compile() failed: missing ) in "(abc" -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n" -+: -+"error: pcre_compile() failed: missing ) in \"(abc\"\n" - --- no_error_log - [error] - -@@ -143,7 +164,10 @@ error: pcre_compile() failed: missing ) - } - --- request - GET /re ----- response_body --error: pcre_compile() failed: missing ) in "(abc" -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n" -+: -+"error: pcre_compile() failed: missing ) in \"(abc\"\n" - --- no_error_log - [error] ---- a/nginx-mod-lua/t/054-gsub-dfa.t -+++ b/nginx-mod-lua/t/054-gsub-dfa.t -@@ -107,8 +107,11 @@ hello, world: 0 - } - --- request - GET /re ----- response_body --error: pcre_compile() failed: missing ) in "(abc" -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n" -+: -+"error: pcre_compile() failed: missing ) in \"(abc\"\n" - - - -@@ -126,8 +129,11 @@ error: pcre_compile() failed: missing ) - } - --- request - GET /re ----- response_body --error: pcre_compile() failed: missing ) in "(abc" -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n" -+: -+"error: pcre_compile() failed: missing ) in \"(abc\"\n" - --- no_error_log - [error] - ---- a/nginx-mod-lua/t/120-re-find.t -+++ b/nginx-mod-lua/t/120-re-find.t -@@ -354,8 +354,11 @@ matched: he - } - --- request - GET /re ----- response_body --error: pcre_compile() failed: missing ) in "(abc" -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n" -+: -+"error: pcre_compile() failed: missing ) in \"(abc\"\n" - --- no_error_log - [error] - -@@ -562,8 +565,11 @@ matched: hello, 1234 - } - --- request - GET /t ----- response_body_like chop --^error: pcre_exec\(\) failed: -10$ -+--- response_body eval -+$Test::Nginx::Util::PcreVersion == 2 ? -+"error: pcre_exec\(\) failed: -4\n" -+: -+"error: pcre_exec\(\) failed: -10\n" - - --- no_error_log - [error] -@@ -587,6 +593,7 @@ GET /t - '; - } - --- stap -+# TODO: PCRE2 use different option values from PCRE - probe process("$LIBPCRE_PATH").function("pcre_compile") { - printf("compile opts: %x\n", $options) - } -@@ -645,8 +652,14 @@ end - - --- request - GET /re ----- response_body --error: pcre_exec() failed: -8 -+--- response_body eval -+# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE, -+# but PCRE2 replaces this with pcre2_set_match_limit interface, -+# which has different effects. -+$Test::Nginx::Util::PcreVersion == 2 ? -+"failed to match.\n" -+: -+"error: pcre_exec() failed: -8\n" - --- no_error_log - [error] - ---- a/nginx-mod-lua/util/build-with-dd.sh -+++ b/nginx-mod-lua/util/build-with-dd.sh -@@ -20,9 +20,13 @@ fi - - disable_pcre2=--without-pcre2 - answer=`$root/util/ver-ge "$NGINX_VERSION" 1.25.1` --if [ "$answer" = "N" ]; then -+if [ "$answer" = "N" ] || [ "$USE_PCRE2" = "Y" ]; then - disable_pcre2="" - fi -+if [ "$USE_PCRE2" = "Y" ]; then -+ PCRE_INC=$PCRE2_INC -+ PCRE_LIB=$PCRE2_LIB -+fi - - time ngx-build $force $version \ - --with-threads \ ---- a/nginx-mod-lua/util/build-without-ssl.sh -+++ b/nginx-mod-lua/util/build-without-ssl.sh -@@ -26,9 +26,13 @@ add_fake_shm_module="--add-module=$root/ - - disable_pcre2=--without-pcre2 - answer=`$root/util/ver-ge "$NGINX_VERSION" 1.25.1` --if [ "$answer" = "N" ]; then -+if [ "$answer" = "N" ] || [ "$USE_PCRE2" = "Y" ]; then - disable_pcre2="" - fi -+if [ "$USE_PCRE2" = "Y" ]; then -+ PCRE_INC=$PCRE2_INC -+ PCRE_LIB=$PCRE2_LIB -+fi - - time ngx-build $force $version \ - --with-threads \ ---- a/nginx-mod-lua/util/build.sh -+++ b/nginx-mod-lua/util/build.sh -@@ -32,9 +32,13 @@ fi - - disable_pcre2=--without-pcre2 - answer=`$root/util/ver-ge "$NGINX_VERSION" 1.25.1` --if [ "$answer" = "N" ]; then -+if [ "$answer" = "N" ] || [ "$USE_PCRE2" = "Y" ]; then - disable_pcre2="" - fi -+if [ "$USE_PCRE2" = "Y" ]; then -+ PCRE_INC=$PCRE2_INC -+ PCRE_LIB=$PCRE2_LIB -+fi - - time ngx-build $force $version \ - --with-threads \ ---- a/nginx-mod-lua/valgrind.suppress -+++ b/nginx-mod-lua/valgrind.suppress -@@ -234,3 +234,73 @@ - fun:ngx_pass_open_channel - fun:ngx_start_privileged_agent_processes - } -+{ -+ -+ Memcheck:Leak -+ match-leak-kinds: definite -+ fun:malloc -+ fun:ngx_alloc -+ fun:ngx_regex_malloc -+ fun:pcre2_compile_context_create_8 -+ fun:ngx_regex_compile -+ fun:ngx_http_regex_compile -+ fun:ngx_http_core_regex_location -+ fun:ngx_http_core_location -+ fun:ngx_conf_handler -+ fun:ngx_conf_parse -+ fun:ngx_http_core_server -+ fun:ngx_conf_handler -+ fun:ngx_conf_parse -+ fun:ngx_http_block -+ fun:ngx_conf_handler -+ fun:ngx_conf_parse -+ fun:ngx_init_cycle -+ fun:main -+} -+{ -+ -+ Memcheck:Leak -+ match-leak-kinds: definite -+ fun:malloc -+ fun:ngx_alloc -+ fun:ngx_regex_malloc -+ fun:pcre2_compile_context_create_8 -+ fun:ngx_regex_compile -+ fun:ngx_http_regex_compile -+ fun:ngx_http_rewrite -+ fun:ngx_conf_handler -+ fun:ngx_conf_parse -+ fun:ngx_http_core_location -+ fun:ngx_conf_handler -+ fun:ngx_conf_parse -+ fun:ngx_http_core_server -+ fun:ngx_conf_handler -+ fun:ngx_conf_parse -+ fun:ngx_http_block -+ fun:ngx_conf_handler -+ fun:ngx_conf_parse -+ fun:ngx_init_cycle -+ fun:main -+} -+{ -+ -+ Memcheck:Leak -+ match-leak-kinds: definite -+ fun:malloc -+ fun:ngx_alloc -+ fun:ngx_regex_malloc -+ fun:pcre2_compile_context_create_8 -+ fun:ngx_regex_compile -+ fun:ngx_http_regex_compile -+ fun:ngx_http_rewrite -+ fun:ngx_conf_handler -+ fun:ngx_conf_parse -+ fun:ngx_http_core_server -+ fun:ngx_conf_handler -+ fun:ngx_conf_parse -+ fun:ngx_http_block -+ fun:ngx_conf_handler -+ fun:ngx_conf_parse -+ fun:ngx_init_cycle -+ fun:main -+} ---- a/nginx-mod-lua/t/cert/test.crt -+++ b/nginx-mod-lua/t/cert/test.crt -@@ -1,17 +1,22 @@ - -----BEGIN CERTIFICATE----- --MIICqTCCAhICCQClDm1WkreW4jANBgkqhkiG9w0BAQUFADCBlzELMAkGA1UEBhMC --VVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28x --EjAQBgNVBAoMCU9wZW5SZXN0eTESMBAGA1UECwwJT3BlblJlc3R5MREwDwYDVQQD --DAh0ZXN0LmNvbTEgMB4GCSqGSIb3DQEJARYRYWdlbnR6aEBnbWFpbC5jb20wIBcN --MTQwNzIxMDMyMzQ3WhgPMjE1MTA2MTMwMzIzNDdaMIGXMQswCQYDVQQGEwJVUzET --MBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2FuIEZyYW5jaXNjbzESMBAG --A1UECgwJT3BlblJlc3R5MRIwEAYDVQQLDAlPcGVuUmVzdHkxETAPBgNVBAMMCHRl --c3QuY29tMSAwHgYJKoZIhvcNAQkBFhFhZ2VudHpoQGdtYWlsLmNvbTCBnzANBgkq --hkiG9w0BAQEFAAOBjQAwgYkCgYEA6P18zUvtmaKQK2xePy8ZbFwSyTLw+jW6t9eZ --aiTec8X3ibN9WemrxHzkTRikxP3cAQoITRuZiQvF4Q7DO6wMkz/b0zwfgX5uedGq --047AJP6n/mwlDOjGSNomBLoXQzo7tVe60ikEm3ZyDUqnJPJMt3hImO5XSop4MPMu --Za9WhFcCAwEAATANBgkqhkiG9w0BAQUFAAOBgQA4OBb9bOyWB1//93nSXX1mdENZ --IQeyTK0Dd6My76lnZxnZ4hTWrvvd0b17KLDU6JnS2N5ee3ATVkojPidRLWLIhnh5 --0eXrcKalbO2Ce6nShoFvQCQKXN2Txmq2vO/Mud2bHAWwJALg+qi1Iih/gVYB9sct --FLg8zFOzRlYiU+6Mmw== -+MIIDtzCCAp8CFCJnLifDCaXjYb2ARKBBhs+aAgYOMA0GCSqGSIb3DQEBCwUAMIGX -+MQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2Fu -+IEZyYW5jaXNjbzESMBAGA1UECgwJT3BlblJlc3R5MRIwEAYDVQQLDAlPcGVuUmVz -+dHkxETAPBgNVBAMMCHRlc3QuY29tMSAwHgYJKoZIhvcNAQkBFhFhZ2VudHpoQGdt -+YWlsLmNvbTAeFw0yMzA5MDUwNDE5MjhaFw0zMzA5MDIwNDE5MjhaMIGXMQswCQYD -+VQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2FuIEZyYW5j -+aXNjbzESMBAGA1UECgwJT3BlblJlc3R5MRIwEAYDVQQLDAlPcGVuUmVzdHkxETAP -+BgNVBAMMCHRlc3QuY29tMSAwHgYJKoZIhvcNAQkBFhFhZ2VudHpoQGdtYWlsLmNv -+bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJzRMFoLDuYOwJ8szrS4 -+nOibtiimiXZJGx3I/RcFZxaH4nL/WcEb1fwftMQxx73IBJnqnDYkDOzUmzItPMn0 -+t2WrNYesC5GqLNRm87m6PVt010tZvq/WxTn6+9qruiGm1PhFxzLQfrClpEeOshlG -+UeoQjPOMrhCmofDM2NQo3D4wIQT0kCJxIPq6wCZt22/Yqz1EmR0UnF/R3ZtiB8O+ -+SQGcsUKy4se3919xq+ZkzBdMxLneO5sofUiDC9MgRfiU960tbHPGX9I9P+kLK89S -+yajPEYaRUkSBFjV5kdDK3+L6XckdMbY2pvwhAnVXSmd13Bf2V9XisUrX2Mr4YlnS -+sy0CAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAVPY/z6Mvjg5EGHzU8bXyuXqxrx8Q -+GBwf3PY25aDF6ofRrTCzMdIhthv8eRtGwHinkpgaK34D7hI/dPB7aswQTzED5c+l -+S2au5OzzCj454oXdhSRA5Rt0mu/+pxmQ+iNk+7XJxgTN0mk1dYQqodyZ+vC4NIYb -+javMlU4zDm4JPtwDs0Mz/d7gf14MU60jppF2vl6AYFHKYBLMHBmqxjy6H9YHjRjQ -+oe4TNpn0zxJAPu5LqMkfB2+eLOe6ced7DcLLbbeVJ4Xtqj6Y5KsAyVojWQxrk4vW -+3WO/953pHofO5F2ricS/rsf+5ivTmfiP8mQYTtp7k3T11sIZ4DOmtNwO4A== - -----END CERTIFICATE----- ---- a/nginx-mod-lua/t/cert/test.key -+++ b/nginx-mod-lua/t/cert/test.key -@@ -1,15 +1,28 @@ -------BEGIN RSA PRIVATE KEY----- --MIICXgIBAAKBgQDo/XzNS+2ZopArbF4/LxlsXBLJMvD6Nbq315lqJN5zxfeJs31Z --6avEfORNGKTE/dwBCghNG5mJC8XhDsM7rAyTP9vTPB+Bfm550arTjsAk/qf+bCUM --6MZI2iYEuhdDOju1V7rSKQSbdnINSqck8ky3eEiY7ldKingw8y5lr1aEVwIDAQAB --AoGBANgB66sKMga2SKN5nQdHS3LDCkevCutu1OWM5ZcbB4Kej5kC57xsf+tzPtab --emeIVGhCPOAALqB4YcT+QtMX967oM1MjcFbtH7si5oq6UYyp3i0G9Si6jIoVHz3+ --8yOUaqwKbK+bRX8VS0YsHZmBsPK5ryN50iUwsU08nemoA94BAkEA9GS9Q5OPeFkM --tFxsIQ1f2FSsZAuN/1cpZgJqY+YaAN7MSPGTWyfd7nWG/Zgk3GO9/2ihh4gww+7B --To09GkmW4QJBAPQOHC2V+t2TA98+6Lj6+TYwcGEkhOENfVpH25mQ+kXgF/1Bd6rA --nosT1bdAY+SnmWXbSw6Kv5C20Em+bEX8WjcCQCSRRjhsRdVODbaW9Z7kb2jhEoJN --sEt6cTlQNzcHYPCsZYisjM3g4zYg47fiIfHQAsfKkhDDcfh/KvFj9LaQOEECQQCH --eBWYEDpSJ7rsfqT7mQQgWj7nDThdG/nK1TxGP71McBmg0Gg2dfkLRhVJRQqt74Is --kc9V4Rp4n6F6baL4Lh19AkEA6pZZer0kg3Kv9hjhaITIKUYdfIp9vYnDRWbQlBmR --atV8V9u9q2ETZvqfHpN+9Lu6NYR4yXIEIRf1bnIZ/mr9eQ== -------END RSA PRIVATE KEY----- -+-----BEGIN PRIVATE KEY----- -+MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCc0TBaCw7mDsCf -+LM60uJzom7Yopol2SRsdyP0XBWcWh+Jy/1nBG9X8H7TEMce9yASZ6pw2JAzs1Jsy -+LTzJ9LdlqzWHrAuRqizUZvO5uj1bdNdLWb6v1sU5+vvaq7ohptT4Rccy0H6wpaRH -+jrIZRlHqEIzzjK4QpqHwzNjUKNw+MCEE9JAicSD6usAmbdtv2Ks9RJkdFJxf0d2b -+YgfDvkkBnLFCsuLHt/dfcavmZMwXTMS53jubKH1IgwvTIEX4lPetLWxzxl/SPT/p -+CyvPUsmozxGGkVJEgRY1eZHQyt/i+l3JHTG2Nqb8IQJ1V0pnddwX9lfV4rFK19jK -++GJZ0rMtAgMBAAECggEABjaOkcllis1o/yrVZMPPabLpAHV6tZ5MuKfNiUOMSPr+ -+HfF1OFQL7MxCdfyFQ1prqOp/9nAut+puMgp99wAfDQ7qanNGq7vgQKkfPSD+dy4V -+rUquELBJH6nh9SZqfpSqKaJgHlNe6vehHuRYikJRkrJwVzegGjuekm3B+y6Zl/gc -+e0p5Ha3MTLTFjocwYzgTjJlxD40wlbjpuVnmzKjo8AKNv1F1azMaqBmt1VfPiDn0 -+Xyq4SPEsWKnEAl2kZdaIBR6zIx7Z3zNUwkfb32QwNoSyo8wS7lCgf2GVS7r1Eul6 -+iiCE/Gd7w10alW4Pu96shVqkvKn7ROF2nBP9xOSPwQKBgQDCuD6mlNpA07iOX364 -+aAzIAYookceVA0I9L/fbOQW7RgpvYpM8lxr31TQ3fBDkXSgjzMMYjnk4kz+xN+BB -+WFdjb4raUBtrvip8Q8QZ53DVQK/LodHh0XhipbOxZrDm+6o5nQD0fTqHCBIHSVFF -+tXX2Y90t1cxWMMleRhfNEuzkQQKBgQDOK0rs7mf04Xhc4ZIRIxOtNFnthGp4Kqp7 -+SD8VQpbPOLV8iqZEtXIy/hvoTpfQW30c1931KgDQ3Pv5MZYpI7PLqrqkj4tGCQ91 -+DJ03GWkSXcMwlPmJRbvgWIeCLgShU5PLxmQu3mH2DP+uGFUBq5/6miDDVjF9z6vb -+BwYlG66j7QKBgA0n/bOrowN2SqXz9c/n19U7pWYQU3fR/Iu9zfVV6Pk6RkI4WtJh -+M0VDdn+5Njr3wFqK3zOtjKsx57/FkrVXjq/9PVh6yR+CfcRfn8RQSuNdt4L+r/ud -+95BSuc1mrtUsc9for8PVIjs1ZGJxpbgcBphbLvqF04SPT0u7WKhWewMBAoGAcJO/ -+RAUiitsbaExcADORKQDvIf0uThOuJ8dZevhzdQ/YOftTsy0JAMM05fMUfteWR8uw -+DZE0BNjGVlo3TpuKL+o4JGele0azRAzxRAcCEt9UGBEg+U40utpclD8glB8ZEypv -+xg/0mfCbJKtwr4rRvnuu7DsCp1pg0ybQui6VfDkCgYBXHwcrZwmv7kgr4pUG6oZj -+fzjFenQFqibvb2h7QESyCW13O885GxU13DKv4zg1yi6EqPIopz16qCiUNCvWr5Us -+6sI74wEVI3MzmzG0Htgl29q5yWpeY+7libC/fbZYG8GFgdINq58ko9be1u/8644S -+t2hoKM9/vrVFh9p9qGzckg== -+-----END PRIVATE KEY----- diff --git a/packages/nginx/patches/nginx-mod-lua/100-no_by_lua_block.patch b/packages/nginx/patches/nginx-mod-lua/100-no_by_lua_block.patch deleted file mode 100644 index 1572a4cbb..000000000 --- a/packages/nginx/patches/nginx-mod-lua/100-no_by_lua_block.patch +++ /dev/null @@ -1,250 +0,0 @@ ---- a/nginx-mod-lua/src/ngx_http_lua_module.c -+++ b/nginx-mod-lua/src/ngx_http_lua_module.c -@@ -212,12 +212,14 @@ static ngx_command_t ngx_http_lua_cmds[] - offsetof(ngx_http_lua_loc_conf_t, log_socket_errors), - NULL }, - -+#ifndef NGX_LUA_NO_BY_LUA_BLOCK - { ngx_string("init_by_lua_block"), - NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, - ngx_http_lua_init_by_lua_block, - NGX_HTTP_MAIN_CONF_OFFSET, - 0, - (void *) ngx_http_lua_init_by_inline }, -+#endif - - { ngx_string("init_by_lua"), - NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, -@@ -233,12 +235,14 @@ static ngx_command_t ngx_http_lua_cmds[] - 0, - (void *) ngx_http_lua_init_by_file }, - -+#ifndef NGX_LUA_NO_BY_LUA_BLOCK - { ngx_string("init_worker_by_lua_block"), - NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, - ngx_http_lua_init_worker_by_lua_block, - NGX_HTTP_MAIN_CONF_OFFSET, - 0, - (void *) ngx_http_lua_init_worker_by_inline }, -+#endif - - { ngx_string("init_worker_by_lua"), - NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, -@@ -254,12 +258,14 @@ static ngx_command_t ngx_http_lua_cmds[] - 0, - (void *) ngx_http_lua_init_worker_by_file }, - -+#ifndef NGX_LUA_NO_BY_LUA_BLOCK - { ngx_string("exit_worker_by_lua_block"), - NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, - ngx_http_lua_exit_worker_by_lua_block, - NGX_HTTP_MAIN_CONF_OFFSET, - 0, - (void *) ngx_http_lua_exit_worker_by_inline }, -+#endif - - { ngx_string("exit_worker_by_lua_file"), - NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, -@@ -269,6 +275,7 @@ static ngx_command_t ngx_http_lua_cmds[] - (void *) ngx_http_lua_exit_worker_by_file }, - - #if defined(NDK) && NDK -+#ifndef NGX_LUA_NO_BY_LUA_BLOCK - /* set_by_lua_block $res { inline Lua code } */ - { ngx_string("set_by_lua_block"), - NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF -@@ -277,6 +284,7 @@ static ngx_command_t ngx_http_lua_cmds[] - NGX_HTTP_LOC_CONF_OFFSET, - 0, - (void *) ngx_http_lua_filter_set_by_lua_inline }, -+#endif - - /* set_by_lua $res [$arg1 [$arg2 [...]]] */ - { ngx_string("set_by_lua"), -@@ -297,6 +305,7 @@ static ngx_command_t ngx_http_lua_cmds[] - (void *) ngx_http_lua_filter_set_by_lua_file }, - #endif - -+#ifndef NGX_LUA_NO_BY_LUA_BLOCK - /* server_rewrite_by_lua_block { } */ - { ngx_string("server_rewrite_by_lua_block"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, -@@ -304,6 +313,7 @@ static ngx_command_t ngx_http_lua_cmds[] - NGX_HTTP_SRV_CONF_OFFSET, - 0, - (void *) ngx_http_lua_server_rewrite_handler_inline }, -+#endif - - /* server_rewrite_by_lua_file filename; */ - { ngx_string("server_rewrite_by_lua_file"), -@@ -322,6 +332,7 @@ static ngx_command_t ngx_http_lua_cmds[] - 0, - (void *) ngx_http_lua_rewrite_handler_inline }, - -+#ifndef NGX_LUA_NO_BY_LUA_BLOCK - /* rewrite_by_lua_block { } */ - { ngx_string("rewrite_by_lua_block"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF -@@ -330,6 +341,7 @@ static ngx_command_t ngx_http_lua_cmds[] - NGX_HTTP_LOC_CONF_OFFSET, - 0, - (void *) ngx_http_lua_rewrite_handler_inline }, -+#endif - - /* access_by_lua "" */ - { ngx_string("access_by_lua"), -@@ -340,6 +352,7 @@ static ngx_command_t ngx_http_lua_cmds[] - 0, - (void *) ngx_http_lua_access_handler_inline }, - -+#ifndef NGX_LUA_NO_BY_LUA_BLOCK - /* access_by_lua_block { } */ - { ngx_string("access_by_lua_block"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF -@@ -348,6 +361,7 @@ static ngx_command_t ngx_http_lua_cmds[] - NGX_HTTP_LOC_CONF_OFFSET, - 0, - (void *) ngx_http_lua_access_handler_inline }, -+#endif - - /* content_by_lua "" */ - { ngx_string("content_by_lua"), -@@ -357,6 +371,7 @@ static ngx_command_t ngx_http_lua_cmds[] - 0, - (void *) ngx_http_lua_content_handler_inline }, - -+#ifndef NGX_LUA_NO_BY_LUA_BLOCK - /* content_by_lua_block { } */ - { ngx_string("content_by_lua_block"), - NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, -@@ -364,6 +379,7 @@ static ngx_command_t ngx_http_lua_cmds[] - NGX_HTTP_LOC_CONF_OFFSET, - 0, - (void *) ngx_http_lua_content_handler_inline }, -+#endif - - /* log_by_lua */ - { ngx_string("log_by_lua"), -@@ -374,6 +390,7 @@ static ngx_command_t ngx_http_lua_cmds[] - 0, - (void *) ngx_http_lua_log_handler_inline }, - -+#ifndef NGX_LUA_NO_BY_LUA_BLOCK - /* log_by_lua_block { } */ - { ngx_string("log_by_lua_block"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF -@@ -382,6 +399,7 @@ static ngx_command_t ngx_http_lua_cmds[] - NGX_HTTP_LOC_CONF_OFFSET, - 0, - (void *) ngx_http_lua_log_handler_inline }, -+#endif - - { ngx_string("rewrite_by_lua_file"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF -@@ -438,6 +456,7 @@ static ngx_command_t ngx_http_lua_cmds[] - 0, - (void *) ngx_http_lua_header_filter_inline }, - -+#ifndef NGX_LUA_NO_BY_LUA_BLOCK - /* header_filter_by_lua_block { } */ - { ngx_string("header_filter_by_lua_block"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF -@@ -446,6 +465,7 @@ static ngx_command_t ngx_http_lua_cmds[] - NGX_HTTP_LOC_CONF_OFFSET, - 0, - (void *) ngx_http_lua_header_filter_inline }, -+#endif - - { ngx_string("header_filter_by_lua_file"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF -@@ -463,6 +483,7 @@ static ngx_command_t ngx_http_lua_cmds[] - 0, - (void *) ngx_http_lua_body_filter_inline }, - -+#ifndef NGX_LUA_NO_BY_LUA_BLOCK - /* body_filter_by_lua_block { } */ - { ngx_string("body_filter_by_lua_block"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF -@@ -471,6 +492,7 @@ static ngx_command_t ngx_http_lua_cmds[] - NGX_HTTP_LOC_CONF_OFFSET, - 0, - (void *) ngx_http_lua_body_filter_inline }, -+#endif - - { ngx_string("body_filter_by_lua_file"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF -@@ -480,12 +502,14 @@ static ngx_command_t ngx_http_lua_cmds[] - 0, - (void *) ngx_http_lua_body_filter_file }, - -+#ifndef NGX_LUA_NO_BY_LUA_BLOCK - { ngx_string("balancer_by_lua_block"), - NGX_HTTP_UPS_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, - ngx_http_lua_balancer_by_lua_block, - NGX_HTTP_SRV_CONF_OFFSET, - 0, - (void *) ngx_http_lua_balancer_handler_inline }, -+#endif - - { ngx_string("balancer_by_lua_file"), - NGX_HTTP_UPS_CONF|NGX_CONF_TAKE1, -@@ -590,12 +614,14 @@ static ngx_command_t ngx_http_lua_cmds[] - offsetof(ngx_http_lua_loc_conf_t, ssl_ciphers), - NULL }, - -+#ifndef NGX_LUA_NO_BY_LUA_BLOCK - { ngx_string("ssl_client_hello_by_lua_block"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, - ngx_http_lua_ssl_client_hello_by_lua_block, - NGX_HTTP_SRV_CONF_OFFSET, - 0, - (void *) ngx_http_lua_ssl_client_hello_handler_inline }, -+#endif - - { ngx_string("ssl_client_hello_by_lua_file"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, -@@ -604,12 +630,14 @@ static ngx_command_t ngx_http_lua_cmds[] - 0, - (void *) ngx_http_lua_ssl_client_hello_handler_file }, - -+#ifndef NGX_LUA_NO_BY_LUA_BLOCK - { ngx_string("ssl_certificate_by_lua_block"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, - ngx_http_lua_ssl_cert_by_lua_block, - NGX_HTTP_SRV_CONF_OFFSET, - 0, - (void *) ngx_http_lua_ssl_cert_handler_inline }, -+#endif - - { ngx_string("ssl_certificate_by_lua_file"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, -@@ -618,12 +646,14 @@ static ngx_command_t ngx_http_lua_cmds[] - 0, - (void *) ngx_http_lua_ssl_cert_handler_file }, - -+#ifndef NGX_LUA_NO_BY_LUA_BLOCK - { ngx_string("ssl_session_store_by_lua_block"), - NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, - ngx_http_lua_ssl_sess_store_by_lua_block, - NGX_HTTP_SRV_CONF_OFFSET, - 0, - (void *) ngx_http_lua_ssl_sess_store_handler_inline }, -+#endif - - { ngx_string("ssl_session_store_by_lua_file"), - NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, -@@ -632,12 +662,14 @@ static ngx_command_t ngx_http_lua_cmds[] - 0, - (void *) ngx_http_lua_ssl_sess_store_handler_file }, - -+#ifndef NGX_LUA_NO_BY_LUA_BLOCK - { ngx_string("ssl_session_fetch_by_lua_block"), - NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, - ngx_http_lua_ssl_sess_fetch_by_lua_block, - NGX_HTTP_SRV_CONF_OFFSET, - 0, - (void *) ngx_http_lua_ssl_sess_fetch_handler_inline }, -+#endif - - { ngx_string("ssl_session_fetch_by_lua_file"), - NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, diff --git a/packages/nginx/patches/nginx-mod-lua/101-bugfix-don-t-include-pcre.h-with-PCRE2-used.patch b/packages/nginx/patches/nginx-mod-lua/101-bugfix-don-t-include-pcre.h-with-PCRE2-used.patch deleted file mode 100644 index da3c4607d..000000000 --- a/packages/nginx/patches/nginx-mod-lua/101-bugfix-don-t-include-pcre.h-with-PCRE2-used.patch +++ /dev/null @@ -1,27 +0,0 @@ -From f968d74c3af8259f325090d282aeb64854cdddf9 Mon Sep 17 00:00:00 2001 -From: Christian Marangi -Date: Fri, 13 Oct 2023 20:23:51 +0200 -Subject: [PATCH] bugfix: don't include pcre.h with PCRE2 used - -pcre.h is a PCRE header and is not exposed by PCRE2 library causing -compilation error as the header is not found. - -Don't include pcre.h if nginx is compiled with PCRE2 support enabled. - -Fixes: cb83e33e2657 ("feature: support pcre2") -Signed-off-by: Christian Marangi ---- - nginx-mod-lua/src/ngx_http_lua_common.h | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - ---- a/nginx-mod-lua/src/ngx_http_lua_common.h -+++ b/nginx-mod-lua/src/ngx_http_lua_common.h -@@ -54,7 +54,7 @@ typedef struct { - #endif - - --#if (NGX_PCRE) -+#if defined(NGX_PCRE) && !(NGX_PCRE2) - #include - # if (PCRE_MAJOR > 8) || (PCRE_MAJOR == 8 && PCRE_MINOR >= 21) - # define LUA_HAVE_PCRE_JIT 1 diff --git a/packages/nginx/patches/nginx-mod-rtmp/100-bigedian.patch b/packages/nginx/patches/nginx-mod-rtmp/100-bigedian.patch deleted file mode 100644 index b7b78fc92..000000000 --- a/packages/nginx/patches/nginx-mod-rtmp/100-bigedian.patch +++ /dev/null @@ -1,1521 +0,0 @@ -From 5b06d1cad5f6711667038169b7ed759d749334da Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Jan=20Bub=C3=ADk?= -Date: Wed, 13 May 2020 19:57:47 +0200 -Subject: [PATCH 1/3] arut's e0e278bc7fedd6f7465648d1d20df1a8422d60bf [removed - endian-dependent code] - ---- - ngx_rtmp.c | 4 ++ - ngx_rtmp.h | 12 +++-- - ngx_rtmp_amf.c | 6 +-- - ngx_rtmp_flv_module.c | 2 +- - ngx_rtmp_handler.c | 108 +++++++++++++++++++++--------------------- - 5 files changed, 68 insertions(+), 64 deletions(-) - ---- a/nginx-mod-rtmp/ngx_rtmp.c -+++ b/nginx-mod-rtmp/ngx_rtmp.c -@@ -825,22 +825,6 @@ ngx_rtmp_fire_event(ngx_rtmp_session_t * - } - - --void * --ngx_rtmp_rmemcpy(void *dst, const void* src, size_t n) --{ -- u_char *d, *s; -- -- d = dst; -- s = (u_char*)src + n - 1; -- -- while(s >= (u_char*)src) { -- *d++ = *s--; -- } -- -- return dst; --} -- -- - static ngx_int_t - ngx_rtmp_init_process(ngx_cycle_t *cycle) - { ---- a/nginx-mod-rtmp/ngx_rtmp.h -+++ b/nginx-mod-rtmp/ngx_rtmp.h -@@ -417,34 +417,33 @@ ngx_int_t ngx_rtmp_fire_event(ngx_rtmp_s - ngx_int_t ngx_rtmp_set_chunk_size(ngx_rtmp_session_t *s, ngx_uint_t size); - - --/* Bit reverse: we need big-endians in many places */ --void * ngx_rtmp_rmemcpy(void *dst, const void* src, size_t n); -- --#define ngx_rtmp_rcpymem(dst, src, n) \ -- (((u_char*)ngx_rtmp_rmemcpy(dst, src, n)) + (n)) -- -- --static ngx_inline uint16_t --ngx_rtmp_r16(uint16_t n) -+/* Bit agnosticism: we need network to host byte-order conversion in many places */ -+static ngx_inline uint64_t -+ntohll(uint64_t n) - { -- return (n << 8) | (n >> 8); -+#if (NGX_HAVE_LITTLE_ENDIAN) -+ return (uint64_t) ntohl((uint32_t) n) << 32 | -+ ntohl((uint32_t) (n >> 32)); -+#else -+ return n; -+#endif - } - -- - static ngx_inline uint32_t --ngx_rtmp_r32(uint32_t n) -+n3toh4(u_char* src) - { -- return (n << 24) | ((n << 8) & 0xff0000) | ((n >> 8) & 0xff00) | (n >> 24); -+ return ((uint32_t)src[0]<<16)|((uint32_t)src[1]<<8)|src[2]; - } - -- --static ngx_inline uint64_t --ngx_rtmp_r64(uint64_t n) -+static ngx_inline u_char* -+h4ton3(u_char* dst, uint32_t src) - { -- return (uint64_t) ngx_rtmp_r32((uint32_t) n) << 32 | -- ngx_rtmp_r32((uint32_t) (n >> 32)); --} -+ dst[0]=(u_char)(src>>16); -+ dst[1]=(u_char)(src>>8); -+ dst[2]=(u_char)src; - -+ return dst+3; -+} - - /* Receiving messages */ - ngx_int_t ngx_rtmp_receive_message(ngx_rtmp_session_t *s, ---- a/nginx-mod-rtmp/ngx_rtmp_amf.c -+++ b/nginx-mod-rtmp/ngx_rtmp_amf.c -@@ -10,23 +10,6 @@ - #include "ngx_rtmp.h" - #include - -- --static ngx_inline void* --ngx_rtmp_amf_reverse_copy(void *dst, void* src, size_t len) --{ -- size_t k; -- -- if (dst == NULL || src == NULL) { -- return NULL; -- } -- -- for(k = 0; k < len; ++k) { -- ((u_char*)dst)[k] = ((u_char*)src)[len - 1 - k]; -- } -- -- return dst; --} -- - #define NGX_RTMP_AMF_DEBUG_SIZE 72 - - #ifdef NGX_DEBUG -@@ -207,7 +190,7 @@ ngx_rtmp_amf_read_object(ngx_rtmp_amf_ct - return NGX_ERROR; - } - -- ngx_rtmp_amf_reverse_copy(&len, buf, 2); -+ len=ntohs(*(uint16_t*)&buf[0]); - - if (!len) - break; -@@ -258,7 +241,7 @@ ngx_rtmp_amf_read_array(ngx_rtmp_amf_ctx - if (ngx_rtmp_amf_get(ctx, buf, 4) != NGX_OK) - return NGX_ERROR; - -- ngx_rtmp_amf_reverse_copy(&len, buf, 4); -+ len=ntohl(*(uint32_t*)&buf[0]); - - for (n = 0; n < len; ++n) { - if (ngx_rtmp_amf_read(ctx, n < nelts ? &elts[n] : NULL, 1) != NGX_OK) -@@ -352,10 +335,9 @@ ngx_rtmp_amf_read(ngx_rtmp_amf_ctx_t *ct - - switch (type) { - case NGX_RTMP_AMF_NUMBER: -- if (ngx_rtmp_amf_get(ctx, buf, 8) != NGX_OK) { -+ if (ngx_rtmp_amf_get(ctx, data, 8) != NGX_OK) { - return NGX_ERROR; - } -- ngx_rtmp_amf_reverse_copy(data, buf, 8); - break; - - case NGX_RTMP_AMF_BOOLEAN: -@@ -368,7 +350,7 @@ ngx_rtmp_amf_read(ngx_rtmp_amf_ctx_t *ct - if (ngx_rtmp_amf_get(ctx, buf, 2) != NGX_OK) { - return NGX_ERROR; - } -- ngx_rtmp_amf_reverse_copy(&len, buf, 2); -+ len=ntohs(*(uint16_t*)buf); - - if (data == NULL) { - rc = ngx_rtmp_amf_get(ctx, data, len); -@@ -438,14 +420,14 @@ ngx_rtmp_amf_read(ngx_rtmp_amf_ctx_t *ct - if (ngx_rtmp_amf_get(ctx, buf, 2) != NGX_OK) { - return NGX_ERROR; - } -- ngx_rtmp_amf_reverse_copy(data, buf, 2); -+ *(uint16_t*)data=ntohs(*(uint16_t*)buf); - break; - - case NGX_RTMP_AMF_INT32: - if (ngx_rtmp_amf_get(ctx, buf, 4) != NGX_OK) { - return NGX_ERROR; - } -- ngx_rtmp_amf_reverse_copy(data, buf, 4); -+ *(uint32_t*)data=ntohs(*(uint32_t*)buf); - break; - - case NGX_RTMP_AMF_END: -@@ -476,9 +458,8 @@ ngx_rtmp_amf_write_object(ngx_rtmp_amf_c - - len = (uint16_t) elts[n].name.len; - -- if (ngx_rtmp_amf_put(ctx, -- ngx_rtmp_amf_reverse_copy(buf, -- &len, 2), 2) != NGX_OK) -+ *(uint16_t*)buf = htons(len); -+ if (ngx_rtmp_amf_put(ctx, buf, 2) != NGX_OK) - { - return NGX_ERROR; - } -@@ -509,9 +490,8 @@ ngx_rtmp_amf_write_array(ngx_rtmp_amf_ct - u_char buf[4]; - - len = nelts; -- if (ngx_rtmp_amf_put(ctx, -- ngx_rtmp_amf_reverse_copy(buf, -- &len, 4), 4) != NGX_OK) -+ *(uint32_t*)buf = htonl(len); -+ if (ngx_rtmp_amf_put(ctx, buf, 4) != NGX_OK) - { - return NGX_ERROR; - } -@@ -554,9 +534,7 @@ ngx_rtmp_amf_write(ngx_rtmp_amf_ctx_t *c - - switch(type) { - case NGX_RTMP_AMF_NUMBER: -- if (ngx_rtmp_amf_put(ctx, -- ngx_rtmp_amf_reverse_copy(buf, -- data, 8), 8) != NGX_OK) -+ if (ngx_rtmp_amf_put(ctx, data, 8) != NGX_OK) - { - return NGX_ERROR; - } -@@ -573,9 +551,8 @@ ngx_rtmp_amf_write(ngx_rtmp_amf_ctx_t *c - len = (uint16_t) ngx_strlen((u_char*) data); - } - -- if (ngx_rtmp_amf_put(ctx, -- ngx_rtmp_amf_reverse_copy(buf, -- &len, 2), 2) != NGX_OK) -+ *(uint16_t*)buf = htons(len); -+ if (ngx_rtmp_amf_put(ctx, buf, 2) != NGX_OK) - { - return NGX_ERROR; - } -@@ -621,18 +598,16 @@ ngx_rtmp_amf_write(ngx_rtmp_amf_ctx_t *c - break; - - case NGX_RTMP_AMF_INT16: -- if (ngx_rtmp_amf_put(ctx, -- ngx_rtmp_amf_reverse_copy(buf, -- data, 2), 2) != NGX_OK) -+ *(uint16_t*)buf = htons(*(uint16_t*)data); -+ if (ngx_rtmp_amf_put(ctx, buf, 2) != NGX_OK) - { - return NGX_ERROR; - } - break; - - case NGX_RTMP_AMF_INT32: -- if (ngx_rtmp_amf_put(ctx, -- ngx_rtmp_amf_reverse_copy(buf, -- data, 4), 4) != NGX_OK) -+ *(uint32_t*)buf = htonl(*(uint32_t*)data); -+ if (ngx_rtmp_amf_put(ctx, buf, 4) != NGX_OK) - { - return NGX_ERROR; - } ---- a/nginx-mod-rtmp/ngx_rtmp_flv_module.c -+++ b/nginx-mod-rtmp/ngx_rtmp_flv_module.c -@@ -102,7 +102,7 @@ ngx_rtmp_flv_fill_index(ngx_rtmp_amf_ctx - return NGX_ERROR; - } - -- ngx_rtmp_rmemcpy(&nelts, b->pos + ctx->offset, 4); -+ nelts=htonl(*(uint32_t*)(b->pos + ctx->offset)); - - idx->nelts = nelts; - idx->offset = ctx->offset + 4; -@@ -201,11 +201,7 @@ ngx_rtmp_flv_init_index(ngx_rtmp_session - static double - ngx_rtmp_flv_index_value(void *src) - { -- double v; -- -- ngx_rtmp_rmemcpy(&v, src, 8); -- -- return v; -+ return *(double*)src; - } - - -@@ -352,8 +348,7 @@ ngx_rtmp_flv_read_meta(ngx_rtmp_session_ - h.msid = NGX_RTMP_MSID; - h.csid = NGX_RTMP_CSID_AMF; - -- size = 0; -- ngx_rtmp_rmemcpy(&size, ngx_rtmp_flv_header + 1, 3); -+ size = n3toh4(ngx_rtmp_flv_header + 1); - - ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "flv: metadata size=%D", size); -@@ -440,12 +435,9 @@ ngx_rtmp_flv_send(ngx_rtmp_session_t *s, - h.msid = NGX_RTMP_MSID; - h.type = ngx_rtmp_flv_header[0]; - -- size = 0; -- -- ngx_rtmp_rmemcpy(&size, ngx_rtmp_flv_header + 1, 3); -- ngx_rtmp_rmemcpy(&h.timestamp, ngx_rtmp_flv_header + 4, 3); -- -- ((u_char *) &h.timestamp)[3] = ngx_rtmp_flv_header[7]; -+ size = n3toh4(ngx_rtmp_flv_header + 1); -+ h.timestamp = n3toh4(ngx_rtmp_flv_header + 4); -+ h.timestamp |= ((uint32_t) ngx_rtmp_flv_header[7] << 24); - - ctx->offset += (sizeof(ngx_rtmp_flv_header) + size + 4); - ---- a/nginx-mod-rtmp/ngx_rtmp_handler.c -+++ b/nginx-mod-rtmp/ngx_rtmp_handler.c -@@ -200,7 +200,7 @@ ngx_rtmp_recv(ngx_event_t *rev) - ngx_rtmp_stream_t *st, *st0; - ngx_chain_t *in, *head; - ngx_buf_t *b; -- u_char *p, *pp, *old_pos; -+ u_char *p, *old_pos; - size_t size, fsize, old_size; - uint8_t fmt, ext; - uint32_t csid, timestamp; -@@ -308,14 +308,14 @@ ngx_rtmp_recv(ngx_event_t *rev) - if (b->last - p < 1) - continue; - csid = 64; -- csid += *(uint8_t*)p++; -+ csid += *p++; - - } else if (csid == 1) { - if (b->last - p < 2) - continue; - csid = 64; -- csid += *(uint8_t*)p++; -- csid += (uint32_t)256 * (*(uint8_t*)p++); -+ csid += *p++; -+ csid += ((uint32_t) *p++ << 8); - } - - ngx_log_debug2(NGX_LOG_DEBUG_RTMP, c->log, 0, -@@ -355,40 +355,37 @@ ngx_rtmp_recv(ngx_event_t *rev) - if (fmt <= 2 ) { - if (b->last - p < 3) - continue; -- /* timestamp: -- * big-endian 3b -> little-endian 4b */ -- pp = (u_char*)×tamp; -- pp[2] = *p++; -- pp[1] = *p++; -- pp[0] = *p++; -- pp[3] = 0; -+ -+ /* timestamp: big-endian 3 bytes */ -+ -+ timestamp = ((uint32_t) *p++ << 16); -+ timestamp |= ((uint32_t) *p++ << 8); -+ timestamp |= *p++; - - ext = (timestamp == 0x00ffffff); - - if (fmt <= 1) { - if (b->last - p < 4) - continue; -- /* size: -- * big-endian 3b -> little-endian 4b -- * type: -- * 1b -> 1b*/ -- pp = (u_char*)&h->mlen; -- pp[2] = *p++; -- pp[1] = *p++; -- pp[0] = *p++; -- pp[3] = 0; -- h->type = *(uint8_t*)p++; -+ -+ /* size: big-endian 3 bytes */ -+ -+ h->mlen = ((uint32_t) *p++ << 16); -+ h->mlen |= ((uint32_t) *p++ << 8); -+ h->mlen |= *p++; -+ -+ h->type = *p++; - - if (fmt == 0) { - if (b->last - p < 4) - continue; -- /* stream: -- * little-endian 4b -> little-endian 4b */ -- pp = (u_char*)&h->msid; -- pp[0] = *p++; -- pp[1] = *p++; -- pp[2] = *p++; -- pp[3] = *p++; -+ -+ /* stream: little-endian 4 bytes */ -+ -+ h->msid = *p++; -+ h->msid |= ((uint32_t) *p++ << 8); -+ h->msid |= ((uint32_t) *p++ << 16); -+ h->msid |= ((uint32_t) *p++ << 24); - } - } - } -@@ -397,13 +394,13 @@ ngx_rtmp_recv(ngx_event_t *rev) - if (ext) { - if (b->last - p < 4) - continue; -- pp = (u_char*)×tamp; -- /* extented time stamp: -- * big-endian 4b -> little-endian 4b */ -- pp[3] = *p++; -- pp[2] = *p++; -- pp[1] = *p++; -- pp[0] = *p++; -+ -+ /* timestamp: big-endian 4 bytes */ -+ -+ timestamp = ((uint32_t) *p++ << 24); -+ timestamp |= ((uint32_t) *p++ << 16); -+ timestamp |= ((uint32_t) *p++ << 8); -+ timestamp |= *p++; - ngx_log_debug1(NGX_LOG_DEBUG_RTMP, c->log, 0, "RTMP extended timestamp %uD", (uint32_t)timestamp); - } - -@@ -584,7 +581,7 @@ ngx_rtmp_prepare_message(ngx_rtmp_sessio - ngx_rtmp_header_t *lh, ngx_chain_t *out) - { - ngx_chain_t *l; -- u_char *p, *pp; -+ u_char *p; - ngx_int_t hsize, thsize, nbufs; - uint32_t mlen, timestamp, ext_timestamp; - static uint8_t hdrsize[] = { 12, 8, 4, 1 }; -@@ -677,33 +674,36 @@ ngx_rtmp_prepare_message(ngx_rtmp_sessio - - /* message header */ - if (fmt <= 2) { -- pp = (u_char*)×tamp; -- *p++ = pp[2]; -- *p++ = pp[1]; -- *p++ = pp[0]; -+ -+ *p++ = (u_char) (timestamp >> 16); -+ *p++ = (u_char) (timestamp >> 8); -+ *p++ = (u_char) timestamp; -+ - if (fmt <= 1) { -- pp = (u_char*)&mlen; -- *p++ = pp[2]; -- *p++ = pp[1]; -- *p++ = pp[0]; -+ -+ *p++ = (u_char) (mlen >> 16); -+ *p++ = (u_char) (mlen >> 8); -+ *p++ = (u_char) mlen; -+ - *p++ = h->type; -+ - if (fmt == 0) { -- pp = (u_char*)&h->msid; -- *p++ = pp[0]; -- *p++ = pp[1]; -- *p++ = pp[2]; -- *p++ = pp[3]; -+ -+ *p++ = (u_char) h->msid; -+ *p++ = (u_char) (h->msid >> 8); -+ *p++ = (u_char) (h->msid >> 16); -+ *p++ = (u_char) (h->msid >> 24); - } - } - } - - /* extended header */ - if (ext_timestamp) { -- pp = (u_char*)&ext_timestamp; -- *p++ = pp[3]; -- *p++ = pp[2]; -- *p++ = pp[1]; -- *p++ = pp[0]; -+ -+ *p++ = (u_char) (ext_timestamp >> 24); -+ *p++ = (u_char) (ext_timestamp >> 16); -+ *p++ = (u_char) (ext_timestamp >> 8); -+ *p++ = (u_char) ext_timestamp; - - /* This CONTRADICTS the standard - * but that's the way flash client ---- a/nginx-mod-rtmp/ngx_rtmp_send.c -+++ b/nginx-mod-rtmp/ngx_rtmp_send.c -@@ -33,13 +33,13 @@ - *(__b->last++) = (u_char)(utype); - - #define NGX_RTMP_USER_OUT1(v) \ -- *(__b->last++) = ((u_char*)&v)[0]; -+ *(__b->last++) = (u_char) v; - - #define NGX_RTMP_USER_OUT4(v) \ -- *(__b->last++) = ((u_char*)&v)[3]; \ -- *(__b->last++) = ((u_char*)&v)[2]; \ -- *(__b->last++) = ((u_char*)&v)[1]; \ -- *(__b->last++) = ((u_char*)&v)[0]; -+ *(__b->last++) = (u_char) (v >> 24); \ -+ *(__b->last++) = (u_char) (v >> 16); \ -+ *(__b->last++) = (u_char) (v >> 8); \ -+ *(__b->last++) = (u_char) v; - - #define NGX_RTMP_USER_END(s) \ - ngx_rtmp_prepare_message(s, &__h, NULL, __l); \ ---- a/nginx-mod-rtmp/hls/ngx_rtmp_hls_module.c -+++ b/nginx-mod-rtmp/hls/ngx_rtmp_hls_module.c -@@ -296,7 +296,7 @@ static ngx_command_t ngx_rtmp_hls_comman - ngx_conf_set_enum_slot, - NGX_RTMP_APP_CONF_OFFSET, - offsetof(ngx_rtmp_hls_app_conf_t, allow_client_cache), -- &ngx_rtmp_hls_cache }, -+ &ngx_rtmp_hls_cache }, - - { ngx_string("hls_variant"), - NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_1MORE, -@@ -816,7 +816,7 @@ ngx_rtmp_hls_append_sps_pps(ngx_rtmp_ses - return NGX_ERROR; - } - -- ngx_rtmp_rmemcpy(&len, &rlen, 2); -+ len=ntohs(rlen); - - ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "hls: header NAL length: %uz", (size_t) len); -@@ -2072,7 +2072,21 @@ ngx_rtmp_hls_video(ngx_rtmp_session_t *s - } - - len = 0; -- ngx_rtmp_rmemcpy(&len, &rlen, nal_bytes); -+ -+ switch (nal_bytes) { -+ case 1: -+ len=*(uint8_t*)&rlen; -+ break; -+ case 2: -+ len=ntohs(*(uint16_t*)&rlen); -+ break; -+ case 3: -+ len=n3toh4((u_char*)&rlen); -+ break; -+ case 4: -+ len=ntohl(rlen); -+ break; -+ }; - - if (len == 0) { - continue; ---- a/nginx-mod-rtmp/ngx_rtmp_bitop.h -+++ b/nginx-mod-rtmp/ngx_rtmp_bitop.h -@@ -40,7 +40,7 @@ uint64_t ngx_rtmp_bit_read_golomb(ngx_rt - ((uint32_t) ngx_rtmp_bit_read(br, 32)) - - #define ngx_rtmp_bit_read_64(br) \ -- ((uint64_t) ngx_rtmp_read(br, 64)) -+ ((uint64_t) ngx_rtmp_bit_read(br, 64)) - - - #endif /* _NGX_RTMP_BITOP_H_INCLUDED_ */ ---- a/nginx-mod-rtmp/ngx_rtmp_eval.c -+++ b/nginx-mod-rtmp/ngx_rtmp_eval.c -@@ -166,7 +166,7 @@ ngx_rtmp_eval(void *ctx, ngx_str_t *in, - state = ESCAPE; - continue; - } -- -+ /* fall through */ - case ESCAPE: - ngx_rtmp_eval_append(&b, &c, 1, log); - state = NORMAL; ---- a/nginx-mod-rtmp/ngx_rtmp_handshake.c -+++ b/nginx-mod-rtmp/ngx_rtmp_handshake.c -@@ -264,7 +264,8 @@ ngx_rtmp_handshake_create_challenge(ngx_ - b = s->hs_buf; - b->last = b->pos = b->start; - *b->last++ = '\x03'; -- b->last = ngx_rtmp_rcpymem(b->last, &s->epoch, 4); -+ *(uint32_t*)b->last=htonl(s->epoch); -+ b->last +=4; - b->last = ngx_cpymem(b->last, version, 4); - ngx_rtmp_fill_random_buffer(b); - ++b->pos; -@@ -292,8 +293,7 @@ ngx_rtmp_handshake_parse_challenge(ngx_r - return NGX_ERROR; - } - ++b->pos; -- s->peer_epoch = 0; -- ngx_rtmp_rmemcpy(&s->peer_epoch, b->pos, 4); -+ s->peer_epoch = ntohl(*(uint32_t*)b->pos); - - p = b->pos + 4; - ngx_log_debug5(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, ---- a/nginx-mod-rtmp/ngx_rtmp_mp4_module.c -+++ b/nginx-mod-rtmp/ngx_rtmp_mp4_module.c -@@ -528,9 +528,9 @@ ngx_rtmp_mp4_parse_mdhd(ngx_rtmp_session - } - - pos += 12; -- t->time_scale = ngx_rtmp_r32(*(uint32_t *) pos); -+ t->time_scale = ntohl(*(uint32_t *) pos); - pos += 4; -- t->duration = ngx_rtmp_r32(*(uint32_t *) pos); -+ t->duration = ntohl(*(uint32_t *) pos); - break; - - case 1: -@@ -539,9 +539,9 @@ ngx_rtmp_mp4_parse_mdhd(ngx_rtmp_session - } - - pos += 20; -- t->time_scale = ngx_rtmp_r32(*(uint32_t *) pos); -+ t->time_scale = ntohl(*(uint32_t *) pos); - pos += 4; -- t->duration = ngx_rtmp_r64(*(uint64_t *) pos); -+ t->duration = ntohll(*(uint64_t *) pos); - break; - - default: -@@ -616,11 +616,11 @@ ngx_rtmp_mp4_parse_video(ngx_rtmp_sessio - - pos += 24; - -- ctx->width = ngx_rtmp_r16(*(uint16_t *) pos); -+ ctx->width = ntohs(*(uint16_t *) pos); - - pos += 2; - -- ctx->height = ngx_rtmp_r16(*(uint16_t *) pos); -+ ctx->height = ntohs(*(uint16_t *) pos); - - pos += 52; - -@@ -660,19 +660,19 @@ ngx_rtmp_mp4_parse_audio(ngx_rtmp_sessio - - pos += 8; - -- version = ngx_rtmp_r16(*(uint16_t *) pos); -+ version = ntohs(*(uint16_t *) pos); - - pos += 8; - -- ctx->nchannels = ngx_rtmp_r16(*(uint16_t *) pos); -+ ctx->nchannels = ntohs(*(uint16_t *) pos); - - pos += 2; - -- ctx->sample_size = ngx_rtmp_r16(*(uint16_t *) pos); -+ ctx->sample_size = ntohs(*(uint16_t *) pos); - - pos += 6; - -- ctx->sample_rate = ngx_rtmp_r16(*(uint16_t *) pos); -+ ctx->sample_rate = ntohs(*(uint16_t *) pos); - - pos += 4; - -@@ -862,7 +862,7 @@ ngx_rtmp_mp4_parse_es(ngx_rtmp_session_t - return NGX_ERROR; - } - -- id = ngx_rtmp_r16(*(uint16_t *) pos); -+ id = ntohs(*(uint16_t *) pos); - pos += 2; - - flags = *(uint8_t *) pos; -@@ -1018,13 +1018,13 @@ ngx_rtmp_mp4_parse_stsc(ngx_rtmp_session - - t->chunks = (ngx_rtmp_mp4_chunks_t *) pos; - -- if (pos + sizeof(*t->chunks) + ngx_rtmp_r32(t->chunks->entry_count) * -+ if (pos + sizeof(*t->chunks) + ntohl(t->chunks->entry_count) * - sizeof(t->chunks->entries[0]) - <= last) - { - ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: chunks entries=%uD", -- ngx_rtmp_r32(t->chunks->entry_count)); -+ ntohl(t->chunks->entry_count)); - return NGX_OK; - } - -@@ -1049,13 +1049,13 @@ ngx_rtmp_mp4_parse_stts(ngx_rtmp_session - - t->times = (ngx_rtmp_mp4_times_t *) pos; - -- if (pos + sizeof(*t->times) + ngx_rtmp_r32(t->times->entry_count) * -+ if (pos + sizeof(*t->times) + ntohl(t->times->entry_count) * - sizeof(t->times->entries[0]) - <= last) - { - ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: times entries=%uD", -- ngx_rtmp_r32(t->times->entry_count)); -+ ntohl(t->times->entry_count)); - return NGX_OK; - } - -@@ -1080,13 +1080,13 @@ ngx_rtmp_mp4_parse_ctts(ngx_rtmp_session - - t->delays = (ngx_rtmp_mp4_delays_t *) pos; - -- if (pos + sizeof(*t->delays) + ngx_rtmp_r32(t->delays->entry_count) * -+ if (pos + sizeof(*t->delays) + ntohl(t->delays->entry_count) * - sizeof(t->delays->entries[0]) - <= last) - { - ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: delays entries=%uD", -- ngx_rtmp_r32(t->delays->entry_count)); -+ ntohl(t->delays->entry_count)); - return NGX_OK; - } - -@@ -1111,13 +1111,13 @@ ngx_rtmp_mp4_parse_stss(ngx_rtmp_session - - t->keys = (ngx_rtmp_mp4_keys_t *) pos; - -- if (pos + sizeof(*t->keys) + ngx_rtmp_r32(t->keys->entry_count) * -+ if (pos + sizeof(*t->keys) + ntohl(t->keys->entry_count) * - sizeof(t->keys->entries[0]) - <= last) - { - ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: keys entries=%uD", -- ngx_rtmp_r32(t->keys->entry_count)); -+ ntohl(t->keys->entry_count)); - return NGX_OK; - } - -@@ -1145,18 +1145,18 @@ ngx_rtmp_mp4_parse_stsz(ngx_rtmp_session - if (pos + sizeof(*t->sizes) <= last && t->sizes->sample_size) { - ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: sizes size=%uD", -- ngx_rtmp_r32(t->sizes->sample_size)); -+ ntohl(t->sizes->sample_size)); - return NGX_OK; - } - -- if (pos + sizeof(*t->sizes) + ngx_rtmp_r32(t->sizes->sample_count) * -+ if (pos + sizeof(*t->sizes) + ntohl(t->sizes->sample_count) * - sizeof(t->sizes->entries[0]) - <= last) - - { - ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: sizes entries=%uD", -- ngx_rtmp_r32(t->sizes->sample_count)); -+ ntohl(t->sizes->sample_count)); - return NGX_OK; - } - -@@ -1181,14 +1181,14 @@ ngx_rtmp_mp4_parse_stz2(ngx_rtmp_session - - t->sizes2 = (ngx_rtmp_mp4_sizes2_t *) pos; - -- if (pos + sizeof(*t->sizes) + ngx_rtmp_r32(t->sizes2->sample_count) * -- ngx_rtmp_r32(t->sizes2->field_size) / 8 -+ if (pos + sizeof(*t->sizes) + ntohl(t->sizes2->sample_count) * -+ ntohl(t->sizes2->field_size) / 8 - <= last) - { - ngx_log_debug2(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: sizes2 field_size=%uD entries=%uD", -- ngx_rtmp_r32(t->sizes2->field_size), -- ngx_rtmp_r32(t->sizes2->sample_count)); -+ ntohl(t->sizes2->field_size), -+ ntohl(t->sizes2->sample_count)); - return NGX_OK; - } - -@@ -1213,13 +1213,13 @@ ngx_rtmp_mp4_parse_stco(ngx_rtmp_session - - t->offsets = (ngx_rtmp_mp4_offsets_t *) pos; - -- if (pos + sizeof(*t->offsets) + ngx_rtmp_r32(t->offsets->entry_count) * -+ if (pos + sizeof(*t->offsets) + ntohl(t->offsets->entry_count) * - sizeof(t->offsets->entries[0]) - <= last) - { - ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: offsets entries=%uD", -- ngx_rtmp_r32(t->offsets->entry_count)); -+ ntohl(t->offsets->entry_count)); - return NGX_OK; - } - -@@ -1244,13 +1244,13 @@ ngx_rtmp_mp4_parse_co64(ngx_rtmp_session - - t->offsets64 = (ngx_rtmp_mp4_offsets64_t *) pos; - -- if (pos + sizeof(*t->offsets64) + ngx_rtmp_r32(t->offsets64->entry_count) * -+ if (pos + sizeof(*t->offsets64) + ntohl(t->offsets64->entry_count) * - sizeof(t->offsets64->entries[0]) - <= last) - { - ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: offsets64 entries=%uD", -- ngx_rtmp_r32(t->offsets64->entry_count)); -+ ntohl(t->offsets64->entry_count)); - return NGX_OK; - } - -@@ -1275,7 +1275,7 @@ ngx_rtmp_mp4_parse(ngx_rtmp_session_t *s - } - - hdr = (uint32_t *) pos; -- size = ngx_rtmp_r32(hdr[0]); -+ size = ntohl(hdr[0]); - tag = hdr[1]; - - if (pos + size > last) { -@@ -1318,11 +1318,11 @@ ngx_rtmp_mp4_next_time(ngx_rtmp_session_ - - cr = &t->cursor; - -- if (cr->time_pos >= ngx_rtmp_r32(t->times->entry_count)) { -+ if (cr->time_pos >= ntohl(t->times->entry_count)) { - ngx_log_debug3(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui time[%ui/%uD] overflow", - t->id, cr->time_pos, -- ngx_rtmp_r32(t->times->entry_count)); -+ ntohl(t->times->entry_count)); - - return NGX_ERROR; - } -@@ -1330,22 +1330,22 @@ ngx_rtmp_mp4_next_time(ngx_rtmp_session_ - te = &t->times->entries[cr->time_pos]; - - cr->last_timestamp = cr->timestamp; -- cr->timestamp += ngx_rtmp_r32(te->sample_delta); -+ cr->timestamp += ntohl(te->sample_delta); - - cr->not_first = 1; - - ngx_log_debug8(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui time[%ui] [%ui/%uD][%ui/%uD]=%uD t=%uD", - t->id, cr->pos, cr->time_pos, -- ngx_rtmp_r32(t->times->entry_count), -- cr->time_count, ngx_rtmp_r32(te->sample_count), -- ngx_rtmp_r32(te->sample_delta), -+ ntohl(t->times->entry_count), -+ cr->time_count, ntohl(te->sample_count), -+ ntohl(te->sample_delta), - cr->timestamp); - - cr->time_count++; - cr->pos++; - -- if (cr->time_count >= ngx_rtmp_r32(te->sample_count)) { -+ if (cr->time_count >= ntohl(te->sample_count)) { - cr->time_pos++; - cr->time_count = 0; - } -@@ -1370,8 +1370,8 @@ ngx_rtmp_mp4_seek_time(ngx_rtmp_session_ - - te = t->times->entries; - -- while (cr->time_pos < ngx_rtmp_r32(t->times->entry_count)) { -- dt = ngx_rtmp_r32(te->sample_delta) * ngx_rtmp_r32(te->sample_count); -+ while (cr->time_pos < ntohl(t->times->entry_count)) { -+ dt = ntohl(te->sample_delta) * ntohl(te->sample_count); - - if (cr->timestamp + dt >= timestamp) { - if (te->sample_delta == 0) { -@@ -1379,24 +1379,24 @@ ngx_rtmp_mp4_seek_time(ngx_rtmp_session_ - } - - cr->time_count = (timestamp - cr->timestamp) / -- ngx_rtmp_r32(te->sample_delta); -- cr->timestamp += ngx_rtmp_r32(te->sample_delta) * cr->time_count; -+ ntohl(te->sample_delta); -+ cr->timestamp += ntohl(te->sample_delta) * cr->time_count; - cr->pos += cr->time_count; - - break; - } - - cr->timestamp += dt; -- cr->pos += ngx_rtmp_r32(te->sample_count); -+ cr->pos += ntohl(te->sample_count); - cr->time_pos++; - te++; - } - -- if (cr->time_pos >= ngx_rtmp_r32(t->times->entry_count)) { -+ if (cr->time_pos >= ntohl(t->times->entry_count)) { - ngx_log_debug3(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui seek time[%ui/%uD] overflow", - t->id, cr->time_pos, -- ngx_rtmp_r32(t->times->entry_count)); -+ ntohl(t->times->entry_count)); - - return NGX_ERROR; - } -@@ -1405,10 +1405,10 @@ ngx_rtmp_mp4_seek_time(ngx_rtmp_session_ - "mp4: track#%ui seek time[%ui] [%ui/%uD][%ui/%uD]=%uD " - "t=%uD", - t->id, cr->pos, cr->time_pos, -- ngx_rtmp_r32(t->times->entry_count), -+ ntohl(t->times->entry_count), - cr->time_count, -- ngx_rtmp_r32(te->sample_count), -- ngx_rtmp_r32(te->sample_delta), -+ ntohl(te->sample_count), -+ ntohl(te->sample_delta), - cr->timestamp); - - return NGX_OK; -@@ -1433,44 +1433,44 @@ ngx_rtmp_mp4_update_offset(ngx_rtmp_sess - chunk = cr->chunk - 1; - - if (t->offsets) { -- if (chunk >= ngx_rtmp_r32(t->offsets->entry_count)) { -+ if (chunk >= ntohl(t->offsets->entry_count)) { - ngx_log_debug3(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui offset[%ui/%uD] overflow", - t->id, cr->chunk, -- ngx_rtmp_r32(t->offsets->entry_count)); -+ ntohl(t->offsets->entry_count)); - - return NGX_ERROR; - } - -- cr->offset = (off_t) ngx_rtmp_r32(t->offsets->entries[chunk]); -+ cr->offset = (off_t) ntohl(t->offsets->entries[chunk]); - cr->size = 0; - - ngx_log_debug4(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui offset[%ui/%uD]=%O", - t->id, cr->chunk, -- ngx_rtmp_r32(t->offsets->entry_count), -+ ntohl(t->offsets->entry_count), - cr->offset); - - return NGX_OK; - } - - if (t->offsets64) { -- if (chunk >= ngx_rtmp_r32(t->offsets64->entry_count)) { -+ if (chunk >= ntohl(t->offsets64->entry_count)) { - ngx_log_debug3(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui offset64[%ui/%uD] overflow", - t->id, cr->chunk, -- ngx_rtmp_r32(t->offsets->entry_count)); -+ ntohl(t->offsets->entry_count)); - - return NGX_ERROR; - } - -- cr->offset = (off_t) ngx_rtmp_r64(t->offsets64->entries[chunk]); -+ cr->offset = (off_t) ntohll(t->offsets64->entries[chunk]); - cr->size = 0; - - ngx_log_debug4(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui offset64[%ui/%uD]=%O", - t->id, cr->chunk, -- ngx_rtmp_r32(t->offsets->entry_count), -+ ntohl(t->offsets->entry_count), - cr->offset); - - return NGX_OK; -@@ -1493,11 +1493,11 @@ ngx_rtmp_mp4_next_chunk(ngx_rtmp_session - - cr = &t->cursor; - -- if (cr->chunk_pos >= ngx_rtmp_r32(t->chunks->entry_count)) { -+ if (cr->chunk_pos >= ntohl(t->chunks->entry_count)) { - ngx_log_debug3(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui chunk[%ui/%uD] overflow", - t->id, cr->chunk_pos, -- ngx_rtmp_r32(t->chunks->entry_count)); -+ ntohl(t->chunks->entry_count)); - - return NGX_ERROR; - } -@@ -1506,13 +1506,13 @@ ngx_rtmp_mp4_next_chunk(ngx_rtmp_session - - cr->chunk_count++; - -- if (cr->chunk_count >= ngx_rtmp_r32(ce->samples_per_chunk)) { -+ if (cr->chunk_count >= ntohl(ce->samples_per_chunk)) { - cr->chunk_count = 0; - cr->chunk++; - -- if (cr->chunk_pos + 1 < ngx_rtmp_r32(t->chunks->entry_count)) { -+ if (cr->chunk_pos + 1 < ntohl(t->chunks->entry_count)) { - nce = ce + 1; -- if (cr->chunk >= ngx_rtmp_r32(nce->first_chunk)) { -+ if (cr->chunk >= ntohl(nce->first_chunk)) { - cr->chunk_pos++; - ce = nce; - } -@@ -1527,10 +1527,10 @@ ngx_rtmp_mp4_next_chunk(ngx_rtmp_session - ngx_log_debug7(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui chunk[%ui/%uD][%uD..%ui][%ui/%uD]", - t->id, cr->chunk_pos, -- ngx_rtmp_r32(t->chunks->entry_count), -- ngx_rtmp_r32(ce->first_chunk), -+ ntohl(t->chunks->entry_count), -+ ntohl(ce->first_chunk), - cr->chunk, cr->chunk_count, -- ngx_rtmp_r32(ce->samples_per_chunk)); -+ ntohl(ce->samples_per_chunk)); - - - if (new_chunk) { -@@ -1558,12 +1558,12 @@ ngx_rtmp_mp4_seek_chunk(ngx_rtmp_session - ce = t->chunks->entries; - pos = 0; - -- while (cr->chunk_pos + 1 < ngx_rtmp_r32(t->chunks->entry_count)) { -+ while (cr->chunk_pos + 1 < ntohl(t->chunks->entry_count)) { - nce = ce + 1; - -- dpos = (ngx_rtmp_r32(nce->first_chunk) - -- ngx_rtmp_r32(ce->first_chunk)) * -- ngx_rtmp_r32(ce->samples_per_chunk); -+ dpos = (ntohl(nce->first_chunk) - -+ ntohl(ce->first_chunk)) * -+ ntohl(ce->samples_per_chunk); - - if (pos + dpos > cr->pos) { - break; -@@ -1578,20 +1578,20 @@ ngx_rtmp_mp4_seek_chunk(ngx_rtmp_session - return NGX_ERROR; - } - -- dchunk = (cr->pos - pos) / ngx_rtmp_r32(ce->samples_per_chunk); -+ dchunk = (cr->pos - pos) / ntohl(ce->samples_per_chunk); - -- cr->chunk = ngx_rtmp_r32(ce->first_chunk) + dchunk; -+ cr->chunk = ntohl(ce->first_chunk) + dchunk; - cr->chunk_pos = (ngx_uint_t) (ce - t->chunks->entries); - cr->chunk_count = (ngx_uint_t) (cr->pos - pos - dchunk * -- ngx_rtmp_r32(ce->samples_per_chunk)); -+ ntohl(ce->samples_per_chunk)); - - ngx_log_debug7(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui seek chunk[%ui/%uD][%uD..%ui][%ui/%uD]", - t->id, cr->chunk_pos, -- ngx_rtmp_r32(t->chunks->entry_count), -- ngx_rtmp_r32(ce->first_chunk), -+ ntohl(t->chunks->entry_count), -+ ntohl(ce->first_chunk), - cr->chunk, cr->chunk_count, -- ngx_rtmp_r32(ce->samples_per_chunk)); -+ ntohl(ce->samples_per_chunk)); - - return ngx_rtmp_mp4_update_offset(s, t); - } -@@ -1608,7 +1608,7 @@ ngx_rtmp_mp4_next_size(ngx_rtmp_session_ - - if (t->sizes) { - if (t->sizes->sample_size) { -- cr->size = ngx_rtmp_r32(t->sizes->sample_size); -+ cr->size = ntohl(t->sizes->sample_size); - - ngx_log_debug2(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui size fix=%uz", -@@ -1619,32 +1619,32 @@ ngx_rtmp_mp4_next_size(ngx_rtmp_session_ - - cr->size_pos++; - -- if (cr->size_pos >= ngx_rtmp_r32(t->sizes->sample_count)) { -+ if (cr->size_pos >= ntohl(t->sizes->sample_count)) { - ngx_log_debug3(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui size[%ui/%uD] overflow", - t->id, cr->size_pos, -- ngx_rtmp_r32(t->sizes->sample_count)); -+ ntohl(t->sizes->sample_count)); - - return NGX_ERROR; - } - -- cr->size = ngx_rtmp_r32(t->sizes->entries[cr->size_pos]); -+ cr->size = ntohl(t->sizes->entries[cr->size_pos]); - - ngx_log_debug4(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui size[%ui/%uD]=%uz", - t->id, cr->size_pos, -- ngx_rtmp_r32(t->sizes->sample_count), -+ ntohl(t->sizes->sample_count), - cr->size); - - return NGX_OK; - } - - if (t->sizes2) { -- if (cr->size_pos >= ngx_rtmp_r32(t->sizes2->sample_count)) { -+ if (cr->size_pos >= ntohl(t->sizes2->sample_count)) { - ngx_log_debug3(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui size[%ui/%uD] overflow", - t->id, cr->size_pos, -- ngx_rtmp_r32(t->sizes2->sample_count)); -+ ntohl(t->sizes2->sample_count)); - - return NGX_ERROR; - } -@@ -1672,7 +1672,7 @@ ngx_rtmp_mp4_seek_size(ngx_rtmp_session_ - - if (t->sizes) { - if (t->sizes->sample_size) { -- cr->size = ngx_rtmp_r32(t->sizes->sample_size); -+ cr->size = ntohl(t->sizes->sample_size); - - cr->offset += cr->size * cr->chunk_count; - -@@ -1683,37 +1683,37 @@ ngx_rtmp_mp4_seek_size(ngx_rtmp_session_ - return NGX_OK; - } - -- if (cr->pos >= ngx_rtmp_r32(t->sizes->sample_count)) { -+ if (cr->pos >= ntohl(t->sizes->sample_count)) { - ngx_log_debug3(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui seek size[%ui/%uD] overflow", - t->id, cr->pos, -- ngx_rtmp_r32(t->sizes->sample_count)); -+ ntohl(t->sizes->sample_count)); - - return NGX_ERROR; - } - - for (pos = 1; pos <= cr->chunk_count; ++pos) { -- cr->offset += ngx_rtmp_r32(t->sizes->entries[cr->pos - pos]); -+ cr->offset += ntohl(t->sizes->entries[cr->pos - pos]); - } - - cr->size_pos = cr->pos; -- cr->size = ngx_rtmp_r32(t->sizes->entries[cr->size_pos]); -+ cr->size = ntohl(t->sizes->entries[cr->size_pos]); - - ngx_log_debug4(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui seek size[%ui/%uD]=%uz", - t->id, cr->size_pos, -- ngx_rtmp_r32(t->sizes->sample_count), -+ ntohl(t->sizes->sample_count), - cr->size); - - return NGX_OK; - } - - if (t->sizes2) { -- if (cr->size_pos >= ngx_rtmp_r32(t->sizes2->sample_count)) { -+ if (cr->size_pos >= ntohl(t->sizes2->sample_count)) { - ngx_log_debug3(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui seek size2[%ui/%uD] overflow", - t->id, cr->size_pos, -- ngx_rtmp_r32(t->sizes->sample_count)); -+ ntohl(t->sizes->sample_count)); - - return NGX_ERROR; - } -@@ -1744,11 +1744,11 @@ ngx_rtmp_mp4_next_key(ngx_rtmp_session_t - cr->key_pos++; - } - -- if (cr->key_pos >= ngx_rtmp_r32(t->keys->entry_count)) { -+ if (cr->key_pos >= ntohl(t->keys->entry_count)) { - ngx_log_debug3(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui key[%ui/%uD] overflow", - t->id, cr->key_pos, -- ngx_rtmp_r32(t->keys->entry_count)); -+ ntohl(t->keys->entry_count)); - - cr->key = 0; - -@@ -1756,13 +1756,13 @@ ngx_rtmp_mp4_next_key(ngx_rtmp_session_t - } - - ke = &t->keys->entries[cr->key_pos]; -- cr->key = (cr->pos + 1 == ngx_rtmp_r32(*ke)); -+ cr->key = (cr->pos + 1 == ntohl(*ke)); - - ngx_log_debug6(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui key[%ui/%uD][%ui/%uD]=%s", - t->id, cr->key_pos, -- ngx_rtmp_r32(t->keys->entry_count), -- cr->pos, ngx_rtmp_r32(*ke), -+ ntohl(t->keys->entry_count), -+ cr->pos, ntohl(*ke), - cr->key ? "match" : "miss"); - - return NGX_OK; -@@ -1782,27 +1782,27 @@ ngx_rtmp_mp4_seek_key(ngx_rtmp_session_t - return NGX_OK; - } - -- while (cr->key_pos < ngx_rtmp_r32(t->keys->entry_count)) { -- if (ngx_rtmp_r32(t->keys->entries[cr->key_pos]) > cr->pos) { -+ while (cr->key_pos < ntohl(t->keys->entry_count)) { -+ if (ntohl(t->keys->entries[cr->key_pos]) > cr->pos) { - break; - } - - cr->key_pos++; - } - -- if (cr->key_pos >= ngx_rtmp_r32(t->keys->entry_count)) { -+ if (cr->key_pos >= ntohl(t->keys->entry_count)) { - ngx_log_debug3(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui seek key[%ui/%uD] overflow", - t->id, cr->key_pos, -- ngx_rtmp_r32(t->keys->entry_count)); -+ ntohl(t->keys->entry_count)); - return NGX_OK; - } - - ke = &t->keys->entries[cr->key_pos]; -- /*cr->key = (cr->pos + 1 == ngx_rtmp_r32(*ke));*/ -+ /*cr->key = (cr->pos + 1 == ntohl(*ke));*/ - - /* distance to the next keyframe */ -- dpos = ngx_rtmp_r32(*ke) - cr->pos - 1; -+ dpos = ntohl(*ke) - cr->pos - 1; - cr->key = 1; - - /* TODO: range version needed */ -@@ -1810,13 +1810,13 @@ ngx_rtmp_mp4_seek_key(ngx_rtmp_session_t - ngx_rtmp_mp4_next_time(s, t); - } - --/* cr->key = (cr->pos + 1 == ngx_rtmp_r32(*ke));*/ -+/* cr->key = (cr->pos + 1 == ntohl(*ke));*/ - - ngx_log_debug6(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui seek key[%ui/%uD][%ui/%uD]=%s", - t->id, cr->key_pos, -- ngx_rtmp_r32(t->keys->entry_count), -- cr->pos, ngx_rtmp_r32(*ke), -+ ntohl(t->keys->entry_count), -+ cr->pos, ntohl(*ke), - cr->key ? "match" : "miss"); - - return NGX_OK; -@@ -1835,11 +1835,11 @@ ngx_rtmp_mp4_next_delay(ngx_rtmp_session - return NGX_OK; - } - -- if (cr->delay_pos >= ngx_rtmp_r32(t->delays->entry_count)) { -+ if (cr->delay_pos >= ntohl(t->delays->entry_count)) { - ngx_log_debug3(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui delay[%ui/%uD] overflow", - t->id, cr->delay_pos, -- ngx_rtmp_r32(t->delays->entry_count)); -+ ntohl(t->delays->entry_count)); - - return NGX_OK; - } -@@ -1847,29 +1847,29 @@ ngx_rtmp_mp4_next_delay(ngx_rtmp_session - cr->delay_count++; - de = &t->delays->entries[cr->delay_pos]; - -- if (cr->delay_count >= ngx_rtmp_r32(de->sample_count)) { -+ if (cr->delay_count >= ntohl(de->sample_count)) { - cr->delay_pos++; - de++; - cr->delay_count = 0; - } - -- if (cr->delay_pos >= ngx_rtmp_r32(t->delays->entry_count)) { -+ if (cr->delay_pos >= ntohl(t->delays->entry_count)) { - ngx_log_debug3(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui delay[%ui/%uD] overflow", - t->id, cr->delay_pos, -- ngx_rtmp_r32(t->delays->entry_count)); -+ ntohl(t->delays->entry_count)); - - return NGX_OK; - } - -- cr->delay = ngx_rtmp_r32(de->sample_offset); -+ cr->delay = ntohl(de->sample_offset); - - ngx_log_debug6(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui delay[%ui/%uD][%ui/%uD]=%ui", - t->id, cr->delay_pos, -- ngx_rtmp_r32(t->delays->entry_count), -+ ntohl(t->delays->entry_count), - cr->delay_count, -- ngx_rtmp_r32(de->sample_count), cr->delay); -+ ntohl(de->sample_count), cr->delay); - - return NGX_OK; - } -@@ -1891,12 +1891,12 @@ ngx_rtmp_mp4_seek_delay(ngx_rtmp_session - pos = 0; - de = t->delays->entries; - -- while (cr->delay_pos < ngx_rtmp_r32(t->delays->entry_count)) { -- dpos = ngx_rtmp_r32(de->sample_count); -+ while (cr->delay_pos < ntohl(t->delays->entry_count)) { -+ dpos = ntohl(de->sample_count); - - if (pos + dpos > cr->pos) { - cr->delay_count = cr->pos - pos; -- cr->delay = ngx_rtmp_r32(de->sample_offset); -+ cr->delay = ntohl(de->sample_offset); - break; - } - -@@ -1905,11 +1905,11 @@ ngx_rtmp_mp4_seek_delay(ngx_rtmp_session - de++; - } - -- if (cr->delay_pos >= ngx_rtmp_r32(t->delays->entry_count)) { -+ if (cr->delay_pos >= ntohl(t->delays->entry_count)) { - ngx_log_debug3(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui seek delay[%ui/%uD] overflow", - t->id, cr->delay_pos, -- ngx_rtmp_r32(t->delays->entry_count)); -+ ntohl(t->delays->entry_count)); - - return NGX_OK; - } -@@ -1917,9 +1917,9 @@ ngx_rtmp_mp4_seek_delay(ngx_rtmp_session - ngx_log_debug6(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "mp4: track#%ui seek delay[%ui/%uD][%ui/%uD]=%ui", - t->id, cr->delay_pos, -- ngx_rtmp_r32(t->delays->entry_count), -+ ntohl(t->delays->entry_count), - cr->delay_count, -- ngx_rtmp_r32(de->sample_count), cr->delay); -+ ntohl(de->sample_count), cr->delay); - - return NGX_OK; - } -@@ -2348,7 +2348,7 @@ ngx_rtmp_mp4_init(ngx_rtmp_session_t *s, - return NGX_ERROR; - } - -- size = (size_t) ngx_rtmp_r32(hdr[0]); -+ size = (size_t) ntohl(hdr[0]); - shift = sizeof(hdr); - - if (size == 1) { -@@ -2362,7 +2362,7 @@ ngx_rtmp_mp4_init(ngx_rtmp_session_t *s, - return NGX_ERROR; - } - -- size = (size_t) ngx_rtmp_r64(extended_size); -+ size = (size_t) ntohll(extended_size); - shift += sizeof(extended_size); - - } else if (size == 0) { ---- a/nginx-mod-rtmp/ngx_rtmp_receive.c -+++ b/nginx-mod-rtmp/ngx_rtmp_receive.c -@@ -17,7 +17,6 @@ ngx_rtmp_protocol_message_handler(ngx_rt - ngx_rtmp_header_t *h, ngx_chain_t *in) - { - ngx_buf_t *b; -- u_char *p; - uint32_t val; - uint8_t limit; - -@@ -30,11 +29,7 @@ ngx_rtmp_protocol_message_handler(ngx_rt - return NGX_OK; - } - -- p = (u_char*)&val; -- p[0] = b->pos[3]; -- p[1] = b->pos[2]; -- p[2] = b->pos[1]; -- p[3] = b->pos[0]; -+ val=ntohl(*(uint32_t*)&b->pos[0]); - - switch(h->type) { - case NGX_RTMP_MSG_CHUNK_SIZE: -@@ -88,7 +83,6 @@ ngx_rtmp_user_message_handler(ngx_rtmp_s - ngx_chain_t *in) - { - ngx_buf_t *b; -- u_char *p; - uint16_t evt; - uint32_t val; - -@@ -101,21 +95,13 @@ ngx_rtmp_user_message_handler(ngx_rtmp_s - return NGX_OK; - } - -- p = (u_char*)&evt; -- -- p[0] = b->pos[1]; -- p[1] = b->pos[0]; -+ evt=ntohs(*(uint16_t*)&b->pos[0]); - - ngx_log_debug2(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "RTMP recv user evt %s (%i)", - ngx_rtmp_user_message_type(evt), (ngx_int_t) evt); - -- p = (u_char *) &val; -- -- p[0] = b->pos[5]; -- p[1] = b->pos[4]; -- p[2] = b->pos[3]; -- p[3] = b->pos[2]; -+ val=ntohl(*(uint32_t*)&b->pos[2]); - - switch(evt) { - case NGX_RTMP_USER_STREAM_BEGIN: -@@ -164,12 +150,7 @@ ngx_rtmp_user_message_handler(ngx_rtmp_s - return NGX_OK; - } - -- p = (u_char *) &v.buflen; -- -- p[0] = b->pos[9]; -- p[1] = b->pos[8]; -- p[2] = b->pos[7]; -- p[3] = b->pos[6]; -+ v.buflen=ntohl(*(uint32_t*)&b->pos[6]); - - ngx_log_debug2(NGX_LOG_DEBUG_RTMP, s->connection->log, 0, - "receive: set_buflen msid=%uD buflen=%uD", -@@ -240,18 +221,20 @@ ngx_rtmp_fetch_uint8(ngx_chain_t **in, u - static ngx_int_t - ngx_rtmp_fetch_uint32(ngx_chain_t **in, uint32_t *ret, ngx_int_t n) - { -- u_char *r = (u_char *) ret; -+ u_char b; -+ uint32_t val=0; - ngx_int_t rc; - -- *ret = 0; -- - while (--n >= 0) { -- rc = ngx_rtmp_fetch(in, &r[n]); -+ rc = ngx_rtmp_fetch(in, &b); - if (rc != NGX_OK) { -+ *ret = 0; - return rc; - } -+ val = (val<<8)|b; - } - -+ *ret=val; - return NGX_OK; - } - ---- a/nginx-mod-rtmp/ngx_rtmp_record_module.c -+++ b/nginx-mod-rtmp/ngx_rtmp_record_module.c -@@ -454,7 +454,7 @@ ngx_rtmp_record_node_open(ngx_rtmp_sessi - ngx_err_t err; - ngx_str_t path; - ngx_int_t mode, create_mode; -- u_char buf[8], *p; -+ u_char buf[8]; - off_t file_size; - uint32_t tag_size, mlen, timestamp; - -@@ -551,11 +551,7 @@ ngx_rtmp_record_node_open(ngx_rtmp_sessi - goto done; - } - -- p = (u_char *) &tag_size; -- p[0] = buf[3]; -- p[1] = buf[2]; -- p[2] = buf[1]; -- p[3] = buf[0]; -+ tag_size=ntohl(*(uint32_t*)&buf[0]); - - if (tag_size == 0 || tag_size + 4 > file_size) { - file_size = 0; -@@ -569,11 +565,7 @@ ngx_rtmp_record_node_open(ngx_rtmp_sessi - goto done; - } - -- p = (u_char *) &mlen; -- p[0] = buf[3]; -- p[1] = buf[2]; -- p[2] = buf[1]; -- p[3] = 0; -+ mlen=n3toh4(&buf[1]); - - if (tag_size != mlen + 11) { - ngx_log_error(NGX_LOG_CRIT, s->connection->log, ngx_errno, -@@ -582,11 +574,7 @@ ngx_rtmp_record_node_open(ngx_rtmp_sessi - goto done; - } - -- p = (u_char *) ×tamp; -- p[3] = buf[7]; -- p[0] = buf[6]; -- p[1] = buf[5]; -- p[2] = buf[4]; -+ timestamp=n3toh4(&buf[4])|((uint32_t)buf[7]<<24); - - done: - rctx->file.offset = file_size; -@@ -891,7 +879,7 @@ ngx_rtmp_record_write_frame(ngx_rtmp_ses - ngx_rtmp_header_t *h, ngx_chain_t *in, - ngx_int_t inc_nframes) - { -- u_char hdr[11], *p, *ph; -+ u_char hdr[11], *ph; - uint32_t timestamp, tag_size; - ngx_rtmp_record_app_conf_t *rracf; - -@@ -937,16 +925,10 @@ ngx_rtmp_record_write_frame(ngx_rtmp_ses - - *ph++ = (u_char)h->type; - -- p = (u_char*)&h->mlen; -- *ph++ = p[2]; -- *ph++ = p[1]; -- *ph++ = p[0]; -- -- p = (u_char*)×tamp; -- *ph++ = p[2]; -- *ph++ = p[1]; -- *ph++ = p[0]; -- *ph++ = p[3]; -+ ph = h4ton3(ph, h->mlen); -+ -+ ph = h4ton3(ph, timestamp); -+ *ph++ = (u_char)(timestamp>>24); - - *ph++ = 0; - *ph++ = 0; -@@ -985,12 +967,8 @@ ngx_rtmp_record_write_frame(ngx_rtmp_ses - - /* write tag size */ - ph = hdr; -- p = (u_char*)&tag_size; -- -- *ph++ = p[3]; -- *ph++ = p[2]; -- *ph++ = p[1]; -- *ph++ = p[0]; -+ *(uint32_t*)ph = htonl(tag_size); -+ ph += 4; - - if (ngx_write_file(&rctx->file, hdr, ph - hdr, - rctx->file.offset) diff --git a/packages/nginx/patches/nginx/101-feature_test_fix.patch b/packages/nginx/patches/nginx/101-feature_test_fix.patch deleted file mode 100644 index e4d9a7183..000000000 --- a/packages/nginx/patches/nginx/101-feature_test_fix.patch +++ /dev/null @@ -1,116 +0,0 @@ ---- a/auto/cc/name -+++ b/auto/cc/name -@@ -7,7 +7,7 @@ if [ "$NGX_PLATFORM" != win32 ]; then - - ngx_feature="C compiler" - ngx_feature_name= -- ngx_feature_run=yes -+ ngx_feature_run= - ngx_feature_incs= - ngx_feature_path= - ngx_feature_libs= ---- a/auto/cc/conf -+++ b/auto/cc/conf -@@ -183,7 +183,7 @@ if [ "$NGX_PLATFORM" != win32 ]; then - else - ngx_feature="gcc builtin atomic operations" - ngx_feature_name=NGX_HAVE_GCC_ATOMIC -- ngx_feature_run=yes -+ ngx_feature_run=no - ngx_feature_incs= - ngx_feature_path= - ngx_feature_libs= -@@ -204,7 +204,7 @@ if [ "$NGX_PLATFORM" != win32 ]; then - else - ngx_feature="C99 variadic macros" - ngx_feature_name="NGX_HAVE_C99_VARIADIC_MACROS" -- ngx_feature_run=yes -+ ngx_feature_run=no - ngx_feature_incs="#include - #define var(dummy, ...) sprintf(__VA_ARGS__)" - ngx_feature_path= -@@ -218,7 +218,7 @@ if [ "$NGX_PLATFORM" != win32 ]; then - - ngx_feature="gcc variadic macros" - ngx_feature_name="NGX_HAVE_GCC_VARIADIC_MACROS" -- ngx_feature_run=yes -+ ngx_feature_run=no - ngx_feature_incs="#include - #define var(dummy, args...) sprintf(args)" - ngx_feature_path= ---- a/auto/os/linux -+++ b/auto/os/linux -@@ -36,7 +36,7 @@ fi - - ngx_feature="epoll" - ngx_feature_name="NGX_HAVE_EPOLL" --ngx_feature_run=yes -+ngx_feature_run=no - ngx_feature_incs="#include " - ngx_feature_path= - ngx_feature_libs= -@@ -135,7 +135,7 @@ ngx_feature_test="int fd; struct stat sb - CC_AUX_FLAGS="$cc_aux_flags -D_GNU_SOURCE" - ngx_feature="sendfile()" - ngx_feature_name="NGX_HAVE_SENDFILE" --ngx_feature_run=yes -+ngx_feature_run=no - ngx_feature_incs="#include - #include " - ngx_feature_path= -@@ -156,7 +156,7 @@ fi - CC_AUX_FLAGS="$cc_aux_flags -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64" - ngx_feature="sendfile64()" - ngx_feature_name="NGX_HAVE_SENDFILE64" --ngx_feature_run=yes -+ngx_feature_run=no - ngx_feature_incs="#include - #include " - ngx_feature_path= -@@ -174,7 +174,7 @@ ngx_include="sys/prctl.h"; . auto/includ - - ngx_feature="prctl(PR_SET_DUMPABLE)" - ngx_feature_name="NGX_HAVE_PR_SET_DUMPABLE" --ngx_feature_run=yes -+ngx_feature_run=no - ngx_feature_incs="#include " - ngx_feature_path= - ngx_feature_libs= ---- a/auto/unix -+++ b/auto/unix -@@ -853,7 +853,7 @@ ngx_feature_test="void *p; p = memalign( - - ngx_feature="mmap(MAP_ANON|MAP_SHARED)" - ngx_feature_name="NGX_HAVE_MAP_ANON" --ngx_feature_run=yes -+ngx_feature_run=no - ngx_feature_incs="#include " - ngx_feature_path= - ngx_feature_libs= -@@ -866,7 +866,7 @@ ngx_feature_test="void *p; - - ngx_feature='mmap("/dev/zero", MAP_SHARED)' - ngx_feature_name="NGX_HAVE_MAP_DEVZERO" --ngx_feature_run=yes -+ngx_feature_run=no - ngx_feature_incs="#include - #include - #include " -@@ -881,7 +881,7 @@ ngx_feature_test='void *p; int fd; - - ngx_feature="System V shared memory" - ngx_feature_name="NGX_HAVE_SYSVSHM" --ngx_feature_run=yes -+ngx_feature_run=no - ngx_feature_incs="#include - #include " - ngx_feature_path= -@@ -895,7 +895,7 @@ ngx_feature_test="int id; - - ngx_feature="POSIX semaphores" - ngx_feature_name="NGX_HAVE_POSIX_SEM" --ngx_feature_run=yes -+ngx_feature_run=no - ngx_feature_incs="#include " - ngx_feature_path= - ngx_feature_libs= diff --git a/packages/nginx/patches/nginx/102-sizeof_test_fix.patch b/packages/nginx/patches/nginx/102-sizeof_test_fix.patch deleted file mode 100644 index 7d2430eab..000000000 --- a/packages/nginx/patches/nginx/102-sizeof_test_fix.patch +++ /dev/null @@ -1,27 +0,0 @@ ---- a/auto/types/sizeof -+++ b/auto/types/sizeof -@@ -25,8 +25,14 @@ $NGX_INCLUDE_UNISTD_H - $NGX_INCLUDE_INTTYPES_H - $NGX_INCLUDE_AUTO_CONFIG_H - -+char object_code_block[] = { -+ '\n', 'e', '4', 'V', 'A', -+ '0', 'x', ('0' + sizeof($ngx_type)), -+ 'Y', '3', 'p', 'M', '\n' -+}; -+ - int main(void) { -- printf("%d", (int) sizeof($ngx_type)); -+ printf("dummy use of object_code_block to avoid gc-section: %c", object_code_block[0]); - return 0; - } - -@@ -40,7 +46,7 @@ eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>& - - - if [ -x $NGX_AUTOTEST ]; then -- ngx_size=`$NGX_AUTOTEST` -+ ngx_size=`sed -ne 's/^e4VA0x\(.\)Y3pM$/\1/p' < $NGX_AUTOTEST` - echo " $ngx_size bytes" - fi - diff --git a/packages/nginx/patches/nginx/103-sys_nerr.patch b/packages/nginx/patches/nginx/103-sys_nerr.patch deleted file mode 100644 index c5101f695..000000000 --- a/packages/nginx/patches/nginx/103-sys_nerr.patch +++ /dev/null @@ -1,12 +0,0 @@ ---- a/src/os/unix/ngx_errno.c -+++ b/src/os/unix/ngx_errno.c -@@ -8,6 +8,9 @@ - #include - #include - -+#ifndef NGX_SYS_NERR -+#define NGX_SYS_NERR 128 -+#endif - - static ngx_str_t ngx_unknown_error = ngx_string("Unknown error"); - diff --git a/packages/nginx/patches/nginx/104-endianness_fix.patch b/packages/nginx/patches/nginx/104-endianness_fix.patch deleted file mode 100644 index 4d8255e93..000000000 --- a/packages/nginx/patches/nginx/104-endianness_fix.patch +++ /dev/null @@ -1,19 +0,0 @@ ---- a/auto/endianness -+++ b/auto/endianness -@@ -12,6 +12,16 @@ checking for system byte ordering - - END - -+if [ "${CONFIG_BIG_ENDIAN}" != "y" ]; then -+ echo " little endian" -+ have=NGX_HAVE_LITTLE_ENDIAN . auto/have -+else -+ echo " big endian" -+fi -+ -+return -+ -+ - - cat << END > $NGX_AUTOTEST.c - diff --git a/packages/nginx/patches/nginx/200-config.patch b/packages/nginx/patches/nginx/200-config.patch deleted file mode 100644 index f35009576..000000000 --- a/packages/nginx/patches/nginx/200-config.patch +++ /dev/null @@ -1,18 +0,0 @@ ---- a/conf/nginx.conf -+++ b/conf/nginx.conf -@@ -1,5 +1,5 @@ - --#user nobody; -+user nobody nogroup; - worker_processes 1; - - #error_log logs/error.log; -@@ -16,7 +16,7 @@ events { - - http { - include mime.types; -- default_type application/octet-stream; -+ #default_type application/octet-stream; - - #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - # '$status $body_bytes_sent "$http_referer" ' diff --git a/packages/nginx/patches/nginx/201-ignore-invalid-options.patch b/packages/nginx/patches/nginx/201-ignore-invalid-options.patch deleted file mode 100644 index af2bab15e..000000000 --- a/packages/nginx/patches/nginx/201-ignore-invalid-options.patch +++ /dev/null @@ -1,12 +0,0 @@ ---- a/auto/options -+++ b/auto/options -@@ -411,8 +411,7 @@ $0: warning: the \"--with-sha1-asm\" opt - --test-build-solaris-sendfilev) NGX_TEST_BUILD_SOLARIS_SENDFILEV=YES ;; - - *) -- echo "$0: error: invalid option \"$option\"" -- exit 1 -+ echo "$0: error: ignoring invalid option \"$option\"" - ;; - esac - done diff --git a/packages/ns-reverse-proxy/Makefile b/packages/ns-reverse-proxy/Makefile new file mode 100644 index 000000000..5fe029c9e --- /dev/null +++ b/packages/ns-reverse-proxy/Makefile @@ -0,0 +1,43 @@ +# +# Copyright (C) 2026 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-2.0-only +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=ns-reverse-proxy +PKG_VERSION:=0.0.3 +PKG_RELEASE:=1 + +PKG_BUILD_DIR:=$(BUILD_DIR)/ns-reverse-proxy-$(PKG_VERSION) + +PKG_MAINTAINER:=Giacomo Sanchietti +PKG_LICENSE:=GPL-3.0-only + +include $(INCLUDE_DIR)/package.mk + +define Package/ns-reverse-proxy + SECTION:=base + CATEGORY:=NethSecurity + TITLE:=NethSecurity reverse-proxy manager + URL:=https://github.com/NethServer/nethsecurity/ + DEPENDS:=+nginx + PKGARCH:=all +endef + +define Package/ns-reverse-proxy/description + Manage reverse-proxy +endef + +# this is required, otherwise compile will fail +define Build/Compile +endef + +define Package/ns-reverse-proxy/install + $(INSTALL_DIR) $(1)/usr/libexec + $(INSTALL_BIN) ./files/nginx-proxy-gen $(1)/usr/libexec + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/ns-reverse-proxy $(1)/etc/init.d +endef + +$(eval $(call BuildPackage,ns-reverse-proxy)) diff --git a/packages/nginx/README.md b/packages/ns-reverse-proxy/README.md similarity index 91% rename from packages/nginx/README.md rename to packages/ns-reverse-proxy/README.md index 263fef2da..821be8e68 100644 --- a/packages/nginx/README.md +++ b/packages/ns-reverse-proxy/README.md @@ -1,7 +1,7 @@ -# nginx +# ns-reverse-proxy -This is a fork of the [official OpenWrt nginx package](https://github.com/openwrt/packages/tree/master/net/nginx). -It adds the location reverse proxy, which is not available in the official package. +Use nginx to act as a reverse proxy. +The reverse proxy forwards web requests to another HTTP server and serves responses in behalf of it. The reverse proxy supports the following rules: @@ -48,10 +48,9 @@ config location 'ns_location1' To enable the rule: ``` -nginx-proxy-gen uci add_list nginx._lan.include='conf.d/_lan.proxy' uci commit nginx -/etc/init.d/nginx restart +reload_config ``` Example of a path rule for a WebSocket inside the `ns_server2` virtual host: @@ -67,10 +66,9 @@ config location 'ns_server2_location1' To enable the rule: ``` -nginx-proxy-gen uci add_list nginx.ns_server2.include='conf.d/ns_server2.proxy' uci commit nginx -/etc/init.d/nginx restart +reload_config ``` ### Host rules @@ -102,6 +100,5 @@ config server 'ns_server1' To enable the rule: ``` -nginx-proxy-gen -/etc/init.d/nginx restart +reload_config ``` diff --git a/packages/nginx/files/nginx-proxy-gen b/packages/ns-reverse-proxy/files/nginx-proxy-gen similarity index 95% rename from packages/nginx/files/nginx-proxy-gen rename to packages/ns-reverse-proxy/files/nginx-proxy-gen index b3c4bdae0..110344776 100755 --- a/packages/nginx/files/nginx-proxy-gen +++ b/packages/ns-reverse-proxy/files/nginx-proxy-gen @@ -10,6 +10,7 @@ This script generates location entries for nginx, find more info in the README.m """ import os +import subprocess from glob import glob from euci import EUci @@ -57,3 +58,5 @@ for section in u.get_all('nginx'): for server in servers: write_locations(servers[server], f'/etc/nginx/conf.d/{server}.proxy') + +subprocess.run(['/etc/init.d/nginx', 'reload']) diff --git a/packages/ns-reverse-proxy/files/ns-reverse-proxy b/packages/ns-reverse-proxy/files/ns-reverse-proxy new file mode 100755 index 000000000..5776e3cc0 --- /dev/null +++ b/packages/ns-reverse-proxy/files/ns-reverse-proxy @@ -0,0 +1,30 @@ +#!/bin/sh /etc/rc.common + +# +# Copyright (C) 2026 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-2.0-only +# + +START=90 + +USE_PROCD=1 + +start_service() { + procd_open_instance + procd_set_param stdout 1 + procd_set_param stderr 1 + procd_set_param command '/usr/libexec/nginx-proxy-gen' + procd_set_param respawn 3600 60 0 + procd_close_instance +} + +service_triggers() +{ + procd_add_reload_trigger "nginx" +} + +reload_service() +{ + stop + start +} From 6dff3cf50772ae158c0ce492ecd76287ae405b78 Mon Sep 17 00:00:00 2001 From: Giacomo Sanchietti Date: Tue, 10 Feb 2026 15:43:44 +0100 Subject: [PATCH 2/2] fixup: cleanup init.d --- packages/ns-reverse-proxy/files/ns-reverse-proxy | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/ns-reverse-proxy/files/ns-reverse-proxy b/packages/ns-reverse-proxy/files/ns-reverse-proxy index 5776e3cc0..56896afff 100755 --- a/packages/ns-reverse-proxy/files/ns-reverse-proxy +++ b/packages/ns-reverse-proxy/files/ns-reverse-proxy @@ -14,7 +14,6 @@ start_service() { procd_set_param stdout 1 procd_set_param stderr 1 procd_set_param command '/usr/libexec/nginx-proxy-gen' - procd_set_param respawn 3600 60 0 procd_close_instance } @@ -25,6 +24,5 @@ service_triggers() reload_service() { - stop - start + start }