19 #include "validatordomain_p.h"
21 #include <QStringList>
26 using namespace Cutelyst;
29 ValidatorRule(* new ValidatorDomainPrivate(field, checkDNS, messages, defValKey))
44 bool hasRootDot =
false;
55 if (!nonAceParts.
empty()) {
62 for (
const QChar &ch : tld) {
63 const ushort &uc = ch.unicode();
64 if (((uc > 47) && (uc < 58)) || (uc == 45)) {
77 if (parts.
size() > 1) {
79 if (parts.
last().length() > 1) {
80 for (
int i = 0; i < parts.
size(); ++i) {
86 bool isTld = (i == (parts.
size() -1));
88 for (
int j = 0; j < part.
size(); ++j) {
90 const bool isDigit = ((uc > 47) && (uc < 58));
91 const bool isDash = (uc == 45);
93 if ((j == 0) && (isDash || isDigit)) {
99 if ((j == (part.
size() - 1)) && isDash) {
104 const bool isChar = ((uc > 96) && (uc < 123));
107 if (!(isDigit || isDash || isChar)) {
114 if (!(isDigit || isDash || isChar)) {
169 if (valid && checkDNS) {
177 if (((alookup.
error() != QDnsLookup::NoError) && (alookup.
error() != QDnsLookup::OperationCancelledError)) || alookup.
hostAddressRecords().empty()) {
185 if (((aaaaLookup.
error() != QDnsLookup::NoError) && (aaaaLookup.
error() != QDnsLookup::OperationCancelledError)) || aaaaLookup.
hostAddressRecords().empty()) {
188 }
else if (aaaaLookup.
error() == QDnsLookup::OperationCancelledError) {
192 }
else if (alookup.
error() == QDnsLookup::OperationCancelledError) {
202 if (valid && extractedValue) {
220 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The domain name seems to be valid but could not be found in the domain name system.");
223 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The domain name contains characters that are not allowed.");
226 error = c->
translate(
"Cutelyst::ValidatorDomain",
"At least one of the sections separated by dots exceeds the maximum allowed length of 63 characters. Note that internationalized domain names can be longer internally than they are displayed.");
229 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The full name of the domain must not be longer than 253 characters. Note that internationalized domain names can be longer internally than they are displayed.");
232 error = c->
translate(
"Cutelyst::ValidatorDomain",
"This is not a valid domain name because it has either no parts (is empty) or only has a top level domain.");
235 error = c->
translate(
"Cutelyst::ValidatorDomain",
"At least one of the sections separated by dots is empty. Check whether you have entered two dots consecutively.");
238 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The top level domain (last part) contains characters that are not allowed, like digits and/or dashes.");
241 error = c->
translate(
"Cutelyst::ValidatorDomain",
"Domain name sections are not allowed to start with a dash.");
244 error = c->
translate(
"Cutelyst::ValidatorDomain",
"Domain name sections are not allowed to end with a dash.");
247 error = c->
translate(
"Cutelyst::ValidatorDomain",
"Domain name sections are not allowed to start with a digit.");
250 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The domain name is valid.");
253 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The DNS lookup was aborted because it took too long.");
256 Q_ASSERT_X(
false,
"domain validation diagnose",
"invalid diagnose");
262 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The domain name in the “%1“ field seems to be valid but could not be found in the domain name system.").
arg(label);
265 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The domain name in the “%1“ field contains characters that are not allowed.").
arg(label);
268 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The domain name in the “%1“ field is not valid because at least one of the sections separated by dots exceeds the maximum allowed length of 63 characters. Note that internationalized domain names can be longer internally than they are displayed.").
arg(label);
271 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The full name of the domain in the “%1” field must not be longer than 253 characters. Note that internationalized domain names can be longer internally than they are displayed.").
arg(label);
274 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The “%1” field does not contain a valid domain name because it has either no parts (is empty) or only has a top level domain.").
arg(label);
277 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The domain name in the “%1“ field is not valid because at least one of the sections separated by dots is empty. Check whether you have entered two dots consecutively.").
arg(label);
280 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The top level domain (last part) of the domain name in the “%1” field contains characters that are not allowed, like digits and or dashes.").
arg(label);
283 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The domain name in the “%1“ field is not valid because domain name sections are not allowed to start with a dash.").
arg(label);
286 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The domain name in the “%1“ field is not valid because domain name sections are not allowed to end with a dash.").
arg(label);
289 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The domain name in the “%1“ field is not valid because domain name sections are not allowed to start with a digit.").
arg(label);
292 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The domain name in the “%1” field is valid.").
arg(label);
295 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The DNS lookup for the domain name in the “%1” field was aborted because it took too long.").
arg(label);
298 Q_ASSERT_X(
false,
"domain validation diagnose",
"invalid diagnose");
337 #include "moc_validatordomain.cpp"
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error message if validation failed.
Checks if the value of the input field contains FQDN according to RFC 1035.
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
Stores custom error messages and the input field label.
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
const T & at(int i) const
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
int exec(ProcessEventsFlags flags)
QByteArray toAce(const QString &domain)
QString validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
static QString diagnoseString(Context *c, Diagnose diagnose, const QString &label=QString())
Returns a human readable description of a Diagnose.
Base class for all validator rules.
Diagnose
Possible diagnose information for the checked domain.
ValidatorDomain(const QString &field, bool checkDNS=false, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new ValidatorDomain with the given parameters.
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 ...
QList< QDnsHostAddressRecord > hostAddressRecords() const
void setValue(const T &value)
static bool validate(const QString &value, bool checkDNS, Diagnose *diagnose=nullptr, QString *extractedValue=nullptr)
Returns true if value is a valid domain name.
const QChar at(int position) const
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
QString fromLatin1(const char *str, int size)
~ValidatorDomain() override
Deconstructs ValidatorDomain.
Contains the result of a single input parameter validation.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const