From 08aebd2729600f0836bd4454a5ef793f4217343a Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 28 Jun 2016 18:52:51 -0400 Subject: [PATCH] format more log messages in alert constructors --- include/libtorrent/alert_types.hpp | 9 +++------ src/alert.cpp | 25 ++++++++---------------- src/peer_connection.cpp | 31 +++++++++++++++--------------- src/session_impl.cpp | 14 ++++---------- src/torrent.cpp | 8 ++------ 5 files changed, 33 insertions(+), 54 deletions(-) diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index e93a674d6..5fb144cae 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -2092,6 +2092,7 @@ namespace libtorrent { // internal log_alert(aux::stack_allocator& alloc, char const* log); + log_alert(aux::stack_allocator& alloc, char const* fmt, va_list v); TORRENT_DEFINE_ALERT(log_alert, 79) @@ -2114,7 +2115,7 @@ namespace libtorrent { // internal torrent_log_alert(aux::stack_allocator& alloc, torrent_handle const& h - , char const* log); + , char const* fmt, va_list v); TORRENT_DEFINE_ALERT(torrent_log_alert, 80) @@ -2146,10 +2147,6 @@ namespace libtorrent }; // internal - peer_log_alert(aux::stack_allocator& alloc, torrent_handle const& h - , tcp::endpoint const& i, peer_id const& pi - , peer_log_alert::direction_t dir - , char const* event, char const* log); peer_log_alert(aux::stack_allocator& alloc, torrent_handle const& h , tcp::endpoint const& i, peer_id const& pi , peer_log_alert::direction_t dir @@ -2301,7 +2298,7 @@ namespace libtorrent }; dht_log_alert(aux::stack_allocator& alloc - , dht_module_t m, char const* msg); + , dht_module_t m, char const* fmt, va_list v); static const int static_category = alert::dht_log_notification; TORRENT_DEFINE_ALERT(dht_log_alert, 85) diff --git a/src/alert.cpp b/src/alert.cpp index c179369cc..46d6305c8 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -1659,6 +1659,10 @@ namespace libtorrent { : m_alloc(alloc) , m_str_idx(alloc.copy_string(log)) {} + log_alert::log_alert(aux::stack_allocator& alloc, char const* fmt, va_list v) + : m_alloc(alloc) + , m_str_idx(alloc.format_string(fmt, v)) + {} char const* log_alert::msg() const { @@ -1671,9 +1675,9 @@ namespace libtorrent { } torrent_log_alert::torrent_log_alert(aux::stack_allocator& alloc, torrent_handle const& h - , char const* log) + , char const* fmt, va_list v) : torrent_alert(alloc, h) - , m_str_idx(alloc.copy_string(log)) + , m_str_idx(alloc.format_string(fmt, v)) {} char const* torrent_log_alert::msg() const @@ -1686,19 +1690,6 @@ namespace libtorrent { return torrent_alert::message() + ": " + msg(); } - peer_log_alert::peer_log_alert(aux::stack_allocator& alloc - , torrent_handle const& h - , tcp::endpoint const& i - , peer_id const& pi - , direction_t dir - , char const* event - , char const* log) - : peer_alert(alloc, h, i, pi) - , event_type(event) - , direction(dir) - , m_str_idx(alloc.copy_string(log)) - {} - peer_log_alert::peer_log_alert(aux::stack_allocator& alloc , torrent_handle const& h , tcp::endpoint const& i, peer_id const& pi @@ -1866,10 +1857,10 @@ namespace libtorrent { } dht_log_alert::dht_log_alert(aux::stack_allocator& alloc - , dht_log_alert::dht_module_t m, const char* msg) + , dht_log_alert::dht_module_t m, const char* fmt, va_list v) : module(m) , m_alloc(alloc) - , m_msg_idx(alloc.copy_string(msg)) + , m_msg_idx(alloc.format_string(fmt, v)) {} char const* dht_log_alert::log_message() const diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 146a4b1d0..a5327b137 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -34,21 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#if TORRENT_USE_ASSERTS -#include -#endif - -#ifdef TORRENT_USE_OPENSSL -#include -#endif - -#ifndef TORRENT_DISABLE_LOGGING -#include // for va_start, va_end -#include // for vsnprintf -#include "libtorrent/socket_io.hpp" -#include "libtorrent/hex.hpp" // to_hex -#endif - +#include "libtorrent/config.hpp" #include "libtorrent/peer_connection.hpp" #include "libtorrent/identify_client.hpp" #include "libtorrent/entry.hpp" @@ -79,6 +65,21 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/close_reason.hpp" #include "libtorrent/aux_/time.hpp" +#if TORRENT_USE_ASSERTS +#include +#endif + +#ifdef TORRENT_USE_OPENSSL +#include +#endif + +#ifndef TORRENT_DISABLE_LOGGING +#include // for va_start, va_end +#include // for vsnprintf +#include "libtorrent/socket_io.hpp" +#include "libtorrent/hex.hpp" // to_hex +#endif + //#define TORRENT_CORRUPT_DATA using boost::shared_ptr; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index c927223d1..7cf4752c6 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -4443,10 +4443,7 @@ namespace aux { void session_impl::session_vlog(char const* fmt, va_list& v) const { if (!m_alerts.should_post()) return; - - char buf[1024]; - vsnprintf(buf, sizeof(buf), fmt, v); - m_alerts.emplace_alert(buf); + m_alerts.emplace_alert(fmt, v); } #endif @@ -6593,10 +6590,9 @@ namespace aux { va_list v; va_start(v, fmt); - char buf[1024]; - std::vsnprintf(buf, sizeof(buf), fmt, v); + m_alerts.emplace_alert( + static_cast(m), fmt, v); va_end(v); - m_alerts.emplace_alert(static_cast(m), buf); } void session_impl::log_packet(message_direction_t dir, char const* pkt, int len @@ -6938,10 +6934,8 @@ namespace aux { { va_list v; va_start(v, fmt); - char usr[1024]; - vsnprintf(usr, sizeof(usr), fmt, v); + m_ses.session_vlog(fmt, v); va_end(v); - m_ses.session_log("%s", usr); } #endif // TORRENT_DISABLE_LOGGING }} diff --git a/src/torrent.cpp b/src/torrent.cpp index 807aab605..218a0c56c 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -11310,13 +11310,9 @@ namespace libtorrent va_list v; va_start(v, fmt); - - char buf[400]; - vsnprintf(buf, sizeof(buf), fmt, v); - va_end(v); - alerts().emplace_alert( - const_cast(this)->get_handle(), buf); + const_cast(this)->get_handle(), fmt, v); + va_end(v); } #endif