entry and scrape bug fix
This commit is contained in:
@@ -167,6 +167,8 @@ namespace libtorrent
|
|||||||
#endif
|
#endif
|
||||||
entry* find_key(char const* key);
|
entry* find_key(char const* key);
|
||||||
entry const* find_key(char const* key) const;
|
entry const* find_key(char const* key) const;
|
||||||
|
entry* find_key(std::string const& key);
|
||||||
|
entry const* find_key(std::string const& key) const;
|
||||||
|
|
||||||
void print(std::ostream& os, int indent = 0) const;
|
void print(std::ostream& os, int indent = 0) const;
|
||||||
|
|
||||||
|
@@ -142,6 +142,9 @@ namespace libtorrent
|
|||||||
iterator begin() { return m_number; }
|
iterator begin() { return m_number; }
|
||||||
iterator end() { return m_number+number_size; }
|
iterator end() { return m_number+number_size; }
|
||||||
|
|
||||||
|
std::string to_string() const
|
||||||
|
{ return std::string((char const*)&m_number[0], number_size); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
unsigned char m_number[number_size];
|
unsigned char m_number[number_size];
|
||||||
|
@@ -54,19 +54,6 @@ namespace
|
|||||||
TORRENT_ASSERT(o);
|
TORRENT_ASSERT(o);
|
||||||
o->~T();
|
o->~T();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct compare_string
|
|
||||||
{
|
|
||||||
compare_string(char const* s): m_str(s) {}
|
|
||||||
|
|
||||||
bool operator()(
|
|
||||||
std::pair<std::string
|
|
||||||
, libtorrent::entry> const& e) const
|
|
||||||
{
|
|
||||||
return m_str && e.first == m_str;
|
|
||||||
}
|
|
||||||
char const* m_str;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
@@ -94,6 +81,16 @@ namespace libtorrent
|
|||||||
}
|
}
|
||||||
|
|
||||||
entry& entry::operator[](char const* key)
|
entry& entry::operator[](char const* key)
|
||||||
|
{
|
||||||
|
dictionary_type::iterator i = dict().find(key);
|
||||||
|
if (i != dict().end()) return i->second;
|
||||||
|
dictionary_type::iterator ret = dict().insert(
|
||||||
|
dict().begin()
|
||||||
|
, std::make_pair(key, entry()));
|
||||||
|
return ret->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry& entry::operator[](std::string const& key)
|
||||||
{
|
{
|
||||||
dictionary_type::iterator i = dict().find(key);
|
dictionary_type::iterator i = dict().find(key);
|
||||||
if (i != dict().end()) return i->second;
|
if (i != dict().end()) return i->second;
|
||||||
@@ -103,21 +100,11 @@ namespace libtorrent
|
|||||||
return ret->second;
|
return ret->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
entry& entry::operator[](std::string const& key)
|
|
||||||
{
|
|
||||||
return (*this)[key.c_str()];
|
|
||||||
}
|
|
||||||
|
|
||||||
entry* entry::find_key(char const* key)
|
entry* entry::find_key(char const* key)
|
||||||
{
|
{
|
||||||
dictionary_type::iterator i = std::find_if(
|
dictionary_type::iterator i = dict().find(key);
|
||||||
dict().begin()
|
|
||||||
, dict().end()
|
|
||||||
, compare_string(key));
|
|
||||||
if (i == dict().end()) return 0;
|
if (i == dict().end()) return 0;
|
||||||
return &i->second;
|
return &i->second;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
entry const* entry::find_key(char const* key) const
|
entry const* entry::find_key(char const* key) const
|
||||||
@@ -127,6 +114,20 @@ namespace libtorrent
|
|||||||
return &i->second;
|
return &i->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entry* entry::find_key(std::string const& key)
|
||||||
|
{
|
||||||
|
dictionary_type::iterator i = dict().find(key);
|
||||||
|
if (i == dict().end()) return 0;
|
||||||
|
return &i->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry const* entry::find_key(std::string const& key) const
|
||||||
|
{
|
||||||
|
dictionary_type::const_iterator i = dict().find(key);
|
||||||
|
if (i == dict().end()) return 0;
|
||||||
|
return &i->second;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef BOOST_NO_EXCEPTIONS
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
const entry& entry::operator[](char const* key) const
|
const entry& entry::operator[](char const* key) const
|
||||||
{
|
{
|
||||||
|
@@ -313,9 +313,7 @@ namespace libtorrent
|
|||||||
|
|
||||||
if (tracker_req().kind == tracker_request::scrape_request)
|
if (tracker_req().kind == tracker_request::scrape_request)
|
||||||
{
|
{
|
||||||
std::string ih;
|
std::string ih = tracker_req().info_hash.to_string();
|
||||||
std::copy(tracker_req().info_hash.begin(), tracker_req().info_hash.end()
|
|
||||||
, std::back_inserter(ih));
|
|
||||||
|
|
||||||
entry const* files = e.find_key("files");
|
entry const* files = e.find_key("files");
|
||||||
if (files == 0 || files->type() != entry::dictionary_t)
|
if (files == 0 || files->type() != entry::dictionary_t)
|
||||||
@@ -324,7 +322,7 @@ namespace libtorrent
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry const* scrape_data = e.find_key(ih.c_str());
|
entry const* scrape_data = files->find_key(ih);
|
||||||
if (scrape_data == 0 || scrape_data->type() != entry::dictionary_t)
|
if (scrape_data == 0 || scrape_data->type() != entry::dictionary_t)
|
||||||
{
|
{
|
||||||
fail(-1, "missing or invalid info-hash entry in scrape response");
|
fail(-1, "missing or invalid info-hash entry in scrape response");
|
||||||
|
Reference in New Issue
Block a user