Browse Source

- FEATURE: Added support for PeerGuardian p2b filters (binary)

adaptive-webui-19844
Christophe Dumez 17 years ago
parent
commit
ce627de39d
  1. 3
      Changelog
  2. 127
      src/options_imp.cpp
  3. 12
      src/options_imp.h

3
Changelog

@ -9,7 +9,8 @@
- FEATURE: Display if UPnP/NAT-PMP was successful or not - FEATURE: Display if UPnP/NAT-PMP was successful or not
- FEATURE: Threadified torrent creation - FEATURE: Threadified torrent creation
- FEATURE: Improved eMule DAT ip filter parser - FEATURE: Improved eMule DAT ip filter parser
- FEATURE: Added support for PeerGuardian p2p filters - FEATURE: Added support for PeerGuardian p2p filters (text)
- FEATURE: Added support for PeerGuardian p2b filters (binary)
- BUGFIX: Do not display seeds number in seeding list (always 0) - BUGFIX: Do not display seeds number in seeding list (always 0)
- COSMETIC: Do not display progress bar in seeding list (always 100%) - COSMETIC: Do not display progress bar in seeding list (always 100%)
- COSMETIC: Added a progress bar for torrent creation - COSMETIC: Added a progress bar for torrent creation

127
src/options_imp.cpp

@ -39,6 +39,10 @@
#include <QMacStyle> #include <QMacStyle>
#endif #endif
// P2B Stuff
#include <arpa/inet.h>
// End of P2B stuff
#include "options_imp.h" #include "options_imp.h"
#include "misc.h" #include "misc.h"
@ -1218,11 +1222,121 @@ void options_imp::parseP2PFilterFile(QString filePath) {
} }
} }
int options_imp::getlineInStream(QDataStream& stream, string& name, char delim) {
char c;
int total_read = 0;
do {
int read = stream.readRawData(&c, 1);
total_read += read;
if(read > 0) {
if(c != delim) {
name += c;
} else {
// Delim found
return total_read;
}
}
} while(read > 0);
return total_read;
}
// Parser for PeerGuardian ip filter in p2p format
void options_imp::parseP2BFilterFile(QString filePath) {
QFile file(filePath);
if (file.exists()){
if(!file.open(QIODevice::ReadOnly)){
QMessageBox::critical(0, tr("I/O Error", "Input/Output Error"), tr("Couldn't open %1 in read mode.").arg(filePath));
return;
}
QDataStream stream(&file);
// Read header
char buf[7];
unsigned char version;
if(
!stream.readRawData(buf, sizeof(buf)) ||
memcmp(buf, "\xFF\xFF\xFF\xFFP2B", 7) ||
!stream.readRawData((char*)&version, sizeof(version))
) {
QMessageBox::critical(0, tr("I/O Error", "Input/Output Error"), tr("%1 is not a valid PeerGuardian P2B file.").arg(filePath));
return;
}
if(version==1 || version==2) {
unsigned int start, end;
string name;
while(getlineInStream(stream, name, '\0')) {
if(
!stream.readRawData((char*)&start, sizeof(start)) ||
!stream.readRawData((char*)&end, sizeof(end))
) {
QMessageBox::critical(0, tr("I/O Error", "Input/Output Error"), tr("%1 is not a valid PeerGuardian P2B file.").arg(filePath));
return;
}
// Network byte order to Host byte order
// asio address_v4 contructor expects it
// that way
address_v4 first(ntohl(start));
address_v4 last(ntohl(end));
// Apply to bittorrent session
filter.add_rule(first, last, ip_filter::blocked);
}
}
else if(version==3) {
unsigned int namecount;
if(!stream.readRawData((char*)&namecount, sizeof(namecount))) {
QMessageBox::critical(0, tr("I/O Error", "Input/Output Error"), tr("%1 is not a valid PeerGuardian P2B file.").arg(filePath));
return;
}
namecount=ntohl(namecount);
// Reading names although, we don't really care about them
for(unsigned int i=0; i<namecount; i++) {
string name;
if(!getlineInStream(stream, name, '\0')) {
QMessageBox::critical(0, tr("I/O Error", "Input/Output Error"), tr("%1 is not a valid PeerGuardian P2B file.").arg(filePath));
return;
}
}
// Reading the ranges
unsigned int rangecount;
if(!stream.readRawData((char*)&rangecount, sizeof(rangecount))) {
QMessageBox::critical(0, tr("I/O Error", "Input/Output Error"), tr("%1 is not a valid PeerGuardian P2B file.").arg(filePath));
return;
}
rangecount=ntohl(rangecount);
unsigned int name, start, end;
for(unsigned int i=0; i<rangecount; i++) {
if(
!stream.readRawData((char*)&name, sizeof(name)) ||
!stream.readRawData((char*)&start, sizeof(start)) ||
!stream.readRawData((char*)&end, sizeof(end))
) {
QMessageBox::critical(0, tr("I/O Error", "Input/Output Error"), tr("%1 is not a valid PeerGuardian P2B file.").arg(filePath));
return;
}
// Network byte order to Host byte order
// asio address_v4 contructor expects it
// that way
address_v4 first(ntohl(start));
address_v4 last(ntohl(end));
// Apply to bittorrent session
filter.add_rule(first, last, ip_filter::blocked);
}
} else {
QMessageBox::critical(0, tr("I/O Error", "Input/Output Error"), tr("%1 is not a valid PeerGuardian P2B file.").arg(filePath));
return;
}
file.close();
}
}
// Process ip filter file // Process ip filter file
// Supported formats: // Supported formats:
// * 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 (TODO) // * PeerGuardian Text (P2P): http://wiki.phoenixlabs.org/wiki/P2P_Format
// * PeerGuardian Binary (P2B): http://wiki.phoenixlabs.org/wiki/P2B_Format (TODO) // * PeerGuardian Binary (P2B): http://wiki.phoenixlabs.org/wiki/P2B_Format
void options_imp::processFilterFile(QString filePath){ void options_imp::processFilterFile(QString filePath){
qDebug("Processing filter files"); qDebug("Processing filter files");
if(filePath.endsWith(".dat", Qt::CaseInsensitive)) { if(filePath.endsWith(".dat", Qt::CaseInsensitive)) {
@ -1232,8 +1346,15 @@ void options_imp::processFilterFile(QString filePath){
if(filePath.endsWith(".p2p", Qt::CaseInsensitive)) { if(filePath.endsWith(".p2p", Qt::CaseInsensitive)) {
// PeerGuardian p2p file // PeerGuardian p2p file
parseP2PFilterFile(filePath); parseP2PFilterFile(filePath);
} else {
if(filePath.endsWith(".p2p", Qt::CaseInsensitive)) {
// PeerGuardian p2p file
parseP2BFilterFile(filePath);
} else {
// Default: eMule DAT format
parseDATFilterFile(filePath);
}
} }
// TODO: Add p2b support
} }
} }

12
src/options_imp.h

@ -24,12 +24,11 @@
#include "ui_options.h" #include "ui_options.h"
#include <libtorrent/ip_filter.hpp> #include <libtorrent/ip_filter.hpp>
#include <QDataStream>
/*#include <QDialog> // P2B Stuff
#include <qdialog.h> #include <string.h>
#include "ui_options.h" // End of P2B stuff
#include "ui_dialog.h"
#include <libtorrent/ip_filter.hpp>*/
#define HTTP 1 #define HTTP 1
#define SOCKS5 2 #define SOCKS5 2
@ -42,6 +41,7 @@
#define SHOW_PROPERTIES 2 #define SHOW_PROPERTIES 2
using namespace libtorrent; using namespace libtorrent;
using namespace std;
class QCloseEvent; class QCloseEvent;
@ -115,6 +115,7 @@ class options_imp : public QDialog, private Ui::Dialog {
quint16 webUiPort() const; quint16 webUiPort() const;
QString webUiUsername() const; QString webUiUsername() const;
QString webUiPassword() const; QString webUiPassword() const;
int getlineInStream(QDataStream& stream, string& name, char delim);
protected slots: protected slots:
void enableUploadLimit(int checkBoxValue); void enableUploadLimit(int checkBoxValue);
@ -145,6 +146,7 @@ class options_imp : public QDialog, private Ui::Dialog {
void enableWebUi(bool checkBoxValue); void enableWebUi(bool checkBoxValue);
void parseDATFilterFile(QString filePath); void parseDATFilterFile(QString filePath);
void parseP2PFilterFile(QString filePath); void parseP2PFilterFile(QString filePath);
void parseP2BFilterFile(QString filePath);
public slots: public slots:
void setLocale(QString locale); void setLocale(QString locale);

Loading…
Cancel
Save