nginx-util: fix ubus::~iterator() and minor issues
authorPeter Stadler <redacted>
Mon, 20 Jan 2020 09:48:22 +0000 (10:48 +0100)
committerPeter Stadler <redacted>
Mon, 20 Jan 2020 14:13:23 +0000 (15:13 +0100)
* Do not destroy the iterator twice if cur==this (segfault).
* Do not add the delimiter clim=='\0' when creating the SSL directives.
* Set the right SSL_SESSION_CACHE_ARG for nginx-util get_env.
* Remove static from the constexpr that are used only for Line::build.
* Concat strings instead of appending them for not using a non-const ref
(to remove some warnings of clang-tidy -checks=google-runtime-references)

Signed-off-by: Peter Stadler <redacted>
net/nginx-util/Makefile
net/nginx-util/src/CMakeLists.txt
net/nginx-util/src/nginx-ssl-util.cpp
net/nginx-util/src/nginx-util.cpp
net/nginx-util/src/px5g.cpp
net/nginx-util/src/ubus-cxx.hpp

index 4730b2d1a38343ece811886b2f420f8c872ab108..b07206c9b0e51ae1564f8aaf1236cceacf15820b 100644 (file)
@@ -1,7 +1,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=nginx-util
-PKG_VERSION:=1.0
+PKG_VERSION:=1.1
 PKG_RELEASE:=1
 
 include $(INCLUDE_DIR)/package.mk
index d78ec5d593b3d43889fe98e318ba1ec12a1ba389..df7440d3831c105b269ed4d603565fd7e831b262 100644 (file)
@@ -9,7 +9,7 @@ FIND_LIBRARY(ubox NAMES ubox)
 FIND_LIBRARY(ubus NAMES ubus)
 INCLUDE_DIRECTORIES(${ubus_include_dir})
 
-ADD_DEFINITIONS(-Os -Wall -Werror -Wextra --std=c++17 -g3)
+ADD_DEFINITIONS(-Os -Wall -Werror -Wextra --std=c++2a -g3)
 ADD_DEFINITIONS(-Wno-unused-parameter -Wmissing-declarations)
 
 SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
index f4a85739733e044c8689b8caf4fec856b22fb1c7..fcd81a405ee1f47a92e830101f237b7d60735f53 100644 (file)
@@ -100,7 +100,7 @@ void del_ssl_directives_from(const std::string & name, bool isdefault);
 void del_ssl(const std::string & name);
 
 
-static constexpr auto _begin = _Line{
+constexpr auto _begin = _Line{
     [](const std::string & /*param*/, const std::string & begin) -> std::string
     { return begin; },
 
@@ -110,7 +110,7 @@ static constexpr auto _begin = _Line{
 };
 
 
-static constexpr auto _space = _Line{
+constexpr auto _space = _Line{
     [](const std::string & /*param*/, const std::string & /*begin*/)
         -> std::string
     { return std::string{" "}; },
@@ -121,7 +121,7 @@ static constexpr auto _space = _Line{
 };
 
 
-static constexpr auto _newline = _Line{
+constexpr auto _newline = _Line{
     [](const std::string & /*param*/, const std::string & /*begin*/)
         -> std::string
     { return std::string{"\n"}; },
@@ -132,7 +132,7 @@ static constexpr auto _newline = _Line{
 };
 
 
-static constexpr auto _end = _Line{
+constexpr auto _end = _Line{
     [](const std::string & /*param*/, const std::string & /*begin*/)
         -> std::string
     { return std::string{";"}; },
@@ -144,7 +144,7 @@ static constexpr auto _end = _Line{
 
 
 template<char clim='\0'>
-static constexpr auto _capture = _Line{
+constexpr auto _capture = _Line{
     [](const std::string & param, const std::string & /*begin*/) -> std::string
     { return '\'' + param + '\''; },
 
@@ -159,10 +159,14 @@ static constexpr auto _capture = _Line{
 
 
 template<const std::string_view & strptr, char clim='\0'>
-static constexpr auto _escape = _Line{
+constexpr auto _escape = _Line{
     [](const std::string &  /*param*/, const std::string & /*begin*/)
         -> std::string
-    { return clim + std::string{strptr.data()} + clim; },
+    {
+        return clim=='\0' ?
+            std::string{strptr.data()} :
+            clim + std::string{strptr.data()} + clim;
+    },
 
     [](const std::string & /*param*/, const std::string & /*begin*/)
         -> std::string
@@ -184,17 +188,17 @@ static constexpr auto _escape = _Line{
 };
 
 
-static constexpr std::string_view _server_name = "server_name";
+constexpr std::string_view _server_name = "server_name";
 
-static constexpr std::string_view _include = "include";
+constexpr std::string_view _include = "include";
 
-static constexpr std::string_view _ssl_certificate = "ssl_certificate";
+constexpr std::string_view _ssl_certificate = "ssl_certificate";
 
-static constexpr std::string_view _ssl_certificate_key = "ssl_certificate_key";
+constexpr std::string_view _ssl_certificate_key = "ssl_certificate_key";
 
-static constexpr std::string_view _ssl_session_cache = "ssl_session_cache";
+constexpr std::string_view _ssl_session_cache = "ssl_session_cache";
 
-static constexpr std::string_view _ssl_session_timeout = "ssl_session_timeout";
+constexpr std::string_view _ssl_session_timeout = "ssl_session_timeout";
 
 
 // For a compile time regex lib, this must be fixed, use one of these options:
index 7e675986abeb055de8eac9121a56c266a9e8ae2b..935a005f2f1f7695759f0c45ffa4609786d25814 100644 (file)
@@ -91,7 +91,8 @@ void get_env()
     std::cout<<"LAN_LISTEN="<<"'"<<LAN_LISTEN<<"'"<<std::endl;
 #ifdef NGINX_OPENSSL
     std::cout<<"LAN_SSL_LISTEN="<<"'"<<LAN_SSL_LISTEN<<"'"<<std::endl;
-    std::cout<<"SSL_SESSION_CACHE_ARG="<<"'"<<LAN_NAME<<"'"<<std::endl;
+    std::cout<<"SSL_SESSION_CACHE_ARG="<<"'"<<SSL_SESSION_CACHE_ARG(LAN_NAME)<<
+        "'"<<std::endl;
     std::cout<<"SSL_SESSION_TIMEOUT_ARG="<<"'"<<SSL_SESSION_TIMEOUT_ARG<<"'\n";
     std::cout<<"ADD_SSL_FCT="<<"'"<<ADD_SSL_FCT<<"'"<<std::endl;
 #endif
index 56a063254939635f9b32fb0a010ebb75241ced8b..5ad13357bddc14230963beea525129c463834c18 100644 (file)
@@ -1,9 +1,9 @@
+#include "px5g-openssl.hpp"
 #include <array>
 #include <iostream>
 #include <string>
 #include <string_view>
 #include <unistd.h>
-#include "px5g-openssl.hpp"
 
 
 class argv_view { // TODO(pst): use std::span when available.
index 21dc26ff8042ee91d9094061ee0f8eed05c73f4a..22edae77ea4a8c3bf2efb9d9596bc3bc9e528e82 100644 (file)
@@ -109,28 +109,29 @@ extern "C" { //TODO(pst): remove when in upstream
 
 namespace ubus {
 
+using msg_ptr = std::shared_ptr<const blob_attr>;
 
 using strings = std::vector<std::string>;
 
 
-inline void append(strings & /*dest*/) {}
+inline auto concat(strings dest) { return dest; }
 
 
 template<class ...Strings>
-inline void append(strings & dest, strings src, Strings ...more)
+inline auto concat(strings dest, strings src, Strings ...more)
 {
     dest.reserve(dest.size() + src.size());
     dest.insert(std::end(dest), std::make_move_iterator(std::begin(src)),
                 std::make_move_iterator(std::end(src)));
-    append(dest, std::move(more)...);
+    return concat(std::move(dest), std::move(more)...);
 }
 
 
 template<class S, class ...Strings>
-inline void append(strings & dest, S src, Strings ...more)
+inline auto concat(strings dest, S src, Strings ...more)
 {
     dest.push_back(std::move(src));
-    append(dest, std::move(more)...);
+    return concat(std::move(dest), std::move(more)...);
 }
 
 
@@ -208,7 +209,7 @@ public:
     auto operator++() -> iterator &;
 
 
-    inline ~iterator() = default;
+    inline ~iterator() { if (cur.get()==this) { cur.release(); } }
 
 };
 
@@ -218,15 +219,14 @@ class message {
 
 private:
 
-    const std::shared_ptr<const blob_attr> msg{}; // initialized by callback.
+    const msg_ptr msg{}; // initialized by callback.
 
     const strings keys{};
 
 
 public:
 
-    inline explicit message(std::shared_ptr<const blob_attr>  message,
-                        strings filter={""})
+    inline explicit message(msg_ptr  message, strings filter={""})
     : msg{std::move(message)}, keys{std::move(filter)} {}
 
 
@@ -258,7 +258,7 @@ public:
     {
         strings both{};
         if (keys.size()!=1 || !keys[0].empty()) { both = keys; }
-        append(both, std::move(filter)...);
+        both = concat(std::move(both), std::move(filter)...);
         return std::move(message{msg, std::move(both)});
     }
 
@@ -408,20 +408,20 @@ inline auto call(const char * path, const char * method, const int timeout)
         ubus::unlock_shared_blob_buf();
 
         if (err==0) {
-            using msg_t = std::shared_ptr<const blob_attr>;
 
-            msg_t msg;
-            req.priv = &msg;
+            msg_ptr msg;
 
             /* Cannot capture anything (msg), the lambda would be another type.
             * Pass a location where to save the message as priv pointer when
             * invoking and get it back here:
             */
+            req.priv = &msg;
+
             req.data_cb = [](ubus_request * req, int /*type*/, blob_attr * msg)
             {
-                if ((req == nullptr) || (msg == nullptr)) { return; }
+                if (req==nullptr || msg==nullptr) { return; }
 
-                auto saved = static_cast<msg_t *>(req->priv);
+                auto saved = static_cast<msg_ptr *>(req->priv);
                 if (saved==nullptr || *saved) { return; }
 
                 saved->reset(blob_memdup(msg), free);
git clone https://git.99rst.org/PROJECT