From 1fbb33f6d2e3adeb5bd5c738e739f2b92d472474 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 11 Oct 2004 21:50:04 +0000 Subject: [PATCH] *** empty log message *** --- include/libtorrent/tracker_manager.hpp | 2 ++ src/session.cpp | 15 +++++---- src/torrent_info.cpp | 4 +-- src/tracker_manager.cpp | 45 ++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index 3d96551e9..69f868dba 100755 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -62,6 +62,8 @@ namespace libtorrent struct request_callback; class tracker_manager; + address parse_url(std::string const& url); + // encodes a string using the base64 scheme std::string base64encode(const std::string& s); diff --git a/src/session.cpp b/src/session.cpp index 95ea091bd..b9728e903 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -558,13 +558,16 @@ namespace libtorrent { namespace detail ++i) { connection_map::iterator p = m_connections.find(*i); - if (m_alerts.should_post(alert::debug)) + if (p != m_connections.end()) { - m_alerts.post_alert( - peer_error_alert( - p->first->sender() - , p->second->id() - , "connection closed")); + if (m_alerts.should_post(alert::debug)) + { + m_alerts.post_alert( + peer_error_alert( + p->first->sender() + , p->second->id() + , "connection closed")); + } } m_selector.remove(*i); diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index da6a6a605..8c28477cf 100755 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -369,11 +369,11 @@ namespace libtorrent if (m_files.size() == 1) { - info["name"] = m_files.front().path.string(); + info["name"] = m_name; } else { - info["name"] = m_files.front().path.root_name(); + info["name"] = m_name; } if (m_files.size() > 1) diff --git a/src/tracker_manager.cpp b/src/tracker_manager.cpp index 0022fcb13..baad832c2 100755 --- a/src/tracker_manager.cpp +++ b/src/tracker_manager.cpp @@ -74,6 +74,51 @@ namespace namespace libtorrent { + address parse_url(std::string const& url) + { + std::string hostname; // hostname only + int port = 80; + + // PARSE URL + std::string::const_iterator start = url.begin(); + std::string::const_iterator end + = std::find(url.begin(), url.end(), ':'); + + if (end == url.end()) throw std::runtime_error("invalid url"); + ++end; + if (end == url.end()) throw std::runtime_error("invalid url"); + if (*end != '/') throw std::runtime_error("invalid url"); + ++end; + if (end == url.end()) throw std::runtime_error("invalid url"); + if (*end != '/') throw std::runtime_error("invalid url"); + ++end; + start = end; + + end = std::find(start, url.end(), '/'); + std::string::const_iterator port_pos + = std::find(start, url.end(), ':'); + + if (port_pos < end) + { + hostname.assign(start, port_pos); + ++port_pos; + try + { + port = boost::lexical_cast(std::string(port_pos, end)); + } + catch(boost::bad_lexical_cast&) + { + throw std::runtime_error("invalid url: \"" + url + "\""); + } + } + else + { + hostname.assign(start, end); + } + + return address(hostname.c_str(), port); + } + // returns -1 if gzip header is invalid or the header size in bytes int gzip_header(const char* buf, int size) {