From 28d1671bb82606cf7421572caef70892eaea4e96 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 25 Sep 2011 11:45:57 +0300 Subject: [PATCH] Web UI code clean up --- src/webui/httpserver.cpp | 24 +++++++++--------------- src/webui/httpserver.h | 3 ++- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/webui/httpserver.cpp b/src/webui/httpserver.cpp index 1efd94262..153a3db6c 100644 --- a/src/webui/httpserver.cpp +++ b/src/webui/httpserver.cpp @@ -33,7 +33,6 @@ #include "httpconnection.h" #include "eventmanager.h" #include "qbtsession.h" -#include #include #include #include @@ -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; } diff --git a/src/webui/httpserver.h b/src/webui/httpserver.h index b3d8b4640..15601b078 100644 --- a/src/webui/httpserver.h +++ b/src/webui/httpserver.h @@ -36,6 +36,7 @@ #include #include #include +#include #ifndef QT_NO_OPENSSL #include @@ -88,7 +89,7 @@ private: QByteArray m_username; QByteArray m_passwordSha1; EventManager *m_eventManager; - QTimer *m_timer; + QTimer m_timer; QHash m_clientFailedAttempts; bool m_localAuth; #ifndef QT_NO_OPENSSL