1 // Copyright 2005-2019 The Mumble Developers. All rights reserved.
2 // Use of this source code is governed by a BSD-style license
3 // that can be found in the LICENSE file at the root of the
4 // Mumble source tree or at <https://www.mumble.info/LICENSE>.
5
6 #ifdef MUMBLE
7 #include "mumble_pch.hpp"
8 #else
9 #include "murmur_pch.h"
10 #endif
11
12 #include "Ban.h"
13
isExpired() const14 bool Ban::isExpired() const {
15 return (iDuration > 0) && static_cast<int>(iDuration - qdtStart.secsTo(QDateTime::currentDateTime().toUTC())) < 0;
16 }
17
operator <(const Ban & other) const18 bool Ban::operator <(const Ban &other) const {
19 // Compare username primarily and address secondarily
20 const int unameDifference = qsUsername.localeAwareCompare(other.qsUsername);
21 if (unameDifference == 0)
22 return haAddress < other.haAddress;
23 else
24 return unameDifference < 0;
25 }
26
operator ==(const Ban & other) const27 bool Ban::operator ==(const Ban &other) const {
28 return (haAddress == other.haAddress)
29 && (iMask == other.iMask)
30 && (qsUsername == other.qsUsername)
31 && (qsHash == other.qsHash)
32 && (qsReason == other.qsReason)
33 && (qdtStart == other.qdtStart)
34 && (iDuration == other.iDuration);
35 }
36
isValid() const37 bool Ban::isValid() const {
38 return haAddress.isValid() && (iMask >= 8) && (iMask <= 128);
39 }
40
toString() const41 QString Ban::toString() const {
42 return QString(QLatin1String("Hash: \"%1\", Host: \"%2\", Mask: \"%3\", Username: \"%4\", Reason: \"%5\", BanStart: \"%6\", BanEnd: \"%7\" %8")).arg(
43 qsHash,
44 haAddress.toString(),
45 haAddress.isV6() ? QString::number(iMask) : QString::number(iMask-96),
46 qsUsername,
47 qsReason,
48 qdtStart.toLocalTime().toString(QLatin1String("yyyy-MM-dd hh:mm:ss")),
49 qdtStart.toLocalTime().addSecs(iDuration).toString(QLatin1String("yyyy-MM-dd hh:mm:ss")),
50 iDuration == 0 ? QLatin1String("(permanent)") : QLatin1String("(temporary)")
51 );
52 }
53
qHash(const Ban & b)54 quint32 qHash(const Ban &b) {
55 return qHash(b.qsHash) ^ qHash(b.haAddress) ^ qHash(b.qsUsername) ^ qHash(b.iMask);
56 }
57