aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/http_parser_merged.h28
-rw-r--r--include/http_server.h1
-rw-r--r--include/json.h10
-rw-r--r--include/logging.h189
-rw-r--r--include/settings.h10
5 files changed, 124 insertions, 114 deletions
diff --git a/include/http_parser_merged.h b/include/http_parser_merged.h
index c672352..e058517 100644
--- a/include/http_parser_merged.h
+++ b/include/http_parser_merged.h
@@ -637,7 +637,7 @@ int http_message_needs_eof(const http_parser *parser);
* assumed that the caller cares about (and can detect) the transition between
* URL and non-URL states by looking for these.
*/
-enum state
+inline enum state
parse_url_char(enum state s, const char ch)
{
#if HTTP_PARSER_STRICT
@@ -828,7 +828,7 @@ static const uint8_t normal_url_char[32] = {
return s_dead;
}
-size_t http_parser_execute (http_parser *parser,
+inline size_t http_parser_execute (http_parser *parser,
const http_parser_settings *settings,
const char *data,
size_t len)
@@ -2240,7 +2240,7 @@ error:
/* Does the parser need to see an EOF to find the end of the message? */
-int
+inline int
http_message_needs_eof (const http_parser *parser)
{
if (parser->type == HTTP_REQUEST) {
@@ -2263,7 +2263,7 @@ http_message_needs_eof (const http_parser *parser)
}
-int
+inline int
http_should_keep_alive (const http_parser *parser)
{
if (parser->http_major > 0 && parser->http_minor > 0) {
@@ -2282,7 +2282,7 @@ http_should_keep_alive (const http_parser *parser)
}
-const char *
+inline const char *
http_method_str (enum http_method m)
{
static const char *method_strings[] =
@@ -2295,7 +2295,7 @@ static const char *method_strings[] =
}
-void
+inline void
http_parser_init (http_parser *parser, enum http_parser_type t)
{
void *data = parser->data; /* preserve application data */
@@ -2306,7 +2306,7 @@ http_parser_init (http_parser *parser, enum http_parser_type t)
parser->http_errno = HPE_OK;
}
-const char *
+inline const char *
http_errno_name(enum http_errno err) {
/* Map errno values to strings for human-readable output */
#define HTTP_STRERROR_GEN(n, s) { "HPE_" #n, s },
@@ -2321,7 +2321,7 @@ static struct {
return http_strerror_tab[err].name;
}
-const char *
+inline const char *
http_errno_description(enum http_errno err) {
/* Map errno values to strings for human-readable output */
#define HTTP_STRERROR_GEN(n, s) { "HPE_" #n, s },
@@ -2336,7 +2336,7 @@ static struct {
return http_strerror_tab[err].description;
}
-static enum http_host_state
+inline static enum http_host_state
http_parse_host_char(enum http_host_state s, const char ch) {
switch(s) {
case s_http_userinfo:
@@ -2401,7 +2401,7 @@ http_parse_host_char(enum http_host_state s, const char ch) {
return s_http_host_dead;
}
-static int
+inline int
http_parse_host(const char * buf, struct http_parser_url *u, int found_at) {
enum http_host_state s;
@@ -2474,7 +2474,7 @@ http_parse_host(const char * buf, struct http_parser_url *u, int found_at) {
return 0;
}
-int
+inline int
http_parser_parse_url(const char *buf, size_t buflen, int is_connect,
struct http_parser_url *u)
{
@@ -2573,7 +2573,7 @@ http_parser_parse_url(const char *buf, size_t buflen, int is_connect,
return 0;
}
-void
+inline void
http_parser_pause(http_parser *parser, int paused) {
/* Users should only be pausing/unpausing a parser that is not in an error
* state. In non-debug builds, there's not much that we can do about this
@@ -2587,12 +2587,12 @@ http_parser_pause(http_parser *parser, int paused) {
}
}
-int
+inline int
http_body_is_final(const struct http_parser *parser) {
return parser->state == s_message_done;
}
-unsigned long
+inline unsigned long
http_parser_version(void) {
return HTTP_PARSER_VERSION_MAJOR * 0x10000 |
HTTP_PARSER_VERSION_MINOR * 0x00100 |
diff --git a/include/http_server.h b/include/http_server.h
index 9381fdb..6a3c109 100644
--- a/include/http_server.h
+++ b/include/http_server.h
@@ -3,6 +3,7 @@
#include <boost/asio.hpp>
#include <cstdint>
#include <atomic>
+#include <future>
#include <memory>
diff --git a/include/json.h b/include/json.h
index bcfa24e..9306e2a 100644
--- a/include/json.h
+++ b/include/json.h
@@ -159,27 +159,27 @@ namespace crow
friend rvalue crow::json::load(const char* data, size_t size);
};
- bool operator < (const r_string& l, const r_string& r)
+ inline bool operator < (const r_string& l, const r_string& r)
{
return boost::lexicographical_compare(l,r);
}
- bool operator < (const r_string& l, const std::string& r)
+ inline bool operator < (const r_string& l, const std::string& r)
{
return boost::lexicographical_compare(l,r);
}
- bool operator > (const r_string& l, const std::string& r)
+ inline bool operator > (const r_string& l, const std::string& r)
{
return boost::lexicographical_compare(r,l);
}
- bool operator == (const r_string& l, const r_string& r)
+ inline bool operator == (const r_string& l, const r_string& r)
{
return boost::equals(l,r);
}
- bool operator == (const r_string& l, const std::string& r)
+ inline bool operator == (const r_string& l, const std::string& r)
{
return boost::equals(l,r);
}
diff --git a/include/logging.h b/include/logging.h
index 2984cce..0a15e86 100644
--- a/include/logging.h
+++ b/include/logging.h
@@ -13,98 +13,107 @@ using namespace std;
namespace crow
{
- enum class LogLevel
- {
- CRITICAL,
- ERROR,
- WARNING,
- INFO,
- DEBUG
- };
-
- class ILogHandler {
- public:
- virtual void log(string message, LogLevel level) = 0;
- };
-
- class CerrLogHandler : public ILogHandler {
- public:
- void log(string message, LogLevel level) override {
- cerr << message;
- }
- };
-
- class logger {
-
- private:
- //
- static string timeStamp()
- {
- char date[32];
- time_t t = time(0);
- strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", gmtime(&t));
- return string(date);
- }
-
- public:
-
- //
- static LogLevel currentLevel;
- static std::shared_ptr<ILogHandler> currentHandler;
-
- logger(string prefix, LogLevel level) : m_prefix(prefix), m_level(level) {
-
- }
- ~logger() {
- #ifdef CROW_ENABLE_LOGGING
- if(m_level <= currentLevel) {
- ostringstream str;
- str << "(" << timeStamp() << ") [" << m_prefix << "] " << m_stringStream.str() << endl;
- currentHandler->log(str.str(), m_level);
- }
- #endif
- }
-
- //
- template <typename T>
- logger& operator<<(T const &value) {
-
- #ifdef CROW_ENABLE_LOGGING
- if(m_level <= currentLevel) {
- m_stringStream << value;
- }
- #endif
- return *this;
- }
-
- //
- static void setLogLevel(LogLevel level) {
- currentLevel = level;
- }
-
- static void setHandler(std::shared_ptr<ILogHandler> handler) {
- currentHandler = handler;
- }
-
- private:
-
- //
- ostringstream m_stringStream;
- string m_prefix;
- LogLevel m_level;
- };
-
- //
- LogLevel logger::currentLevel = (LogLevel)CROW_LOG_LEVEL;
- std::shared_ptr<ILogHandler> logger::currentHandler = std::make_shared<CerrLogHandler>();
-
+ enum class LogLevel
+ {
+ DEBUG,
+ INFO,
+ WARNING,
+ ERROR,
+ CRITICAL,
+ };
+
+ class ILogHandler {
+ public:
+ virtual void log(string message, LogLevel level) = 0;
+ };
+
+ class CerrLogHandler : public ILogHandler {
+ public:
+ void log(string message, LogLevel level) override {
+ cerr << message;
+ }
+ };
+
+ class logger {
+
+ private:
+ //
+ static string timestamp()
+ {
+ char date[32];
+ time_t t = time(0);
+ strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", gmtime(&t));
+ return string(date);
+ }
+
+ public:
+
+
+ logger(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_ << 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;
+ }
+
+ //
+ 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 LogLevel current_level = (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;
+ }
+
+ //
+ ostringstream stringstream_;
+ LogLevel level_;
+ };
}
-#define CROW_LOG_CRITICAL crow::logger("CRITICAL", crow::LogLevel::CRITICAL)
-#define CROW_LOG_ERROR crow::logger("ERROR ", crow::LogLevel::ERROR)
-#define CROW_LOG_WARNING crow::logger("WARNING ", crow::LogLevel::WARNING)
-#define CROW_LOG_INFO crow::logger("INFO ", crow::LogLevel::INFO)
-#define CROW_LOG_DEBUG crow::logger("DEBUG ", crow::LogLevel::DEBUG)
+#define CROW_LOG_CRITICAL crow::logger("CRITICAL", crow::LogLevel::CRITICAL)
+#define CROW_LOG_ERROR crow::logger("ERROR ", crow::LogLevel::ERROR)
+#define CROW_LOG_WARNING crow::logger("WARNING ", crow::LogLevel::WARNING)
+#define CROW_LOG_INFO crow::logger("INFO ", crow::LogLevel::INFO)
+#define CROW_LOG_DEBUG crow::logger("DEBUG ", crow::LogLevel::DEBUG)
diff --git a/include/settings.h b/include/settings.h
index 563fb1b..fa51405 100644
--- a/include/settings.h
+++ b/include/settings.h
@@ -9,10 +9,10 @@
/* #define - specifies log level */
/*
- CRITICAL = 0
- ERROR = 1
+ DEBUG = 0
+ INFO = 1
WARNING = 2
- INFO = 3
- DEBUG = 4
+ ERROR = 3
+ CRITICAL = 4
*/
-#define CROW_LOG_LEVEL 4 \ No newline at end of file
+#define CROW_LOG_LEVEL 0