diff options
Diffstat (limited to 'contrib/epee/include')
-rw-r--r-- | contrib/epee/include/console_handler.h | 17 | ||||
-rw-r--r-- | contrib/epee/include/net/abstract_tcp_server2.inl | 4 | ||||
-rw-r--r-- | contrib/epee/include/net/http_protocol_handler.h | 45 | ||||
-rw-r--r-- | contrib/epee/include/net/http_server_handlers_map2.h | 99 | ||||
-rw-r--r-- | contrib/epee/include/net/net_utils_base.h | 17 | ||||
-rw-r--r-- | contrib/epee/include/profile_tools.h | 10 | ||||
-rw-r--r-- | contrib/epee/include/serialization/keyvalue_serialization.h | 6 | ||||
-rw-r--r-- | contrib/epee/include/storages/portable_storage.h | 24 | ||||
-rw-r--r-- | contrib/epee/include/storages/portable_storage_template_helper.h | 11 | ||||
-rw-r--r-- | contrib/epee/include/storages/portable_storage_to_json.h | 59 | ||||
-rw-r--r-- | contrib/epee/include/string_tools.h | 1 |
11 files changed, 101 insertions, 192 deletions
diff --git a/contrib/epee/include/console_handler.h b/contrib/epee/include/console_handler.h index 5798d2def..fcab35aaa 100644 --- a/contrib/epee/include/console_handler.h +++ b/contrib/epee/include/console_handler.h @@ -267,23 +267,6 @@ namespace epee if(0 == command.compare("exit") || 0 == command.compare("q")) { continue_handle = false; - }else if (!command.compare(0, 7, "set_log")) - { - //parse set_log command - if(command.size() != 9) - { - std::cout << "wrong syntax: " << command << std::endl << "use set_log n" << std::endl; - continue; - } - uint16_t n = 0; - if(!string_tools::get_xtype_from_string(n, command.substr(8, 1))) - { - std::cout << "wrong syntax: " << command << std::endl << "use set_log n" << std::endl; - continue; - } - log_space::get_set_log_detalisation_level(true, 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/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl index 2a4b10e48..403f5a3bd 100644 --- a/contrib/epee/include/net/abstract_tcp_server2.inl +++ b/contrib/epee/include/net/abstract_tcp_server2.inl @@ -52,11 +52,11 @@ PRAGMA_WARNING_DISABLE_VS(4355) typename t_protocol_handler::config_type& config, volatile uint32_t& sock_count, i_connection_filter* &pfilter) : strand_(io_service), socket_(io_service), - m_protocol_handler(this, config, context), m_want_close_connection(0), m_was_shutdown(0), m_ref_sockets_count(sock_count), - m_pfilter(pfilter) + m_pfilter(pfilter), + m_protocol_handler(this, config, context) { boost::interprocess::ipcdetail::atomic_inc32(&m_ref_sockets_count); } diff --git a/contrib/epee/include/net/http_protocol_handler.h b/contrib/epee/include/net/http_protocol_handler.h index 4bf48750e..aed909778 100644 --- a/contrib/epee/include/net/http_protocol_handler.h +++ b/contrib/epee/include/net/http_protocol_handler.h @@ -55,20 +55,20 @@ namespace net_utils /************************************************************************/ /* */ /************************************************************************/ - template<class t_connection_context = net_utils::connection_context_base> + template<class t_connection_context = net_utils::connection_context_base> class simple_http_connection_handler { public: - typedef t_connection_context connection_context;//t_connection_context net_utils::connection_context_base connection_context; + typedef t_connection_context connection_context;//t_connection_context net_utils::connection_context_base connection_context; typedef http_server_config config_type; simple_http_connection_handler(i_service_endpoint* psnd_hndlr, config_type& config); virtual ~simple_http_connection_handler(){} - bool release_protocol() - { - return true; - } + bool release_protocol() + { + return true; + } virtual bool thread_init() { @@ -85,10 +85,6 @@ namespace net_utils } virtual bool handle_recv(const void* ptr, size_t cb); virtual bool handle_request(const http::http_request_info& query_info, http_response_info& response); - - - //temporary here - //bool parse_uri(const std::string uri, uri_content& content); private: enum machine_state{ @@ -142,34 +138,37 @@ namespace net_utils i_service_endpoint* m_psnd_hndlr; }; - template<class t_connection_context> + template<class t_connection_context> struct i_http_server_handler { virtual ~i_http_server_handler(){} - virtual bool handle_http_request(const http_request_info& query_info, http_response_info& response, t_connection_context& m_conn_context)=0; - virtual bool init_server_thread(){return true;} + virtual bool handle_http_request(const http_request_info& query_info, + http_response_info& response, + t_connection_context& m_conn_context) = 0; + virtual bool init_server_thread(){return true;} virtual bool deinit_server_thread(){return true;} }; - template<class t_connection_context> + template<class t_connection_context> struct custum_handler_config: public http_server_config { i_http_server_handler<t_connection_context>* m_phandler; }; - /************************************************************************/ - /* */ - /************************************************************************/ + /************************************************************************/ + /* */ + /************************************************************************/ - template<class t_connection_context = net_utils::connection_context_base> + template<class t_connection_context = net_utils::connection_context_base> class http_custom_handler: public simple_http_connection_handler<t_connection_context> { public: typedef custum_handler_config<t_connection_context> config_type; - http_custom_handler(i_service_endpoint* psnd_hndlr, config_type& config, t_connection_context& conn_context):simple_http_connection_handler<t_connection_context>(psnd_hndlr, config), - m_config(config), - m_conn_context(conn_context) + http_custom_handler(i_service_endpoint* psnd_hndlr, config_type& config, t_connection_context& conn_context) + : simple_http_connection_handler<t_connection_context>(psnd_hndlr, config), + m_config(config), + m_conn_context(conn_context) {} inline bool handle_request(const http_request_info& query_info, http_response_info& response) { @@ -191,8 +190,8 @@ namespace net_utils { return m_config.m_phandler->deinit_server_thread(); } - void handle_qued_callback() - {} + void handle_qued_callback() + {} bool after_init_connection() { return true; diff --git a/contrib/epee/include/net/http_server_handlers_map2.h b/contrib/epee/include/net/http_server_handlers_map2.h index af4e035f8..201460130 100644 --- a/contrib/epee/include/net/http_server_handlers_map2.h +++ b/contrib/epee/include/net/http_server_handlers_map2.h @@ -26,9 +26,10 @@ #pragma once -#include "serialization/keyvalue_serialization.h" -#include "storages/portable_storage_template_helper.h" #include "http_base.h" +#include "jsonrpc_structs.h" +#include "storages/portable_storage.h" +#include "storages/portable_storage_template_helper.h" #define CHAIN_HTTP_TO_MAP2(context_type) bool handle_http_request(const epee::net_utils::http::http_request_info& query_info, \ @@ -109,98 +110,6 @@ #define END_URI_MAP2() return handled;} - - -namespace epee -{ - namespace json_rpc - { - template<typename t_param> - struct request - { - std::string jsonrpc; - std::string method; - epee::serialization::storage_entry id; - t_param params; - - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(jsonrpc) - KV_SERIALIZE(id) - KV_SERIALIZE(method) - KV_SERIALIZE(params) - END_KV_SERIALIZE_MAP() - }; - - struct error - { - int64_t code; - std::string message; - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(code) - KV_SERIALIZE(message) - END_KV_SERIALIZE_MAP() - }; - - struct dummy_error - { - BEGIN_KV_SERIALIZE_MAP() - 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; - epee::serialization::storage_entry 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; - epee::serialization::storage_entry 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; - epee::serialization::storage_entry id; - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(jsonrpc) - KV_SERIALIZE(id) - KV_SERIALIZE(error) - END_KV_SERIALIZE_MAP() - }; - - typedef response<dummy_result, error> error_response; - } -} - - - - #define BEGIN_JSON_RPC_MAP(uri) else if(query_info.m_URI == uri) \ { \ uint64_t ticks = epee::misc_utils::get_tick_count(); \ @@ -315,6 +224,6 @@ namespace epee 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; \ - } +} diff --git a/contrib/epee/include/net/net_utils_base.h b/contrib/epee/include/net/net_utils_base.h index 793135b87..b5619bab3 100644 --- a/contrib/epee/include/net/net_utils_base.h +++ b/contrib/epee/include/net/net_utils_base.h @@ -47,8 +47,8 @@ namespace net_utils struct connection_context_base { const boost::uuids::uuid m_connection_id; - const uint32_t m_remote_ip; - const uint32_t m_remote_port; + const uint32_t m_remote_ip; + const uint32_t m_remote_port; const bool m_is_income; const time_t m_started; time_t m_last_recv; @@ -56,27 +56,30 @@ namespace net_utils uint64_t m_recv_cnt; uint64_t m_send_cnt; - connection_context_base(boost::uuids::uuid connection_id, long remote_ip, int remote_port, bool is_income, time_t last_recv = 0, time_t last_send = 0, uint64_t recv_cnt = 0, uint64_t send_cnt = 0): + connection_context_base(boost::uuids::uuid connection_id, + long remote_ip, int remote_port, bool is_income, + time_t last_recv = 0, time_t last_send = 0, + uint64_t recv_cnt = 0, uint64_t send_cnt = 0): m_connection_id(connection_id), m_remote_ip(remote_ip), m_remote_port(remote_port), m_is_income(is_income), + m_started(time(NULL)), m_last_recv(last_recv), m_last_send(last_send), m_recv_cnt(recv_cnt), - m_send_cnt(send_cnt), - m_started(time(NULL)) + m_send_cnt(send_cnt) {} connection_context_base(): m_connection_id(), m_remote_ip(0), m_remote_port(0), m_is_income(false), + m_started(time(NULL)), m_last_recv(0), m_last_send(0), m_recv_cnt(0), - m_send_cnt(0), - m_started(time(NULL)) + m_send_cnt(0) {} connection_context_base& operator=(const connection_context_base& a) diff --git a/contrib/epee/include/profile_tools.h b/contrib/epee/include/profile_tools.h index be45feafe..0e1646f60 100644 --- a/contrib/epee/include/profile_tools.h +++ b/contrib/epee/include/profile_tools.h @@ -51,13 +51,13 @@ namespace epee #define PROFILE_FUNC_THIRD(immortal_ptr_str) #endif -#define START_WAY_POINTS() uint64_t _____way_point_time = misc_utils::get_tick_count(); -#define WAY_POINT(name) {uint64_t delta = misc_utils::get_tick_count()-_____way_point_time; LOG_PRINT("Way point " << name << ": " << delta, LOG_LEVEL_2);_____way_point_time = misc_utils::get_tick_count();} -#define WAY_POINT2(name, avrg_obj) {uint64_t delta = misc_utils::get_tick_count()-_____way_point_time; avrg_obj.push(delta); LOG_PRINT("Way point " << name << ": " << delta, LOG_LEVEL_2);_____way_point_time = misc_utils::get_tick_count();} +#define START_WAY_POINTS() uint64_t _____way_point_time = epee::misc_utils::get_tick_count(); +#define WAY_POINT(name) {uint64_t delta = epee::misc_utils::get_tick_count()-_____way_point_time; LOG_PRINT("Way point " << name << ": " << delta, LOG_LEVEL_2);_____way_point_time = misc_utils::get_tick_count();} +#define WAY_POINT2(name, avrg_obj) {uint64_t delta = epee::misc_utils::get_tick_count()-_____way_point_time; avrg_obj.push(delta); LOG_PRINT("Way point " << name << ": " << delta, LOG_LEVEL_2);_____way_point_time = misc_utils::get_tick_count();} -#define TIME_MEASURE_START(var_name) uint64_t var_name = misc_utils::get_tick_count(); -#define TIME_MEASURE_FINISH(var_name) var_name = misc_utils::get_tick_count() - var_name; +#define TIME_MEASURE_START(var_name) uint64_t var_name = epee::misc_utils::get_tick_count(); +#define TIME_MEASURE_FINISH(var_name) var_name = epee::misc_utils::get_tick_count() - var_name; namespace profile_tools { diff --git a/contrib/epee/include/serialization/keyvalue_serialization.h b/contrib/epee/include/serialization/keyvalue_serialization.h index 27fb0f1e2..bf2c8dacd 100644 --- a/contrib/epee/include/serialization/keyvalue_serialization.h +++ b/contrib/epee/include/serialization/keyvalue_serialization.h @@ -31,6 +31,8 @@ #include "misc_log_ex.h" #include "enableable.h" #include "keyvalue_serialization_overloads.h" +#include "serialization/serialization.h" + namespace epee { /************************************************************************/ @@ -41,12 +43,12 @@ public: \ template<class t_storage> \ bool store( t_storage& st, typename t_storage::hsection hparent_section = nullptr) const\ {\ - return serialize_map<true>(*this, st, hparent_section);\ + return serialize_map<true>(*this, st, hparent_section);\ }\ template<class t_storage> \ bool _load( t_storage& stg, typename t_storage::hsection hparent_section = nullptr)\ {\ - return serialize_map<false>(*this, stg, hparent_section);\ + return serialize_map<false>(*this, stg, hparent_section);\ }\ template<class t_storage> \ bool load( t_storage& stg, typename t_storage::hsection hparent_section = nullptr)\ diff --git a/contrib/epee/include/storages/portable_storage.h b/contrib/epee/include/storages/portable_storage.h index c244dac19..bbfe5f85c 100644 --- a/contrib/epee/include/storages/portable_storage.h +++ b/contrib/epee/include/storages/portable_storage.h @@ -83,7 +83,7 @@ namespace epee bool load_from_binary(const binarybuffer& target); template<class trace_policy> bool dump_as_xml(std::string& targetObj, const std::string& root_name = ""); - bool dump_as_json(std::string& targetObj, size_t indent = 0); + bool dump_as_json(std::string& targetObj, size_t indent = 0, bool insert_newlines = true); bool load_from_json(const std::string& source); private: @@ -106,17 +106,17 @@ namespace epee #pragma pack(pop) }; inline - bool portable_storage::dump_as_json(std::string& buff, size_t indent) + bool portable_storage::dump_as_json(std::string& buff, size_t indent, bool insert_newlines) { TRY_ENTRY(); std::stringstream ss; - epee::serialization::dump_as_json(ss, m_root, indent); + epee::serialization::dump_as_json(ss, m_root, indent, insert_newlines); buff = ss.str(); return true; CATCH_ENTRY("portable_storage::dump_as_json", false) } inline - bool portable_storage::load_from_json(const std::string& source) + bool portable_storage::load_from_json(const std::string& source) { TRY_ENTRY(); return json::load_from_json(source, *this); @@ -124,13 +124,13 @@ namespace epee } template<class trace_policy> - bool portable_storage::dump_as_xml(std::string& targetObj, const std::string& root_name) + bool portable_storage::dump_as_xml(std::string& targetObj, const std::string& root_name) { return false;//TODO: don't think i ever again will use xml - ambiguous and "overtagged" format } inline - bool portable_storage::store_to_binary(binarybuffer& target) + bool portable_storage::store_to_binary(binarybuffer& target) { TRY_ENTRY(); std::stringstream ss; @@ -145,7 +145,7 @@ namespace epee CATCH_ENTRY("portable_storage::store_to_binary", false) } inline - bool portable_storage::load_from_binary(const binarybuffer& source) + bool portable_storage::load_from_binary(const binarybuffer& source) { m_root.m_entries.clear(); if(source.size() < sizeof(storage_block_header)) @@ -174,7 +174,7 @@ namespace epee } //--------------------------------------------------------------------------------------------------------------- inline - hsection portable_storage::open_section(const std::string& section_name, hsection hparent_section, bool create_if_notexist) + hsection portable_storage::open_section(const std::string& section_name, hsection hparent_section, bool create_if_notexist) { TRY_ENTRY(); hparent_section = hparent_section ? hparent_section:&m_root; @@ -238,7 +238,7 @@ namespace epee } //--------------------------------------------------------------------------------------------------------------- template<class t_value> - bool portable_storage::set_value(const std::string& value_name, const t_value& v, hsection hparent_section) + bool portable_storage::set_value(const std::string& value_name, const t_value& v, hsection hparent_section) { BOOST_MPL_ASSERT(( boost::mpl::contains<boost::mpl::push_front<storage_entry::types, storage_entry>::type, t_value> )); TRY_ENTRY(); @@ -345,7 +345,7 @@ namespace epee template<class t_value> - bool portable_storage::get_next_value(harray hval_array, t_value& target) + bool portable_storage::get_next_value(harray hval_array, t_value& target) { BOOST_MPL_ASSERT(( boost::mpl::contains<storage_entry::types, t_value> )); //TRY_ENTRY(); @@ -462,7 +462,7 @@ namespace epee } //--------------------------------------------------------------------------------------------------------------- inline - bool portable_storage::insert_next_section(harray hsec_array, hsection& hinserted_childsection) + bool portable_storage::insert_next_section(harray hsec_array, hsection& hinserted_childsection) { TRY_ENTRY(); CHECK_AND_ASSERT(hsec_array, false); @@ -476,4 +476,4 @@ namespace epee } //--------------------------------------------------------------------------------------------------------------- } -}
\ No newline at end of file +} diff --git a/contrib/epee/include/storages/portable_storage_template_helper.h b/contrib/epee/include/storages/portable_storage_template_helper.h index 2163cb879..008f44321 100644 --- a/contrib/epee/include/storages/portable_storage_template_helper.h +++ b/contrib/epee/include/storages/portable_storage_template_helper.h @@ -25,6 +25,9 @@ // #pragma once + +#include <string> + #include "parserse_base_utils.h" #include "portable_storage.h" #include "file_io_utils.h" @@ -56,19 +59,19 @@ namespace epee } //----------------------------------------------------------------------------------------------------------- template<class t_struct> - bool store_t_to_json(t_struct& str_in, std::string& json_buff, size_t indent = 0) + bool store_t_to_json(t_struct& str_in, std::string& json_buff, size_t indent = 0, bool insert_newlines = true) { portable_storage ps; str_in.store(ps); - ps.dump_as_json(json_buff, indent); + ps.dump_as_json(json_buff, indent, insert_newlines); return true; } //----------------------------------------------------------------------------------------------------------- template<class t_struct> - std::string store_t_to_json(t_struct& str_in, size_t indent = 0) + std::string store_t_to_json(t_struct& str_in, size_t indent = 0, bool insert_newlines = true) { std::string json_buff; - store_t_to_json(str_in, json_buff, indent); + store_t_to_json(str_in, json_buff, indent, insert_newlines); return std::move(json_buff); } //----------------------------------------------------------------------------------------------------------- diff --git a/contrib/epee/include/storages/portable_storage_to_json.h b/contrib/epee/include/storages/portable_storage_to_json.h index aff85b201..e3fdcec29 100644 --- a/contrib/epee/include/storages/portable_storage_to_json.h +++ b/contrib/epee/include/storages/portable_storage_to_json.h @@ -30,6 +30,7 @@ #include "misc_language.h" #include "portable_storage_base.h" +#include "parserse_base_utils.h" namespace epee { @@ -37,21 +38,21 @@ namespace epee { template<class t_stream> - void dump_as_json(t_stream& strm, const array_entry& ae, size_t indent); + void dump_as_json(t_stream& strm, const array_entry& ae, size_t indent, bool insert_newlines); template<class t_stream> - void dump_as_json(t_stream& strm, const storage_entry& se, size_t indent); + void dump_as_json(t_stream& strm, const storage_entry& se, size_t indent, bool insert_newlines); template<class t_stream> - void dump_as_json(t_stream& strm, const std::string& v, size_t indent); + void dump_as_json(t_stream& strm, const std::string& v, size_t indent, bool insert_newlines); template<class t_stream> - void dump_as_json(t_stream& strm, const int8_t& v, size_t indent); + void dump_as_json(t_stream& strm, const int8_t& v, size_t indent, bool insert_newlines); template<class t_stream> - void dump_as_json(t_stream& strm, const uint8_t& v, size_t indent); + void dump_as_json(t_stream& strm, const uint8_t& v, size_t indent, bool insert_newlines); template<class t_stream> - void dump_as_json(t_stream& strm, const bool& v, size_t indent); + void dump_as_json(t_stream& strm, const bool& v, size_t indent, bool insert_newlines); template<class t_stream, class t_type> - void dump_as_json(t_stream& strm, const t_type& v, size_t indent); + void dump_as_json(t_stream& strm, const t_type& v, size_t indent, bool insert_newlines); template<class t_stream> - void dump_as_json(t_stream& strm, const section& sec, size_t indent); + void dump_as_json(t_stream& strm, const section& sec, size_t indent, bool insert_newlines); inline std::string make_indent(size_t indent) @@ -64,7 +65,11 @@ namespace epee { t_stream& m_strm; size_t m_indent; - array_entry_store_to_json_visitor(t_stream& strm, size_t indent):m_strm(strm), m_indent(indent){} + bool m_insert_newlines; + array_entry_store_to_json_visitor(t_stream& strm, size_t indent, + bool insert_newlines = true) + : m_strm(strm), m_indent(indent), m_insert_newlines(insert_newlines) + {} template<class t_type> void operator()(const array_entry_t<t_type>& a) @@ -75,7 +80,7 @@ namespace epee auto last_it = --a.m_array.end(); for(auto it = a.m_array.begin(); it != a.m_array.end(); it++) { - dump_as_json(m_strm, *it, m_indent); + dump_as_json(m_strm, *it, m_indent, m_insert_newlines); if(it != last_it) m_strm << ","; } @@ -89,50 +94,53 @@ namespace epee { t_stream& m_strm; size_t m_indent; - storage_entry_store_to_json_visitor(t_stream& strm, size_t indent):m_strm(strm), m_indent(indent) + bool m_insert_newlines; + storage_entry_store_to_json_visitor(t_stream& strm, size_t indent, + bool insert_newlines = true) + : m_strm(strm), m_indent(indent), m_insert_newlines(insert_newlines) {} //section, array_entry template<class visited_type> void operator()(const visited_type& v) { - dump_as_json(m_strm, v, m_indent); + dump_as_json(m_strm, v, m_indent, m_insert_newlines); } }; template<class t_stream> - void dump_as_json(t_stream& strm, const array_entry& ae, size_t indent) + void dump_as_json(t_stream& strm, const array_entry& ae, size_t indent, bool insert_newlines) { - array_entry_store_to_json_visitor<t_stream> aesv(strm, indent); + array_entry_store_to_json_visitor<t_stream> aesv(strm, indent, insert_newlines); boost::apply_visitor(aesv, ae); } template<class t_stream> - void dump_as_json(t_stream& strm, const storage_entry& se, size_t indent) + void dump_as_json(t_stream& strm, const storage_entry& se, size_t indent, bool insert_newlines) { - storage_entry_store_to_json_visitor<t_stream> sv(strm, indent); + storage_entry_store_to_json_visitor<t_stream> sv(strm, indent, insert_newlines); boost::apply_visitor(sv, se); } template<class t_stream> - void dump_as_json(t_stream& strm, const std::string& v, size_t indent) + void dump_as_json(t_stream& strm, const std::string& v, size_t indent, bool insert_newlines) { strm << "\"" << misc_utils::parse::transform_to_escape_sequence(v) << "\""; } template<class t_stream> - void dump_as_json(t_stream& strm, const int8_t& v, size_t indent) + void dump_as_json(t_stream& strm, const int8_t& v, size_t indent, bool insert_newlines) { strm << static_cast<int32_t>(v); } template<class t_stream> - void dump_as_json(t_stream& strm, const uint8_t& v, size_t indent) + void dump_as_json(t_stream& strm, const uint8_t& v, size_t indent, bool insert_newlines) { strm << static_cast<int32_t>(v); } template<class t_stream> - void dump_as_json(t_stream& strm, const bool& v, size_t indent) + void dump_as_json(t_stream& strm, const bool& v, size_t indent, bool insert_newlines) { if(v) strm << "true"; @@ -143,16 +151,17 @@ namespace epee template<class t_stream, class t_type> - void dump_as_json(t_stream& strm, const t_type& v, size_t indent) + void dump_as_json(t_stream& strm, const t_type& v, size_t indent, bool insert_newlines) { strm << v; } template<class t_stream> - void dump_as_json(t_stream& strm, const section& sec, size_t indent) + void dump_as_json(t_stream& strm, const section& sec, size_t indent, bool insert_newlines) { size_t local_indent = indent + 1; - strm << "{\r\n"; + std::string newline = insert_newlines ? "\r\n" : ""; + strm << "{" << newline; std::string indent_str = make_indent(local_indent); if(sec.m_entries.size()) { @@ -160,10 +169,10 @@ namespace epee for(auto it = sec.m_entries.begin(); it!= sec.m_entries.end();it++) { strm << indent_str << "\"" << misc_utils::parse::transform_to_escape_sequence(it->first) << "\"" << ": "; - dump_as_json(strm, it->second, local_indent); + dump_as_json(strm, it->second, local_indent, insert_newlines); if(it_last != it) strm << ","; - strm << "\r\n"; + strm << newline; } } strm << make_indent(indent) << "}"; diff --git a/contrib/epee/include/string_tools.h b/contrib/epee/include/string_tools.h index 4cc88418c..8289ee0ba 100644 --- a/contrib/epee/include/string_tools.h +++ b/contrib/epee/include/string_tools.h @@ -32,6 +32,7 @@ //#include <objbase.h> #include <locale> #include <cstdlib> +#include <iomanip> //#include <strsafe.h> #include <boost/uuid/uuid.hpp> #include <boost/uuid/uuid_io.hpp> |