refactor: has and owns
This commit is contained in:
parent
9aaa085098
commit
f222cce4ff
@ -1,5 +1,4 @@
|
||||
#include <webserv/config/AConfig.hpp> // for AConfig
|
||||
|
||||
#include <webserv/config/directive/ADirective.hpp> // for ADirective
|
||||
#include <webserv/config/directive/DirectiveFactory.hpp> // for DirectiveFactory
|
||||
#include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValue
|
||||
@ -47,7 +46,21 @@ std::vector<const ADirective *> AConfig::getDirectives() const
|
||||
return result;
|
||||
}
|
||||
|
||||
bool AConfig::hasDirective(const std::string &name) const
|
||||
bool AConfig::has(const std::string &name) const
|
||||
{
|
||||
if (owns(name))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (parent_ != nullptr)
|
||||
{
|
||||
return parent_->has(name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AConfig::owns(const std::string &name) const
|
||||
{
|
||||
for (const auto &directive : directives_)
|
||||
{
|
||||
@ -56,10 +69,7 @@ bool AConfig::hasDirective(const std::string &name) const
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (parent_ != nullptr)
|
||||
{
|
||||
return parent_->hasDirective(name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -24,7 +24,9 @@ class AConfig
|
||||
void addDirective(const std::string &line);
|
||||
[[nodiscard]] std::string getErrorPage(int statusCode) const;
|
||||
|
||||
[[nodiscard]] bool hasDirective(const std::string &name) const;
|
||||
[[nodiscard]] bool has(const std::string &name) const;
|
||||
[[nodiscard]] bool owns(const std::string &name) const;
|
||||
|
||||
[[nodiscard]] const ADirective *getDirective(const std::string &name) const;
|
||||
[[nodiscard]] std::vector<const ADirective *> getDirectives() const;
|
||||
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
#include <webserv/config/validation/ValidationEngine.hpp>
|
||||
|
||||
#include <webserv/config/AConfig.hpp> // for AConfig
|
||||
#include <webserv/config/GlobalConfig.hpp> // for GlobalConfig
|
||||
#include <webserv/config/LocationConfig.hpp> // for LocationConfig
|
||||
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
|
||||
#include <webserv/config/validation/ValidationEngine.hpp>
|
||||
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
|
||||
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
|
||||
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
||||
@ -92,7 +91,7 @@ void ValidationEngine::validateConfig(RuleMap const &rulesMap, const AConfig *co
|
||||
Log::trace(LOCATION);
|
||||
for (const auto &[directiveName, rules] : rulesMap)
|
||||
{
|
||||
if (!config->hasDirective(directiveName))
|
||||
if (!config->has(directiveName))
|
||||
{
|
||||
// Check if any rule requires the directive
|
||||
for (const auto &rule : rules)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user