6 #include "validatorip_p.h"
10 #include <QHostAddress>
15 u
"^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$"_qs};
18 Constraints constraints,
21 :
ValidatorRule(*new ValidatorIpPrivate(field, constraints, messages, defValKey))
41 qCDebug(C_VALIDATOR).noquote() <<
"Not a valid IP address";
64 static const std::vector<std::pair<QHostAddress, int>> ipv4Private(
83 static const std::vector<std::pair<QHostAddress, int>> ipv4Reserved(
126 {
QHostAddress(QStringLiteral(
"255.255.255.255")), 32}});
129 static const std::vector<std::pair<QHostAddress, int>> ipv6Private(
137 static const std::vector<std::pair<QHostAddress, int>> ipv6Reserved(
172 if (a.setAddress(
value)) {
178 if (constraints.testFlag(
IPv6Only)) {
185 for (
const std::pair<QHostAddress, int> &subnet : ipv4Private) {
186 if (a.isInSubnet(subnet.first, subnet.second)) {
196 for (
const std::pair<QHostAddress, int> &subnet : ipv4Reserved) {
197 if (a.isInSubnet(subnet.first, subnet.second)) {
206 if (a.isInSubnet(
QHostAddress(QStringLiteral(
"224.0.0.0")), 4)) {
213 if (constraints.testFlag(
IPv4Only)) {
220 for (
const std::pair<QHostAddress, int> &subnet : ipv6Private) {
221 if (a.isInSubnet(subnet.first, subnet.second)) {
231 for (
const std::pair<QHostAddress, int> &subnet : ipv6Reserved) {
232 if (a.isInSubnet(subnet.first, subnet.second)) {
241 if (a.isInSubnet(
QHostAddress(QStringLiteral(
"ff00::")), 8)) {
262 return c->
qtTrId(
"cutelyst-valip-genvalerr");
266 return c->
qtTrId(
"cutelyst-valip-genvalerr-label").
arg(_label);
QString qtTrId(const char *id, int n=-1) const
Checks if the field value is a valid IP address.
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
ValidatorIp(const QString &field, Constraints constraints=NoConstraint, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Base class for all validator rules.
QString validationError(Context *c, const QVariant &errorData={}) const
QString label(Context *c) const
void defaultValue(Context *c, ValidatorReturnType *result) const
QString value(const ParamsMultiMap ¶ms) const
static bool validate(const QString &value, Constraints constraints=NoConstraint)
Returns true if value is a valid IP address within the constraints.
The Cutelyst namespace holds all public Cutelyst API.
QString arg(Args &&... args) const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
void setValue(QVariant &&value)
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.