Implement feature selection in bmcweb
This patchsets implements feature selection in BMCWEB using compile
time macros. This allows certain features, security implementations,
and other things to be selected at compile time.
Change-Id: Ic14343d36d82830e6cf51311ca886a90749ae6a7
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
diff --git a/crow/include/crow.h b/crow/include/crow.h
index 28d46b6..edc0d7f 100644
--- a/crow/include/crow.h
+++ b/crow/include/crow.h
@@ -1,17 +1,16 @@
#pragma once
-#include "crow/query_string.h"
-#include "crow/settings.h"
-#include "crow/socket_adaptors.h"
+#include "crow/app.h"
+#include "crow/common.h"
+#include "crow/http_connection.h"
+#include "crow/http_request.h"
+#include "crow/http_response.h"
+#include "crow/http_server.h"
#include "crow/logging.h"
+#include "crow/middleware_context.h"
+#include "crow/query_string.h"
+#include "crow/routing.h"
+#include "crow/socket_adaptors.h"
#include "crow/timer_queue.h"
#include "crow/utility.h"
-#include "crow/common.h"
-#include "crow/http_request.h"
#include "crow/websocket.h"
-#include "crow/http_response.h"
-#include "crow/routing.h"
-#include "crow/middleware_context.h"
-#include "crow/http_connection.h"
-#include "crow/http_server.h"
-#include "crow/app.h"
#include "boost/beast/core.hpp"
diff --git a/crow/include/crow/app.h b/crow/include/crow/app.h
index bb5a33b..9abf6bb 100644
--- a/crow/include/crow/app.h
+++ b/crow/include/crow/app.h
@@ -13,7 +13,6 @@
#include "crow/logging.h"
#include "crow/middleware_context.h"
#include "crow/routing.h"
-#include "crow/settings.h"
#include "crow/utility.h"
#define CROW_ROUTE(app, url) \
diff --git a/crow/include/crow/http_connection.h b/crow/include/crow/http_connection.h
index e34b758..43437ef 100644
--- a/crow/include/crow/http_connection.h
+++ b/crow/include/crow/http_connection.h
@@ -8,7 +8,6 @@
#include "crow/http_response.h"
#include "crow/logging.h"
#include "crow/middleware_context.h"
-#include "crow/settings.h"
#include "crow/socket_adaptors.h"
#include "crow/timer_queue.h"
#include <boost/algorithm/string.hpp>
diff --git a/crow/include/crow/logging.h b/crow/include/crow/logging.h
index fb3aba0..390f80f 100644
--- a/crow/include/crow/logging.h
+++ b/crow/include/crow/logging.h
@@ -1,141 +1,123 @@
#pragma once
-#include <string>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
+#include <string>
-#include "crow/settings.h"
-
-namespace crow
-{
- enum class LogLevel
- {
+namespace crow {
+enum class LogLevel {
#ifndef ERROR
- DEBUG = 0,
- INFO,
- WARNING,
- ERROR,
- CRITICAL,
+ DEBUG = 0,
+ INFO,
+ WARNING,
+ ERROR,
+ CRITICAL,
#endif
- Debug = 0,
- Info,
- Warning,
- Error,
- Critical,
- };
+ Debug = 0,
+ Info,
+ Warning,
+ Error,
+ Critical,
+};
- class ILogHandler {
- public:
- virtual void log(std::string message, LogLevel level) = 0;
- };
+class ILogHandler {
+ public:
+ virtual void log(std::string message, LogLevel level) = 0;
+};
- class CerrLogHandler : public ILogHandler {
- public:
- void log(std::string message, LogLevel /*level*/) override {
- std::cerr << message;
- }
- };
+class CerrLogHandler : public ILogHandler {
+ public:
+ void log(std::string message, LogLevel /*level*/) override {
+ std::cerr << message;
+ }
+};
- class logger {
+class logger {
+ private:
+ //
+ static std::string timestamp() {
+ char date[32];
+ time_t t = time(0);
- private:
- //
- static std::string timestamp()
- {
- char date[32];
- time_t t = time(0);
-
- tm my_tm{};
+ tm my_tm{};
#ifdef _MSC_VER
- gmtime_s(&my_tm, &t);
+ gmtime_s(&my_tm, &t);
#else
- gmtime_r(&t, &my_tm);
+ gmtime_r(&t, &my_tm);
#endif
- size_t sz = strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", &my_tm);
- return std::string(date, date+sz);
- }
+ size_t sz = strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", &my_tm);
+ return std::string(date, date + sz);
+ }
- public:
+ public:
+ logger(const std::string& prefix, LogLevel level) : level_(level) {
+#ifdef CROW_ENABLE_LOGGING
+ stringstream_ << "(" << timestamp() << ") [" << prefix << "] ";
+#endif
+ }
+ ~logger() {
+#ifdef CROW_ENABLE_LOGGING
+ if (level_ >= get_current_log_level()) {
+ stringstream_ << std::endl;
+ get_handler_ref()->log(stringstream_.str(), level_);
+ }
+#endif
+ }
+ //
+ template <typename T>
+ logger& operator<<(T const& value) {
+#ifdef CROW_ENABLE_LOGGING
+ if (level_ >= get_current_log_level()) {
+ stringstream_ << value;
+ }
+#endif
+ return *this;
+ }
- logger(const std::string& prefix, LogLevel level) : level_(level) {
- #ifdef CROW_ENABLE_LOGGING
- stringstream_ << "(" << timestamp() << ") [" << prefix << "] ";
- #endif
+ //
+ static void setLogLevel(LogLevel level) { get_log_level_ref() = level; }
- }
- ~logger() {
- #ifdef CROW_ENABLE_LOGGING
- if(level_ >= get_current_log_level()) {
- stringstream_ << std::endl;
- get_handler_ref()->log(stringstream_.str(), level_);
- }
- #endif
- }
+ static void setHandler(ILogHandler* handler) { get_handler_ref() = handler; }
- //
- template <typename T>
- logger& operator<<(T const &value) {
+ static LogLevel get_current_log_level() { return get_log_level_ref(); }
- #ifdef CROW_ENABLE_LOGGING
- if(level_ >= get_current_log_level()) {
- stringstream_ << value;
- }
- #endif
- return *this;
- }
+ private:
+ //
+ static LogLevel& get_log_level_ref() {
+ static auto current_level = static_cast<LogLevel>(1);
+ return current_level;
+ }
+ static ILogHandler*& get_handler_ref() {
+ static CerrLogHandler default_handler;
+ static ILogHandler* current_handler = &default_handler;
+ return current_handler;
+ }
- //
- static void setLogLevel(LogLevel level) {
- get_log_level_ref() = level;
- }
-
- static void setHandler(ILogHandler* handler) {
- get_handler_ref() = handler;
- }
-
- static LogLevel get_current_log_level() {
- return get_log_level_ref();
- }
-
- private:
- //
- static LogLevel& get_log_level_ref()
- {
- static auto current_level = static_cast<LogLevel>(CROW_LOG_LEVEL);
- return current_level;
- }
- static ILogHandler*& get_handler_ref()
- {
- static CerrLogHandler default_handler;
- static ILogHandler* current_handler = &default_handler;
- return current_handler;
- }
-
- //
- std::ostringstream stringstream_;
- LogLevel level_;
- };
+ //
+ std::ostringstream stringstream_;
+ LogLevel level_;
+};
} // namespace crow
-#define CROW_LOG_CRITICAL \
- if (crow::logger::get_current_log_level() <= crow::LogLevel::Critical) \
- crow::logger("CRITICAL", crow::LogLevel::Critical)
-#define CROW_LOG_ERROR \
- if (crow::logger::get_current_log_level() <= crow::LogLevel::Error) \
- crow::logger("ERROR ", crow::LogLevel::Error)
-#define CROW_LOG_WARNING \
- if (crow::logger::get_current_log_level() <= crow::LogLevel::Warning) \
- crow::logger("WARNING ", crow::LogLevel::Warning)
-#define CROW_LOG_INFO \
- if (crow::logger::get_current_log_level() <= crow::LogLevel::Info) \
- crow::logger("INFO ", crow::LogLevel::Info)
-#define CROW_LOG_DEBUG \
- if (crow::logger::get_current_log_level() <= crow::LogLevel::Debug) \
- crow::logger("DEBUG ", crow::LogLevel::Debug)
+#define CROW_LOG_CRITICAL \
+ if (crow::logger::get_current_log_level() <= crow::LogLevel::Critical) \
+ crow::logger("CRITICAL", crow::LogLevel::Critical)
+#define CROW_LOG_ERROR \
+ if (crow::logger::get_current_log_level() <= crow::LogLevel::Error) \
+ crow::logger("ERROR ", crow::LogLevel::Error)
+#define CROW_LOG_WARNING \
+ if (crow::logger::get_current_log_level() <= crow::LogLevel::Warning) \
+ crow::logger("WARNING ", crow::LogLevel::Warning)
+#define CROW_LOG_INFO \
+ if (crow::logger::get_current_log_level() <= crow::LogLevel::Info) \
+ crow::logger("INFO ", crow::LogLevel::Info)
+#define CROW_LOG_DEBUG \
+ if (crow::logger::get_current_log_level() <= crow::LogLevel::Debug) \
+ crow::logger("DEBUG ", crow::LogLevel::Debug)
diff --git a/crow/include/crow/socket_adaptors.h b/crow/include/crow/socket_adaptors.h
index a057240..e3d0081 100644
--- a/crow/include/crow/socket_adaptors.h
+++ b/crow/include/crow/socket_adaptors.h
@@ -1,6 +1,6 @@
#pragma once
#include "crow/logging.h"
-#include "crow/settings.h"
+
#include <boost/asio.hpp>
#include <boost/lexical_cast.hpp>
diff --git a/crow/include/crow/utility.h b/crow/include/crow/utility.h
index 7cae52e..98b6534 100644
--- a/crow/include/crow/utility.h
+++ b/crow/include/crow/utility.h
@@ -6,10 +6,8 @@
#include <stdexcept>
#include <string>
#include <tuple>
-#include <boost/utility/string_view.hpp>
#include "nlohmann/json.hpp"
-
-#include "crow/settings.h"
+#include <boost/utility/string_view.hpp>
namespace crow {
namespace black_magic {
@@ -519,8 +517,7 @@
// TODO this is temporary and should be deleted once base64 is refactored out of
// crow
-inline bool base64_decode(const boost::string_view input,
- std::string& output) {
+inline bool base64_decode(const boost::string_view input, std::string& output) {
static const char nop = -1;
// See note on encoding_data[] in above function
static const char decoding_data[] = {