Move http client to URL

Type safety is a good thing.  In:
https://gerrit.openbmc.org/c/openbmc/bmcweb/+/65606

It was found that splitting out the URI into encoded pieces in the early
phase removed some information we needed, namely whether or not a URI
was ipv6.  This commit changes http client such that it passes all the
information through, with the correct type, rather than passing in
hostname, port, path, and ssl separately.

Opportunistically, because a number of log lines are changing, this uses
the opportunity to remove a number of calls to std::to_string, and rely
on std::format instead.

Now that we no longer use custom URI splitting code, the
ValidateAndSplitUrl() method can be removed, given that our validation
now happens in the URI class.

Tested: Aggregation works properly when satellite URIs are queried.

Change-Id: I9f605863179af54c5af2719bc5ce9d29cbfffab7
Signed-off-by: Ed Tanous <edtanous@google.com>
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp
index b49e35a..89c2337 100644
--- a/redfish-core/lib/event_service.hpp
+++ b/redfish-core/lib/event_service.hpp
@@ -24,6 +24,7 @@
 
 #include <boost/beast/http/fields.hpp>
 #include <boost/system/error_code.hpp>
+#include <boost/url/parse.hpp>
 #include <sdbusplus/unpack_properties.hpp>
 #include <utils/dbus_utils.hpp>
 
@@ -317,19 +318,30 @@
             }
         }
 
-        std::string host;
-        std::string urlProto;
-        uint16_t port = 0;
-        std::string path;
-
-        if (!crow::utility::validateAndSplitUrl(destUrl, urlProto, host, port,
-                                                path))
+        boost::urls::result<boost::urls::url> url =
+            boost::urls::parse_absolute_uri(destUrl);
+        if (!url)
         {
             BMCWEB_LOG_WARNING("Failed to validate and split destination url");
             messages::propertyValueFormatError(asyncResp->res, destUrl,
                                                "Destination");
             return;
         }
+        url->normalize();
+        crow::utility::setProtocolDefaults(*url, protocol);
+        crow::utility::setPortDefaults(*url);
+
+        if (url->path().empty())
+        {
+            url->set_path("/");
+        }
+
+        if (url->has_userinfo())
+        {
+            messages::propertyValueFormatError(asyncResp->res, destUrl,
+                                               "Destination");
+            return;
+        }
 
         if (protocol == "SNMPv2c")
         {
@@ -381,20 +393,22 @@
                     asyncResp->res, "MetricReportDefinitions", "Protocol");
                 return;
             }
+            if (url->scheme() != "snmp")
+            {
+                messages::propertyValueConflict(asyncResp->res, "Destination",
+                                                "Protocol");
+                return;
+            }
 
-            addSnmpTrapClient(asyncResp, host, port);
+            addSnmpTrapClient(asyncResp, url->host_address(),
+                              url->port_number());
             return;
         }
 
-        if (path.empty())
-        {
-            path = "/";
-        }
+        std::shared_ptr<Subscription> subValue =
+            std::make_shared<Subscription>(*url, app.ioContext());
 
-        std::shared_ptr<Subscription> subValue = std::make_shared<Subscription>(
-            host, port, path, urlProto, app.ioContext());
-
-        subValue->destinationUrl = destUrl;
+        subValue->destinationUrl = std::move(*url);
 
         if (subscriptionType)
         {