feat(validation): add IValidationRule interface and implementations for port validation
This commit is contained in:
parent
abb832a380
commit
fad0f6f5b4
BIN
static_site/img/nginy.png
Normal file
BIN
static_site/img/nginy.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 151 KiB |
@ -170,7 +170,7 @@
|
||||
<p><strong>Version:</strong> 1.0.0</p>
|
||||
<p><strong>Started:</strong> <span id="timestamp"></span></p>
|
||||
</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);">
|
||||
<footer class="footer">
|
||||
<p>© 2024 WebServ Project. Built with passion for web technologies.</p>
|
||||
|
||||
21
webserv/config/config_validator/IValidationRule.hpp
Normal file
21
webserv/config/config_validator/IValidationRule.hpp
Normal 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;
|
||||
|
||||
};
|
||||
18
webserv/config/config_validator/PortValidationRule.hpp
Normal file
18
webserv/config/config_validator/PortValidationRule.hpp
Normal 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"; }
|
||||
};
|
||||
22
webserv/config/config_validator/ValidationResult.hpp
Normal file
22
webserv/config/config_validator/ValidationResult.hpp
Normal 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;
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user