Web UI code clean up

This commit is contained in:
Christophe Dumez 2011-09-25 11:45:57 +03:00
parent 8e026e68d7
commit 28d1671bb8
2 changed files with 11 additions and 16 deletions

View file

@ -33,7 +33,6 @@
#include "httpconnection.h"
#include "eventmanager.h"
#include "qbtsession.h"
#include <QTimer>
#include <QCryptographicHash>
#include <QTime>
#include <QRegExp>
@ -51,15 +50,12 @@ const int BAN_TIME = 3600000; // 1 hour
class UnbanTimer: public QTimer {
public:
UnbanTimer(QObject *parent, const QString& peer_ip): QTimer(parent), m_peerIp(peer_ip){
UnbanTimer(const QString& peer_ip, QObject *parent): QTimer(parent),
m_peerIp(peer_ip) {
setSingleShot(true);
setInterval(BAN_TIME);
}
~UnbanTimer() {
qDebug("||||||||||||Deleting ban timer|||||||||||||||");
}
inline QString peerIp() const { return m_peerIp; }
private:
@ -78,13 +74,13 @@ int HttpServer::NbFailedAttemptsForIp(const QString& ip) const {
}
void HttpServer::increaseNbFailedAttemptsForIp(const QString& ip) {
const int nb_fail = m_clientFailedAttempts.value(ip, 0);
m_clientFailedAttempts.insert(ip, nb_fail+1);
if(nb_fail == MAX_AUTH_FAILED_ATTEMPTS-1) {
const int nb_fail = m_clientFailedAttempts.value(ip, 0) + 1;
m_clientFailedAttempts.insert(ip, nb_fail);
if(nb_fail == MAX_AUTH_FAILED_ATTEMPTS) {
// Max number of failed attempts reached
// Start ban period
UnbanTimer* ubantimer = new UnbanTimer(this, ip);
connect(ubantimer, SIGNAL(timeout()), this, SLOT(UnbanTimerEvent()));
UnbanTimer* ubantimer = new UnbanTimer(ip, this);
connect(ubantimer, SIGNAL(timeout()), SLOT(UnbanTimerEvent()));
ubantimer->start();
}
}
@ -125,9 +121,8 @@ HttpServer::HttpServer(int msec, QObject* parent) : QTcpServer(parent),
connect(QBtSession::instance(), SIGNAL(deletedTorrent(QString)), m_eventManager, SLOT(deletedTorrent(QString)));
//set timer
m_timer = new QTimer(this);
connect(m_timer, SIGNAL(timeout()), this, SLOT(onTimer()));
m_timer->start(msec);
connect(&m_timer, SIGNAL(timeout()), SLOT(onTimer()));
m_timer.start(msec);
// Additional translations for Web UI
QString a = tr("File");
@ -161,7 +156,6 @@ HttpServer::HttpServer(int msec, QObject* parent) : QTcpServer(parent),
}
HttpServer::~HttpServer() {
delete m_timer;
delete m_eventManager;
}

View file

@ -36,6 +36,7 @@
#include <QTcpServer>
#include <QByteArray>
#include <QHash>
#include <QTimer>
#ifndef QT_NO_OPENSSL
#include <QSslCertificate>
@ -88,7 +89,7 @@ private:
QByteArray m_username;
QByteArray m_passwordSha1;
EventManager *m_eventManager;
QTimer *m_timer;
QTimer m_timer;
QHash<QString, int> m_clientFailedAttempts;
bool m_localAuth;
#ifndef QT_NO_OPENSSL