mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-27 11:49:01 +03:00
Improved IP address parsing
This commit is contained in:
parent
da95d5e0df
commit
41a61ced89
2 changed files with 40 additions and 7 deletions
|
@ -35,6 +35,7 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <QHostAddress>
|
||||||
|
|
||||||
#include <libtorrent/session.hpp>
|
#include <libtorrent/session.hpp>
|
||||||
#include <libtorrent/ip_filter.hpp>
|
#include <libtorrent/ip_filter.hpp>
|
||||||
|
@ -61,6 +62,14 @@ private:
|
||||||
QString filePath;
|
QString filePath;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
QString cleanupIPAddress(QString _ip) {
|
||||||
|
QHostAddress ip(_ip.trimmed());
|
||||||
|
if(ip.isNull()) {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
return ip.toString();
|
||||||
|
}
|
||||||
|
|
||||||
void run(){
|
void run(){
|
||||||
qDebug("Processing filter file");
|
qDebug("Processing filter file");
|
||||||
if(filePath.endsWith(".dat", Qt::CaseInsensitive)) {
|
if(filePath.endsWith(".dat", Qt::CaseInsensitive)) {
|
||||||
|
@ -125,14 +134,24 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
const QString strStartIP = IPs.at(0).trimmed();
|
const QString strStartIP = cleanupIPAddress(IPs.at(0));
|
||||||
|
if(strStartIP.isEmpty()) {
|
||||||
|
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
|
||||||
|
qDebug("Start IP of the range is malformated: %s", qPrintable(strStartIP));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
libtorrent::address startAddr = libtorrent::address::from_string(qPrintable(strStartIP), ec);
|
libtorrent::address startAddr = libtorrent::address::from_string(qPrintable(strStartIP), ec);
|
||||||
if(ec) {
|
if(ec) {
|
||||||
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
|
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
|
||||||
qDebug("Start IP of the range is malformated: %s", qPrintable(strStartIP));
|
qDebug("Start IP of the range is malformated: %s", qPrintable(strStartIP));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const QString strEndIP = IPs.at(1).trimmed();
|
const QString strEndIP = cleanupIPAddress(IPs.at(1));
|
||||||
|
if(strEndIP.isEmpty()) {
|
||||||
|
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
|
||||||
|
qDebug("End IP of the range is malformated: %s", qPrintable(strEndIP));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
libtorrent::address endAddr = libtorrent::address::from_string(qPrintable(strEndIP), ec);
|
libtorrent::address endAddr = libtorrent::address::from_string(qPrintable(strEndIP), ec);
|
||||||
if(ec) {
|
if(ec) {
|
||||||
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
|
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
|
||||||
|
@ -197,14 +216,24 @@ public:
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
QString strStartIP = IPs.at(0).trimmed();
|
QString strStartIP = cleanupIPAddress(IPs.at(0));
|
||||||
|
if(strStartIP.isEmpty()) {
|
||||||
|
qDebug("p2p file: line %d is malformed.", nbLine);
|
||||||
|
qDebug("Start IP is invalid: %s", qPrintable(strStartIP));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
libtorrent::address startAddr = libtorrent::address::from_string(qPrintable(strStartIP), ec);
|
libtorrent::address startAddr = libtorrent::address::from_string(qPrintable(strStartIP), ec);
|
||||||
if(ec) {
|
if(ec) {
|
||||||
qDebug("p2p file: line %d is malformed.", nbLine);
|
qDebug("p2p file: line %d is malformed.", nbLine);
|
||||||
qDebug("Start IP is invalid: %s", qPrintable(strStartIP));
|
qDebug("Start IP is invalid: %s", qPrintable(strStartIP));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
QString strEndIP = IPs.at(1).trimmed();
|
QString strEndIP = cleanupIPAddress(IPs.at(1));
|
||||||
|
if(strEndIP.isEmpty()) {
|
||||||
|
qDebug("p2p file: line %d is malformed.", nbLine);
|
||||||
|
qDebug("End IP is invalid: %s", qPrintable(strStartIP));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
libtorrent::address endAddr = libtorrent::address::from_string(qPrintable(strEndIP), ec);
|
libtorrent::address endAddr = libtorrent::address::from_string(qPrintable(strEndIP), ec);
|
||||||
if(ec) {
|
if(ec) {
|
||||||
qDebug("p2p file: line %d is malformed.", nbLine);
|
qDebug("p2p file: line %d is malformed.", nbLine);
|
||||||
|
|
|
@ -60,7 +60,12 @@ public:
|
||||||
~PeerAdditionDlg(){}
|
~PeerAdditionDlg(){}
|
||||||
|
|
||||||
QString getIP() const {
|
QString getIP() const {
|
||||||
return lineIP->text();
|
QHostAddress ip(lineIP->text());
|
||||||
|
if(!ip.isNull()) {
|
||||||
|
// QHostAddress::toString() cleans up the IP for libtorrent
|
||||||
|
return ip.toString();
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned short getPort() const {
|
unsigned short getPort() const {
|
||||||
|
@ -87,8 +92,7 @@ public:
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void validateInput() {
|
void validateInput() {
|
||||||
QHostAddress ip(getIP());
|
if(getIP().isEmpty()) {
|
||||||
if(ip.isNull()) {
|
|
||||||
QMessageBox::warning(this, tr("Invalid IP"),
|
QMessageBox::warning(this, tr("Invalid IP"),
|
||||||
tr("The IP you provided is invalid."),
|
tr("The IP you provided is invalid."),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
|
|
Loading…
Reference in a new issue