31 QString *extractedValue)
38 bool hasRootDot =
false;
39 if (_v.endsWith(u
'.')) {
45 const QString v = QString::fromLatin1(QUrl::toAce(_v)).toLower();
48 const QStringList nonAceParts = _v.split(QLatin1Char(
'.'));
49 if (!nonAceParts.empty()) {
50 const QString tld = nonAceParts.last();
56 for (
const QChar &ch : tld) {
57 const ushort &uc = ch.unicode();
58 if (((uc > 47) && (uc < 58)) || (uc == 45)) {
68 if (v.length() < 254) {
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()) {
79 if (part.length() < 64) {
80 bool isTld = (i == (parts.size() - 1));
81 bool isPunyCode = part.startsWith(u
"xn--");
82 for (
int j = 0; j < part.size(); ++j) {
83 const ushort &uc = part.at(j).unicode();
84 const bool isDigit = ((uc > 47) && (uc < 58));
85 const bool isDash = (uc == 45);
88 if ((j == 0) && (isDash || isDigit)) {
94 if ((j == (part.size() - 1)) && isDash) {
99 const bool isChar = ((uc > 96) && (uc < 123));
103 if (!(isDigit || isDash || isChar)) {
110 if (!(isDigit || isDash || isChar)) {
164 if (valid && checkDNS) {
165 QDnsLookup alookup(QDnsLookup::A, v);
167 QObject::connect(&alookup, &QDnsLookup::finished, &aloop, &QEventLoop::quit);
168 QTimer::singleShot(std::chrono::milliseconds{3100}, &alookup, &QDnsLookup::abort);
172 if (((alookup.error() != QDnsLookup::NoError) &&
173 (alookup.error() != QDnsLookup::OperationCancelledError)) ||
174 alookup.hostAddressRecords().empty()) {
175 QDnsLookup aaaaLookup(QDnsLookup::AAAA, v);
177 QObject::connect(&aaaaLookup, &QDnsLookup::finished, &aaaaLoop, &QEventLoop::quit);
178 QTimer::singleShot(std::chrono::milliseconds{3100}, &aaaaLookup, &QDnsLookup::abort);
182 if (((aaaaLookup.error() != QDnsLookup::NoError) &&
183 (aaaaLookup.error() != QDnsLookup::OperationCancelledError)) ||
184 aaaaLookup.hostAddressRecords().empty()) {
187 }
else if (aaaaLookup.error() == QDnsLookup::OperationCancelledError) {
191 }
else if (alookup.error() == QDnsLookup::OperationCancelledError) {
201 if (valid && extractedValue) {
203 *extractedValue = v + QLatin1Char(
'.');
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, 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())
Returns a human readable description of a Diagnose.
ValidatorDomain(const QString &field, bool checkDNS=false, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new ValidatorDomain with the given parameters.
~ValidatorDomain() override
Deconstructs ValidatorDomain.
Diagnose
Possible diagnose information for the checked domain.
void defaultValue(Context *c, ValidatorReturnType *result, const char *validatorName) const
I a defValKey has been set in the constructor, this will try to get the default value from the stash ...
static bool validate(const QString &value, bool checkDNS, Diagnose *diagnose=nullptr, QString *extractedValue=nullptr)
Returns true if value is a valid domain name.