From c9392fe0fb1b48258d9fb1653a1d3c2aa0a09fd0 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 30 Oct 2009 03:42:29 +0000 Subject: [PATCH] fixed web seed for windows --- include/libtorrent/escape_string.hpp | 3 +++ src/escape_string.cpp | 7 +++++++ src/web_peer_connection.cpp | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/include/libtorrent/escape_string.hpp b/include/libtorrent/escape_string.hpp index 46c4160ab..cfcdf0338 100644 --- a/include/libtorrent/escape_string.hpp +++ b/include/libtorrent/escape_string.hpp @@ -75,6 +75,9 @@ namespace libtorrent TORRENT_EXPORT boost::optional url_has_argument( std::string const& url, std::string argument); + // replaces \ with / + TORRENT_EXPORT void convert_path_to_posix(std::string& path); + TORRENT_EXPORT std::string read_until(char const*& str, char delim, char const* end); TORRENT_EXPORT std::string to_hex(std::string const& s); TORRENT_EXPORT bool is_hex(char const *in, int len); diff --git a/src/escape_string.cpp b/src/escape_string.cpp index a57ed97b6..ea48c8024 100644 --- a/src/escape_string.cpp +++ b/src/escape_string.cpp @@ -264,6 +264,13 @@ namespace libtorrent return false; } + void convert_path_to_posix(std::string& path) + { + for (std::string::iterator i = path.begin() + , end(path.end()); i != end; ++i) + if (*i == '\\') *i = '/'; + } + std::string read_until(char const*& str, char delim, char const* end) { TORRENT_ASSERT(str <= end); diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index 94c6fa892..73d390937 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -261,12 +261,18 @@ namespace libtorrent { request += m_url; std::string path = info.orig_files().at(f.file_index).path; +#ifdef TORRENT_WINDOWS + convert_path_to_posix(path); +#endif request += escape_path(path.c_str(), path.length()); } else { std::string path = m_path; path += info.orig_files().at(f.file_index).path; +#ifdef TORRENT_WINDOWS + convert_path_to_posix(path); +#endif request += escape_path(path.c_str(), path.length()); } request += " HTTP/1.1\r\n"; @@ -453,6 +459,9 @@ namespace libtorrent torrent_info const& info = t->torrent_file(); std::string path = info.orig_files().at(file_index).path; +#ifdef TORRENT_WINDOWS + convert_path_to_posix(path); +#endif path = escape_path(path.c_str(), path.length()); size_t i = location.rfind(path); if (i == std::string::npos)