mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
* Addition of new File Transfer structure. (server / search / extralist / controller)
* Fixed up variable names in p3Qblog.cc * Cleaned up unused BaseInfo/PersonInfo/DirInfo in rstypes/rsiface * added new rsfiles interface (rough outline at the moment) git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@628 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
eeb13e7b18
commit
473f3f75f3
109
libretroshare/src/ft/ftcontroller.h
Normal file
109
libretroshare/src/ft/ftcontroller.h
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/ft: ftcontroller.h
|
||||||
|
*
|
||||||
|
* File Transfer for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FT_CONTROLLER_HEADER
|
||||||
|
#define FT_CONTROLLER_HEADER
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ftController
|
||||||
|
*
|
||||||
|
* Top level download controller.
|
||||||
|
*
|
||||||
|
* inherits configuration (save downloading files)
|
||||||
|
* inherits pqiMonitor (knows which peers are online).
|
||||||
|
* inherits CacheTransfer (transfers cache files too)
|
||||||
|
* inherits RsThread (to control transfers)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class ftController: public CacheTransfer, public RsThread, public pqiMonitor, public p3Config
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/* Setup */
|
||||||
|
ftController(std::string configDir);
|
||||||
|
|
||||||
|
void setFtSearch(ftSearch *);
|
||||||
|
|
||||||
|
virtual void run();
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/********************** Controller Access **********************/
|
||||||
|
/***************************************************************/
|
||||||
|
|
||||||
|
bool FileRequest(std::string fname, std::string hash,
|
||||||
|
uint32_t size, std::string dest, uint32_t flags);
|
||||||
|
|
||||||
|
bool FileCancel(std::string hash);
|
||||||
|
bool FileControl(std::string hash, uint32_t flags);
|
||||||
|
bool FileClearCompleted();
|
||||||
|
|
||||||
|
/* get Details of File Transfers */
|
||||||
|
bool FileDownloads(std::list<std::string> &hashs);
|
||||||
|
|
||||||
|
/* Directory Handling */
|
||||||
|
void setDownloadDirectory(std::string path);
|
||||||
|
void setPartialsDirectory(std::string path);
|
||||||
|
std::string getDownloadDirectory();
|
||||||
|
std::string getPartialsDirectory();
|
||||||
|
bool FileDetails(std::string hash, FileInfo &info);
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/********************** Controller Access **********************/
|
||||||
|
/***************************************************************/
|
||||||
|
|
||||||
|
/* pqiMonitor callback (also provided mConnMgr pointer!) */
|
||||||
|
public:
|
||||||
|
virtual void statusChange(const std::list<pqipeer> &plist);
|
||||||
|
|
||||||
|
|
||||||
|
/* p3Config Interface */
|
||||||
|
protected:
|
||||||
|
virtual RsSerialiser *setupSerialiser();
|
||||||
|
virtual std::list<RsItem *> saveList(bool &cleanup);
|
||||||
|
virtual bool loadList(std::list<RsItem *> load);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/* RunTime Functions */
|
||||||
|
|
||||||
|
/* pointers to other components */
|
||||||
|
|
||||||
|
ftSearch *mSearch;
|
||||||
|
|
||||||
|
RsMutex ctrlMutex;
|
||||||
|
|
||||||
|
std::list<FileDetails> incomingQueue;
|
||||||
|
std::map<std::string, FileDetails> mCompleted;
|
||||||
|
|
||||||
|
std::map<std::string, ftTransferModule *> mTransfers;
|
||||||
|
std::map<std::string, ftFileCreator *> mFileCreators;
|
||||||
|
|
||||||
|
std::string mConfigPath;
|
||||||
|
std::string mDownloadPath;
|
||||||
|
std::string mPartialPath;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
268
libretroshare/src/ft/ftextralist.cc
Normal file
268
libretroshare/src/ft/ftextralist.cc
Normal file
@ -0,0 +1,268 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/ft: ftextralist.cc
|
||||||
|
*
|
||||||
|
* File Transfer for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FT_FILE_EXTRA_LIST_HEADER
|
||||||
|
#define FT_FILE_EXTRA_LIST_HEADER
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ftFileExtraList
|
||||||
|
*
|
||||||
|
* This maintains a list of 'Extra Files' to share with peers.
|
||||||
|
*
|
||||||
|
* Files are added via:
|
||||||
|
* 1) For Files which have been hashed already:
|
||||||
|
* addExtraFile(std::string path, std::string hash, uint64_t size, uint32_t period, uint32_t flags);
|
||||||
|
*
|
||||||
|
* 2) For Files to be hashed:
|
||||||
|
* hashExtraFile(std::string path, uint32_t period, uint32_t flags);
|
||||||
|
*
|
||||||
|
* Results of Hashing can be retrieved via:
|
||||||
|
* hashExtraFileDone(std::string path, std::string &hash, uint64_t &size);
|
||||||
|
*
|
||||||
|
* Files can be searched for via:
|
||||||
|
* searchExtraFiles(std::string hash, ftFileDetail file);
|
||||||
|
*
|
||||||
|
* This Class is Mutexed protected, and has a thread in it which checks the files periodically.
|
||||||
|
* If a file is found to have changed... It is discarded from the list - and not updated.
|
||||||
|
*
|
||||||
|
* this thread is also used to hash added files.
|
||||||
|
*
|
||||||
|
* The list of extra files is stored using the configuration system.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class FileDetails
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
std::list<std::string> sources;
|
||||||
|
std::string path;
|
||||||
|
std::string fname;
|
||||||
|
std::string hash;
|
||||||
|
uint64_t size;
|
||||||
|
|
||||||
|
uint32_t start;
|
||||||
|
uint32_t period;
|
||||||
|
uint32_t flags;
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint32_t FT_DETAILS_CLEANUP = 0x0100; /* remove when it expires */
|
||||||
|
const uint32_t FT_DETAILS_LOCAL = 0x0001;
|
||||||
|
const uint32_t FT_DETAILS_REMOTE = 0x0002;
|
||||||
|
|
||||||
|
class ftExtraList: public p3Config
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
ftExtraList::ftExtraList()
|
||||||
|
:p3Config(CONFIG_FT_EXTRA_LIST)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ftExtraList::run()
|
||||||
|
{
|
||||||
|
bool todo = false;
|
||||||
|
time_t cleanup = 0;
|
||||||
|
time_t now = 0;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
now = time(NULL);
|
||||||
|
|
||||||
|
{
|
||||||
|
RsStackMutex stack(extMutex);
|
||||||
|
|
||||||
|
todo = (mToHash.size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (todo)
|
||||||
|
{
|
||||||
|
/* Hash a file */
|
||||||
|
hashAFile();
|
||||||
|
|
||||||
|
/* microsleep */
|
||||||
|
usleep(10);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* cleanup */
|
||||||
|
if (cleanup < now)
|
||||||
|
{
|
||||||
|
cleanupOldFiles();
|
||||||
|
cleanup = now + CLEANUP_PERIOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* sleep */
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ftExtraList::hashAFile()
|
||||||
|
{
|
||||||
|
/* extract entry from the queue */
|
||||||
|
std::string path;
|
||||||
|
|
||||||
|
{
|
||||||
|
RsStackMutex stack(extMutex);
|
||||||
|
path = mToHash.front();
|
||||||
|
mToHash.pop_front();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* hash it! */
|
||||||
|
if (hashFile(path, details))
|
||||||
|
{
|
||||||
|
/* stick it in the available queue */
|
||||||
|
addExtraFile(path, hash, size, period, flags);
|
||||||
|
|
||||||
|
/* add to the path->hash map */
|
||||||
|
addNewlyHashed(path, details);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
* If the File is alreay Hashed, then just add it in.
|
||||||
|
**/
|
||||||
|
|
||||||
|
bool ftExtraList::addExtraFile(std::string path, std::string hash,
|
||||||
|
uint64_t size, uint32_t period, uint32_t flags)
|
||||||
|
{
|
||||||
|
RsStackMutex stack(extMutex);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool ftExtraList::cleanupOldFiles()
|
||||||
|
{
|
||||||
|
RsStackMutex stack(extMutex);
|
||||||
|
|
||||||
|
std::list<std::string> toRemove;
|
||||||
|
std::list<std::string>::iterator rit;
|
||||||
|
|
||||||
|
std::map<std::string, FileDetails>::iterator it;
|
||||||
|
for(it = mFiles.begin(); it != mFiles.end(); it++)
|
||||||
|
{
|
||||||
|
/* check timestamps */
|
||||||
|
if (it->
|
||||||
|
{
|
||||||
|
toRemove.push_back(it->first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toRemove.size() > 0)
|
||||||
|
{
|
||||||
|
/* remove items */
|
||||||
|
for(rit = toRemove.begin(); rit != toRemove.end(); rit++)
|
||||||
|
{
|
||||||
|
if (mFiles.end() != (it = mFiles.find(*rit)))
|
||||||
|
{
|
||||||
|
mFiles.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Hash file, and add to the files,
|
||||||
|
* file is removed after period.
|
||||||
|
**/
|
||||||
|
|
||||||
|
bool ftExtraList::hashExtraFile(std::string path, uint32_t period, uint32_t flags)
|
||||||
|
{
|
||||||
|
/* add into queue */
|
||||||
|
RsStackMutex stack(extMutex);
|
||||||
|
|
||||||
|
FileDetails details(path, period, flags);
|
||||||
|
mToHash.push_back(details);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ftExtraList::hashExtraFileDone(std::string path, FileDetails &details)
|
||||||
|
{
|
||||||
|
std::string hash;
|
||||||
|
{
|
||||||
|
/* Find in the path->hash map */
|
||||||
|
RsStackMutex stack(extMutex);
|
||||||
|
|
||||||
|
std::map<std::string, std::string>::iterator it;
|
||||||
|
if (mHashedList.end() == (it = mHashedList.find(path)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
hash = it->second;
|
||||||
|
}
|
||||||
|
return searchExtraFiles(hash, details);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Search Function - used by File Transfer
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
bool ftExtraList::searchExtraFiles(std::string hash, FileDetails &details)
|
||||||
|
{
|
||||||
|
RsStackMutex stack(extMutex);
|
||||||
|
|
||||||
|
/* find hash */
|
||||||
|
std::map<std::string, FileDetails>::iterator fit;
|
||||||
|
if (mFiles.end() == (fit = mFiles.find(hash)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
details = fit->second;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Configuration - store extra files.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
RsSerialiser *ftExtraList::setupSerialiser()
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<RsItem *> ftExtraList::saveList(bool &cleanup)
|
||||||
|
{
|
||||||
|
std::list<RsItem *> sList;
|
||||||
|
return sList;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ftExtraList::loadList(std::list<RsItem *> load)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
122
libretroshare/src/ft/ftextralist.h
Normal file
122
libretroshare/src/ft/ftextralist.h
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/ft: ftextralist.h
|
||||||
|
*
|
||||||
|
* File Transfer for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FT_FILE_EXTRA_LIST_HEADER
|
||||||
|
#define FT_FILE_EXTRA_LIST_HEADER
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ftFileExtraList
|
||||||
|
*
|
||||||
|
* This maintains a list of 'Extra Files' to share with peers.
|
||||||
|
*
|
||||||
|
* Files are added via:
|
||||||
|
* 1) For Files which have been hashed already:
|
||||||
|
* addExtraFile(std::string path, std::string hash, uint64_t size, uint32_t period, uint32_t flags);
|
||||||
|
*
|
||||||
|
* 2) For Files to be hashed:
|
||||||
|
* hashExtraFile(std::string path, uint32_t period, uint32_t flags);
|
||||||
|
*
|
||||||
|
* Results of Hashing can be retrieved via:
|
||||||
|
* hashExtraFileDone(std::string path, std::string &hash, uint64_t &size);
|
||||||
|
*
|
||||||
|
* Files can be searched for via:
|
||||||
|
* searchExtraFiles(std::string hash, ftFileDetail file);
|
||||||
|
*
|
||||||
|
* This Class is Mutexed protected, and has a thread in it which checks the files periodically.
|
||||||
|
* If a file is found to have changed... It is discarded from the list - and not updated.
|
||||||
|
*
|
||||||
|
* this thread is also used to hash added files.
|
||||||
|
*
|
||||||
|
* The list of extra files is stored using the configuration system.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class FileDetails
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
std::list<std::string> sources;
|
||||||
|
std::string path;
|
||||||
|
std::string fname;
|
||||||
|
std::string hash;
|
||||||
|
uint64_t size;
|
||||||
|
|
||||||
|
uint32_t start;
|
||||||
|
uint32_t period;
|
||||||
|
uint32_t flags;
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint32_t FT_DETAILS_CLEANUP = 0x0100; /* remove when it expires */
|
||||||
|
const uint32_t FT_DETAILS_LOCAL = 0x0001;
|
||||||
|
const uint32_t FT_DETAILS_REMOTE = 0x0002;
|
||||||
|
|
||||||
|
class ftExtraList: public p3Config
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
ftExtraList();
|
||||||
|
|
||||||
|
/***
|
||||||
|
* If the File is alreay Hashed, then just add it in.
|
||||||
|
**/
|
||||||
|
|
||||||
|
bool addExtraFile(std::string path, std::string hash,
|
||||||
|
uint64_t size, uint32_t period, uint32_t flags);
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Hash file, and add to the files,
|
||||||
|
* file is removed after period.
|
||||||
|
**/
|
||||||
|
|
||||||
|
bool hashExtraFile(std::string path, uint32_t period, uint32_t flags);
|
||||||
|
bool hashExtraFileDone(std::string path, FileDetails &details);
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Search Function - used by File Transfer
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
bool searchExtraFiles(std::string hash, FileDetails &details);
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Configuration - store extra files.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
protected:
|
||||||
|
virtual RsSerialiser *setupSerialiser();
|
||||||
|
virtual std::list<RsItem *> saveList(bool &cleanup);
|
||||||
|
virtual bool loadList(std::list<RsItem *> load);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
RsMutex extMutex;
|
||||||
|
|
||||||
|
std::map<std::string, std::string> hashedList; /* path -> hash ( not saved ) */
|
||||||
|
std::map<std::string, FileDetails> files;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
79
libretroshare/src/ft/ftfilesearch.cc
Normal file
79
libretroshare/src/ft/ftfilesearch.cc
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/ft: ftfilesearch.cc
|
||||||
|
*
|
||||||
|
* File Transfer for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FT_FILE_SEARCH_HEADERd
|
||||||
|
#define FT_FILE_SEARCH_HEADER
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ftFileSearch
|
||||||
|
*
|
||||||
|
* This is actually implements the ftSearch Interface.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ft/ftfilesearch.h"
|
||||||
|
#include "dbase/cachestrapper.h"
|
||||||
|
#include "dbase/fimonitor.h"
|
||||||
|
#include "dbase/fistore.h"
|
||||||
|
|
||||||
|
bool ftFileSearch::search(std::string hash, uint64_t size, uint32_t hintflags, FileInfo &info)
|
||||||
|
{
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* actual search depends on the hints */
|
||||||
|
if (hintflags | CACHE)
|
||||||
|
{
|
||||||
|
mCacheStrapper->..
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hintflags | LOCAL)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hintflags | EXTRA)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hintflags | REMOTE)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
CacheStrapper *mCacheStrapper;
|
||||||
|
ftExtraList *mExtraList;
|
||||||
|
FileIndexMonitor *mFileMonitor;
|
||||||
|
FileIndexStore *mFileStore;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
64
libretroshare/src/ft/ftfilesearch.h
Normal file
64
libretroshare/src/ft/ftfilesearch.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/ft: ftfilesearch.h
|
||||||
|
*
|
||||||
|
* File Transfer for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FT_FILE_SEARCH_HEADER
|
||||||
|
#define FT_FILE_SEARCH_HEADER
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ftFileSearch
|
||||||
|
*
|
||||||
|
* This is actually implements the ftSearch Interface.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ft/ftsearch.h"
|
||||||
|
|
||||||
|
class CacheStrapper;
|
||||||
|
class ftExtraList;
|
||||||
|
class FileIndexMonitor;
|
||||||
|
class FileIndexStore;
|
||||||
|
|
||||||
|
class ftFileSearch: public ftSearch
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
ftFileSearch(CacheStrapper *c, ftExtraList *x, FileIndexMonitor *m, FileIndexStore *s)
|
||||||
|
:mCacheStrapper(c), mExtraList(x), mFileMonitor(m), mFileStore(s) { return; }
|
||||||
|
|
||||||
|
virtual bool search(std::string hash, uint64_t size, uint32_t hintflags, FileInfo &info);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
CacheStrapper *mCacheStrapper;
|
||||||
|
ftExtraList *mExtraList;
|
||||||
|
FileIndexMonitor *mFileMonitor;
|
||||||
|
FileIndexStore *mFileStore;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
51
libretroshare/src/ft/ftsearch.h
Normal file
51
libretroshare/src/ft/ftsearch.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/ft: ftsearch.h
|
||||||
|
*
|
||||||
|
* File Transfer for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FT_SEARCH_HEADER
|
||||||
|
#define FT_SEARCH_HEADER
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ftSearch
|
||||||
|
*
|
||||||
|
* This is a generic search interface - used by ft* to find files.
|
||||||
|
* The derived class will search for Caches/Local/ExtraList/Remote entries.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "rsiface/rstypes.h"
|
||||||
|
|
||||||
|
class ftSearch
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
ftSearch() { return; }
|
||||||
|
virtual bool search(std::string hash, uint64_t size, uint32_t hintflags, FileInfo &info);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
301
libretroshare/src/ft/ftserver.cc
Normal file
301
libretroshare/src/ft/ftserver.cc
Normal file
@ -0,0 +1,301 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/ft: ftserver.cc
|
||||||
|
*
|
||||||
|
* File Transfer for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Setup */
|
||||||
|
ftServer::ftServer(CacheStrapper *cStrapper, p3ConnectMgr *connMgr)
|
||||||
|
:mCacheStrapper(cStrapper), mConnMgr(connMgr)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Final Setup (once everything is assigned) */
|
||||||
|
ftServer::SetupFtServer()
|
||||||
|
{
|
||||||
|
/* make Controller */
|
||||||
|
mFtController = new ftController();
|
||||||
|
NotifyBase *cb = getNotify();
|
||||||
|
|
||||||
|
/* setup FiStore/Monitor */
|
||||||
|
std::string localcachedir = config_dir + "/cache/local";
|
||||||
|
std::string remotecachedir = config_dir + "/cache/remote";
|
||||||
|
std::string ownId = mConnMgr->getOwnId();
|
||||||
|
|
||||||
|
mFiStore = new FileIndexStore(mCacheStrapper, mFtController, cb, ownId, remotecachedir);
|
||||||
|
mFiMon = new FileIndexMonitor(mCacheStrapper, localcachedir, ownId);
|
||||||
|
|
||||||
|
/* now add the set to the cachestrapper */
|
||||||
|
CachePair cp(mFiMon, mFiStore, CacheId(RS_SERVICE_TYPE_FILE_INDEX, 0));
|
||||||
|
mCacheStrapper -> addCachePair(cp);
|
||||||
|
|
||||||
|
/* extras List */
|
||||||
|
mFtExtra = new ftExtraList();
|
||||||
|
mFtSearch = new ftFileSearch(mCacheStrapper, mFtExtra, mFiMon, mFiStore);
|
||||||
|
|
||||||
|
mFtController -> setFtSearch(mFtSearch);
|
||||||
|
ftFiler -> setSaveBasePath(save_dir);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Assign important variables */
|
||||||
|
void setConfigDirectory(std::string path);
|
||||||
|
|
||||||
|
void setPQInterface(PQInterface *pqi);
|
||||||
|
|
||||||
|
/* Final Setup (once everything is assigned) */
|
||||||
|
void SetupFtServer();
|
||||||
|
|
||||||
|
/* add Config Items (Extra, Controller) */
|
||||||
|
void addConfigComponents(p3ConfigMgr *mgr);
|
||||||
|
|
||||||
|
|
||||||
|
void ftServer::setConfigDirectory(std::string path)
|
||||||
|
{
|
||||||
|
mConfigPath = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ftServer::setPQInterface(PQInterface *pqi)
|
||||||
|
|
||||||
|
/* Control Interface */
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void ftServer::StartupThreads()
|
||||||
|
{
|
||||||
|
/* start up Controller thread */
|
||||||
|
|
||||||
|
/* start own thread */
|
||||||
|
}
|
||||||
|
|
||||||
|
CacheStrapper *ftServer::getCacheStrapper()
|
||||||
|
{
|
||||||
|
return mCacheStrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
CacheTransfer *ftServer::getCacheTransfer()
|
||||||
|
{
|
||||||
|
return mFtController;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/********************** RsFiles Interface **********************/
|
||||||
|
/***************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/********************** Controller Access **********************/
|
||||||
|
/***************************************************************/
|
||||||
|
|
||||||
|
bool ftServer::FileRequest(std::string fname, std::string hash,
|
||||||
|
uint32_t size, std::string dest, uint32_t flags)
|
||||||
|
{
|
||||||
|
return mFtController->FileRequest(fname, hash, size, dest, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ftServer::FileCancel(std::string hash);
|
||||||
|
{
|
||||||
|
return mFtController->FileCancel(hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ftServer::FileControl(std::string hash, uint32_t flags);
|
||||||
|
{
|
||||||
|
return mFtController->FileControl(hash, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ftServer::FileClearCompleted();
|
||||||
|
{
|
||||||
|
return mFtController->FileClearCompleted();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get Details of File Transfers */
|
||||||
|
bool ftServer::FileDownloads(std::list<std::string> &hashs);
|
||||||
|
{
|
||||||
|
return mFtController->FileDownloads(hashs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Directory Handling */
|
||||||
|
void ftServer::setDownloadDirectory(std::string path)
|
||||||
|
{
|
||||||
|
return mFtController->setDownloadDirectory(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ftServer::getDownloadDirectory()
|
||||||
|
{
|
||||||
|
return mFtController->getDownloadDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ftServer::setPartialsDirectory(std::string path);
|
||||||
|
{
|
||||||
|
return mFtController->setPartialsDirectory(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ftServer::getPartialsDirectory()
|
||||||
|
{
|
||||||
|
return mFtController->getPartialsDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/************************* Other Access ************************/
|
||||||
|
/***************************************************************/
|
||||||
|
|
||||||
|
bool ftServer::FileUploads(std::list<std::string> &hashs);
|
||||||
|
{
|
||||||
|
return mFtUploader->FileUploads(hashes);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ftServer::FileDetails(std::string hash, uint32_t hintflags, FileInfo &info);
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
if (hintflags | DOWNLOADING)
|
||||||
|
{
|
||||||
|
found = mFtController->FileDetails(hash, info);
|
||||||
|
}
|
||||||
|
else if (hintflags | UPLOADING)
|
||||||
|
{
|
||||||
|
found = mFtUploader->FileDetails(hash, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
mFtSearch->FileDetails(hash, hintflags, info);
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/******************* ExtraFileList Access **********************/
|
||||||
|
/***************************************************************/
|
||||||
|
|
||||||
|
bool ftServer::ExtraFileAdd(std::string fname, std::string hash, uint32_t size,
|
||||||
|
uint32_t period, uint32_t flags)
|
||||||
|
{
|
||||||
|
return mFtExtra->addExtraFile(fname, hash, size, period, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ftServer::ExtraFileRemove(std::string hash, uin32_t flags);
|
||||||
|
{
|
||||||
|
return mFtExtra->removeExtraFile(hash, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ftServer::ExtraFileHash(std::string localpath, uint32_t period, uint32_t flags);
|
||||||
|
{
|
||||||
|
return mFtExtra->hashExtraFile(localpath, period, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ftServer::ExtraFileStatus(std::string localpath, FileInfo &info);
|
||||||
|
{
|
||||||
|
return mFtExtra->hashExtraFileDone(localpath, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/******************** Directory Listing ************************/
|
||||||
|
/***************************************************************/
|
||||||
|
|
||||||
|
int ftServer::RequestDirDetails(std::string uid, std::string path, DirDetails &details);
|
||||||
|
{
|
||||||
|
return mFiStore->RequestDirDetails(uid, path, details);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags);
|
||||||
|
{
|
||||||
|
return mFiStore->RequestDirDetails(ref, details, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/******************** Search Interface *************************/
|
||||||
|
/***************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
int ftServer::SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results);
|
||||||
|
{
|
||||||
|
return mFiStore->SearchKeywords(keywords, results);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ftServer::SearchBoolExp(Expression * exp, std::list<FileDetail> &results);
|
||||||
|
{
|
||||||
|
return mFiStore->searchBoolExp(exp, results);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/*************** Local Shared Dir Interface ********************/
|
||||||
|
/***************************************************************/
|
||||||
|
|
||||||
|
bool ftServer::ConvertSharedFilePath(std::string path, std::string &fullpath)
|
||||||
|
{
|
||||||
|
return mFiMon->convertSharedFilePath(path, fullpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ftServer::ForceDirectoryCheck()
|
||||||
|
{
|
||||||
|
mFiMon->forceDirectoryCheck();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ftServer::InDirectoryCheck()
|
||||||
|
{
|
||||||
|
return mFtMon->inDirectoryCheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ftServer::getSharedDirectories(std::list<std::string> &dirs)
|
||||||
|
{
|
||||||
|
return mFtMon->getSharedDirectories(dirs);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ftServer::addSharedDirectory(std::string dir)
|
||||||
|
{
|
||||||
|
return mFtMon->addSharedDirectory(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ftServer::removeSharedDirectory(std::string dir)
|
||||||
|
{
|
||||||
|
return mFtMon->removeSharedDirectory(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/****************** End of RsFiles Interface *******************/
|
||||||
|
/***************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/**************** Config Interface *****************************/
|
||||||
|
/***************************************************************/
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/* Key Functions to be overloaded for Full Configuration */
|
||||||
|
virtual RsSerialiser *setupSerialiser();
|
||||||
|
virtual std::list<RsItem *> saveList(bool &cleanup);
|
||||||
|
virtual bool loadList(std::list<RsItem *> load);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool loadConfigMap(std::map<std::string, std::string> &configMap);
|
||||||
|
/******************* p3 Config Overload ************************/
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
181
libretroshare/src/ft/ftserver.h
Normal file
181
libretroshare/src/ft/ftserver.h
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/ft: ftserver.h
|
||||||
|
*
|
||||||
|
* File Transfer for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FT_SERVER_HEADER
|
||||||
|
#define FT_SERVER_HEADER
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ftServer.
|
||||||
|
*
|
||||||
|
* Top level File Transfer interface.
|
||||||
|
* (replaces old filedexserver)
|
||||||
|
*
|
||||||
|
* sets up the whole File Transfer class structure.
|
||||||
|
* sets up the File Indexing side of cache system too.
|
||||||
|
*
|
||||||
|
* provides rsFiles interface for external control.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "pqi/pqi.h"
|
||||||
|
#include "pqi/pqiindic.h"
|
||||||
|
#include "serialiser/rsconfigitems.h"
|
||||||
|
#include <map>
|
||||||
|
#include <deque>
|
||||||
|
#include <list>
|
||||||
|
#include <map>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "rsiface/rsiface.h"
|
||||||
|
|
||||||
|
#include "pqi/p3cfgmgr.h"
|
||||||
|
|
||||||
|
class p3ConnectMgr;
|
||||||
|
class p3AuthMgr;
|
||||||
|
|
||||||
|
class CacheStrapper;
|
||||||
|
class ftfiler;
|
||||||
|
class FileIndexStore;
|
||||||
|
class FileIndexMonitor;
|
||||||
|
|
||||||
|
|
||||||
|
class ftServer: public RsFiles
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/******************** Setup ************************************/
|
||||||
|
/***************************************************************/
|
||||||
|
|
||||||
|
ftServer(CacheStrapper *cStrapper) { return; }
|
||||||
|
|
||||||
|
/* Assign important variables */
|
||||||
|
void setConfigDirectory(std::string path);
|
||||||
|
|
||||||
|
void setPQInterface(PQInterface *pqi);
|
||||||
|
|
||||||
|
/* Final Setup (once everything is assigned) */
|
||||||
|
void SetupFtServer();
|
||||||
|
|
||||||
|
/* add Config Items (Extra, Controller) */
|
||||||
|
void addConfigComponents(p3ConfigMgr *mgr);
|
||||||
|
|
||||||
|
CacheTransfer *getCacheTransfer();
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/*************** Control Interface *****************************/
|
||||||
|
/************** (Implements RsFiles) ***************************/
|
||||||
|
/***************************************************************/
|
||||||
|
|
||||||
|
virtual int FileRequest(std::string fname, std::string hash,
|
||||||
|
uint32_t size, std::string dest, uint32_t flags);
|
||||||
|
virtual int FileCancel(std::string hash);
|
||||||
|
virtual int FileControl(std::string hash, uint32_t flags);
|
||||||
|
virtual int FileClearCompleted();
|
||||||
|
|
||||||
|
/* get Details of File Transfers */
|
||||||
|
virtual bool FileDownloads(std::list<std::string> &hashs);
|
||||||
|
virtual bool FileUploads(std::list<std::string> &hashs);
|
||||||
|
virtual bool FileDetails(std::string hash, uint32_t hintflags, FileInfo &info);
|
||||||
|
|
||||||
|
/* Access ftExtraList - Details */
|
||||||
|
virtual int ExtraFileAdd(std::string fname, std::string hash, uint32_t size,
|
||||||
|
uint32_t period, uint32_t flags);
|
||||||
|
virtual int ExtraFileRemove(std::string hash, uin32_t flags);
|
||||||
|
virtual bool ExtraFileHash(std::string localpath, uint32_t period, uint32_t flags);
|
||||||
|
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info);
|
||||||
|
|
||||||
|
/* Directory Listing */
|
||||||
|
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details);
|
||||||
|
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags);
|
||||||
|
|
||||||
|
/* Search Interface */
|
||||||
|
virtual int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results);
|
||||||
|
virtual int SearchBoolExp(Expression * exp, std::list<FileDetail> &results);
|
||||||
|
|
||||||
|
/* Utility Functions */
|
||||||
|
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath);
|
||||||
|
virtual void ForceDirectoryCheck();
|
||||||
|
virtual bool InDirectoryCheck();
|
||||||
|
|
||||||
|
/* Directory Handling */
|
||||||
|
virtual void setDownloadDirectory(std::string path);
|
||||||
|
virtual void setPartialsDirectory(std::string path);
|
||||||
|
|
||||||
|
virtual bool getSharedDirectories(std::list<std::string> &dirs);
|
||||||
|
virtual int addSharedDirectory(std::string dir);
|
||||||
|
virtual int removeSharedDirectory(std::string dir);
|
||||||
|
virtual int reScanDirs();
|
||||||
|
virtual int check_dBUpdate();
|
||||||
|
|
||||||
|
std::string getSaveDir();
|
||||||
|
void setSaveDir(std::string d);
|
||||||
|
void setEmergencySaveDir(std::string s);
|
||||||
|
|
||||||
|
void setConfigDir(std::string d) { config_dir = d; }
|
||||||
|
bool getSaveIncSearch();
|
||||||
|
void setSaveIncSearch(bool v);
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************/
|
||||||
|
/*************** Control Interface *****************************/
|
||||||
|
/***************************************************************/
|
||||||
|
|
||||||
|
/******************* p3 Config Overload ************************/
|
||||||
|
protected:
|
||||||
|
/* Key Functions to be overloaded for Full Configuration */
|
||||||
|
virtual RsSerialiser *setupSerialiser();
|
||||||
|
virtual std::list<RsItem *> saveList(bool &cleanup);
|
||||||
|
virtual bool loadList(std::list<RsItem *> load);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool loadConfigMap(std::map<std::string, std::string> &configMap);
|
||||||
|
/******************* p3 Config Overload ************************/
|
||||||
|
|
||||||
|
/*************************** p3 Config Overload ********************/
|
||||||
|
private:
|
||||||
|
|
||||||
|
/* no need for Mutex protection -
|
||||||
|
* as each component is protected independently.
|
||||||
|
*/
|
||||||
|
|
||||||
|
CacheStrapper *mCacheStrapper;
|
||||||
|
ftController *mFtController;
|
||||||
|
ftExtraList *mFtExtra;
|
||||||
|
|
||||||
|
FileIndexStore *fiStore;
|
||||||
|
FileIndexMonitor *fimon;
|
||||||
|
|
||||||
|
RsMutex srvMutex;
|
||||||
|
std::string mConfigPath;
|
||||||
|
std::string mDownloadPath;
|
||||||
|
std::string mPartialsPath;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
135
libretroshare/src/rsiface/rsfiles.h
Normal file
135
libretroshare/src/rsiface/rsfiles.h
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
#ifndef RS_FILES_GUI_INTERFACE_H
|
||||||
|
#define RS_FILES_GUI_INTERFACE_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* libretroshare/src/rsiface: rsfiles.h
|
||||||
|
*
|
||||||
|
* RetroShare C++ Interface.
|
||||||
|
*
|
||||||
|
* Copyright 2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "rsiface/rstypes.h"
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &out, const MessageInfo &info);
|
||||||
|
std::ostream &operator<<(std::ostream &out, const ChatInfo &info);
|
||||||
|
|
||||||
|
class RsFiles;
|
||||||
|
extern RsFiles *rsFiles;
|
||||||
|
|
||||||
|
|
||||||
|
const uint32_t RS_FILE_CTRL_PAUSE = 0x0100;
|
||||||
|
const uint32_t RS_FILE_CTRL_START = 0x0200;
|
||||||
|
|
||||||
|
const uint32_t RS_FILE_CTRL_TRICKLE = 0x0001;
|
||||||
|
const uint32_t RS_FILE_CTRL_SLOW = 0x0002;
|
||||||
|
const uint32_t RS_FILE_CTRL_STANDARD = 0x0003;
|
||||||
|
const uint32_t RS_FILE_CTRL_FAST = 0x0004;
|
||||||
|
const uint32_t RS_FILE_CTRL_STREAM_AUDIO = 0x0005;
|
||||||
|
const uint32_t RS_FILE_CTRL_STREAM_VIDEO = 0x0006;
|
||||||
|
|
||||||
|
|
||||||
|
const uint32_t RS_FILE_EXTRA_DELETE = 0x0010;
|
||||||
|
|
||||||
|
|
||||||
|
class RsFiles
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
RsFiles() { return; }
|
||||||
|
virtual ~RsFiles() { return; }
|
||||||
|
|
||||||
|
/****************************************/
|
||||||
|
/* download */
|
||||||
|
|
||||||
|
/* Required Interfaces ......
|
||||||
|
*
|
||||||
|
* 1) Access to downloading / uploading files.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* get Details of File Transfers */
|
||||||
|
virtual bool FileDownloads(std::list<std::string> &hashs)= 0;
|
||||||
|
virtual bool FileUploads(std::list<std::string> &hashs)= 0;
|
||||||
|
virtual bool FileDetails(std::string hash, uint32_t hintflags, FileInfo &info)= 0;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 2) Control of Downloads.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
virtual int FileRequest(std::string fname, std::string hash,
|
||||||
|
uint32_t size, std::string dest, uint32_t flags)= 0;
|
||||||
|
virtual int FileCancel(std::string hash)= 0;
|
||||||
|
virtual int FileControl(std::string hash, uint32_t flags)= 0;
|
||||||
|
virtual int FileClearCompleted()= 0;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 3) Addition of Extra Files... From File System
|
||||||
|
* These are Hashed and stored in the 'Hidden Files' section
|
||||||
|
* which can only be accessed if you know the hash.
|
||||||
|
*
|
||||||
|
* FileHash is called to start the hashing process,
|
||||||
|
* and add the file to the HiddenStore.
|
||||||
|
*
|
||||||
|
* FileHashStatus is called to lookup files
|
||||||
|
* and see if the hashing is completed.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Access ftExtraList - Details */
|
||||||
|
virtual int ExtraFileAdd(std::string fname, std::string hash, uint32_t size,
|
||||||
|
uint32_t period, uint32_t flags)= 0;
|
||||||
|
virtual int ExtraFileRemove(std::string hash, uin32_t flags)= 0;
|
||||||
|
virtual bool ExtraFileHash(std::string localpath,
|
||||||
|
uint32_t period, uint32_t flags)= 0;
|
||||||
|
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info)= 0;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 4) Search and Listing Interface
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Directory Listing / Search Interface */
|
||||||
|
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 SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results)= 0;
|
||||||
|
virtual int SearchBoolExp(Expression * exp, std::list<FileDetail> &results)= 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 5) Utility Functions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath) = 0;
|
||||||
|
virtual void ForceDirectoryCheck() = 0;
|
||||||
|
virtual bool InDirectoryCheck() = 0;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -91,15 +91,6 @@ virtual void unlockData() = 0;
|
|||||||
const std::list<FileTransferInfo> &getTransferList()
|
const std::list<FileTransferInfo> &getTransferList()
|
||||||
{ return mTransferList; }
|
{ return mTransferList; }
|
||||||
|
|
||||||
const std::list<PersonInfo> &getRemoteDirectoryList()
|
|
||||||
{ return mRemoteDirList; }
|
|
||||||
|
|
||||||
const std::list<PersonInfo> &getLocalDirectoryList()
|
|
||||||
{ return mLocalDirList; }
|
|
||||||
|
|
||||||
const PersonInfo *getPerson(std::string id);
|
|
||||||
const DirInfo *getDirectory(std::string id, std::string path);
|
|
||||||
|
|
||||||
const std::list<FileInfo> &getRecommendList()
|
const std::list<FileInfo> &getRecommendList()
|
||||||
{ return mRecommendList; }
|
{ return mRecommendList; }
|
||||||
|
|
||||||
@ -135,15 +126,9 @@ bool hasChanged(DataFlags set); /* resets it */
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/* Internal Fn for getting the Directory Entry */
|
|
||||||
PersonInfo *getPersonMod(std::string id);
|
|
||||||
DirInfo *getDirectoryMod(std::string id, std::string path);
|
|
||||||
|
|
||||||
void fillLists(); /* create some dummy data to display */
|
void fillLists(); /* create some dummy data to display */
|
||||||
|
|
||||||
/* Internals */
|
/* Internals */
|
||||||
std::list<PersonInfo> mRemoteDirList;
|
|
||||||
std::list<PersonInfo> mLocalDirList;
|
|
||||||
std::list<FileTransferInfo> mTransferList;
|
std::list<FileTransferInfo> mTransferList;
|
||||||
std::list<FileInfo> mRecommendList;
|
std::list<FileInfo> mRecommendList;
|
||||||
|
|
||||||
|
@ -38,28 +38,19 @@ typedef std::string RsMsgId;
|
|||||||
typedef std::string RsAuthId;
|
typedef std::string RsAuthId;
|
||||||
|
|
||||||
|
|
||||||
/* forward declarations of the classes */
|
class FileInfo
|
||||||
|
|
||||||
#define INFO_SAME 0x01
|
|
||||||
#define INFO_CHG 0x02
|
|
||||||
#define INFO_NEW 0x04
|
|
||||||
#define INFO_DEL 0x08
|
|
||||||
|
|
||||||
class BaseInfo
|
|
||||||
{
|
{
|
||||||
|
/* old BaseInfo Entries */
|
||||||
public:
|
public:
|
||||||
BaseInfo() :flags(0), mId(0) { return; }
|
|
||||||
|
FileInfo() :flags(0), mId(0) { return; }
|
||||||
RsCertId id; /* key for matching everything */
|
RsCertId id; /* key for matching everything */
|
||||||
int flags; /* INFO_TAG above */
|
int flags; /* INFO_TAG above */
|
||||||
|
|
||||||
/* allow this to be tweaked by the GUI Model */
|
/* allow this to be tweaked by the GUI Model */
|
||||||
mutable unsigned int mId; /* (GUI) Model Id -> unique number */
|
mutable unsigned int mId; /* (GUI) Model Id -> unique number */
|
||||||
};
|
|
||||||
|
|
||||||
/********************** For the Directory Listing *****************/
|
/* Old FileInfo Entries */
|
||||||
|
|
||||||
class FileInfo: public BaseInfo
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static const int kRsFiStatusNone = 0;
|
static const int kRsFiStatusNone = 0;
|
||||||
@ -83,52 +74,8 @@ static const int kRsFiStatusDone = 2;
|
|||||||
|
|
||||||
double rank;
|
double rank;
|
||||||
int age;
|
int age;
|
||||||
};
|
|
||||||
|
|
||||||
class DirInfo: public BaseInfo
|
/* Old FileTransferInfo Entries */
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
DirInfo() :infoAge(0), nofiles(0), nobytes(0) { return; }
|
|
||||||
std::string path;
|
|
||||||
std::string dirname;
|
|
||||||
std::list<DirInfo> subdirs;
|
|
||||||
std::list<FileInfo> files;
|
|
||||||
int infoAge;
|
|
||||||
int nofiles;
|
|
||||||
int nobytes;
|
|
||||||
|
|
||||||
double rank;
|
|
||||||
int age;
|
|
||||||
|
|
||||||
int merge(const DirInfo &udir);
|
|
||||||
|
|
||||||
bool exists(const DirInfo&);
|
|
||||||
DirInfo* existsPv(const DirInfo&);
|
|
||||||
bool add(const DirInfo&);
|
|
||||||
int update(const DirInfo &udir);
|
|
||||||
|
|
||||||
|
|
||||||
bool exists(const FileInfo&);
|
|
||||||
FileInfo* existsPv(const FileInfo&);
|
|
||||||
bool add(const FileInfo&);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class PersonInfo: public BaseInfo
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::string name;
|
|
||||||
bool online;
|
|
||||||
int infoAge; /* time() at when this was last updated */
|
|
||||||
|
|
||||||
DirInfo rootdir;
|
|
||||||
};
|
|
||||||
|
|
||||||
/********************** For Messages and Channels *****************/
|
|
||||||
|
|
||||||
class FileTransferInfo: public FileInfo
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
std::string source;
|
std::string source;
|
||||||
std::list<std::string> peerIds;
|
std::list<std::string> peerIds;
|
||||||
@ -138,6 +85,12 @@ class FileTransferInfo: public FileInfo
|
|||||||
int downloadStatus; /* 0 = Err, 1 = Ok, 2 = Done */
|
int downloadStatus; /* 0 = Err, 1 = Ok, 2 = Done */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class FileTransferInfo: public FileInfo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FileTransferInfo() { return; }
|
||||||
|
};
|
||||||
|
|
||||||
/* matched to the uPnP states */
|
/* matched to the uPnP states */
|
||||||
#define UPNP_STATE_UNINITIALISED 0
|
#define UPNP_STATE_UNINITIALISED 0
|
||||||
#define UPNP_STATE_UNAVAILABILE 1
|
#define UPNP_STATE_UNAVAILABILE 1
|
||||||
@ -210,9 +163,6 @@ class SearchRequest
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const PersonInfo &info);
|
|
||||||
std::ostream &print(std::ostream &out, const DirInfo &info, int indentLvl);
|
|
||||||
|
|
||||||
/********************** For FileCache Interface *****************/
|
/********************** For FileCache Interface *****************/
|
||||||
|
|
||||||
#define DIR_TYPE_ROOT 0x01
|
#define DIR_TYPE_ROOT 0x01
|
||||||
|
@ -18,9 +18,9 @@ RSOBJ = p3peers.o \
|
|||||||
p3face-config.o \
|
p3face-config.o \
|
||||||
p3face-startup.o \
|
p3face-startup.o \
|
||||||
p3face-msgs.o \
|
p3face-msgs.o \
|
||||||
rstypes.o \
|
|
||||||
rsiface.o
|
rsiface.o
|
||||||
|
|
||||||
|
# rstypes.o \
|
||||||
# pqistrings.o \
|
# pqistrings.o \
|
||||||
# p3face-people.o
|
# p3face-people.o
|
||||||
# p3face-network.o \
|
# p3face-network.o \
|
||||||
|
@ -662,6 +662,11 @@ int RsServer::StartupRetroShare(RsInit *config)
|
|||||||
|
|
||||||
mConfigMgr->loadConfiguration();
|
mConfigMgr->loadConfiguration();
|
||||||
|
|
||||||
|
/* NOTE: CacheStrapper's load causes Cache Files to be
|
||||||
|
* loaded into all the CacheStores/Sources. This happens
|
||||||
|
* after all the other configurations have happened.
|
||||||
|
*/
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/* Hack Old Configuration into new System (first load only) */
|
/* Hack Old Configuration into new System (first load only) */
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
@ -29,152 +29,6 @@
|
|||||||
#include "rsiface/rsiface.h"
|
#include "rsiface/rsiface.h"
|
||||||
#include "util/rsdir.h"
|
#include "util/rsdir.h"
|
||||||
|
|
||||||
const DirInfo *RsIface::getDirectory(std::string id, std::string path)
|
|
||||||
{
|
|
||||||
const DirInfo *dir = getDirectoryMod(id, path);
|
|
||||||
return dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const PersonInfo *RsIface::getPerson(std::string id)
|
|
||||||
{
|
|
||||||
const PersonInfo *pi = getPersonMod(id);
|
|
||||||
return pi;
|
|
||||||
}
|
|
||||||
|
|
||||||
PersonInfo *RsIface::getPersonMod(std::string uid)
|
|
||||||
{
|
|
||||||
RsCertId id(uid);
|
|
||||||
|
|
||||||
/* get the Root of the Directories */
|
|
||||||
std::list<PersonInfo>::iterator pit;
|
|
||||||
|
|
||||||
/* check if local */
|
|
||||||
for(pit = mLocalDirList.begin();
|
|
||||||
(pit != mLocalDirList.end()) && (pit->id != id); pit++);
|
|
||||||
|
|
||||||
if (pit == mLocalDirList.end())
|
|
||||||
{
|
|
||||||
/* check the remote ones */
|
|
||||||
for(pit = mRemoteDirList.begin();
|
|
||||||
(pit != mRemoteDirList.end()) && (pit->id != id); pit++);
|
|
||||||
|
|
||||||
/* bailout ...? */
|
|
||||||
if (pit == mRemoteDirList.end())
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return &(*pit);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DirInfo *RsIface::getDirectoryMod(std::string uid, std::string path)
|
|
||||||
{
|
|
||||||
RsCertId id(uid);
|
|
||||||
|
|
||||||
/* get the Root of the Directories */
|
|
||||||
std::list<DirInfo>::iterator dit;
|
|
||||||
|
|
||||||
std::list<std::string> subdirs;
|
|
||||||
std::list<std::string>::iterator sit;
|
|
||||||
|
|
||||||
PersonInfo *pi = getPersonMod(uid);
|
|
||||||
if (!pi)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* have the correct person now */
|
|
||||||
RsDirUtil::breakupDirList(path, subdirs);
|
|
||||||
|
|
||||||
DirInfo *node = &(pi -> rootdir);
|
|
||||||
|
|
||||||
for(sit = subdirs.begin(); sit != subdirs.end(); sit++)
|
|
||||||
{
|
|
||||||
for(dit = node->subdirs.begin();
|
|
||||||
(dit != node->subdirs.end()) &&
|
|
||||||
(dit->dirname != *sit); dit++);
|
|
||||||
|
|
||||||
if (dit == node->subdirs.end())
|
|
||||||
{
|
|
||||||
/* Directory don't exist..... */
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
node = &(*dit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
const MessageInfo *RsIface::getMessage(std::string cid_in, std::string mid_in)
|
|
||||||
{
|
|
||||||
/* check for this message */
|
|
||||||
std::list<MessageInfo>::iterator it;
|
|
||||||
|
|
||||||
RsCertId cId(cid_in);
|
|
||||||
RsMsgId mId(mid_in);
|
|
||||||
|
|
||||||
std::cerr << "RsIface::getMessage()" << std::endl;
|
|
||||||
std::cerr << "cid: " << cid_in << " -> cId " << cId << std::endl;
|
|
||||||
std::cerr << "mid: " << mid_in << " -> mId " << mId << std::endl;
|
|
||||||
|
|
||||||
for(it = mMessageList.begin(); it != mMessageList.end(); it++)
|
|
||||||
{
|
|
||||||
std::cerr << "VS: cid: " << it->id << std::endl;
|
|
||||||
std::cerr << "VS: mid: " << it->msgId << std::endl;
|
|
||||||
if ((it->id == cId) && (mId == it->msgId))
|
|
||||||
{
|
|
||||||
std::cerr << "MATCH!" << std::endl;
|
|
||||||
return &(*it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cerr << "NO MATCH :(" << std::endl;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const MessageInfo *RsIface::getChannelMsg(std::string chid_in, std::string mid_in)
|
|
||||||
{
|
|
||||||
RsChanId cId(chid_in);
|
|
||||||
RsMsgId mId(mid_in);
|
|
||||||
|
|
||||||
std::map<RsChanId, ChannelInfo>::iterator it;
|
|
||||||
it = mChannelMap.find(cId);
|
|
||||||
|
|
||||||
if (it == mChannelMap.end())
|
|
||||||
{
|
|
||||||
it = mChannelOwnMap.find(cId);
|
|
||||||
|
|
||||||
if (it == mChannelOwnMap.end())
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* else */
|
|
||||||
std::list<MessageInfo>::iterator it2;
|
|
||||||
std::list<MessageInfo> &msgs = (it->second).msglist;
|
|
||||||
for(it2 = msgs.begin(); it2 != msgs.end(); it2++)
|
|
||||||
{
|
|
||||||
if (mId == it2->msgId)
|
|
||||||
{
|
|
||||||
return &(*it2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* set to true */
|
/* set to true */
|
||||||
bool RsIface::setChanged(DataFlags set)
|
bool RsIface::setChanged(DataFlags set)
|
||||||
{
|
{
|
||||||
|
@ -45,189 +45,3 @@
|
|||||||
*
|
*
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
|
|
||||||
/****************************************/
|
|
||||||
/* Print Functions for Info Classes */
|
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const PersonInfo &info)
|
|
||||||
{
|
|
||||||
out << "Directory Listing for: " << info.name;
|
|
||||||
out << std::endl;
|
|
||||||
print(out, info.rootdir, 0);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostream &print(std::ostream &out, const DirInfo &info, int indentLvl)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
std::ostringstream indents;
|
|
||||||
for(i = 0; i < indentLvl; i++)
|
|
||||||
{
|
|
||||||
indents << " ";
|
|
||||||
}
|
|
||||||
out << indents.str() << "Dir: " << info.dirname << std::endl;
|
|
||||||
if (info.subdirs.size() > 0)
|
|
||||||
{
|
|
||||||
out << indents.str() << "subdirs:" << std::endl;
|
|
||||||
std::list<DirInfo>::const_iterator it;
|
|
||||||
for(it = info.subdirs.begin(); it != info.subdirs.end(); it++)
|
|
||||||
{
|
|
||||||
print(out, *it, indentLvl + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (info.files.size() > 0)
|
|
||||||
{
|
|
||||||
out << indents.str() << "files:" << std::endl;
|
|
||||||
std::list<FileInfo>::const_iterator it2;
|
|
||||||
for(it2 = info.files.begin(); it2 != info.files.end(); it2++)
|
|
||||||
{
|
|
||||||
out << indents.str() << " " << it2->fname;
|
|
||||||
out << " " << it2->size << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const MessageInfo &info)
|
|
||||||
{
|
|
||||||
out << "MessageInfo(TODO)";
|
|
||||||
out << std::endl;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const ChatInfo &info)
|
|
||||||
{
|
|
||||||
out << "ChatInfo(TODO)";
|
|
||||||
out << std::endl;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int DirInfo::merge(const DirInfo &udir)
|
|
||||||
{
|
|
||||||
/* add in the data from the udir */
|
|
||||||
if (infoAge > udir.infoAge)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::list<DirInfo>::const_iterator it;
|
|
||||||
for(it = udir.subdirs.begin(); it != udir.subdirs.end(); it++)
|
|
||||||
{
|
|
||||||
update(*it);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::list<FileInfo>::const_iterator it2;
|
|
||||||
for(it2 = udir.files.begin(); it2 != udir.files.end(); it2++)
|
|
||||||
{
|
|
||||||
add(*it2);
|
|
||||||
}
|
|
||||||
|
|
||||||
infoAge = udir.infoAge;
|
|
||||||
nobytes = udir.nobytes;
|
|
||||||
|
|
||||||
//nofiles = udir.nofiles;
|
|
||||||
nofiles = subdirs.size() + files.size();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int DirInfo::update(const DirInfo &dir)
|
|
||||||
{
|
|
||||||
/* add in the data from the udir */
|
|
||||||
DirInfo *odir = existsPv(dir);
|
|
||||||
if (odir)
|
|
||||||
{
|
|
||||||
// leave.. dirup -> subdirs = pd.data.subdirs;
|
|
||||||
// leave.. dirup -> files = pd.data.files;
|
|
||||||
odir->infoAge = dir.infoAge;
|
|
||||||
odir->nofiles = dir.nofiles;
|
|
||||||
odir->nobytes = dir.nobytes;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
subdirs.push_back(dir);
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DirInfo::exists(const DirInfo &sdir)
|
|
||||||
{
|
|
||||||
return (existsPv(sdir) != NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DirInfo *DirInfo::existsPv(const DirInfo &sdir)
|
|
||||||
{
|
|
||||||
std::list<DirInfo>::iterator it;
|
|
||||||
for(it = subdirs.begin(); it != subdirs.end(); it++)
|
|
||||||
{
|
|
||||||
if (sdir.dirname == it->dirname)
|
|
||||||
{
|
|
||||||
return &(*it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool DirInfo::exists(const FileInfo &file)
|
|
||||||
{
|
|
||||||
return (existsPv(file) != NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FileInfo *DirInfo::existsPv(const FileInfo &file)
|
|
||||||
{
|
|
||||||
std::list<FileInfo>::iterator it;
|
|
||||||
for(it = files.begin(); it != files.end(); it++)
|
|
||||||
{
|
|
||||||
if (file.fname == it->fname)
|
|
||||||
{
|
|
||||||
return &(*it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool DirInfo::add(const DirInfo & sdir)
|
|
||||||
{
|
|
||||||
DirInfo *entry = existsPv(sdir);
|
|
||||||
if (entry)
|
|
||||||
{
|
|
||||||
*entry = sdir;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
subdirs.push_back(sdir);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool DirInfo::add(const FileInfo & file)
|
|
||||||
{
|
|
||||||
FileInfo *entry = existsPv(file);
|
|
||||||
if (entry)
|
|
||||||
{
|
|
||||||
*entry = file;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
files.push_back(file);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -188,8 +188,8 @@ bool p3Qblog::loadBlogFile(std::string filename, std::string src)
|
|||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
/* check timestamp */
|
/* check timestamp */
|
||||||
else if (((time_t) newBlog->timeStamp < min) ||
|
else if (((time_t) newBlog->sendTime < min) ||
|
||||||
((time_t) newBlog->timeStamp > max))
|
((time_t) newBlog->sendTime > max))
|
||||||
{
|
{
|
||||||
#ifdef QBLOG_DEBUG
|
#ifdef QBLOG_DEBUG
|
||||||
std::cerr << "p3Qblog::loadBlogFile() Outside TimeRange (deleting):";
|
std::cerr << "p3Qblog::loadBlogFile() Outside TimeRange (deleting):";
|
||||||
@ -227,16 +227,16 @@ bool p3Qblog::addBlog(RsQblogMsg *newBlog)
|
|||||||
{
|
{
|
||||||
RsStackMutex Stack(mBlogMtx);
|
RsStackMutex Stack(mBlogMtx);
|
||||||
|
|
||||||
mUsrBlogSet[newBlog->PeerId()].insert(std::make_pair(newBlog->timeStamp, newBlog->blogMsg));
|
mUsrBlogSet[newBlog->PeerId()].insert(std::make_pair(newBlog->sendTime, newBlog->message));
|
||||||
|
|
||||||
#ifdef QBLOG_DEBUG
|
#ifdef QBLOG_DEBUG
|
||||||
std::cerr << "p3Qblog::addBlog()";
|
std::cerr << "p3Qblog::addBlog()";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
std::cerr << "\tpeerId" << newBlog->PeerId();
|
std::cerr << "\tpeerId" << newBlog->PeerId();
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
std::cerr << "\tmUsrBlogSet: time" << newBlog->timeStamp;
|
std::cerr << "\tmUsrBlogSet: time" << newBlog->sendTime;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
std::cerr << "\tmUsrBlogSet: blog" << newBlog->blogMsg;
|
std::cerr << "\tmUsrBlogSet: blog" << newBlog->message;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
mPostsUpdated = false; // need to figure how this should work/ wherre this should be placed
|
mPostsUpdated = false; // need to figure how this should work/ wherre this should be placed
|
||||||
@ -472,16 +472,16 @@ bool p3Qblog::sendBlog(const std::wstring &msg)
|
|||||||
RsQblogMsg *blog = new RsQblogMsg();
|
RsQblogMsg *blog = new RsQblogMsg();
|
||||||
blog->clear();
|
blog->clear();
|
||||||
|
|
||||||
blog->timeStamp = blogTimeStamp;
|
blog->sendTime = blogTimeStamp;
|
||||||
blog->blogMsg = msg;
|
blog->message = msg;
|
||||||
|
|
||||||
|
|
||||||
#ifdef QBLOG_DEBUG
|
#ifdef QBLOG_DEBUG
|
||||||
std::cerr << "p3Qblog::sendBlogFile()";
|
std::cerr << "p3Qblog::sendBlogFile()";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
std::cerr << "\tblogItem->timeStamp" << blog->timeStamp;
|
std::cerr << "\tblogItem->sendTime" << blog->sendTime;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
std::cerr << "\tblogItem->blogMsg.second" << blog->blogMsg;
|
std::cerr << "\tblogItem->message" << blog->message;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user