From 78c1c574248d990ca344882233596abc8a14c529 Mon Sep 17 00:00:00 2001 From: "Maarten L. Hekkelman" Date: Mon, 27 Nov 2023 11:04:25 +0100 Subject: [PATCH 01/11] properly create postfixed debug library. And export it too. --- CMakeLists.txt | 31 ++++++++++++------- ...epConfig.cmake.in => zeep-config.cmake.in} | 2 +- 2 files changed, 21 insertions(+), 12 deletions(-) rename cmake/{zeepConfig.cmake.in => zeep-config.cmake.in} (74%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 879667b0..91be3dea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") @@ -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 ) @@ -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 ) diff --git a/cmake/zeepConfig.cmake.in b/cmake/zeep-config.cmake.in similarity index 74% rename from cmake/zeepConfig.cmake.in rename to cmake/zeep-config.cmake.in index 67b69709..85c8929d 100644 --- a/cmake/zeepConfig.cmake.in +++ b/cmake/zeep-config.cmake.in @@ -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) From f5993e2fc1070e258dfb87954cb407230830bc49 Mon Sep 17 00:00:00 2001 From: "Maarten L. Hekkelman" Date: Mon, 27 Nov 2023 11:04:56 +0100 Subject: [PATCH 02/11] Do not attempt to read PID file in run_foreground --- lib-http/src/daemon.cpp | 68 ++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 39 deletions(-) diff --git a/lib-http/src/daemon.cpp b/lib-http/src/daemon.cpp index 9cca1e07..011a77e2 100644 --- a/lib-http/src/daemon.cpp +++ b/lib-http/src/daemon.cpp @@ -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 s(m_factory()); - s->bind(address, port); - std::thread t(std::bind(&server::run, s.get(), 1)); + std::unique_ptr 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 From 71b039e1fee60e80134e1eab8df65da672b04b50 Mon Sep 17 00:00:00 2001 From: "Maarten L. Hekkelman" Date: Mon, 27 Nov 2023 11:23:32 +0100 Subject: [PATCH 03/11] Fix same error in rest controller... --- lib-http/src/rest-controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib-http/src/rest-controller.cpp b/lib-http/src/rest-controller.cpp index 05b93271..abc34a4c 100644 --- a/lib-http/src/rest-controller.cpp +++ b/lib-http/src/rest-controller.cpp @@ -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 }); } } From fdc74befb31831e9a26ed8551934001de4323ac8 Mon Sep 17 00:00:00 2001 From: "Maarten L. Hekkelman" Date: Mon, 27 Nov 2023 12:12:11 +0100 Subject: [PATCH 04/11] Version bump --- CMakeLists.txt | 2 +- changelog | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 91be3dea..0f345425 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/changelog b/changelog index 2b7f3fed..f15d0e92 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,7 @@ +Version 6.0.10 +- Fix html_controller and rest_controller to pass + path parameters decoded. + Version 6.0.9 - Fix writing encoded path segments for URI's From 24c94512d10bf3d5110981418d966092109cae4f Mon Sep 17 00:00:00 2001 From: "Maarten L. Hekkelman" Date: Mon, 4 Dec 2023 08:21:04 +0100 Subject: [PATCH 05/11] include cassert --- CMakeLists.txt | 2 +- include/zeep/http/rest-controller.hpp | 6 ++++-- include/zeep/http/security.hpp | 2 ++ include/zeep/json/element.hpp | 2 ++ include/zeep/json/iterator.hpp | 2 ++ include/zeep/xml/serialize.hpp | 10 ++++++---- 6 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 879667b0..a6222804 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,7 +109,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) diff --git a/include/zeep/http/rest-controller.hpp b/include/zeep/http/rest-controller.hpp index 121e062f..e04010ed 100644 --- a/include/zeep/http/rest-controller.hpp +++ b/include/zeep/http/rest-controller.hpp @@ -13,13 +13,15 @@ #include +#include +#include + #include #include #include #include -#include -#include +#include namespace zeep::http { diff --git a/include/zeep/http/security.hpp b/include/zeep/http/security.hpp index f49d34e6..2ca952c0 100644 --- a/include/zeep/http/security.hpp +++ b/include/zeep/http/security.hpp @@ -17,6 +17,8 @@ #include +#include + // -------------------------------------------------------------------- // diff --git a/include/zeep/json/element.hpp b/include/zeep/json/element.hpp index 5176fe72..bec05efa 100644 --- a/include/zeep/json/element.hpp +++ b/include/zeep/json/element.hpp @@ -19,6 +19,8 @@ #include +#include + namespace zeep::json { diff --git a/include/zeep/json/iterator.hpp b/include/zeep/json/iterator.hpp index ed7f5389..5f75b8c7 100644 --- a/include/zeep/json/iterator.hpp +++ b/include/zeep/json/iterator.hpp @@ -10,6 +10,8 @@ #include +#include + namespace zeep::json::detail { diff --git a/include/zeep/xml/serialize.hpp b/include/zeep/xml/serialize.hpp index 8ae35196..6b66a759 100644 --- a/include/zeep/xml/serialize.hpp +++ b/include/zeep/xml/serialize.hpp @@ -11,16 +11,18 @@ #include -#include -#include -#include - #include #include #include #include #include +#include +#include + +#include +#include + namespace zeep::xml { From 90edc8d92066e58ece4543f96228a9252a8815e1 Mon Sep 17 00:00:00 2001 From: "Maarten L. Hekkelman" Date: Mon, 4 Dec 2023 10:34:18 +0100 Subject: [PATCH 06/11] ONLY_C_LOCALE? wtf... --- include/zeep/value-serializer.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/zeep/value-serializer.hpp b/include/zeep/value-serializer.hpp index d381614a..f4de56a2 100644 --- a/include/zeep/value-serializer.hpp +++ b/include/zeep/value-serializer.hpp @@ -24,6 +24,11 @@ #include #if __has_include() +#if defined(ONLY_C_LOCALE) AND ONLY_C_LOCALE +#warning "ONLY_C_LOCALE was defined building the date library, will have to unset it to make libzeep work correctly" +#undef ONLY_C_LOCALE +#endif +#define ONLY_C_LOCALE 0 #include #endif From 8577613a2390148673bd771130ba3311fe5d8982 Mon Sep 17 00:00:00 2001 From: "Maarten L. Hekkelman" Date: Mon, 4 Dec 2023 10:36:29 +0100 Subject: [PATCH 07/11] ONLY_C_LOCALE? wtf... --- include/zeep/value-serializer.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/zeep/value-serializer.hpp b/include/zeep/value-serializer.hpp index f4de56a2..bbe09342 100644 --- a/include/zeep/value-serializer.hpp +++ b/include/zeep/value-serializer.hpp @@ -24,7 +24,7 @@ #include #if __has_include() -#if defined(ONLY_C_LOCALE) AND ONLY_C_LOCALE +#if defined(ONLY_C_LOCALE) and ONLY_C_LOCALE #warning "ONLY_C_LOCALE was defined building the date library, will have to unset it to make libzeep work correctly" #undef ONLY_C_LOCALE #endif From 68ea2b7a68957c583485d65aeb18233ed85fb44c Mon Sep 17 00:00:00 2001 From: "Maarten L. Hekkelman" Date: Mon, 4 Dec 2023 11:42:59 +0100 Subject: [PATCH 08/11] Do not use date::to_stream since date might only use C locale --- include/zeep/unicode-support.hpp | 53 ++++++++++++++++++++++++++++++++ lib-http/src/el-processing.cpp | 14 +++------ 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/include/zeep/unicode-support.hpp b/include/zeep/unicode-support.hpp index 3200423e..844ca60a 100644 --- a/include/zeep/unicode-support.hpp +++ b/include/zeep/unicode-support.hpp @@ -206,6 +206,59 @@ std::tuple 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(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]; diff --git a/lib-http/src/el-processing.cpp b/lib-http/src/el-processing.cpp index c53b64bf..6e62c002 100644 --- a/lib-http/src/el-processing.cpp +++ b/lib-http/src/el-processing.cpp @@ -1520,20 +1520,14 @@ class date_expr_util_object : public expression_utility_object::from_string(t); -#if __has_include() - 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> 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(std::gmtime(&tt), wf.c_str()); + result = convert_w2s(os.str()); } } From 1036c6d873a213836a341e2f848ead983e3bb3de Mon Sep 17 00:00:00 2001 From: "Maarten L. Hekkelman" Date: Mon, 4 Dec 2023 13:17:46 +0100 Subject: [PATCH 09/11] Update changelog --- changelog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelog b/changelog index f15d0e92..d47de78e 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,9 @@ 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 Version 6.0.9 - Fix writing encoded path segments for URI's From f2c6e90a7e4bd56cd79fdae18ae701dc967e7db5 Mon Sep 17 00:00:00 2001 From: "Maarten L. Hekkelman" Date: Mon, 4 Dec 2023 13:22:58 +0100 Subject: [PATCH 10/11] revert setting ONLY_C_LOCALE --- include/zeep/value-serializer.hpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/include/zeep/value-serializer.hpp b/include/zeep/value-serializer.hpp index bbe09342..d381614a 100644 --- a/include/zeep/value-serializer.hpp +++ b/include/zeep/value-serializer.hpp @@ -24,11 +24,6 @@ #include #if __has_include() -#if defined(ONLY_C_LOCALE) and ONLY_C_LOCALE -#warning "ONLY_C_LOCALE was defined building the date library, will have to unset it to make libzeep work correctly" -#undef ONLY_C_LOCALE -#endif -#define ONLY_C_LOCALE 0 #include #endif From 4eacb7759d4874a743d1fe3b106257822c3ed394 Mon Sep 17 00:00:00 2001 From: "Maarten L. Hekkelman" Date: Mon, 4 Dec 2023 13:27:29 +0100 Subject: [PATCH 11/11] Update changelog --- changelog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog b/changelog index d47de78e..1aed37d2 100644 --- a/changelog +++ b/changelog @@ -4,6 +4,8 @@ Version 6.0.10 - 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