cutelyst 5.0.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
validatordomain.h
1/*
2 * SPDX-FileCopyrightText: (C) 2018-2025 Matthias Fehring <mf@huessenbergnetz.de>
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef CUTELYSTVALIDATORDOMAIN_H
7#define CUTELYSTVALIDATORDOMAIN_H
8
9#include "validatorrule.h"
10
11namespace Cutelyst {
12
13class ValidatorDomainPrivate;
14
41class CUTELYST_PLUGIN_UTILS_VALIDATOR_EXPORT ValidatorDomain : public ValidatorRule
42{
43 Q_GADGET
44public:
48 enum Diagnose : quint8 {
49 Valid = 0,
51 MissingDNS = 1,
53 InvalidChars = 2,
54 LabelTooLong =
55 3,
56 TooLong = 4,
57 InvalidLabelCount =
58 5,
59 EmptyLabel = 6,
60 InvalidTLD = 7,
61 DashStart = 8,
62 DashEnd = 9,
63 DigitStart = 10,
64 DNSTimeout = 11,
65 DNSError = 12
66 };
67 Q_ENUM(Diagnose)
68
69
73 enum Option {
74 NoOption = 0,
75 CheckARecord = 1,
76 CheckAAAARecord = 2,
77 CheckDNS = CheckARecord | CheckAAAARecord
79 };
80 Q_DECLARE_FLAGS(Options, Option)
81
82
92 explicit ValidatorDomain(const QString &field,
93 Options options = NoOption,
94 const ValidatorMessages &messages = {},
95 const QString &defValKey = {});
96
101
114 static bool validate(const QString &value,
115 Diagnose *diagnose = nullptr,
116 QString *extractedValue = nullptr);
117
127 static void
128 validateCb(const QString &value,
129 Options options,
130 std::function<void(Diagnose diagnose, const QString &extractedValue)> cb);
131
140 static QString diagnoseString(Context *c, Diagnose diagnose, const QString &label = {});
141
142protected:
149 ValidatorReturnType validate(Context *c, const ParamsMultiMap &params) const override;
150
160 void validateCb(Context *c, const ParamsMultiMap &params, ValidatorRtFn cb) const override;
161
167 QString genericValidationError(Context *c,
168 const QVariant &errorData = QVariant()) const override;
169
170private:
171 Q_DECLARE_PRIVATE(ValidatorDomain) // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
172 Q_DISABLE_COPY(ValidatorDomain)
173};
174
175} // namespace Cutelyst
176
177Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::ValidatorDomain::Options);
178
179#endif // CUTELYSTVALIDATORDOMAIN_H
The Cutelyst Context.
Definition context.h:42
Checks if the value of the input field contains a FQDN according to RFC 1035.
Option
Options for the domain validation.
Diagnose
Possible diagnose information for the checked domain.
Base class for all validator rules.
The Cutelyst namespace holds all public Cutelyst API.
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.