1 #include "otsdaq/CgiDataUtilities/CgiDataUtilities.h"
2 #include "otsdaq/Macros/CoutMacros.h"
11 std::string CgiDataUtilities::getOrPostData(cgicc::Cgicc& cgi,
const std::string& needle)
13 std::string postData =
"";
14 if((postData = CgiDataUtilities::postData(cgi, needle)) ==
"")
15 postData = CgiDataUtilities::getData(cgi, needle);
24 std::string CgiDataUtilities::postData(cgicc::Cgicc& cgi,
const std::string& needle)
26 std::string postData =
"&" + cgi.getEnvironment().getPostData();
28 size_t start_pos = postData.find(
"&" + needle +
"=");
29 if(start_pos == std::string::npos)
32 size_t end_pos = postData.find(
'=', start_pos);
33 if(end_pos == std::string::npos)
36 start_pos += needle.length() + 2;
37 end_pos = postData.find(
'&', start_pos);
38 if(end_pos == std::string::npos)
43 return postData.substr(start_pos, end_pos - start_pos);
50 std::string CgiDataUtilities::getData(cgicc::Cgicc& cgi,
const std::string& needle)
52 std::string getData =
"&" + cgi.getEnvironment().getQueryString();
55 size_t start_pos = getData.find(
"&" + needle +
"=");
56 if(start_pos == std::string::npos)
59 size_t end_pos = getData.find(
'=', start_pos);
60 if(end_pos == std::string::npos)
63 start_pos += needle.length() + 2;
64 end_pos = getData.find(
'&', start_pos);
65 if(end_pos != std::string::npos)
72 return getData.substr(start_pos, end_pos);
76 int CgiDataUtilities::getOrPostDataAsInt(cgicc::Cgicc& cgi,
const std::string& needle) {
return atoi(getOrPostData(cgi, needle).c_str()); }
77 int CgiDataUtilities::postDataAsInt(cgicc::Cgicc& cgi,
const std::string& needle) {
return atoi(postData(cgi, needle).c_str()); }
78 int CgiDataUtilities::getDataAsInt(cgicc::Cgicc& cgi,
const std::string& needle) {
return atoi(getData(cgi, needle).c_str()); }