cutelyst  4.5.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
validatorip.h
1 /*
2  * SPDX-FileCopyrightText: (C) 2017-2023 Matthias Fehring <mf@huessenbergnetz.de>
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 #ifndef CUTELYSTVALIDATORIP_H
6 #define CUTELYSTVALIDATORIP_H
7 
8 #include "validatorrule.h"
9 
10 namespace Cutelyst {
11 
12 class ValidatorIpPrivate;
13 
34 class CUTELYST_PLUGIN_UTILS_VALIDATOR_EXPORT ValidatorIp : public ValidatorRule
35 {
36 public:
40  enum Constraint {
41  NoConstraint = 0,
42  IPv4Only = 1,
43  IPv6Only = 2,
44  NoPrivateRange = 4,
46  NoReservedRange = 8,
48  NoMultiCast = 16,
49  PublicOnly = 32
50  };
51  Q_DECLARE_FLAGS(Constraints, Constraint)
52 
53 
62  ValidatorIp(const QString &field,
63  Constraints constraints = NoConstraint,
64  const ValidatorMessages &messages = ValidatorMessages(),
65  const QString &defValKey = QString());
66 
70  ~ValidatorIp() override;
71 
79  static bool validate(const QString &value, Constraints constraints = NoConstraint);
80 
81 protected:
88  ValidatorReturnType validate(Context *c, const ParamsMultiMap &params) const override;
89 
93  QString genericValidationError(Context *c,
94  const QVariant &errorData = QVariant()) const override;
95 
96 private:
97  Q_DECLARE_PRIVATE(ValidatorIp) // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
98  Q_DISABLE_COPY(ValidatorIp)
99 };
100 
101 } // namespace Cutelyst
102 
103 Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::ValidatorIp::Constraints)
104 
105 #endif // CUTELYSTVALIDATORIP_H
The Cutelyst Context.
Definition: context.h:42
Checks if the field value is a valid IP address.
Definition: validatorip.h:35
Constraint
Acceptable address ranges.
Definition: validatorip.h:40
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.
Definition: validatorrule.h:49