Browse Source

Output log messages for ip filter parsing errors.

adaptive-webui-19844
sledgehammer999 9 years ago
parent
commit
f53dab8ad4
No known key found for this signature in database
GPG Key ID: 6E4A2D025B7CC9A2
  1. 2
      src/app/application.cpp
  2. 53
      src/base/bittorrent/private/filterparserthread.cpp

2
src/app/application.cpp

@ -106,6 +106,8 @@ Application::Application(const QString &id, int &argc, char **argv)
, m_shutdownAct(ShutdownDialogAction::Exit) , m_shutdownAct(ShutdownDialogAction::Exit)
, m_commandLineArgs(parseCommandLine(this->arguments())) , m_commandLineArgs(parseCommandLine(this->arguments()))
{ {
qRegisterMetaType<Log::Msg>("Log::Msg");
setApplicationName("qBittorrent"); setApplicationName("qBittorrent");
validateCommandLineParameters(); validateCommandLineParameters();

53
src/base/bittorrent/private/filterparserthread.cpp

@ -125,34 +125,25 @@ int FilterParserThread::parseDATFilterFile()
// IP Range should be split by a dash // IP Range should be split by a dash
QList<QByteArray> IPs = partsList.first().split('-'); QList<QByteArray> IPs = partsList.first().split('-');
if (IPs.size() != 2) { if (IPs.size() != 2) {
qDebug("Ipfilter.dat: line %d is malformed.", nbLine); Logger::instance()->addMessage(tr("IP filter line %1 is malformed. Line is: %2").arg(nbLine).arg(QString(line)), Log::CRITICAL);
qDebug("Line was %s", line.constData());
continue; continue;
} }
libt::address startAddr; libt::address startAddr;
if (!parseIPAddress(IPs.at(0), startAddr)) { if (!parseIPAddress(IPs.at(0), startAddr)) {
qDebug("Ipfilter.dat: line %d is malformed.", nbLine); Logger::instance()->addMessage(tr("IP filter line %1 is malformed. Start IP of the range is malformed: %2").arg(nbLine).arg(QString(IPs.at(0))), Log::CRITICAL);
qDebug("Start IP of the range is malformated: %s", qPrintable(IPs.at(0)));
continue; continue;
} }
libt::address endAddr; libt::address endAddr;
if (!parseIPAddress(IPs.at(1), endAddr)) { if (!parseIPAddress(IPs.at(1), endAddr)) {
qDebug("Ipfilter.dat: line %d is malformed.", nbLine); Logger::instance()->addMessage(tr("IP filter line %1 is malformed. End IP of the range is malformed: %2").arg(nbLine).arg(QString(IPs.at(1))), Log::CRITICAL);
qDebug("End IP of the range is malformated: %s", qPrintable(IPs.at(1)));
continue; continue;
} }
if (startAddr.is_v4() != endAddr.is_v4()) { if (startAddr.is_v4() != endAddr.is_v4()
qDebug("Ipfilter.dat: line %d is malformed.", nbLine); || startAddr.is_v6() != endAddr.is_v6()) {
qDebug("One IP is IPv4 and the other is IPv6!"); Logger::instance()->addMessage(tr("IP filter line %1 is malformed. One IP is IPv4 and the other is IPv6!").arg(nbLine), Log::CRITICAL);
continue;
}
if (startAddr.is_v6() != endAddr.is_v6()) {
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
qDebug("One IP is IPv6 and the other is IPv4!");
continue; continue;
} }
@ -162,11 +153,10 @@ int FilterParserThread::parseDATFilterFile()
++ruleCount; ++ruleCount;
} }
catch(std::exception &) { catch(std::exception &) {
qDebug("Bad line in filter file, avoided crash..."); Logger::instance()->addMessage(tr("IP filter exception thrown for line %1. Line is: %2").arg(nbLine).arg(QString(line)), Log::CRITICAL);
} }
} }
file.close();
return ruleCount; return ruleCount;
} }
@ -193,41 +183,32 @@ int FilterParserThread::parseP2PFilterFile()
// Line is split by : // Line is split by :
QList<QByteArray> partsList = line.split(':'); QList<QByteArray> partsList = line.split(':');
if (partsList.size() < 2) { if (partsList.size() < 2) {
qDebug("p2p file: line %d is malformed.", nbLine); Logger::instance()->addMessage(tr("IP filter line %1 is malformed. Line is: %2").arg(nbLine).arg(QString(line)), Log::CRITICAL);
continue; continue;
} }
// Get IP range // Get IP range
QList<QByteArray> IPs = partsList.last().split('-'); QList<QByteArray> IPs = partsList.last().split('-');
if (IPs.size() != 2) { if (IPs.size() != 2) {
qDebug("p2p file: line %d is malformed.", nbLine); Logger::instance()->addMessage(tr("IP filter line %1 is malformed. Line is: %2").arg(nbLine).arg(QString(line)), Log::CRITICAL);
qDebug("line was: %s", line.constData());
continue; continue;
} }
libt::address startAddr; libt::address startAddr;
if (!parseIPAddress(IPs.at(0), startAddr)) { if (!parseIPAddress(IPs.at(0), startAddr)) {
qDebug("p2p file: line %d is malformed.", nbLine); Logger::instance()->addMessage(tr("IP filter line %1 is malformed. Start IP of the range is malformed: %2").arg(nbLine).arg(QString(IPs.at(0))), Log::CRITICAL);
qDebug("Start IP is invalid: %s", qPrintable(IPs.at(0)));
continue; continue;
} }
libt::address endAddr; libt::address endAddr;
if (!parseIPAddress(IPs.at(1), endAddr)) { if (!parseIPAddress(IPs.at(1), endAddr)) {
qDebug("p2p file: line %d is malformed.", nbLine); Logger::instance()->addMessage(tr("IP filter line %1 is malformed. End IP of the range is malformed: %2").arg(nbLine).arg(QString(IPs.at(1))), Log::CRITICAL);
qDebug("End IP is invalid: %s", qPrintable(IPs.at(1)));
continue; continue;
} }
if (startAddr.is_v4() != endAddr.is_v4()) { if (startAddr.is_v4() != endAddr.is_v4()
qDebug("p2p file: line %d is malformed.", nbLine); || startAddr.is_v6() != endAddr.is_v6()) {
qDebug("One IP is IPv4 and the other is IPv6!"); Logger::instance()->addMessage(tr("IP filter line %1 is malformed. One IP is IPv4 and the other is IPv6!").arg(nbLine), Log::CRITICAL);
continue;
}
if (startAddr.is_v6() != endAddr.is_v6()) {
qDebug("p2p file: line %d is malformed.", nbLine);
qDebug("One IP is IPv6 and the other is IPv4!");
continue; continue;
} }
@ -236,13 +217,10 @@ int FilterParserThread::parseP2PFilterFile()
++ruleCount; ++ruleCount;
} }
catch(std::exception &) { catch(std::exception &) {
qDebug("p2p file: line %d is malformed.", nbLine); Logger::instance()->addMessage(tr("IP filter exception thrown for line %1. Line is: %2").arg(nbLine).arg(QString(line)), Log::CRITICAL);
qDebug("Line was: %s", line.constData());
continue;
} }
} }
file.close();
return ruleCount; return ruleCount;
} }
@ -373,7 +351,6 @@ int FilterParserThread::parseP2BFilterFile()
Logger::instance()->addMessage(tr("Parsing Error: The filter file is not a valid PeerGuardian P2B file."), Log::CRITICAL); Logger::instance()->addMessage(tr("Parsing Error: The filter file is not a valid PeerGuardian P2B file."), Log::CRITICAL);
} }
file.close();
return ruleCount; return ruleCount;
} }

Loading…
Cancel
Save