mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-22 20:44:15 +00:00
- Made ipfilter.dat parser less sensitive to errors
This commit is contained in:
parent
86cfe82b89
commit
98ecb97790
@ -790,50 +790,54 @@ void options_imp::processFilterFile(const QString& filePath){
|
|||||||
while (!file.atEnd()) {
|
while (!file.atEnd()) {
|
||||||
++nbLine;
|
++nbLine;
|
||||||
QByteArray line = file.readLine();
|
QByteArray line = file.readLine();
|
||||||
if(!line.startsWith('#') && !line.startsWith("//")){
|
if(line.startsWith('#') || line.startsWith("//")) continue;
|
||||||
// Line is not commented
|
// Line is not commented
|
||||||
QList<QByteArray> partsList = line.split(',');
|
QList<QByteArray> partsList = line.split(',');
|
||||||
unsigned int nbElem = partsList.size();
|
unsigned int nbElem = partsList.size();
|
||||||
if(nbElem < 2){
|
if(nbElem < 2){
|
||||||
std::cerr << "Ipfilter.dat: line " << nbLine << " is malformed.\n";
|
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
bool ok;
|
||||||
|
int nbAccess = partsList.at(1).trimmed().toInt(&ok);
|
||||||
|
if(!ok){
|
||||||
|
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(nbAccess <= 127){
|
||||||
|
QString strComment;
|
||||||
|
QString strStartIP = partsList.at(0).split('-').at(0).trimmed();
|
||||||
|
QString strEndIP = partsList.at(0).split('-').at(1).trimmed();
|
||||||
|
if(nbElem > 2){
|
||||||
|
strComment = partsList.at(2).trimmed();
|
||||||
|
}else{
|
||||||
|
strComment = QString();
|
||||||
|
}
|
||||||
|
// Split IP
|
||||||
|
IP = strStartIP.split('.');
|
||||||
|
if(IP.size() != 4){
|
||||||
|
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int nbAccess = partsList.at(1).trimmed().toInt();
|
address_v4 start((IP.at(0).toInt() << 24) + (IP.at(1).toInt() << 16) + (IP.at(2).toInt() << 8) + IP.at(3).toInt());
|
||||||
if(nbAccess <= 127){
|
IP = strEndIP.split('.');
|
||||||
QString strComment;
|
if(IP.size() != 4){
|
||||||
QString strStartIP = partsList.at(0).split('-').at(0).trimmed();
|
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
|
||||||
QString strEndIP = partsList.at(0).split('-').at(1).trimmed();
|
continue;
|
||||||
if(nbElem > 2){
|
|
||||||
strComment = partsList.at(2).trimmed();
|
|
||||||
}else{
|
|
||||||
strComment = QString();
|
|
||||||
}
|
|
||||||
// Split IP
|
|
||||||
IP = strStartIP.split('.');
|
|
||||||
if(IP.size() != 4){
|
|
||||||
std::cerr << "Ipfilter.dat: line " << nbLine << ", first IP is malformed.\n";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
address_v4 start((IP.at(0).toInt() << 24) + (IP.at(1).toInt() << 16) + (IP.at(2).toInt() << 8) + IP.at(3).toInt());
|
|
||||||
IP = strEndIP.split('.');
|
|
||||||
if(IP.size() != 4){
|
|
||||||
std::cerr << "Ipfilter.dat: line " << nbLine << ", second IP is malformed.\n";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
address_v4 last((IP.at(0).toInt() << 24) + (IP.at(1).toInt() << 16) + (IP.at(2).toInt() << 8) + IP.at(3).toInt());
|
|
||||||
// add it to list
|
|
||||||
QStringList item(QString(start.to_string().c_str()));
|
|
||||||
item.append(QString(last.to_string().c_str()));
|
|
||||||
if(!i){
|
|
||||||
item.append("Manual");
|
|
||||||
}else{
|
|
||||||
item.append("ipfilter.dat");
|
|
||||||
}
|
|
||||||
item.append(strComment);
|
|
||||||
new QTreeWidgetItem(filtersList, item);
|
|
||||||
// Apply to bittorrent session
|
|
||||||
filter.add_rule(start, last, ip_filter::blocked);
|
|
||||||
}
|
}
|
||||||
|
address_v4 last((IP.at(0).toInt() << 24) + (IP.at(1).toInt() << 16) + (IP.at(2).toInt() << 8) + IP.at(3).toInt());
|
||||||
|
// add it to list
|
||||||
|
QStringList item(QString(start.to_string().c_str()));
|
||||||
|
item.append(QString(last.to_string().c_str()));
|
||||||
|
if(!i){
|
||||||
|
item.append("Manual");
|
||||||
|
}else{
|
||||||
|
item.append("ipfilter.dat");
|
||||||
|
}
|
||||||
|
item.append(strComment);
|
||||||
|
new QTreeWidgetItem(filtersList, item);
|
||||||
|
// Apply to bittorrent session
|
||||||
|
filter.add_rule(start, last, ip_filter::blocked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user