Implement nbd-proxy as a part of bmcweb

Nbd-proxy is responsible for exposing websocket endpoint in bmcweb.
It matches WS endpoints with unix socket paths using configuration
exposed on D-Bus by Virtual-Media.

Virtual-Media is then notified about unix socket availability through
mount/unmount D-Bus methods.

Currently, this feature is disabled by default.

Tested: Integrated with initial version of Virtual-Media.

Change-Id: I9c572e9841b16785727e5676fea1bb63b0311c63
Signed-off-by: Iwona Klimaszewska <iwona.klimaszewska@intel.com>
Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com>
diff --git a/http/websocket.h b/http/websocket.h
index 61b3e5a..80d536a 100644
--- a/http/websocket.h
+++ b/http/websocket.h
@@ -1,5 +1,6 @@
 #pragma once
 #include <array>
+#include <async_resp.hpp>
 #include <boost/algorithm/string/predicate.hpp>
 #include <boost/asio/buffer.hpp>
 #include <boost/beast/websocket.hpp>
@@ -15,10 +16,11 @@
 {
 namespace websocket
 {
+
 struct Connection : std::enable_shared_from_this<Connection>
 {
   public:
-    explicit Connection(const crow::Request& reqIn) :
+    explicit Connection(const crow::Request& reqIn, crow::Response& res) :
         req(reqIn), userdataPtr(nullptr){};
 
     virtual void sendBinary(const std::string_view msg) = 0;
@@ -39,6 +41,7 @@
     }
 
     crow::Request req;
+    crow::Response res;
 
   private:
     void* userdataPtr;
@@ -48,13 +51,14 @@
 {
   public:
     ConnectionImpl(
-        const crow::Request& reqIn, Adaptor adaptorIn,
-        std::function<void(Connection&)> open_handler,
+        const crow::Request& reqIn, crow::Response& res, Adaptor adaptorIn,
+        std::function<void(Connection&, std::shared_ptr<bmcweb::AsyncResp>)>
+            open_handler,
         std::function<void(Connection&, const std::string&, bool)>
             message_handler,
         std::function<void(Connection&, const std::string&)> close_handler,
         std::function<void(Connection&)> error_handler) :
-        Connection(reqIn),
+        Connection(reqIn, res),
         ws(std::move(adaptorIn)), inString(), inBuffer(inString, 131088),
         openHandler(std::move(open_handler)),
         messageHandler(std::move(message_handler)),
@@ -158,11 +162,15 @@
     {
         BMCWEB_LOG_DEBUG << "Websocket accepted connection";
 
+        auto asyncResp = std::make_shared<bmcweb::AsyncResp>(
+            res, [this, self(shared_from_this())]() { doRead(); });
+
+        asyncResp->res.result(boost::beast::http::status::ok);
+
         if (openHandler)
         {
-            openHandler(*this);
+            openHandler(*this, asyncResp);
         }
-        doRead();
     }
 
     void doRead()
@@ -241,7 +249,8 @@
     std::vector<std::string> outBuffer;
     bool doingWrite = false;
 
-    std::function<void(Connection&)> openHandler;
+    std::function<void(Connection&, std::shared_ptr<bmcweb::AsyncResp>)>
+        openHandler;
     std::function<void(Connection&, const std::string&, bool)> messageHandler;
     std::function<void(Connection&, const std::string&)> closeHandler;
     std::function<void(Connection&)> errorHandler;