nginx-util: fix ubus::~iterator() and minor issues

* 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 <peter.stadler@student.uibk.ac.at>
This commit is contained in:
Peter Stadler 2020-01-20 10:48:22 +01:00
parent 9d8dbdd86e
commit 5cd9d62f52
6 changed files with 37 additions and 32 deletions

View 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

View 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 "")

View 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:

View 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

View 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.

View 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);