Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 5cf60a8
Author: Nick Logozzo <[email protected]>
Date:   Tue Dec 5 12:10:30 2023 -0500

    Helpers - Use curl for URL Validation

commit 64143f7
Author: Nick Logozzo <[email protected]>
Date:   Tue Dec 5 11:33:54 2023 -0500

    Update CMakeLists.txt
  • Loading branch information
nlogozzo committed Dec 5, 2023
1 parent 93216a7 commit af0e1f4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,21 @@ find_package(SQLiteCpp REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIBS})
target_link_libraries(${PROJECT_NAME}-static PUBLIC ${LIBS})
if(LINUX)
set(LIBS-LINUX libsecret::libsecret PkgConfig::glib-2.0 PkgConfig::gio-2.0 PkgConfig::gmodule-2.0 PkgConfig::gobject-2.0 PkgConfig::gthread-2.0)
find_package(PkgConfig REQUIRED)
find_package(libsecret REQUIRED CONFIG)
target_link_libraries(${PROJECT_NAME} PUBLIC libsecret::libsecret)
target_link_libraries(${PROJECT_NAME}-static PUBLIC libsecret::libsecret)
pkg_check_modules(glib-2.0 REQUIRED IMPORTED_TARGET glib-2.0)
pkg_check_modules(gio-2.0 REQUIRED IMPORTED_TARGET gio-2.0)
pkg_check_modules(gmodule-2.0 REQUIRED IMPORTED_TARGET gmodule-2.0)
pkg_check_modules(gobject-2.0 REQUIRED IMPORTED_TARGET gobject-2.0)
pkg_check_modules(gthread-2.0 REQUIRED IMPORTED_TARGET gthread-2.0)
target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::glib-2.0 PkgConfig::gio-2.0 PkgConfig::gmodule-2.0 PkgConfig::gobject-2.0 PkgConfig::gthread-2.0)
target_link_libraries(${PROJECT_NAME}-static PUBLIC PkgConfig::glib-2.0 PkgConfig::gio-2.0 PkgConfig::gmodule-2.0 PkgConfig::gobject-2.0 PkgConfig::gthread-2.0)
pkg_search_module(UUID REQUIRED uuid)
target_include_directories(${PROJECT_NAME} PUBLIC ${UUID_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME}-static PUBLIC ${UUID_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIBS-LINUX} ${UUID_LIBRARIES})
target_link_libraries(${PROJECT_NAME}-static PUBLIC ${LIBS-LINUX} ${UUID_LIBRARIES})
else()
target_link_libraries(${PROJECT_NAME}-static PUBLIC Advapi32 Shell32)
endif()

#libaura Install
Expand Down
7 changes: 5 additions & 2 deletions src/helpers/stringhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <iomanip>
#include <regex>
#include <sstream>
#include <curl/curl.h>
#ifdef _WIN32
#include <windows.h>
#else
Expand Down Expand Up @@ -112,7 +113,9 @@ namespace Nickvision::Aura
{
return false;
}
std::regex urlRegex{ "^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$" };
return std::regex_match(s, urlRegex);
CURLU* url{ curl_url() };
int res{ curl_url_set(url, CURLUPART_URL, s.c_str(), 0) };
curl_url_cleanup(url);
return res == CURLUE_OK;
}
}
5 changes: 1 addition & 4 deletions src/helpers/webhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ namespace Nickvision::Aura
}
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true);
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
curl_easy_setopt(curl, CURLOPT_HEADER, false);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, [](char*, size_t size, size_t nmemb, void*)
{
return size * nmemb;
});
CURLcode code = curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl_global_cleanup();
Expand Down
2 changes: 1 addition & 1 deletion tests/stringtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ TEST(StringTests, UrlValidity2)

TEST(StringTests, UrlValidity3)
{
EXPECT_FALSE(StringHelpers::isValidUrl("https://microsoft"));
EXPECT_TRUE(StringHelpers::isValidUrl("https://microsoft"));
}

TEST(StringTests, UrlValidity4)
Expand Down

0 comments on commit af0e1f4

Please sign in to comment.