mirror of
https://git.wownero.com/wownero/onion-wownero-blockchain-explorer.git
synced 2024-08-15 00:33:12 +00:00
parse_crow_post_data function added
This commit is contained in:
parent
f6037bc33e
commit
2ebc9eda37
4 changed files with 86 additions and 9 deletions
19
main.cpp
19
main.cpp
|
@ -216,15 +216,18 @@ int main(int ac, const char* av[]) {
|
|||
|
||||
CROW_ROUTE(app, "/checkandpush").methods("POST"_method)
|
||||
([&](const crow::request& req) {
|
||||
//string rawtxdata = string(req.post().get("rawtxdata"));
|
||||
crow::query_string post_data(req.body);
|
||||
//cout << req.url_params.get("rawtxdata") << endl;
|
||||
cout << req.body << endl;
|
||||
//auto j = crow::json::load(req.body);
|
||||
//cout << req.get_header_value("rawtxdata") << endl;
|
||||
//cout << j["rawtxdata"] << endl;
|
||||
|
||||
return xmrblocks.show_checkandpushtx();
|
||||
map<std::string, std::string> post_body = xmreg::parse_crow_post_data(req.body);
|
||||
|
||||
if (post_body.count("rawtxdata") == 0 || post_body.count("action") == 0)
|
||||
{
|
||||
return string("Raw tx data or action not provided");
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -1529,8 +1529,12 @@ namespace xmreg {
|
|||
}
|
||||
|
||||
string
|
||||
show_checkandpushtx()
|
||||
show_checkandpushtx(string raw_tx_data, string action)
|
||||
{
|
||||
|
||||
cout << raw_tx_data << endl;
|
||||
cout << action << endl;
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -671,5 +671,71 @@ namespace xmreg
|
|||
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,
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue