|
|
|
@ -2359,7 +2359,7 @@ public:
@@ -2359,7 +2359,7 @@ public:
|
|
|
|
|
TextSearch(std::string const &keyword, libtorrent::entry const ¶ms); |
|
|
|
|
|
|
|
|
|
bool matchText(std::string msg); |
|
|
|
|
libtorrent::lazy_entry const* matchRawMessage(std::string const &rawMessage); |
|
|
|
|
libtorrent::lazy_entry const* matchRawMessage(std::string const &rawMessage, libtorrent::lazy_entry &v); |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
std::vector<std::string> keywords; |
|
|
|
@ -2465,7 +2465,7 @@ bool TextSearch::matchText(string msg)
@@ -2465,7 +2465,7 @@ bool TextSearch::matchText(string msg)
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
lazy_entry const* TextSearch::matchRawMessage(string const &rawMessage) |
|
|
|
|
lazy_entry const* TextSearch::matchRawMessage(string const &rawMessage, libtorrent::lazy_entry &v) |
|
|
|
|
{ |
|
|
|
|
if( keywords.size() == 0 ) { |
|
|
|
|
return 0; |
|
|
|
@ -2475,7 +2475,6 @@ lazy_entry const* TextSearch::matchRawMessage(string const &rawMessage)
@@ -2475,7 +2475,6 @@ lazy_entry const* TextSearch::matchRawMessage(string const &rawMessage)
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
lazy_entry v; |
|
|
|
|
int pos; |
|
|
|
|
libtorrent::error_code ec; |
|
|
|
|
if (lazy_bdecode(rawMessage.data(), rawMessage.data()+rawMessage.size(), v, ec, &pos) == 0) { |
|
|
|
@ -2539,6 +2538,7 @@ Value search(const Array& params, bool fHelp)
@@ -2539,6 +2538,7 @@ Value search(const Array& params, bool fHelp)
|
|
|
|
|
if( scope == "messages" ) { |
|
|
|
|
// search public messages
|
|
|
|
|
std::map< pair<std::string,int>, pair<int64,entry> > posts; |
|
|
|
|
lazy_entry v; |
|
|
|
|
|
|
|
|
|
TextSearch searcher(keyword, options); |
|
|
|
|
|
|
|
|
@ -2547,6 +2547,7 @@ Value search(const Array& params, bool fHelp)
@@ -2547,6 +2547,7 @@ Value search(const Array& params, bool fHelp)
|
|
|
|
|
LOCK(cs_twister); |
|
|
|
|
|
|
|
|
|
std::map<std::string,torrent_handle> users; |
|
|
|
|
|
|
|
|
|
if( username.size() == 0 ) { |
|
|
|
|
users = m_userTorrent; |
|
|
|
|
} else { |
|
|
|
@ -2559,7 +2560,7 @@ Value search(const Array& params, bool fHelp)
@@ -2559,7 +2560,7 @@ Value search(const Array& params, bool fHelp)
|
|
|
|
|
item.second.get_pieces(pieces, std::numeric_limits<int>::max(), std::numeric_limits<int>::max(), -1, ~USERPOST_FLAG_DM); |
|
|
|
|
|
|
|
|
|
BOOST_FOREACH(string const& piece, pieces) { |
|
|
|
|
lazy_entry const* p = searcher.matchRawMessage(piece); |
|
|
|
|
lazy_entry const* p = searcher.matchRawMessage(piece, v); |
|
|
|
|
if( p ) { |
|
|
|
|
string n = p->dict_find_string_value("n"); |
|
|
|
|
int k = p->dict_find_int_value("k"); |
|
|
|
@ -2581,12 +2582,16 @@ Value search(const Array& params, bool fHelp)
@@ -2581,12 +2582,16 @@ Value search(const Array& params, bool fHelp)
|
|
|
|
|
{ |
|
|
|
|
entry data = ses->dht_getLocalData(); |
|
|
|
|
|
|
|
|
|
if( data.type() == entry::dictionary_t ) { |
|
|
|
|
|
|
|
|
|
for (entry::dictionary_type::const_iterator i = data.dict().begin(); i != data.dict().end(); ++i) { |
|
|
|
|
if ( i->second.type() != entry::list_t ) |
|
|
|
|
continue; |
|
|
|
|
for (entry::list_type::const_iterator j = i->second.list().begin(); j != i->second.list().end(); ++j) { |
|
|
|
|
string str_p = j->find_key("p")->string(); |
|
|
|
|
lazy_entry const* p = searcher.matchRawMessage(str_p); |
|
|
|
|
entry const* key_p = j->find_key("p"); |
|
|
|
|
if( key_p ) { |
|
|
|
|
string str_p = key_p->string(); |
|
|
|
|
lazy_entry const* p = searcher.matchRawMessage(str_p, v); |
|
|
|
|
if( p ) { |
|
|
|
|
string n = p->dict_find_string_value("n"); |
|
|
|
|
int k = p->dict_find_int_value("k"); |
|
|
|
@ -2604,6 +2609,8 @@ Value search(const Array& params, bool fHelp)
@@ -2604,6 +2609,8 @@ Value search(const Array& params, bool fHelp)
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::multimap<int64,entry> postsByTime; |
|
|
|
|
BOOST_FOREACH(const PAIRTYPE(PAIRTYPE(std::string,int),PAIRTYPE(int64,entry))& item, posts) { |
|
|
|
|