-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdns.cc
91 lines (75 loc) · 2.63 KB
/
dns.cc
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
#include "dns.h"
#include "dns_system.h"
#include "dns_https_get.h"
#include "dns_https_post.h"
#include "dns_dot.h"
#include "dns_udp.h"
#include <QDnsLookup>
#include <QTimer>
DnsImplementation::DnsImplementation(QObject *parent) : QObject(parent) {
}
BadImplementation::BadImplementation(const QString &error, QObject *parent) : DnsImplementation(parent), errorString(error) {
}
void BadImplementation::lookup() {
QTimer::singleShot(0, this, &BadImplementation::finished);
}
DnsLookup::DnsLookup(const QString &queryType, const QString &name, const QString resolver, QObject *parent) : QObject(parent){
ushort type=0;
QString typeName = queryType.toUpper().trimmed();
if (typeName == "A") {
type = QDnsLookup::A;
} else if (typeName == "AAAA") {
type = QDnsLookup::AAAA;
} else if (typeName == "CNAME") {
type = QDnsLookup::CNAME;
} else if (typeName == "MX") {
type = QDnsLookup::MX;
} else if (typeName == "NS") {
type = QDnsLookup::NS;
} else if (typeName == "PTR") {
type = QDnsLookup::PTR;
} else if (typeName == "SRV") {
type = QDnsLookup::SRV;
} else if (typeName == "TXT") {
type = QDnsLookup::TXT;
} else {
type = typeName.toUShort();
}
if (type == 0) {
q = new BadImplementation(tr("Bad query type: %1").arg(queryType));
} else {
if (resolver == "system") {
q = new SystemImplementation(type, name, this);
} else if (resolver.startsWith("https:")) {
if (resolver.contains("{")) {
q = new DohGetImplementation(type, name, resolver, this);
} else {
q = new DohPostImplementation(type, name, resolver, this);
}
} else if (resolver.startsWith("dot:")) {
q = new DotImplementation(type, name, resolver, this);
} else if (resolver.startsWith("udp:")) {
q = new UdpImplementation(type, name,resolver, this);
} else {
QUrl u = QUrl::fromUserInput(resolver);
if (u.isValid()) {
q = new UdpImplementation(type, name, "udp://" + u.host() + ":" + QString::number(u.port(53)));
} else {
q = new BadImplementation(tr("Bad resolver: %1").arg(resolver));
}
}
}
connect(q, &DnsImplementation::finished, this, &DnsLookup::finished);
}
void DnsLookup::lookup() {
q->lookup();
}
QString DnsLookup::ErrorString() const {
return q->ErrorString();
}
QList<QHostAddress> DnsLookup::Addresses() const {
return q->Addresses();
}
QString DnsLookup::PrettyResults() {
return q->PrettyResults();
}