|
|
@ -221,9 +221,7 @@ namespace client |
|
|
|
std::ostringstream response; |
|
|
|
std::ostringstream response; |
|
|
|
#if GCC47_BOOST149 |
|
|
|
#if GCC47_BOOST149 |
|
|
|
LogPrint (eLogError, "I2PControl: json_read is not supported due bug in boost 1.49 with gcc 4.7"); |
|
|
|
LogPrint (eLogError, "I2PControl: json_read is not supported due bug in boost 1.49 with gcc 4.7"); |
|
|
|
response << "{\"id\":null,\"error\":"; |
|
|
|
BuildErrorResponse(content, 32603, "JSON requests is not supported with this version of boost"); |
|
|
|
response << "{\"code\":-32603,\"message\":\"JSON requests is not supported with this version of boost\"},"; |
|
|
|
|
|
|
|
response << "\"jsonrpc\":\"2.0\"}"; |
|
|
|
|
|
|
|
#else |
|
|
|
#else |
|
|
|
boost::property_tree::ptree pt; |
|
|
|
boost::property_tree::ptree pt; |
|
|
|
boost::property_tree::read_json (ss, pt); |
|
|
|
boost::property_tree::read_json (ss, pt); |
|
|
@ -236,19 +234,18 @@ namespace client |
|
|
|
response << "{\"id\":" << id << ",\"result\":{"; |
|
|
|
response << "{\"id\":" << id << ",\"result\":{"; |
|
|
|
(this->*(it->second))(pt.get_child ("params"), response); |
|
|
|
(this->*(it->second))(pt.get_child ("params"), response); |
|
|
|
response << "},\"jsonrpc\":\"2.0\"}"; |
|
|
|
response << "},\"jsonrpc\":\"2.0\"}"; |
|
|
|
|
|
|
|
content = response.str(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
LogPrint (eLogWarning, "I2PControl: unknown method ", method); |
|
|
|
LogPrint (eLogWarning, "I2PControl: unknown method ", method); |
|
|
|
response << "{\"id\":null,\"error\":"; |
|
|
|
BuildErrorResponse(content, 32601, "Method not found"); |
|
|
|
response << "{\"code\":-32601,\"message\":\"Method not found\"},"; |
|
|
|
|
|
|
|
response << "\"jsonrpc\":\"2.0\"}"; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
content = response.str(); |
|
|
|
|
|
|
|
SendResponse (socket, buf, content, isHtml); |
|
|
|
SendResponse (socket, buf, content, isHtml); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (std::exception& ex) |
|
|
|
catch (std::exception& ex) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogError, "I2PControl: exception when handle request: ", ex.what ()); |
|
|
|
LogPrint (eLogError, "I2PControl: exception when handle request: ", ex.what ()); |
|
|
|
|
|
|
|
/* TODO: also send error, code 32603 */ |
|
|
|
} |
|
|
|
} |
|
|
|
catch (...) |
|
|
|
catch (...) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -276,6 +273,14 @@ namespace client |
|
|
|
ss << "\"" << name << "\":" << std::fixed << std::setprecision(2) << value; |
|
|
|
ss << "\"" << name << "\":" << std::fixed << std::setprecision(2) << value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void I2PControlService::BuildErrorResponse (std::string & content, int code, const char *message) { |
|
|
|
|
|
|
|
std::stringstream ss; |
|
|
|
|
|
|
|
ss << "{\"id\":null,\"error\":"; |
|
|
|
|
|
|
|
ss << "{\"code\":" << -code << ",\"message\":\"" << message << "\"},"; |
|
|
|
|
|
|
|
ss << "\"jsonrpc\":\"2.0\"}"; |
|
|
|
|
|
|
|
content = ss.str(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void I2PControlService::SendResponse (std::shared_ptr<ssl_socket> socket, |
|
|
|
void I2PControlService::SendResponse (std::shared_ptr<ssl_socket> socket, |
|
|
|
std::shared_ptr<I2PControlBuffer> buf, std::string& content, bool isHtml) |
|
|
|
std::shared_ptr<I2PControlBuffer> buf, std::string& content, bool isHtml) |
|
|
|
{ |
|
|
|
{ |
|
|
|