|
|
@ -33,17 +33,13 @@ |
|
|
|
#include <QDataStream> |
|
|
|
#include <QDataStream> |
|
|
|
#include <QStringList> |
|
|
|
#include <QStringList> |
|
|
|
|
|
|
|
|
|
|
|
#include <libtorrent/session.hpp> |
|
|
|
|
|
|
|
#include <libtorrent/ip_filter.hpp> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "base/logger.h" |
|
|
|
#include "base/logger.h" |
|
|
|
#include "filterparserthread.h" |
|
|
|
#include "filterparserthread.h" |
|
|
|
|
|
|
|
|
|
|
|
namespace libt = libtorrent; |
|
|
|
namespace libt = libtorrent; |
|
|
|
|
|
|
|
|
|
|
|
FilterParserThread::FilterParserThread(libt::session *s, QObject *parent) |
|
|
|
FilterParserThread::FilterParserThread(QObject *parent) |
|
|
|
: QThread(parent) |
|
|
|
: QThread(parent) |
|
|
|
, m_session(s) |
|
|
|
|
|
|
|
, m_abort(false) |
|
|
|
, m_abort(false) |
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
@ -55,10 +51,10 @@ FilterParserThread::~FilterParserThread() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Parser for eMule ip filter in DAT format
|
|
|
|
// Parser for eMule ip filter in DAT format
|
|
|
|
int FilterParserThread::parseDATFilterFile(QString filePath, libt::ip_filter &filter) |
|
|
|
int FilterParserThread::parseDATFilterFile() |
|
|
|
{ |
|
|
|
{ |
|
|
|
int ruleCount = 0; |
|
|
|
int ruleCount = 0; |
|
|
|
QFile file(filePath); |
|
|
|
QFile file(m_filePath); |
|
|
|
if (!file.exists()) return ruleCount; |
|
|
|
if (!file.exists()) return ruleCount; |
|
|
|
|
|
|
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
|
@ -136,7 +132,7 @@ int FilterParserThread::parseDATFilterFile(QString filePath, libt::ip_filter &fi |
|
|
|
|
|
|
|
|
|
|
|
// Now Add to the filter
|
|
|
|
// Now Add to the filter
|
|
|
|
try { |
|
|
|
try { |
|
|
|
filter.add_rule(startAddr, endAddr, libt::ip_filter::blocked); |
|
|
|
m_filter.add_rule(startAddr, endAddr, libt::ip_filter::blocked); |
|
|
|
++ruleCount; |
|
|
|
++ruleCount; |
|
|
|
} |
|
|
|
} |
|
|
|
catch(std::exception &) { |
|
|
|
catch(std::exception &) { |
|
|
@ -149,10 +145,10 @@ int FilterParserThread::parseDATFilterFile(QString filePath, libt::ip_filter &fi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Parser for PeerGuardian ip filter in p2p format
|
|
|
|
// Parser for PeerGuardian ip filter in p2p format
|
|
|
|
int FilterParserThread::parseP2PFilterFile(QString filePath, libt::ip_filter &filter) |
|
|
|
int FilterParserThread::parseP2PFilterFile() |
|
|
|
{ |
|
|
|
{ |
|
|
|
int ruleCount = 0; |
|
|
|
int ruleCount = 0; |
|
|
|
QFile file(filePath); |
|
|
|
QFile file(m_filePath); |
|
|
|
if (!file.exists()) return ruleCount; |
|
|
|
if (!file.exists()) return ruleCount; |
|
|
|
|
|
|
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
|
@ -219,7 +215,7 @@ int FilterParserThread::parseP2PFilterFile(QString filePath, libt::ip_filter &fi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
filter.add_rule(startAddr, endAddr, libt::ip_filter::blocked); |
|
|
|
m_filter.add_rule(startAddr, endAddr, libt::ip_filter::blocked); |
|
|
|
++ruleCount; |
|
|
|
++ruleCount; |
|
|
|
} |
|
|
|
} |
|
|
|
catch(std::exception &) { |
|
|
|
catch(std::exception &) { |
|
|
@ -257,10 +253,10 @@ int FilterParserThread::getlineInStream(QDataStream &stream, std::string &name, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Parser for PeerGuardian ip filter in p2p format
|
|
|
|
// Parser for PeerGuardian ip filter in p2p format
|
|
|
|
int FilterParserThread::parseP2BFilterFile(QString filePath, libt::ip_filter &filter) |
|
|
|
int FilterParserThread::parseP2BFilterFile() |
|
|
|
{ |
|
|
|
{ |
|
|
|
int ruleCount = 0; |
|
|
|
int ruleCount = 0; |
|
|
|
QFile file(filePath); |
|
|
|
QFile file(m_filePath); |
|
|
|
if (!file.exists()) return ruleCount; |
|
|
|
if (!file.exists()) return ruleCount; |
|
|
|
|
|
|
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly)) { |
|
|
|
if (!file.open(QIODevice::ReadOnly)) { |
|
|
@ -298,7 +294,7 @@ int FilterParserThread::parseP2BFilterFile(QString filePath, libt::ip_filter &fi |
|
|
|
libt::address_v4 last(ntohl(end)); |
|
|
|
libt::address_v4 last(ntohl(end)); |
|
|
|
// Apply to bittorrent session
|
|
|
|
// Apply to bittorrent session
|
|
|
|
try { |
|
|
|
try { |
|
|
|
filter.add_rule(first, last, libt::ip_filter::blocked); |
|
|
|
m_filter.add_rule(first, last, libt::ip_filter::blocked); |
|
|
|
++ruleCount; |
|
|
|
++ruleCount; |
|
|
|
} |
|
|
|
} |
|
|
|
catch(std::exception &) {} |
|
|
|
catch(std::exception &) {} |
|
|
@ -348,7 +344,7 @@ int FilterParserThread::parseP2BFilterFile(QString filePath, libt::ip_filter &fi |
|
|
|
libt::address_v4 last(ntohl(end)); |
|
|
|
libt::address_v4 last(ntohl(end)); |
|
|
|
// Apply to bittorrent session
|
|
|
|
// Apply to bittorrent session
|
|
|
|
try { |
|
|
|
try { |
|
|
|
filter.add_rule(first, last, libt::ip_filter::blocked); |
|
|
|
m_filter.add_rule(first, last, libt::ip_filter::blocked); |
|
|
|
++ruleCount; |
|
|
|
++ruleCount; |
|
|
|
} |
|
|
|
} |
|
|
|
catch(std::exception &) {} |
|
|
|
catch(std::exception &) {} |
|
|
@ -369,7 +365,7 @@ int FilterParserThread::parseP2BFilterFile(QString filePath, libt::ip_filter &fi |
|
|
|
// * eMule IP list (DAT): http://wiki.phoenixlabs.org/wiki/DAT_Format
|
|
|
|
// * eMule IP list (DAT): http://wiki.phoenixlabs.org/wiki/DAT_Format
|
|
|
|
// * PeerGuardian Text (P2P): http://wiki.phoenixlabs.org/wiki/P2P_Format
|
|
|
|
// * PeerGuardian Text (P2P): http://wiki.phoenixlabs.org/wiki/P2P_Format
|
|
|
|
// * PeerGuardian Binary (P2B): http://wiki.phoenixlabs.org/wiki/P2B_Format
|
|
|
|
// * PeerGuardian Binary (P2B): http://wiki.phoenixlabs.org/wiki/P2B_Format
|
|
|
|
void FilterParserThread::processFilterFile(QString filePath) |
|
|
|
void FilterParserThread::processFilterFile(const QString &filePath) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (isRunning()) { |
|
|
|
if (isRunning()) { |
|
|
|
// Already parsing a filter, m_abort first
|
|
|
|
// Already parsing a filter, m_abort first
|
|
|
@ -379,10 +375,16 @@ void FilterParserThread::processFilterFile(QString filePath) |
|
|
|
|
|
|
|
|
|
|
|
m_abort = false; |
|
|
|
m_abort = false; |
|
|
|
m_filePath = filePath; |
|
|
|
m_filePath = filePath; |
|
|
|
|
|
|
|
m_filter = libt::ip_filter(); |
|
|
|
// Run it
|
|
|
|
// Run it
|
|
|
|
start(); |
|
|
|
start(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
libt::ip_filter FilterParserThread::IPfilter() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return m_filter; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QString FilterParserThread::cleanupIPAddress(QString _ip) |
|
|
|
QString FilterParserThread::cleanupIPAddress(QString _ip) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_ip = _ip.trimmed(); |
|
|
|
_ip = _ip.trimmed(); |
|
|
@ -417,25 +419,23 @@ QString FilterParserThread::cleanupIPAddress(QString _ip) |
|
|
|
void FilterParserThread::run() |
|
|
|
void FilterParserThread::run() |
|
|
|
{ |
|
|
|
{ |
|
|
|
qDebug("Processing filter file"); |
|
|
|
qDebug("Processing filter file"); |
|
|
|
libt::ip_filter filter = m_session->get_ip_filter(); |
|
|
|
|
|
|
|
int ruleCount = 0; |
|
|
|
int ruleCount = 0; |
|
|
|
if (m_filePath.endsWith(".p2p", Qt::CaseInsensitive)) { |
|
|
|
if (m_filePath.endsWith(".p2p", Qt::CaseInsensitive)) { |
|
|
|
// PeerGuardian p2p file
|
|
|
|
// PeerGuardian p2p file
|
|
|
|
ruleCount = parseP2PFilterFile(m_filePath, filter); |
|
|
|
ruleCount = parseP2PFilterFile(); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (m_filePath.endsWith(".p2b", Qt::CaseInsensitive)) { |
|
|
|
else if (m_filePath.endsWith(".p2b", Qt::CaseInsensitive)) { |
|
|
|
// PeerGuardian p2b file
|
|
|
|
// PeerGuardian p2b file
|
|
|
|
ruleCount = parseP2BFilterFile(m_filePath, filter); |
|
|
|
ruleCount = parseP2BFilterFile(); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (m_filePath.endsWith(".dat", Qt::CaseInsensitive)) { |
|
|
|
else if (m_filePath.endsWith(".dat", Qt::CaseInsensitive)) { |
|
|
|
// eMule DAT format
|
|
|
|
// eMule DAT format
|
|
|
|
ruleCount = parseDATFilterFile(m_filePath, filter); |
|
|
|
ruleCount = parseDATFilterFile(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (m_abort) return; |
|
|
|
if (m_abort) return; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
m_session->set_ip_filter(filter); |
|
|
|
|
|
|
|
emit IPFilterParsed(ruleCount); |
|
|
|
emit IPFilterParsed(ruleCount); |
|
|
|
} |
|
|
|
} |
|
|
|
catch(std::exception &) { |
|
|
|
catch(std::exception &) { |
|
|
|