update ASIO interfaces

This commit does 2 things.

1. Upgrades and prepares bmcweb for boost 1.70.
2. Allows us to compile with BOOST_AIO_NO_DEPRECATED

Tested: Compiled against 1.69 and 1.70.  All changes should be no-op.

Change-Id: I557ecd840fe2b88c0fa01978a1b666b40ccccca4
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1300c23..70e56fd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -125,6 +125,7 @@
 add_definitions (-DBOOST_BEAST_USE_STD_STRING_VIEW)
 add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
 add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
+add_definitions (-DBOOST_ASIO_NO_DEPRECATED)
 add_definitions (-DBOOST_ALL_NO_LIB)
 add_definitions (-DBOOST_NO_RTTI)
 add_definitions (-DBOOST_NO_TYPEID)
diff --git a/crow/include/crow/http_connection.h b/crow/include/crow/http_connection.h
index c02f4ec..ba2bcdd 100644
--- a/crow/include/crow/http_connection.h
+++ b/crow/include/crow/http_connection.h
@@ -8,7 +8,11 @@
 #include <boost/asio/ip/tcp.hpp>
 #include <boost/asio/ssl.hpp>
 #include <boost/beast/core/flat_static_buffer.hpp>
+#if BOOST_VERSION >= 107000
+#include <boost/beast/ssl/ssl_stream.hpp>
+#else
 #include <boost/beast/experimental/core/ssl_stream.hpp>
+#endif
 #include <boost/beast/http.hpp>
 #include <boost/beast/websocket.hpp>
 #include <chrono>
@@ -323,30 +327,22 @@
             }
         }
 
-        std::string epName;
-        boost::system::error_code ec;
-        tcp::endpoint ep = adaptor.lowest_layer().remote_endpoint(ec);
-        if (!ec)
-        {
-            epName = boost::lexical_cast<std::string>(ep);
-        }
-
-        BMCWEB_LOG_INFO << "Request: " << epName << " " << this << " HTTP/"
-                        << req->version() / 10 << "." << req->version() % 10
-                        << ' ' << req->methodString() << " " << req->target();
+        BMCWEB_LOG_INFO << "Request: "
+                        << " " << this << " HTTP/" << req->version() / 10 << "."
+                        << req->version() % 10 << ' ' << req->methodString()
+                        << " " << req->target();
 
         needToCallAfterHandlers = false;
 
         if (!isInvalidRequest)
         {
             res.completeRequestHandler = [] {};
-            res.isAliveHelper = [this]() -> bool {
-                return adaptor.lowest_layer().is_open();
-            };
+            res.isAliveHelper = [this]() -> bool { return isAlive(); };
 
             ctx = detail::Context<Middlewares...>();
-            req->middlewareContext = (void*)&ctx;
-            req->ioService = &adaptor.get_executor().context();
+            req->middlewareContext = static_cast<void*>(&ctx);
+            req->ioService = static_cast<decltype(req->ioService)>(
+                &adaptor.get_executor().context());
             detail::middlewareCallHelper<
                 0, decltype(ctx), decltype(*middlewares), Middlewares...>(
                 *middlewares, *req, res, ctx);
@@ -378,6 +374,35 @@
         }
     }
 
+    bool isAlive()
+    {
+
+        if constexpr (std::is_same_v<Adaptor,
+                                     boost::beast::ssl_stream<
+                                         boost::asio::ip::tcp::socket>>)
+        {
+            return adaptor.next_layer().is_open();
+        }
+        else
+        {
+            return adaptor.is_open();
+        }
+    }
+    void close()
+    {
+
+        if constexpr (std::is_same_v<Adaptor,
+                                     boost::beast::ssl_stream<
+                                         boost::asio::ip::tcp::socket>>)
+        {
+            adaptor.next_layer().close();
+        }
+        else
+        {
+            adaptor.close();
+        }
+    }
+
     void completeRequest()
     {
         BMCWEB_LOG_INFO << "Response: " << this << ' ' << req->url << ' '
@@ -397,7 +422,7 @@
         // auto self = this->shared_from_this();
         res.completeRequestHandler = res.completeRequestHandler = [] {};
 
-        if (!adaptor.lowest_layer().is_open())
+        if (!isAlive())
         {
             // BMCWEB_LOG_DEBUG << this << " delete (socket is closed) " <<
             // isReading
@@ -456,7 +481,7 @@
                 {
                     // if the adaptor isn't open anymore, and wasn't handed to a
                     // websocket, treat as an error
-                    if (!adaptor.lowest_layer().is_open() && !req->isUpgrade())
+                    if (!isAlive() && !req->isUpgrade())
                     {
                         errorWhileReading = true;
                     }
@@ -465,7 +490,7 @@
                 if (errorWhileReading)
                 {
                     cancelDeadlineTimer();
-                    adaptor.lowest_layer().close();
+                    close();
                     BMCWEB_LOG_DEBUG << this << " from read(1)";
                     checkDestroy();
                     return;
@@ -505,7 +530,7 @@
                 }
                 else
                 {
-                    if (!adaptor.lowest_layer().is_open())
+                    if (!isAlive())
                     {
                         errorWhileReading = true;
                     }
@@ -513,7 +538,7 @@
                 if (errorWhileReading)
                 {
                     cancelDeadlineTimer();
-                    adaptor.lowest_layer().close();
+                    close();
                     BMCWEB_LOG_DEBUG << this << " from read(1)";
                     checkDestroy();
                     return;
@@ -545,7 +570,7 @@
                 }
                 if (!res.keepAlive())
                 {
-                    adaptor.lowest_layer().close();
+                    close();
                     BMCWEB_LOG_DEBUG << this << " from write(1)";
                     checkDestroy();
                     return;
@@ -587,11 +612,11 @@
         cancelDeadlineTimer();
 
         timerCancelKey = timerQueue.add([this] {
-            if (!adaptor.lowest_layer().is_open())
+            if (!isAlive())
             {
                 return;
             }
-            adaptor.lowest_layer().close();
+            close();
         });
         BMCWEB_LOG_DEBUG << this << " timer added: " << &timerQueue << ' '
                          << timerCancelKey;
diff --git a/crow/include/crow/http_server.h b/crow/include/crow/http_server.h
index 75b49a4..31b8ec2 100644
--- a/crow/include/crow/http_server.h
+++ b/crow/include/crow/http_server.h
@@ -2,10 +2,16 @@
 
 #include <atomic>
 #include <boost/asio/deadline_timer.hpp>
+#include <boost/asio/ip/address.hpp>
 #include <boost/asio/ip/tcp.hpp>
 #include <boost/asio/signal_set.hpp>
 #include <boost/asio/ssl/context.hpp>
+#if BOOST_VERSION >= 107000
+#include <boost/beast/ssl/ssl_stream.hpp>
+#else
 #include <boost/beast/experimental/core/ssl_stream.hpp>
+#endif
+
 #include <boost/date_time/posix_time/posix_time.hpp>
 #include <chrono>
 #include <cstdint>
@@ -47,9 +53,8 @@
                std::make_shared<boost::asio::io_context>()) :
         Server(handler,
                std::make_unique<tcp::acceptor>(
-                   *io,
-                   tcp::endpoint(
-                       boost::asio::ip::address::from_string(bindaddr), port)),
+                   *io, tcp::endpoint(boost::asio::ip::make_address(bindaddr),
+                                      port)),
                middlewares, adaptor_ctx, io)
     {
     }
@@ -168,30 +173,50 @@
                                        boost::asio::ip::tcp::socket>>::value)
         {
             adaptorTemp = Adaptor(*ioService, *adaptorCtx);
+            Connection<Adaptor, Handler, Middlewares...>* p =
+                new Connection<Adaptor, Handler, Middlewares...>(
+                    *ioService, handler, serverName, middlewares,
+                    getCachedDateStr, timerQueue,
+                    std::move(adaptorTemp.value()));
+
+            acceptor->async_accept(p->socket().next_layer(),
+                                   [this, p](boost::system::error_code ec) {
+                                       if (!ec)
+                                       {
+                                           boost::asio::post(
+                                               *this->ioService,
+                                               [p] { p->start(); });
+                                       }
+                                       else
+                                       {
+                                           delete p;
+                                       }
+                                       doAccept();
+                                   });
         }
         else
         {
             adaptorTemp = Adaptor(*ioService);
+            Connection<Adaptor, Handler, Middlewares...>* p =
+                new Connection<Adaptor, Handler, Middlewares...>(
+                    *ioService, handler, serverName, middlewares,
+                    getCachedDateStr, timerQueue,
+                    std::move(adaptorTemp.value()));
+
+            acceptor->async_accept(
+                p->socket(), [this, p](boost::system::error_code ec) {
+                    if (!ec)
+                    {
+                        boost::asio::post(*this->ioService,
+                                          [p] { p->start(); });
+                    }
+                    else
+                    {
+                        delete p;
+                    }
+                    doAccept();
+                });
         }
-
-        Connection<Adaptor, Handler, Middlewares...>* p =
-            new Connection<Adaptor, Handler, Middlewares...>(
-                *ioService, handler, serverName, middlewares, getCachedDateStr,
-                timerQueue, std::move(adaptorTemp.value()));
-
-        acceptor->async_accept(p->socket().lowest_layer(),
-                               [this, p](boost::system::error_code ec) {
-                                   if (!ec)
-                                   {
-                                       this->ioService->post(
-                                           [p] { p->start(); });
-                                   }
-                                   else
-                                   {
-                                       delete p;
-                                   }
-                                   doAccept();
-                               });
     }
 
   private:
diff --git a/crow/include/crow/websocket.h b/crow/include/crow/websocket.h
index 6901eb1..778a297 100644
--- a/crow/include/crow/websocket.h
+++ b/crow/include/crow/websocket.h
@@ -66,7 +66,7 @@
 
     boost::asio::io_context& get_io_context() override
     {
-        return ws.get_executor().context();
+        return (boost::asio::io_context&)ws.get_executor().context();
     }
 
     void start()
diff --git a/include/kvm_websocket.hpp b/include/kvm_websocket.hpp
index 8034ba7..d0c5539 100644
--- a/include/kvm_websocket.hpp
+++ b/include/kvm_websocket.hpp
@@ -137,7 +137,7 @@
             if (hostSocket == nullptr)
             {
                 boost::asio::ip::tcp::endpoint endpoint(
-                    boost::asio::ip::address::from_string("127.0.0.1"), 5900);
+                    boost::asio::ip::make_address("127.0.0.1"), 5900);
 
                 hostSocket = std::make_unique<boost::asio::ip::tcp::socket>(
                     conn.get_io_context());
@@ -148,8 +148,13 @@
             [](crow::websocket::Connection& conn, const std::string& reason) {
                 session = nullptr;
                 hostSocket = nullptr;
+#if BOOST_VERSION >= 107000
+                inputBuffer.clear();
+                outputBuffer.clear();
+#else
                 inputBuffer.reset();
                 outputBuffer.reset();
+#endif
             })
         .onmessage([](crow::websocket::Connection& conn,
                       const std::string& data, bool is_binary) {
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index bbed047..d3c858f 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -588,8 +588,15 @@
             {
                 return; // don't have to have this interface
             }
-            for (const auto& [path, objDict] : resp)
+            for (const std::pair<std::string,
+                                 std::vector<std::pair<
+                                     std::string, std::vector<std::string>>>>&
+                     pathPair : resp)
             {
+                const std::string& path = pathPair.first;
+                const std::vector<
+                    std::pair<std::string, std::vector<std::string>>>& objDict =
+                    pathPair.second;
                 if (objDict.empty())
                 {
                     continue; // this should be impossible