diff --git a/main.cpp b/main.cpp index 019fdc6..d5f4ad5 100644 --- a/main.cpp +++ b/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 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) diff --git a/src/page.h b/src/page.h index dcfd252..4efdabf 100644 --- a/src/page.h +++ b/src/page.h @@ -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 {}; } diff --git a/src/tools.cpp b/src/tools.cpp index f742b59..d217351 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -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(value); + i += 2; + } + else + { + return false; + } + } + else + { + return false; + } + } + else if (in[i] == '+') + { + out += ' '; + } + else + { + out += in[i]; + } + } + return true; + } + + map + parse_crow_post_data(const string& req_body) + { + map body; + vector 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; + } } + diff --git a/src/tools.h b/src/tools.h index 81e603e..eeacf05 100644 --- a/src/tools.h +++ b/src/tools.h @@ -223,7 +223,11 @@ namespace xmreg rct::key & mask, uint64_t & amount); + bool + url_decode(const std::string& in, std::string& out); + map + parse_crow_post_data(const string& req_body); } #endif //XMREG01_TOOLS_H