Browse Source

nginx-util: allow comments in begin of regex

Signed-off-by: Peter Stadler <peter.stadler@student.uibk.ac.at>
lilik-openwrt-22.03
Peter Stadler 5 years ago
parent
commit
4b03122ce5
2 changed files with 18 additions and 20 deletions
  1. +7
    -7
      net/nginx-util/Makefile
  2. +11
    -13
      net/nginx-util/src/nginx-ssl-util.cpp

+ 7
- 7
net/nginx-util/Makefile View File

@ -1,8 +1,8 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=nginx-util PKG_NAME:=nginx-util
PKG_VERSION:=1.1
PKG_RELEASE:=2
PKG_VERSION:=1.2
PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk include $(INCLUDE_DIR)/cmake.mk
@ -23,17 +23,17 @@ define Package/nginx-ssl-util/default
PROVIDES:=nginx-ssl-util PROVIDES:=nginx-ssl-util
endef endef
define Package/nginx-ssl-util-nopcre
$(Package/nginx-ssl-util/default)
TITLE+= (using <regex>)
endef
define Package/nginx-ssl-util define Package/nginx-ssl-util
$(Package/nginx-ssl-util/default) $(Package/nginx-ssl-util/default)
TITLE+= (using PCRE) TITLE+= (using PCRE)
DEPENDS+= +libpcre DEPENDS+= +libpcre
endef endef
define Package/nginx-ssl-util-nopcre
$(Package/nginx-ssl-util/default)
TITLE+= (using <regex>)
endef
define Package/nginx-util/description define Package/nginx-util/description
Utility that builds dynamically LAN listen directives for Nginx. Utility that builds dynamically LAN listen directives for Nginx.
endef endef


+ 11
- 13
net/nginx-util/src/nginx-ssl-util.cpp View File

@ -106,7 +106,7 @@ constexpr auto _begin = _Line{
[](const std::string & /*param*/, const std::string & /*begin*/) [](const std::string & /*param*/, const std::string & /*begin*/)
-> std::string -> std::string
{ return R"([{;](\s*))"; }
{ return R"([{;](?:\s*#[^\n]*(?=\n))*(\s*))"; }
}; };
@ -139,7 +139,7 @@ constexpr auto _end = _Line{
[](const std::string & /*param*/, const std::string & /*begin*/) [](const std::string & /*param*/, const std::string & /*begin*/)
-> std::string -> std::string
{ return std::string{R"(\s*;)"}; }
{ return std::string{R"(\s*;(?:[\t ]*#[^\n]*)?)"}; }
}; };
@ -256,7 +256,7 @@ auto get_if_missed(const std::string & conf, const Line & LINE,
rgx::regex_search(pos, conf.end(), match, LINE.RGX()); rgx::regex_search(pos, conf.end(), match, LINE.RGX());
pos += match.position(0) + match.length(0)) pos += match.position(0) + match.length(0))
{ {
const std::string_view value = match.str(match.size() - 1);
const std::string value = match.str(match.size() - 1);
if (value==val || value=="'"+val+"'" || value=='"'+val+'"') { if (value==val || value=="'"+val+"'" || value=='"'+val+'"') {
return ""; return "";
@ -278,13 +278,12 @@ auto delete_if(const std::string & conf, const rgx::regex & rgx,
rgx::regex_search(pos, conf.end(), match, rgx); rgx::regex_search(pos, conf.end(), match, rgx);
pos += match.position(0) + match.length(0)) pos += match.position(0) + match.length(0))
{ {
const std::string_view value = match.str(match.size() - 1);
auto skip = 1; // one for delimiter!
const std::string value = match.str(match.size() - 1);
auto len = match.position(1);
if (compare && value!=val && value!="'"+val+"'" && value!='"'+val+'"') { if (compare && value!=val && value!="'"+val+"'" && value!='"'+val+'"') {
skip = match.length(0);
len = match.position(0) + match.length(0);
} }
ret.append(pos, pos + match.position(0) + skip);
ret.append(pos, pos + len);
} }
ret.append(pos, conf.end()); ret.append(pos, conf.end());
@ -559,7 +558,7 @@ void del_ssl_directives_from(const std::string & name, const bool isdefault)
get_if_missed(conf, NGX_INCLUDE_LAN_LISTEN, "", indent); get_if_missed(conf, NGX_INCLUDE_LAN_LISTEN, "", indent);
if (adds.length() > 0) { if (adds.length() > 0) {
pos += match.position(0) + 1;
pos += match.position(1);
conf = std::string(const_conf.begin(), pos) + adds conf = std::string(const_conf.begin(), pos) + adds
+ std::string(pos, const_conf.end()); + std::string(pos, const_conf.end());
@ -609,10 +608,9 @@ void del_ssl(const std::string & name)
auto line = const_conf.substr(prev, curr-prev+1); auto line = const_conf.substr(prev, curr-prev+1);
line = delete_if(line, CRON_CMD.RGX(), std::string{name}, true);
if (line.substr(0,line.size()-1)==CRON_INTERVAL) { changed = true; }
else { conf += line; }
if (line==delete_if(line,CRON_CMD.RGX(),std::string{name},true)) {
conf += line;
} else { changed = true; }
prev = curr + 1; prev = curr + 1;
} }


Loading…
Cancel
Save