diff options
-rw-r--r-- | src/Ban.cpp | 52 | ||||
-rw-r--r-- | src/Ban.h | 34 | ||||
-rw-r--r-- | src/Net.h | 17 | ||||
-rw-r--r-- | src/mumble.pri | 4 | ||||
-rw-r--r-- | src/mumble/BanEditor.cpp | 2 | ||||
-rw-r--r-- | src/mumble/BanEditor.h | 2 | ||||
-rw-r--r-- | src/murmur/MurmurIce.cpp | 1 | ||||
-rw-r--r-- | src/murmur/Server.h | 2 |
8 files changed, 92 insertions, 22 deletions
diff --git a/src/Ban.cpp b/src/Ban.cpp new file mode 100644 index 000000000..e7f530d54 --- /dev/null +++ b/src/Ban.cpp @@ -0,0 +1,52 @@ +// Copyright 2005-2017 The Mumble Developers. All rights reserved. +// Use of this source code is governed by a BSD-style license +// that can be found in the LICENSE file at the root of the +// Mumble source tree or at <https://www.mumble.info/LICENSE>. + +#include "murmur_pch.h" + +#include "Ban.h" + +bool Ban::isExpired() const { + return (iDuration > 0) && static_cast<int>(iDuration - qdtStart.secsTo(QDateTime::currentDateTime().toUTC())) < 0; +} + +bool Ban::operator <(const Ban &other) const { + // Compare username primarily and address secondarily + const int unameDifference = qsUsername.localeAwareCompare(other.qsUsername); + if (unameDifference == 0) + return haAddress < other.haAddress; + else + return unameDifference < 0; +} + +bool Ban::operator ==(const Ban &other) const { + return (haAddress == other.haAddress) + && (iMask == other.iMask) + && (qsUsername == other.qsUsername) + && (qsHash == other.qsHash) + && (qsReason == other.qsReason) + && (qdtStart == other.qdtStart) + && (iDuration == other.iDuration); +} + +bool Ban::isValid() const { + return haAddress.isValid() && (iMask >= 8) && (iMask <= 128); +} + +QString Ban::toString() const { + return QString(QLatin1String("Hash: \"%1\", Host: \"%2\", Mask: \"%3\", Username: \"%4\", Reason: \"%5\", BanStart: \"%6\", BanEnd: \"%7\" %8")).arg( + qsHash, + haAddress.toString(), + haAddress.isV6() ? QString::number(iMask) : QString::number(iMask-96), + qsUsername, + qsReason, + qdtStart.toLocalTime().toString(QLatin1String("yyyy-MM-dd hh:mm:ss")), + qdtStart.toLocalTime().addSecs(iDuration).toString(QLatin1String("yyyy-MM-dd hh:mm:ss")), + iDuration == 0 ? QLatin1String("(permanent)") : QLatin1String("(temporary)") + ); +} + +quint32 qHash(const Ban &b) { + return qHash(b.qsHash) ^ qHash(b.haAddress) ^ qHash(b.qsUsername) ^ qHash(b.iMask); +} diff --git a/src/Ban.h b/src/Ban.h new file mode 100644 index 000000000..d7b8b9c78 --- /dev/null +++ b/src/Ban.h @@ -0,0 +1,34 @@ +// Copyright 2005-2017 The Mumble Developers. All rights reserved. +// Use of this source code is governed by a BSD-style license +// that can be found in the LICENSE file at the root of the +// Mumble source tree or at <https://www.mumble.info/LICENSE>. + +#ifndef MUMBLE_BAN_H_ +#define MUMBLE_BAN_H_ + +#include "HostAddress.h" + +#include <QtCore/QtGlobal> +#include <QtCore/QString> +#include <QtCore/QDateTime> +#include <QtNetwork/QHostAddress> +#include <QtNetwork/Q_IPV6ADDR> + +struct Ban { + HostAddress haAddress; + int iMask; + QString qsUsername; + QString qsHash; + QString qsReason; + QDateTime qdtStart; + unsigned int iDuration; + bool isExpired() const; + bool isValid() const; + bool operator < (const Ban &) const; + bool operator == (const Ban &) const; + QString toString() const; +}; + +quint32 qHash(const Ban &); + +#endif @@ -16,21 +16,4 @@ #define DEFAULT_MUMBLE_PORT 64738 #endif -struct Ban { - HostAddress haAddress; - int iMask; - QString qsUsername; - QString qsHash; - QString qsReason; - QDateTime qdtStart; - unsigned int iDuration; - bool isExpired() const; - bool isValid() const; - bool operator < (const Ban &) const; - bool operator == (const Ban &) const; - QString toString() const; -}; - -quint32 qHash(const Ban &); - #endif diff --git a/src/mumble.pri b/src/mumble.pri index 35f8fef88..3852d7f2d 100644 --- a/src/mumble.pri +++ b/src/mumble.pri @@ -14,8 +14,8 @@ CONFIG += qt thread debug_and_release warn_on DEFINES *= MUMBLE_VERSION_STRING=$$VERSION INCLUDEPATH += $$PWD . ../mumble_proto VPATH += $$PWD -HEADERS *= ACL.h Channel.h CryptState.h Connection.h Group.h HTMLFilter.h User.h Net.h OSInfo.h Timer.h SSL.h Version.h SSLCipherInfo.h SSLCipherInfoTable.h licenses.h License.h LogEmitter.h CryptographicHash.h CryptographicRandom.h PasswordGenerator.h ByteSwap.h HostAddress.cpp -SOURCES *= ACL.cpp Group.cpp Channel.cpp Connection.cpp HTMLFilter.cpp User.cpp Timer.cpp CryptState.cpp OSInfo.cpp Net.cpp SSL.cpp Version.cpp SSLCipherInfo.cpp License.cpp LogEmitter.cpp CryptographicHash.cpp CryptographicRandom.cpp PasswordGenerator.cpp HostAddress.cpp +HEADERS *= ACL.h Channel.h CryptState.h Connection.h Group.h HTMLFilter.h User.h Net.h OSInfo.h Timer.h SSL.h Version.h SSLCipherInfo.h SSLCipherInfoTable.h licenses.h License.h LogEmitter.h CryptographicHash.h CryptographicRandom.h PasswordGenerator.h ByteSwap.h HostAddress.cpp Ban.h +SOURCES *= ACL.cpp Group.cpp Channel.cpp Connection.cpp HTMLFilter.cpp User.cpp Timer.cpp CryptState.cpp OSInfo.cpp SSL.cpp Version.cpp SSLCipherInfo.cpp License.cpp LogEmitter.cpp CryptographicHash.cpp CryptographicRandom.cpp PasswordGenerator.cpp HostAddress.cpp Ban.cpp LIBS *= -lmumble_proto # Add arc4random_uniform diff --git a/src/mumble/BanEditor.cpp b/src/mumble/BanEditor.cpp index 0e534c55a..197a3e655 100644 --- a/src/mumble/BanEditor.cpp +++ b/src/mumble/BanEditor.cpp @@ -9,7 +9,7 @@ #include "Channel.h" #include "Global.h" -#include "Net.h" +#include "Ban.h" #include "ServerHandler.h" BanEditor::BanEditor(const MumbleProto::BanList &msg, QWidget *p) : QDialog(p) diff --git a/src/mumble/BanEditor.h b/src/mumble/BanEditor.h index 2f32c4b49..cb1ed252f 100644 --- a/src/mumble/BanEditor.h +++ b/src/mumble/BanEditor.h @@ -6,7 +6,7 @@ #ifndef MUMBLE_MUMBLE_BANEDITOR_H_ #define MUMBLE_MUMBLE_BANEDITOR_H_ -#include "Net.h" +#include "Ban.h" #include "ui_BanEditor.h" diff --git a/src/murmur/MurmurIce.cpp b/src/murmur/MurmurIce.cpp index b43de9353..f6f470a6c 100644 --- a/src/murmur/MurmurIce.cpp +++ b/src/murmur/MurmurIce.cpp @@ -21,6 +21,7 @@ #include "ServerUser.h" #include "ServerDB.h" #include "User.h" +#include "Ban.h" using namespace std; using namespace Murmur; diff --git a/src/murmur/Server.h b/src/murmur/Server.h index efa9ac938..70d487444 100644 --- a/src/murmur/Server.h +++ b/src/murmur/Server.h @@ -35,8 +35,8 @@ #include "Mumble.pb.h" #include "User.h" #include "Timer.h" -#include "Net.h" #include "HostAddress.h" +#include "Ban.h" class BonjourServer; class Channel; |