mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Expose JSON API for file filtering
This commit is contained in:
parent
2556af692e
commit
406822b5ec
@ -1913,11 +1913,11 @@ bool p3FileDatabase::banFile(const RsFileHash& real_file_hash, const std::string
|
||||
RS_STACK_MUTEX(mFLSMtx) ;
|
||||
BannedFileEntry& entry(mPrimaryBanList[real_file_hash]) ; // primary list (user controlled) of files banned from FT search and forwarding. map<real hash, BannedFileEntry>
|
||||
|
||||
if(entry.ban_time_stamp == 0)
|
||||
if(entry.mBanTimeStamp == 0)
|
||||
{
|
||||
entry.filename = filename ;
|
||||
entry.size = file_size ;
|
||||
entry.ban_time_stamp = time(NULL);
|
||||
entry.mFilename = filename ;
|
||||
entry.mSize = file_size ;
|
||||
entry.mBanTimeStamp = time(NULL);
|
||||
|
||||
RsFileHash hash_of_hash ;
|
||||
ftServer::encryptHash(real_file_hash,hash_of_hash) ;
|
||||
|
@ -50,12 +50,7 @@ void RsFileListsBannedHashesConfigItem::serial_process(RsGenericSerializer::Seri
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,primary_banned_files_list,"primary_banned_files_list") ;
|
||||
}
|
||||
template<> void RsTypeSerializer::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,BannedFileEntry& entry,const std::string& /*name*/)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,entry.filename ,"entry.file_name") ;
|
||||
RsTypeSerializer::serial_process<uint64_t>(j,ctx, entry.size ,"entry.size") ;
|
||||
RsTypeSerializer::serial_process<time_t> (j,ctx, entry.ban_time_stamp,"entry.ban_time_stamp") ;
|
||||
}
|
||||
|
||||
RsItem *RsFileListsSerialiser::create_item(uint16_t service,uint8_t type) const
|
||||
{
|
||||
if(service != RS_SERVICE_TYPE_FILE_DATABASE)
|
||||
|
@ -181,13 +181,22 @@ public:
|
||||
uint64_t mTotalSize ;
|
||||
};
|
||||
|
||||
struct BannedFileEntry
|
||||
struct BannedFileEntry : RsSerializable
|
||||
{
|
||||
BannedFileEntry() : size(0),filename(""),ban_time_stamp(0) {}
|
||||
BannedFileEntry() : mFilename(""), mSize(0), mBanTimeStamp(0) {}
|
||||
|
||||
uint64_t size ;
|
||||
std::string filename ;
|
||||
time_t ban_time_stamp;
|
||||
std::string mFilename;
|
||||
uint64_t mSize;
|
||||
time_t mBanTimeStamp; // TODO: use rstime_t
|
||||
|
||||
/// @see RsSerializable::serial_process
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RS_SERIAL_PROCESS(mFilename);
|
||||
RS_SERIAL_PROCESS(mSize);
|
||||
RS_SERIAL_PROCESS(mBanTimeStamp);
|
||||
}
|
||||
};
|
||||
|
||||
class RsFiles
|
||||
@ -430,10 +439,41 @@ public:
|
||||
virtual int SearchBoolExp(RsRegularExpression::Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id) = 0;
|
||||
virtual int getSharedDirStatistics(const RsPeerId& pid, SharedDirStats& stats) =0;
|
||||
|
||||
virtual int banFile(const RsFileHash& real_file_hash, const std::string& filename, uint64_t file_size) =0;
|
||||
virtual int unbanFile(const RsFileHash& real_file_hash)=0;
|
||||
virtual bool getPrimaryBannedFilesList(std::map<RsFileHash,BannedFileEntry>& banned_files) =0;
|
||||
virtual bool isHashBanned(const RsFileHash& hash) =0;
|
||||
/**
|
||||
* @brief Ban unwanted file from being, searched and forwarded by this node
|
||||
* @jsonapi{development}
|
||||
* @param[in] realFileHash this is what will really enforce banning
|
||||
* @param[in] filename expected name of the file, for the user to read
|
||||
* @param[in] fileSize expected file size, for the user to read
|
||||
* @return meaningless value
|
||||
*/
|
||||
virtual int banFile( const RsFileHash& realFileHash,
|
||||
const std::string& filename, uint64_t fileSize ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Remove file from unwanted list
|
||||
* @jsonapi{development}
|
||||
* @param[in] realFileHash hash of the file
|
||||
* @return meaningless value
|
||||
*/
|
||||
virtual int unbanFile(const RsFileHash& realFileHash) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get list of banned files
|
||||
* @jsonapi{development}
|
||||
* @param[out] bannedFiles storage for banned files information
|
||||
* @return meaningless value
|
||||
*/
|
||||
virtual bool getPrimaryBannedFilesList(
|
||||
std::map<RsFileHash,BannedFileEntry>& bannedFiles ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Check if a file is on banned list
|
||||
* @jsonapi{development}
|
||||
* @param[in] hash hash of the file
|
||||
* @return true if the hash is on the list, false otherwise
|
||||
*/
|
||||
virtual bool isHashBanned(const RsFileHash& hash) = 0;
|
||||
|
||||
/***
|
||||
* Utility Functions.
|
||||
|
@ -77,10 +77,10 @@ void BannedFilesDialog::fillFilesList()
|
||||
|
||||
for(auto it(banned_files.begin());it!=banned_files.end();++it)
|
||||
{
|
||||
ui.bannedFiles_TW->setItem(row, COLUMN_FILE_NAME, new QTableWidgetItem(QIcon(),QString::fromUtf8(it->second.filename.c_str()),0));
|
||||
ui.bannedFiles_TW->setItem(row, COLUMN_FILE_NAME, new QTableWidgetItem(QIcon(),QString::fromUtf8(it->second.mFilename.c_str()),0));
|
||||
ui.bannedFiles_TW->setItem(row, COLUMN_FILE_HASH, new QTableWidgetItem(QIcon(),QString::fromStdString(it->first.toStdString()),0));
|
||||
ui.bannedFiles_TW->setItem(row, COLUMN_FILE_SIZE, new QTableWidgetItem(QIcon(),QString::number(it->second.size),0));
|
||||
ui.bannedFiles_TW->setItem(row, COLUMN_FILE_TIME, new QTableWidgetItem(QIcon(),QDateTime::fromTime_t(it->second.ban_time_stamp).toString(),0));
|
||||
ui.bannedFiles_TW->setItem(row, COLUMN_FILE_SIZE, new QTableWidgetItem(QIcon(),QString::number(it->second.mSize),0));
|
||||
ui.bannedFiles_TW->setItem(row, COLUMN_FILE_TIME, new QTableWidgetItem(QIcon(),QDateTime::fromTime_t(it->second.mBanTimeStamp).toString(),0));
|
||||
|
||||
ui.bannedFiles_TW->item(row, COLUMN_FILE_HASH)->setData(Qt::UserRole, QString::fromStdString(it->first.toStdString()));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user