cutelyst 5.0.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
Cutelyst::ValidatorDomain Class Reference

Checks if the value of the input field contains a FQDN according to RFC 1035. More...

#include <Cutelyst/Plugins/Utils/validatordomain.h>

Inheritance diagram for Cutelyst::ValidatorDomain:

Public Types

enum  Diagnose : quint8 {
  Valid , MissingDNS , InvalidChars , LabelTooLong ,
  TooLong , InvalidLabelCount , EmptyLabel , InvalidTLD ,
  DashStart , DashEnd , DigitStart , DNSTimeout ,
  DNSError
}
 Possible diagnose information for the checked domain. More...
 
enum  Option { NoOption , CheckARecord , CheckAAAARecord , CheckDNS }
 Options for the domain validation. More...
 

Public Member Functions

 ValidatorDomain (const QString &field, Options options=NoOption, const ValidatorMessages &messages={}, const QString &defValKey={})
 Constructs a new ValidatorDomain object with the given parameters.
 
 ~ValidatorDomain () override
 
- Public Member Functions inherited from Cutelyst::ValidatorRule
 ValidatorRule (const QString &field, const ValidatorMessages &messages={}, const QString &defValKey={}, QByteArrayView validatorName=nullptr)
 
virtual ~ValidatorRule ()
 Deconstructs the ValidatorRule.
 

Static Public Member Functions

static QString diagnoseString (Context *c, Diagnose diagnose, const QString &label={})
 
static bool validate (const QString &value, Diagnose *diagnose=nullptr, QString *extractedValue=nullptr)
 Returns true if value is a valid fully qualified domain name.
 
static void validateCb (const QString &value, Options options, std::function< void(Diagnose diagnose, const QString &extractedValue)> cb)
 Checks if value is a vaid fully qualified domain name and writes the result to the callback cb.
 

Protected Member Functions

QString genericValidationError (Context *c, const QVariant &errorData=QVariant()) const override
 Returns a generic error message if validation failed.
 
ValidatorReturnType validate (Context *c, const ParamsMultiMap &params) const override
 
void validateCb (Context *c, const ParamsMultiMap &params, ValidatorRtFn cb) const override
 
- Protected Member Functions inherited from Cutelyst::ValidatorRule
 ValidatorRule (ValidatorRulePrivate &dd)
 
QString debugString (const Context *c) const
 
void defaultValue (Context *c, ValidatorReturnType *result) const
 
void defaultValue (Context *c, ValidatorRtFn cb) const
 
QString field () const noexcept
 
virtual QString genericParsingError (Context *c, const QVariant &errorData={}) const
 
virtual QString genericValidationDataError (Context *c, const QVariant &errorData={}) const
 
QString label (const Context *c) const
 
QString parsingError (Context *c, const QVariant &errorData={}) const
 
bool trimBefore () const noexcept
 
QString validationDataError (Context *c, const QVariant &errorData={}) const
 
QString validationError (Context *c, const QVariant &errorData={}) const
 
QString value (const ParamsMultiMap &params) const
 

Additional Inherited Members

Detailed Description

The field under validation must contain a fully qualified domain name according to RFC 1035. Internationalized domain names will first be converted into puny code according to IDNA. To also check if there are A and/or AAAA records published for the domain, use the CheckARecord, CheckAAAARecord or CheckDNS options, otherwise there will be no check if the domain is known to the domain name system and the validator will only check the conformance to RFC 1035. DNS lookups are only supported by the validateCb() methods.

Note
Unless validation is started with NoTrimming, whitespaces will be removed from the beginning and the end of the input value before validation. If the field's value is empty or if the field is missing in the input data, the validation will succeed without performing the validation itself. Use one of the required validators to require the field to be present and not empty.
Return type
On success, ValidatorReturnType::value will contain a QString with the ACE version of the domain name.
See also
Validator for general usage of validators.

Definition at line 41 of file validatordomain.h.

Member Enumeration Documentation

◆ Diagnose

Enumerator
Valid 

The domain name is valid. If checkDNS has been set to false, this says nothing about the existence of the domain in the DNS.

MissingDNS 

The domain name is valid according to RFC 1035, but there could be no DNS entry found for it.

InvalidChars 

The domain name contains chars that are not allowed.

LabelTooLong 

At least one of the domain name labels exceeds the maximum size of 63 chars.

TooLong 

The whole domain name exceeds the maximum size of 253 chars.

InvalidLabelCount 

Not a valid domain name because it has either no labels or only the TLD.

EmptyLabel 

At least one of the domain name labels is empty.

InvalidTLD 

The TLD label contains characters that are not allowed.

DashStart 

At least one label starts with a dash.

DashEnd 

At least one label ends with a dash.

DigitStart 

At least one label starts with a digit.

DNSTimeout 

The DNS lookup took too long.

DNSError 

Other DNS errors than timeouts or not existing domain (NXDOMAIN).

Definition at line 48 of file validatordomain.h.

◆ Option

Since
Cutelyst 5.0.0
Enumerator
NoOption 

No special option selected.

CheckARecord 

Check if there is an A record for the domain.

CheckAAAARecord 

Check if there is an AAAA record for the domain.

CheckDNS 

Check if there are bot, A and AAAA records for the domain.

Definition at line 73 of file validatordomain.h.

Constructor & Destructor Documentation

◆ ValidatorDomain()

ValidatorDomain::ValidatorDomain ( const QString field,
Options  options = NoOption,
const ValidatorMessages messages = {},
const QString defValKey = {} 
)
explicit
Since
Cutelyst 5.0.0
Parameters
fieldName of the input field to validate.
optionsOptions used for checking the domain. When checking DNS entries, it is highly recommended to use the validator in a coroutine context.
messagesCustom error messages if validation fails.
defValKeyStash key containing a default value if input field is empty. This value will NOT be validated.

Definition at line 17 of file validatordomain.cpp.

◆ ~ValidatorDomain()

ValidatorDomain::~ValidatorDomain ( )
overridedefault

Destroys the ValidatorDomain object.

Member Function Documentation

◆ diagnoseString()

QString ValidatorDomain::diagnoseString ( Context c,
Diagnose  diagnose,
const QString label = {} 
)
static

Returns a human readable description of a Diagnose.

Parameters
cCurrent Context, used for translations.
diagnoseThe Diagnose to get the description for.
labelOptinonal label that will be part of the diagnose string if not empty.
Returns
a human readable diagnose description.

Definition at line 252 of file validatordomain.cpp.

References QString::arg(), DashEnd, DashStart, DigitStart, DNSError, DNSTimeout, EmptyLabel, InvalidChars, InvalidLabelCount, InvalidTLD, QString::isEmpty(), Cutelyst::ValidatorRule::label(), LabelTooLong, MissingDNS, Cutelyst::Context::qtTrId(), TooLong, and Valid.

Referenced by genericValidationError().

◆ genericValidationError()

QString ValidatorDomain::genericValidationError ( Context c,
const QVariant errorData = QVariant() 
) const
overrideprotectedvirtual

errorData will contain the Diagnose returned by ValidatorDomain::validate().

Reimplemented from Cutelyst::ValidatorRule.

Definition at line 477 of file validatordomain.cpp.

References diagnoseString(), Cutelyst::ValidatorRule::label(), and QVariant::value().

◆ validate()

ValidatorReturnType ValidatorDomain::validate ( Context c,
const ParamsMultiMap params 
) const
overrideprotectedvirtual

Performs the validation on the input params and returns the result.

If validation succeeded, ValidatorReturnType::value will contain the input paramter value as ACE version of the domain in a QString.

Implements Cutelyst::ValidatorRule.

Definition at line 430 of file validatordomain.cpp.

References Cutelyst::ValidatorRule::debugString(), Cutelyst::ValidatorRule::defaultValue(), Cutelyst::ValidatorReturnType::errorMessage, QString::isEmpty(), QVariant::setValue(), Valid, validate(), Cutelyst::ValidatorRule::validationError(), Cutelyst::ValidatorReturnType::value, and Cutelyst::ValidatorRule::value().

◆ validateCb()

void ValidatorDomain::validateCb ( Context c,
const ParamsMultiMap params,
ValidatorRtFn  cb 
) const
overrideprotectedvirtual

Performs the validation on the input params and calls the cb with the ValidatorReturnType as argument.

If validation succeeded, ValidatorReturnType::value will contain the input parameter value as ACE version of the domain in a QString.

Since
Cutelyst 5.0.0

Reimplemented from Cutelyst::ValidatorRule.

Definition at line 455 of file validatordomain.cpp.

References QString::isEmpty(), validateCb(), Cutelyst::ValidatorRule::validationError(), and Cutelyst::ValidatorRule::value().