Electroneum
Loading...
Searching...
No Matches
http_server_handlers_map2.h File Reference
Include dependency graph for http_server_handlers_map2.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ELECTRONEUM_DEFAULT_LOG_CATEGORY   "net.http"
#define CHAIN_HTTP_TO_MAP2(context_type)
#define BEGIN_URI_MAP2()
#define MAP_URI2(pattern, callback)
#define MAP_URI_AUTO_XML2(s_pattern, callback_f, command_type)
#define MAP_URI_AUTO_JON2_IF(s_pattern, callback_f, command_type, cond)
#define MAP_URI_AUTO_JON2(s_pattern, callback_f, command_type)
#define MAP_URI_AUTO_BIN2(s_pattern, callback_f, command_type)
#define CHAIN_URI_MAP2(callback)
#define END_URI_MAP2()
#define BEGIN_JSON_RPC_MAP(uri)
#define PREPARE_OBJECTS_FROM_JSON(command_type)
#define FINALIZE_OBJECTS_TO_JSON(method_name)
#define MAP_JON_RPC_WE_IF(method_name, callback_f, command_type, cond)
#define MAP_JON_RPC_WE(method_name, callback_f, command_type)
#define MAP_JON_RPC_WERI(method_name, callback_f, command_type)
#define MAP_JON_RPC(method_name, callback_f, command_type)
#define END_JSON_RPC_MAP()

Macro Definition Documentation

◆ BEGIN_JSON_RPC_MAP

#define BEGIN_JSON_RPC_MAP ( uri)
Value:
else if(query_info.m_URI == uri) \
{ \
if(!ps.load_from_json(query_info.m_body)) \
{ \
boost::value_initialized<epee::json_rpc::error_response> rsp; \
static_cast<epee::json_rpc::error_response&>(rsp).jsonrpc = "2.0"; \
static_cast<epee::json_rpc::error_response&>(rsp).error.code = -32700; \
static_cast<epee::json_rpc::error_response&>(rsp).error.message = "Parse error"; \
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(rsp), response_info.m_body); \
return true; \
} \
id_ = epee::serialization::storage_entry(std::string()); \
ps.get_value("id", id_, nullptr); \
std::string callback_name; \
if(!ps.get_value("method", callback_name, nullptr)) \
{ \
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); \
return true; \
} \
if(false) return true;
bool get_value(const std::string &value_name, t_value &val, hsection hparent_section)
bool load_from_json(const std::string &source)
response< dummy_result, error > error_response
uint64_t get_tick_count()
boost::variant< uint64_t, uint32_t, uint16_t, uint8_t, int64_t, int32_t, int16_t, int8_t, double, bool, std::string, section, array_entry > storage_entry
#define true
unsigned __int64 uint64_t
Definition stdint.h:136

Definition at line 120 of file http_server_handlers_map2.h.

120#define BEGIN_JSON_RPC_MAP(uri) else if(query_info.m_URI == uri) \
121 { \
122 uint64_t ticks = epee::misc_utils::get_tick_count(); \
123 epee::serialization::portable_storage ps; \
124 if(!ps.load_from_json(query_info.m_body)) \
125 { \
126 boost::value_initialized<epee::json_rpc::error_response> rsp; \
127 static_cast<epee::json_rpc::error_response&>(rsp).jsonrpc = "2.0"; \
128 static_cast<epee::json_rpc::error_response&>(rsp).error.code = -32700; \
129 static_cast<epee::json_rpc::error_response&>(rsp).error.message = "Parse error"; \
130 epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(rsp), response_info.m_body); \
131 return true; \
132 } \
133 epee::serialization::storage_entry id_; \
134 id_ = epee::serialization::storage_entry(std::string()); \
135 ps.get_value("id", id_, nullptr); \
136 std::string callback_name; \
137 if(!ps.get_value("method", callback_name, nullptr)) \
138 { \
139 epee::json_rpc::error_response rsp; \
140 rsp.jsonrpc = "2.0"; \
141 rsp.error.code = -32600; \
142 rsp.error.message = "Invalid Request"; \
143 epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(rsp), response_info.m_body); \
144 return true; \
145 } \
146 if(false) return true; //just a stub to have "else if"

◆ BEGIN_URI_MAP2

#define BEGIN_URI_MAP2 ( )
Value:
template<class t_context> bool handle_http_request_map(const epee::net_utils::http::http_request_info& query_info, \
t_context& m_conn_context) { \
bool handled = false; \
if(false) return true;

Definition at line 51 of file http_server_handlers_map2.h.

51#define BEGIN_URI_MAP2() template<class t_context> bool handle_http_request_map(const epee::net_utils::http::http_request_info& query_info, \
52 epee::net_utils::http::http_response_info& response_info, \
53 t_context& m_conn_context) { \
54 bool handled = false; \
55 if(false) return true; //just a stub to have "else if"

◆ CHAIN_HTTP_TO_MAP2

#define CHAIN_HTTP_TO_MAP2 ( context_type)
Value:
bool handle_http_request(const epee::net_utils::http::http_request_info& query_info, \
context_type& m_conn_context) \
{\
MINFO("HTTP [" << m_conn_context.m_remote_address.host_str() << "] " << query_info.m_http_method_str << " " << query_info.m_URI); \
response.m_response_code = 200; \
response.m_response_comment = "Ok"; \
if(!handle_http_request_map(query_info, response, m_conn_context)) \
{response.m_response_code = 404;response.m_response_comment = "Not found";} \
return true; \
}

Definition at line 38 of file http_server_handlers_map2.h.

38#define CHAIN_HTTP_TO_MAP2(context_type) bool handle_http_request(const epee::net_utils::http::http_request_info& query_info, \
39 epee::net_utils::http::http_response_info& response, \
40 context_type& m_conn_context) \
41{\
42 MINFO("HTTP [" << m_conn_context.m_remote_address.host_str() << "] " << query_info.m_http_method_str << " " << query_info.m_URI); \
43 response.m_response_code = 200; \
44 response.m_response_comment = "Ok"; \
45 if(!handle_http_request_map(query_info, response, m_conn_context)) \
46 {response.m_response_code = 404;response.m_response_comment = "Not found";} \
47 return true; \
48}

◆ CHAIN_URI_MAP2

#define CHAIN_URI_MAP2 ( callback)
Value:
else {callback(query_info, response_info, m_conn_context);handled = true;}

Definition at line 115 of file http_server_handlers_map2.h.

◆ ELECTRONEUM_DEFAULT_LOG_CATEGORY

#define ELECTRONEUM_DEFAULT_LOG_CATEGORY   "net.http"

Definition at line 35 of file http_server_handlers_map2.h.

◆ END_JSON_RPC_MAP

#define END_JSON_RPC_MAP ( )
Value:
rsp.id = id_; \
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); \
return true; \
}
epee::serialization::storage_entry id

Definition at line 232 of file http_server_handlers_map2.h.

232#define END_JSON_RPC_MAP() \
233 epee::json_rpc::error_response rsp; \
234 rsp.id = id_; \
235 rsp.jsonrpc = "2.0"; \
236 rsp.error.code = -32601; \
237 rsp.error.message = "Method not found"; \
238 epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(rsp), response_info.m_body); \
239 return true; \
240}

◆ END_URI_MAP2

#define END_URI_MAP2 ( )
Value:
return handled;}

Definition at line 117 of file http_server_handlers_map2.h.

◆ FINALIZE_OBJECTS_TO_JSON

#define FINALIZE_OBJECTS_TO_JSON ( method_name)
Value:
epee::serialization::store_t_to_json(resp, response_info.m_body); \
response_info.m_mime_tipe = "application/json"; \
response_info.m_header_info.m_content_type = " application/json"; \
MDEBUG( query_info.m_URI << "[" << method_name << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms");

Definition at line 169 of file http_server_handlers_map2.h.

169#define FINALIZE_OBJECTS_TO_JSON(method_name) \
170 uint64_t ticks2 = epee::misc_utils::get_tick_count(); \
171 epee::serialization::store_t_to_json(resp, response_info.m_body); \
172 uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
173 response_info.m_mime_tipe = "application/json"; \
174 response_info.m_header_info.m_content_type = " application/json"; \
175 MDEBUG( query_info.m_URI << "[" << method_name << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms");

◆ MAP_JON_RPC

#define MAP_JON_RPC ( method_name,
callback_f,
command_type )
Value:
else if(callback_name == method_name) \
{ \
PREPARE_OBJECTS_FROM_JSON(command_type) \
MINFO(m_conn_context << "calling RPC method " << method_name); \
if(!callback_f(req.params, resp.result, &m_conn_context)) \
{ \
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; \
} \
FINALIZE_OBJECTS_TO_JSON(method_name) \
return true;\
}
#define AUTO_VAL_INIT(v)

Definition at line 213 of file http_server_handlers_map2.h.

213#define MAP_JON_RPC(method_name, callback_f, command_type) \
214 else if(callback_name == method_name) \
215{ \
216 PREPARE_OBJECTS_FROM_JSON(command_type) \
217 MINFO(m_conn_context << "calling RPC method " << method_name); \
218 if(!callback_f(req.params, resp.result, &m_conn_context)) \
219 { \
220 epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
221 fail_resp.jsonrpc = "2.0"; \
222 fail_resp.id = req.id; \
223 fail_resp.error.code = -32603; \
224 fail_resp.error.message = "Internal error"; \
225 epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
226 return true; \
227 } \
228 FINALIZE_OBJECTS_TO_JSON(method_name) \
229 return true;\
230}

◆ MAP_JON_RPC_WE

#define MAP_JON_RPC_WE ( method_name,
callback_f,
command_type )
Value:
MAP_JON_RPC_WE_IF(method_name, callback_f, command_type, true)
#define MAP_JON_RPC_WE_IF(method_name, callback_f, command_type, cond)

Definition at line 194 of file http_server_handlers_map2.h.

◆ MAP_JON_RPC_WE_IF

#define MAP_JON_RPC_WE_IF ( method_name,
callback_f,
command_type,
cond )
Value:
else if((callback_name == method_name) && (cond)) \
{ \
PREPARE_OBJECTS_FROM_JSON(command_type) \
fail_resp.jsonrpc = "2.0"; \
fail_resp.id = req.id; \
MINFO(m_conn_context << "Calling RPC method " << method_name); \
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; \
} \
FINALIZE_OBJECTS_TO_JSON(method_name) \
return true;\
}

Definition at line 177 of file http_server_handlers_map2.h.

177#define MAP_JON_RPC_WE_IF(method_name, callback_f, command_type, cond) \
178 else if((callback_name == method_name) && (cond)) \
179{ \
180 PREPARE_OBJECTS_FROM_JSON(command_type) \
181 epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
182 fail_resp.jsonrpc = "2.0"; \
183 fail_resp.id = req.id; \
184 MINFO(m_conn_context << "Calling RPC method " << method_name); \
185 if(!callback_f(req.params, resp.result, fail_resp.error, &m_conn_context)) \
186 { \
187 epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
188 return true; \
189 } \
190 FINALIZE_OBJECTS_TO_JSON(method_name) \
191 return true;\
192}

◆ MAP_JON_RPC_WERI

#define MAP_JON_RPC_WERI ( method_name,
callback_f,
command_type )
Value:
else if(callback_name == method_name) \
{ \
PREPARE_OBJECTS_FROM_JSON(command_type) \
fail_resp.jsonrpc = "2.0"; \
fail_resp.id = req.id; \
MINFO(m_conn_context << "calling RPC method " << method_name); \
if(!callback_f(req.params, resp.result, fail_resp.error, response_info, &m_conn_context)) \
{ \
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
return true; \
} \
FINALIZE_OBJECTS_TO_JSON(method_name) \
return true;\
}

Definition at line 196 of file http_server_handlers_map2.h.

196#define MAP_JON_RPC_WERI(method_name, callback_f, command_type) \
197 else if(callback_name == method_name) \
198{ \
199 PREPARE_OBJECTS_FROM_JSON(command_type) \
200 epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
201 fail_resp.jsonrpc = "2.0"; \
202 fail_resp.id = req.id; \
203 MINFO(m_conn_context << "calling RPC method " << method_name); \
204 if(!callback_f(req.params, resp.result, fail_resp.error, response_info, &m_conn_context)) \
205 { \
206 epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
207 return true; \
208 } \
209 FINALIZE_OBJECTS_TO_JSON(method_name) \
210 return true;\
211}

◆ MAP_URI2

#define MAP_URI2 ( pattern,
callback )
Value:
else if(std::string::npos != query_info.m_URI.find(pattern)) return callback(query_info, response_info, &m_conn_context);

Definition at line 57 of file http_server_handlers_map2.h.

◆ MAP_URI_AUTO_BIN2

#define MAP_URI_AUTO_BIN2 ( s_pattern,
callback_f,
command_type )
Value:
else if(query_info.m_URI == s_pattern) \
{ \
handled = true; \
uint64_t ticks = misc_utils::get_tick_count(); \
boost::value_initialized<command_type::request> req; \
bool parse_res = epee::serialization::load_t_from_binary(static_cast<command_type::request&>(req), epee::strspan<uint8_t>(query_info.m_body)); \
CHECK_AND_ASSERT_MES(parse_res, false, "Failed to parse bin body data, body size=" << query_info.m_body.size()); \
uint64_t ticks1 = misc_utils::get_tick_count(); \
boost::value_initialized<command_type::response> resp;\
MINFO(m_conn_context << "calling " << s_pattern); \
if(!callback_f(static_cast<command_type::request&>(req), static_cast<command_type::response&>(resp), &m_conn_context)) \
{ \
LOG_ERROR("Failed to " << #callback_f << "()"); \
response_info.m_response_code = 500; \
response_info.m_response_comment = "Internal Server Error"; \
return true; \
} \
uint64_t ticks2 = misc_utils::get_tick_count(); \
epee::serialization::store_t_to_binary(static_cast<command_type::response&>(resp), response_info.m_body); \
response_info.m_mime_tipe = " application/octet-stream"; \
response_info.m_header_info.m_content_type = " application/octet-stream"; \
MDEBUG( s_pattern << "() processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms"); \
}
bool load_t_from_binary(t_struct &out, const epee::span< const uint8_t > binary_buff)
span< const T > strspan(const std::string &s) noexcept
make a span from a std::string
Definition span.h:171

Definition at line 89 of file http_server_handlers_map2.h.

89#define MAP_URI_AUTO_BIN2(s_pattern, callback_f, command_type) \
90 else if(query_info.m_URI == s_pattern) \
91 { \
92 handled = true; \
93 uint64_t ticks = misc_utils::get_tick_count(); \
94 boost::value_initialized<command_type::request> req; \
95 bool parse_res = epee::serialization::load_t_from_binary(static_cast<command_type::request&>(req), epee::strspan<uint8_t>(query_info.m_body)); \
96 CHECK_AND_ASSERT_MES(parse_res, false, "Failed to parse bin body data, body size=" << query_info.m_body.size()); \
97 uint64_t ticks1 = misc_utils::get_tick_count(); \
98 boost::value_initialized<command_type::response> resp;\
99 MINFO(m_conn_context << "calling " << s_pattern); \
100 if(!callback_f(static_cast<command_type::request&>(req), static_cast<command_type::response&>(resp), &m_conn_context)) \
101 { \
102 LOG_ERROR("Failed to " << #callback_f << "()"); \
103 response_info.m_response_code = 500; \
104 response_info.m_response_comment = "Internal Server Error"; \
105 return true; \
106 } \
107 uint64_t ticks2 = misc_utils::get_tick_count(); \
108 epee::serialization::store_t_to_binary(static_cast<command_type::response&>(resp), response_info.m_body); \
109 uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
110 response_info.m_mime_tipe = " application/octet-stream"; \
111 response_info.m_header_info.m_content_type = " application/octet-stream"; \
112 MDEBUG( s_pattern << "() processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms"); \
113 }

◆ MAP_URI_AUTO_JON2

#define MAP_URI_AUTO_JON2 ( s_pattern,
callback_f,
command_type )
Value:
MAP_URI_AUTO_JON2_IF(s_pattern, callback_f, command_type, true)
#define MAP_URI_AUTO_JON2_IF(s_pattern, callback_f, command_type, cond)

Definition at line 87 of file http_server_handlers_map2.h.

◆ MAP_URI_AUTO_JON2_IF

#define MAP_URI_AUTO_JON2_IF ( s_pattern,
callback_f,
command_type,
cond )
Value:
else if((query_info.m_URI == s_pattern) && (cond)) \
{ \
handled = true; \
uint64_t ticks = misc_utils::get_tick_count(); \
boost::value_initialized<command_type::request> req; \
bool parse_res = epee::serialization::load_t_from_json(static_cast<command_type::request&>(req), query_info.m_body); \
CHECK_AND_ASSERT_MES(parse_res, false, "Failed to parse json: \r\n" << query_info.m_body); \
boost::value_initialized<command_type::response> resp;\
MINFO(m_conn_context << "calling " << s_pattern); \
if(!callback_f(static_cast<command_type::request&>(req), static_cast<command_type::response&>(resp), &m_conn_context)) \
{ \
LOG_ERROR("Failed to " << #callback_f << "()"); \
response_info.m_response_code = 500; \
response_info.m_response_comment = "Internal Server Error"; \
return true; \
} \
epee::serialization::store_t_to_json(static_cast<command_type::response&>(resp), response_info.m_body); \
response_info.m_mime_tipe = "application/json"; \
response_info.m_header_info.m_content_type = " application/json"; \
MDEBUG( s_pattern << " processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms"); \
}
bool load_t_from_json(t_struct &out, const std::string &json_buff)

Definition at line 61 of file http_server_handlers_map2.h.

61#define MAP_URI_AUTO_JON2_IF(s_pattern, callback_f, command_type, cond) \
62 else if((query_info.m_URI == s_pattern) && (cond)) \
63 { \
64 handled = true; \
65 uint64_t ticks = misc_utils::get_tick_count(); \
66 boost::value_initialized<command_type::request> req; \
67 bool parse_res = epee::serialization::load_t_from_json(static_cast<command_type::request&>(req), query_info.m_body); \
68 CHECK_AND_ASSERT_MES(parse_res, false, "Failed to parse json: \r\n" << query_info.m_body); \
69 uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
70 boost::value_initialized<command_type::response> resp;\
71 MINFO(m_conn_context << "calling " << s_pattern); \
72 if(!callback_f(static_cast<command_type::request&>(req), static_cast<command_type::response&>(resp), &m_conn_context)) \
73 { \
74 LOG_ERROR("Failed to " << #callback_f << "()"); \
75 response_info.m_response_code = 500; \
76 response_info.m_response_comment = "Internal Server Error"; \
77 return true; \
78 } \
79 uint64_t ticks2 = epee::misc_utils::get_tick_count(); \
80 epee::serialization::store_t_to_json(static_cast<command_type::response&>(resp), response_info.m_body); \
81 uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
82 response_info.m_mime_tipe = "application/json"; \
83 response_info.m_header_info.m_content_type = " application/json"; \
84 MDEBUG( s_pattern << " processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms"); \
85 }

◆ MAP_URI_AUTO_XML2

#define MAP_URI_AUTO_XML2 ( s_pattern,
callback_f,
command_type )

Definition at line 59 of file http_server_handlers_map2.h.

◆ PREPARE_OBJECTS_FROM_JSON

#define PREPARE_OBJECTS_FROM_JSON ( command_type)
Value:
handled = true; \
boost::value_initialized<epee::json_rpc::request<command_type::request> > req_; \
if(!req.load(ps)) \
{ \
fail_resp.jsonrpc = "2.0"; \
fail_resp.id = req.id; \
fail_resp.error.code = -32602; \
fail_resp.error.message = "Invalid params"; \
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
return true; \
} \
boost::value_initialized<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> > resp_; \
resp.jsonrpc = "2.0"; \
resp.id = req.id;
epee::serialization::storage_entry id

Definition at line 149 of file http_server_handlers_map2.h.

149#define PREPARE_OBJECTS_FROM_JSON(command_type) \
150 handled = true; \
151 boost::value_initialized<epee::json_rpc::request<command_type::request> > req_; \
152 epee::json_rpc::request<command_type::request>& req = static_cast<epee::json_rpc::request<command_type::request>&>(req_);\
153 if(!req.load(ps)) \
154 { \
155 epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
156 fail_resp.jsonrpc = "2.0"; \
157 fail_resp.id = req.id; \
158 fail_resp.error.code = -32602; \
159 fail_resp.error.message = "Invalid params"; \
160 epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
161 return true; \
162 } \
163 uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
164 boost::value_initialized<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> > resp_; \
165 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_); \
166 resp.jsonrpc = "2.0"; \
167 resp.id = req.id;