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(
25 std::string CgiDataUtilities::postData(cgicc::Cgicc& cgi,
const std::string& needle)
27 std::string postData =
"&" + cgi.getEnvironment().getPostData();
29 size_t start_pos = postData.find(
32 if(start_pos == std::string::npos)
35 size_t end_pos = postData.find(
'=', start_pos);
36 if(end_pos == std::string::npos)
39 start_pos += needle.length() + 2;
40 end_pos = postData.find(
'&', start_pos);
41 if(end_pos == std::string::npos)
46 return postData.substr(start_pos, end_pos - start_pos);
53 std::string CgiDataUtilities::getData(cgicc::Cgicc& cgi,
const std::string& needle)
55 std::string getData =
"&" + cgi.getEnvironment().getQueryString();
58 size_t start_pos = getData.find(
61 if(start_pos == std::string::npos)
64 size_t end_pos = getData.find(
'=', start_pos);
65 if(end_pos == std::string::npos)
68 start_pos += needle.length() + 2;
69 end_pos = getData.find(
'&', start_pos);
70 if(end_pos != std::string::npos)
77 return getData.substr(start_pos, end_pos);
81 int CgiDataUtilities::getOrPostDataAsInt(cgicc::Cgicc& cgi,
const std::string& needle)
83 return atoi(getOrPostData(cgi, needle).c_str());
85 int CgiDataUtilities::postDataAsInt(cgicc::Cgicc& cgi,
const std::string& needle)
87 return atoi(postData(cgi, needle).c_str());
89 int CgiDataUtilities::getDataAsInt(cgicc::Cgicc& cgi,
const std::string& needle)
91 return atoi(getData(cgi, needle).c_str());