Cutelyst  2.3.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
Cutelyst::ValidatorDomain Class Reference

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

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

Inheritance diagram for Cutelyst::ValidatorDomain:
Inheritance graph
[legend]

Public Types

enum  Diagnose : quint8 {
  Valid, MissingDNS, InvalidChars, LabelTooLong,
  TooLong, InvalidLabelCount, EmptyLabel, InvalidTLD,
  DashStart, DashEnd, DigitStart, DNSTimeout
}
 Possible diagnose information for the checked domain. More...
 

Public Member Functions

 ValidatorDomain (const QString &field, bool checkDNS=false, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
 Constructs a new ValidatorDomain with the given parameters. More...
 
 ~ValidatorDomain ()
 Deconstructs ValidatorDomain.
 
- Public Member Functions inherited from Cutelyst::ValidatorRule
 ValidatorRule (const QString &field, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
 Constructs a new ValidatorRule with the given parameters. More...
 
 ~ValidatorRule ()
 Deconstructs the ValidatorRule.
 

Static Public Member Functions

static QString diagnoseString (Context *c, Diagnose diagnose, const QString &label=QString())
 Returns a human readable description of a Diagnose. More...
 
static bool validate (const QString &value, bool checkDNS, Diagnose *diagnose=nullptr, QString *extractedValue=nullptr)
 Returns true if value is a valid domain name. More...
 

Protected Member Functions

QString genericValidationError (Context *c, const QVariant &errorData=QVariant()) const override
 Returns a generic error message if validation failed. More...
 
ValidatorReturnType validate (Context *c, const ParamsMultiMap &params) const override
 Performs the validation and returns the result. More...
 
- Protected Member Functions inherited from Cutelyst::ValidatorRule
 ValidatorRule (ValidatorRulePrivate &dd)
 Constructs a new ValidatorRule object with the given private class. More...
 
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 and put it into the result. More...
 
QString field () const
 Returns the name of the field to validate. More...
 
virtual QString genericParsingError (Context *c, const QVariant &errorData=QVariant()) const
 Returns a generic error message if an error occures while parsing input. More...
 
virtual QString genericValidationDataError (Context *c, const QVariant &errorData=QVariant()) const
 Returns a generic error message if any validation data is missing or invalid. More...
 
QString label (Context *c) const
 Returns the human readable field label used for generic error messages. More...
 
QString parsingError (Context *c, const QVariant &errorData=QVariant()) const
 Returns an error message if an error occured while parsing input. More...
 
bool trimBefore () const
 Returns true if the field value should be trimmed before validation. More...
 
QString validationDataError (Context *c, const QVariant &errorData=QVariant()) const
 Returns an error message if any validation data is missing or invalid. More...
 
QString validationError (Context *c, const QVariant &errorData=QVariant()) const
 Returns a descriptive error message if validation failed. More...
 
QString value (const ParamsMultiMap &params) const
 Returns the value of the field from the input params.
 

Detailed Description

The field under validation must contain a fully qualified domain name according to RFC 1035. If checkDNS is set to false, there will be no check if the domain is known to the domain name system, the validator will only check conformance to RFC 1035. Internationalized domain names will first be converted into puny code according to IDNA.

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.
See also
Validator for general usage of validators.

Definition at line 46 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.

Definition at line 53 of file validatordomain.h.

Constructor & Destructor Documentation

◆ ValidatorDomain()

ValidatorDomain::ValidatorDomain ( const QString &  field,
bool  checkDNS = false,
const ValidatorMessages messages = ValidatorMessages(),
const QString &  defValKey = QString() 
)
Parameters
fieldName of the input field to validate.
checkDNSIf true, a DNS lookup will be performed to check if the domain name exists in the domain name system.
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 28 of file validatordomain.cpp.

Member Function Documentation

◆ diagnoseString()

QString ValidatorDomain::diagnoseString ( Context c,
Diagnose  diagnose,
const QString &  label = QString() 
)
static
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 213 of file validatordomain.cpp.

References DashEnd, DashStart, DigitStart, DNSTimeout, EmptyLabel, InvalidChars, InvalidLabelCount, InvalidTLD, LabelTooLong, MissingDNS, TooLong, Cutelyst::Context::translate(), 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 328 of file validatordomain.cpp.

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

◆ validate()

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