mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Tweaked dbase functions for ftSearch functionality.
(made a bunch of functions "const") git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@674 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
de2956637b
commit
d7e1a90c28
@ -69,7 +69,7 @@ CacheSource::CacheSource(uint16_t t, bool m, CacheStrapper *cs, std::string cach
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Mutex Stuff -> to be done... */
|
/* Mutex Stuff -> to be done... */
|
||||||
void CacheSource::lockData()
|
void CacheSource::lockData() const
|
||||||
{
|
{
|
||||||
#ifdef CS_DEBUG
|
#ifdef CS_DEBUG
|
||||||
std::cerr << "CacheSource::lockData()" << std::endl;
|
std::cerr << "CacheSource::lockData()" << std::endl;
|
||||||
@ -77,7 +77,7 @@ void CacheSource::lockData()
|
|||||||
cMutex.lock();
|
cMutex.lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CacheSource::unlockData()
|
void CacheSource::unlockData() const
|
||||||
{
|
{
|
||||||
#ifdef CS_DEBUG
|
#ifdef CS_DEBUG
|
||||||
std::cerr << "CacheSource::unlockData()" << std::endl;
|
std::cerr << "CacheSource::unlockData()" << std::endl;
|
||||||
@ -154,12 +154,12 @@ bool CacheSource::cachesAvailable(RsPeerId pid, std::map<CacheId, CacheData>
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CacheSource::findCache(std::string hash, CacheData &data)
|
bool CacheSource::findCache(std::string hash, CacheData &data) const
|
||||||
{
|
{
|
||||||
lockData(); /* LOCK MUTEX */
|
lockData(); /* LOCK MUTEX */
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
CacheSet::iterator it;
|
CacheSet::const_iterator it;
|
||||||
for(it = caches.begin(); it != caches.end(); it++)
|
for(it = caches.begin(); it != caches.end(); it++)
|
||||||
{
|
{
|
||||||
if (hash == (it->second).hash)
|
if (hash == (it->second).hash)
|
||||||
@ -205,7 +205,7 @@ CacheStore::CacheStore(uint16_t t, bool m,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Mutex Stuff -> to be done... */
|
/* Mutex Stuff -> to be done... */
|
||||||
void CacheStore::lockData()
|
void CacheStore::lockData() const
|
||||||
{
|
{
|
||||||
#ifdef CS_DEBUG
|
#ifdef CS_DEBUG
|
||||||
std::cerr << "CacheStore::lockData()" << std::endl;
|
std::cerr << "CacheStore::lockData()" << std::endl;
|
||||||
@ -213,7 +213,7 @@ void CacheStore::lockData()
|
|||||||
cMutex.lock();
|
cMutex.lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CacheStore::unlockData()
|
void CacheStore::unlockData() const
|
||||||
{
|
{
|
||||||
#ifdef CS_DEBUG
|
#ifdef CS_DEBUG
|
||||||
std::cerr << "CacheStore::unlockData()" << std::endl;
|
std::cerr << "CacheStore::unlockData()" << std::endl;
|
||||||
@ -685,10 +685,10 @@ void CacheStrapper::listPeerStatus(std::ostream &out)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CacheStrapper::findCache(std::string hash, CacheData &data)
|
bool CacheStrapper::findCache(std::string hash, CacheData &data) const
|
||||||
{
|
{
|
||||||
/* can overwrite for more control! */
|
/* can overwrite for more control! */
|
||||||
std::map<uint16_t, CachePair>::iterator it;
|
std::map<uint16_t, CachePair>::const_iterator it;
|
||||||
for(it = caches.begin(); it != caches.end(); it++)
|
for(it = caches.begin(); it != caches.end(); it++)
|
||||||
{
|
{
|
||||||
if ((it->second).source->findCache(hash, data))
|
if ((it->second).source->findCache(hash, data))
|
||||||
|
@ -165,7 +165,7 @@ uint16_t getCacheType() { return cacheType; }
|
|||||||
void listCaches(std::ostream &out);
|
void listCaches(std::ostream &out);
|
||||||
|
|
||||||
/* search */
|
/* search */
|
||||||
bool findCache(std::string hash, CacheData &data);
|
bool findCache(std::string hash, CacheData &data) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -174,15 +174,15 @@ bool findCache(std::string hash, CacheData &data);
|
|||||||
CacheStrapper *mStrapper;
|
CacheStrapper *mStrapper;
|
||||||
|
|
||||||
/*** MUTEX LOCKING */
|
/*** MUTEX LOCKING */
|
||||||
void lockData();
|
void lockData() const;
|
||||||
void unlockData();
|
void unlockData() const;
|
||||||
|
|
||||||
CacheSet caches;
|
CacheSet caches;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string cacheDir;
|
std::string cacheDir;
|
||||||
RsMutex cMutex;
|
mutable RsMutex cMutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -221,8 +221,8 @@ void listCaches(std::ostream &out);
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
/*** MUTEX LOCKING */
|
/*** MUTEX LOCKING */
|
||||||
void lockData();
|
void lockData() const;
|
||||||
void unlockData();
|
void unlockData() const;
|
||||||
|
|
||||||
/* This function is called to store Cache Entry in the CacheStore Table.
|
/* This function is called to store Cache Entry in the CacheStore Table.
|
||||||
* it must be called from within a Mutex Lock....
|
* it must be called from within a Mutex Lock....
|
||||||
@ -242,7 +242,7 @@ bool locked_getStoredCache(CacheData &data);
|
|||||||
|
|
||||||
std::string cacheDir;
|
std::string cacheDir;
|
||||||
|
|
||||||
RsMutex cMutex;
|
mutable RsMutex cMutex;
|
||||||
|
|
||||||
std::map<RsPeerId, CacheSet> caches;
|
std::map<RsPeerId, CacheSet> caches;
|
||||||
|
|
||||||
@ -299,7 +299,7 @@ void handleCacheQuery(RsPeerId id, std::map<CacheId, CacheData> &data);
|
|||||||
|
|
||||||
|
|
||||||
/* search through CacheSources. */
|
/* search through CacheSources. */
|
||||||
bool findCache(std::string hash, CacheData &data);
|
bool findCache(std::string hash, CacheData &data) const;
|
||||||
|
|
||||||
/* display */
|
/* display */
|
||||||
void listCaches(std::ostream &out);
|
void listCaches(std::ostream &out);
|
||||||
|
@ -57,7 +57,7 @@ FileIndexMonitor::~FileIndexMonitor()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool FileIndexMonitor::findLocalFile(std::string hash,
|
bool FileIndexMonitor::findLocalFile(std::string hash,
|
||||||
std::string &fullpath, uint64_t &size)
|
std::string &fullpath, uint64_t &size) const
|
||||||
{
|
{
|
||||||
std::list<FileEntry *> results;
|
std::list<FileEntry *> results;
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
@ -80,7 +80,7 @@ bool FileIndexMonitor::findLocalFile(std::string hash,
|
|||||||
#endif
|
#endif
|
||||||
std::string shpath = RsDirUtil::removeRootDir(de->path);
|
std::string shpath = RsDirUtil::removeRootDir(de->path);
|
||||||
std::string basedir = RsDirUtil::getRootDir(de->path);
|
std::string basedir = RsDirUtil::getRootDir(de->path);
|
||||||
std::string realroot = findRealRoot(basedir);
|
std::string realroot = locked_findRealRoot(basedir);
|
||||||
|
|
||||||
/* construct full name */
|
/* construct full name */
|
||||||
if (realroot.length() > 0)
|
if (realroot.length() > 0)
|
||||||
@ -119,7 +119,7 @@ bool FileIndexMonitor::convertSharedFilePath(std::string path, std::string &f
|
|||||||
|
|
||||||
std::string shpath = RsDirUtil::removeRootDir(path);
|
std::string shpath = RsDirUtil::removeRootDir(path);
|
||||||
std::string basedir = RsDirUtil::getRootDir(path);
|
std::string basedir = RsDirUtil::getRootDir(path);
|
||||||
std::string realroot = findRealRoot(basedir);
|
std::string realroot = locked_findRealRoot(basedir);
|
||||||
|
|
||||||
/* construct full name */
|
/* construct full name */
|
||||||
if (realroot.length() > 0)
|
if (realroot.length() > 0)
|
||||||
@ -280,7 +280,7 @@ void FileIndexMonitor::updateCycle()
|
|||||||
std::string rootdir = RsDirUtil::getRootDir(olddir->path);
|
std::string rootdir = RsDirUtil::getRootDir(olddir->path);
|
||||||
std::string remdir = RsDirUtil::removeRootDir(olddir->path);
|
std::string remdir = RsDirUtil::removeRootDir(olddir->path);
|
||||||
|
|
||||||
std::string realroot = findRealRoot(rootdir);
|
std::string realroot = locked_findRealRoot(rootdir);
|
||||||
|
|
||||||
std::string realpath = realroot;
|
std::string realpath = realroot;
|
||||||
if (remdir != "")
|
if (remdir != "")
|
||||||
@ -602,6 +602,22 @@ void FileIndexMonitor::setSharedDirectories(std::list<std::string> dirs)
|
|||||||
} fiMutex.unlock(); /* UNLOCKED DIRS */
|
} fiMutex.unlock(); /* UNLOCKED DIRS */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* interface */
|
||||||
|
void FileIndexMonitor::getSharedDirectories(std::list<std::string> &dirs)
|
||||||
|
{
|
||||||
|
fiMutex.lock(); { /* LOCKED DIRS */
|
||||||
|
|
||||||
|
/* get actual list (not pending stuff) */
|
||||||
|
std::map<std::string, std::string>::const_iterator it;
|
||||||
|
for(it = directoryMap.begin(); it != directoryMap.end(); it++)
|
||||||
|
{
|
||||||
|
dirs.push_back(it->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
} fiMutex.unlock(); /* UNLOCKED DIRS */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* interface */
|
/* interface */
|
||||||
void FileIndexMonitor::forceDirectoryCheck()
|
void FileIndexMonitor::forceDirectoryCheck()
|
||||||
{
|
{
|
||||||
@ -700,7 +716,7 @@ bool FileIndexMonitor::internal_setSharedDirectories()
|
|||||||
|
|
||||||
|
|
||||||
/* lookup directory function */
|
/* lookup directory function */
|
||||||
std::string FileIndexMonitor::findRealRoot(std::string rootdir)
|
std::string FileIndexMonitor::locked_findRealRoot(std::string rootdir) const
|
||||||
{
|
{
|
||||||
/**** MUST ALREADY BE LOCKED ****/
|
/**** MUST ALREADY BE LOCKED ****/
|
||||||
std::string realroot = "";
|
std::string realroot = "";
|
||||||
@ -708,7 +724,7 @@ std::string FileIndexMonitor::findRealRoot(std::string rootdir)
|
|||||||
std::map<std::string, std::string>::const_iterator cit;
|
std::map<std::string, std::string>::const_iterator cit;
|
||||||
if (directoryMap.end()== (cit=directoryMap.find(rootdir)))
|
if (directoryMap.end()== (cit=directoryMap.find(rootdir)))
|
||||||
{
|
{
|
||||||
std::cerr << "FileIndexMonitor::findRealRoot() Invalid RootDir: ";
|
std::cerr << "FileIndexMonitor::locked_findRealRoot() Invalid RootDir: ";
|
||||||
std::cerr << rootdir << std::endl;
|
std::cerr << rootdir << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -72,7 +72,7 @@ class FileIndexMonitor: public CacheSource, public RsThread
|
|||||||
virtual ~FileIndexMonitor();
|
virtual ~FileIndexMonitor();
|
||||||
|
|
||||||
/* external interface for filetransfer */
|
/* external interface for filetransfer */
|
||||||
bool findLocalFile(std::string hash, std::string &fullpath, uint64_t &size);
|
bool findLocalFile(std::string hash, std::string &fullpath, uint64_t &size) const;
|
||||||
|
|
||||||
/* external interface for local access to files */
|
/* external interface for local access to files */
|
||||||
bool convertSharedFilePath(std::string path, std::string &fullpath);
|
bool convertSharedFilePath(std::string path, std::string &fullpath);
|
||||||
@ -89,6 +89,8 @@ virtual void run(); /* overloaded from RsThread */
|
|||||||
void updateCycle();
|
void updateCycle();
|
||||||
|
|
||||||
void setSharedDirectories(std::list<std::string> dirs);
|
void setSharedDirectories(std::list<std::string> dirs);
|
||||||
|
void getSharedDirectories(std::list<std::string> &dirs);
|
||||||
|
|
||||||
void setPeriod(int insecs);
|
void setPeriod(int insecs);
|
||||||
void forceDirectoryCheck();
|
void forceDirectoryCheck();
|
||||||
bool inDirectoryCheck();
|
bool inDirectoryCheck();
|
||||||
@ -97,12 +99,12 @@ bool inDirectoryCheck();
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
/* the mutex should be locked before calling... these. */
|
/* the mutex should be locked before calling... these. */
|
||||||
std::string findRealRoot(std::string base); /* To Implement */
|
std::string locked_findRealRoot(std::string base) const;
|
||||||
bool hashFile(std::string path, FileEntry &fi); /* To Implement */
|
bool hashFile(std::string path, FileEntry &fi); /* To Implement */
|
||||||
|
|
||||||
/* data */
|
/* data */
|
||||||
|
|
||||||
RsMutex fiMutex;
|
mutable RsMutex fiMutex;
|
||||||
|
|
||||||
FileIndex fi;
|
FileIndex fi;
|
||||||
|
|
||||||
|
@ -946,7 +946,7 @@ int DirEntry::saveEntry(std::ostringstream &oss)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int FileIndex::searchHash(std::string hash, std::list<FileEntry *> &results)
|
int FileIndex::searchHash(std::string hash, std::list<FileEntry *> &results) const
|
||||||
{
|
{
|
||||||
DirEntry *ndir = NULL;
|
DirEntry *ndir = NULL;
|
||||||
std::list<DirEntry *> dirlist;
|
std::list<DirEntry *> dirlist;
|
||||||
@ -978,7 +978,7 @@ int FileIndex::searchHash(std::string hash, std::list<FileEntry *> &results)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int FileIndex::searchTerms(std::list<std::string> terms, std::list<FileEntry *> &results)
|
int FileIndex::searchTerms(std::list<std::string> terms, std::list<FileEntry *> &results) const
|
||||||
{
|
{
|
||||||
DirEntry *ndir = NULL;
|
DirEntry *ndir = NULL;
|
||||||
std::list<DirEntry *> dirlist;
|
std::list<DirEntry *> dirlist;
|
||||||
@ -1029,7 +1029,7 @@ int FileIndex::searchTerms(std::list<std::string> terms, std::list<FileEntry *>
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FileIndex::searchBoolExp(Expression * exp, std::list<FileEntry *> &results)
|
int FileIndex::searchBoolExp(Expression * exp, std::list<FileEntry *> &results) const
|
||||||
{
|
{
|
||||||
DirEntry *ndir = NULL;
|
DirEntry *ndir = NULL;
|
||||||
std::list<DirEntry *> dirlist;
|
std::list<DirEntry *> dirlist;
|
||||||
|
@ -217,9 +217,9 @@ int loadIndex(std::string filename, std::string expectedHash, uint64_t size);
|
|||||||
int saveIndex(std::string filename, std::string &fileHash, uint64_t &size);
|
int saveIndex(std::string filename, std::string &fileHash, uint64_t &size);
|
||||||
|
|
||||||
/* search through this index */
|
/* search through this index */
|
||||||
int searchTerms(std::list<std::string> terms, std::list<FileEntry *> &results);
|
int searchTerms(std::list<std::string> terms, std::list<FileEntry *> &results) const;
|
||||||
int searchHash(std::string hash, std::list<FileEntry *> &results);
|
int searchHash(std::string hash, std::list<FileEntry *> &results) const;
|
||||||
int searchBoolExp(Expression * exp, std::list<FileEntry *> &results);
|
int searchBoolExp(Expression * exp, std::list<FileEntry *> &results) const;
|
||||||
|
|
||||||
PersonEntry *root;
|
PersonEntry *root;
|
||||||
};
|
};
|
||||||
|
@ -140,12 +140,12 @@ int FileIndexStore::loadCache(const CacheData &data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Search Interface - For Directory Access */
|
/* Search Interface - For Directory Access */
|
||||||
int FileIndexStore::RequestDirDetails(std::string uid, std::string path, DirDetails &details)
|
int FileIndexStore::RequestDirDetails(std::string uid, std::string path, DirDetails &details) const
|
||||||
{
|
{
|
||||||
/* lock it up */
|
/* lock it up */
|
||||||
lockData();
|
lockData();
|
||||||
|
|
||||||
std::map<RsPeerId, FileIndex *>::iterator it;
|
std::map<RsPeerId, FileIndex *>::const_iterator it;
|
||||||
it = indices.find(uid);
|
it = indices.find(uid);
|
||||||
bool found = true;
|
bool found = true;
|
||||||
if (it == indices.end())
|
if (it == indices.end())
|
||||||
@ -164,11 +164,11 @@ int FileIndexStore::RequestDirDetails(std::string uid, std::string path, DirDeta
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
|
int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const
|
||||||
{
|
{
|
||||||
lockData();
|
lockData();
|
||||||
bool found = true;
|
bool found = true;
|
||||||
std::map<RsPeerId, FileIndex *>::iterator pit;
|
std::map<RsPeerId, FileIndex *>::const_iterator pit;
|
||||||
|
|
||||||
/* so cast *ref to a DirEntry */
|
/* so cast *ref to a DirEntry */
|
||||||
FileEntry *file = (FileEntry *) ref;
|
FileEntry *file = (FileEntry *) ref;
|
||||||
@ -339,10 +339,10 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int FileIndexStore::SearchHash(std::string hash, std::list<FileDetail> &results)
|
int FileIndexStore::SearchHash(std::string hash, std::list<FileDetail> &results) const
|
||||||
{
|
{
|
||||||
lockData();
|
lockData();
|
||||||
std::map<RsPeerId, FileIndex *>::iterator pit;
|
std::map<RsPeerId, FileIndex *>::const_iterator pit;
|
||||||
std::list<FileEntry *>::iterator rit;
|
std::list<FileEntry *>::iterator rit;
|
||||||
std::list<FileEntry *> firesults;
|
std::list<FileEntry *> firesults;
|
||||||
|
|
||||||
@ -378,10 +378,10 @@ int FileIndexStore::SearchHash(std::string hash, std::list<FileDetail> &results)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results)
|
int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results) const
|
||||||
{
|
{
|
||||||
lockData();
|
lockData();
|
||||||
std::map<RsPeerId, FileIndex *>::iterator pit;
|
std::map<RsPeerId, FileIndex *>::const_iterator pit;
|
||||||
std::list<FileEntry *>::iterator rit;
|
std::list<FileEntry *>::iterator rit;
|
||||||
std::list<FileEntry *> firesults;
|
std::list<FileEntry *> firesults;
|
||||||
|
|
||||||
@ -438,10 +438,10 @@ int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<Fi
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int FileIndexStore::searchBoolExp(Expression * exp, std::list<FileDetail> &results)
|
int FileIndexStore::searchBoolExp(Expression * exp, std::list<FileDetail> &results) const
|
||||||
{
|
{
|
||||||
lockData();
|
lockData();
|
||||||
std::map<RsPeerId, FileIndex *>::iterator pit;
|
std::map<RsPeerId, FileIndex *>::const_iterator pit;
|
||||||
std::list<FileEntry *>::iterator rit;
|
std::list<FileEntry *>::iterator rit;
|
||||||
std::list<FileEntry *> firesults;
|
std::list<FileEntry *> firesults;
|
||||||
|
|
||||||
|
@ -71,18 +71,18 @@ virtual ~FileIndexStore();
|
|||||||
virtual int loadCache(const CacheData &data); /* actual load, once data available */
|
virtual int loadCache(const CacheData &data); /* actual load, once data available */
|
||||||
|
|
||||||
/* Search Interface - For FileTransfer Lookup */
|
/* Search Interface - For FileTransfer Lookup */
|
||||||
int SearchHash(std::string hash, std::list<FileDetail> &results);
|
int SearchHash(std::string hash, std::list<FileDetail> &results) const;
|
||||||
|
|
||||||
/* Search Interface - For Search Interface */
|
/* Search Interface - For Search Interface */
|
||||||
int SearchKeywords(std::list<std::string> terms, std::list<FileDetail> &results);
|
int SearchKeywords(std::list<std::string> terms, std::list<FileDetail> &results) const;
|
||||||
|
|
||||||
/* Search Interface - for Adv Search Interface */
|
/* Search Interface - for Adv Search Interface */
|
||||||
int searchBoolExp(Expression * exp, std::list<FileDetail> &results);
|
int searchBoolExp(Expression * exp, std::list<FileDetail> &results) const;
|
||||||
|
|
||||||
|
|
||||||
/* Search Interface - For Directory Access */
|
/* Search Interface - For Directory Access */
|
||||||
int RequestDirDetails(std::string uid, std::string path, DirDetails &details);
|
int RequestDirDetails(std::string uid, std::string path, DirDetails &details) const;
|
||||||
int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags);
|
int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int AboutToModify();
|
int AboutToModify();
|
||||||
|
Loading…
Reference in New Issue
Block a user