diff --git a/include/libtorrent/escape_string.hpp b/include/libtorrent/escape_string.hpp index 98317464b..f24923015 100644 --- a/include/libtorrent/escape_string.hpp +++ b/include/libtorrent/escape_string.hpp @@ -45,7 +45,8 @@ namespace libtorrent { boost::array::digits10> TORRENT_EXPORT to_string(size_type n); bool TORRENT_EXPORT is_digit(char c); - bool TORRENT_EXPORT isprint(char c); + bool TORRENT_EXPORT is_print(char c); + bool TORRENT_EXPORT is_space(char c); char TORRENT_EXPORT to_lower(char c); bool TORRENT_EXPORT string_begins_no_case(char const* s1, char const* s2); diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index efb6c3c9c..8b394856a 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -152,6 +152,12 @@ namespace libtorrent { return fails == 0; } + + void trim() + { + while (!url.empty() && is_space(url[0])) + url.erase(url.begin()); + } }; #ifndef BOOST_NO_EXCEPTIONS diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index d2b562687..66dbaf5de 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -49,6 +49,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/extensions.hpp" #include "libtorrent/aux_/session_impl.hpp" #include "libtorrent/broadcast_socket.hpp" +#include "libtorrent/escape_string.hpp" #ifndef TORRENT_DISABLE_ENCRYPTION #include "libtorrent/pe_crypto.hpp" @@ -2728,7 +2729,7 @@ namespace libtorrent char ascii_pid[21]; for (int i = 0; i != 20; ++i) { - if (isprint(recv_buffer.begin[i])) ascii_pid[i] = recv_buffer.begin[i]; + if (is_print(recv_buffer.begin[i])) ascii_pid[i] = recv_buffer.begin[i]; else ascii_pid[i] = '.'; } char msg[200]; diff --git a/src/entry.cpp b/src/entry.cpp index 0189f65fb..d23234c70 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -43,10 +43,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/escape_string.hpp" #if defined(_MSC_VER) -namespace std -{ - using ::isprint; -} #define for if (false) {} else for #endif @@ -370,7 +366,7 @@ namespace libtorrent bool binary_string = false; for (std::string::const_iterator i = string().begin(); i != string().end(); ++i) { - if (!std::isprint(static_cast(*i))) + if (!is_print(static_cast(*i))) { binary_string = true; break; @@ -395,7 +391,7 @@ namespace libtorrent bool binary_string = false; for (std::string::const_iterator k = i->first.begin(); k != i->first.end(); ++k) { - if (!std::isprint(static_cast(*k))) + if (!is_print(static_cast(*k))) { binary_string = true; break; diff --git a/src/escape_string.cpp b/src/escape_string.cpp index 7d16c748b..2190123c0 100644 --- a/src/escape_string.cpp +++ b/src/escape_string.cpp @@ -87,11 +87,16 @@ namespace libtorrent return c >= '0' && c <= '9'; } - bool isprint(char c) + bool is_print(char c) { return c >= 32 && c < 127; } + bool is_space(char c) + { + return c == ' ' || c == '\t'; + } + char to_lower(char c) { return (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c; diff --git a/src/identify_client.cpp b/src/identify_client.cpp index 7d54be02c..9bae799c4 100644 --- a/src/identify_client.cpp +++ b/src/identify_client.cpp @@ -69,7 +69,7 @@ namespace { fingerprint ret("..", 0, 0, 0, 0); - if (id[0] != '-' || !isprint(id[1]) || (id[2] < '0') + if (id[0] != '-' || !is_print(id[1]) || (id[2] < '0') || (id[3] < '0') || (id[4] < '0') || (id[5] < '0') || (id[6] < '0') || id[7] != '-') @@ -131,7 +131,7 @@ namespace ret.tag_version = 0; if (sscanf(ids, "%c%d-%d-%d--", &ret.name[0], &ret.major_version, &ret.minor_version , &ret.revision_version) != 4 - || !isprint(ret.name[0])) + || !is_print(ret.name[0])) return boost::optional(); return boost::optional(ret); @@ -384,7 +384,7 @@ namespace libtorrent std::string unknown("Unknown ["); for (peer_id::const_iterator i = p.begin(); i != p.end(); ++i) { - unknown += isprint(char(*i))?*i:'.'; + unknown += is_print(char(*i))?*i:'.'; } unknown += "]"; return unknown; diff --git a/src/lazy_bdecode.cpp b/src/lazy_bdecode.cpp index 1ede7972a..7fcf4e176 100644 --- a/src/lazy_bdecode.cpp +++ b/src/lazy_bdecode.cpp @@ -391,7 +391,7 @@ namespace libtorrent for (int i = 0; i < e.string_length(); ++i) { using namespace std; - if (isprint((unsigned char)str[i])) continue; + if (is_print((unsigned char)str[i])) continue; printable = false; break; } diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index dc1f56fa4..00bd709be 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -776,6 +776,7 @@ namespace libtorrent e.tier = j; e.fail_limit = 0; e.source = announce_entry::source_torrent; + e.trim(); m_urls.push_back(e); } } @@ -805,6 +806,7 @@ namespace libtorrent announce_entry e(torrent_file.dict_find_string_value("announce")); e.fail_limit = 0; e.source = announce_entry::source_torrent; + e.trim(); if (!e.url.empty()) m_urls.push_back(e); }