Skip to content

Commit

Permalink
Merge pull request #20 from mhekkel/develop
Browse files Browse the repository at this point in the history
Merging develop into trunk
  • Loading branch information
mhekkel authored Dec 4, 2023
2 parents d174691 + 4eacb77 commit c0d26c4
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 70 deletions.
35 changes: 22 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

cmake_minimum_required(VERSION 3.22)

project(libzeep VERSION 6.0.9 LANGUAGES CXX)
project(libzeep VERSION 6.0.10 LANGUAGES CXX)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

Expand All @@ -29,9 +29,6 @@ if(ZEEP_BUILD_LIBRARY)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Build debug library with d postfix
set(CMAKE_DEBUG_POSTFIX d)

# When building with ninja-multiconfig, build both debug and release by default
if(CMAKE_GENERATOR STREQUAL "Ninja Multi-Config")
set(CMAKE_CROSS_CONFIGS "Debug;Release")
Expand Down Expand Up @@ -109,7 +106,7 @@ if(ZEEP_BUILD_LIBRARY)
configure_file(${PROJECT_SOURCE_DIR}/cmake/asio.hpp.in ${PROJECT_SOURCE_DIR}/include/zeep/http/asio.hpp @ONLY)
endif()

find_package(date 3.0.1 QUIET)
find_package(date 3.0.1 QUIET NAMES libhowardhinnant-date)

if(NOT date_FOUND)
if(ZEEP_ALLOW_FETCH_CONTENT)
Expand Down Expand Up @@ -242,16 +239,19 @@ if(ZEEP_BUILD_LIBRARY)
target_link_options(zeep PRIVATE -undefined dynamic_lookup)
endif()

# Build debug library with d postfix
set(CMAKE_DEBUG_POSTFIX d)
set_target_properties(zeep PROPERTIES DEBUG_POSTFIX "d")

# Install rules
install(TARGETS zeep
EXPORT zeepTargets
EXPORT zeep-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

install(EXPORT zeepTargets
FILE "zeepTargets.cmake"
install(EXPORT zeep-targets
NAMESPACE zeep::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zeep
)
Expand All @@ -263,19 +263,28 @@ if(ZEEP_BUILD_LIBRARY)
PATTERN "config.hpp.in" EXCLUDE
)

configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/zeepConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/zeep/zeepConfig.cmake
configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/zeep-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/zeep/zeep-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zeep
)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/zeep/zeepConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/zeep/zeep-config-version.cmake"
COMPATIBILITY AnyNewerVersion
)

file(GLOB OLD_CONFIG_FILES
${CMAKE_INSTALL_FULL_LIBDIR}/cmake/zeep/zeepConfig*.cmake
${CMAKE_INSTALL_FULL_LIBDIR}/cmake/zeep/zeepTargets*.cmake)

if (OLD_CONFIG_FILES)
message(STATUS "Installation will remove old config files: ${OLD_CONFIG_FILES}")
install(CODE "file(REMOVE ${OLD_CONFIG_FILES})")
endif()

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/zeep/zeepConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/zeep/zeepConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/zeep/zeep-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/zeep/zeep-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zeep
COMPONENT Devel
)
Expand Down
9 changes: 9 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Version 6.0.10
- Fix html_controller and rest_controller to pass
path parameters decoded.
- No longer use the date library to write out localised date/time formats
since the installed date library might contain ONLY_C_LOCALE defined.
- Do not read PID file when running the foreground
- Renamed the cmake config files for libzeep from CamelCase to kebab-case.
The install rules should remove older config files.

Version 6.0.9
- Fix writing encoded path segments for URI's

Expand Down
2 changes: 1 addition & 1 deletion cmake/zeepConfig.cmake.in → cmake/zeep-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ find_dependency(Threads)
@FIND_DEPENDENCY_BOOST@
find_dependency(date REQUIRED)

include("${CMAKE_CURRENT_LIST_DIR}/zeepTargets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/zeep-targets.cmake")

check_required_components(zeep)
6 changes: 4 additions & 2 deletions include/zeep/http/rest-controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@

#include <zeep/config.hpp>

#include <zeep/http/controller.hpp>
#include <zeep/json/parser.hpp>

#include <filesystem>
#include <fstream>
#include <tuple>
#include <utility>

#include <zeep/http/controller.hpp>
#include <zeep/json/parser.hpp>
#include <cassert>

namespace zeep::http
{
Expand Down
2 changes: 2 additions & 0 deletions include/zeep/http/security.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include <set>

#include <cassert>

// --------------------------------------------------------------------
//

Expand Down
2 changes: 2 additions & 0 deletions include/zeep/json/element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include <map>

#include <cassert>

namespace zeep::json
{

Expand Down
2 changes: 2 additions & 0 deletions include/zeep/json/iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include <zeep/config.hpp>

#include <cassert>

namespace zeep::json::detail
{

Expand Down
53 changes: 53 additions & 0 deletions include/zeep/unicode-support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,59 @@ std::tuple<unicode,Iter> get_first_char(Iter ptr, Iter end)

// --------------------------------------------------------------------

/**
* @brief Return a std::wstring for the UTF-8 encoded std::string @a s.
* @note This simplistic code assumes all unicode characters will fit in a wchar_t
*
* @param s The input string
* @return std::wstring The recoded output string
*/
inline std::wstring convert_s2w(std::string_view s)
{
auto b = s.begin();
auto e = s.end();

std::wstring result;

while (b != e)
{
const auto &[uc, i] = get_first_char(b, e);
if (not uc)
break;

result += static_cast<wchar_t>(uc);
b = i;
}

return result;
}

/**
* @brief Return a std::string encoded in UTF-8 for the input std::wstring @a s.
* @note This simplistic code assumes input contains only UCS-2 characters which are deprecated, I know.
* This means UTF-16 surrogates are ruined.
*
* @param s The input string
* @return std::string The recoded output string
*/
inline std::string convert_w2s(std::wstring_view s)
{
std::string result;

for (unicode ch : s)
append(result, ch);

return result;
}

// --------------------------------------------------------------------

/**
* @brief Return a hexadecimal string representation for the numerical value in @a i
*
* @param i The value to convert
* @return std::string The hexadecimal representation
*/
inline std::string to_hex(uint32_t i)
{
char s[sizeof(i) * 2 + 3];
Expand Down
10 changes: 6 additions & 4 deletions include/zeep/xml/serialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@

#include <zeep/config.hpp>

#include <cstring>
#include <regex>
#include <optional>

#include <zeep/exception.hpp>
#include <zeep/nvp.hpp>
#include <zeep/value-serializer.hpp>
#include <zeep/type-traits.hpp>
#include <zeep/xml/node.hpp>

#include <regex>
#include <optional>

#include <cassert>
#include <cstring>

namespace zeep::xml
{

Expand Down
68 changes: 29 additions & 39 deletions lib-http/src/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,57 +53,47 @@ daemon::daemon(server_factory_type &&factory, const char *name)

int daemon::run_foreground(const std::string &address, uint16_t port)
{
int result = 0;
asio_ns::io_context io_context;
asio_ns::ip::tcp::endpoint endpoint;

if (pid_is_for_executable())
{
std::cerr << "Server is already running." << std::endl;
result = 1;
}
asio_system_ns::error_code ec;
auto addr = asio_ns::ip::make_address(address, ec);
if (not ec)
endpoint = asio_ns::ip::tcp::endpoint(addr, port);
else
{
asio_ns::io_context io_context;
asio_ns::ip::tcp::endpoint endpoint;

asio_system_ns::error_code ec;
auto addr = asio_ns::ip::make_address(address, ec);
if (not ec)
endpoint = asio_ns::ip::tcp::endpoint(addr, port);
else
{
asio_ns::ip::tcp::resolver resolver(io_context);
asio_ns::ip::tcp::resolver::query query(address, std::to_string(port));
endpoint = *resolver.resolve(query);
}
asio_ns::ip::tcp::resolver resolver(io_context);
asio_ns::ip::tcp::resolver::query query(address, std::to_string(port));
endpoint = *resolver.resolve(query);
}

asio_ns::ip::tcp::acceptor acceptor(io_context);
acceptor.open(endpoint.protocol());
acceptor.set_option(asio_ns::ip::tcp::acceptor::reuse_address(true));
acceptor.bind(endpoint, ec);
if (ec)
throw std::runtime_error(std::string("Is server running already? ") + ec.message());
acceptor.listen();
asio_ns::ip::tcp::acceptor acceptor(io_context);
acceptor.open(endpoint.protocol());
acceptor.set_option(asio_ns::ip::tcp::acceptor::reuse_address(true));
acceptor.bind(endpoint, ec);
if (ec)
throw std::runtime_error(std::string("Is server running already? ") + ec.message());
acceptor.listen();

acceptor.close();
acceptor.close();

signal_catcher sc;
sc.block();
signal_catcher sc;
sc.block();

std::unique_ptr<basic_server> s(m_factory());
s->bind(address, port);
std::thread t(std::bind(&server::run, s.get(), 1));
std::unique_ptr<basic_server> s(m_factory());
s->bind(address, port);
std::thread t(std::bind(&server::run, s.get(), 1));

sc.unblock();
sc.unblock();

sc.wait();
sc.wait();

s->stop();
s->stop();

if (t.joinable())
t.join();
}
if (t.joinable())
t.join();

return result;
return 0;
}

#if _WIN32
Expand Down
14 changes: 4 additions & 10 deletions lib-http/src/el-processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1520,20 +1520,14 @@ class date_expr_util_object : public expression_utility_object<date_expr_util_ob

auto st = value_serializer<std::chrono::system_clock::time_point>::from_string(t);

#if __has_include(<date/date.h>)
std::ostringstream os;
os << date::format(scope.get_request().get_locale(), f, st);
#else
std::wostringstream os;
os.imbue(scope.get_request().get_locale());

std::wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
std::wstring time = myconv.from_bytes(f);
auto tt = std::chrono::system_clock::to_time_t(st);
auto wf = convert_s2w(f);

auto t = std::chrono::system_clock::to_time_t(st);
os << std::put_time(std::gmtime(&t), time.c_str());
#endif
result = os.str();
os << std::put_time<wchar_t>(std::gmtime(&tt), wf.c_str());
result = convert_w2s(os.str());
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib-http/src/rest-controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool rest_controller::handle_request(http::request& req, http::reply& rep)
for (size_t i = 0; i < mp->m_path_params.size(); ++i)
{
std::string v = m[i + 1].str();
decode_url(v);
v = decode_url(v);
params.m_path_parameters.push_back({ mp->m_path_params[i], v });
}
}
Expand Down

0 comments on commit c0d26c4

Please sign in to comment.