-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHttpServerHelpers.cpp
66 lines (56 loc) · 1.57 KB
/
HttpServerHelpers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "HttpServerHelpers.h"
#include "Logger.h"
#include <cstdio>
#ifdef _MSC_VER
#pragma warning( disable : 4996 ) // warning C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead.
#endif
std::string HttpServerHelpers::url_decode(const std::string& value)
{
const size_t len = value.length();
std::string result;
result.reserve(len);
for (size_t i = 0; i < len; ++i)
{
if (value[i] == '+')
{
result += ' ';
continue;
}
if (value[i] == '%' && i < len - 2)
{
char buf[] = { value[i + 1], value[i + 2], '\0' };
int number = 0;
if (EOF != std::sscanf(buf, "%x", &number))
{
result += static_cast<char>(number);
i += 2;
continue;
}
}
result += value[i];
}
return result;
}
void HttpServerHelpers::LogHandler::log(std::string message, crow::LogLevel level)
{
Logger::LogLevel newLevel = Logger::LogLevel::Critical;
switch (level)
{
case crow::LogLevel::Debug:
newLevel = Logger::LogLevel::Debug;
break;
case crow::LogLevel::Info:
newLevel = Logger::LogLevel::Info;
break;
case crow::LogLevel::Warning:
newLevel = Logger::LogLevel::Warning;
break;
case crow::LogLevel::Error:
newLevel = Logger::LogLevel::Error;
break;
case crow::LogLevel::Critical:
newLevel = Logger::LogLevel::Critical;
break;
}
Logger::log(message, newLevel);
}