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 "UnresolvedServerAddress.h"
13
UnresolvedServerAddress()14 UnresolvedServerAddress::UnresolvedServerAddress()
15 : port(0) {}
16
UnresolvedServerAddress(QString hostname_,unsigned short port_)17 UnresolvedServerAddress::UnresolvedServerAddress(QString hostname_, unsigned short port_)
18 : hostname(hostname_.toLower())
19 , port(port_) {}
20
isValid() const21 bool UnresolvedServerAddress::isValid() const {
22 return !hostname.isEmpty() && port != 0;
23 }
24
operator ==(const UnresolvedServerAddress & lhs,const UnresolvedServerAddress & rhs)25 bool operator==(const UnresolvedServerAddress &lhs, const UnresolvedServerAddress &rhs) {
26 return lhs.hostname == rhs.hostname && lhs.port == rhs.port;
27 }
28
operator !=(const UnresolvedServerAddress & lhs,const UnresolvedServerAddress & rhs)29 bool operator!=(const UnresolvedServerAddress &lhs, const UnresolvedServerAddress &rhs) {
30 return !operator==(lhs, rhs);
31 }
32
operator <(const UnresolvedServerAddress & lhs,const UnresolvedServerAddress & rhs)33 bool operator<(const UnresolvedServerAddress &lhs, const UnresolvedServerAddress &rhs) {
34 if (lhs.hostname < rhs.hostname) {
35 return true;
36 }
37 if (lhs.hostname == rhs.hostname) {
38 if (lhs.port < rhs.port) {
39 return true;
40 }
41 }
42 return false;
43 }
44
qHash(const UnresolvedServerAddress & key)45 uint qHash(const UnresolvedServerAddress &key) {
46 return qHash(key.hostname) ^ uint(key.port);
47 }
48