diff options
author | Ed Tanous <edtanous@google.com> | 2022-02-09 23:14:12 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-02-15 08:33:22 +0300 |
commit | 11baefe467d1b6d4c845325276bc46de01d23cdb (patch) | |
tree | dfa5230cfd80fa258697d25fc2a7a9fc50c61412 /redfish-core/include | |
parent | dbb59d4dd8e4fc13b1cad11fd3a093f374a2a7ed (diff) | |
download | bmcweb-11baefe467d1b6d4c845325276bc46de01d23cdb.tar.xz |
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 <edtanous@google.com>
Change-Id: I3343ba1aa9c0dd542fbb98628b7628cb0704fb3b
Diffstat (limited to 'redfish-core/include')
-rw-r--r-- | redfish-core/include/event_service_manager.hpp | 50 |
1 files changed, 2 insertions, 48 deletions
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>://<host>:<port>/<path> - // 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 |