From cb5f22a5c6095f37d728b3e20b090b8b33c5a539 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 10 Aug 2009 19:44:45 +0000 Subject: [PATCH] Share Flags - now, only files with the NETWORK_WIDE flag are searchable by turtle hopping. Next move: - integrate turtle search in default gui. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1512 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/dbase/fimonitor.cc | 38 +++++++++++++++++++++++++--- libretroshare/src/dbase/fimonitor.h | 3 ++- libretroshare/src/ft/ftserver.cc | 5 +++- libretroshare/src/turtle/p3turtle.cc | 2 +- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/libretroshare/src/dbase/fimonitor.cc b/libretroshare/src/dbase/fimonitor.cc index bd26d61b3..2713894a9 100644 --- a/libretroshare/src/dbase/fimonitor.cc +++ b/libretroshare/src/dbase/fimonitor.cc @@ -59,8 +59,39 @@ FileIndexMonitor::~FileIndexMonitor() return; } -bool FileIndexMonitor::findLocalFile(std::string hash,uint32_t flags, - std::string &fullpath, uint64_t &size) const +int FileIndexMonitor::SearchKeywords(std::list keywords, std::list &results,uint32_t flags) +{ + results.clear(); + std::list firesults; + + fi.searchTerms(keywords, firesults); + time_t now = time(NULL) ; + + /* translate/filter results */ + + for(std::list::const_iterator rit(firesults.begin()); rit != firesults.end(); ++rit) + { + DirDetails details ; + RequestDirDetails((*rit)->parent,details,0) ; + + if(( details.flags & flags & (DIR_FLAGS_BROWSABLE | DIR_FLAGS_NETWORK_WIDE) ) > 0 ) + { + FileDetail fd; + fd.id = "Local"; //localId; + fd.name = (*rit)->name; + fd.hash = (*rit)->hash; + fd.path = ""; /* TODO */ + fd.size = (*rit)->size; + fd.age = now - (*rit)->modtime; + fd.rank = (*rit)->pop; + + results.push_back(fd); + } + } + return !results.empty() ; +} + +bool FileIndexMonitor::findLocalFile(std::string hash,uint32_t flags, std::string &fullpath, uint64_t &size) const { std::list results; bool ok = false; @@ -72,6 +103,7 @@ bool FileIndexMonitor::findLocalFile(std::string hash,uint32_t flags, #endif /* search through the fileIndex */ fi.searchHash(hash, results); + if (results.size() > 0) { /* find the full path for the first entry */ @@ -937,7 +969,7 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t bool b = fi.RequestDirDetails(ref,details,flags) ; // look for the top level and setup flags accordingly - + FileEntry *file = (FileEntry *) ref; DirEntry *dir = dynamic_cast(file); DirEntry *last_dir = NULL ; diff --git a/libretroshare/src/dbase/fimonitor.h b/libretroshare/src/dbase/fimonitor.h index 741620b8f..efb96d468 100644 --- a/libretroshare/src/dbase/fimonitor.h +++ b/libretroshare/src/dbase/fimonitor.h @@ -74,7 +74,8 @@ class FileIndexMonitor: public CacheSource, public RsThread virtual ~FileIndexMonitor(); /* external interface for filetransfer */ - bool findLocalFile(std::string hash,uint32_t f, std::string &fullpath, uint64_t &size) const; + bool findLocalFile(std::string hash,uint32_t f, std::string &fullpath, uint64_t &size) const; + int SearchKeywords(std::list keywords, std::list &results,uint32_t flags) ; /* external interface for local access to files */ bool convertSharedFilePath(std::string path, std::string &fullpath); diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index eaa365c75..693de6ff6 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -447,7 +447,10 @@ int ftServer::SearchKeywords(std::list keywords, std::listSearchKeywords(keywords, results,flags); + if(flags & DIR_FLAGS_LOCAL) + return mFiMon->SearchKeywords(keywords, results,flags); + else + return mFiStore->SearchKeywords(keywords, results,flags); } int ftServer::SearchBoolExp(Expression * exp, std::list &results) diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index 07d93290f..9f34e4832 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -1307,7 +1307,7 @@ void p3turtle::performLocalSearch(const std::string& s,std::list words.push_back(s) ; // now, search! - rsFiles->SearchKeywords(words, initialResults,DIR_FLAGS_LOCAL); + rsFiles->SearchKeywords(words, initialResults,DIR_FLAGS_LOCAL | DIR_FLAGS_NETWORK_WIDE); result.clear() ;