dropped some iostream dependencies

This commit is contained in:
Arvid Norberg 2009-04-04 09:52:25 +00:00
parent ac7e4fed7e
commit aba5b2e9d0
34 changed files with 404 additions and 326 deletions

View File

@ -114,9 +114,10 @@ namespace libtorrent
virtual char const* what() const { return "read piece"; } virtual char const* what() const { return "read piece"; }
virtual std::string message() const virtual std::string message() const
{ {
std::stringstream ret; char msg[200];
ret << torrent_alert::message() << ": piece " << (buffer ? "successful " : "failed ") << piece; snprintf(msg, 200, "%s: piece %s %u", torrent_alert::message().c_str()
return ret.str(); , buffer ? "successful" : "failed", piece);
return msg;
} }
boost::shared_array<char> buffer; boost::shared_array<char> buffer;
@ -141,10 +142,10 @@ namespace libtorrent
virtual char const* what() const { return "file renamed"; } virtual char const* what() const { return "file renamed"; }
virtual std::string message() const virtual std::string message() const
{ {
std::stringstream ret; char msg[200];
ret << torrent_alert::message() << ": file " snprintf(msg, 200, "%s: file %d renamed to %s", torrent_alert::message().c_str()
<< index << " renamed to " << name; , index, name.c_str());
return ret.str(); return msg;
} }
std::string name; std::string name;
@ -167,10 +168,10 @@ namespace libtorrent
virtual char const* what() const { return "file rename failed"; } virtual char const* what() const { return "file rename failed"; }
virtual std::string message() const virtual std::string message() const
{ {
std::stringstream ret; char ret[200];
ret << torrent_alert::message() << ": failed to rename file " snprintf(ret, 200, "%s: failed to rename file %d: %s"
<< index << ": " << msg; , torrent_alert::message().c_str(), index, msg.c_str());
return ret.str(); return ret;
} }
const static int static_category = alert::storage_notification; const static int static_category = alert::storage_notification;
@ -273,10 +274,10 @@ namespace libtorrent
virtual char const* what() const { return "tracker error"; } virtual char const* what() const { return "tracker error"; }
virtual std::string message() const virtual std::string message() const
{ {
std::stringstream ret; char ret[200];
ret << tracker_alert::message() << " (" << status_code << ") " snprintf(ret, 200, "%s (%u) %s (%d)"
<< msg << " (" << times_in_row << ")"; , torrent_alert::message().c_str(), status_code, msg.c_str(), times_in_row);
return ret.str(); return ret;
} }
int times_in_row; int times_in_row;
@ -325,10 +326,10 @@ namespace libtorrent
virtual char const* what() const { return "tracker scrape reply"; } virtual char const* what() const { return "tracker scrape reply"; }
virtual std::string message() const virtual std::string message() const
{ {
std::stringstream ret; char ret[200];
ret << tracker_alert::message() << " scrape reply: " << incomplete snprintf(ret, 200, "%s scrape reply: %u %u"
<< " " << complete; , torrent_alert::message().c_str(), incomplete, complete);
return ret.str(); return ret;
} }
}; };
@ -370,10 +371,10 @@ namespace libtorrent
virtual char const* what() const { return "tracker reply"; } virtual char const* what() const { return "tracker reply"; }
virtual std::string message() const virtual std::string message() const
{ {
std::stringstream ret; char ret[200];
ret << tracker_alert::message() << " received peers: " snprintf(ret, 200, "%s received peers: %u"
<< num_peers; , torrent_alert::message().c_str(), num_peers);
return ret.str(); return ret;
} }
}; };
@ -392,10 +393,10 @@ namespace libtorrent
virtual char const* what() const { return "DHT reply"; } virtual char const* what() const { return "DHT reply"; }
virtual std::string message() const virtual std::string message() const
{ {
std::stringstream ret; char ret[200];
ret << torrent_alert::message() << " received DHT peers: " snprintf(ret, 200, "%s received DHT peers: %u"
<< num_peers; , torrent_alert::message().c_str(), num_peers);
return ret.str(); return ret;
} }
}; };
@ -435,10 +436,10 @@ namespace libtorrent
virtual int category() const { return static_category; } virtual int category() const { return static_category; }
virtual std::string message() const virtual std::string message() const
{ {
std::stringstream ret; char ret[200];
ret << torrent_alert::message() << " hash for piece " snprintf(ret, 200, "%s hash for piece %u failed"
<< piece_index << " failed"; , torrent_alert::message().c_str(), piece_index);
return ret.str(); return ret;
} }
int piece_index; int piece_index;
@ -567,11 +568,10 @@ namespace libtorrent
virtual char const* what() const { return "invalid piece request"; } virtual char const* what() const { return "invalid piece request"; }
virtual std::string message() const virtual std::string message() const
{ {
std::stringstream ret; char ret[200];
ret << peer_alert::message() << " peer sent an invalid piece request " snprintf(ret, 200, "%s peer sent an invalid piece request (piece: %u start: %u len: %u)"
"( piece: " << request.piece << " start: " << request.start , torrent_alert::message().c_str(), request.piece, request.start, request.length);
<< " len: " << request.length << ")"; return ret;
return ret.str();
} }
peer_request request; peer_request request;
@ -613,10 +613,10 @@ namespace libtorrent
virtual int category() const { return static_category; } virtual int category() const { return static_category; }
virtual std::string message() const virtual std::string message() const
{ {
std::stringstream ret; char ret[200];
ret << torrent_alert::message() << " piece " << piece_index snprintf(ret, 200, "%s piece: %u finished downloading"
<< " finished downloading"; , torrent_alert::message().c_str(), piece_index);
return ret.str(); return ret;
} }
}; };
@ -640,10 +640,10 @@ namespace libtorrent
virtual int category() const { return static_category; } virtual int category() const { return static_category; }
virtual std::string message() const virtual std::string message() const
{ {
std::stringstream ret; char ret[200];
ret << peer_alert::message() << " peer dropped block ( piece: " snprintf(ret, 200, "%s peer dropped block ( piece: %u block: %u)"
<< piece_index << " block: " << block_index << ")"; , torrent_alert::message().c_str(), piece_index, block_index);
return ret.str(); return ret;
} }
}; };
@ -667,10 +667,10 @@ namespace libtorrent
virtual int category() const { return static_category; } virtual int category() const { return static_category; }
virtual std::string message() const virtual std::string message() const
{ {
std::stringstream ret; char ret[200];
ret << peer_alert::message() << " peer timed out request ( piece: " snprintf(ret, 200, "%s peer timed out request ( piece: %u block: %u)"
<< piece_index << " block: " << block_index << ")"; , torrent_alert::message().c_str(), piece_index, block_index);
return ret.str(); return ret;
} }
}; };
@ -693,10 +693,10 @@ namespace libtorrent
virtual int category() const { return static_category; } virtual int category() const { return static_category; }
virtual std::string message() const virtual std::string message() const
{ {
std::stringstream ret; char ret[200];
ret << peer_alert::message() << " block finished downloading ( piece: " snprintf(ret, 200, "%s block finished downloading (piece: %u block: %u)"
<< piece_index << " block: " << block_index << ")"; , torrent_alert::message().c_str(), piece_index, block_index);
return ret.str(); return ret;
} }
}; };
@ -721,10 +721,10 @@ namespace libtorrent
virtual int category() const { return static_category; } virtual int category() const { return static_category; }
virtual std::string message() const virtual std::string message() const
{ {
std::stringstream ret; char ret[200];
ret << peer_alert::message() << " requested block ( piece: " snprintf(ret, 200, "%s requested block (piece: %u block: %u) %s"
<< piece_index << " block: " << block_index << ") " << peer_speedmsg; , torrent_alert::message().c_str(), piece_index, block_index, peer_speedmsg);
return ret.str(); return ret;
} }
}; };
@ -745,10 +745,10 @@ namespace libtorrent
virtual char const* what() const { return "unwanted block received"; } virtual char const* what() const { return "unwanted block received"; }
virtual std::string message() const virtual std::string message() const
{ {
std::stringstream ret; char ret[200];
ret << peer_alert::message() << " received block not in download queue ( piece: " snprintf(ret, 200, "%s received block not in download queue (piece: %u block: %u)"
<< piece_index << " block: " << block_index << ")"; , torrent_alert::message().c_str(), piece_index, block_index);
return ret.str(); return ret;
} }
}; };
@ -1059,11 +1059,10 @@ namespace libtorrent
virtual int category() const { return static_category; } virtual int category() const { return static_category; }
virtual std::string message() const virtual std::string message() const
{ {
error_code ec; char ret[200];
std::stringstream ret; snprintf(ret, 200, "listening on %s failed: %s"
ret << "listening on " << endpoint , print_endpoint(endpoint).c_str(), error.message().c_str());
<< " failed: " << error.message(); return ret;
return ret.str();
} }
}; };
@ -1082,10 +1081,9 @@ namespace libtorrent
virtual int category() const { return static_category; } virtual int category() const { return static_category; }
virtual std::string message() const virtual std::string message() const
{ {
error_code ec; char ret[200];
std::stringstream ret; snprintf(ret, 200, "successfully listening on %s", print_endpoint(endpoint).c_str());
ret << "successfully listening on " << endpoint; return ret;
return ret.str();
} }
}; };
@ -1131,10 +1129,10 @@ namespace libtorrent
virtual std::string message() const virtual std::string message() const
{ {
static char const* type_str[] = {"NAT-PMP", "UPnP"}; static char const* type_str[] = {"NAT-PMP", "UPnP"};
std::stringstream ret; char ret[200];
ret << "successfully mapped port using " << type_str[type] snprintf(ret, 200, "successfully mapped port using %s. external port: %u"
<< ". external port: " << external_port; , type_str[type], external_port);
return ret.str(); return ret;
} }
}; };
@ -1155,9 +1153,9 @@ namespace libtorrent
virtual std::string message() const virtual std::string message() const
{ {
static char const* type_str[] = {"NAT-PMP", "UPnP"}; static char const* type_str[] = {"NAT-PMP", "UPnP"};
std::stringstream ret; char ret[200];
ret << type_str[type] << ": " << msg; snprintf(ret, 200, "%s: %s", type_str[type], msg.c_str());
return ret.str(); return ret;
} }
}; };
@ -1224,10 +1222,12 @@ namespace libtorrent
virtual std::string message() const virtual std::string message() const
{ {
error_code ec; error_code ec;
std::stringstream ret; char ih_hex[41];
ret << "incoming dht annonce: " << ip.to_string(ec) << ":" to_hex((const char*)&info_hash[0], 20, ih_hex);
<< port << " (" << info_hash << ")"; char msg[200];
return ret.str(); snprintf(msg, 200, "incoming dht announce: %s:%u (%s)"
, ip.to_string(ec).c_str(), port, ih_hex);
return msg;
} }
}; };
@ -1246,10 +1246,11 @@ namespace libtorrent
virtual int category() const { return static_category; } virtual int category() const { return static_category; }
virtual std::string message() const virtual std::string message() const
{ {
error_code ec; char ih_hex[41];
std::stringstream ret; to_hex((const char*)&info_hash[0], 20, ih_hex);
ret << "incoming dht get_peers: " << info_hash; char msg[200];
return ret.str(); snprintf(msg, 200, "incoming dht get_peers: %s", ih_hex);
return msg;
} }
}; };
} }

View File

@ -650,20 +650,24 @@ namespace libtorrent
, int incomplete , int incomplete
, address const& external_ip) , address const& external_ip)
{ {
std::stringstream s; std::string s;
s << "TRACKER RESPONSE:\n" s = "TRACKER RESPONSE:\n";
"interval: " << interval << "\n" char tmp[200];
"peers:\n"; snprintf(tmp, 200, "interval: %d\npeers:\n", interval);
s += tmp;
for (std::vector<peer_entry>::const_iterator i = peers.begin(); for (std::vector<peer_entry>::const_iterator i = peers.begin();
i != peers.end(); ++i) i != peers.end(); ++i)
{ {
s << " " << std::setfill(' ') << std::setw(16) << i->ip char pid[41];
<< " " << std::setw(5) << std::dec << i->port << " "; to_hex((const char*)&i->pid[0], 20, pid);
if (!i->pid.is_all_zeros()) s << " " << i->pid; if (i->pid.is_all_zeros()) pid[0] = 0;
s << "\n";
snprintf(tmp, 200, " %16s %5d %s\n", i->ip.c_str(), i->port, pid);
s += tmp;
} }
s << "external ip: " << external_ip << "\n"; snprintf(tmp, 200, "external ip: %s\n", print_address(external_ip).c_str());
debug_log(s.str()); s += tmp;
debug_log(s);
} }
void tracker_request_timed_out( void tracker_request_timed_out(

View File

@ -88,6 +88,7 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_USE_MLOCK 1 #define TORRENT_USE_MLOCK 1
#define TORRENT_USE_READV 1 #define TORRENT_USE_READV 1
#define TORRENT_USE_WRITEV 1 #define TORRENT_USE_WRITEV 1
#define TORRENT_USE_IOSTREAM 1
// should wpath or path be used? // should wpath or path be used?
#if defined UNICODE && !defined BOOST_FILESYSTEM_NARROW_ONLY \ #if defined UNICODE && !defined BOOST_FILESYSTEM_NARROW_ONLY \

View File

@ -33,9 +33,15 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_DEBUG_HPP_INCLUDED #ifndef TORRENT_DEBUG_HPP_INCLUDED
#define TORRENT_DEBUG_HPP_INCLUDED #define TORRENT_DEBUG_HPP_INCLUDED
#ifdef TORRENT_DEBUG
#include <string> #include <string>
#include "libtorrent/config.hpp"
#if TORRENT_USE_IOSTREAM
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push, 1) #pragma warning(push, 1)
@ -60,6 +66,8 @@ namespace libtorrent
{ {
logger(fs::path const& logpath, fs::path const& filename, int instance, bool append = true) logger(fs::path const& logpath, fs::path const& filename, int instance, bool append = true)
{ {
#if TORRENT_USE_IOSTREAM
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
try try
{ {
@ -74,21 +82,27 @@ namespace libtorrent
{ {
std::cerr << "failed to create log '" << filename.string() << "': " << e.what() << std::endl; std::cerr << "failed to create log '" << filename.string() << "': " << e.what() << std::endl;
} }
#endif
#endif #endif
} }
template <class T> template <class T>
logger& operator<<(T const& v) logger& operator<<(T const& v)
{ {
#if TORRENT_USE_IOSTREAM
m_file << v; m_file << v;
m_file.flush(); m_file.flush();
#endif
return *this; return *this;
} }
#if TORRENT_USE_IOSTREAM
std::ofstream m_file; std::ofstream m_file;
#endif
}; };
} }
#endif // TORRENT_DEBUG
#endif // TORRENT_DEBUG_HPP_INCLUDED #endif // TORRENT_DEBUG_HPP_INCLUDED

View File

@ -61,6 +61,8 @@ namespace libtorrent
std::string const& url, std::string argument); std::string const& url, std::string argument);
TORRENT_EXPORT std::string to_hex(std::string const& s); TORRENT_EXPORT std::string to_hex(std::string const& s);
TORRENT_EXPORT void to_hex(char const *in, int len, char* out);
TORRENT_EXPORT bool from_hex(char const *in, int len, char* out);
#if TORRENT_USE_WPATH #if TORRENT_USE_WPATH
TORRENT_EXPORT std::wstring convert_to_wstring(std::string const& s); TORRENT_EXPORT std::wstring convert_to_wstring(std::string const& s);

View File

@ -43,6 +43,10 @@ POSSIBILITY OF SUCH DAMAGE.
#pragma warning(pop) #pragma warning(pop)
#endif #endif
#include "libtorrent/config.hpp"
#if TORRENT_USE_IOSTREAM
namespace libtorrent namespace libtorrent
{ {
struct torrent_plugin; struct torrent_plugin;
@ -50,5 +54,7 @@ namespace libtorrent
boost::shared_ptr<torrent_plugin> create_logger_plugin(torrent*); boost::shared_ptr<torrent_plugin> create_logger_plugin(torrent*);
} }
#endif
#endif // TORRENT_LOGGER_HPP_INCLUDED #endif // TORRENT_LOGGER_HPP_INCLUDED

View File

@ -34,7 +34,6 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_IP_FILTER_HPP #define TORRENT_IP_FILTER_HPP
#include <set> #include <set>
#include <iostream>
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push, 1) #pragma warning(push, 1)

View File

@ -33,6 +33,10 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_LOGGING_HPP #ifndef TORRENT_LOGGING_HPP
#define TORRENT_LOGGING_HPP #define TORRENT_LOGGING_HPP
#include "libtorrent/config.hpp"
#if TORRENT_USE_IOSTREAM
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include "libtorrent/time.hpp" #include "libtorrent/time.hpp"
@ -143,5 +147,7 @@ public:
if (libtorrent::dht::inverted_log_event event_object__ = name ## _log()); \ if (libtorrent::dht::inverted_log_event event_object__ = name ## _log()); \
else static_cast<log_event&>(event_object__) else static_cast<log_event&>(event_object__)
#endif // TORRENT_USE_IOSTREAM
#endif #endif

View File

@ -35,12 +35,15 @@ POSSIBILITY OF SUCH DAMAGE.
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <iosfwd>
#include <string> #include <string>
#include "libtorrent/config.hpp" #include "libtorrent/config.hpp"
#include "libtorrent/assert.hpp" #include "libtorrent/assert.hpp"
#include "libtorrent/size_type.hpp" #include "libtorrent/size_type.hpp"
#if TORRENT_USE_IOSTREAM
#include <iosfwd>
#endif
namespace libtorrent namespace libtorrent
{ {
struct lazy_entry; struct lazy_entry;
@ -227,7 +230,9 @@ namespace libtorrent
char const* m_end; char const* m_end;
}; };
#if TORRENT_USE_IOSTREAM
TORRENT_EXPORT std::ostream& operator<<(std::ostream& os, lazy_entry const& e); TORRENT_EXPORT std::ostream& operator<<(std::ostream& os, lazy_entry const& e);
#endif
} }

View File

@ -33,8 +33,6 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_PEER_ID_HPP_INCLUDED #ifndef TORRENT_PEER_ID_HPP_INCLUDED
#define TORRENT_PEER_ID_HPP_INCLUDED #define TORRENT_PEER_ID_HPP_INCLUDED
#include <iostream>
#include <iomanip>
#include <cctype> #include <cctype>
#include <algorithm> #include <algorithm>
#include <string> #include <string>
@ -44,6 +42,11 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/assert.hpp" #include "libtorrent/assert.hpp"
#include "libtorrent/escape_string.hpp" #include "libtorrent/escape_string.hpp"
#if TORRENT_USE_IOSTREAM
#include <iostream>
#include <iomanip>
#endif
namespace libtorrent namespace libtorrent
{ {
@ -160,41 +163,23 @@ namespace libtorrent
typedef big_number peer_id; typedef big_number peer_id;
typedef big_number sha1_hash; typedef big_number sha1_hash;
#if TORRENT_USE_IOSTREAM
inline std::ostream& operator<<(std::ostream& os, big_number const& peer) inline std::ostream& operator<<(std::ostream& os, big_number const& peer)
{ {
for (big_number::const_iterator i = peer.begin(); char out[41];
i != peer.end(); ++i) to_hex((char const*)&peer[0], big_number::size, out);
{ return os << out;
os << std::hex << std::setw(2) << std::setfill('0')
<< static_cast<unsigned int>(*i);
}
os << std::dec << std::setfill(' ');
return os;
} }
inline std::istream& operator>>(std::istream& is, big_number& peer) inline std::istream& operator>>(std::istream& is, big_number& peer)
{ {
for (big_number::iterator i = peer.begin(); char hex[40];
i != peer.end(); ++i) is.read(hex, 40);
{ if (from_hex(hex, 40, (char*)&peer[0]) == -1)
char c[2]; is.setstate(std::ios_base::failbit);
is >> c[0] >> c[1];
c[0] = tolower(c[0]);
c[1] = tolower(c[1]);
if (
((c[0] < '0' || c[0] > '9') && (c[0] < 'a' || c[0] > 'f'))
|| ((c[1] < '0' || c[1] > '9') && (c[1] < 'a' || c[1] > 'f'))
|| is.fail())
{
is.setstate(std::ios_base::failbit);
return is;
}
*i = ((is_digit(c[0])?c[0]-'0':c[0]-'a'+10) << 4)
+ (is_digit(c[1])?c[1]-'0':c[1]-'a'+10);
}
return is; return is;
} }
#endif // TORRENT_USE_IOSTREAM
} }
#endif // TORRENT_PEER_ID_HPP_INCLUDED #endif // TORRENT_PEER_ID_HPP_INCLUDED

View File

@ -74,6 +74,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/io.hpp" #include "libtorrent/io.hpp"
#include "libtorrent/time.hpp" #include "libtorrent/time.hpp"
#include "libtorrent/error_code.hpp" #include "libtorrent/error_code.hpp"
#include "libtorrent/escape_string.hpp" // for to_string
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
@ -114,6 +115,36 @@ namespace libtorrent
typedef boost::asio::basic_deadline_timer<libtorrent::ptime> deadline_timer; typedef boost::asio::basic_deadline_timer<libtorrent::ptime> deadline_timer;
#endif #endif
inline std::string print_address(address const& addr)
{
error_code ec;
return addr.to_string(ec);
}
inline std::string print_endpoint(tcp::endpoint const& ep)
{
error_code ec;
std::string ret;
address const& addr = ep.address();
#if TORRENT_USE_IPV6
if (addr.is_v6())
{
ret += '[';
ret += addr.to_string(ec);
ret += ']';
ret += ':';
ret += to_string(ep.port()).elems;
}
else
#endif
{
ret += addr.to_string(ec);
ret += ':';
ret += to_string(ep.port()).elems;
}
return ret;
}
/*
inline std::ostream& print_address(std::ostream& os, address const& addr) inline std::ostream& print_address(std::ostream& os, address const& addr)
{ {
error_code ec; error_code ec;
@ -137,7 +168,7 @@ namespace libtorrent
os << ep.port(); os << ep.port();
return os; return os;
} }
*/
namespace detail namespace detail
{ {
template<class OutIt> template<class OutIt>

View File

@ -37,7 +37,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <vector> #include <vector>
#include <set> #include <set>
#include <list> #include <list>
#include <iostream>
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push, 1) #pragma warning(push, 1)
@ -204,9 +203,6 @@ namespace libtorrent
void second_tick(stat& accumulator, float tick_interval); void second_tick(stat& accumulator, float tick_interval);
// debug purpose only
void print(std::ostream& os) const;
std::string name() const; std::string name() const;
stat statistics() const { return m_stat; } stat statistics() const { return m_stat; }

View File

@ -34,8 +34,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/pch.hpp" #include "libtorrent/pch.hpp"
#include <vector> #include <vector>
#include <iostream>
#include <iomanip>
#include <limits> #include <limits>
#include <boost/bind.hpp> #include <boost/bind.hpp>
@ -1013,11 +1011,10 @@ namespace libtorrent
if (t->valid_metadata() if (t->valid_metadata()
&& packet_size() - 1 != (t->torrent_file().num_pieces() + 7) / 8) && packet_size() - 1 != (t->torrent_file().num_pieces() + 7) / 8)
{ {
std::stringstream msg; char msg[200];
msg << "got bitfield with invalid size: " << (packet_size() - 1) snprintf(msg, 200, "got bitfield with invalid size: %d bytes. expected: %d bytes"
<< " bytes. expected: " << ((t->torrent_file().num_pieces() + 7) / 8) , int(packet_size()-1), int((t->torrent_file().num_pieces() + 7) / 8));
<< " bytes"; disconnect(msg, 2);
disconnect(msg.str().c_str(), 2);
return; return;
} }
@ -1433,9 +1430,9 @@ namespace libtorrent
} }
#endif #endif
std::stringstream msg; char msg[200];
msg << "unknown extended message id: " << extended_id; snprintf(msg, 200, "unknown extended message id: %d", extended_id);
disconnect(msg.str().c_str(), 2); disconnect(msg, 2);
return; return;
} }
@ -1558,9 +1555,9 @@ namespace libtorrent
#endif #endif
m_statistics.received_bytes(0, received); m_statistics.received_bytes(0, received);
std::stringstream msg; char msg[200];
msg << "unkown message id: " << packet_type << " size: " << packet_size(); snprintf(msg, 200, "unknown message message id: %d size: %d", packet_type, packet_size());
disconnect(msg.str().c_str(), 2); disconnect(msg, 2);
return packet_finished(); return packet_finished();
} }
@ -1743,14 +1740,15 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
(*m_logger) << time_now_string() << " ==> BITFIELD "; (*m_logger) << time_now_string() << " ==> BITFIELD ";
std::stringstream bitfield_string; char bitfield_string[1000];
for (int k = 0; k < num_pieces; ++k) for (int k = 0; k < num_pieces; ++k)
{ {
if (i.begin[k / 8] & (0x80 >> (k % 8))) bitfield_string << "1"; if (i.begin[k / 8] & (0x80 >> (k % 8))) bitfield_string[k] = '1';
else bitfield_string << "0"; else bitfield_string[k] = '0';
} }
bitfield_string << "\n"; bitfield_string[num_pieces] = '\n';
(*m_logger) << bitfield_string.str(); bitfield_string[num_pieces + 1] = '\0';
(*m_logger) << bitfield_string;
#endif #endif
#ifdef TORRENT_DEBUG #ifdef TORRENT_DEBUG
m_sent_bitfield = true; m_sent_bitfield = true;
@ -2728,18 +2726,18 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
{ {
peer_id tmp; char hex_pid[41];
std::copy(recv_buffer.begin, recv_buffer.begin + 20, (char*)tmp.begin()); to_hex(recv_buffer.begin, 20, hex_pid);
std::stringstream s; char ascii_pid[21];
s << "received peer_id: " << tmp << " client: " << identify_client(tmp) << "\n"; for (int i = 0; i != 20; ++i)
s << "as ascii: ";
for (peer_id::iterator i = tmp.begin(); i != tmp.end(); ++i)
{ {
if (std::isprint(*i)) s << *i; if (isprint(recv_buffer.begin[i])) ascii_pid[i] = recv_buffer.begin[i];
else s << "."; else ascii_pid[i] = '.';
} }
s << "\n"; char msg[200];
(*m_logger) << s.str(); snprintf(msg, 200, "received peer_id: %s client: %s\nas ascii: %s\n"
, hex_pid, identify_client(peer_id(recv_buffer.begin)).c_str(), ascii_pid);
(*m_logger) << msg;
} }
#endif #endif
peer_id pid; peer_id pid;
@ -2875,9 +2873,9 @@ namespace libtorrent
{ {
m_statistics.received_bytes(0, bytes_transferred); m_statistics.received_bytes(0, bytes_transferred);
// packet too large // packet too large
std::stringstream msg; char msg[200];
msg << "packet > 1 MB (" << (unsigned int)packet_size << " bytes)"; printf("packet > 1 MB (%u bytes)", (unsigned int)packet_size);
disconnect(msg.str().c_str(), 2); disconnect(msg, 2);
return; return;
} }

View File

@ -33,8 +33,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/pch.hpp" #include "libtorrent/pch.hpp"
#include <algorithm> #include <algorithm>
#include <iostream> #if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM
#include <iomanip> #include <iomanip>
#include <iostream>
#endif
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include "libtorrent/entry.hpp" #include "libtorrent/entry.hpp"
#include "libtorrent/config.hpp" #include "libtorrent/config.hpp"
@ -353,6 +355,7 @@ namespace libtorrent
TORRENT_ASSERT(false); TORRENT_ASSERT(false);
} }
#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM
void entry::print(std::ostream& os, int indent) const void entry::print(std::ostream& os, int indent) const
{ {
TORRENT_ASSERT(indent >= 0); TORRENT_ASSERT(indent >= 0);
@ -415,5 +418,6 @@ namespace libtorrent
os << "<uninitialized>\n"; os << "<uninitialized>\n";
} }
} }
#endif
} }

View File

@ -33,12 +33,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/pch.hpp" #include "libtorrent/pch.hpp"
#include <string> #include <string>
#include <stdexcept>
#include <sstream>
#include <iomanip>
#include <cctype> #include <cctype>
#include <algorithm> #include <algorithm>
#include <iostream>
#include <limits> #include <limits>
#include <cstring> #include <cstring>
@ -54,7 +50,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <windows.h> #include <windows.h>
#endif #endif
#include <boost/filesystem/exception.hpp>
#include "libtorrent/utf8.hpp" #include "libtorrent/utf8.hpp"
#endif #endif
@ -150,20 +145,21 @@ namespace libtorrent
return ret; return ret;
} }
// http://www.ietf.org/rfc/rfc2396.txt
// section 2.3
// some trackers seems to require that ' is escaped
//static const char unreserved_chars[] = "-_.!~*'()";
static const char unreserved_chars[] = "/-_.!~*()"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
"0123456789";
static const char hex_chars[] = "0123456789abcdef";
std::string escape_string(const char* str, int len) std::string escape_string(const char* str, int len)
{ {
TORRENT_ASSERT(str != 0); TORRENT_ASSERT(str != 0);
TORRENT_ASSERT(len >= 0); TORRENT_ASSERT(len >= 0);
// http://www.ietf.org/rfc/rfc2396.txt
// section 2.3
// some trackers seems to require that ' is escaped
// static const char unreserved_chars[] = "-_.!~*'()";
static const char unreserved_chars[] = "-_.!~*()"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
"0123456789";
std::stringstream ret; std::string ret;
ret << std::hex << std::setfill('0');
for (int i = 0; i < len; ++i) for (int i = 0; i < len; ++i)
{ {
if (std::count( if (std::count(
@ -171,29 +167,25 @@ namespace libtorrent
, unreserved_chars+sizeof(unreserved_chars)-1 , unreserved_chars+sizeof(unreserved_chars)-1
, *str)) , *str))
{ {
ret << *str; ret += *str;
} }
else else
{ {
ret << '%' ret += '%';
<< std::setw(2) ret += hex_chars[((unsigned int)*str) >> 4];
<< (int)static_cast<unsigned char>(*str); ret += hex_chars[((unsigned int)*str) & 15];
} }
++str; ++str;
} }
return ret.str(); return ret;
} }
std::string escape_path(const char* str, int len) std::string escape_path(const char* str, int len)
{ {
TORRENT_ASSERT(str != 0); TORRENT_ASSERT(str != 0);
TORRENT_ASSERT(len >= 0); TORRENT_ASSERT(len >= 0);
static const char unreserved_chars[] = "/-_.!~*()"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
"0123456789";
std::stringstream ret; std::string ret;
ret << std::hex << std::setfill('0');
for (int i = 0; i < len; ++i) for (int i = 0; i < len; ++i)
{ {
if (std::count( if (std::count(
@ -201,17 +193,17 @@ namespace libtorrent
, unreserved_chars+sizeof(unreserved_chars)-1 , unreserved_chars+sizeof(unreserved_chars)-1
, *str)) , *str))
{ {
ret << *str; ret += *str;
} }
else else
{ {
ret << '%' ret += '%';
<< std::setw(2) ret += hex_chars[((unsigned int)*str) >> 4];
<< (int)static_cast<unsigned char>(*str); ret += hex_chars[((unsigned int)*str) & 15];
} }
++str; ++str;
} }
return ret.str(); return ret;
} }
std::string base64encode(const std::string& s) std::string base64encode(const std::string& s)
@ -400,15 +392,46 @@ namespace libtorrent
TORRENT_EXPORT std::string to_hex(std::string const& s) TORRENT_EXPORT std::string to_hex(std::string const& s)
{ {
std::string ret; std::string ret;
char const* digits = "0123456789abcdef";
for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) for (std::string::const_iterator i = s.begin(); i != s.end(); ++i)
{ {
ret += digits[((unsigned char)*i) >> 4]; ret += hex_chars[((unsigned char)*i) >> 4];
ret += digits[((unsigned char)*i) & 0xf]; ret += hex_chars[((unsigned char)*i) & 0xf];
} }
return ret; return ret;
} }
TORRENT_EXPORT void to_hex(char const *in, int len, char* out)
{
for (char const* end = in + len; in < end; ++in)
{
*out++ = hex_chars[((unsigned char)*in) >> 4];
*out++ = hex_chars[((unsigned char)*in) & 0xf];
}
*out = '\0';
}
int hex_to_int(char in)
{
if (in >= '0' && in <= '9') return int(in) - '0';
if (in >= 'A' && in <= 'F') return int(in) - 'A' + 10;
if (in >= 'a' && in <= 'f') return int(in) - 'a' + 10;
return -1;
}
TORRENT_EXPORT bool from_hex(char const *in, int len, char* out)
{
for (char const* end = in + len; in < end; ++in, ++out)
{
int t = hex_to_int(*in);
if (t == -1) return false;
*out = t << 4;
t = hex_to_int(*in);
if (t == -1) return false;
*out |= t & 15;
}
return true;
}
#if TORRENT_USE_WPATH #if TORRENT_USE_WPATH
std::wstring convert_to_wstring(std::string const& s) std::wstring convert_to_wstring(std::string const& s)
{ {

View File

@ -35,8 +35,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/file_pool.hpp" #include "libtorrent/file_pool.hpp"
#include "libtorrent/error_code.hpp" #include "libtorrent/error_code.hpp"
#include <iostream>
namespace libtorrent namespace libtorrent
{ {
using boost::multi_index::nth_index; using boost::multi_index::nth_index;

View File

@ -33,11 +33,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/pch.hpp" #include "libtorrent/pch.hpp"
#include <vector> #include <vector>
#include <iostream>
#include <iomanip>
#include <limits> #include <limits>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <sstream>
#include "libtorrent/http_seed_connection.hpp" #include "libtorrent/http_seed_connection.hpp"
#include "libtorrent/session.hpp" #include "libtorrent/session.hpp"
@ -355,9 +352,9 @@ namespace libtorrent
// add the redirected url and remove the current one // add the redirected url and remove the current one
t->add_web_seed(location, web_seed_entry::http_seed); t->add_web_seed(location, web_seed_entry::http_seed);
t->remove_web_seed(m_url, web_seed_entry::http_seed); t->remove_web_seed(m_url, web_seed_entry::http_seed);
std::stringstream msg; char msg[200];
msg << "redirecting to \"" << location << "\""; snprintf(msg, 200, "redirecting to \"%s\"", location.c_str());
disconnect(msg.str().c_str()); disconnect(msg, 2);
return; return;
} }

View File

@ -33,10 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/pch.hpp" #include "libtorrent/pch.hpp"
#include <vector> #include <vector>
#include <iostream>
#include <cctype> #include <cctype>
#include <iomanip>
#include <sstream>
#include <algorithm> #include <algorithm>
#include "libtorrent/config.hpp" #include "libtorrent/config.hpp"
@ -148,9 +145,9 @@ namespace libtorrent
} }
url += "&key="; url += "&key=";
std::stringstream key_string; char key[200];
key_string << std::hex << tracker_req().key; snprintf(key, 200, "%x", tracker_req().key);
url += key_string.str(); url += key;
url += "&compact=1"; url += "&compact=1";

View File

@ -34,7 +34,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/ip_filter.hpp" #include "libtorrent/ip_filter.hpp"
#include <boost/utility.hpp> #include <boost/utility.hpp>
//#include <iostream>
namespace libtorrent namespace libtorrent

View File

@ -893,7 +893,9 @@ namespace libtorrent { namespace dht
ret["nodes"] = nodes; ret["nodes"] = nodes;
} }
ret["node-id"] = boost::lexical_cast<std::string>(m_dht.nid()); char node_id[41];
to_hex((char*)&m_dht.nid()[0], 20, node_id);
ret["node-id"] = node_id;
return ret; return ret;
} }

View File

@ -32,9 +32,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/lazy_entry.hpp" #include "libtorrent/lazy_entry.hpp"
#include "libtorrent/escape_string.hpp" #include "libtorrent/escape_string.hpp"
#include <cstring>
#if TORRENT_USE_IOSTREAM
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <cstring> #endif
namespace namespace
{ {
@ -363,6 +366,7 @@ namespace libtorrent
return return_t(m_begin, m_end - m_begin); return return_t(m_begin, m_end - m_begin);
} }
#if TORRENT_USE_IOSTREAM
std::ostream& operator<<(std::ostream& os, lazy_entry const& e) std::ostream& operator<<(std::ostream& os, lazy_entry const& e)
{ {
switch (e.type()) switch (e.type())
@ -431,6 +435,6 @@ namespace libtorrent
} }
return os; return os;
} }
#endif // TORRENT_USE_IOSTREAM
}; };

View File

@ -52,6 +52,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/peer_request.hpp" #include "libtorrent/peer_request.hpp"
#include "libtorrent/peer_connection.hpp" #include "libtorrent/peer_connection.hpp"
#if TORRENT_USE_IOSTREAM
namespace libtorrent { namespace libtorrent {
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
@ -229,4 +231,5 @@ namespace libtorrent
} }
#endif

View File

@ -83,17 +83,19 @@ void lsd::announce(sha1_hash const& ih, int listen_port)
{ {
if (m_disabled) return; if (m_disabled) return;
std::stringstream btsearch; char ih_hex[41];
btsearch << "BT-SEARCH * HTTP/1.1\r\n" to_hex((char const*)&ih[0], 20, ih_hex);
char msg[200];
int msg_len = snprintf(msg, 200,
"BT-SEARCH * HTTP/1.1\r\n"
"Host: 239.192.152.143:6771\r\n" "Host: 239.192.152.143:6771\r\n"
"Port: " << to_string(listen_port).elems << "\r\n" "Port: %d\r\n"
"Infohash: " << ih << "\r\n" "Infohash: %s\r\n"
"\r\n\r\n"; "\r\n\r\n", listen_port, ih_hex);
std::string const& msg = btsearch.str();
m_retry_count = 1; m_retry_count = 1;
error_code ec; error_code ec;
m_socket.send(msg.c_str(), int(msg.size()), ec); m_socket.send(msg, msg_len, ec);
if (ec) if (ec)
{ {
m_disabled = true; m_disabled = true;
@ -101,8 +103,9 @@ void lsd::announce(sha1_hash const& ih, int listen_port)
} }
#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) #if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
m_log << time_now_string() snprintf(msg, 200, "%s ==> announce: ih: %s port: %u\n"
<< " ==> announce: ih: " << ih << " port: " << to_string(listen_port).elems << std::endl; , time_now_string(), ih_hex, listen_port);
m_log << msg;
#endif #endif
m_broadcast_timer.expires_from_now(milliseconds(250 * m_retry_count), ec); m_broadcast_timer.expires_from_now(milliseconds(250 * m_retry_count), ec);
@ -174,16 +177,16 @@ void lsd::on_announce(udp::endpoint const& from, char* buffer
} }
sha1_hash ih(0); sha1_hash ih(0);
std::istringstream ih_sstr(ih_str); from_hex(ih_str.c_str(), 40, (char*)&ih[0]);
ih_sstr >> ih;
int port = std::atoi(port_str.c_str()); int port = std::atoi(port_str.c_str());
if (!ih.is_all_zeros() && port != 0) if (!ih.is_all_zeros() && port != 0)
{ {
#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) #if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
m_log << time_now_string() char msg[200];
<< " *** incoming local announce " << from.address() snprintf(msg, 200, "%s *** incoming local announce %s:%d ih: %s\n"
<< ":" << to_string(port).elems << " ih: " << ih << std::endl; , time_now_string(), print_address(from.address()).c_str()
, port, ih_str.c_str());
#endif #endif
// we got an announce, pass it on through the callback // we got an announce, pass it on through the callback
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS

View File

@ -33,8 +33,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/pch.hpp" #include "libtorrent/pch.hpp"
#include <vector> #include <vector>
#include <iostream>
#include <iomanip>
#include <limits> #include <limits>
#include <boost/bind.hpp> #include <boost/bind.hpp>
@ -1395,11 +1393,10 @@ namespace libtorrent
if (t->valid_metadata() if (t->valid_metadata()
&& (bits.size() + 7) / 8 != (m_have_piece.size() + 7) / 8) && (bits.size() + 7) / 8 != (m_have_piece.size() + 7) / 8)
{ {
std::stringstream msg; char msg[200];
msg << "got bitfield with invalid size: " << ((bits.size() + 7) / 8) snprintf(msg, 200, "got bitfield with invalid size: %d bytes. expected: %d bytes"
<< "bytes. expected: " << ((m_have_piece.size() + 7) / 8) , int((bits.size() + 7) / 8), int((m_have_piece.size() + 7) / 8));
<< " bytes"; disconnect(msg, 2);
disconnect(msg.str().c_str(), 2);
return; return;
} }

View File

@ -32,8 +32,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/pch.hpp" #include "libtorrent/pch.hpp"
#include <iostream>
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push, 1) #pragma warning(push, 1)
#endif #endif
@ -834,9 +832,12 @@ namespace libtorrent
// it again. // it again.
error_code ec; error_code ec;
m_torrent->debug_log("already connected to peer: " + remote.address().to_string(ec) + ":" char hex_pid[41];
+ boost::lexical_cast<std::string>(remote.port()) + " " to_hex((char*)&i->second.connection->pid()[0], 20, hex_pid);
+ boost::lexical_cast<std::string>(i->second.connection->pid())); char msg[200];
snprintf(msg, 200, "already connected to peer: %s %s"
, print_endpoint(remote).c_str(), hex_pid);
m_torrent->debug_log(msg);
TORRENT_ASSERT(i->second.connection->associated_torrent().lock().get() == m_torrent); TORRENT_ASSERT(i->second.connection->associated_torrent().lock().get() == m_torrent);
} }

View File

@ -33,9 +33,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/pch.hpp" #include "libtorrent/pch.hpp"
#include <ctime> #include <ctime>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <iterator> #include <iterator>
#include <algorithm> #include <algorithm>
#include <set> #include <set>

View File

@ -672,10 +672,10 @@ namespace aux {
if (m_alerts.should_post<listen_failed_alert>()) if (m_alerts.should_post<listen_failed_alert>())
m_alerts.post_alert(listen_failed_alert(ep, ec)); m_alerts.post_alert(listen_failed_alert(ep, ec));
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
std::stringstream msg; char msg[200];
msg << "cannot bind to interface '"; snprintf(msg, 200, "cannot bind to interface \"%s\": %s"
print_endpoint(msg, ep) << "' " << ec.message(); , print_endpoint(ep).c_str(), ec.message().c_str());
(*m_logger) << msg.str() << "\n"; (*m_logger) << msg << "\n";
#endif #endif
return listen_socket_t(); return listen_socket_t();
} }
@ -686,10 +686,10 @@ namespace aux {
if (m_alerts.should_post<listen_failed_alert>()) if (m_alerts.should_post<listen_failed_alert>())
m_alerts.post_alert(listen_failed_alert(ep, ec)); m_alerts.post_alert(listen_failed_alert(ep, ec));
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
std::stringstream msg; char msg[200];
msg << "cannot listen on interface '"; snprintf(msg, 200, "cannot listen on interface \"%s\": %s"
print_endpoint(msg, ep) << "' " << ec.message(); , print_endpoint(ep).c_str(), ec.message().c_str());
(*m_logger) << msg.str() << "\n"; (*m_logger) << msg << "\n";
#endif #endif
return listen_socket_t(); return listen_socket_t();
} }

View File

@ -45,8 +45,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/filesystem/convenience.hpp> #include <boost/filesystem/convenience.hpp>
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/ref.hpp> #include <boost/ref.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/version.hpp> #include <boost/version.hpp>
@ -72,13 +70,15 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/disk_buffer_holder.hpp" #include "libtorrent/disk_buffer_holder.hpp"
#include "libtorrent/alloca.hpp" #include "libtorrent/alloca.hpp"
#include <cstdio>
//#define TORRENT_PARTIAL_HASH_LOG //#define TORRENT_PARTIAL_HASH_LOG
#ifdef TORRENT_DEBUG #if TORRENT_USE_IOSTREAM
#include <boost/filesystem/fstream.hpp>
#include <ios> #include <ios>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <cstdio>
#endif #endif
#if defined(__APPLE__) #if defined(__APPLE__)
@ -110,7 +110,7 @@ using boost::bind;
using namespace ::boost::multi_index; using namespace ::boost::multi_index;
using boost::multi_index::multi_index_container; using boost::multi_index::multi_index_container;
#if defined TORRENT_DEBUG && defined TORRENT_STORAGE_DEBUG #if defined TORRENT_DEBUG && defined TORRENT_STORAGE_DEBUG && TORRENT_USE_IOSTREAM
namespace namespace
{ {
using namespace libtorrent; using namespace libtorrent;
@ -1644,7 +1644,7 @@ ret:
// only save the partial hash if the write succeeds // only save the partial hash if the write succeeds
if (ret != size) return ret; if (ret != size) return ret;
#ifdef TORRENT_PARTIAL_HASH_LOG #if defined TORRENT_PARTIAL_HASH_LOG && TORRENT_USE_IOSTREAM
std::ofstream out("partial_hash.log", std::ios::app); std::ofstream out("partial_hash.log", std::ios::app);
#endif #endif
@ -1657,7 +1657,7 @@ ret:
for (file::iovec_t* i = iov, *end(iov + num_bufs); i < end; ++i) for (file::iovec_t* i = iov, *end(iov + num_bufs); i < end; ++i)
ph.h.update((char const*)i->iov_base, i->iov_len); ph.h.update((char const*)i->iov_base, i->iov_len);
#ifdef TORRENT_PARTIAL_HASH_LOG #if defined TORRENT_PARTIAL_HASH_LOG && TORRENT_USE_IOSTREAM
out << time_now_string() << " NEW [" out << time_now_string() << " NEW ["
" s: " << this " s: " << this
<< " p: " << piece_index << " p: " << piece_index
@ -2713,7 +2713,7 @@ ret:
&& m_slot_to_piece[piece_index] >= 0) && m_slot_to_piece[piece_index] >= 0)
{ {
#if defined TORRENT_DEBUG && defined TORRENT_STORAGE_DEBUG #if defined TORRENT_DEBUG && defined TORRENT_STORAGE_DEBUG && TORRENT_USE_IOSTREAM
std::stringstream s; std::stringstream s;
s << "there is another piece at our slot, swapping.."; s << "there is another piece at our slot, swapping..";
@ -2953,7 +2953,7 @@ ret:
} }
} }
#ifdef TORRENT_STORAGE_DEBUG #ifdef TORRENT_STORAGE_DEBUG && TORRENT_USE_IOSTREAM
void piece_manager::debug_log() const void piece_manager::debug_log() const
{ {
std::stringstream s; std::stringstream s;

View File

@ -33,8 +33,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/pch.hpp" #include "libtorrent/pch.hpp"
#include <ctime> #include <ctime>
#include <fstream>
#include <iomanip>
#include <iterator> #include <iterator>
#include <algorithm> #include <algorithm>
#include <set> #include <set>
@ -79,6 +77,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/assert.hpp" #include "libtorrent/assert.hpp"
#include "libtorrent/broadcast_socket.hpp" #include "libtorrent/broadcast_socket.hpp"
#if TORRENT_USE_IOSTREAM
#include <iostream>
#endif
using namespace libtorrent; using namespace libtorrent;
using boost::tuples::tuple; using boost::tuples::tuple;
using boost::tuples::get; using boost::tuples::get;
@ -1166,7 +1168,7 @@ namespace libtorrent
if (complete >= 0 && incomplete >= 0) if (complete >= 0 && incomplete >= 0)
m_last_scrape = now; m_last_scrape = now;
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING #if (defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING) && TORRENT_USE_IOSTREAM
std::stringstream s; std::stringstream s;
s << "TRACKER RESPONSE:\n" s << "TRACKER RESPONSE:\n"
"interval: " << interval << "\n" "interval: " << interval << "\n"
@ -2783,10 +2785,10 @@ namespace libtorrent
{ {
if (m_ses.m_alerts.should_post<url_seed_alert>()) if (m_ses.m_alerts.should_post<url_seed_alert>())
{ {
std::stringstream msg; char msg[200];
msg << "HTTP seed hostname lookup failed: " << e.message(); snprintf(msg, 200, "HTTP seed hostname lookup failed: %s", e.message().c_str());
m_ses.m_alerts.post_alert( m_ses.m_alerts.post_alert(
url_seed_alert(get_handle(), web.url, msg.str())); url_seed_alert(get_handle(), web.url, msg));
} }
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
(*m_ses.m_logger) << " ** HOSTNAME LOOKUP FAILED!**: " << web.url << "\n"; (*m_ses.m_logger) << " ** HOSTNAME LOOKUP FAILED!**: " << web.url << "\n";

View File

@ -33,9 +33,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/pch.hpp" #include "libtorrent/pch.hpp"
#include <ctime> #include <ctime>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <iterator> #include <iterator>
#include <algorithm> #include <algorithm>
#include <set> #include <set>

View File

@ -33,9 +33,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/pch.hpp" #include "libtorrent/pch.hpp"
#include <ctime> #include <ctime>
#if !defined TORRENT_NO_DEPRECATE && TORRENT_USE_IOSTREAM
#include <iostream> #include <iostream>
#include <fstream>
#include <iomanip> #include <iomanip>
#endif
#include <iterator> #include <iterator>
#include <algorithm> #include <algorithm>
#include <set> #include <set>
@ -903,7 +906,7 @@ namespace libtorrent
< bind(&announce_entry::tier, _2)); < bind(&announce_entry::tier, _2));
} }
#ifndef TORRENT_NO_DEPRECATE #if !defined TORRENT_NO_DEPRECATE && TORRENT_USE_IOSTREAM
// ------- start deprecation ------- // ------- start deprecation -------
void torrent_info::print(std::ostream& os) const void torrent_info::print(std::ostream& os) const

View File

@ -33,10 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/pch.hpp" #include "libtorrent/pch.hpp"
#include <vector> #include <vector>
#include <iostream>
#include <cctype> #include <cctype>
#include <iomanip>
#include <sstream>
#include <boost/bind.hpp> #include <boost/bind.hpp>

View File

@ -33,10 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/pch.hpp" #include "libtorrent/pch.hpp"
#include <vector> #include <vector>
#include <iostream>
#include <cctype> #include <cctype>
#include <iomanip>
#include <sstream>
#include "zlib.h" #include "zlib.h"
@ -46,11 +43,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/bind.hpp> #include <boost/bind.hpp>
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
#include <boost/lexical_cast.hpp>
using boost::lexical_cast;
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
#endif #endif
@ -195,9 +187,9 @@ namespace libtorrent
{ {
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
boost::shared_ptr<request_callback> cb = requester(); boost::shared_ptr<request_callback> cb = requester();
std::stringstream msg; char msg[200];
msg << "*** UDP_TRACKER [ timed out url: " << tracker_req().url << " ]"; snprintf(msg, 200, "*** UDP_TRACKER [ timed out url: %s ]", tracker_req().url.c_str());
if (cb) cb->debug_log(msg.str().c_str()); if (cb) cb->debug_log(msg);
#endif #endif
m_socket.close(); m_socket.close();
m_name_lookup.cancel(); m_name_lookup.cancel();
@ -230,9 +222,9 @@ namespace libtorrent
boost::shared_ptr<request_callback> cb = requester(); boost::shared_ptr<request_callback> cb = requester();
if (cb) if (cb)
{ {
std::stringstream msg; char msg[200];
msg << "<== UDP_TRACKER_PACKET [ size: " << size << " ]"; snprintf(msg, 200, "<== UDP_TRACKER_PACKET [ size: %d ]", size);
cb->debug_log(msg.str()); cb->debug_log(msg);
} }
#endif #endif
@ -248,9 +240,9 @@ namespace libtorrent
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
if (cb) if (cb)
{ {
std::stringstream msg; char msg[200];
msg << "*** UDP_TRACKER_PACKET [ acton: " << action << " ]"; snprintf(msg, 200, "*** UDP_TRACKER_PACKET [ action: %d ]", action);
cb->debug_log(msg.str()); cb->debug_log(msg);
} }
#endif #endif
@ -269,9 +261,10 @@ namespace libtorrent
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
if (cb) if (cb)
{ {
std::stringstream msg; char msg[200];
msg << "*** UDP_TRACKER_RESPONSE [ cid: " << m_connection_id << " ]"; snprintf(msg, 200, "*** UDP_TRACKER_RESPONSE [ cid: %x%x ]"
cb->debug_log(msg.str()); , int(m_connection_id >> 32), int(m_connection_id & 0xffffffff));
cb->debug_log(msg);
} }
#endif #endif
@ -315,8 +308,11 @@ namespace libtorrent
boost::shared_ptr<request_callback> cb = requester(); boost::shared_ptr<request_callback> cb = requester();
if (cb) if (cb)
{ {
cb->debug_log("==> UDP_TRACKER_CONNECT [" char hex_ih[41];
+ lexical_cast<std::string>(tracker_req().info_hash) + "]"); to_hex((char const*)&tracker_req().info_hash[0], 20, hex_ih);
char msg[200];
snprintf(msg, 200, "==> UDP_TRACKER_CONNECT [%s]", hex_ih);
cb->debug_log(msg);
} }
#endif #endif
if (!m_socket.is_open()) return; // the operation was aborted if (!m_socket.is_open()) return; // the operation was aborted
@ -398,9 +394,9 @@ namespace libtorrent
if (cb) if (cb)
{ {
boost::shared_ptr<request_callback> cb = requester(); boost::shared_ptr<request_callback> cb = requester();
std::stringstream msg; char msg[200];
msg << "<== UDP_ANNOUNCE_RESPONSE [ url: " << tracker_req().url << " ]"; snprintf(msg, 200, "<== UDP_TRACKER_RESPONSE [ url: %s ]", tracker_req().url.c_str());
cb->debug_log(msg.str().c_str()); cb->debug_log(msg);
} }
#endif #endif
@ -415,12 +411,13 @@ namespace libtorrent
{ {
// TODO: don't use a string here // TODO: don't use a string here
peer_entry e; peer_entry e;
std::stringstream s; char ip_string[100];
s << (int)detail::read_uint8(buf) << "."; unsigned int a = detail::read_uint8(buf);
s << (int)detail::read_uint8(buf) << "."; unsigned int b = detail::read_uint8(buf);
s << (int)detail::read_uint8(buf) << "."; unsigned int c = detail::read_uint8(buf);
s << (int)detail::read_uint8(buf); unsigned int d = detail::read_uint8(buf);
e.ip = s.str(); snprintf(ip_string, 100, "%u.%u.%u.%u", a, b, c, d);
e.ip = ip_string;
e.port = detail::read_uint16(buf); e.port = detail::read_uint16(buf);
e.pid.clear(); e.pid.clear();
peer_list.push_back(e); peer_list.push_back(e);
@ -521,11 +518,11 @@ namespace libtorrent
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
boost::shared_ptr<request_callback> cb = requester(); boost::shared_ptr<request_callback> cb = requester();
if (cb) char hex_ih[41];
{ to_hex((char const*)&req.info_hash[0], 20, hex_ih);
cb->debug_log("==> UDP_TRACKER_ANNOUNCE [" char msg[200];
+ lexical_cast<std::string>(req.info_hash) + "]"); snprintf(msg, 200, "==> UDP_TRACKER_ANNOUNCE [%s]", hex_ih);
} cb->debug_log(msg);
#endif #endif
error_code ec; error_code ec;

View File

@ -33,11 +33,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/pch.hpp" #include "libtorrent/pch.hpp"
#include <vector> #include <vector>
#include <iostream>
#include <iomanip>
#include <limits> #include <limits>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <sstream>
#include <stdlib.h> #include <stdlib.h>
#include "libtorrent/web_peer_connection.hpp" #include "libtorrent/web_peer_connection.hpp"
@ -448,19 +445,19 @@ namespace libtorrent
if (i == std::string::npos) if (i == std::string::npos)
{ {
t->remove_web_seed(m_url, web_seed_entry::url_seed); t->remove_web_seed(m_url, web_seed_entry::url_seed);
std::stringstream msg; char msg[200];
msg << "got invalid HTTP redirection location (\"" << location << "\") " snprintf(msg, 200, "got invalid HTTP redirection location (\"%s\") "
"expected it to end with: " << path; "expected it to end with: %s", location.c_str(), path.c_str());
disconnect(msg.str().c_str(), 2); disconnect(msg, 2);
return; return;
} }
location.resize(i); location.resize(i);
} }
t->add_web_seed(location, web_seed_entry::url_seed); t->add_web_seed(location, web_seed_entry::url_seed);
t->remove_web_seed(m_url, web_seed_entry::url_seed); t->remove_web_seed(m_url, web_seed_entry::url_seed);
std::stringstream msg; char msg[200];
msg << "redirecting to \"" << location << "\""; snprintf(msg, 200, "redirecting to \"%s\"", location.c_str());
disconnect(msg.str().c_str()); disconnect(msg, 2);
return; return;
} }
@ -488,17 +485,29 @@ namespace libtorrent
size_type range_end; size_type range_end;
if (m_parser.status_code() == 206) if (m_parser.status_code() == 206)
{ {
std::stringstream range_str(m_parser.header("content-range")); std::string const& range_str = m_parser.header("content-range");
char dummy;
std::string bytes; bool success = true;
range_str >> bytes >> range_start >> dummy >> range_end; char const* ptr = range_str.c_str();
if (!range_str) char* end;
range_start = strtoll(ptr, &end, 10);
if (end == ptr) success = false;
else if (*end != '-') success = false;
else
{
ptr = end + 1;
range_end = strtoll(ptr, &end, 10);
if (end == ptr) success = false;
}
if (!success)
{ {
// we should not try this server again. // we should not try this server again.
t->remove_web_seed(m_url, web_seed_entry::url_seed); t->remove_web_seed(m_url, web_seed_entry::url_seed);
std::stringstream msg; char msg[200];
msg << "invalid range in HTTP response: " << range_str.str(); snprintf(msg, 200, "invalid range in HTTP response: %s"
disconnect(msg.str().c_str(), 2); , range_str.c_str());
disconnect(msg, 2);
return; return;
} }
// the http range is inclusive // the http range is inclusive