* 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>
include $(TOPDIR)/rules.mk
PKG_NAME:=nginx-util
-PKG_VERSION:=1.0
+PKG_VERSION:=1.1
PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk
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 "")
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; },
};
-static constexpr auto _space = _Line{
+constexpr auto _space = _Line{
[](const std::string & /*param*/, const std::string & /*begin*/)
-> std::string
{ return std::string{" "}; },
};
-static constexpr auto _newline = _Line{
+constexpr auto _newline = _Line{
[](const std::string & /*param*/, const std::string & /*begin*/)
-> std::string
{ return std::string{"\n"}; },
};
-static constexpr auto _end = _Line{
+constexpr auto _end = _Line{
[](const std::string & /*param*/, const std::string & /*begin*/)
-> std::string
{ return std::string{";"}; },
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 + '\''; },
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
};
-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:
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
+#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.
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)...);
}
auto operator++() -> iterator &;
- inline ~iterator() = default;
+ inline ~iterator() { if (cur.get()==this) { cur.release(); } }
};
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)} {}
{
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)});
}
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);