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