6 #include "validatordomain_p.h" 10 #include <QStringList> 20 :
ValidatorRule(*new ValidatorDomainPrivate(field, checkDNS, messages, defValKey))
38 bool hasRootDot =
false;
49 if (!nonAceParts.
empty()) {
56 for (
const QChar &ch : tld) {
57 const ushort &uc = ch.unicode();
58 if (((uc > 47) && (uc < 58)) || (uc == 45)) {
71 if (parts.
size() > 1) {
73 if (parts.
last().length() > 1) {
74 for (
int i = 0; i < parts.
size(); ++i) {
80 bool isTld = (i == (parts.
size() - 1));
82 for (
int j = 0; j < part.
size(); ++j) {
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) {
201 if (valid && extractedValue) {
219 error = c->
translate(
"Cutelyst::ValidatorDomain",
220 "The domain name seems to be valid but could not be found in the " 221 "domain name system.");
224 error = c->
translate(
"Cutelyst::ValidatorDomain",
225 "The domain name contains characters that are not allowed.");
229 c->
translate(
"Cutelyst::ValidatorDomain",
230 "At least one of the sections separated by dots exceeds the maximum " 231 "allowed length of 63 characters. Note that internationalized domain " 232 "names can be longer internally than they are displayed.");
236 "Cutelyst::ValidatorDomain",
237 "The full name of the domain must not be longer than 253 characters. Note that " 238 "internationalized domain names can be longer internally than they are displayed.");
241 error = c->
translate(
"Cutelyst::ValidatorDomain",
242 "This is not a valid domain name because it has either no parts " 243 "(is empty) or only has a top level domain.");
246 error = c->
translate(
"Cutelyst::ValidatorDomain",
247 "At least one of the sections separated by dots is empty. Check " 248 "whether you have entered two dots consecutively.");
251 error = c->
translate(
"Cutelyst::ValidatorDomain",
252 "The top level domain (last part) contains characters that are " 253 "not allowed, like digits and/or dashes.");
256 error = c->
translate(
"Cutelyst::ValidatorDomain",
257 "Domain name sections are not allowed to start with a dash.");
260 error = c->
translate(
"Cutelyst::ValidatorDomain",
261 "Domain name sections are not allowed to end with a dash.");
264 error = c->
translate(
"Cutelyst::ValidatorDomain",
265 "Domain name sections are not allowed to start with a digit.");
268 error = c->
translate(
"Cutelyst::ValidatorDomain",
"The domain name is valid.");
271 error = c->
translate(
"Cutelyst::ValidatorDomain",
272 "The DNS lookup was aborted because it took too long.");
275 Q_ASSERT_X(
false,
"domain validation diagnose",
"invalid diagnose");
281 error = c->
translate(
"Cutelyst::ValidatorDomain",
282 "The domain name in the “%1“ field seems to be valid but could " 283 "not be found in the domain name system.")
289 "Cutelyst::ValidatorDomain",
290 "The domain name in the “%1“ field contains characters that are not allowed.")
294 error = c->
translate(
"Cutelyst::ValidatorDomain",
295 "The domain name in the “%1“ field is not valid because at least " 296 "one of the sections separated by dots exceeds the maximum " 297 "allowed length of 63 characters. Note that internationalized " 298 "domain names can be longer internally than they are displayed.")
302 error = c->
translate(
"Cutelyst::ValidatorDomain",
303 "The full name of the domain in the “%1” field must not be longer " 304 "than 253 characters. Note that internationalized domain names " 305 "can be longer internally than they are displayed.")
309 error = c->
translate(
"Cutelyst::ValidatorDomain",
310 "The “%1” field does not contain a valid domain name because it " 311 "has either no parts (is empty) or only has a top level domain.")
315 error = c->
translate(
"Cutelyst::ValidatorDomain",
316 "The domain name in the “%1“ field is not valid because at least " 317 "one of the sections separated by dots is empty. Check whether " 318 "you have entered two dots consecutively.")
323 "Cutelyst::ValidatorDomain",
324 "The top level domain (last part) of the domain name in the “%1” field " 325 "contains characters that are not allowed, like digits and or dashes.")
329 error = c->
translate(
"Cutelyst::ValidatorDomain",
330 "The domain name in the “%1“ field is not valid because domain " 331 "name sections are not allowed to start with a dash.")
335 error = c->
translate(
"Cutelyst::ValidatorDomain",
336 "The domain name in the “%1“ field is not valid because domain " 337 "name sections are not allowed to end with a dash.")
341 error = c->
translate(
"Cutelyst::ValidatorDomain",
342 "The domain name in the “%1“ field is not valid because domain " 343 "name sections are not allowed to start with a digit.")
347 error = c->
translate(
"Cutelyst::ValidatorDomain",
348 "The domain name in the “%1” field is valid.")
352 error = c->
translate(
"Cutelyst::ValidatorDomain",
353 "The DNS lookup for the domain name in the “%1” field was aborted " 354 "because it took too long.")
358 Q_ASSERT_X(
false,
"domain validation diagnose",
"invalid diagnose");
397 #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.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
Stores custom error messages and the input field label.
const_reference at(qsizetype i) const const
qsizetype size() const const
qsizetype size() const const
int exec(ProcessEventsFlags flags)
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QByteArray toAce(const QString &domain, AceProcessingOptions options)
bool isEmpty() const const
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) 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.
QString toLower() const const
QList< QDnsHostAddressRecord > hostAddressRecords() const const
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.
QString fromLatin1(QByteArrayView str)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
const QChar at(qsizetype position) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
qsizetype length() const const
~ValidatorDomain() override
Deconstructs ValidatorDomain.
Contains the result of a single input parameter validation.
QString arg(Args &&... args) 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 ...
void setValue(QVariant &&value)