Expose JSON API for file filtering

This commit is contained in:
Gioacchino Mazzurco 2018-10-09 00:55:32 +02:00
parent 2556af692e
commit 406822b5ec
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
4 changed files with 57 additions and 22 deletions

View File

@ -1913,11 +1913,11 @@ bool p3FileDatabase::banFile(const RsFileHash& real_file_hash, const std::string
RS_STACK_MUTEX(mFLSMtx) ; 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> 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.mFilename = filename ;
entry.size = file_size ; entry.mSize = file_size ;
entry.ban_time_stamp = time(NULL); entry.mBanTimeStamp = time(NULL);
RsFileHash hash_of_hash ; RsFileHash hash_of_hash ;
ftServer::encryptHash(real_file_hash,hash_of_hash) ; ftServer::encryptHash(real_file_hash,hash_of_hash) ;

View File

@ -50,12 +50,7 @@ void RsFileListsBannedHashesConfigItem::serial_process(RsGenericSerializer::Seri
{ {
RsTypeSerializer::serial_process(j,ctx,primary_banned_files_list,"primary_banned_files_list") ; 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 RsItem *RsFileListsSerialiser::create_item(uint16_t service,uint8_t type) const
{ {
if(service != RS_SERVICE_TYPE_FILE_DATABASE) if(service != RS_SERVICE_TYPE_FILE_DATABASE)

View File

@ -181,13 +181,22 @@ public:
uint64_t mTotalSize ; 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 mFilename;
std::string filename ; uint64_t mSize;
time_t ban_time_stamp; 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 class RsFiles
@ -430,9 +439,40 @@ public:
virtual int SearchBoolExp(RsRegularExpression::Expression * exp, std::list<DirDetails> &results,FileSearchFlags flags,const RsPeerId& peer_id) = 0; 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 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; * @brief Ban unwanted file from being, searched and forwarded by this node
virtual bool getPrimaryBannedFilesList(std::map<RsFileHash,BannedFileEntry>& banned_files) =0; * @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; virtual bool isHashBanned(const RsFileHash& hash) = 0;
/*** /***

View File

@ -77,10 +77,10 @@ void BannedFilesDialog::fillFilesList()
for(auto it(banned_files.begin());it!=banned_files.end();++it) 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_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_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.ban_time_stamp).toString(),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())); ui.bannedFiles_TW->item(row, COLUMN_FILE_HASH)->setData(Qt::UserRole, QString::fromStdString(it->first.toStdString()));