Clean up BMCWEB_ENABLE_SSL

This macro came originally from CROW_ENABLE_SSL, and was used as a macro
to optionally compile without openssl being required.

OpenSSL has been pulled into many other dependencies, and has been
functionally required to be included for a long time, so there's no
reason to hold onto this macro.

Remove most uses of the macro, and for the couple functional places the
macro is used, transition to a constexpr if to enable the TLS paths.

This allows a large simplification of code in some places.

Tested: Redfish service validator passes.

Change-Id: Iebd46a68e5e417b6031479e24be3c21bef782f4c
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/http/http_server.hpp b/http/http_server.hpp
index 2a6bd9f..da73b10 100644
--- a/http/http_server.hpp
+++ b/http/http_server.hpp
@@ -27,38 +27,15 @@
 class Server
 {
   public:
-    Server(Handler* handlerIn,
-           std::unique_ptr<boost::asio::ip::tcp::acceptor>&& acceptorIn,
+    Server(Handler* handlerIn, boost::asio::ip::tcp::acceptor&& acceptorIn,
            std::shared_ptr<boost::asio::ssl::context> adaptorCtxIn,
-           std::shared_ptr<boost::asio::io_context> io =
-               std::make_shared<boost::asio::io_context>()) :
+           std::shared_ptr<boost::asio::io_context> io) :
         ioService(std::move(io)),
         acceptor(std::move(acceptorIn)),
         signals(*ioService, SIGINT, SIGTERM, SIGHUP), handler(handlerIn),
         adaptorCtx(std::move(adaptorCtxIn))
     {}
 
-    Server(Handler* handlerIn, uint16_t port,
-           const std::shared_ptr<boost::asio::ssl::context>& adaptorCtxIn,
-           const std::shared_ptr<boost::asio::io_context>& io =
-               std::make_shared<boost::asio::io_context>()) :
-        Server(handlerIn,
-               std::make_unique<boost::asio::ip::tcp::acceptor>(
-                   *io, boost::asio::ip::tcp::endpoint(
-                            boost::asio::ip::make_address("0.0.0.0"), port)),
-               adaptorCtxIn, io)
-    {}
-
-    Server(Handler* handlerIn, int existingSocket,
-           const std::shared_ptr<boost::asio::ssl::context>& adaptorCtxIn,
-           const std::shared_ptr<boost::asio::io_context>& io =
-               std::make_shared<boost::asio::io_context>()) :
-        Server(handlerIn,
-               std::make_unique<boost::asio::ip::tcp::acceptor>(
-                   *io, boost::asio::ip::tcp::v6(), existingSocket),
-               adaptorCtxIn, io)
-    {}
-
     void updateDateStr()
     {
         time_t lastTimeT = time(nullptr);
@@ -90,14 +67,17 @@
         };
 
         BMCWEB_LOG_INFO("bmcweb server is running, local endpoint {}",
-                        acceptor->local_endpoint().address().to_string());
+                        acceptor.local_endpoint().address().to_string());
         startAsyncWaitForSignal();
         doAccept();
     }
 
     void loadCertificate()
     {
-#ifdef BMCWEB_ENABLE_SSL
+        if constexpr (!bmcwebEnableTLS)
+        {
+            return;
+        }
         namespace fs = std::filesystem;
         // Cleanup older certificate file existing in the system
         fs::path oldCert = "/home/root/server.pem";
@@ -121,7 +101,6 @@
             ensuressl::getSslContext(sslPemFile);
         adaptorCtx = sslContext;
         handler->ssl(std::move(sslContext));
-#endif
     }
 
     void startAsyncWaitForSignal()
@@ -139,7 +118,7 @@
                     BMCWEB_LOG_INFO("Receivied reload signal");
                     loadCertificate();
                     boost::system::error_code ec2;
-                    acceptor->cancel(ec2);
+                    acceptor.cancel(ec2);
                     if (ec2)
                     {
                         BMCWEB_LOG_ERROR(
@@ -163,12 +142,23 @@
 
     void doAccept()
     {
+        if (ioService == nullptr)
+        {
+            BMCWEB_LOG_CRITICAL("IoService was null");
+            return;
+        }
         boost::asio::steady_timer timer(*ioService);
         std::shared_ptr<Connection<Adaptor, Handler>> connection;
         if constexpr (std::is_same<Adaptor,
                                    boost::beast::ssl_stream<
                                        boost::asio::ip::tcp::socket>>::value)
         {
+            if (adaptorCtx == nullptr)
+            {
+                BMCWEB_LOG_CRITICAL(
+                    "Asked to lauch TLS socket but no context available");
+                return;
+            }
             connection = std::make_shared<Connection<Adaptor, Handler>>(
                 handler, std::move(timer), getCachedDateStr,
                 Adaptor(*ioService, *adaptorCtx));
@@ -179,7 +169,7 @@
                 handler, std::move(timer), getCachedDateStr,
                 Adaptor(*ioService));
         }
-        acceptor->async_accept(
+        acceptor.async_accept(
             boost::beast::get_lowest_layer(connection->socket()),
             [this, connection](const boost::system::error_code& ec) {
             if (!ec)
@@ -194,7 +184,7 @@
   private:
     std::shared_ptr<boost::asio::io_context> ioService;
     std::function<std::string()> getCachedDateStr;
-    std::unique_ptr<boost::asio::ip::tcp::acceptor> acceptor;
+    boost::asio::ip::tcp::acceptor acceptor;
     boost::asio::signal_set signals;
 
     std::string dateStr;