From feaeeb444e5787bf48f3b123ea4eb498ece6b38b Mon Sep 17 00:00:00 2001 From: tomasz-karczewski-red Date: Wed, 13 Nov 2024 11:39:04 +0100 Subject: [PATCH] ARRISEOS-46608 WebKitBrowser: normalize compared urls - adding libcurl to browser plugin - using libcurl to normalize urls before comparison --- WebKitBrowser/CMakeLists.txt | 6 +++++- WebKitBrowser/WebKitImplementation.cpp | 27 +++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/WebKitBrowser/CMakeLists.txt b/WebKitBrowser/CMakeLists.txt index 3c8272ab4a..1130552682 100644 --- a/WebKitBrowser/CMakeLists.txt +++ b/WebKitBrowser/CMakeLists.txt @@ -186,6 +186,7 @@ find_package(CompileSettingsDebug CONFIG REQUIRED) find_package(WPEWebKit REQUIRED) find_package(WPEBackend REQUIRED) find_package(OpenSSL REQUIRED) +find_package(CURL REQUIRED) add_library(${MODULE_NAME} SHARED Module.cpp @@ -223,7 +224,10 @@ target_link_libraries(${PLUGIN_WEBKITBROWSER_IMPLEMENTATION} ${NAMESPACE}Definitions::${NAMESPACE}Definitions WPEBackend::WPEBackend WPEWebKit::WPEWebKit - OpenSSL::Crypto) + OpenSSL::Crypto + ${CURL_LIBRARIES}) + +target_include_directories(${PLUGIN_WEBKITBROWSER_IMPLEMENTATION} PRIVATE ${CURL_INCLUDE_DIRS}) if (PLUGIN_WEBKITBROWSER_ODH_TELEMETRY) find_package(OdhErrTelemetry REQUIRED) diff --git a/WebKitBrowser/WebKitImplementation.cpp b/WebKitBrowser/WebKitImplementation.cpp index ce3623e0fd..c84454959a 100644 --- a/WebKitBrowser/WebKitImplementation.cpp +++ b/WebKitBrowser/WebKitImplementation.cpp @@ -30,6 +30,8 @@ #include "odhlog.h" +#include + #ifdef WEBKIT_GLIB_API #include #include "Tags.h" @@ -186,6 +188,29 @@ namespace return input.substr(0, end).append("/"); } + string normalizedUrl(const string& url) { + static thread_local CURLU *normalizedUrl = curl_url(); + string ret {url}; + char *normalizedCstr = nullptr; + CURLUcode ecode; + if (CURLUE_OK == (ecode = curl_url_set(normalizedUrl, CURLUPART_URL, url.c_str(), 0))) { + if (CURLUE_OK == (ecode = curl_url_get(normalizedUrl, CURLUPART_URL, &normalizedCstr, 0))) { + ret = normalizedCstr; + } + } + if (ecode != CURLUE_OK) { + SYSLOG_GLOBAL(Logging::Error, (_T("Error normalizing url '%s' : %d. Will return the input."), url.c_str(), ecode)); + } + if (normalizedCstr) { + curl_free(normalizedCstr); + normalizedCstr = nullptr; + } + return ret; + } + + bool normalizedUrlsEqual(const string& url1, const string& url2) { + return normalizedUrl(url1) == normalizedUrl(url2); + } } namespace WPEFramework { @@ -4368,7 +4393,7 @@ static GSourceFuncs _handlerIntervention = urlData_.loadResult.waitForFailedOrFinished, Core::ERROR_NONE == result ? "OK" : "NOK", URL.c_str()); - if (urlData_.loadResult.waitForFailedOrFinished && URL.find(urlData_.loadResult.loadUrl) != string::npos) { + if (urlData_.loadResult.waitForFailedOrFinished && normalizedUrlsEqual(URL, urlData_.loadResult.loadUrl)) { TRACE_L1("Notyfying with result = %s, url: %s\n", Core::ERROR_NONE == result ? "OK" : "NOK", URL.c_str()); urlData_.result = result; urlData_.loadResult.waitForFailedOrFinished = false;