1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
// Copyright 2005-2019 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 "ServerResolver.h"
#include <QtNetwork/QHostInfo>
class ServerResolverPrivate : public QObject {
private:
Q_OBJECT
Q_DISABLE_COPY(ServerResolverPrivate)
public:
ServerResolverPrivate(QObject *parent);
void resolve(QString hostname, quint16 port);
QList<ServerResolverRecord> records();
QString m_origHostname;
quint16 m_origPort;
QList<ServerResolverRecord> m_resolved;
signals:
void resolved();
public slots:
void hostResolved(QHostInfo hostInfo);
};
ServerResolverPrivate::ServerResolverPrivate(QObject *parent)
: QObject(parent)
, m_origPort(0) {
}
void ServerResolverPrivate::resolve(QString hostname, quint16 port) {
m_origHostname = hostname;
m_origPort = port;
QHostInfo::lookupHost(hostname, this, SLOT(hostResolved(QHostInfo)));
}
QList<ServerResolverRecord> ServerResolverPrivate::records() {
return m_resolved;
}
void ServerResolverPrivate::hostResolved(QHostInfo hostInfo) {
if (hostInfo.error() == QHostInfo::NoError) {
QList<QHostAddress> resolvedAddresses = hostInfo.addresses();
// Convert QHostAddress -> HostAddress.
QList<HostAddress> addresses;
foreach (QHostAddress ha, resolvedAddresses) {
addresses << HostAddress(ha);
}
m_resolved << ServerResolverRecord(m_origHostname, m_origPort, 0, addresses);
}
emit resolved();
}
ServerResolver::ServerResolver(QObject *parent)
: QObject(parent) {
d = new ServerResolverPrivate(this);
}
QString ServerResolver::hostname() {
if (d) {
return d->m_origHostname;
}
return QString();
}
quint16 ServerResolver::port() {
if (d) {
return d->m_origPort;
}
return 0;
}
void ServerResolver::resolve(QString hostname, quint16 port) {
if (d) {
connect(d, SIGNAL(resolved()), this, SIGNAL(resolved()));
d->resolve(hostname, port);
}
}
QList<ServerResolverRecord> ServerResolver::records() {
if (d) {
return d->records();
}
return QList<ServerResolverRecord>();
}
#include "ServerResolver_nosrv.moc"
|