From 1f061c966668c8c9199dd973728c2af0eedfb460 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 31 Aug 2025 10:08:40 -0400 Subject: [PATCH] Include CxxUrl and use it to build the correct url in Amcrest API --- .gitmodules | 3 +++ CMakeLists.txt | 3 +++ dep/CMakeLists.txt | 1 + dep/CxxUrl | 1 + src/zm_monitor_amcrest.cpp | 14 ++++++++------ 5 files changed, 16 insertions(+), 6 deletions(-) create mode 160000 dep/CxxUrl diff --git a/.gitmodules b/.gitmodules index fd07ba226..5a03d4ace 100644 --- a/.gitmodules +++ b/.gitmodules @@ -8,3 +8,6 @@ [submodule "dep/RtspServer"] path = dep/RtspServer url = https://github.com/ZoneMinder/RtspServer +[submodule "dep/CxxUrl"] + path = dep/CxxUrl + url = git@github.com:chmike/CxxUrl.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 421615d05..ac642edb8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -363,6 +363,9 @@ else() "ZoneMinder requires jpeg but it was not found on your system") endif() +list(APPEND ZM_BIN_LIBS chmike::CxxUrl) + + # libjwt if (${ZM_JWT_BACKEND} STREQUAL "libjwt") find_package(LibJWT REQUIRED COMPONENTS ${ZM_CRYPTO_BACKEND}) diff --git a/dep/CMakeLists.txt b/dep/CMakeLists.txt index 792048adf..291bc39dc 100644 --- a/dep/CMakeLists.txt +++ b/dep/CMakeLists.txt @@ -2,3 +2,4 @@ add_subdirectory(jwt-cpp) add_subdirectory(libbcrypt) add_subdirectory(RtspServer) add_subdirectory(span-lite) +add_subdirectory(CxxUrl) diff --git a/dep/CxxUrl b/dep/CxxUrl new file mode 160000 index 000000000..eaf46c020 --- /dev/null +++ b/dep/CxxUrl @@ -0,0 +1 @@ +Subproject commit eaf46c0207df24853a238d4499e7f4426d9d234c diff --git a/src/zm_monitor_amcrest.cpp b/src/zm_monitor_amcrest.cpp index 0688db95f..bfcdd32c8 100644 --- a/src/zm_monitor_amcrest.cpp +++ b/src/zm_monitor_amcrest.cpp @@ -18,6 +18,7 @@ // #include "zm_monitor.h" +#include "dep/CxxUrl/url.hpp" Monitor::AmcrestAPI::AmcrestAPI(Monitor *parent_) : parent(parent_), @@ -45,16 +46,17 @@ int Monitor::AmcrestAPI::start() { curl_easy_cleanup(Amcrest_handle); } - std::string full_url = parent->onvif_url; - if (full_url.back() != '/') full_url += '/'; - full_url += "eventManager.cgi?action=attach&codes=[VideoMotion]"; - Debug(1, "AMCREST url is %s", full_url.c_str()); + Url full_url(parent->onvif_url); + //std::string full_url = parent->onvif_url; + //if (full_url.path().back() != '/') full_url += '/'; + full_url.path("eventManager.cgi?action=attach&codes=[VideoMotion]"); + Debug(1, "AMCREST url is %s", full_url.str().c_str()); Amcrest_handle = curl_easy_init(); if (!Amcrest_handle) { Warning("Handle is null!"); return -1; } - curl_easy_setopt(Amcrest_handle, CURLOPT_URL, full_url.c_str()); + curl_easy_setopt(Amcrest_handle, CURLOPT_URL, full_url.str().c_str()); curl_easy_setopt(Amcrest_handle, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(Amcrest_handle, CURLOPT_WRITEDATA, &amcrest_response); curl_easy_setopt(Amcrest_handle, CURLOPT_USERNAME, parent->onvif_username.c_str()); @@ -88,7 +90,7 @@ int Monitor::AmcrestAPI::start() { } else { Warning("AMCREST Response: %s", amcrest_response.c_str()); Warning("AMCREST Seeing %i streams, and error of %i, url: %s", - running_handles, curl_error, full_url.c_str()); + running_handles, curl_error, full_url.str().c_str()); long response_code; curl_easy_getinfo(Amcrest_handle, CURLINFO_OS_ERRNO, &response_code); Warning("AMCREST Response code: %lu", response_code);