-
Notifications
You must be signed in to change notification settings - Fork 10
/
basecgi.cpp
92 lines (74 loc) · 2.25 KB
/
basecgi.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "basecgi.h"
const std::string BaseCgi::m_emptyString;
BaseCgi::BaseCgi()
{
}
BaseCgi::~BaseCgi()
{
}
void BaseCgi::Process(const HttpMessage * ptHttpMessage, int & respondCode, std::string & sRespMsg, std::string & sContentType, std::string & sRespBoby)
{
m_ptHttpMessage = ptHttpMessage;
respondCode = 200;
sRespMsg.assign("OK", 2);
sContentType.assign("text/html", 9);
ProcessImp(respondCode, sRespMsg, sContentType, sRespBoby);
}
const std::string & BaseCgi::GetUrl()
{
return m_ptHttpMessage->GetUrl();
}
const std::string & BaseCgi::GetBody()
{
return m_ptHttpMessage->GetBody();
}
int32_t BaseCgi::GetInt32withDefault(const char * keyName, int32_t defaultValue /* = 0 */)
{
const HeadMapType & headContentMap = m_ptHttpMessage->GetHeadContent();
HeadMapTypeConstIter iter = headContentMap.find(keyName);
if (headContentMap.end() == iter)
{
return defaultValue;
}
return (std::stoi(iter->second));
}
int64_t BaseCgi::GetInt64withDefault(const char * keyName, int64_t defaultValue /* = 0 */)
{
const HeadMapType & headContentMap = m_ptHttpMessage->GetHeadContent();
HeadMapTypeConstIter iter = headContentMap.find(keyName);
if (headContentMap.end() == iter)
{
return defaultValue;
}
return (static_cast<int64_t>(std::stoll(iter->second)));
}
uint32_t BaseCgi::GetUint32withDefault(const char * keyName, uint32_t defaultValue /* = 0 */)
{
const HeadMapType & headContentMap = m_ptHttpMessage->GetHeadContent();
HeadMapTypeConstIter iter = headContentMap.find(keyName);
if (headContentMap.end() == iter)
{
return defaultValue;
}
return (static_cast<uint32_t>(std::stoul(iter->second)));
}
uint64_t BaseCgi::GetUint64withDefault(const char * keyName, uint64_t defaultValue /* = 0 */)
{
const HeadMapType & headContentMap = m_ptHttpMessage->GetHeadContent();
HeadMapTypeConstIter iter = headContentMap.find(keyName);
if (headContentMap.end() == iter)
{
return defaultValue;
}
return (static_cast<uint64_t>(std::stoull(iter->second)));
}
const std::string & BaseCgi::GetStringValue(const char * keyName)
{
const HeadMapType & headContentMap = m_ptHttpMessage->GetHeadContent();
HeadMapTypeConstIter iter = headContentMap.find(keyName);
if (headContentMap.end() == iter)
{
return m_emptyString;
}
return (iter->second);
}