added strutil to verify urls

This commit is contained in:
2021-08-04 22:09:58 +02:00
parent fc2eb3718d
commit 78fa43edcf
3 changed files with 16 additions and 0 deletions

View File

@ -30,6 +30,7 @@ set(dependencies
esp_system
# esp_http_client
esp_websocket_client
nghttp
tcp_transport
cpputils

View File

@ -2,6 +2,7 @@
// esp-idf includes
#include <esp_log.h>
#include <http_parser.h>
// 3rdparty lib includes
#include <fmt/core.h>
@ -57,4 +58,13 @@ void urldecode(char *dst, const char *src)
*dst++ = '\0';
}
tl::expected<void, std::string> urlverify(std::string_view str)
{
http_parser_url puri;
http_parser_url_init(&puri);
if (const auto result = http_parser_parse_url(str.data(), str.size(), 0, &puri); result != 0)
return tl::make_unexpected(fmt::format("http_parser_parse_url() failed parsing the url with {}", result));
return {};
}
} // namespace espcpputils

View File

@ -6,10 +6,15 @@
// esp-idf includes
#include <esp_sntp.h>
// 3rdparty lib includes
#include <tl/expected.hpp>
namespace espcpputils {
std::string toString(sntp_sync_mode_t val);
void urldecode(char *dst, const char *src);
tl::expected<void, std::string> urlverify(std::string_view str);
} // namespace espcpputils