aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorAntonio Juarez <antonio.maria.juarez@live.com>2014-04-02 17:00:17 +0100
committerAntonio Juarez <antonio.maria.juarez@live.com>2014-04-02 17:00:17 +0100
commit29c2859a3e8a935ef605534c6c36333894980d50 (patch)
tree1d31daa09741cc82ecc24c0c89f15b84e74cb12d /contrib
parentsome fixes (diff)
downloadmonero-29c2859a3e8a935ef605534c6c36333894980d50.tar.xz
json rpc for wallet and bugfix
Diffstat (limited to 'contrib')
-rw-r--r--contrib/epee/demo/demo_http_server/demo_http_server.cpp4
-rw-r--r--contrib/epee/include/console_handler.h4
-rw-r--r--contrib/epee/include/misc_log_ex.h3
-rw-r--r--contrib/epee/include/net/http_client.h2
-rw-r--r--contrib/epee/include/net/http_server_handlers_map2.h102
-rw-r--r--contrib/epee/include/net/net_utils_base.h6
-rw-r--r--contrib/epee/include/storages/http_abstract_invoke.h4
7 files changed, 102 insertions, 23 deletions
diff --git a/contrib/epee/demo/demo_http_server/demo_http_server.cpp b/contrib/epee/demo/demo_http_server/demo_http_server.cpp
index f614da6c5..fda53b9ad 100644
--- a/contrib/epee/demo/demo_http_server/demo_http_server.cpp
+++ b/contrib/epee/demo/demo_http_server/demo_http_server.cpp
@@ -42,10 +42,10 @@ bool communicate(const std::string url, t_request& req, t_response& rsp, const s
if(use_jrpc)
{
epee::json_rpc::request<t_request> req_t = AUTO_VAL_INIT(req_t);
- req_t.params = req;
+ req_t.jsonrpc = "2.0";
req_t.id = "10";
req_t.method = "command_example_1";
- req_t.version = "1.1";
+ req_t.params = req;
epee::json_rpc::response<t_response, std::string> resp_t = AUTO_VAL_INIT(resp_t);
if(!epee::net_utils::invoke_http_json_remote_command2("/request_json_rpc", req_t, resp_t, http_client))
{
diff --git a/contrib/epee/include/console_handler.h b/contrib/epee/include/console_handler.h
index 778679e75..65414a265 100644
--- a/contrib/epee/include/console_handler.h
+++ b/contrib/epee/include/console_handler.h
@@ -261,6 +261,7 @@ namespace epee
continue_handle = false;
break;
}
+ string_tools::trim(command);
LOG_PRINT_L2("Read command: " << command);
if(0 == command.compare("exit") || 0 == command.compare("q"))
@@ -281,7 +282,8 @@ namespace epee
continue;
}
log_space::get_set_log_detalisation_level(true, n);
- LOG_PRINT_L0("New log level set " << n);
+ std::cout << "New log level set " << n;
+ LOG_PRINT_L2("New log level set " << n);
}else if (command.empty())
{
continue;
diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h
index f2bd03b02..44f50afa2 100644
--- a/contrib/epee/include/misc_log_ex.h
+++ b/contrib/epee/include/misc_log_ex.h
@@ -1380,6 +1380,9 @@ POP_WARNINGS
#define LOG_PRINT_RED(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_red)
#define LOG_PRINT_GREEN(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_green)
#define LOG_PRINT_BLUE(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_blue)
+#define LOG_PRINT_YELLOW(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_yellow)
+#define LOG_PRINT_CYAN(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_cyan)
+#define LOG_PRINT_MAGENTA(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_magenta)
#define LOG_PRINT_RED_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_red)
diff --git a/contrib/epee/include/net/http_client.h b/contrib/epee/include/net/http_client.h
index 4a88c06ef..7e6b52d9c 100644
--- a/contrib/epee/include/net/http_client.h
+++ b/contrib/epee/include/net/http_client.h
@@ -801,7 +801,7 @@ using namespace std;
}else
{ //Apparently there are no signs of the form of transfer, will receive data until the connection is closed
m_state = reciev_machine_state_error;
- LOG_PRINT("Undefinded transfer type, consider http_body_transfer_connection_close method.", LOG_LEVEL_2);
+ LOG_PRINT("Undefinded transfer type, consider http_body_transfer_connection_close method. header: " << m_header_cache, LOG_LEVEL_2);
return false;
}
return false;
diff --git a/contrib/epee/include/net/http_server_handlers_map2.h b/contrib/epee/include/net/http_server_handlers_map2.h
index 80c32e3c5..0b6ffa095 100644
--- a/contrib/epee/include/net/http_server_handlers_map2.h
+++ b/contrib/epee/include/net/http_server_handlers_map2.h
@@ -118,15 +118,15 @@ namespace epee
template<typename t_param>
struct request
{
- std::string version;
+ std::string jsonrpc;
std::string method;
std::string id;
t_param params;
BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(version)
- KV_SERIALIZE(method)
+ KV_SERIALIZE(jsonrpc)
KV_SERIALIZE(id)
+ KV_SERIALIZE(method)
KV_SERIALIZE(params)
END_KV_SERIALIZE_MAP()
};
@@ -147,21 +147,54 @@ namespace epee
END_KV_SERIALIZE_MAP()
};
+ struct dummy_result
+ {
+ BEGIN_KV_SERIALIZE_MAP()
+ END_KV_SERIALIZE_MAP()
+ };
+
template<typename t_param, typename t_error>
struct response
{
+ std::string jsonrpc;
t_param result;
- t_error error;
std::string id;
-
+ t_error error;
BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(jsonrpc)
+ KV_SERIALIZE(id)
KV_SERIALIZE(result)
KV_SERIALIZE(error)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ template<typename t_param>
+ struct response<t_param, dummy_error>
+ {
+ std::string jsonrpc;
+ t_param result;
+ std::string id;
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(jsonrpc)
+ KV_SERIALIZE(id)
+ KV_SERIALIZE(result)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ template<typename t_error>
+ struct response<dummy_result, t_error>
+ {
+ std::string jsonrpc;
+ t_error error;
+ std::string id;
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(jsonrpc)
KV_SERIALIZE(id)
+ KV_SERIALIZE(error)
END_KV_SERIALIZE_MAP()
};
- typedef response<std::string, error> error_response;
+ typedef response<dummy_result, error> error_response;
}
}
@@ -184,6 +217,7 @@ namespace epee
if(!ps.get_value("method", callback_name, nullptr)) \
{ \
epee::json_rpc::error_response rsp; \
+ rsp.jsonrpc = "2.0"; \
rsp.error.code = -32600; \
rsp.error.message = "Invalid Request"; \
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(rsp), response_info.m_body); \
@@ -201,14 +235,45 @@ namespace epee
uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
boost::value_initialized<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> > resp_; \
epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error>& resp = static_cast<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> &>(resp_); \
+ resp.jsonrpc = "2.0"; \
resp.id = req.id; \
epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
+ fail_resp.jsonrpc = "2.0"; \
fail_resp.id = req.id; \
if(!callback_f(req.params, resp.result, fail_resp.error, m_conn_context)) \
+ { \
+ epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
+ return true; \
+ } \
+ uint64_t ticks2 = epee::misc_utils::get_tick_count(); \
+ epee::serialization::store_t_to_json(resp, response_info.m_body); \
+ uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
+ response_info.m_mime_tipe = "application/json"; \
+ response_info.m_header_info.m_content_type = " application/json"; \
+ LOG_PRINT( query_info.m_URI << "[" << method_name << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2); \
+ return true;\
+}
+
+#define MAP_JON_RPC_WERI(method_name, callback_f, command_type) \
+ else if(callback_name == method_name) \
{ \
- epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
- return true; \
-} \
+ handled = true; \
+ boost::value_initialized<epee::json_rpc::request<command_type::request> > req_; \
+ epee::json_rpc::request<command_type::request>& req = static_cast<epee::json_rpc::request<command_type::request>&>(req_);\
+ req.load(ps); \
+ uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
+ boost::value_initialized<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> > resp_; \
+ epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error>& resp = static_cast<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> &>(resp_); \
+ resp.jsonrpc = "2.0"; \
+ resp.id = req.id; \
+ epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
+ fail_resp.jsonrpc = "2.0"; \
+ fail_resp.id = req.id; \
+ if(!callback_f(req.params, resp.result, fail_resp.error, m_conn_context, response_info)) \
+ { \
+ epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
+ return true; \
+ } \
uint64_t ticks2 = epee::misc_utils::get_tick_count(); \
epee::serialization::store_t_to_json(resp, response_info.m_body); \
uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
@@ -229,16 +294,18 @@ namespace epee
uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
boost::value_initialized<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> > resp_; \
epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error>& resp = static_cast<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> &>(resp_); \
+ resp.jsonrpc = "2.0"; \
resp.id = req.id; \
if(!callback_f(req.params, resp.result, m_conn_context)) \
-{ \
- epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
- fail_resp.id = req.id; \
- fail_resp.error.code = -32603; \
- fail_resp.error.message = "Internal error"; \
- epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
- return true; \
-} \
+ { \
+ epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
+ fail_resp.jsonrpc = "2.0"; \
+ fail_resp.id = req.id; \
+ fail_resp.error.code = -32603; \
+ fail_resp.error.message = "Internal error"; \
+ epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
+ return true; \
+ } \
uint64_t ticks2 = epee::misc_utils::get_tick_count(); \
epee::serialization::store_t_to_json(resp, response_info.m_body); \
uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
@@ -251,6 +318,7 @@ namespace epee
#define END_JSON_RPC_MAP() \
epee::json_rpc::error_response rsp; \
+ rsp.jsonrpc = "2.0"; \
rsp.error.code = -32601; \
rsp.error.message = "Method not found"; \
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(rsp), response_info.m_body); \
diff --git a/contrib/epee/include/net/net_utils_base.h b/contrib/epee/include/net/net_utils_base.h
index 3afbbb119..793135b87 100644
--- a/contrib/epee/include/net/net_utils_base.h
+++ b/contrib/epee/include/net/net_utils_base.h
@@ -137,6 +137,9 @@ namespace net_utils
#define LOG_PRINT_CC_GREEN(ct, message, log_level) LOG_PRINT_GREEN("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
#define LOG_PRINT_CC_RED(ct, message, log_level) LOG_PRINT_RED("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
#define LOG_PRINT_CC_BLUE(ct, message, log_level) LOG_PRINT_BLUE("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
+#define LOG_PRINT_CC_YELLOW(ct, message, log_level) LOG_PRINT_YELLOW("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
+#define LOG_PRINT_CC_CYAN(ct, message, log_level) LOG_PRINT_CYAN("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
+#define LOG_PRINT_CC_MAGENTA(ct, message, log_level) LOG_PRINT_MAGENTA("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
#define LOG_ERROR_CC(ct, message) LOG_ERROR("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message)
#define LOG_PRINT_CC_L0(ct, message) LOG_PRINT_L0("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message)
@@ -154,6 +157,9 @@ namespace net_utils
#define LOG_PRINT_CCONTEXT_GREEN(message, log_level) LOG_PRINT_CC_GREEN(context, message, log_level)
#define LOG_PRINT_CCONTEXT_RED(message, log_level) LOG_PRINT_CC_RED(context, message, log_level)
#define LOG_PRINT_CCONTEXT_BLUE(message, log_level) LOG_PRINT_CC_BLUE(context, message, log_level)
+#define LOG_PRINT_CCONTEXT_YELLOW(message, log_level) LOG_PRINT_CC_YELLOW(context, message, log_level)
+#define LOG_PRINT_CCONTEXT_CYAN(message, log_level) LOG_PRINT_CC_CYAN(context, message, log_level)
+#define LOG_PRINT_CCONTEXT_MAGENTA(message, log_level) LOG_PRINT_CC_MAGENTA(context, message, log_level)
#define CHECK_AND_ASSERT_MES_CC(condition, return_val, err_message) CHECK_AND_ASSERT_MES(condition, return_val, "[" << epee::net_utils::print_connection_context_short(context) << "]" << err_message)
diff --git a/contrib/epee/include/storages/http_abstract_invoke.h b/contrib/epee/include/storages/http_abstract_invoke.h
index 07720f496..00ee8a4ad 100644
--- a/contrib/epee/include/storages/http_abstract_invoke.h
+++ b/contrib/epee/include/storages/http_abstract_invoke.h
@@ -98,10 +98,10 @@ namespace epee
bool invoke_http_json_rpc(const std::string& url, const std::string& method_name, t_request& out_struct, t_response& result_struct, t_transport& transport, unsigned int timeout = 5000, const std::string& http_method = "GET", const std::string& req_id = "0")
{
epee::json_rpc::request<t_request> req_t = AUTO_VAL_INIT(req_t);
- req_t.params = out_struct;
+ req_t.jsonrpc = "2.0";
req_t.id = req_id;
req_t.method = method_name;
- req_t.version = "2.0";
+ req_t.params = out_struct;
epee::json_rpc::response<t_response, epee::json_rpc::error> resp_t = AUTO_VAL_INIT(resp_t);
if(!epee::net_utils::invoke_http_json_remote_command2(url, req_t, resp_t, transport, timeout, http_method))
{