From 11baefe467d1b6d4c845325276bc46de01d23cdb Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Wed, 9 Feb 2022 12:14:12 -0800 Subject: Move validateAndSplitUri to common utility header This function in practice looks like it has another use where the code is essentially the same. Move it to a header so it can be used by other things. And add unit tests to ensure it stays reliable. Tested: Unit tests pass. Signed-off-by: Ed Tanous Change-Id: I3343ba1aa9c0dd542fbb98628b7628cb0704fb3b --- redfish-core/include/event_service_manager.hpp | 50 ++------------------------ 1 file changed, 2 insertions(+), 48 deletions(-) (limited to 'redfish-core/include/event_service_manager.hpp') diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp index 5592d641d3..e879f9e039 100644 --- a/redfish-core/include/event_service_manager.hpp +++ b/redfish-core/include/event_service_manager.hpp @@ -620,8 +620,8 @@ class EventServiceManager std::string urlProto; std::string port; std::string path; - bool status = validateAndSplitUrl(newSub->destinationUrl, urlProto, - host, port, path); + bool status = crow::utility::validateAndSplitUrl( + newSub->destinationUrl, urlProto, host, port, path); if (!status) { @@ -1392,52 +1392,6 @@ class EventServiceManager getReadingsForReport(msg); }); } - - bool validateAndSplitUrl(const std::string& destUrl, std::string& urlProto, - std::string& host, std::string& port, - std::string& path) - { - // Validate URL using regex expression - // Format: ://:/ - // protocol: http/https - const std::regex urlRegex( - "(http|https)://([^/\\x20\\x3f\\x23\\x3a]+):?([0-9]*)(/" - "([^\\x20\\x23\\x3f]*\\x3f?([^\\x20\\x23\\x3f])*)?)"); - std::cmatch match; - if (!std::regex_match(destUrl.c_str(), match, urlRegex)) - { - BMCWEB_LOG_INFO << "Dest. url did not match "; - return false; - } - - urlProto = std::string(match[1].first, match[1].second); - if (urlProto == "http") - { -#ifndef BMCWEB_INSECURE_ENABLE_HTTP_PUSH_STYLE_EVENTING - return false; -#endif - } - - host = std::string(match[2].first, match[2].second); - port = std::string(match[3].first, match[3].second); - path = std::string(match[4].first, match[4].second); - if (port.empty()) - { - if (urlProto == "http") - { - port = "80"; - } - else - { - port = "443"; - } - } - if (path.empty()) - { - path = "/"; - } - return true; - } }; } // namespace redfish -- cgit v1.2.3