parse_crow_post_data function added

master
moneroexamples 8 years ago
parent f6037bc33e
commit 2ebc9eda37

@ -216,15 +216,18 @@ int main(int ac, const char* av[]) {
CROW_ROUTE(app, "/checkandpush").methods("POST"_method) CROW_ROUTE(app, "/checkandpush").methods("POST"_method)
([&](const crow::request& req) { ([&](const crow::request& req) {
//string rawtxdata = string(req.post().get("rawtxdata"));
crow::query_string post_data(req.body); map<std::string, std::string> post_body = xmreg::parse_crow_post_data(req.body);
//cout << req.url_params.get("rawtxdata") << endl;
cout << req.body << endl; if (post_body.count("rawtxdata") == 0 || post_body.count("action") == 0)
//auto j = crow::json::load(req.body); {
//cout << req.get_header_value("rawtxdata") << endl; return string("Raw tx data or action not provided");
//cout << j["rawtxdata"] << endl; }
return xmrblocks.show_checkandpushtx(); string raw_tx_data = post_body["rawtxdata"];
string action = post_body["action"];
return xmrblocks.show_checkandpushtx(raw_tx_data, action);
}); });
CROW_ROUTE(app, "/search").methods("GET"_method) CROW_ROUTE(app, "/search").methods("GET"_method)

@ -1529,8 +1529,12 @@ namespace xmreg {
} }
string string
show_checkandpushtx() show_checkandpushtx(string raw_tx_data, string action)
{ {
cout << raw_tx_data << endl;
cout << action << endl;
return {}; return {};
} }

@ -671,5 +671,71 @@ namespace xmreg
return true; return true;
} }
bool
url_decode(const std::string& in, std::string& out)
{
out.clear();
out.reserve(in.size());
for (std::size_t i = 0; i < in.size(); ++i)
{
if (in[i] == '%')
{
if (i + 3 <= in.size())
{
int value = 0;
std::istringstream is(in.substr(i + 1, 2));
if (is >> std::hex >> value)
{
out += static_cast<char>(value);
i += 2;
}
else
{
return false;
}
}
else
{
return false;
}
}
else if (in[i] == '+')
{
out += ' ';
}
else
{
out += in[i];
}
}
return true;
}
map<std::string, std::string>
parse_crow_post_data(const string& req_body)
{
map<std::string, std::string> body;
vector<string> vec;
string tmp;
bool result = url_decode(req_body, tmp);
if (result)
{
boost::algorithm::split(vec, tmp, [](char x) {return x == '&'; });
for(auto &it : vec)
{
auto pos = it.find("=");
if (pos != string::npos)
{
body[it.substr(0, pos)] = it.substr(pos + 1);
}
else
{
break;
}
}
}
return body;
}
} }

@ -223,7 +223,11 @@ namespace xmreg
rct::key & mask, rct::key & mask,
uint64_t & amount); uint64_t & amount);
bool
url_decode(const std::string& in, std::string& out);
map<std::string, std::string>
parse_crow_post_data(const string& req_body);
} }
#endif //XMREG01_TOOLS_H #endif //XMREG01_TOOLS_H

Loading…
Cancel
Save