6 #include "validatordomain_p.h" 16 ValidatorRule(* new ValidatorDomainPrivate(field, checkDNS, messages, defValKey))
31 bool hasRootDot =
false;
42 if (!nonAceParts.
empty()) {
49 for (
const QChar &ch : tld) {
50 const ushort &uc = ch.unicode();
51 if (((uc > 47) && (uc < 58)) || (uc == 45)) {
62 #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) 68 if (parts.
size() > 1) {
70 if (parts.
last().length() > 1) {
71 for (
int i = 0; i < parts.
size(); ++i) {
77 bool isTld = (i == (parts.
size() -1));
79 for (
int j = 0; j < part.
size(); ++j) {
81 const bool isDigit = ((uc > 47) && (uc < 58));
82 const bool isDash = (uc == 45);
84 if ((j == 0) && (isDash || isDigit)) {
90 if ((j == (part.
size() - 1)) && isDash) {
95 const bool isChar = ((uc > 96) && (uc < 123));
98 if (!(isDigit || isDash || isChar)) {
105 if (!(isDigit || isDash || isChar)) {
160 if (valid && checkDNS) {
168 if (((alookup.
error() != QDnsLookup::NoError) && (alookup.
error() != QDnsLookup::OperationCancelledError)) || alookup.
hostAddressRecords().empty()) {
176 if (((aaaaLookup.
error() != QDnsLookup::NoError) && (aaaaLookup.
error() != QDnsLookup::OperationCancelledError)) || aaaaLookup.
hostAddressRecords().empty()) {
179 }
else if (aaaaLookup.
error() == QDnsLookup::OperationCancelledError) {
183 }
else if (alookup.
error() == QDnsLookup::OperationCancelledError) {
193 if (valid && extractedValue) {
211 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The domain name seems to be valid but could not be found in the domain name system.");
214 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The domain name contains characters that are not allowed.");
217 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.");
220 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.");
223 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.");
226 error = c->
translate(
"Cutelyst::ValidatorDomain",
"At least one of the sections separated by dots is empty. Check whether you have entered two dots consecutively.");
229 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The top level domain (last part) contains characters that are not allowed, like digits and/or dashes.");
232 error = c->
translate(
"Cutelyst::ValidatorDomain",
"Domain name sections are not allowed to start with a dash.");
235 error = c->
translate(
"Cutelyst::ValidatorDomain",
"Domain name sections are not allowed to end with a dash.");
238 error = c->
translate(
"Cutelyst::ValidatorDomain",
"Domain name sections are not allowed to start with a digit.");
241 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The domain name is valid.");
244 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The DNS lookup was aborted because it took too long.");
247 Q_ASSERT_X(
false,
"domain validation diagnose",
"invalid diagnose");
253 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);
256 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The domain name in the “%1“ field contains characters that are not allowed.").
arg(
label);
259 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);
262 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);
265 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);
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 is empty. Check whether you have entered two dots consecutively.").
arg(
label);
271 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);
274 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);
277 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);
280 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);
283 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The domain name in the “%1” field is valid.").
arg(
label);
286 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);
289 Q_ASSERT_X(
false,
"domain validation diagnose",
"invalid diagnose");
328 #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 validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
Stores custom error messages and the input field label.
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
const T & at(int i) const const
int exec(QEventLoop::ProcessEventsFlags flags)
QByteArray toAce(const QString &domain)
bool isEmpty() const const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const const
The Cutelyst namespace holds all public Cutelyst API.
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.
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
ValidatorDomain(const QString &field, bool checkDNS=false, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new ValidatorDomain with the given parameters.
ushort unicode() const const
QString toLower() const const
QList< QDnsHostAddressRecord > hostAddressRecords() const const
void setValue(const T &value)
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
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 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 const
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 ...