29 QString *extractedValue)
36 bool hasRootDot =
false;
37 if (_v.endsWith(u
'.')) {
43 const QString v = QString::fromLatin1(QUrl::toAce(_v)).toLower();
46 const QStringList nonAceParts = _v.split(QLatin1Char(
'.'));
47 if (!nonAceParts.empty()) {
48 const QString tld = nonAceParts.last();
54 for (
const QChar &ch : tld) {
55 const ushort &uc = ch.unicode();
56 if (((uc >= ValidatorRulePrivate::ascii_0) &&
57 (uc <= ValidatorRulePrivate::ascii_9)) ||
58 (uc == ValidatorRulePrivate::ascii_dash)) {
68 if (v.length() <= ValidatorDomainPrivate::maxDnsNameWithLastDot) {
69 const QStringList parts = v.split(QLatin1Char(
'.'), Qt::KeepEmptyParts);
71 if (parts.size() > 1) {
73 if (parts.last().length() > 1) {
74 for (
int i = 0; i < parts.size(); ++i) {
76 const QString &part = parts.at(i);
77 if (!part.isEmpty()) {
80 ValidatorDomainPrivate::maxDnsLabelLength) {
81 bool isTld = (i == (parts.size() - 1));
82 bool isPunyCode = part.startsWith(u
"xn--");
83 for (
int j = 0; j < part.size(); ++j) {
84 const ushort &uc = part.at(j).unicode();
86 ((uc >= ValidatorRulePrivate::ascii_0) &&
87 (uc <= ValidatorRulePrivate::ascii_9));
89 (uc == ValidatorRulePrivate::ascii_dash);
92 if ((j == 0) && (isDash || isDigit)) {
98 if ((j == (part.size() - 1)) && isDash) {
104 ((uc >= ValidatorRulePrivate::ascii_a) &&
105 (uc <= ValidatorRulePrivate::ascii_z));
109 if (!(isDigit || isDash || isChar)) {
116 if (!(isDigit || isDash || isChar)) {
170 if (valid && checkDNS) {
171 QDnsLookup alookup(QDnsLookup::A, v);
173 QObject::connect(&alookup, &QDnsLookup::finished, &aloop, &QEventLoop::quit);
174 QTimer::singleShot(ValidatorDomainPrivate::dnsLookupTimeout, &alookup, &QDnsLookup::abort);
178 if (((alookup.error() != QDnsLookup::NoError) &&
179 (alookup.error() != QDnsLookup::OperationCancelledError)) ||
180 alookup.hostAddressRecords().empty()) {
181 QDnsLookup aaaaLookup(QDnsLookup::AAAA, v);
183 QObject::connect(&aaaaLookup, &QDnsLookup::finished, &aaaaLoop, &QEventLoop::quit);
185 ValidatorDomainPrivate::dnsLookupTimeout, &aaaaLookup, &QDnsLookup::abort);
189 if (((aaaaLookup.error() != QDnsLookup::NoError) &&
190 (aaaaLookup.error() != QDnsLookup::OperationCancelledError)) ||
191 aaaaLookup.hostAddressRecords().empty()) {
194 }
else if (aaaaLookup.error() == QDnsLookup::OperationCancelledError) {
198 }
else if (alookup.error() == QDnsLookup::OperationCancelledError) {
208 if (valid && extractedValue) {
210 *extractedValue = v + QLatin1Char(
'.');
336 const QString &v =
value(params);
343 result.
value.setValue(exVal);
346 if (C_VALIDATOR().isDebugEnabled()) {
351 qCDebug(C_VALIDATOR).noquote()
352 <<
debugString(c) <<
"Can not find valid DNS entry for" << v;
355 qCDebug(C_VALIDATOR).noquote()
357 <<
"The domain name contains characters that are not allowed";
360 qCDebug(C_VALIDATOR).noquote()
362 <<
"At least on of the domain name labels exceeds the maximum" <<
"size of"
363 << ValidatorDomainPrivate::maxDnsLabelLength <<
"characters";
366 qCDebug(C_VALIDATOR).noquote()
367 <<
debugString(c) <<
"The domain name exceeds the maximum size of"
368 << ValidatorDomainPrivate::maxDnsNameWithLastDot <<
"characters";
371 qCDebug(C_VALIDATOR).noquote()
372 <<
debugString(c) <<
"Invalid label count. Either no labels or only TLD";
375 qCDebug(C_VALIDATOR).noquote()
376 <<
debugString(c) <<
"At least one of the domain name labels is empty";
379 qCDebug(C_VALIDATOR).noquote()
381 <<
"The TLD label contains characters that are not allowed";
384 qCDebug(C_VALIDATOR).noquote()
385 <<
debugString(c) <<
"At least one label starts with a dash";
388 qCDebug(C_VALIDATOR).noquote()
389 <<
debugString(c) <<
"At least one label ends with a dash";
392 qCDebug(C_VALIDATOR).noquote()
393 <<
debugString(c) <<
"At least one label starts with a digit";
396 qCDebug(C_VALIDATOR).noquote()
397 <<
debugString(c) <<
"The DNS lookup exceeds the timeout of"
398#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
399 << ValidatorDomainPrivate::dnsLookupTimeout;
401 << ValidatorDomainPrivate::dnsLookupTimeout.count() <<
"milliseconds";
QString qtTrId(const char *id, int n=-1) const
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error message if validation failed.
static QString diagnoseString(Context *c, Diagnose diagnose, const QString &label=QString())
ValidatorDomain(const QString &field, bool checkDNS=false, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new ValidatorDomain object with the given parameters.
~ValidatorDomain() override
Diagnose
Possible diagnose information for the checked domain.