feat(validation): add IValidationRule interface and implementations for port validation

This commit is contained in:
whaffman 2025-10-06 11:28:29 +02:00
parent abb832a380
commit fad0f6f5b4
5 changed files with 62 additions and 1 deletions

BIN
static_site/img/nginy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 KiB

View File

@ -170,7 +170,7 @@
<p><strong>Version:</strong> 1.0.0</p> <p><strong>Version:</strong> 1.0.0</p>
<p><strong>Started:</strong> <span id="timestamp"></span></p> <p><strong>Started:</strong> <span id="timestamp"></span></p>
</div> </div>
<img src="/images/nginy.jpg" alt="Nginx" <img src="/images/nginy.png" alt="Nginx"
style="display: block; margin: 2rem auto; max-width: 100%; border-radius: 15px; box-shadow: 0 8px 32px rgba(0,0,0,0.1);"> style="display: block; margin: 2rem auto; max-width: 100%; border-radius: 15px; box-shadow: 0 8px 32px rgba(0,0,0,0.1);">
<footer class="footer"> <footer class="footer">
<p>&copy; 2024 WebServ Project. Built with passion for web technologies.</p> <p>&copy; 2024 WebServ Project. Built with passion for web technologies.</p>

View File

@ -0,0 +1,21 @@
#pragma once
#include <string>
class ValidationResult;
class IValidationRule
{
public:
virtual ~IValidationRule() = default;
IValidationRule(const IValidationRule &other) = delete;
IValidationRule &operator=(const IValidationRule &other) = delete;
IValidationRule(IValidationRule &&other) noexcept = delete;
IValidationRule &operator=(IValidationRule &&other) noexcept = delete;
[[nodiscard]] virtual ValidationResult validate(const std::string &Adirective) const = 0;
[[nodiscard]] virtual std::string getRuleName() const = 0;
[[nodiscard]] virtual std::string getDescription() const = 0;
};

View File

@ -0,0 +1,18 @@
#pragma once
#include "webserv/config/config_validator/IValidationRule.hpp"
class PortValidationRule : public IValidationRule
{
public:
PortValidationRule() = default;
~PortValidationRule() override = default;
PortValidationRule(const PortValidationRule &other) = delete;
PortValidationRule &operator=(const PortValidationRule &other) = delete;
PortValidationRule(PortValidationRule &&other) noexcept = delete;
PortValidationRule &operator=(PortValidationRule &&other) noexcept = delete;
[[nodiscard]] ValidationResult validate(const std::string &value) const override;
[[nodiscard]] std::string getRuleName() const override { return "PortValidationRule"; }
[[nodiscard]] std::string getDescription() const override { return "Validates that a port number is between 1 and 65535"; }
};

View File

@ -0,0 +1,22 @@
#pragma once
#include <string>
class ValidationResult
{
public:
~ValidationResult() = default;
ValidationResult(const ValidationResult &other) = delete;
ValidationResult &operator=(const ValidationResult &other) = delete;
ValidationResult(ValidationResult &&other) noexcept = default;
ValidationResult &operator=(ValidationResult &&other) noexcept = default;
static ValidationResult success();
static ValidationResult error(const std::string &message);
private:
ValidationResult(bool isValid, std::string errorMessage = "");
bool isValid;
std::string errorMessage;
};