mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-21 05:44:29 -05:00
-add support for searching and display directories
-downloading directories from search dialog not implemented yet -needs more code clean and beautify the directory tree git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1566 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
1292a69ccf
commit
10d44a15b8
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* RetroShare FileCache Module: fimonitor.cc
|
* RetroShare FileCache Module: fimonitor.cc
|
||||||
*
|
*
|
||||||
* Copyright 2004-2007 by Robert Fernie.
|
* Copyright 2004-2007 by Robert Fernie.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
* License Version 2 as published by the Free Software Foundation.
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
*
|
*
|
||||||
* This library is distributed in the hope that it will be useful,
|
* This library is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* Library General Public License for more details.
|
* Library General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Library General Public
|
* You should have received a copy of the GNU Library General Public
|
||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
@ -44,8 +44,8 @@
|
|||||||
// ***********/
|
// ***********/
|
||||||
|
|
||||||
FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in,std::string cachedir, std::string pid)
|
FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in,std::string cachedir, std::string pid)
|
||||||
:CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fi(pid),
|
:CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fi(pid),
|
||||||
pendingDirs(false), pendingForceCacheWrite(false),
|
pendingDirs(false), pendingForceCacheWrite(false),
|
||||||
mForceCheck(false), mInCheck(false),cb(cb_in)
|
mForceCheck(false), mInCheck(false),cb(cb_in)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -59,7 +59,7 @@ FileIndexMonitor::~FileIndexMonitor()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results,uint32_t flags)
|
int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags)
|
||||||
{
|
{
|
||||||
results.clear();
|
results.clear();
|
||||||
std::list<FileEntry *> firesults;
|
std::list<FileEntry *> firesults;
|
||||||
@ -69,7 +69,7 @@ int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<
|
|||||||
return filterResults(firesults,results,flags) ;
|
return filterResults(firesults,results,flags) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<FileDetail>& results,uint32_t flags) const
|
int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<DirDetails>& results,uint32_t flags) const
|
||||||
{
|
{
|
||||||
results.clear();
|
results.clear();
|
||||||
std::list<FileEntry *> firesults;
|
std::list<FileEntry *> firesults;
|
||||||
@ -79,29 +79,22 @@ int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<FileDetail>& resu
|
|||||||
return filterResults(firesults,results,flags) ;
|
return filterResults(firesults,results,flags) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<FileDetail>& results,uint32_t flags) const
|
int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,uint32_t flags) const
|
||||||
{
|
{
|
||||||
time_t now = time(NULL) ;
|
|
||||||
|
|
||||||
/* translate/filter results */
|
/* translate/filter results */
|
||||||
|
|
||||||
for(std::list<FileEntry*>::const_iterator rit(firesults.begin()); rit != firesults.end(); ++rit)
|
for(std::list<FileEntry*>::const_iterator rit(firesults.begin()); rit != firesults.end(); ++rit)
|
||||||
{
|
{
|
||||||
DirDetails details ;
|
DirDetails pdetails ;
|
||||||
RequestDirDetails((*rit)->parent,details,0) ;
|
RequestDirDetails((*rit)->parent,pdetails,0) ;
|
||||||
|
DirDetails cdetails ;
|
||||||
|
RequestDirDetails (*rit,cdetails,0);
|
||||||
|
|
||||||
if(( details.flags & flags & (DIR_FLAGS_BROWSABLE | DIR_FLAGS_NETWORK_WIDE) ) > 0 )
|
if ( ((cdetails.type == DIR_TYPE_FILE) && (pdetails.flags & flags & (DIR_FLAGS_BROWSABLE | DIR_FLAGS_NETWORK_WIDE)) > 0) ||
|
||||||
|
((cdetails.type == DIR_TYPE_DIR) && (cdetails.flags & flags & (DIR_FLAGS_BROWSABLE | DIR_FLAGS_NETWORK_WIDE)) > 0) )
|
||||||
{
|
{
|
||||||
FileDetail fd;
|
cdetails.id = "Local";
|
||||||
fd.id = "Local"; //localId;
|
results.push_back(cdetails);
|
||||||
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() ;
|
return !results.empty() ;
|
||||||
@ -198,7 +191,7 @@ bool FileIndexMonitor::loadLocalCache(const CacheData &data) /* called with sto
|
|||||||
//fi.root->name = data.pid;
|
//fi.root->name = data.pid;
|
||||||
|
|
||||||
/* More error checking needed here! */
|
/* More error checking needed here! */
|
||||||
|
|
||||||
std::string name = data.name ; // this trick allows to load the complete file. Not the one being shared.
|
std::string name = data.name ; // this trick allows to load the complete file. Not the one being shared.
|
||||||
name[name.length()-1] = 'c' ;
|
name[name.length()-1] = 'c' ;
|
||||||
|
|
||||||
@ -218,7 +211,7 @@ bool FileIndexMonitor::loadLocalCache(const CacheData &data) /* called with sto
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
} fiMutex.unlock(); /* UNLOCKED DIRS */
|
} fiMutex.unlock(); /* UNLOCKED DIRS */
|
||||||
|
|
||||||
if (ok)
|
if (ok)
|
||||||
@ -306,7 +299,7 @@ void FileIndexMonitor::updateCycle()
|
|||||||
/* reset start time */
|
/* reset start time */
|
||||||
startstamp = time(NULL);
|
startstamp = time(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle a Single out-of-date directory */
|
/* Handle a Single out-of-date directory */
|
||||||
|
|
||||||
time_t stamp = time(NULL);
|
time_t stamp = time(NULL);
|
||||||
@ -332,7 +325,7 @@ void FileIndexMonitor::updateCycle()
|
|||||||
|
|
||||||
FileEntry fe;
|
FileEntry fe;
|
||||||
/* entries that need to be checked properly */
|
/* entries that need to be checked properly */
|
||||||
std::list<FileEntry> filesToHash;
|
std::list<FileEntry> filesToHash;
|
||||||
std::list<FileEntry>::iterator hit;
|
std::list<FileEntry>::iterator hit;
|
||||||
|
|
||||||
/* determine the full root path */
|
/* determine the full root path */
|
||||||
@ -347,7 +340,7 @@ void FileIndexMonitor::updateCycle()
|
|||||||
{
|
{
|
||||||
realpath += "/" + remdir;
|
realpath += "/" + remdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef FIM_DEBUG
|
#ifdef FIM_DEBUG
|
||||||
@ -502,11 +495,11 @@ void FileIndexMonitor::updateCycle()
|
|||||||
* next files - hashing them, before adding into the system.
|
* next files - hashing them, before adding into the system.
|
||||||
*/
|
*/
|
||||||
/* for safety - blank out data we cannot use (TODO) */
|
/* for safety - blank out data we cannot use (TODO) */
|
||||||
olddir = NULL;
|
olddir = NULL;
|
||||||
|
|
||||||
/* close directory */
|
/* close directory */
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
/* unlock dirs */
|
/* unlock dirs */
|
||||||
fiMutex.unlock();
|
fiMutex.unlock();
|
||||||
|
|
||||||
@ -530,7 +523,7 @@ void FileIndexMonitor::updateCycle()
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* update files */
|
/* update files */
|
||||||
for(hit = filesToHash.begin(); hit != filesToHash.end(); hit++)
|
for(hit = filesToHash.begin(); hit != filesToHash.end(); hit++)
|
||||||
{
|
{
|
||||||
@ -564,14 +557,14 @@ void FileIndexMonitor::updateCycle()
|
|||||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filesToHash.size() > 0)
|
if (filesToHash.size() > 0)
|
||||||
cb->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0);
|
cb->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fiMutex.lock(); { /* LOCKED DIRS */
|
fiMutex.lock(); { /* LOCKED DIRS */
|
||||||
|
|
||||||
/* finished update cycle - cleanup extra dirs/files that
|
/* finished update cycle - cleanup extra dirs/files that
|
||||||
* have not had their timestamps updated.
|
* have not had their timestamps updated.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -586,7 +579,7 @@ void FileIndexMonitor::updateCycle()
|
|||||||
fi.printFileIndex(std::cerr);
|
fi.printFileIndex(std::cerr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* now if we have changed things -> restore file/hash it/and
|
/* now if we have changed things -> restore file/hash it/and
|
||||||
* tell the CacheSource
|
* tell the CacheSource
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -596,11 +589,11 @@ void FileIndexMonitor::updateCycle()
|
|||||||
fiMods = true;
|
fiMods = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fiMods)
|
if (fiMods)
|
||||||
locked_saveFileIndexes() ;
|
locked_saveFileIndexes() ;
|
||||||
|
|
||||||
fiMutex.unlock(); /* UNLOCKED DIRS */
|
fiMutex.unlock(); /* UNLOCKED DIRS */
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -620,12 +613,12 @@ void FileIndexMonitor::locked_saveFileIndexes()
|
|||||||
// Two files are saved: one with only browsable dirs, which will be shared by the cache system,
|
// Two files are saved: one with only browsable dirs, which will be shared by the cache system,
|
||||||
// and one with the complete file collection.
|
// and one with the complete file collection.
|
||||||
//
|
//
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
out << "fc-own-" << time(NULL) << ".rsfb";
|
out << "fc-own-" << time(NULL) << ".rsfb";
|
||||||
std::string tmpname_browsable = out.str();
|
std::string tmpname_browsable = out.str();
|
||||||
std::string fname_browsable = path + "/" + tmpname_browsable;
|
std::string fname_browsable = path + "/" + tmpname_browsable;
|
||||||
|
|
||||||
std::ostringstream out2;
|
std::ostringstream out2;
|
||||||
out2 << "fc-own-" << time(NULL) << ".rsfc";
|
out2 << "fc-own-" << time(NULL) << ".rsfc";
|
||||||
std::string tmpname_total = out2.str();
|
std::string tmpname_total = out2.str();
|
||||||
std::string fname_total = path + "/" + tmpname_total;
|
std::string fname_total = path + "/" + tmpname_total;
|
||||||
@ -693,7 +686,7 @@ void FileIndexMonitor::updateShareFlags(const SharedDirInfo& dir)
|
|||||||
#ifdef FIM_DEBUG
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "*** FileIndexMonitor: Updating flags for " << dir.filename << " to " << dir.shareflags << std::endl ;
|
std::cerr << "*** FileIndexMonitor: Updating flags for " << dir.filename << " to " << dir.shareflags << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
RsStackMutex stack(fiMutex) ; /* LOCKED DIRS */
|
RsStackMutex stack(fiMutex) ; /* LOCKED DIRS */
|
||||||
|
|
||||||
for(std::list<SharedDirInfo>::iterator it(pendingDirList.begin());it!=pendingDirList.end();++it)
|
for(std::list<SharedDirInfo>::iterator it(pendingDirList.begin());it!=pendingDirList.end();++it)
|
||||||
@ -828,14 +821,14 @@ bool FileIndexMonitor::internal_setSharedDirectories()
|
|||||||
fiMutex.unlock(); /* UNLOCKED DIRS */
|
fiMutex.unlock(); /* UNLOCKED DIRS */
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mForceCheck = false;
|
mForceCheck = false;
|
||||||
pendingDirs = false;
|
pendingDirs = false;
|
||||||
pendingForceCacheWrite = true;
|
pendingForceCacheWrite = true;
|
||||||
|
|
||||||
/* clear old directories */
|
/* clear old directories */
|
||||||
directoryMap.clear();
|
directoryMap.clear();
|
||||||
|
|
||||||
/* iterate through the directories */
|
/* iterate through the directories */
|
||||||
std::list<SharedDirInfo>::iterator it;
|
std::list<SharedDirInfo>::iterator it;
|
||||||
std::map<std::string, SharedDirInfo>::const_iterator cit;
|
std::map<std::string, SharedDirInfo>::const_iterator cit;
|
||||||
@ -844,7 +837,7 @@ bool FileIndexMonitor::internal_setSharedDirectories()
|
|||||||
/* get the head directory */
|
/* get the head directory */
|
||||||
std::string root_dir = (*it).filename;
|
std::string root_dir = (*it).filename;
|
||||||
std::string top_dir = RsDirUtil::getTopDir(root_dir);
|
std::string top_dir = RsDirUtil::getTopDir(root_dir);
|
||||||
|
|
||||||
/* if unique -> add, else add modifier */
|
/* if unique -> add, else add modifier */
|
||||||
bool unique = false;
|
bool unique = false;
|
||||||
for(i = 0; !unique; i++)
|
for(i = 0; !unique; i++)
|
||||||
@ -878,20 +871,20 @@ bool FileIndexMonitor::internal_setSharedDirectories()
|
|||||||
}
|
}
|
||||||
|
|
||||||
fi.setRootDirectories(topdirs, 0);
|
fi.setRootDirectories(topdirs, 0);
|
||||||
|
|
||||||
locked_saveFileIndexes() ;
|
locked_saveFileIndexes() ;
|
||||||
fiMutex.unlock(); /* UNLOCKED DIRS */
|
fiMutex.unlock(); /* UNLOCKED DIRS */
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* lookup directory function */
|
/* lookup directory function */
|
||||||
std::string FileIndexMonitor::locked_findRealRoot(std::string rootdir) const
|
std::string FileIndexMonitor::locked_findRealRoot(std::string rootdir) const
|
||||||
{
|
{
|
||||||
/**** MUST ALREADY BE LOCKED ****/
|
/**** MUST ALREADY BE LOCKED ****/
|
||||||
std::string realroot = "";
|
std::string realroot = "";
|
||||||
|
|
||||||
std::map<std::string, SharedDirInfo>::const_iterator cit;
|
std::map<std::string, SharedDirInfo>::const_iterator cit;
|
||||||
@ -933,7 +926,7 @@ bool FileIndexMonitor::hashFile(std::string fullpath, FileEntry &fent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* reading failed for some reason */
|
/* reading failed for some reason */
|
||||||
if (ferror(fd))
|
if (ferror(fd))
|
||||||
{
|
{
|
||||||
delete sha_ctx;
|
delete sha_ctx;
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
@ -942,7 +935,7 @@ bool FileIndexMonitor::hashFile(std::string fullpath, FileEntry &fent)
|
|||||||
|
|
||||||
SHA1_Final(&sha_buf[0], sha_ctx);
|
SHA1_Final(&sha_buf[0], sha_ctx);
|
||||||
|
|
||||||
/* TODO: Actually we should store the hash data as binary ...
|
/* TODO: Actually we should store the hash data as binary ...
|
||||||
* but then it shouldn't be put in a string.
|
* but then it shouldn't be put in a string.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* RetroShare FileCache Module: fimonitor.h
|
* RetroShare FileCache Module: fimonitor.h
|
||||||
*
|
*
|
||||||
* Copyright 2004-2007 by Robert Fernie.
|
* Copyright 2004-2007 by Robert Fernie.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
* License Version 2 as published by the Free Software Foundation.
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
*
|
*
|
||||||
* This library is distributed in the hope that it will be useful,
|
* This library is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* Library General Public License for more details.
|
* Library General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Library General Public
|
* You should have received a copy of the GNU Library General Public
|
||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
@ -75,9 +75,9 @@ class FileIndexMonitor: public CacheSource, public RsThread
|
|||||||
|
|
||||||
/* external interface for filetransfer */
|
/* 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<std::string> keywords, std::list<FileDetail> &results,uint32_t flags) ;
|
int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags) ;
|
||||||
int SearchBoolExp(Expression *exp, std::list<FileDetail> &results,uint32_t flags) const ;
|
int SearchBoolExp(Expression *exp, std::list<DirDetails> &results,uint32_t flags) const ;
|
||||||
int filterResults(std::list<FileEntry*>& firesults,std::list<FileDetail>& results,uint32_t flags) const ;
|
int filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,uint32_t flags) const ;
|
||||||
|
|
||||||
|
|
||||||
/* external interface for local access to files */
|
/* external interface for local access to files */
|
||||||
|
@ -44,20 +44,20 @@
|
|||||||
static RsMutex FIndexPtrMtx ;
|
static RsMutex FIndexPtrMtx ;
|
||||||
std::set<void*> FileIndex::_pointers ;
|
std::set<void*> FileIndex::_pointers ;
|
||||||
|
|
||||||
void FileIndex::registerEntry(void*p)
|
void FileIndex::registerEntry(void*p)
|
||||||
{
|
{
|
||||||
RsStackMutex m(FIndexPtrMtx) ;
|
RsStackMutex m(FIndexPtrMtx) ;
|
||||||
_pointers.insert(p) ;
|
_pointers.insert(p) ;
|
||||||
}
|
}
|
||||||
void FileIndex::unregisterEntry(void*p)
|
void FileIndex::unregisterEntry(void*p)
|
||||||
{
|
{
|
||||||
RsStackMutex m(FIndexPtrMtx) ;
|
RsStackMutex m(FIndexPtrMtx) ;
|
||||||
_pointers.erase(p) ;
|
_pointers.erase(p) ;
|
||||||
}
|
}
|
||||||
bool FileIndex::isValid(void*p)
|
bool FileIndex::isValid(void*p)
|
||||||
{
|
{
|
||||||
RsStackMutex m(FIndexPtrMtx) ;
|
RsStackMutex m(FIndexPtrMtx) ;
|
||||||
return _pointers.find(p) != _pointers.end() ;
|
return _pointers.find(p) != _pointers.end() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
DirEntry::~DirEntry()
|
DirEntry::~DirEntry()
|
||||||
@ -291,7 +291,7 @@ int DirEntry::removeOldEntries(time_t old, bool recursive)
|
|||||||
|
|
||||||
DirEntry *DirEntry::findOldDirectory(time_t old)
|
DirEntry *DirEntry::findOldDirectory(time_t old)
|
||||||
{
|
{
|
||||||
/* check if one of our directories is old ...
|
/* check if one of our directories is old ...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* get all dirs with old time */
|
/* get all dirs with old time */
|
||||||
@ -480,7 +480,7 @@ int FileEntry::print(std::ostream &out)
|
|||||||
else
|
else
|
||||||
out << "[MISSING PARENT]";
|
out << "[MISSING PARENT]";
|
||||||
|
|
||||||
out << " " << name;
|
out << " " << name;
|
||||||
out << " [ s: " << size << " ] ==> ";
|
out << " [ s: " << size << " ] ==> ";
|
||||||
out << " [ " << hash << " ]";
|
out << " [ " << hash << " ]";
|
||||||
out << std::endl;
|
out << std::endl;
|
||||||
@ -645,7 +645,7 @@ int FileIndex::removeOldDirectory(std::string fpath, std::string name, time_t
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* because of this find - we cannot get a child of
|
/* because of this find - we cannot get a child of
|
||||||
* root (which is what we want!)
|
* root (which is what we want!)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -697,7 +697,7 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_
|
|||||||
{
|
{
|
||||||
#ifdef FI_DEBUG
|
#ifdef FI_DEBUG
|
||||||
std::cerr << "FileIndex::loadIndex error opening file: " << filename;
|
std::cerr << "FileIndex::loadIndex error opening file: " << filename;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -714,10 +714,10 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_
|
|||||||
|
|
||||||
/* calculate hash */
|
/* calculate hash */
|
||||||
unsigned char sha_buf[SHA_DIGEST_LENGTH];
|
unsigned char sha_buf[SHA_DIGEST_LENGTH];
|
||||||
SHA_CTX *sha_ctx = new SHA_CTX;
|
SHA_CTX *sha_ctx = new SHA_CTX;
|
||||||
SHA1_Init(sha_ctx);
|
SHA1_Init(sha_ctx);
|
||||||
SHA1_Update(sha_ctx, ss.str().c_str(), ss.str().length());
|
SHA1_Update(sha_ctx, ss.str().c_str(), ss.str().length());
|
||||||
SHA1_Final(&sha_buf[0], sha_ctx);
|
SHA1_Final(&sha_buf[0], sha_ctx);
|
||||||
delete sha_ctx;
|
delete sha_ctx;
|
||||||
|
|
||||||
std::ostringstream tmpout;
|
std::ostringstream tmpout;
|
||||||
@ -729,19 +729,19 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_
|
|||||||
if (expectedHash != tmpout.str())
|
if (expectedHash != tmpout.str())
|
||||||
{
|
{
|
||||||
#ifdef FI_DEBUG
|
#ifdef FI_DEBUG
|
||||||
std::cerr << "FileIndex::loadIndex expected hash does not match" << std::endl;
|
std::cerr << "FileIndex::loadIndex expected hash does not match" << std::endl;
|
||||||
std::cerr << "Expected hash: " << expectedHash << std::endl;
|
std::cerr << "Expected hash: " << expectedHash << std::endl;
|
||||||
std::cerr << "Hash found: " << tmpout.str() << std::endl;
|
std::cerr << "Hash found: " << tmpout.str() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
DirEntry *ndir = NULL;
|
DirEntry *ndir = NULL;
|
||||||
FileEntry *nfile = NULL;
|
FileEntry *nfile = NULL;
|
||||||
std::list<DirEntry *> dirlist;
|
std::list<DirEntry *> dirlist;
|
||||||
std::string word;
|
std::string word;
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
while(ss.get(ch))
|
while(ss.get(ch))
|
||||||
{
|
{
|
||||||
if (ch == '-')
|
if (ch == '-')
|
||||||
@ -750,7 +750,7 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_
|
|||||||
switch(dirlist.size())
|
switch(dirlist.size())
|
||||||
{
|
{
|
||||||
/* parse error: out of directory */
|
/* parse error: out of directory */
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
#ifdef FI_DEBUG
|
#ifdef FI_DEBUG
|
||||||
std::cerr << "loadIndex error parsing saved file: " << filename;
|
std::cerr << "loadIndex error parsing saved file: " << filename;
|
||||||
@ -760,16 +760,16 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
/* finished parse, last dir is root */
|
/* finished parse, last dir is root */
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
std::string pid = root -> id;
|
std::string pid = root -> id;
|
||||||
FileIndex::unregisterEntry((void*)root) ;
|
FileIndex::unregisterEntry((void*)root) ;
|
||||||
delete root; /* to clean up old entries */
|
delete root; /* to clean up old entries */
|
||||||
root = new PersonEntry(pid);
|
root = new PersonEntry(pid);
|
||||||
registerEntry((void*)root) ;
|
registerEntry((void*)root) ;
|
||||||
|
|
||||||
/* shallow copy of all except id */
|
/* shallow copy of all except id */
|
||||||
ndir = dirlist.back();
|
ndir = dirlist.back();
|
||||||
dirlist.pop_back(); /* empty list */
|
dirlist.pop_back(); /* empty list */
|
||||||
(*root) = (*ndir);
|
(*root) = (*ndir);
|
||||||
|
|
||||||
@ -782,13 +782,13 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_
|
|||||||
|
|
||||||
/* must reset parent pointers now */
|
/* must reset parent pointers now */
|
||||||
std::map<std::string, DirEntry *>::iterator it;
|
std::map<std::string, DirEntry *>::iterator it;
|
||||||
for(it = root->subdirs.begin();
|
for(it = root->subdirs.begin();
|
||||||
it != root->subdirs.end(); it++)
|
it != root->subdirs.end(); it++)
|
||||||
{
|
{
|
||||||
(it->second)->parent = root;
|
(it->second)->parent = root;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* pop stack */
|
/* pop stack */
|
||||||
default: dirlist.pop_back(); ndir = dirlist.back();
|
default: dirlist.pop_back(); ndir = dirlist.back();
|
||||||
@ -897,12 +897,12 @@ int FileIndex::saveIndex(std::string filename, std::string &fileHash, uint64_t &
|
|||||||
unsigned char sha_buf[SHA_DIGEST_LENGTH];
|
unsigned char sha_buf[SHA_DIGEST_LENGTH];
|
||||||
std::ofstream file (filename.c_str(), std::ofstream::binary);
|
std::ofstream file (filename.c_str(), std::ofstream::binary);
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
|
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
#ifdef FI_DEBUG
|
#ifdef FI_DEBUG
|
||||||
std::cerr << "FileIndex::saveIndex error opening file: " << filename;
|
std::cerr << "FileIndex::saveIndex error opening file: " << filename;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -912,7 +912,7 @@ int FileIndex::saveIndex(std::string filename, std::string &fileHash, uint64_t &
|
|||||||
oss << "# Dir: d name, path, parent, size, modtime, pop, updtime;" << std::endl;
|
oss << "# Dir: d name, path, parent, size, modtime, pop, updtime;" << std::endl;
|
||||||
oss << "# File: f name, hash, size, modtime, pop, updtime;" << std::endl;
|
oss << "# File: f name, hash, size, modtime, pop, updtime;" << std::endl;
|
||||||
oss << "#" << std::endl;
|
oss << "#" << std::endl;
|
||||||
|
|
||||||
/* begin recusion */
|
/* begin recusion */
|
||||||
root->writeDirInfo(oss) ;
|
root->writeDirInfo(oss) ;
|
||||||
|
|
||||||
@ -935,10 +935,10 @@ int FileIndex::saveIndex(std::string filename, std::string &fileHash, uint64_t &
|
|||||||
oss << "-" << std::endl;
|
oss << "-" << std::endl;
|
||||||
|
|
||||||
/* calculate sha1 hash */
|
/* calculate sha1 hash */
|
||||||
SHA_CTX *sha_ctx = new SHA_CTX;
|
SHA_CTX *sha_ctx = new SHA_CTX;
|
||||||
SHA1_Init(sha_ctx);
|
SHA1_Init(sha_ctx);
|
||||||
SHA1_Update(sha_ctx, oss.str().c_str(), oss.str().length());
|
SHA1_Update(sha_ctx, oss.str().c_str(), oss.str().length());
|
||||||
SHA1_Final(&sha_buf[0], sha_ctx);
|
SHA1_Final(&sha_buf[0], sha_ctx);
|
||||||
delete sha_ctx;
|
delete sha_ctx;
|
||||||
|
|
||||||
std::ostringstream tmpout;
|
std::ostringstream tmpout;
|
||||||
@ -1022,7 +1022,7 @@ int FileIndex::searchHash(std::string hash, std::list<FileEntry *> &results) con
|
|||||||
{
|
{
|
||||||
#ifdef FI_DEBUG
|
#ifdef FI_DEBUG
|
||||||
std::cerr << "FileIndex::searchHash(" << hash << ")";
|
std::cerr << "FileIndex::searchHash(" << hash << ")";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
DirEntry *ndir = NULL;
|
DirEntry *ndir = NULL;
|
||||||
std::list<DirEntry *> dirlist;
|
std::list<DirEntry *> dirlist;
|
||||||
@ -1049,7 +1049,7 @@ int FileIndex::searchHash(std::string hash, std::list<FileEntry *> &results) con
|
|||||||
#ifdef FI_DEBUG
|
#ifdef FI_DEBUG
|
||||||
std::cerr << "FileIndex::searchHash(" << hash << ")";
|
std::cerr << "FileIndex::searchHash(" << hash << ")";
|
||||||
std::cerr << " found: " << fit->second->name;
|
std::cerr << " found: " << fit->second->name;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1079,6 +1079,28 @@ int FileIndex::searchTerms(std::list<std::string> terms, std::list<FileEntry *>
|
|||||||
dirlist.push_back(it->second);
|
dirlist.push_back(it->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (iter = terms.begin(); iter != terms.end(); iter ++) {
|
||||||
|
std::string::const_iterator it2;
|
||||||
|
const std::string &str1 = ndir->name;
|
||||||
|
const std::string &str2 = *iter;
|
||||||
|
it2 = std::search(str1.begin(), str1.end(), str2.begin(), str2.end(), CompareCharIC());
|
||||||
|
if (it2 != str1.end()) {
|
||||||
|
/* first search to see if its parent is in the results list */
|
||||||
|
bool addDir = true;
|
||||||
|
for (std::list<FileEntry *>::iterator rit(results.begin()); rit != results.end() && addDir; rit ++) {
|
||||||
|
DirEntry *de = dynamic_cast<DirEntry *>(*rit);
|
||||||
|
if (de && (de == root))
|
||||||
|
continue;
|
||||||
|
if (de && (de == ndir->parent))
|
||||||
|
addDir = false;
|
||||||
|
}
|
||||||
|
if (addDir) {
|
||||||
|
results.push_back((FileEntry *) ndir);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for(fit = ndir->files.begin(); fit != ndir->files.end(); fit++)
|
for(fit = ndir->files.begin(); fit != ndir->files.end(); fit++)
|
||||||
{
|
{
|
||||||
/* cycle through terms */
|
/* cycle through terms */
|
||||||
@ -1135,7 +1157,7 @@ int FileIndex::searchBoolExp(Expression * exp, std::list<FileEntry *> &results)
|
|||||||
/*Evaluate the boolean expression and add it to the results if its true*/
|
/*Evaluate the boolean expression and add it to the results if its true*/
|
||||||
bool ret = exp->eval(fit->second);
|
bool ret = exp->eval(fit->second);
|
||||||
if (ret == true){
|
if (ret == true){
|
||||||
results.push_back(fit->second);
|
results.push_back(fit->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} //while
|
} //while
|
||||||
@ -1176,7 +1198,7 @@ int FileIndex::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
|
|||||||
details.age = 0;
|
details.age = 0;
|
||||||
details.flags = 0;
|
details.flags = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (dir) /* has children --- fill */
|
if (dir) /* has children --- fill */
|
||||||
{
|
{
|
||||||
@ -1192,17 +1214,17 @@ int FileIndex::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
|
|||||||
stub.type = DIR_TYPE_DIR;
|
stub.type = DIR_TYPE_DIR;
|
||||||
stub.name = (dit->second) -> name;
|
stub.name = (dit->second) -> name;
|
||||||
stub.ref = (dit->second);
|
stub.ref = (dit->second);
|
||||||
|
|
||||||
details.children.push_back(stub);
|
details.children.push_back(stub);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(fit = dir->files.begin(); fit != dir->files.end(); fit++)
|
for(fit = dir->files.begin(); fit != dir->files.end(); fit++)
|
||||||
{
|
{
|
||||||
DirStub stub;
|
DirStub stub;
|
||||||
stub.type = DIR_TYPE_FILE;
|
stub.type = DIR_TYPE_FILE;
|
||||||
stub.name = (fit->second) -> name;
|
stub.name = (fit->second) -> name;
|
||||||
stub.ref = (fit->second);
|
stub.ref = (fit->second);
|
||||||
|
|
||||||
details.children.push_back(stub);
|
details.children.push_back(stub);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1218,7 +1240,7 @@ int FileIndex::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
|
|||||||
details.type = DIR_TYPE_FILE;
|
details.type = DIR_TYPE_FILE;
|
||||||
details.count = file->size;
|
details.count = file->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FI_DEBUG
|
#ifdef FI_DEBUG
|
||||||
std::cerr << "FileIndexStore::RequestDirDetails() name: " << file->name << std::endl;
|
std::cerr << "FileIndexStore::RequestDirDetails() name: " << file->name << std::endl;
|
||||||
#endif
|
#endif
|
||||||
@ -1253,7 +1275,7 @@ int FileIndex::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
|
|||||||
|
|
||||||
if(parent==NULL)
|
if(parent==NULL)
|
||||||
{
|
{
|
||||||
if(NULL == (person = dynamic_cast<PersonEntry *>(file)))
|
if(NULL == (person = dynamic_cast<PersonEntry *>(file)))
|
||||||
{
|
{
|
||||||
std::cerr << "Major Error- Not PersonEntry!";
|
std::cerr << "Major Error- Not PersonEntry!";
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* RetroShare FileCache Module: fistore.cc
|
* RetroShare FileCache Module: fistore.cc
|
||||||
*
|
*
|
||||||
* Copyright 2004-2007 by Robert Fernie.
|
* Copyright 2004-2007 by Robert Fernie.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
* License Version 2 as published by the Free Software Foundation.
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
*
|
*
|
||||||
* This library is distributed in the hope that it will be useful,
|
* This library is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* Library General Public License for more details.
|
* Library General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Library General Public
|
* You should have received a copy of the GNU Library General Public
|
||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
@ -25,15 +25,15 @@
|
|||||||
#include "rsiface/rsexpr.h"
|
#include "rsiface/rsexpr.h"
|
||||||
#include "serialiser/rsserviceids.h"
|
#include "serialiser/rsserviceids.h"
|
||||||
|
|
||||||
FileIndexStore::FileIndexStore(CacheStrapper *cs, CacheTransfer *cft,
|
FileIndexStore::FileIndexStore(CacheStrapper *cs, CacheTransfer *cft,
|
||||||
NotifyBase *cb_in, RsPeerId ownid, std::string cachedir)
|
NotifyBase *cb_in, RsPeerId ownid, std::string cachedir)
|
||||||
:CacheStore(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cft, cachedir),
|
:CacheStore(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cft, cachedir),
|
||||||
localId(ownid), localindex(NULL), cb(cb_in)
|
localId(ownid), localindex(NULL), cb(cb_in)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileIndexStore::~FileIndexStore()
|
FileIndexStore::~FileIndexStore()
|
||||||
{
|
{
|
||||||
/* clean up the Index */
|
/* clean up the Index */
|
||||||
return;
|
return;
|
||||||
@ -151,7 +151,7 @@ int FileIndexStore::RequestDirDetails(std::string uid, std::string path, DirDeta
|
|||||||
if (it == indices.end())
|
if (it == indices.end())
|
||||||
{
|
{
|
||||||
//DirEntry *fdir = (it->second).lookupDirectory(path);
|
//DirEntry *fdir = (it->second).lookupDirectory(path);
|
||||||
/* translate it
|
/* translate it
|
||||||
*/
|
*/
|
||||||
found = false;
|
found = false;
|
||||||
}
|
}
|
||||||
@ -232,13 +232,13 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f
|
|||||||
/* get remote root entries */
|
/* get remote root entries */
|
||||||
for(pit = indices.begin(); pit != indices.end(); pit++)
|
for(pit = indices.begin(); pit != indices.end(); pit++)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
DirStub stub;
|
DirStub stub;
|
||||||
stub.type = DIR_TYPE_PERSON;
|
stub.type = DIR_TYPE_PERSON;
|
||||||
stub.name = (pit->second)->root->name;
|
stub.name = (pit->second)->root->name;
|
||||||
stub.ref = (pit->second)->root;
|
stub.ref = (pit->second)->root;
|
||||||
|
|
||||||
details.children.push_back(stub);
|
details.children.push_back(stub);
|
||||||
}
|
}
|
||||||
details.parent = NULL;
|
details.parent = NULL;
|
||||||
@ -253,7 +253,7 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f
|
|||||||
details.flags = 0;
|
details.flags = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (dir) /* has children --- fill */
|
if (dir) /* has children --- fill */
|
||||||
{
|
{
|
||||||
@ -263,31 +263,31 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f
|
|||||||
std::map<std::string, FileEntry *>::iterator fit;
|
std::map<std::string, FileEntry *>::iterator fit;
|
||||||
std::map<std::string, DirEntry *>::iterator dit;
|
std::map<std::string, DirEntry *>::iterator dit;
|
||||||
/* extract all the entries */
|
/* extract all the entries */
|
||||||
for(dit = dir->subdirs.begin();
|
for(dit = dir->subdirs.begin();
|
||||||
dit != dir->subdirs.end(); dit++)
|
dit != dir->subdirs.end(); dit++)
|
||||||
{
|
{
|
||||||
DirStub stub;
|
DirStub stub;
|
||||||
stub.type = DIR_TYPE_DIR;
|
stub.type = DIR_TYPE_DIR;
|
||||||
stub.name = (dit->second) -> name;
|
stub.name = (dit->second) -> name;
|
||||||
stub.ref = (dit->second);
|
stub.ref = (dit->second);
|
||||||
|
|
||||||
details.children.push_back(stub);
|
details.children.push_back(stub);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(fit = dir->files.begin();
|
for(fit = dir->files.begin();
|
||||||
fit != dir->files.end(); fit++)
|
fit != dir->files.end(); fit++)
|
||||||
{
|
{
|
||||||
DirStub stub;
|
DirStub stub;
|
||||||
stub.type = DIR_TYPE_FILE;
|
stub.type = DIR_TYPE_FILE;
|
||||||
stub.name = (fit->second) -> name;
|
stub.name = (fit->second) -> name;
|
||||||
stub.ref = (fit->second);
|
stub.ref = (fit->second);
|
||||||
|
|
||||||
details.children.push_back(stub);
|
details.children.push_back(stub);
|
||||||
}
|
}
|
||||||
|
|
||||||
details.type = DIR_TYPE_DIR;
|
details.type = DIR_TYPE_DIR;
|
||||||
details.hash = "";
|
details.hash = "";
|
||||||
details.count = dir->subdirs.size() +
|
details.count = dir->subdirs.size() +
|
||||||
dir->files.size();
|
dir->files.size();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -298,7 +298,7 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f
|
|||||||
details.type = DIR_TYPE_FILE;
|
details.type = DIR_TYPE_FILE;
|
||||||
details.count = file->size;
|
details.count = file->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FIS_DEBUG
|
#ifdef FIS_DEBUG
|
||||||
std::cerr << "FileIndexStore::RequestDirDetails() name: " << file->name << std::endl;
|
std::cerr << "FileIndexStore::RequestDirDetails() name: " << file->name << std::endl;
|
||||||
#endif
|
#endif
|
||||||
@ -333,7 +333,7 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f
|
|||||||
|
|
||||||
if(parent==NULL)
|
if(parent==NULL)
|
||||||
{
|
{
|
||||||
if(NULL == (person = dynamic_cast<PersonEntry *>(file)))
|
if(NULL == (person = dynamic_cast<PersonEntry *>(file)))
|
||||||
{
|
{
|
||||||
std::cerr << "Major Error- Not PersonEntry!";
|
std::cerr << "Major Error- Not PersonEntry!";
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -366,7 +366,7 @@ int FileIndexStore::SearchHash(std::string hash, std::list<FileDetail> &results)
|
|||||||
{
|
{
|
||||||
lockData();
|
lockData();
|
||||||
std::map<RsPeerId, FileIndex *>::const_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;
|
||||||
|
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
@ -411,11 +411,11 @@ int FileIndexStore::SearchHash(std::string hash, std::list<FileDetail> &results)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results,uint32_t flags) const
|
int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags) const
|
||||||
{
|
{
|
||||||
lockData();
|
lockData();
|
||||||
std::map<RsPeerId, FileIndex *>::const_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;
|
||||||
|
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
@ -432,18 +432,10 @@ int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<Fi
|
|||||||
/* translate results */
|
/* translate results */
|
||||||
for(rit = firesults.begin(); rit != firesults.end(); rit++)
|
for(rit = firesults.begin(); rit != firesults.end(); rit++)
|
||||||
{
|
{
|
||||||
FileDetail fd;
|
DirDetails dd;
|
||||||
fd.id = pit->first;
|
(pit->second)->RequestDirDetails(*rit, dd, 0);
|
||||||
fd.name = (*rit)->name;
|
results.push_back(dd);
|
||||||
fd.hash = (*rit)->hash;
|
|
||||||
fd.path = ""; /* TODO */
|
|
||||||
fd.size = (*rit)->size;
|
|
||||||
fd.age = now - (*rit)->modtime;
|
|
||||||
fd.rank = (*rit)->pop;
|
|
||||||
|
|
||||||
results.push_back(fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(flags & DIR_FLAGS_LOCAL)
|
if(flags & DIR_FLAGS_LOCAL)
|
||||||
@ -455,16 +447,10 @@ int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<Fi
|
|||||||
/* translate results */
|
/* translate results */
|
||||||
for(rit = firesults.begin(); rit != firesults.end(); rit++)
|
for(rit = firesults.begin(); rit != firesults.end(); rit++)
|
||||||
{
|
{
|
||||||
FileDetail fd;
|
DirDetails dd;
|
||||||
fd.id = "Local"; //localId;
|
(pit->second)->RequestDirDetails(*rit, dd, 0);
|
||||||
fd.name = (*rit)->name;
|
dd.id = "Local";
|
||||||
fd.hash = (*rit)->hash;
|
results.push_back(dd);
|
||||||
fd.path = ""; /* TODO */
|
|
||||||
fd.size = (*rit)->size;
|
|
||||||
fd.age = now - (*rit)->modtime;
|
|
||||||
fd.rank = (*rit)->pop;
|
|
||||||
|
|
||||||
results.push_back(fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -474,11 +460,11 @@ int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<Fi
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int FileIndexStore::searchBoolExp(Expression * exp, std::list<FileDetail> &results) const
|
int FileIndexStore::searchBoolExp(Expression * exp, std::list<DirDetails> &results) const
|
||||||
{
|
{
|
||||||
lockData();
|
lockData();
|
||||||
std::map<RsPeerId, FileIndex *>::const_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;
|
||||||
|
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
@ -495,16 +481,9 @@ int FileIndexStore::searchBoolExp(Expression * exp, std::list<FileDetail> &resul
|
|||||||
/* translate results */
|
/* translate results */
|
||||||
for(rit = firesults.begin(); rit != firesults.end(); rit++)
|
for(rit = firesults.begin(); rit != firesults.end(); rit++)
|
||||||
{
|
{
|
||||||
FileDetail fd;
|
DirDetails dd;
|
||||||
fd.id = pit->first;
|
(pit->second)->RequestDirDetails(*rit, dd, 0);
|
||||||
fd.name = (*rit)->name;
|
results.push_back(dd);
|
||||||
fd.hash = (*rit)->hash;
|
|
||||||
fd.path = ""; /* TODO */
|
|
||||||
fd.size = (*rit)->size;
|
|
||||||
fd.age = now - (*rit)->modtime;
|
|
||||||
fd.rank = (*rit)->pop;
|
|
||||||
|
|
||||||
results.push_back(fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -519,16 +498,10 @@ int FileIndexStore::searchBoolExp(Expression * exp, std::list<FileDetail> &resul
|
|||||||
/* translate results */
|
/* translate results */
|
||||||
for(rit = firesults.begin(); rit != firesults.end(); rit++)
|
for(rit = firesults.begin(); rit != firesults.end(); rit++)
|
||||||
{
|
{
|
||||||
FileDetail fd;
|
DirDetails dd;
|
||||||
fd.id = "Local"; //localId;
|
(pit->second)->RequestDirDetails(*rit, dd, 0);
|
||||||
fd.name = (*rit)->name;
|
dd.id = "Local";
|
||||||
fd.hash = (*rit)->hash;
|
results.push_back(dd);
|
||||||
fd.path = ""; /* TODO */
|
|
||||||
fd.size = (*rit)->size;
|
|
||||||
fd.age = now - (*rit)->modtime;
|
|
||||||
fd.rank = (*rit)->pop;
|
|
||||||
|
|
||||||
results.push_back(fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* RetroShare FileCache Module: fistore.h
|
* RetroShare FileCache Module: fistore.h
|
||||||
*
|
*
|
||||||
* Copyright 2004-2007 by Robert Fernie.
|
* Copyright 2004-2007 by Robert Fernie.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
* License Version 2 as published by the Free Software Foundation.
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
*
|
*
|
||||||
* This library is distributed in the hope that it will be useful,
|
* This library is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* Library General Public License for more details.
|
* Library General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Library General Public
|
* You should have received a copy of the GNU Library General Public
|
||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
/**********
|
/**********
|
||||||
* Stores the FileCaches of the Peers
|
* Stores the FileCaches of the Peers
|
||||||
* must implement 'loadCache' to
|
* must implement 'loadCache' to
|
||||||
*
|
*
|
||||||
* This class is also accessed by the GUI....
|
* This class is also accessed by the GUI....
|
||||||
* and the FileTransfer class.
|
* and the FileTransfer class.
|
||||||
@ -63,7 +63,7 @@ class FileIndexStore: public CacheStore
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
FileIndexStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in,
|
FileIndexStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in,
|
||||||
RsPeerId ownid, std::string cachedir);
|
RsPeerId ownid, std::string cachedir);
|
||||||
virtual ~FileIndexStore();
|
virtual ~FileIndexStore();
|
||||||
|
|
||||||
@ -74,10 +74,10 @@ virtual int loadCache(const CacheData &data); /* actual load, once data availa
|
|||||||
int SearchHash(std::string hash, std::list<FileDetail> &results) const;
|
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,uint32_t flags) const;
|
int SearchKeywords(std::list<std::string> terms, std::list<DirDetails> &results,uint32_t flags) const;
|
||||||
|
|
||||||
/* Search Interface - for Adv Search Interface */
|
/* Search Interface - for Adv Search Interface */
|
||||||
int searchBoolExp(Expression * exp, std::list<FileDetail> &results) const;
|
int searchBoolExp(Expression * exp, std::list<DirDetails> &results) const;
|
||||||
|
|
||||||
|
|
||||||
/* Search Interface - For Directory Access */
|
/* Search Interface - For Directory Access */
|
||||||
|
@ -438,7 +438,7 @@ int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
|
|||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
|
|
||||||
|
|
||||||
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results,uint32_t flags)
|
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags)
|
||||||
{
|
{
|
||||||
#ifdef SERVER_DEBUG
|
#ifdef SERVER_DEBUG
|
||||||
std::cerr << "ftServer::SearchKeywords()";
|
std::cerr << "ftServer::SearchKeywords()";
|
||||||
@ -457,7 +457,7 @@ int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<FileDeta
|
|||||||
return mFiStore->SearchKeywords(keywords, results,flags);
|
return mFiStore->SearchKeywords(keywords, results,flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ftServer::SearchBoolExp(Expression * exp, std::list<FileDetail> &results,uint32_t flags)
|
int ftServer::SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags)
|
||||||
{
|
{
|
||||||
if(flags & DIR_FLAGS_LOCAL)
|
if(flags & DIR_FLAGS_LOCAL)
|
||||||
return mFiMon->SearchBoolExp(exp,results,flags) ;
|
return mFiMon->SearchBoolExp(exp,results,flags) ;
|
||||||
|
@ -157,8 +157,8 @@ virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size,
|
|||||||
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details);
|
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details);
|
||||||
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags);
|
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags);
|
||||||
|
|
||||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results,uint32_t flags);
|
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags);
|
||||||
virtual int SearchBoolExp(Expression * exp, std::list<FileDetail> &results,uint32_t flags);
|
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags);
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Utility Functions
|
* Utility Functions
|
||||||
|
@ -149,8 +149,8 @@ virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size,
|
|||||||
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details) = 0;
|
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details) = 0;
|
||||||
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) = 0;
|
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) = 0;
|
||||||
|
|
||||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results,uint32_t flags) = 0;
|
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags) = 0;
|
||||||
virtual int SearchBoolExp(Expression * exp, std::list<FileDetail> &results,uint32_t flags) = 0;
|
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags) = 0;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Utility Functions.
|
* Utility Functions.
|
||||||
|
@ -55,8 +55,8 @@
|
|||||||
#include "util/rsprint.h"
|
#include "util/rsprint.h"
|
||||||
#include "pqi/pqinetwork.h"
|
#include "pqi/pqinetwork.h"
|
||||||
|
|
||||||
// These number may be quite important. I setup them with sensible values, but
|
// These number may be quite important. I setup them with sensible values, but
|
||||||
// an in-depth test would be better to get an idea of what the ideal values
|
// an in-depth test would be better to get an idea of what the ideal values
|
||||||
// could ever be.
|
// could ever be.
|
||||||
//
|
//
|
||||||
static const time_t TUNNEL_REQUESTS_LIFE_TIME = 120 ; /// life time for tunnel requests in the cache.
|
static const time_t TUNNEL_REQUESTS_LIFE_TIME = 120 ; /// life time for tunnel requests in the cache.
|
||||||
@ -65,7 +65,7 @@ static const time_t REGULAR_TUNNEL_DIGGING_TIME = 300 ; /// maximum interval be
|
|||||||
static const time_t MAXIMUM_TUNNEL_IDLE_TIME = 60 ; /// maximum life time of an unused tunnel.
|
static const time_t MAXIMUM_TUNNEL_IDLE_TIME = 60 ; /// maximum life time of an unused tunnel.
|
||||||
static const time_t TUNNEL_MANAGEMENT_LAPS_TIME = 10 ; /// look into tunnels regularly every 10 sec.
|
static const time_t TUNNEL_MANAGEMENT_LAPS_TIME = 10 ; /// look into tunnels regularly every 10 sec.
|
||||||
|
|
||||||
p3turtle::p3turtle(p3ConnectMgr *cm,ftServer *fs)
|
p3turtle::p3turtle(p3ConnectMgr *cm,ftServer *fs)
|
||||||
:p3Service(RS_SERVICE_TYPE_TURTLE), p3Config(CONFIG_TYPE_TURTLE), mConnMgr(cm)
|
:p3Service(RS_SERVICE_TYPE_TURTLE), p3Config(CONFIG_TYPE_TURTLE), mConnMgr(cm)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||||
@ -130,7 +130,7 @@ int p3turtle::tick()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
// ------------------------------ Tunnel maintenance. ------------------------------ //
|
// ------------------------------ Tunnel maintenance. ------------------------------ //
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
//
|
//
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ int p3turtle::tick()
|
|||||||
// If A connects, new tunnels should be initiated from A
|
// If A connects, new tunnels should be initiated from A
|
||||||
// If A disconnects, the tunnels passed through A should be closed.
|
// If A disconnects, the tunnels passed through A should be closed.
|
||||||
//
|
//
|
||||||
void p3turtle::statusChange(const std::list<pqipeer> &plist) // derived from pqiMonitor
|
void p3turtle::statusChange(const std::list<pqipeer> &plist) // derived from pqiMonitor
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ void p3turtle::statusChange(const std::list<pqipeer> &plist) // derived from pqi
|
|||||||
|
|
||||||
// adds a virtual peer to the list that is communicated ot ftController.
|
// adds a virtual peer to the list that is communicated ot ftController.
|
||||||
//
|
//
|
||||||
void p3turtle::addDistantPeer(const TurtleFileHash&,TurtleTunnelId tid)
|
void p3turtle::addDistantPeer(const TurtleFileHash&,TurtleTunnelId tid)
|
||||||
{
|
{
|
||||||
char buff[400] ;
|
char buff[400] ;
|
||||||
sprintf(buff,"Turtle tunnel %08x",tid) ;
|
sprintf(buff,"Turtle tunnel %08x",tid) ;
|
||||||
@ -173,7 +173,7 @@ void p3turtle::addDistantPeer(const TurtleFileHash&,TurtleTunnelId tid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3turtle::getVirtualPeersList(std::list<pqipeer>& list)
|
void p3turtle::getVirtualPeersList(std::list<pqipeer>& list)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ void p3turtle::autoWash()
|
|||||||
{
|
{
|
||||||
std::map<TurtleFileHash,TurtleFileHashInfo>::iterator it(_incoming_file_hashes.find(_hashes_to_remove[i])) ;
|
std::map<TurtleFileHash,TurtleFileHashInfo>::iterator it(_incoming_file_hashes.find(_hashes_to_remove[i])) ;
|
||||||
|
|
||||||
if(it == _incoming_file_hashes.end())
|
if(it == _incoming_file_hashes.end())
|
||||||
{
|
{
|
||||||
std::cerr << "p3turtle: asked to stop monitoring file hash " << _hashes_to_remove[i] << ", but this hash is actually not handled by the turtle router." << std::endl ;
|
std::cerr << "p3turtle: asked to stop monitoring file hash " << _hashes_to_remove[i] << ", but this hash is actually not handled by the turtle router." << std::endl ;
|
||||||
continue ;
|
continue ;
|
||||||
@ -257,7 +257,7 @@ void p3turtle::autoWash()
|
|||||||
#endif
|
#endif
|
||||||
std::vector<TurtleTunnelId> tunnels_to_remove ;
|
std::vector<TurtleTunnelId> tunnels_to_remove ;
|
||||||
|
|
||||||
for(std::vector<TurtleTunnelId>::const_iterator it2(it->second.tunnels.begin());it2!=it->second.tunnels.end();++it2)
|
for(std::vector<TurtleTunnelId>::const_iterator it2(it->second.tunnels.begin());it2!=it->second.tunnels.end();++it2)
|
||||||
{
|
{
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << (void*)*it2 << "," ;
|
std::cerr << (void*)*it2 << "," ;
|
||||||
@ -337,7 +337,7 @@ void p3turtle::autoWash()
|
|||||||
void p3turtle::locked_closeTunnel(TurtleTunnelId tid)
|
void p3turtle::locked_closeTunnel(TurtleTunnelId tid)
|
||||||
{
|
{
|
||||||
// This is closing a given tunnel, removing it from file sources, and from the list of tunnels of its
|
// This is closing a given tunnel, removing it from file sources, and from the list of tunnels of its
|
||||||
// corresponding file hash. In the original turtle4privacy paradigm, they also send back and forward
|
// corresponding file hash. In the original turtle4privacy paradigm, they also send back and forward
|
||||||
// tunnel closing commands. I'm not sure this is necessary, because if a tunnel is closed somewhere, it's
|
// tunnel closing commands. I'm not sure this is necessary, because if a tunnel is closed somewhere, it's
|
||||||
// source is not going to be used and the tunnel will eventually disappear.
|
// source is not going to be used and the tunnel will eventually disappear.
|
||||||
//
|
//
|
||||||
@ -352,7 +352,7 @@ void p3turtle::locked_closeTunnel(TurtleTunnelId tid)
|
|||||||
std::cerr << "p3turtle: Closing tunnel " << (void*)tid << std::endl ;
|
std::cerr << "p3turtle: Closing tunnel " << (void*)tid << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(it->second.local_src == mConnMgr->getOwnId()) // this is a starting tunnel. We thus remove
|
if(it->second.local_src == mConnMgr->getOwnId()) // this is a starting tunnel. We thus remove
|
||||||
// - the virtual peer from the vpid list
|
// - the virtual peer from the vpid list
|
||||||
// - the tunnel id from the file hash
|
// - the tunnel id from the file hash
|
||||||
// - the virtual peer from the file sources in the file transfer controller.
|
// - the virtual peer from the file sources in the file transfer controller.
|
||||||
@ -371,7 +371,7 @@ void p3turtle::locked_closeTunnel(TurtleTunnelId tid)
|
|||||||
|
|
||||||
std::vector<TurtleTunnelId>& tunnels(_incoming_file_hashes[hash].tunnels) ;
|
std::vector<TurtleTunnelId>& tunnels(_incoming_file_hashes[hash].tunnels) ;
|
||||||
|
|
||||||
// Remove tunnel id from it's corresponding hash. For security we
|
// Remove tunnel id from it's corresponding hash. For security we
|
||||||
// go through the whole tab, although the tunnel id should only be listed once
|
// go through the whole tab, although the tunnel id should only be listed once
|
||||||
// in this tab.
|
// in this tab.
|
||||||
//
|
//
|
||||||
@ -407,7 +407,7 @@ void p3turtle::stopMonitoringFileTunnels(const std::string& hash)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
// -------------------------------- Config functions ------------------------------ //
|
// -------------------------------- Config functions ------------------------------ //
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
//
|
//
|
||||||
RsSerialiser *p3turtle::setupSerialiser()
|
RsSerialiser *p3turtle::setupSerialiser()
|
||||||
@ -417,7 +417,7 @@ RsSerialiser *p3turtle::setupSerialiser()
|
|||||||
|
|
||||||
return rss ;
|
return rss ;
|
||||||
}
|
}
|
||||||
std::list<RsItem*> p3turtle::saveList(bool& cleanup)
|
std::list<RsItem*> p3turtle::saveList(bool& cleanup)
|
||||||
{
|
{
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << "p3turtle: saving list..." << std::endl ;
|
std::cerr << "p3turtle: saving list..." << std::endl ;
|
||||||
@ -444,7 +444,7 @@ std::list<RsItem*> p3turtle::saveList(bool& cleanup)
|
|||||||
|
|
||||||
return lst ;
|
return lst ;
|
||||||
}
|
}
|
||||||
bool p3turtle::loadList(std::list<RsItem*> load)
|
bool p3turtle::loadList(std::list<RsItem*> load)
|
||||||
{
|
{
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << "p3turtle: loading list..." << std::endl ;
|
std::cerr << "p3turtle: loading list..." << std::endl ;
|
||||||
@ -473,16 +473,16 @@ bool p3turtle::loadList(std::list<RsItem*> load)
|
|||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
// -------------------------------- Helper functions ------------------------------ //
|
// -------------------------------- Helper functions ------------------------------ //
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
//
|
//
|
||||||
uint32_t p3turtle::generateRandomRequestId()
|
uint32_t p3turtle::generateRandomRequestId()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
return rand() ;
|
return rand() ;
|
||||||
}
|
}
|
||||||
uint32_t p3turtle::generatePersonalFilePrint(const TurtleFileHash& hash,bool b)
|
uint32_t p3turtle::generatePersonalFilePrint(const TurtleFileHash& hash,bool b)
|
||||||
{
|
{
|
||||||
// whatever cooking from the file hash and OwnId that cannot be recovered.
|
// whatever cooking from the file hash and OwnId that cannot be recovered.
|
||||||
// The only important thing is that the saem hash produces the same tunnel
|
// The only important thing is that the saem hash produces the same tunnel
|
||||||
@ -505,7 +505,7 @@ uint32_t p3turtle::generatePersonalFilePrint(const TurtleFileHash& hash,bool b)
|
|||||||
return res ;
|
return res ;
|
||||||
}
|
}
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
// -------------------------------- Global routing. -------------------------------- //
|
// -------------------------------- Global routing. -------------------------------- //
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
//
|
//
|
||||||
int p3turtle::handleIncoming()
|
int p3turtle::handleIncoming()
|
||||||
@ -526,7 +526,7 @@ int p3turtle::handleIncoming()
|
|||||||
|
|
||||||
switch(item->PacketSubType())
|
switch(item->PacketSubType())
|
||||||
{
|
{
|
||||||
case RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST:
|
case RS_TURTLE_SUBTYPE_STRING_SEARCH_REQUEST:
|
||||||
case RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST: handleSearchRequest(dynamic_cast<RsTurtleSearchRequestItem *>(item)) ;
|
case RS_TURTLE_SUBTYPE_REGEXP_SEARCH_REQUEST: handleSearchRequest(dynamic_cast<RsTurtleSearchRequestItem *>(item)) ;
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
@ -556,14 +556,14 @@ int p3turtle::handleIncoming()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
// -------------------------------- Search handling. ------------------------------- //
|
// -------------------------------- Search handling. ------------------------------- //
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
//
|
//
|
||||||
void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
|
void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||||
// take a look at the item:
|
// take a look at the item:
|
||||||
// - If the item destimation is
|
// - If the item destimation is
|
||||||
|
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << "Received search request from peer " << item->PeerId() << ": " << std::endl ;
|
std::cerr << "Received search request from peer " << item->PeerId() << ": " << std::endl ;
|
||||||
@ -580,7 +580,7 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a new request. Let's add it to the request map, and forward it to
|
// This is a new request. Let's add it to the request map, and forward it to
|
||||||
// open peers.
|
// open peers.
|
||||||
|
|
||||||
TurtleRequestInfo& req( _search_requests_origins[item->request_id] ) ;
|
TurtleRequestInfo& req( _search_requests_origins[item->request_id] ) ;
|
||||||
@ -588,7 +588,7 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
|
|||||||
req.time_stamp = time(NULL) ;
|
req.time_stamp = time(NULL) ;
|
||||||
|
|
||||||
// If it's not for us, perform a local search. If something found, forward the search result back.
|
// If it's not for us, perform a local search. If something found, forward the search result back.
|
||||||
|
|
||||||
if(item->PeerId() != mConnMgr->getOwnId())
|
if(item->PeerId() != mConnMgr->getOwnId())
|
||||||
{
|
{
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
@ -686,7 +686,7 @@ void p3turtle::handleSearchResult(RsTurtleSearchResultItem *item)
|
|||||||
#endif
|
#endif
|
||||||
if(it == _search_requests_origins.end())
|
if(it == _search_requests_origins.end())
|
||||||
{
|
{
|
||||||
// This is an error: how could we receive a search result corresponding to a search item we
|
// This is an error: how could we receive a search result corresponding to a search item we
|
||||||
// have forwarded but that it not in the list ??
|
// have forwarded but that it not in the list ??
|
||||||
|
|
||||||
std::cerr << __PRETTY_FUNCTION__ << ": search result has no peer direction!" << std::endl ;
|
std::cerr << __PRETTY_FUNCTION__ << ": search result has no peer direction!" << std::endl ;
|
||||||
@ -694,7 +694,7 @@ void p3turtle::handleSearchResult(RsTurtleSearchResultItem *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Is this result's target actually ours ?
|
// Is this result's target actually ours ?
|
||||||
|
|
||||||
++(item->depth) ; // increase depth
|
++(item->depth) ; // increase depth
|
||||||
|
|
||||||
if(it->second.origin == mConnMgr->getOwnId())
|
if(it->second.origin == mConnMgr->getOwnId())
|
||||||
@ -716,17 +716,17 @@ void p3turtle::handleSearchResult(RsTurtleSearchResultItem *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
// --------------------------------- File Transfer. -------------------------------- //
|
// --------------------------------- File Transfer. -------------------------------- //
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
|
||||||
void p3turtle::handleRecvFileRequest(RsTurtleFileRequestItem *item)
|
void p3turtle::handleRecvFileRequest(RsTurtleFileRequestItem *item)
|
||||||
{
|
{
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << "p3Turtle: received file request item:" << std::endl ;
|
std::cerr << "p3Turtle: received file request item:" << std::endl ;
|
||||||
item->print(std::cerr,1) ;
|
item->print(std::cerr,1) ;
|
||||||
#endif
|
#endif
|
||||||
// This is a new request. Let's add it to the request map, and forward it to
|
// This is a new request. Let's add it to the request map, and forward it to
|
||||||
// open peers.
|
// open peers.
|
||||||
|
|
||||||
TurtleVirtualPeerId vpid ;
|
TurtleVirtualPeerId vpid ;
|
||||||
@ -771,7 +771,7 @@ void p3turtle::handleRecvFileRequest(RsTurtleFileRequestItem *item)
|
|||||||
{
|
{
|
||||||
RsTurtleFileRequestItem *res_item = new RsTurtleFileRequestItem(*item) ;
|
RsTurtleFileRequestItem *res_item = new RsTurtleFileRequestItem(*item) ;
|
||||||
|
|
||||||
res_item->PeerId(tunnel.local_dst) ;
|
res_item->PeerId(tunnel.local_dst) ;
|
||||||
|
|
||||||
sendItem(res_item) ;
|
sendItem(res_item) ;
|
||||||
return ;
|
return ;
|
||||||
@ -784,13 +784,13 @@ void p3turtle::handleRecvFileRequest(RsTurtleFileRequestItem *item)
|
|||||||
_ft_server->getMultiplexer()->recvDataRequest(vpid,hash,size,item->chunk_offset,item->chunk_size) ;
|
_ft_server->getMultiplexer()->recvDataRequest(vpid,hash,size,item->chunk_offset,item->chunk_size) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3turtle::handleRecvFileData(RsTurtleFileDataItem *item)
|
void p3turtle::handleRecvFileData(RsTurtleFileDataItem *item)
|
||||||
{
|
{
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << "p3Turtle: received file data item:" << std::endl ;
|
std::cerr << "p3Turtle: received file data item:" << std::endl ;
|
||||||
item->print(std::cerr,1) ;
|
item->print(std::cerr,1) ;
|
||||||
#endif
|
#endif
|
||||||
// This is a new request. Let's add it to the request map, and forward it to
|
// This is a new request. Let's add it to the request map, and forward it to
|
||||||
// open peers.
|
// open peers.
|
||||||
|
|
||||||
TurtleVirtualPeerId vpid ;
|
TurtleVirtualPeerId vpid ;
|
||||||
@ -823,12 +823,12 @@ void p3turtle::handleRecvFileData(RsTurtleFileDataItem *item)
|
|||||||
std::map<TurtleFileHash,TurtleFileHashInfo>::const_iterator it( _incoming_file_hashes.find(tunnel.hash) ) ;
|
std::map<TurtleFileHash,TurtleFileHashInfo>::const_iterator it( _incoming_file_hashes.find(tunnel.hash) ) ;
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
assert(!tunnel.hash.empty()) ;
|
assert(!tunnel.hash.empty()) ;
|
||||||
#endif
|
#endif
|
||||||
if(it==_incoming_file_hashes.end())
|
if(it==_incoming_file_hashes.end())
|
||||||
{
|
{
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << "No tunnel for incoming data. Maybe the tunnel is being closed." << std::endl ;
|
std::cerr << "No tunnel for incoming data. Maybe the tunnel is being closed." << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -859,7 +859,7 @@ void p3turtle::handleRecvFileData(RsTurtleFileDataItem *item)
|
|||||||
}
|
}
|
||||||
memcpy(res_item->chunk_data,item->chunk_data,res_item->chunk_size) ;
|
memcpy(res_item->chunk_data,item->chunk_data,res_item->chunk_size) ;
|
||||||
|
|
||||||
res_item->PeerId(tunnel.local_src) ;
|
res_item->PeerId(tunnel.local_src) ;
|
||||||
|
|
||||||
sendItem(res_item) ;
|
sendItem(res_item) ;
|
||||||
return ;
|
return ;
|
||||||
@ -871,7 +871,7 @@ void p3turtle::handleRecvFileData(RsTurtleFileDataItem *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send a data request into the correct tunnel for the given file hash
|
// Send a data request into the correct tunnel for the given file hash
|
||||||
void p3turtle::sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t, uint64_t offset, uint32_t chunksize)
|
void p3turtle::sendDataRequest(const std::string& peerId, const std::string& hash, uint64_t, uint64_t offset, uint32_t chunksize)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
@ -928,7 +928,7 @@ void p3turtle::sendFileData(const std::string& peerId, const std::string& hash,
|
|||||||
assert(hash == tunnel.hash) ;
|
assert(hash == tunnel.hash) ;
|
||||||
#endif
|
#endif
|
||||||
RsTurtleFileDataItem *item = new RsTurtleFileDataItem ;
|
RsTurtleFileDataItem *item = new RsTurtleFileDataItem ;
|
||||||
item->tunnel_id = tunnel_id ;
|
item->tunnel_id = tunnel_id ;
|
||||||
item->chunk_offset = offset ;
|
item->chunk_offset = offset ;
|
||||||
item->chunk_size = chunksize ;
|
item->chunk_size = chunksize ;
|
||||||
item->chunk_data = malloc(chunksize) ;
|
item->chunk_data = malloc(chunksize) ;
|
||||||
@ -947,7 +947,7 @@ void p3turtle::sendFileData(const std::string& peerId, const std::string& hash,
|
|||||||
sendItem(item) ;
|
sendItem(item) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3turtle::search(std::string hash, uint64_t, uint32_t hintflags, FileInfo &info) const
|
bool p3turtle::search(std::string hash, uint64_t, uint32_t hintflags, FileInfo &info) const
|
||||||
{
|
{
|
||||||
if(! (hintflags & RS_FILE_HINTS_TURTLE)) // this should not happen, but it's a security.
|
if(! (hintflags & RS_FILE_HINTS_TURTLE)) // this should not happen, but it's a security.
|
||||||
return false;
|
return false;
|
||||||
@ -1004,8 +1004,8 @@ bool p3turtle::isTurtlePeer(const std::string& peer_id) const
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string p3turtle::getTurtlePeerId(TurtleTunnelId tid) const
|
std::string p3turtle::getTurtlePeerId(TurtleTunnelId tid) const
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
std::map<TurtleTunnelId,TurtleTunnel>::const_iterator it( _local_tunnels.find(tid) ) ;
|
std::map<TurtleTunnelId,TurtleTunnel>::const_iterator it( _local_tunnels.find(tid) ) ;
|
||||||
@ -1029,7 +1029,7 @@ bool p3turtle::isOnline(const std::string& peer_id) const
|
|||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
// -------------------------------- Tunnel handling. ------------------------------- //
|
// -------------------------------- Tunnel handling. ------------------------------- //
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
//
|
//
|
||||||
|
|
||||||
@ -1052,7 +1052,7 @@ TurtleRequestId p3turtle::diggTunnel(const TurtleFileHash& hash)
|
|||||||
|
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||||
// Store the request id, so that we can find the hash back when we get the response.
|
// Store the request id, so that we can find the hash back when we get the response.
|
||||||
//
|
//
|
||||||
_incoming_file_hashes[hash].last_request = id ;
|
_incoming_file_hashes[hash].last_request = id ;
|
||||||
}
|
}
|
||||||
@ -1066,9 +1066,9 @@ TurtleRequestId p3turtle::diggTunnel(const TurtleFileHash& hash)
|
|||||||
item->request_id = id ;
|
item->request_id = id ;
|
||||||
item->partial_tunnel_id = generatePersonalFilePrint(hash,true) ;
|
item->partial_tunnel_id = generatePersonalFilePrint(hash,true) ;
|
||||||
item->depth = 0 ;
|
item->depth = 0 ;
|
||||||
|
|
||||||
// send it
|
// send it
|
||||||
|
|
||||||
handleTunnelRequest(item) ;
|
handleTunnelRequest(item) ;
|
||||||
|
|
||||||
delete item ;
|
delete item ;
|
||||||
@ -1096,7 +1096,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a new request. Let's add it to the request map, and forward it to
|
// This is a new request. Let's add it to the request map, and forward it to
|
||||||
// open peers.
|
// open peers.
|
||||||
|
|
||||||
TurtleRequestInfo& req( _tunnel_requests_origins[item->request_id] ) ;
|
TurtleRequestInfo& req( _tunnel_requests_origins[item->request_id] ) ;
|
||||||
@ -1122,7 +1122,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
|||||||
|
|
||||||
res_item->request_id = item->request_id ;
|
res_item->request_id = item->request_id ;
|
||||||
res_item->tunnel_id = item->partial_tunnel_id ^ generatePersonalFilePrint(item->file_hash,false) ;
|
res_item->tunnel_id = item->partial_tunnel_id ^ generatePersonalFilePrint(item->file_hash,false) ;
|
||||||
res_item->PeerId(item->PeerId()) ;
|
res_item->PeerId(item->PeerId()) ;
|
||||||
|
|
||||||
sendItem(res_item) ;
|
sendItem(res_item) ;
|
||||||
|
|
||||||
@ -1201,7 +1201,7 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item)
|
|||||||
#endif
|
#endif
|
||||||
if(it == _tunnel_requests_origins.end())
|
if(it == _tunnel_requests_origins.end())
|
||||||
{
|
{
|
||||||
// This is an error: how could we receive a tunnel result corresponding to a tunnel item we
|
// This is an error: how could we receive a tunnel result corresponding to a tunnel item we
|
||||||
// have forwarded but that it not in the list ??
|
// have forwarded but that it not in the list ??
|
||||||
|
|
||||||
std::cerr << __PRETTY_FUNCTION__ << ": tunnel result has no peer direction!" << std::endl ;
|
std::cerr << __PRETTY_FUNCTION__ << ": tunnel result has no peer direction!" << std::endl ;
|
||||||
@ -1284,7 +1284,7 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A new tunnel has been created. Add the corresponding virtual peer to the list, and
|
// A new tunnel has been created. Add the corresponding virtual peer to the list, and
|
||||||
// notify the file transfer controller for the new file source. This should be done off-mutex
|
// notify the file transfer controller for the new file source. This should be done off-mutex
|
||||||
// so we deported this code here.
|
// so we deported this code here.
|
||||||
//
|
//
|
||||||
@ -1296,28 +1296,31 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
// ------------------------------ IO with libretroshare ----------------------------//
|
// ------------------------------ IO with libretroshare ----------------------------//
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
//
|
//
|
||||||
void RsTurtleStringSearchRequestItem::performLocalSearch(std::list<TurtleFileInfo>& result) const
|
void RsTurtleStringSearchRequestItem::performLocalSearch(std::list<TurtleFileInfo>& result) const
|
||||||
{
|
{
|
||||||
/* call to core */
|
/* call to core */
|
||||||
std::list<FileDetail> initialResults;
|
std::list<DirDetails> initialResults;
|
||||||
std::list<std::string> words ;
|
std::list<std::string> words ;
|
||||||
|
|
||||||
// to do: split search string into words.
|
// to do: split search string into words.
|
||||||
words.push_back(match_string) ;
|
words.push_back(match_string) ;
|
||||||
|
|
||||||
// now, search!
|
// now, search!
|
||||||
rsFiles->SearchKeywords(words, initialResults,DIR_FLAGS_LOCAL | DIR_FLAGS_NETWORK_WIDE);
|
rsFiles->SearchKeywords(words, initialResults,DIR_FLAGS_LOCAL | DIR_FLAGS_NETWORK_WIDE);
|
||||||
|
|
||||||
result.clear() ;
|
result.clear() ;
|
||||||
|
|
||||||
for(std::list<FileDetail>::const_iterator it(initialResults.begin());it!=initialResults.end();++it)
|
for(std::list<DirDetails>::const_iterator it(initialResults.begin());it!=initialResults.end();++it)
|
||||||
{
|
{
|
||||||
|
// retain only file type
|
||||||
|
if (it->type == DIR_TYPE_DIR) continue;
|
||||||
|
|
||||||
TurtleFileInfo i ;
|
TurtleFileInfo i ;
|
||||||
i.hash = it->hash ;
|
i.hash = it->hash ;
|
||||||
i.size = it->size ;
|
i.size = it->count ;
|
||||||
i.name = it->name ;
|
i.name = it->name ;
|
||||||
|
|
||||||
result.push_back(i) ;
|
result.push_back(i) ;
|
||||||
@ -1326,21 +1329,21 @@ void RsTurtleStringSearchRequestItem::performLocalSearch(std::list<TurtleFileInf
|
|||||||
void RsTurtleRegExpSearchRequestItem::performLocalSearch(std::list<TurtleFileInfo>& result) const
|
void RsTurtleRegExpSearchRequestItem::performLocalSearch(std::list<TurtleFileInfo>& result) const
|
||||||
{
|
{
|
||||||
/* call to core */
|
/* call to core */
|
||||||
std::list<FileDetail> initialResults;
|
std::list<DirDetails> initialResults;
|
||||||
|
|
||||||
// to do: split search string into words.
|
// to do: split search string into words.
|
||||||
Expression *exp = LinearizedExpression::toExpr(expr) ;
|
Expression *exp = LinearizedExpression::toExpr(expr) ;
|
||||||
|
|
||||||
// now, search!
|
// now, search!
|
||||||
rsFiles->SearchBoolExp(exp,initialResults,DIR_FLAGS_LOCAL | DIR_FLAGS_NETWORK_WIDE);
|
rsFiles->SearchBoolExp(exp,initialResults,DIR_FLAGS_LOCAL | DIR_FLAGS_NETWORK_WIDE);
|
||||||
|
|
||||||
result.clear() ;
|
result.clear() ;
|
||||||
|
|
||||||
for(std::list<FileDetail>::const_iterator it(initialResults.begin());it!=initialResults.end();++it)
|
for(std::list<DirDetails>::const_iterator it(initialResults.begin());it!=initialResults.end();++it)
|
||||||
{
|
{
|
||||||
TurtleFileInfo i ;
|
TurtleFileInfo i ;
|
||||||
i.hash = it->hash ;
|
i.hash = it->hash ;
|
||||||
i.size = it->size ;
|
i.size = it->count ;
|
||||||
i.name = it->name ;
|
i.name = it->name ;
|
||||||
|
|
||||||
result.push_back(i) ;
|
result.push_back(i) ;
|
||||||
@ -1348,10 +1351,10 @@ void RsTurtleRegExpSearchRequestItem::performLocalSearch(std::list<TurtleFileInf
|
|||||||
delete exp ;
|
delete exp ;
|
||||||
}
|
}
|
||||||
|
|
||||||
TurtleRequestId p3turtle::turtleSearch(const std::string& string_to_match)
|
TurtleRequestId p3turtle::turtleSearch(const std::string& string_to_match)
|
||||||
{
|
{
|
||||||
// generate a new search id.
|
// generate a new search id.
|
||||||
|
|
||||||
TurtleRequestId id = generateRandomRequestId() ;
|
TurtleRequestId id = generateRandomRequestId() ;
|
||||||
|
|
||||||
// Form a request packet that simulates a request from us.
|
// Form a request packet that simulates a request from us.
|
||||||
@ -1375,19 +1378,19 @@ TurtleRequestId p3turtle::turtleSearch(const std::string& string_to_match)
|
|||||||
item->match_string = string_to_match ;
|
item->match_string = string_to_match ;
|
||||||
item->request_id = id ;
|
item->request_id = id ;
|
||||||
item->depth = 0 ;
|
item->depth = 0 ;
|
||||||
|
|
||||||
// send it
|
// send it
|
||||||
|
|
||||||
handleSearchRequest(item) ;
|
handleSearchRequest(item) ;
|
||||||
|
|
||||||
delete item ;
|
delete item ;
|
||||||
|
|
||||||
return id ;
|
return id ;
|
||||||
}
|
}
|
||||||
TurtleRequestId p3turtle::turtleSearch(const LinearizedExpression& expr)
|
TurtleRequestId p3turtle::turtleSearch(const LinearizedExpression& expr)
|
||||||
{
|
{
|
||||||
// generate a new search id.
|
// generate a new search id.
|
||||||
|
|
||||||
TurtleRequestId id = generateRandomRequestId() ;
|
TurtleRequestId id = generateRandomRequestId() ;
|
||||||
|
|
||||||
// Form a request packet that simulates a request from us.
|
// Form a request packet that simulates a request from us.
|
||||||
@ -1411,9 +1414,9 @@ TurtleRequestId p3turtle::turtleSearch(const LinearizedExpression& expr)
|
|||||||
item->expr = expr ;
|
item->expr = expr ;
|
||||||
item->request_id = id ;
|
item->request_id = id ;
|
||||||
item->depth = 0 ;
|
item->depth = 0 ;
|
||||||
|
|
||||||
// send it
|
// send it
|
||||||
|
|
||||||
handleSearchRequest(item) ;
|
handleSearchRequest(item) ;
|
||||||
|
|
||||||
delete item ;
|
delete item ;
|
||||||
@ -1421,7 +1424,7 @@ TurtleRequestId p3turtle::turtleSearch(const LinearizedExpression& expr)
|
|||||||
return id ;
|
return id ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3turtle::monitorFileTunnels(const std::string& name,const std::string& file_hash,uint64_t size)
|
void p3turtle::monitorFileTunnels(const std::string& name,const std::string& file_hash,uint64_t size)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||||
@ -1454,7 +1457,7 @@ void p3turtle::monitorFileTunnels(const std::string& name,const std::string& fil
|
|||||||
void p3turtle::returnSearchResult(RsTurtleSearchResultItem *item)
|
void p3turtle::returnSearchResult(RsTurtleSearchResultItem *item)
|
||||||
{
|
{
|
||||||
// just cout for now, but it should be notified to the gui
|
// just cout for now, but it should be notified to the gui
|
||||||
|
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << " Returning result for search request " << (void*)item->request_id << " upwards." << std::endl ;
|
std::cerr << " Returning result for search request " << (void*)item->request_id << " upwards." << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
@ -1462,7 +1465,7 @@ void p3turtle::returnSearchResult(RsTurtleSearchResultItem *item)
|
|||||||
rsicontrol->getNotify().notifyTurtleSearchResult(item->request_id,item->result) ;
|
rsicontrol->getNotify().notifyTurtleSearchResult(item->request_id,item->result) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3turtle::performLocalHashSearch(const TurtleFileHash& hash,FileInfo& info)
|
bool p3turtle::performLocalHashSearch(const TurtleFileHash& hash,FileInfo& info)
|
||||||
{
|
{
|
||||||
return rsFiles->FileDetails(hash, RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SPEC_ONLY, info);
|
return rsFiles->FileDetails(hash, RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SPEC_ONLY, info);
|
||||||
}
|
}
|
||||||
@ -1571,23 +1574,23 @@ void p3turtle::dumpState()
|
|||||||
|
|
||||||
std::cerr << " Local tunnels:" << std::endl ;
|
std::cerr << " Local tunnels:" << std::endl ;
|
||||||
for(std::map<TurtleTunnelId,TurtleTunnel>::const_iterator it(_local_tunnels.begin());it!=_local_tunnels.end();++it)
|
for(std::map<TurtleTunnelId,TurtleTunnel>::const_iterator it(_local_tunnels.begin());it!=_local_tunnels.end();++it)
|
||||||
std::cerr << " " << (void*)it->first << ": from="
|
std::cerr << " " << (void*)it->first << ": from="
|
||||||
<< it->second.local_src << ", to=" << it->second.local_dst
|
<< it->second.local_src << ", to=" << it->second.local_dst
|
||||||
<< ", hash=0x" << it->second.hash << ", ts=" << it->second.time_stamp << " (" << now-it->second.time_stamp << " secs ago)"
|
<< ", hash=0x" << it->second.hash << ", ts=" << it->second.time_stamp << " (" << now-it->second.time_stamp << " secs ago)"
|
||||||
<< ", peer id =" << it->second.vpid << std::endl ;
|
<< ", peer id =" << it->second.vpid << std::endl ;
|
||||||
|
|
||||||
std::cerr << " buffered request origins: " << std::endl ;
|
std::cerr << " buffered request origins: " << std::endl ;
|
||||||
std::cerr << " Search requests: " << _search_requests_origins.size() << std::endl ;
|
std::cerr << " Search requests: " << _search_requests_origins.size() << std::endl ;
|
||||||
|
|
||||||
for(std::map<TurtleSearchRequestId,TurtleRequestInfo>::const_iterator it(_search_requests_origins.begin());it!=_search_requests_origins.end();++it)
|
for(std::map<TurtleSearchRequestId,TurtleRequestInfo>::const_iterator it(_search_requests_origins.begin());it!=_search_requests_origins.end();++it)
|
||||||
std::cerr << " " << (void*)it->first << ": from=" << it->second.origin
|
std::cerr << " " << (void*)it->first << ": from=" << it->second.origin
|
||||||
<< ", ts=" << it->second.time_stamp << " (" << now-it->second.time_stamp
|
<< ", ts=" << it->second.time_stamp << " (" << now-it->second.time_stamp
|
||||||
<< " secs ago)" << std::endl ;
|
<< " secs ago)" << std::endl ;
|
||||||
|
|
||||||
std::cerr << " Tunnel requests: " << _tunnel_requests_origins.size() << std::endl ;
|
std::cerr << " Tunnel requests: " << _tunnel_requests_origins.size() << std::endl ;
|
||||||
for(std::map<TurtleTunnelRequestId,TurtleRequestInfo>::const_iterator it(_tunnel_requests_origins.begin());it!=_tunnel_requests_origins.end();++it)
|
for(std::map<TurtleTunnelRequestId,TurtleRequestInfo>::const_iterator it(_tunnel_requests_origins.begin());it!=_tunnel_requests_origins.end();++it)
|
||||||
std::cerr << " " << (void*)it->first << ": from=" << it->second.origin
|
std::cerr << " " << (void*)it->first << ": from=" << it->second.origin
|
||||||
<< ", ts=" << it->second.time_stamp << " (" << now-it->second.time_stamp
|
<< ", ts=" << it->second.time_stamp << " (" << now-it->second.time_stamp
|
||||||
<< " secs ago)" << std::endl ;
|
<< " secs ago)" << std::endl ;
|
||||||
|
|
||||||
std::cerr << " Virtual peers:" << std::endl ;
|
std::cerr << " Virtual peers:" << std::endl ;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
* Boston, MA 02110-1301, USA.
|
* Boston, MA 02110-1301, USA.
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
@ -44,6 +44,7 @@
|
|||||||
#define IMAGE_START ":/images/download.png"
|
#define IMAGE_START ":/images/download.png"
|
||||||
#define IMAGE_REMOVE ":/images/delete.png"
|
#define IMAGE_REMOVE ":/images/delete.png"
|
||||||
#define IMAGE_REMOVEALL ":/images/deleteall.png"
|
#define IMAGE_REMOVEALL ":/images/deleteall.png"
|
||||||
|
#define IMAGE_DIRECTORY ":/images/folder_green16.png"
|
||||||
|
|
||||||
/* Key for UI Preferences */
|
/* Key for UI Preferences */
|
||||||
#define UI_PREF_ADVANCED_SEARCH "UIOptions/AdvancedSearch"
|
#define UI_PREF_ADVANCED_SEARCH "UIOptions/AdvancedSearch"
|
||||||
@ -76,13 +77,14 @@ const int SearchDialog::FILETYPE_IDX_DOCUMENT = 4;
|
|||||||
const int SearchDialog::FILETYPE_IDX_PICTURE = 5;
|
const int SearchDialog::FILETYPE_IDX_PICTURE = 5;
|
||||||
const int SearchDialog::FILETYPE_IDX_PROGRAM = 6;
|
const int SearchDialog::FILETYPE_IDX_PROGRAM = 6;
|
||||||
const int SearchDialog::FILETYPE_IDX_VIDEO = 7;
|
const int SearchDialog::FILETYPE_IDX_VIDEO = 7;
|
||||||
|
const int SearchDialog::FILETYPE_IDX_DIRECTORY = 8;
|
||||||
QMap<int, QString> * SearchDialog::FileTypeExtensionMap = new QMap<int, QString>();
|
QMap<int, QString> * SearchDialog::FileTypeExtensionMap = new QMap<int, QString>();
|
||||||
bool SearchDialog::initialised = false;
|
bool SearchDialog::initialised = false;
|
||||||
|
|
||||||
/** Constructor */
|
/** Constructor */
|
||||||
SearchDialog::SearchDialog(QWidget *parent)
|
SearchDialog::SearchDialog(QWidget *parent)
|
||||||
: MainPage(parent),
|
: MainPage(parent),
|
||||||
advSearchDialog(NULL),
|
advSearchDialog(NULL),
|
||||||
contextMnu(NULL), contextMnu2(NULL),
|
contextMnu(NULL), contextMnu2(NULL),
|
||||||
nextSearchId(1)
|
nextSearchId(1)
|
||||||
{
|
{
|
||||||
@ -96,15 +98,15 @@ SearchDialog::SearchDialog(QWidget *parent)
|
|||||||
{
|
{
|
||||||
initialiseFileTypeMappings();
|
initialiseFileTypeMappings();
|
||||||
}
|
}
|
||||||
|
|
||||||
RshareSettings rsharesettings;
|
RshareSettings rsharesettings;
|
||||||
|
|
||||||
connect(ui.toggleAdvancedSearchBtn, SIGNAL(clicked()), this, SLOT(showAdvSearchDialog()));
|
connect(ui.toggleAdvancedSearchBtn, SIGNAL(clicked()), this, SLOT(showAdvSearchDialog()));
|
||||||
|
|
||||||
connect( ui.searchResultWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( searchtableWidgetCostumPopupMenu( QPoint ) ) );
|
connect( ui.searchResultWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( searchtableWidgetCostumPopupMenu( QPoint ) ) );
|
||||||
|
|
||||||
connect( ui.searchSummaryWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( searchtableWidget2CostumPopupMenu( QPoint ) ) );
|
connect( ui.searchSummaryWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( searchtableWidget2CostumPopupMenu( QPoint ) ) );
|
||||||
|
|
||||||
connect( ui.lineEdit, SIGNAL( returnPressed ( void ) ), this, SLOT( searchKeywords( void ) ) );
|
connect( ui.lineEdit, SIGNAL( returnPressed ( void ) ), this, SLOT( searchKeywords( void ) ) );
|
||||||
connect( ui.pushButtonsearch, SIGNAL( released ( void ) ), this, SLOT( searchKeywords( void ) ) );
|
connect( ui.pushButtonsearch, SIGNAL( released ( void ) ), this, SLOT( searchKeywords( void ) ) );
|
||||||
connect( ui.pushButtonDownload, SIGNAL( released ( void ) ), this, SLOT( download( void ) ) );
|
connect( ui.pushButtonDownload, SIGNAL( released ( void ) ), this, SLOT( download( void ) ) );
|
||||||
@ -112,12 +114,12 @@ SearchDialog::SearchDialog(QWidget *parent)
|
|||||||
connect( ui.resetButton, SIGNAL(clicked()), this, SLOT(clearKeyword()));
|
connect( ui.resetButton, SIGNAL(clicked()), this, SLOT(clearKeyword()));
|
||||||
|
|
||||||
//connect( ui.searchSummaryWidget, SIGNAL( itemSelectionChanged ( void ) ), this, SLOT( selectSearchResults( void ) ) );
|
//connect( ui.searchSummaryWidget, SIGNAL( itemSelectionChanged ( void ) ), this, SLOT( selectSearchResults( void ) ) );
|
||||||
|
|
||||||
connect( ui.searchResultWidget, SIGNAL( itemDoubleClicked ( QTreeWidgetItem *, int)), this, SLOT(download()));
|
connect( ui.searchResultWidget, SIGNAL( itemDoubleClicked ( QTreeWidgetItem *, int)), this, SLOT(download()));
|
||||||
|
|
||||||
connect ( ui.searchSummaryWidget, SIGNAL( currentItemChanged ( QTreeWidgetItem *, QTreeWidgetItem * ) ),
|
connect ( ui.searchSummaryWidget, SIGNAL( currentItemChanged ( QTreeWidgetItem *, QTreeWidgetItem * ) ),
|
||||||
this, SLOT( selectSearchResults( void ) ) );
|
this, SLOT( selectSearchResults( void ) ) );
|
||||||
|
|
||||||
|
|
||||||
/* hide the Tree +/- */
|
/* hide the Tree +/- */
|
||||||
ui.searchResultWidget -> setRootIsDecorated( false );
|
ui.searchResultWidget -> setRootIsDecorated( false );
|
||||||
@ -127,27 +129,27 @@ SearchDialog::SearchDialog(QWidget *parent)
|
|||||||
|
|
||||||
/* make it extended selection */
|
/* make it extended selection */
|
||||||
ui.searchResultWidget -> setSelectionMode(QAbstractItemView::ExtendedSelection);
|
ui.searchResultWidget -> setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
|
|
||||||
|
|
||||||
/* Set header resize modes and initial section sizes */
|
/* Set header resize modes and initial section sizes */
|
||||||
ui.searchSummaryWidget->setColumnCount(3);
|
ui.searchSummaryWidget->setColumnCount(3);
|
||||||
|
|
||||||
QHeaderView * _smheader = ui.searchSummaryWidget->header () ;
|
QHeaderView * _smheader = ui.searchSummaryWidget->header () ;
|
||||||
_smheader->setResizeMode (0, QHeaderView::Interactive);
|
_smheader->setResizeMode (0, QHeaderView::Interactive);
|
||||||
_smheader->setResizeMode (1, QHeaderView::Interactive);
|
_smheader->setResizeMode (1, QHeaderView::Interactive);
|
||||||
_smheader->setResizeMode (2, QHeaderView::Interactive);
|
_smheader->setResizeMode (2, QHeaderView::Interactive);
|
||||||
|
|
||||||
_smheader->resizeSection ( 0, 80 );
|
_smheader->resizeSection ( 0, 80 );
|
||||||
_smheader->resizeSection ( 1, 75 );
|
_smheader->resizeSection ( 1, 75 );
|
||||||
_smheader->resizeSection ( 2, 75 );
|
_smheader->resizeSection ( 2, 75 );
|
||||||
|
|
||||||
ui.searchResultWidget->setColumnCount(6);
|
ui.searchResultWidget->setColumnCount(6);
|
||||||
_smheader = ui.searchResultWidget->header () ;
|
_smheader = ui.searchResultWidget->header () ;
|
||||||
_smheader->setResizeMode (0, QHeaderView::Custom);
|
_smheader->setResizeMode (0, QHeaderView::Custom);
|
||||||
_smheader->setResizeMode (1, QHeaderView::Interactive);
|
_smheader->setResizeMode (1, QHeaderView::Interactive);
|
||||||
_smheader->setResizeMode (2, QHeaderView::Interactive);
|
_smheader->setResizeMode (2, QHeaderView::Interactive);
|
||||||
_smheader->setResizeMode (3, QHeaderView::Interactive);
|
_smheader->setResizeMode (3, QHeaderView::Interactive);
|
||||||
|
|
||||||
_smheader->resizeSection ( 0, 20 );
|
_smheader->resizeSection ( 0, 20 );
|
||||||
_smheader->resizeSection ( 1, 220 );
|
_smheader->resizeSection ( 1, 220 );
|
||||||
_smheader->resizeSection ( 2, 75 );
|
_smheader->resizeSection ( 2, 75 );
|
||||||
@ -155,12 +157,12 @@ SearchDialog::SearchDialog(QWidget *parent)
|
|||||||
_smheader->resizeSection ( 4, 75 );
|
_smheader->resizeSection ( 4, 75 );
|
||||||
_smheader->resizeSection ( 5, 240 );
|
_smheader->resizeSection ( 5, 240 );
|
||||||
|
|
||||||
|
|
||||||
// set header text aligment
|
// set header text aligment
|
||||||
QTreeWidgetItem * headerItem = ui.searchResultWidget->headerItem();
|
QTreeWidgetItem * headerItem = ui.searchResultWidget->headerItem();
|
||||||
headerItem->setTextAlignment(2, Qt::AlignRight | Qt::AlignRight);
|
headerItem->setTextAlignment(2, Qt::AlignRight | Qt::AlignRight);
|
||||||
headerItem->setTextAlignment(3, Qt::AlignRight | Qt::AlignRight);
|
headerItem->setTextAlignment(3, Qt::AlignRight | Qt::AlignRight);
|
||||||
|
|
||||||
ui.searchResultWidget->sortItems(SR_NAME_COL, Qt::AscendingOrder);
|
ui.searchResultWidget->sortItems(SR_NAME_COL, Qt::AscendingOrder);
|
||||||
|
|
||||||
|
|
||||||
@ -175,20 +177,20 @@ void SearchDialog::initialiseFileTypeMappings()
|
|||||||
{
|
{
|
||||||
/* edit these strings to change the range of extensions recognised by the search */
|
/* edit these strings to change the range of extensions recognised by the search */
|
||||||
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_ANY, "");
|
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_ANY, "");
|
||||||
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_AUDIO,
|
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_AUDIO,
|
||||||
"aac aif iff m3u mid midi mp3 mpa ogg ra ram wav wma");
|
"aac aif iff m3u mid midi mp3 mpa ogg ra ram wav wma");
|
||||||
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_ARCHIVE,
|
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_ARCHIVE,
|
||||||
"7z bz2 gz pkg rar sea sit sitx tar zip");
|
"7z bz2 gz pkg rar sea sit sitx tar zip");
|
||||||
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_CDIMAGE,
|
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_CDIMAGE,
|
||||||
"iso nrg mdf");
|
"iso nrg mdf");
|
||||||
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_DOCUMENT,
|
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_DOCUMENT,
|
||||||
"doc odt ott rtf pdf ps txt log msg wpd wps" );
|
"doc odt ott rtf pdf ps txt log msg wpd wps" );
|
||||||
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_PICTURE,
|
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_PICTURE,
|
||||||
"3dm 3dmf ai bmp drw dxf eps gif ico indd jpe jpeg jpg mng pcx pcc pct pgm "
|
"3dm 3dmf ai bmp drw dxf eps gif ico indd jpe jpeg jpg mng pcx pcc pct pgm "
|
||||||
"pix png psd psp qxd qxprgb sgi svg tga tif tiff xbm xcf");
|
"pix png psd psp qxd qxprgb sgi svg tga tif tiff xbm xcf");
|
||||||
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_PROGRAM,
|
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_PROGRAM,
|
||||||
"app bat cgi com bin exe js pif py pl sh vb ws ");
|
"app bat cgi com bin exe js pif py pl sh vb ws ");
|
||||||
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_VIDEO,
|
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_VIDEO,
|
||||||
"3gp asf asx avi mov mp4 mkv flv mpeg mpg qt rm swf vob wmv");
|
"3gp asf asx avi mov mp4 mkv flv mpeg mpg qt rm swf vob wmv");
|
||||||
SearchDialog::initialised = true;
|
SearchDialog::initialised = true;
|
||||||
}
|
}
|
||||||
@ -196,23 +198,23 @@ void SearchDialog::initialiseFileTypeMappings()
|
|||||||
void SearchDialog::searchtableWidgetCostumPopupMenu( QPoint point )
|
void SearchDialog::searchtableWidgetCostumPopupMenu( QPoint point )
|
||||||
{
|
{
|
||||||
// block the popup if no results available
|
// block the popup if no results available
|
||||||
if ((ui.searchResultWidget->selectedItems()).size() == 0) return;
|
if ((ui.searchResultWidget->selectedItems()).size() == 0) return;
|
||||||
|
|
||||||
// create the menu as required
|
// create the menu as required
|
||||||
if (contextMnu == 0)
|
if (contextMnu == 0)
|
||||||
{
|
{
|
||||||
contextMnu = new QMenu(this);
|
contextMnu = new QMenu(this);
|
||||||
|
|
||||||
downloadAct = new QAction(QIcon(IMAGE_START), tr( "Download" ), this );
|
downloadAct = new QAction(QIcon(IMAGE_START), tr( "Download" ), this );
|
||||||
connect( downloadAct , SIGNAL( triggered() ), this, SLOT( download() ) );
|
connect( downloadAct , SIGNAL( triggered() ), this, SLOT( download() ) );
|
||||||
|
|
||||||
broadcastonchannelAct = new QAction( tr( "Broadcast on Channel" ), this );
|
broadcastonchannelAct = new QAction( tr( "Broadcast on Channel" ), this );
|
||||||
connect( broadcastonchannelAct , SIGNAL( triggered() ), this, SLOT( broadcastonchannel() ) );
|
connect( broadcastonchannelAct , SIGNAL( triggered() ), this, SLOT( broadcastonchannel() ) );
|
||||||
|
|
||||||
recommendtofriendsAct = new QAction( tr( "Recommend to Friends" ), this );
|
recommendtofriendsAct = new QAction( tr( "Recommend to Friends" ), this );
|
||||||
connect( recommendtofriendsAct , SIGNAL( triggered() ), this, SLOT( recommendtofriends() ) );
|
connect( recommendtofriendsAct , SIGNAL( triggered() ), this, SLOT( recommendtofriends() ) );
|
||||||
|
|
||||||
|
|
||||||
contextMnu->clear();
|
contextMnu->clear();
|
||||||
contextMnu->addAction( downloadAct);
|
contextMnu->addAction( downloadAct);
|
||||||
//contextMnu->addSeparator();
|
//contextMnu->addSeparator();
|
||||||
@ -220,7 +222,7 @@ void SearchDialog::searchtableWidgetCostumPopupMenu( QPoint point )
|
|||||||
//contextMnu->addAction( recommendtofriendsAct);
|
//contextMnu->addAction( recommendtofriendsAct);
|
||||||
}
|
}
|
||||||
|
|
||||||
QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point,
|
QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point,
|
||||||
Qt::RightButton, Qt::RightButton, Qt::NoModifier );
|
Qt::RightButton, Qt::RightButton, Qt::NoModifier );
|
||||||
contextMnu->exec( mevent->globalPos() );
|
contextMnu->exec( mevent->globalPos() );
|
||||||
}
|
}
|
||||||
@ -233,7 +235,7 @@ void SearchDialog::download()
|
|||||||
int numdls = itemsForDownload.size();
|
int numdls = itemsForDownload.size();
|
||||||
QTreeWidgetItem * item;
|
QTreeWidgetItem * item;
|
||||||
bool attemptDownloadLocal = false;
|
bool attemptDownloadLocal = false;
|
||||||
|
|
||||||
for (int i = 0; i < numdls; ++i) {
|
for (int i = 0; i < numdls; ++i) {
|
||||||
item = itemsForDownload.at(i);
|
item = itemsForDownload.at(i);
|
||||||
// call the download
|
// call the download
|
||||||
@ -244,13 +246,13 @@ void SearchDialog::download()
|
|||||||
std::list<std::string> srcIds;
|
std::list<std::string> srcIds;
|
||||||
srcIds.push_back(item->text(SR_UID_COL).toStdString()) ;
|
srcIds.push_back(item->text(SR_UID_COL).toStdString()) ;
|
||||||
|
|
||||||
rsFiles -> FileRequest((item->text(SR_NAME_COL)).toStdString(),
|
rsFiles -> FileRequest((item->text(SR_NAME_COL)).toStdString(),
|
||||||
(item->text(SR_HASH_COL)).toStdString(),
|
(item->text(SR_HASH_COL)).toStdString(),
|
||||||
(item->text(SR_REALSIZE_COL)).toInt(),
|
(item->text(SR_REALSIZE_COL)).toInt(),
|
||||||
"", 0, srcIds);
|
"", 0, srcIds);
|
||||||
|
|
||||||
rsTurtle->monitorFileTunnels( item->text(SR_NAME_COL).toStdString(),
|
rsTurtle->monitorFileTunnels( item->text(SR_NAME_COL).toStdString(),
|
||||||
item->text(SR_HASH_COL).toStdString(),
|
item->text(SR_HASH_COL).toStdString(),
|
||||||
item->text(SR_REALSIZE_COL).toInt()) ;
|
item->text(SR_REALSIZE_COL).toInt()) ;
|
||||||
|
|
||||||
std::cout << "isuing file request from search dialog: -" << (item->text(SR_NAME_COL)).toStdString() << "-" << (item->text(SR_HASH_COL)).toStdString() << "-" << (item->text(SR_REALSIZE_COL)).toInt() << "-ids=" ;
|
std::cout << "isuing file request from search dialog: -" << (item->text(SR_NAME_COL)).toStdString() << "-" << (item->text(SR_HASH_COL)).toStdString() << "-" << (item->text(SR_REALSIZE_COL)).toInt() << "-ids=" ;
|
||||||
@ -279,33 +281,33 @@ void SearchDialog::broadcastonchannel()
|
|||||||
void SearchDialog::recommendtofriends()
|
void SearchDialog::recommendtofriends()
|
||||||
{
|
{
|
||||||
QMessageBox::warning(0, tr("Sorry"), tr("This function is not yet implemented."));
|
QMessageBox::warning(0, tr("Sorry"), tr("This function is not yet implemented."));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** context menu searchTablewidget2 **/
|
/** context menu searchTablewidget2 **/
|
||||||
void SearchDialog::searchtableWidget2CostumPopupMenu( QPoint point )
|
void SearchDialog::searchtableWidget2CostumPopupMenu( QPoint point )
|
||||||
{
|
{
|
||||||
|
|
||||||
// block the popup if no results available
|
// block the popup if no results available
|
||||||
if ((ui.searchSummaryWidget->selectedItems()).size() == 0) return;
|
if ((ui.searchSummaryWidget->selectedItems()).size() == 0) return;
|
||||||
|
|
||||||
// create the menu as required
|
// create the menu as required
|
||||||
if (contextMnu2 == 0)
|
if (contextMnu2 == 0)
|
||||||
{
|
{
|
||||||
contextMnu2 = new QMenu( this );
|
contextMnu2 = new QMenu( this );
|
||||||
|
|
||||||
searchRemoveAct = new QAction(QIcon(IMAGE_REMOVE), tr( "Remove" ), this );
|
searchRemoveAct = new QAction(QIcon(IMAGE_REMOVE), tr( "Remove" ), this );
|
||||||
connect( searchRemoveAct , SIGNAL( triggered() ), this, SLOT( searchRemove() ) );
|
connect( searchRemoveAct , SIGNAL( triggered() ), this, SLOT( searchRemove() ) );
|
||||||
|
|
||||||
searchRemoveAllAct = new QAction(QIcon(IMAGE_REMOVEALL), tr( "Remove All" ), this );
|
searchRemoveAllAct = new QAction(QIcon(IMAGE_REMOVEALL), tr( "Remove All" ), this );
|
||||||
connect( searchRemoveAllAct , SIGNAL( triggered() ), this, SLOT( searchRemoveAll() ) );
|
connect( searchRemoveAllAct , SIGNAL( triggered() ), this, SLOT( searchRemoveAll() ) );
|
||||||
|
|
||||||
contextMnu2->clear();
|
contextMnu2->clear();
|
||||||
contextMnu2->addAction( searchRemoveAct);
|
contextMnu2->addAction( searchRemoveAct);
|
||||||
contextMnu2->addAction( searchRemoveAllAct);
|
contextMnu2->addAction( searchRemoveAllAct);
|
||||||
}
|
}
|
||||||
|
|
||||||
QMouseEvent *mevent2 = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier );
|
QMouseEvent *mevent2 = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier );
|
||||||
contextMnu2->exec( mevent2->globalPos() );
|
contextMnu2->exec( mevent2->globalPos() );
|
||||||
}
|
}
|
||||||
@ -384,7 +386,7 @@ void SearchDialog::toggleAdvancedSearchDialog(bool toggled)
|
|||||||
RshareSettings rsharesettings;
|
RshareSettings rsharesettings;
|
||||||
QString key (UI_PREF_ADVANCED_SEARCH);
|
QString key (UI_PREF_ADVANCED_SEARCH);
|
||||||
rsharesettings.setValue(key, QVariant(toggled));
|
rsharesettings.setValue(key, QVariant(toggled));
|
||||||
|
|
||||||
showAdvSearchDialog(toggled);
|
showAdvSearchDialog(toggled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -411,7 +413,7 @@ void SearchDialog::advancedSearch(Expression* expression)
|
|||||||
advSearchDialog->hide();
|
advSearchDialog->hide();
|
||||||
|
|
||||||
/* call to core */
|
/* call to core */
|
||||||
std::list<FileDetail> results;
|
std::list<DirDetails> results;
|
||||||
|
|
||||||
// send a turtle search request
|
// send a turtle search request
|
||||||
LinearizedExpression e ;
|
LinearizedExpression e ;
|
||||||
@ -434,7 +436,7 @@ void SearchDialog::advancedSearch(Expression* expression)
|
|||||||
|
|
||||||
|
|
||||||
void SearchDialog::searchKeywords()
|
void SearchDialog::searchKeywords()
|
||||||
{
|
{
|
||||||
QString qTxt = ui.lineEdit->text();
|
QString qTxt = ui.lineEdit->text();
|
||||||
std::string txt = qTxt.toStdString();
|
std::string txt = qTxt.toStdString();
|
||||||
|
|
||||||
@ -450,7 +452,7 @@ void SearchDialog::searchKeywords()
|
|||||||
{
|
{
|
||||||
words.push_back(qWordsIter.next().toStdString());
|
words.push_back(qWordsIter.next().toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (words.size() < 1)
|
if (words.size() < 1)
|
||||||
{
|
{
|
||||||
/* ignore */
|
/* ignore */
|
||||||
@ -458,37 +460,57 @@ void SearchDialog::searchKeywords()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* call to core */
|
/* call to core */
|
||||||
std::list<FileDetail> initialResults;
|
std::list<DirDetails> initialResults;
|
||||||
std::list<FileDetail> * finalResults = 0;
|
std::list<DirDetails> * finalResults = 0;
|
||||||
|
|
||||||
//rsFiles -> SearchKeywords(words, initialResults,DIR_FLAGS_LOCAL | DIR_FLAGS_REMOTE | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE);
|
//rsFiles -> SearchKeywords(words, initialResults,DIR_FLAGS_LOCAL | DIR_FLAGS_REMOTE | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE);
|
||||||
rsFiles -> SearchKeywords(words, initialResults,DIR_FLAGS_REMOTE | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE);
|
rsFiles -> SearchKeywords(words, initialResults,DIR_FLAGS_REMOTE | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE);
|
||||||
/* which extensions do we use? */
|
/* which extensions do we use? */
|
||||||
QString qExt, qName;
|
QString qExt, qName;
|
||||||
int extIndex;
|
int extIndex;
|
||||||
bool matched =false;
|
bool matched =false;
|
||||||
FileDetail fd;
|
DirDetails dd;
|
||||||
|
|
||||||
if (ui.FileTypeComboBox->currentIndex() == FILETYPE_IDX_ANY)
|
if (ui.FileTypeComboBox->currentIndex() == FILETYPE_IDX_ANY)
|
||||||
{
|
{
|
||||||
finalResults = &initialResults;
|
finalResults = new std::list<DirDetails>;
|
||||||
}
|
std::list<DirDetails>::iterator resultsIter;
|
||||||
else
|
for (resultsIter = initialResults.begin(); resultsIter != initialResults.end(); resultsIter ++)
|
||||||
|
{
|
||||||
|
dd = *resultsIter;
|
||||||
|
if (dd.type == DIR_TYPE_DIR) continue;
|
||||||
|
finalResults->push_back(dd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ui.FileTypeComboBox->currentIndex() == FILETYPE_IDX_DIRECTORY)
|
||||||
{
|
{
|
||||||
finalResults = new std::list<FileDetail>;
|
finalResults = new std::list<DirDetails>;
|
||||||
|
txt += " (" + ui.FileTypeComboBox->currentText().toStdString() + ")";
|
||||||
|
std::list<DirDetails>::iterator resultsIter;
|
||||||
|
for (resultsIter = initialResults.begin(); resultsIter != initialResults.end(); resultsIter ++)
|
||||||
|
{
|
||||||
|
dd = *resultsIter;
|
||||||
|
if (dd.type != DIR_TYPE_DIR) continue;
|
||||||
|
finalResults->push_back(dd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
finalResults = new std::list<DirDetails>;
|
||||||
// amend the text description of the search
|
// amend the text description of the search
|
||||||
txt += " (" + ui.FileTypeComboBox->currentText().toStdString() + ")";
|
txt += " (" + ui.FileTypeComboBox->currentText().toStdString() + ")";
|
||||||
// collect the extensions to use
|
// collect the extensions to use
|
||||||
QString extStr = SearchDialog::FileTypeExtensionMap->value(ui.FileTypeComboBox->currentIndex());
|
QString extStr = SearchDialog::FileTypeExtensionMap->value(ui.FileTypeComboBox->currentIndex());
|
||||||
QStringList extList = extStr.split(" ");
|
QStringList extList = extStr.split(" ");
|
||||||
|
|
||||||
// now iterate through the results ignoring those with wrong extensions
|
// now iterate through the results ignoring those with wrong extensions
|
||||||
std::list<FileDetail>::iterator resultsIter;
|
std::list<DirDetails>::iterator resultsIter;
|
||||||
for (resultsIter = initialResults.begin(); resultsIter != initialResults.end(); resultsIter++)
|
for (resultsIter = initialResults.begin(); resultsIter != initialResults.end(); resultsIter++)
|
||||||
{
|
{
|
||||||
fd = *resultsIter;
|
dd = *resultsIter;
|
||||||
|
if (dd.type == DIR_TYPE_DIR) continue;
|
||||||
// get this file's extension
|
// get this file's extension
|
||||||
qName = QString::fromStdString(fd.name);
|
qName = QString::fromStdString(dd.name);
|
||||||
extIndex = qName.lastIndexOf(".");
|
extIndex = qName.lastIndexOf(".");
|
||||||
if (extIndex >= 0) {
|
if (extIndex >= 0) {
|
||||||
qExt = qName.mid(extIndex+1);
|
qExt = qName.mid(extIndex+1);
|
||||||
@ -500,8 +522,8 @@ void SearchDialog::searchKeywords()
|
|||||||
for (int i = 0; i < extList.size(); ++i)
|
for (int i = 0; i < extList.size(); ++i)
|
||||||
{
|
{
|
||||||
if (qExt.toUpper() == extList.at(i).toUpper())
|
if (qExt.toUpper() == extList.at(i).toUpper())
|
||||||
{
|
{
|
||||||
finalResults->push_back(fd);
|
finalResults->push_back(dd);
|
||||||
matched = true;
|
matched = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -514,27 +536,27 @@ void SearchDialog::searchKeywords()
|
|||||||
resultsToTree(txt,req_id, *finalResults);
|
resultsToTree(txt,req_id, *finalResults);
|
||||||
ui.lineEdit->clear();
|
ui.lineEdit->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchDialog::updateFiles(qulonglong search_id,FileDetail file)
|
void SearchDialog::updateFiles(qulonglong search_id,FileDetail file)
|
||||||
{
|
{
|
||||||
/* which extensions do we use? */
|
/* which extensions do we use? */
|
||||||
std::string txt = ui.lineEdit->text().toStdString();
|
std::string txt = ui.lineEdit->text().toStdString();
|
||||||
|
|
||||||
if (ui.FileTypeComboBox->currentIndex() == FILETYPE_IDX_ANY)
|
if (ui.FileTypeComboBox->currentIndex() == FILETYPE_IDX_ANY)
|
||||||
insertFile(txt,search_id,file);
|
insertFile(txt,search_id,file);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// amend the text description of the search
|
// amend the text description of the search
|
||||||
txt += " (" + ui.FileTypeComboBox->currentText().toStdString() + ")";
|
txt += " (" + ui.FileTypeComboBox->currentText().toStdString() + ")";
|
||||||
// collect the extensions to use
|
// collect the extensions to use
|
||||||
QString extStr = SearchDialog::FileTypeExtensionMap->value(ui.FileTypeComboBox->currentIndex());
|
QString extStr = SearchDialog::FileTypeExtensionMap->value(ui.FileTypeComboBox->currentIndex());
|
||||||
QStringList extList = extStr.split(" ");
|
QStringList extList = extStr.split(" ");
|
||||||
|
|
||||||
// get this file's extension
|
// get this file's extension
|
||||||
QString qName = QString::fromStdString(file.name);
|
QString qName = QString::fromStdString(file.name);
|
||||||
int extIndex = qName.lastIndexOf(".");
|
int extIndex = qName.lastIndexOf(".");
|
||||||
|
|
||||||
if (extIndex >= 0)
|
if (extIndex >= 0)
|
||||||
{
|
{
|
||||||
QString qExt = qName.mid(extIndex+1);
|
QString qExt = qName.mid(extIndex+1);
|
||||||
|
|
||||||
@ -545,20 +567,108 @@ void SearchDialog::updateFiles(qulonglong search_id,FileDetail file)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SearchDialog::insertDirectory(const std::string &txt, qulonglong searchId, const DirDetails &dir, QTreeWidgetItem *item)
|
||||||
|
{
|
||||||
|
if (dir.type == DIR_TYPE_FILE) {
|
||||||
|
QTreeWidgetItem *child;
|
||||||
|
if (item == NULL) {
|
||||||
|
child = new QTreeWidgetItem(ui.searchResultWidget);
|
||||||
|
} else {
|
||||||
|
child = new QTreeWidgetItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* translate search result for a file */
|
||||||
|
|
||||||
|
child->setText(SR_NAME_COL, QString::fromStdString(dir.name));
|
||||||
|
child->setText(SR_HASH_COL, QString::fromStdString(dir.hash));
|
||||||
|
QString ext = QFileInfo(QString::fromStdString(dir.name)).suffix();
|
||||||
|
child->setText(SR_SIZE_COL, misc::friendlyUnit(dir.count));
|
||||||
|
child->setText(SR_REALSIZE_COL, QString::number(dir.count));
|
||||||
|
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
||||||
|
child->setText(SR_ID_COL, QString::number(1));
|
||||||
|
child->setText(SR_SEARCH_ID_COL, QString::number(searchId,16));
|
||||||
|
setIconAndType(child, ext);
|
||||||
|
|
||||||
|
if (item == NULL) {
|
||||||
|
ui.searchResultWidget->addTopLevelItem(child);
|
||||||
|
} else {
|
||||||
|
item->addChild(child);
|
||||||
|
}
|
||||||
|
} else { /* it is a directory */
|
||||||
|
QTreeWidgetItem *child;
|
||||||
|
if (item == NULL) {
|
||||||
|
child = new QTreeWidgetItem(ui.searchResultWidget);
|
||||||
|
} else {
|
||||||
|
child = new QTreeWidgetItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
child->setIcon(SR_ICON_COL, QIcon(IMAGE_DIRECTORY));
|
||||||
|
child->setText(SR_NAME_COL, QString::fromStdString(dir.name));
|
||||||
|
child->setText(SR_HASH_COL, QString::fromStdString(dir.hash));
|
||||||
|
child->setText(SR_SIZE_COL, misc::friendlyUnit(dir.count));
|
||||||
|
child->setText(SR_REALSIZE_COL, QString::number(dir.count));
|
||||||
|
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
||||||
|
child->setText(SR_ID_COL, QString::number(1));
|
||||||
|
child->setText(SR_SEARCH_ID_COL, QString::number(searchId,16));
|
||||||
|
|
||||||
|
if (item == NULL) {
|
||||||
|
ui.searchResultWidget->addTopLevelItem(child);
|
||||||
|
|
||||||
|
/* add to the summary as well */
|
||||||
|
|
||||||
|
int items = ui.searchSummaryWidget->topLevelItemCount();
|
||||||
|
bool found = false ;
|
||||||
|
|
||||||
|
for(int i = 0; i < items; i++)
|
||||||
|
{
|
||||||
|
if(ui.searchSummaryWidget->topLevelItem(i)->text(SS_SEARCH_ID_COL).toInt(NULL,16) == searchId)
|
||||||
|
{
|
||||||
|
// increment result since every item is new
|
||||||
|
int s = ui.searchSummaryWidget->topLevelItem(i)->text(SS_COUNT_COL).toInt() ;
|
||||||
|
ui.searchSummaryWidget->topLevelItem(i)->setText(SS_COUNT_COL,QString::number(s+1));
|
||||||
|
found = true ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!found)
|
||||||
|
{
|
||||||
|
QTreeWidgetItem *item2 = new QTreeWidgetItem();
|
||||||
|
item2->setText(SS_TEXT_COL, QString::fromStdString(txt));
|
||||||
|
item2->setText(SS_COUNT_COL, QString::number(1));
|
||||||
|
item2->setText(SS_SEARCH_ID_COL, QString::number(searchId,16));
|
||||||
|
|
||||||
|
ui.searchSummaryWidget->addTopLevelItem(item2);
|
||||||
|
ui.searchSummaryWidget->setCurrentItem(item2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* select this search result */
|
||||||
|
selectSearchResults();
|
||||||
|
} else {
|
||||||
|
item->addChild(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* go through all children directories/files for a recursive call */
|
||||||
|
for (std::list<DirStub>::const_iterator it(dir.children.begin()); it != dir.children.end(); it ++) {
|
||||||
|
DirDetails details;
|
||||||
|
rsFiles->RequestDirDetails(it->ref, details, 0);
|
||||||
|
insertDirectory(txt, searchId, details, child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const FileDetail& file)
|
void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const FileDetail& file)
|
||||||
{
|
{
|
||||||
// algo:
|
// algo:
|
||||||
//
|
//
|
||||||
// 1 - look in result window whether the file already exist.
|
// 1 - look in result window whether the file already exist.
|
||||||
// 1.1 - If yes, just increment the source number.
|
// 1.1 - If yes, just increment the source number.
|
||||||
// 2.2 - Otherwize, add an entry.
|
// 2.2 - Otherwize, add an entry.
|
||||||
// 2 - look in the summary whether there exist the same request id.
|
// 2 - look in the summary whether there exist the same request id.
|
||||||
// 1.1 - If yes, just increment the result number.
|
// 1.1 - If yes, just increment the result number.
|
||||||
// 2.2 - Otherwize, add an entry.
|
// 2.2 - Otherwize, add an entry.
|
||||||
//
|
//
|
||||||
|
|
||||||
// 1 - look in result window whether the file already exists.
|
// 1 - look in result window whether the file already exists.
|
||||||
//
|
//
|
||||||
int items = ui.searchResultWidget->topLevelItemCount();
|
int items = ui.searchResultWidget->topLevelItemCount();
|
||||||
bool found = false ;
|
bool found = false ;
|
||||||
@ -571,7 +681,7 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const
|
|||||||
ui.searchResultWidget->topLevelItem(i)->setText(SR_ID_COL,QString::number(s+1));
|
ui.searchResultWidget->topLevelItem(i)->setText(SR_ID_COL,QString::number(s+1));
|
||||||
found = true ;
|
found = true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!found)
|
if(!found)
|
||||||
{
|
{
|
||||||
/* translate search results */
|
/* translate search results */
|
||||||
@ -581,56 +691,7 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const
|
|||||||
item->setText(SR_HASH_COL, QString::fromStdString(file.hash));
|
item->setText(SR_HASH_COL, QString::fromStdString(file.hash));
|
||||||
|
|
||||||
QString ext = QFileInfo(QString::fromStdString(file.name)).suffix();
|
QString ext = QFileInfo(QString::fromStdString(file.name)).suffix();
|
||||||
if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif" || ext == "bmp" || ext == "ico" || ext == "svg")
|
setIconAndType(item, ext);
|
||||||
{
|
|
||||||
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypePicture.png"));
|
|
||||||
item->setText(SR_TYPE_COL, QString::fromUtf8("Picture"));
|
|
||||||
}
|
|
||||||
else if (ext == "avi" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "mkv" || ext == "mp4" || ext == "flv" || ext == "mov" || ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp")
|
|
||||||
{
|
|
||||||
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeVideo.png"));
|
|
||||||
item->setText(SR_TYPE_COL, QString::fromUtf8("Video"));
|
|
||||||
}
|
|
||||||
else if (ext == "ogg" || ext == "mp3" || ext == "wav" || ext == "wma")
|
|
||||||
{
|
|
||||||
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeAudio.png"));
|
|
||||||
item->setText(SR_TYPE_COL, QString::fromUtf8("Audio"));
|
|
||||||
}
|
|
||||||
else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "gz" || ext == "rar" || ext == "rpm" || ext == "deb")
|
|
||||||
{
|
|
||||||
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeArchive.png"));
|
|
||||||
item->setText(SR_TYPE_COL, QString::fromUtf8("Archive"));
|
|
||||||
}
|
|
||||||
else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com" || ext == "bin" || ext == "exe" || ext == "js" || ext == "pif" || ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws")
|
|
||||||
{
|
|
||||||
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeProgram.png"));
|
|
||||||
item->setText(SR_TYPE_COL, QString::fromUtf8("Program"));
|
|
||||||
}
|
|
||||||
else if (ext == "iso" || ext == "nrg" || ext == "mdf" )
|
|
||||||
{
|
|
||||||
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeCDImage.png"));
|
|
||||||
item->setText(SR_TYPE_COL, QString::fromUtf8("CD-Image"));
|
|
||||||
}
|
|
||||||
else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h")
|
|
||||||
{
|
|
||||||
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeDocument.png"));
|
|
||||||
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
|
|
||||||
}
|
|
||||||
else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls"
|
|
||||||
|| ext == "sxc" || ext == "odt" || ext == "ods")
|
|
||||||
{
|
|
||||||
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeDocument.png"));
|
|
||||||
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
|
|
||||||
}
|
|
||||||
else if (ext == "html" || ext == "htm" || ext == "php")
|
|
||||||
{
|
|
||||||
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeDocument.png"));
|
|
||||||
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeAny.png"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* to facilitate downlaods we need to save the file size too
|
* to facilitate downlaods we need to save the file size too
|
||||||
@ -676,15 +737,32 @@ void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const
|
|||||||
selectSearchResults();
|
selectSearchResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchDialog::resultsToTree(std::string txt,qulonglong searchId, const std::list<FileDetail>& results)
|
void SearchDialog::resultsToTree(std::string txt,qulonglong searchId, const std::list<DirDetails>& results)
|
||||||
{
|
{
|
||||||
|
ui.searchResultWidget->setSortingEnabled(false);
|
||||||
|
|
||||||
/* translate search results */
|
/* translate search results */
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
out << searchId;
|
out << searchId;
|
||||||
|
|
||||||
std::list<FileDetail>::const_iterator it;
|
std::list<DirDetails>::const_iterator it;
|
||||||
for(it = results.begin(); it != results.end(); it++)
|
for(it = results.begin(); it != results.end(); it++)
|
||||||
insertFile(txt,searchId,*it) ;
|
if (it->type == DIR_TYPE_FILE) {
|
||||||
|
FileDetail fd;
|
||||||
|
fd.id = it->id;
|
||||||
|
fd.name = it->name;
|
||||||
|
fd.hash = it->hash;
|
||||||
|
fd.path = it->path;
|
||||||
|
fd.size = it->count;
|
||||||
|
fd.age = it->age;
|
||||||
|
fd.rank = 0;
|
||||||
|
|
||||||
|
insertFile(txt,searchId,fd);
|
||||||
|
} else if (it->type == DIR_TYPE_DIR) {
|
||||||
|
insertDirectory(txt, searchId, *it, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.searchResultWidget->setSortingEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -722,4 +800,56 @@ void SearchDialog::selectSearchResults()
|
|||||||
ui.searchResultWidget->update();
|
ui.searchResultWidget->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SearchDialog::setIconAndType(QTreeWidgetItem *item, QString &ext)
|
||||||
|
{
|
||||||
|
if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif" || ext == "bmp" || ext == "ico" || ext == "svg")
|
||||||
|
{
|
||||||
|
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypePicture.png"));
|
||||||
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Picture"));
|
||||||
|
}
|
||||||
|
else if (ext == "avi" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "mkv" || ext == "mp4" || ext == "flv" || ext == "mov" || ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp")
|
||||||
|
{
|
||||||
|
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeVideo.png"));
|
||||||
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Video"));
|
||||||
|
}
|
||||||
|
else if (ext == "ogg" || ext == "mp3" || ext == "wav" || ext == "wma")
|
||||||
|
{
|
||||||
|
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeAudio.png"));
|
||||||
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Audio"));
|
||||||
|
}
|
||||||
|
else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "gz" || ext == "rar" || ext == "rpm" || ext == "deb")
|
||||||
|
{
|
||||||
|
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeArchive.png"));
|
||||||
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Archive"));
|
||||||
|
}
|
||||||
|
else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com" || ext == "bin" || ext == "exe" || ext == "js" || ext == "pif" || ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws")
|
||||||
|
{
|
||||||
|
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeProgram.png"));
|
||||||
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Program"));
|
||||||
|
}
|
||||||
|
else if (ext == "iso" || ext == "nrg" || ext == "mdf" )
|
||||||
|
{
|
||||||
|
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeCDImage.png"));
|
||||||
|
item->setText(SR_TYPE_COL, QString::fromUtf8("CD-Image"));
|
||||||
|
}
|
||||||
|
else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h")
|
||||||
|
{
|
||||||
|
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeDocument.png"));
|
||||||
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
|
||||||
|
}
|
||||||
|
else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls"
|
||||||
|
|| ext == "sxc" || ext == "odt" || ext == "ods")
|
||||||
|
{
|
||||||
|
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeDocument.png"));
|
||||||
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
|
||||||
|
}
|
||||||
|
else if (ext == "html" || ext == "htm" || ext == "php")
|
||||||
|
{
|
||||||
|
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeDocument.png"));
|
||||||
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeAny.png"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
* Boston, MA 02110-1301, USA.
|
* Boston, MA 02110-1301, USA.
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
@ -35,38 +35,38 @@
|
|||||||
#include "advsearch/advancedsearchdialog.h"
|
#include "advsearch/advancedsearchdialog.h"
|
||||||
#include "Preferences/rsharesettings.h"
|
#include "Preferences/rsharesettings.h"
|
||||||
|
|
||||||
class SearchDialog : public MainPage
|
class SearchDialog : public MainPage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Default Constructor */
|
/** Default Constructor */
|
||||||
SearchDialog(QWidget *parent = 0);
|
SearchDialog(QWidget *parent = 0);
|
||||||
/** Default Destructor */
|
/** Default Destructor */
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateFiles(qulonglong request_id,FileDetail file) ;
|
void updateFiles(qulonglong request_id,FileDetail file) ;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
/** Create the context popup menu and it's submenus */
|
/** Create the context popup menu and it's submenus */
|
||||||
void searchtableWidgetCostumPopupMenu( QPoint point );
|
void searchtableWidgetCostumPopupMenu( QPoint point );
|
||||||
|
|
||||||
void searchtableWidget2CostumPopupMenu( QPoint point );
|
void searchtableWidget2CostumPopupMenu( QPoint point );
|
||||||
|
|
||||||
void download();
|
void download();
|
||||||
|
|
||||||
void broadcastonchannel();
|
void broadcastonchannel();
|
||||||
|
|
||||||
void recommendtofriends();
|
void recommendtofriends();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void searchRemove();
|
void searchRemove();
|
||||||
|
|
||||||
void searchRemoveAll();
|
void searchRemoveAll();
|
||||||
|
|
||||||
void searchKeywords();
|
void searchKeywords();
|
||||||
|
|
||||||
/** management of the adv search dialog object when switching search modes */
|
/** management of the adv search dialog object when switching search modes */
|
||||||
@ -80,32 +80,34 @@ private slots:
|
|||||||
void advancedSearch(Expression*);
|
void advancedSearch(Expression*);
|
||||||
|
|
||||||
void selectSearchResults();
|
void selectSearchResults();
|
||||||
|
|
||||||
void clearKeyword();
|
void clearKeyword();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** render the results to the tree widget display */
|
/** render the results to the tree widget display */
|
||||||
void resultsToTree(std::string,qulonglong searchId, const std::list<FileDetail>&);
|
void resultsToTree(std::string,qulonglong searchId, const std::list<DirDetails>&);
|
||||||
void insertFile(const std::string& txt,qulonglong searchId, const FileDetail& file) ;
|
void insertFile(const std::string& txt,qulonglong searchId, const FileDetail& file) ;
|
||||||
|
void insertDirectory(const std::string &txt, qulonglong searchId, const DirDetails &dir, QTreeWidgetItem *item);
|
||||||
|
void setIconAndType(QTreeWidgetItem *item, QString &ext);
|
||||||
|
|
||||||
|
|
||||||
/** the advanced search dialog instance */
|
/** the advanced search dialog instance */
|
||||||
AdvancedSearchDialog * advSearchDialog;
|
AdvancedSearchDialog * advSearchDialog;
|
||||||
|
|
||||||
/** Define the popup menus for the Context menu */
|
/** Define the popup menus for the Context menu */
|
||||||
QMenu* contextMnu;
|
QMenu* contextMnu;
|
||||||
|
|
||||||
QMenu* contextMnu2;
|
QMenu* contextMnu2;
|
||||||
|
|
||||||
/** Defines the actions for the context menu */
|
/** Defines the actions for the context menu */
|
||||||
QAction* downloadAct;
|
QAction* downloadAct;
|
||||||
QAction* broadcastonchannelAct;
|
QAction* broadcastonchannelAct;
|
||||||
QAction* recommendtofriendsAct;
|
QAction* recommendtofriendsAct;
|
||||||
|
|
||||||
QAction* searchRemoveAct;
|
QAction* searchRemoveAct;
|
||||||
QAction* searchRemoveAllAct;
|
QAction* searchRemoveAllAct;
|
||||||
|
|
||||||
/** Contains the mapping of filetype combobox to filetype extensions */
|
/** Contains the mapping of filetype combobox to filetype extensions */
|
||||||
static const int FILETYPE_IDX_ANY;
|
static const int FILETYPE_IDX_ANY;
|
||||||
static const int FILETYPE_IDX_ARCHIVE;
|
static const int FILETYPE_IDX_ARCHIVE;
|
||||||
@ -115,19 +117,20 @@ private:
|
|||||||
static const int FILETYPE_IDX_PICTURE;
|
static const int FILETYPE_IDX_PICTURE;
|
||||||
static const int FILETYPE_IDX_PROGRAM;
|
static const int FILETYPE_IDX_PROGRAM;
|
||||||
static const int FILETYPE_IDX_VIDEO;
|
static const int FILETYPE_IDX_VIDEO;
|
||||||
|
static const int FILETYPE_IDX_DIRECTORY;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static QMap<int, QString> * FileTypeExtensionMap;
|
static QMap<int, QString> * FileTypeExtensionMap;
|
||||||
static bool initialised;
|
static bool initialised;
|
||||||
void initialiseFileTypeMappings();
|
void initialiseFileTypeMappings();
|
||||||
|
|
||||||
/****
|
/****
|
||||||
QTreeWidget *searchtableWidget;
|
QTreeWidget *searchtableWidget;
|
||||||
QTreeWidget *searchtablewidget2;
|
QTreeWidget *searchtablewidget2;
|
||||||
****/
|
****/
|
||||||
|
|
||||||
int nextSearchId;
|
int nextSearchId;
|
||||||
|
|
||||||
/** Qt Designer generated object */
|
/** Qt Designer generated object */
|
||||||
Ui::SearchDialog ui;
|
Ui::SearchDialog ui;
|
||||||
};
|
};
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>627</width>
|
<width>645</width>
|
||||||
<height>341</height>
|
<height>341</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -576,6 +576,15 @@
|
|||||||
<normaloff>:/images/FileTypeVideo.png</normaloff>:/images/FileTypeVideo.png</iconset>
|
<normaloff>:/images/FileTypeVideo.png</normaloff>:/images/FileTypeVideo.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Directory</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="images.qrc">
|
||||||
|
<normaloff>:/images/folder_green16.png</normaloff>:/images/folder_green16.png</iconset>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
|
@ -149,8 +149,8 @@ virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size,
|
|||||||
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details) = 0;
|
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details) = 0;
|
||||||
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) = 0;
|
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) = 0;
|
||||||
|
|
||||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results,uint32_t flags) = 0;
|
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags) = 0;
|
||||||
virtual int SearchBoolExp(Expression * exp, std::list<FileDetail> &results,uint32_t flags) = 0;
|
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags) = 0;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Utility Functions.
|
* Utility Functions.
|
||||||
|
Loading…
Reference in New Issue
Block a user