moving some files and fixing includes
This commit is contained in:
parent
95753eea34
commit
010ee3e8b6
@ -1,20 +1,18 @@
|
|||||||
#include "webserv/router/Router.hpp"
|
|
||||||
|
|
||||||
#include <webserv/client/Client.hpp>
|
#include <webserv/client/Client.hpp>
|
||||||
#include <webserv/config/ConfigManager.hpp>
|
|
||||||
#include <webserv/config/ServerConfig.hpp>
|
|
||||||
#include <webserv/handler/ErrorHandler.hpp>
|
|
||||||
#include <webserv/http/HttpHeaders.hpp>
|
|
||||||
#include <webserv/log/Log.hpp>
|
|
||||||
#include <webserv/server/Server.hpp>
|
|
||||||
#include <webserv/socket/Socket.hpp>
|
|
||||||
|
|
||||||
#include <cstdint>
|
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
|
||||||
#include <functional>
|
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
||||||
#include <map>
|
#include <webserv/router/Router.hpp> // for Router
|
||||||
#include <utility>
|
#include <webserv/server/Server.hpp> // for Server
|
||||||
|
#include <webserv/socket/Socket.hpp> // for Socket
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <cstdint> // for uint8_t
|
||||||
|
#include <functional> // for ref, reference_wrapper
|
||||||
|
#include <map> // for map
|
||||||
|
#include <string> // for basic_string, to_string, operator+, operator<=>
|
||||||
|
#include <utility> // for pair, move
|
||||||
|
|
||||||
|
#include <sys/types.h> // for ssize_t
|
||||||
|
|
||||||
Client::Client(std::unique_ptr<Socket> socket, Server &server)
|
Client::Client(std::unique_ptr<Socket> socket, Server &server)
|
||||||
: client_socket_(std::move(socket)), server_(std::ref(server)), httpRequest_(std::make_unique<HttpRequest>(this)),
|
: client_socket_(std::move(socket)), server_(std::ref(server)), httpRequest_(std::make_unique<HttpRequest>(this)),
|
||||||
|
|||||||
@ -1,19 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// #include "webserv/http/HttpResponse.hpp"
|
// #include <webserv/http/HttpResponse.hpp>
|
||||||
|
|
||||||
#include "webserv/http/HttpResponse.hpp"
|
|
||||||
|
|
||||||
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
|
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
|
||||||
#include <webserv/http/HttpConstants.hpp> // for OK
|
#include <webserv/http/HttpConstants.hpp> // for OK
|
||||||
#include <webserv/http/HttpRequest.hpp> // for HttpRequest
|
#include <webserv/http/HttpRequest.hpp> // for HttpRequest
|
||||||
|
#include <webserv/http/HttpResponse.hpp> // for HttpResponse
|
||||||
#include <webserv/server/Server.hpp>
|
#include <webserv/server/Server.hpp>
|
||||||
#include <webserv/socket/Socket.hpp>
|
#include <webserv/socket/Socket.hpp> // for Socket
|
||||||
|
|
||||||
#include <cstddef> // for size_t
|
#include <cstddef> // for size_t
|
||||||
#include <cstdint>
|
#include <cstdint> // for uint8_t
|
||||||
#include <memory> // for unique_ptr
|
#include <memory> // for unique_ptr
|
||||||
#include <vector>
|
#include <vector> // for vector
|
||||||
|
|
||||||
class Server;
|
class Server;
|
||||||
class Socket;
|
class Socket;
|
||||||
@ -39,6 +38,7 @@ class Client
|
|||||||
[[nodiscard]] int getStatusCode() const;
|
[[nodiscard]] int getStatusCode() const;
|
||||||
|
|
||||||
[[nodiscard]] Socket &getSocket() const { return *client_socket_; }
|
[[nodiscard]] Socket &getSocket() const { return *client_socket_; }
|
||||||
|
|
||||||
// void setError(int statusCode);
|
// void setError(int statusCode);
|
||||||
|
|
||||||
void setStatusCode(int code);
|
void setStatusCode(int code);
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
#include <webserv/config/AConfig.hpp> // for AConfig
|
#include <webserv/config/AConfig.hpp> // for AConfig
|
||||||
|
|
||||||
#include <webserv/config/directive/ADirective.hpp> // for ADirective
|
#include <webserv/config/directive/ADirective.hpp> // for ADirective
|
||||||
#include <webserv/config/directive/DirectiveFactory.hpp> // for DirectiveFactory
|
#include <webserv/config/directive/DirectiveFactory.hpp> // for DirectiveFactory
|
||||||
|
#include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValue
|
||||||
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
||||||
#include <webserv/utils/utils.hpp> // for trim
|
#include <webserv/utils/utils.hpp> // for trim
|
||||||
|
|
||||||
#include <sstream> // for basic_stringstream, stringstream
|
#include <sstream> // for basic_stringstream, stringstream
|
||||||
#include <utility> // for move, pair
|
#include <utility> // for pair, move
|
||||||
|
|
||||||
AConfig::AConfig(const AConfig *parent) : parent_(parent) {}
|
AConfig::AConfig(const AConfig *parent) : parent_(parent) {}
|
||||||
|
|
||||||
|
|||||||
@ -3,10 +3,10 @@
|
|||||||
#include <webserv/config/directive/ADirective.hpp> // for ADirective
|
#include <webserv/config/directive/ADirective.hpp> // for ADirective
|
||||||
#include <webserv/config/directive/DirectiveValue.hpp>
|
#include <webserv/config/directive/DirectiveValue.hpp>
|
||||||
|
|
||||||
#include <memory> // for unique_ptr
|
#include <memory> // for unique_ptr
|
||||||
#include <optional>
|
#include <optional> // for nullopt, optional
|
||||||
#include <string> // for string
|
#include <string> // for string
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
|
|
||||||
class AConfig
|
class AConfig
|
||||||
{
|
{
|
||||||
@ -28,8 +28,7 @@ class AConfig
|
|||||||
[[nodiscard]] const ADirective *getDirective(const std::string &name) const;
|
[[nodiscard]] const ADirective *getDirective(const std::string &name) const;
|
||||||
[[nodiscard]] std::vector<const ADirective *> getDirectives() const;
|
[[nodiscard]] std::vector<const ADirective *> getDirectives() const;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> std::optional<T> get(const std::string &name) const
|
||||||
std::optional<T> get(const std::string &name) const
|
|
||||||
{
|
{
|
||||||
const auto *directive = getDirective(name);
|
const auto *directive = getDirective(name);
|
||||||
if (!directive)
|
if (!directive)
|
||||||
@ -39,7 +38,7 @@ class AConfig
|
|||||||
return directive->getValue().try_get<T>();
|
return directive->getValue().try_get<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void parseBlock(const std::string &block) = 0;
|
virtual void parseBlock(const std::string &block) = 0;
|
||||||
void parseDirectives(const std::string &declarations);
|
void parseDirectives(const std::string &declarations);
|
||||||
std::vector<std::unique_ptr<ADirective>>
|
std::vector<std::unique_ptr<ADirective>>
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
#include <webserv/config/ConfigManager.hpp>
|
#include <webserv/config/ConfigManager.hpp>
|
||||||
|
|
||||||
#include <webserv/config/GlobalConfig.hpp> // for GlobalConfig
|
#include <webserv/config/GlobalConfig.hpp> // for GlobalConfig
|
||||||
#include <webserv/log/Log.hpp> // for Log
|
#include <webserv/log/Log.hpp> // for Log
|
||||||
#include <webserv/utils/utils.hpp> // for removeComments
|
#include <webserv/utils/utils.hpp> // for removeComments
|
||||||
|
|
||||||
#include <fstream> // for basic_ifstream, basic_filebuf, basic_ostream::operator<<, ifstream, stringstream
|
#include <fstream> // for basic_ifstream, basic_filebuf, basic_ostream::operator<<, ifstream, stringstream
|
||||||
|
#include <optional> // for optional
|
||||||
#include <sstream> // for basic_stringstream
|
#include <sstream> // for basic_stringstream
|
||||||
#include <stdexcept> // for runtime_error
|
#include <stdexcept> // for runtime_error
|
||||||
#include <string> // for basic_string, char_traits, operator+, string, to_string, operator==, stoi
|
#include <string> // for basic_string, char_traits, operator+, string, to_string, operator==, stoi
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#include <webserv/config/GlobalConfig.hpp>
|
#include <webserv/config/GlobalConfig.hpp>
|
||||||
|
|
||||||
#include <webserv/log/Log.hpp> // for Log
|
#include <webserv/log/Log.hpp> // for Log
|
||||||
#include <webserv/utils/utils.hpp> // for findCorrespondingClosingBrace
|
#include <webserv/utils/utils.hpp> // for findCorrespondingClosingBrace
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,7 @@ class GlobalConfig : public AConfig
|
|||||||
GlobalConfig &operator=(GlobalConfig &&other) noexcept = delete;
|
GlobalConfig &operator=(GlobalConfig &&other) noexcept = delete;
|
||||||
|
|
||||||
~GlobalConfig() override = default;
|
~GlobalConfig() override = default;
|
||||||
|
|
||||||
[[nodiscard]] std::string getName() const override;
|
[[nodiscard]] std::string getName() const override;
|
||||||
[[nodiscard]] std::string getType() const override;
|
[[nodiscard]] std::string getType() const override;
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include <webserv/config/AConfig.hpp> // for AConfig
|
|
||||||
#include <webserv/config/LocationConfig.hpp>
|
#include <webserv/config/LocationConfig.hpp>
|
||||||
|
|
||||||
|
#include <webserv/config/AConfig.hpp> // for AConfig
|
||||||
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
||||||
|
|
||||||
LocationConfig::LocationConfig(const std::string &block, const std::string &path, const AConfig *parent)
|
LocationConfig::LocationConfig(const std::string &block, const std::string &path, const AConfig *parent)
|
||||||
|
|||||||
@ -19,6 +19,7 @@ class LocationConfig : public AConfig
|
|||||||
|
|
||||||
[[nodiscard]] std::string getName() const override;
|
[[nodiscard]] std::string getName() const override;
|
||||||
[[nodiscard]] std::string getType() const override;
|
[[nodiscard]] std::string getType() const override;
|
||||||
|
|
||||||
[[nodiscard]] const std::string &getPath() const { return _path; }
|
[[nodiscard]] const std::string &getPath() const { return _path; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
|
#include <webserv/config/ServerConfig.hpp>
|
||||||
|
|
||||||
#include <webserv/config/AConfig.hpp> // for AConfig
|
#include <webserv/config/AConfig.hpp> // for AConfig
|
||||||
#include <webserv/config/LocationConfig.hpp> // for LocationConfig
|
#include <webserv/config/LocationConfig.hpp> // for LocationConfig
|
||||||
#include <webserv/config/ServerConfig.hpp>
|
|
||||||
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
||||||
#include <webserv/utils/utils.hpp> // for findCorrespondingClosingBrace, trim
|
#include <webserv/utils/utils.hpp> // for findCorrespondingClosingBrace, trim
|
||||||
|
|
||||||
|
#include <optional> // for optional
|
||||||
#include <stdexcept> // for runtime_error
|
#include <stdexcept> // for runtime_error
|
||||||
#include <utility> // for pair
|
#include <utility> // for pair
|
||||||
|
|
||||||
@ -79,4 +81,3 @@ std::vector<std::string> ServerConfig::getLocationPaths() const
|
|||||||
}
|
}
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,6 @@ class ServerConfig : public AConfig
|
|||||||
[[nodiscard]] const LocationConfig *getLocation(const std::string &path) const;
|
[[nodiscard]] const LocationConfig *getLocation(const std::string &path) const;
|
||||||
[[nodiscard]] std::vector<std::string> getLocationPaths() const;
|
[[nodiscard]] std::vector<std::string> getLocationPaths() const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, std::unique_ptr<LocationConfig>> locations_;
|
std::map<std::string, std::unique_ptr<LocationConfig>> locations_;
|
||||||
AConfig *parent_ = nullptr;
|
AConfig *parent_ = nullptr;
|
||||||
|
|||||||
@ -1,18 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "webserv/config/config_validator/AValidationRule.hpp"
|
|
||||||
#include "webserv/config/config_validator/ValidationResult.hpp"
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
class AConfig;
|
|
||||||
|
|
||||||
class AllowedValuesRule : public AValidationRule
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit AllowedValuesRule(const std::vector<std::string> &allowedValues, bool requiresValue = true);
|
|
||||||
|
|
||||||
private:
|
|
||||||
[[nodiscard]] ValidationResult validateValue(const AConfig *config, const std::string &directiveName) const override;
|
|
||||||
std::vector<std::string> allowedValues_;
|
|
||||||
};
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
#include "webserv/config/config_validator/ConfigValidator.hpp"
|
|
||||||
|
|
||||||
#include "webserv/config/GlobalConfig.hpp"
|
|
||||||
#include "webserv/config/config_validator/AllowedValuesRule.hpp"
|
|
||||||
#include "webserv/config/config_validator/PortValidationRule.hpp"
|
|
||||||
#include "webserv/log/Log.hpp"
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
ConfigValidator::ConfigValidator(const GlobalConfig *config)
|
|
||||||
: engine_(std::make_unique<ValidationEngine>(config))
|
|
||||||
{
|
|
||||||
Log::trace(LOCATION);
|
|
||||||
|
|
||||||
engine_->addServerRule("listen", std::make_unique<PortValidationRule>());
|
|
||||||
engine_->addLocationRule("allowed_methods", std::make_unique<AllowedValuesRule>(std::vector<std::string>{"GET", "POST", "DELETE"}));
|
|
||||||
engine_->validate();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<ValidationResult> ConfigValidator::getValidationResults() const
|
|
||||||
{
|
|
||||||
return engine_->getValidationResults();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<ValidationResult> ConfigValidator::getErrors() const
|
|
||||||
{
|
|
||||||
return engine_->getErrors();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<ValidationResult> ConfigValidator::getWarnings() const
|
|
||||||
{
|
|
||||||
return engine_->getWarnings();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ConfigValidator::hasErrors() const
|
|
||||||
{
|
|
||||||
return engine_->hasErrors();
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,32 +0,0 @@
|
|||||||
#include "webserv/config/config_validator/PortValidationRule.hpp"
|
|
||||||
|
|
||||||
#include "webserv/config/AConfig.hpp"
|
|
||||||
#include "webserv/config/config_validator/ValidationResult.hpp"
|
|
||||||
#include "webserv/config/directive/ADirective.hpp"
|
|
||||||
#include "webserv/config/directive/DirectiveValue.hpp"
|
|
||||||
#include "webserv/log/Log.hpp"
|
|
||||||
|
|
||||||
#include <string> // for string, basic_string, operator+, char_traits
|
|
||||||
|
|
||||||
PortValidationRule::PortValidationRule(bool requiresValue)
|
|
||||||
: AValidationRule("PortValidationRule", "Validates that the port number is within the valid range (1-65535)", requiresValue)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ValidationResult PortValidationRule::validateValue(const AConfig *config, const std::string &directiveName) const
|
|
||||||
{
|
|
||||||
Log::trace(LOCATION);
|
|
||||||
const ADirective *directive = config->getDirective(directiveName);
|
|
||||||
if (!directive->getValue().holds<int>())
|
|
||||||
{
|
|
||||||
return ValidationResult::error("Directive '" + directive->getName() + "' does not hold an integer value");
|
|
||||||
}
|
|
||||||
|
|
||||||
int port = directive->getValue().get<int>();
|
|
||||||
if (port < 1 || port > 65535)
|
|
||||||
{
|
|
||||||
return ValidationResult::error("Port number " + std::to_string(port) + " is out of valid range (1-65535)");
|
|
||||||
}
|
|
||||||
|
|
||||||
return ValidationResult::success();
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "webserv/config/config_validator/AValidationRule.hpp"
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class AConfig;
|
|
||||||
class PortValidationRule : public AValidationRule
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PortValidationRule(bool requiresValue = true);
|
|
||||||
|
|
||||||
private:
|
|
||||||
[[nodiscard]] ValidationResult validateValue(const AConfig *config, const std::string &directiveName) const override;
|
|
||||||
};
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
#include "webserv/config/config_validator/ValidationResult.hpp"
|
|
||||||
#include "webserv/config/config_validator/RequiredDirectiveRule.hpp"
|
|
||||||
#include <webserv/config/config_validator/AValidationRule.hpp>
|
|
||||||
#include <webserv/config/AConfig.hpp>
|
|
||||||
|
|
||||||
RequiredDirectiveRule::RequiredDirectiveRule()
|
|
||||||
: AValidationRule("RequiredDirectiveRule", "Ensures that a required directive is present in the configuration", true)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ValidationResult RequiredDirectiveRule::validateValue(const AConfig *config, const std::string &directiveName) const
|
|
||||||
{
|
|
||||||
return ValidationResult::success();
|
|
||||||
}
|
|
||||||
@ -1,5 +1,6 @@
|
|||||||
#include <webserv/config/directive/ADirective.hpp> // for ADirective
|
|
||||||
#include <webserv/config/directive/BoolDirective.hpp> // for IntDirective
|
#include <webserv/config/directive/BoolDirective.hpp> // for IntDirective
|
||||||
|
|
||||||
|
#include <webserv/config/directive/ADirective.hpp> // for ADirective
|
||||||
#include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValueType
|
#include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValueType
|
||||||
#include <webserv/utils/utils.hpp> // for trim
|
#include <webserv/utils/utils.hpp> // for trim
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include <webserv/config/directive/BoolDirective.hpp> // for BoolDirective
|
|
||||||
#include <webserv/config/directive/DirectiveFactory.hpp> // for DirectiveFactory
|
#include <webserv/config/directive/DirectiveFactory.hpp> // for DirectiveFactory
|
||||||
|
|
||||||
|
#include <webserv/config/directive/BoolDirective.hpp> // for BoolDirective
|
||||||
#include <webserv/config/directive/IntDirective.hpp> // for IntDirective
|
#include <webserv/config/directive/IntDirective.hpp> // for IntDirective
|
||||||
#include <webserv/config/directive/IntStringDirective.hpp> // for IntStringDirective
|
#include <webserv/config/directive/IntStringDirective.hpp> // for IntStringDirective
|
||||||
#include <webserv/config/directive/SizeDirective.hpp> // for SizeDirective
|
#include <webserv/config/directive/SizeDirective.hpp> // for SizeDirective
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
|
#include <webserv/config/directive/IntStringDirective.hpp> // for IntDirective
|
||||||
|
|
||||||
#include <webserv/config/directive/ADirective.hpp> // for ADirective
|
#include <webserv/config/directive/ADirective.hpp> // for ADirective
|
||||||
#include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValueType
|
#include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValueType
|
||||||
#include <webserv/config/directive/IntStringDirective.hpp> // for IntDirective
|
|
||||||
#include <webserv/utils/utils.hpp> // for trim
|
#include <webserv/utils/utils.hpp> // for trim
|
||||||
|
|
||||||
#include <sstream> // for basic_istringstream, basic_istream::operator>>, istringstream
|
#include <sstream> // for basic_istringstream, basic_istream::operator>>, istringstream
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
|
#include <webserv/config/directive/SizeDirective.hpp> // for SizeDirective
|
||||||
|
|
||||||
#include <webserv/config/directive/ADirective.hpp> // for ADirective
|
#include <webserv/config/directive/ADirective.hpp> // for ADirective
|
||||||
#include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValueType
|
#include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValueType
|
||||||
#include <webserv/config/directive/SizeDirective.hpp> // for SizeDirective
|
|
||||||
#include <webserv/utils/utils.hpp> // for trim
|
#include <webserv/utils/utils.hpp> // for trim
|
||||||
|
|
||||||
#include <algorithm> // for __transform_fn, transform
|
#include <algorithm> // for __transform_fn, transform
|
||||||
|
|||||||
45
webserv/config/validation/ConfigValidator.cpp
Normal file
45
webserv/config/validation/ConfigValidator.cpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#include <webserv/config/validation/ConfigValidator.hpp>
|
||||||
|
|
||||||
|
#include <webserv/config/validation/ValidationEngine.hpp> // for ValidationEngine
|
||||||
|
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
|
||||||
|
#include <webserv/config/validation/directive_rules/AllowedValuesRule.hpp> // for AllowedValuesRule
|
||||||
|
#include <webserv/config/validation/directive_rules/PortValidationRule.hpp> // for PortValidationRule
|
||||||
|
#include <webserv/log/Log.hpp> // for LOCATION, Log
|
||||||
|
|
||||||
|
#include <string> // for basic_string, string
|
||||||
|
|
||||||
|
ConfigValidator::ConfigValidator(const GlobalConfig *config) : engine_(std::make_unique<ValidationEngine>(config))
|
||||||
|
{
|
||||||
|
Log::trace(LOCATION);
|
||||||
|
|
||||||
|
/*Global Directive Rules*/
|
||||||
|
|
||||||
|
/*Server Directive Rules*/
|
||||||
|
engine_->addServerRule("listen", std::make_unique<PortValidationRule>());
|
||||||
|
|
||||||
|
/*Location Directive Rules*/
|
||||||
|
engine_->addLocationRule("allowed_methods",
|
||||||
|
std::make_unique<AllowedValuesRule>(std::vector<std::string>{"GET", "POST", "DELETE"}));
|
||||||
|
|
||||||
|
engine_->validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ValidationResult> ConfigValidator::getValidationResults() const
|
||||||
|
{
|
||||||
|
return engine_->getValidationResults();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ValidationResult> ConfigValidator::getErrors() const
|
||||||
|
{
|
||||||
|
return engine_->getErrors();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ValidationResult> ConfigValidator::getWarnings() const
|
||||||
|
{
|
||||||
|
return engine_->getWarnings();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ConfigValidator::hasErrors() const
|
||||||
|
{
|
||||||
|
return engine_->hasErrors();
|
||||||
|
}
|
||||||
@ -1,9 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <webserv/config/validation/ValidationEngine.hpp> // for ValidationEngine
|
||||||
|
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
|
||||||
|
|
||||||
|
#include <memory> // for unique_ptr
|
||||||
|
#include <vector> // for vector
|
||||||
|
|
||||||
#include "webserv/config/config_validator/ValidationEngine.hpp"
|
|
||||||
#include <memory>
|
|
||||||
class GlobalConfig;
|
class GlobalConfig;
|
||||||
|
|
||||||
class ConfigValidator
|
class ConfigValidator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -22,5 +26,4 @@ class ConfigValidator
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ValidationEngine> engine_;
|
std::unique_ptr<ValidationEngine> engine_;
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -1,11 +1,14 @@
|
|||||||
#include "webserv/config/config_validator/ValidationEngine.hpp"
|
#include <webserv/config/validation/ValidationEngine.hpp>
|
||||||
|
|
||||||
#include "webserv/config/AConfig.hpp"
|
#include <webserv/config/AConfig.hpp> // for AConfig
|
||||||
#include "webserv/config/LocationConfig.hpp"
|
#include <webserv/config/GlobalConfig.hpp> // for GlobalConfig
|
||||||
#include "webserv/config/config_validator/AValidationRule.hpp"
|
#include <webserv/config/LocationConfig.hpp> // for LocationConfig
|
||||||
#include "webserv/config/config_validator/ValidationResult.hpp"
|
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
|
||||||
#include "webserv/config/directive/ADirective.hpp"
|
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
|
||||||
#include "webserv/log/Log.hpp"
|
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
|
||||||
|
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
||||||
|
|
||||||
|
#include <utility> // for move, get
|
||||||
|
|
||||||
void ValidationEngine::addGlobalRule(const std::string &directiveName, std::unique_ptr<AValidationRule> rule)
|
void ValidationEngine::addGlobalRule(const std::string &directiveName, std::unique_ptr<AValidationRule> rule)
|
||||||
{
|
{
|
||||||
@ -1,15 +1,21 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "webserv/config/GlobalConfig.hpp"
|
#include <webserv/config/AConfig.hpp>
|
||||||
#include "webserv/config/config_validator/AValidationRule.hpp"
|
#include <webserv/config/GlobalConfig.hpp>
|
||||||
#include "webserv/config/config_validator/ValidationResult.hpp"
|
#include <webserv/config/LocationConfig.hpp>
|
||||||
#include "webserv/config/LocationConfig.hpp"
|
#include <webserv/config/ServerConfig.hpp>
|
||||||
#include "webserv/config/ServerConfig.hpp"
|
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
|
||||||
#include "webserv/config/AConfig.hpp"
|
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
|
||||||
#include <map>
|
|
||||||
#include <memory>
|
#include <map> // for map
|
||||||
#include <string>
|
#include <memory> // for unique_ptr
|
||||||
#include <vector>
|
#include <string> // for basic_string, string, operator<=>
|
||||||
|
#include <vector> // for vector
|
||||||
|
|
||||||
|
class AConfig;
|
||||||
|
class GlobalConfig;
|
||||||
|
class LocationConfig;
|
||||||
|
class ServerConfig;
|
||||||
|
|
||||||
class ValidationEngine
|
class ValidationEngine
|
||||||
{
|
{
|
||||||
@ -1,5 +1,8 @@
|
|||||||
#include <webserv/config/config_validator/ValidationResult.hpp>
|
#include <webserv/config/validation/ValidationResult.hpp>
|
||||||
#include <webserv/log/Log.hpp>
|
|
||||||
|
#include <webserv/log/Log.hpp> // for Log
|
||||||
|
|
||||||
|
#include <utility> // for move
|
||||||
|
|
||||||
ValidationResult::ValidationResult(Type type, std::string message) : type_(type), message_(std::move(message)) {}
|
ValidationResult::ValidationResult(Type type, std::string message) : type_(type), message_(std::move(message)) {}
|
||||||
|
|
||||||
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class ValidationResult
|
class ValidationResult
|
||||||
{
|
{
|
||||||
@ -25,7 +25,7 @@ class ValidationResult
|
|||||||
static ValidationResult warning(const std::string &message);
|
static ValidationResult warning(const std::string &message);
|
||||||
|
|
||||||
[[nodiscard]] bool isValidResult() const;
|
[[nodiscard]] bool isValidResult() const;
|
||||||
[[nodiscard]] ValidationResult::Type getType() const ;
|
[[nodiscard]] ValidationResult::Type getType() const;
|
||||||
[[nodiscard]] std::string getMessage() const;
|
[[nodiscard]] std::string getMessage() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -1,8 +1,10 @@
|
|||||||
#include <webserv/config/AConfig.hpp>
|
#include <webserv/config/validation/directive_rules/AValidationRule.hpp>
|
||||||
#include <webserv/config/config_validator/AValidationRule.hpp>
|
|
||||||
#include <webserv/config/config_validator/ValidationResult.hpp>
|
#include <webserv/config/AConfig.hpp> // for AConfig
|
||||||
#include <webserv/config/directive/ADirective.hpp>
|
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
|
||||||
#include <webserv/log/Log.hpp>
|
#include <webserv/log/Log.hpp> // for LOCATION, Log
|
||||||
|
|
||||||
|
#include <utility> // for move
|
||||||
|
|
||||||
AValidationRule::AValidationRule(std::string ruleName, std::string description, bool requiresValue)
|
AValidationRule::AValidationRule(std::string ruleName, std::string description, bool requiresValue)
|
||||||
: ruleName_(std::move(ruleName)), description_(std::move(description)), requiresValue_(requiresValue)
|
: ruleName_(std::move(ruleName)), description_(std::move(description)), requiresValue_(requiresValue)
|
||||||
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string> // for string, basic_string
|
||||||
|
|
||||||
|
|
||||||
class ValidationResult;
|
class ValidationResult;
|
||||||
class ADirective;
|
class ADirective;
|
||||||
@ -18,7 +17,8 @@ class AValidationRule
|
|||||||
|
|
||||||
[[nodiscard]] ValidationResult validate(const AConfig *config, const std::string &directiveName) const;
|
[[nodiscard]] ValidationResult validate(const AConfig *config, const std::string &directiveName) const;
|
||||||
[[nodiscard]] bool isRequired() const;
|
[[nodiscard]] bool isRequired() const;
|
||||||
[[nodiscard]] virtual ValidationResult validateValue(const AConfig *config, const std::string &directiveName) const = 0;
|
[[nodiscard]] virtual ValidationResult validateValue(const AConfig *config,
|
||||||
|
const std::string &directiveName) const = 0;
|
||||||
[[nodiscard]] std::string getRuleName() const;
|
[[nodiscard]] std::string getRuleName() const;
|
||||||
[[nodiscard]] std::string getDescription() const;
|
[[nodiscard]] std::string getDescription() const;
|
||||||
|
|
||||||
@ -1,12 +1,16 @@
|
|||||||
#include <webserv/config/AConfig.hpp>
|
#include <webserv/config/validation/directive_rules/AllowedValuesRule.hpp>
|
||||||
#include <webserv/config/config_validator/AllowedValuesRule.hpp>
|
|
||||||
#include <webserv/config/config_validator/ValidationResult.hpp>
|
|
||||||
#include <webserv/config/directive/ADirective.hpp>
|
|
||||||
|
|
||||||
#include <algorithm> // for find
|
#include <webserv/config/AConfig.hpp> // for AConfig
|
||||||
|
#include <webserv/config/directive/ADirective.hpp> // for ADirective
|
||||||
|
#include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValue
|
||||||
|
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
|
||||||
|
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
|
||||||
|
|
||||||
#include <string> // for string, basic_string, operator+, char_traits
|
#include <functional> // for identity
|
||||||
#include <vector> // for vector
|
#include <ranges> // for __find_fn, find
|
||||||
|
#include <string> // for basic_string, allocator, operator+, char_traits, string, operator==
|
||||||
|
#include <utility> // for move
|
||||||
|
#include <vector> // for vector
|
||||||
|
|
||||||
AllowedValuesRule::AllowedValuesRule(const std::vector<std::string> &allowedValues, bool requiresValue)
|
AllowedValuesRule::AllowedValuesRule(const std::vector<std::string> &allowedValues, bool requiresValue)
|
||||||
: AValidationRule("AllowedValuesRule", "Ensures that the directive's value is within the allowed set",
|
: AValidationRule("AllowedValuesRule", "Ensures that the directive's value is within the allowed set",
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <webserv/config/validation/ValidationResult.hpp>
|
||||||
|
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
|
||||||
|
|
||||||
|
#include <string> // for basic_string, string
|
||||||
|
#include <vector> // for vector
|
||||||
|
|
||||||
|
class AConfig;
|
||||||
|
|
||||||
|
class AllowedValuesRule : public AValidationRule
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit AllowedValuesRule(const std::vector<std::string> &allowedValues, bool requiresValue = true);
|
||||||
|
|
||||||
|
private:
|
||||||
|
[[nodiscard]] ValidationResult validateValue(const AConfig *config,
|
||||||
|
const std::string &directiveName) const override;
|
||||||
|
std::vector<std::string> allowedValues_;
|
||||||
|
};
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
#include <webserv/config/validation/directive_rules/PortValidationRule.hpp>
|
||||||
|
|
||||||
|
#include <webserv/config/AConfig.hpp> // for AConfig
|
||||||
|
#include <webserv/config/directive/ADirective.hpp> // for ADirective
|
||||||
|
#include <webserv/config/directive/DirectiveValue.hpp> // for DirectiveValue
|
||||||
|
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
|
||||||
|
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
|
||||||
|
#include <webserv/log/Log.hpp> // for LOCATION, Log
|
||||||
|
|
||||||
|
#include <string> // for operator+, basic_string, allocator, char_traits, to_string, string
|
||||||
|
|
||||||
|
PortValidationRule::PortValidationRule(bool requiresValue)
|
||||||
|
: AValidationRule("PortValidationRule", "Validates that the port number is within the valid range (1-65535)",
|
||||||
|
requiresValue)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ValidationResult PortValidationRule::validateValue(const AConfig *config, const std::string &directiveName) const
|
||||||
|
{
|
||||||
|
Log::trace(LOCATION);
|
||||||
|
const ADirective *directive = config->getDirective(directiveName);
|
||||||
|
if (!directive->getValue().holds<int>())
|
||||||
|
{
|
||||||
|
return ValidationResult::error("Directive '" + directive->getName() + "' does not hold an integer value");
|
||||||
|
}
|
||||||
|
|
||||||
|
int port = directive->getValue().get<int>();
|
||||||
|
if (port < 1 || port > 65535)
|
||||||
|
{
|
||||||
|
return ValidationResult::error("Port number " + std::to_string(port) + " is out of valid range (1-65535)");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ValidationResult::success();
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
|
||||||
|
|
||||||
|
#include <string> // for string
|
||||||
|
|
||||||
|
class AConfig;
|
||||||
|
|
||||||
|
class PortValidationRule : public AValidationRule
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PortValidationRule(bool requiresValue = true);
|
||||||
|
|
||||||
|
private:
|
||||||
|
[[nodiscard]] ValidationResult validateValue(const AConfig *config,
|
||||||
|
const std::string &directiveName) const override;
|
||||||
|
};
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
#include <webserv/config/validation/directive_rules/RequiredDirectiveRule.hpp>
|
||||||
|
|
||||||
|
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
|
||||||
|
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
|
||||||
|
|
||||||
|
RequiredDirectiveRule::RequiredDirectiveRule()
|
||||||
|
: AValidationRule("RequiredDirectiveRule", "Ensures that a required directive is present in the configuration",
|
||||||
|
true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ValidationResult RequiredDirectiveRule::validateValue(const AConfig *config, const std::string &directiveName) const
|
||||||
|
{
|
||||||
|
return ValidationResult::success();
|
||||||
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "webserv/config/config_validator/AValidationRule.hpp"
|
#include <webserv/config/validation/directive_rules/AValidationRule.hpp> // for AValidationRule
|
||||||
|
|
||||||
#include <string>
|
#include <string> // for string
|
||||||
|
|
||||||
class AConfig;
|
class AConfig;
|
||||||
|
|
||||||
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "webserv/http/HttpResponse.hpp"
|
|
||||||
|
|
||||||
#include <webserv/config/AConfig.hpp>
|
#include <webserv/config/AConfig.hpp>
|
||||||
|
#include <webserv/http/HttpResponse.hpp>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
class ErrorHandler
|
class ErrorHandler
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
#include "webserv/http/HttpResponse.hpp"
|
|
||||||
|
|
||||||
#include <webserv/config/AConfig.hpp> // for AConfig
|
#include <webserv/config/AConfig.hpp> // for AConfig
|
||||||
#include <webserv/config/ConfigManager.hpp> // for ConfigManager
|
#include <webserv/config/ConfigManager.hpp> // for ConfigManager
|
||||||
#include <webserv/config/GlobalConfig.hpp> // for GlobalConfig
|
#include <webserv/config/GlobalConfig.hpp> // for GlobalConfig
|
||||||
#include <webserv/handler/ErrorHandler.hpp> // for ErrorHandler
|
#include <webserv/handler/ErrorHandler.hpp> // for ErrorHandler
|
||||||
#include <webserv/http/HttpConstants.hpp> // for StatusCodeInfo, CRLF, DOUBLE_CRLF, INTERNAL_SERVER_ERROR, statusCodeInfos
|
#include <webserv/http/HttpConstants.hpp> // for StatusCodeInfo, CRLF, DOUBLE_CRLF, INTERNAL_SERVER_ERROR, statusCodeInfos
|
||||||
#include <webserv/log/Log.hpp> // for Log
|
#include <webserv/http/HttpResponse.hpp>
|
||||||
|
#include <webserv/log/Log.hpp> // for Log
|
||||||
|
|
||||||
#include <fstream> // for basic_ifstream, basic_filebuf, basic_ostream::operator<<, ifstream, stringstream
|
#include <fstream> // for basic_ifstream, basic_filebuf, basic_ostream::operator<<, ifstream, stringstream
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|||||||
@ -1,20 +1,21 @@
|
|||||||
#include "webserv/handler/ErrorHandler.hpp"
|
|
||||||
#include "webserv/http/HttpConstants.hpp"
|
|
||||||
#include "webserv/http/HttpResponse.hpp"
|
|
||||||
|
|
||||||
#include <webserv/config/LocationConfig.hpp>
|
|
||||||
#include <webserv/handler/FileHandler.hpp>
|
#include <webserv/handler/FileHandler.hpp>
|
||||||
#include <webserv/handler/MIMETypes.hpp>
|
|
||||||
#include <webserv/handler/URIParser.hpp>
|
|
||||||
#include <webserv/log/Log.hpp>
|
|
||||||
#include <webserv/utils/FileUtils.hpp>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <webserv/config/LocationConfig.hpp> // for LocationConfig
|
||||||
#include <cerrno> // for errno
|
#include <webserv/handler/ErrorHandler.hpp> // for ErrorHandler
|
||||||
#include <cstring> // for strerror, strlen
|
#include <webserv/handler/MIMETypes.hpp> // for MIMETypes
|
||||||
#include <memory>
|
#include <webserv/handler/URIParser.hpp> // for URIParser
|
||||||
#include <string>
|
#include <webserv/http/HttpConstants.hpp> // for NOT_FOUND, FORBIDDEN, OK
|
||||||
#include <vector>
|
#include <webserv/http/HttpResponse.hpp> // for HttpResponse
|
||||||
|
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
||||||
|
#include <webserv/utils/FileUtils.hpp> // for joinPath, getExtension, isFile, readBinaryFile
|
||||||
|
|
||||||
|
#include <functional> // for identity
|
||||||
|
#include <memory> // for unique_ptr, allocator, make_unique
|
||||||
|
#include <optional> // for optional
|
||||||
|
#include <ranges> // for __find_if_fn, find_if
|
||||||
|
#include <string> // for basic_string, string, operator+, char_traits
|
||||||
|
#include <utility> // for move
|
||||||
|
#include <vector> // for vector
|
||||||
|
|
||||||
FileHandler::FileHandler(const LocationConfig *location, const URIParser &uriParser)
|
FileHandler::FileHandler(const LocationConfig *location, const URIParser &uriParser)
|
||||||
: location_(location), uriParser_(uriParser)
|
: location_(location), uriParser_(uriParser)
|
||||||
|
|||||||
@ -1,12 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "webserv/config/LocationConfig.hpp"
|
#include <webserv/config/LocationConfig.hpp>
|
||||||
#include "webserv/handler/URIParser.hpp"
|
#include <webserv/handler/URIParser.hpp>
|
||||||
#include "webserv/http/HttpResponse.hpp"
|
#include <webserv/http/HttpResponse.hpp> // for HttpResponse
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint> // for uint8_t
|
||||||
#include <memory>
|
#include <memory> // for unique_ptr
|
||||||
#include <string>
|
#include <string> // for string
|
||||||
|
|
||||||
|
class LocationConfig;
|
||||||
|
class URIParser;
|
||||||
|
|
||||||
class FileHandler
|
class FileHandler
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,37 +1,42 @@
|
|||||||
|
|
||||||
#include <webserv/handler/MIMETypes.hpp>
|
#include <webserv/handler/MIMETypes.hpp>
|
||||||
|
|
||||||
|
#include <utility> // for pair
|
||||||
|
|
||||||
|
MIMETypes::MIMETypes()
|
||||||
MIMETypes::MIMETypes() {
|
{
|
||||||
initializeDefaults();
|
initializeDefaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MIMETypes::getType(const std::string& extension) const {
|
std::string MIMETypes::getType(const std::string &extension) const
|
||||||
auto it = mimeMap.find(extension);
|
{
|
||||||
if (it != mimeMap.end()) {
|
auto it = mimeMap.find(extension);
|
||||||
return it->second;
|
if (it != mimeMap.end())
|
||||||
}
|
{
|
||||||
return "application/octet-stream"; // Default MIME type
|
return it->second;
|
||||||
|
}
|
||||||
|
return "application/octet-stream"; // Default MIME type
|
||||||
}
|
}
|
||||||
|
|
||||||
void MIMETypes::setType(const std::string& extension, const std::string& mimeType) {
|
void MIMETypes::setType(const std::string &extension, const std::string &mimeType)
|
||||||
mimeMap[extension] = mimeType;
|
{
|
||||||
|
mimeMap[extension] = mimeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MIMETypes::initializeDefaults() {
|
void MIMETypes::initializeDefaults()
|
||||||
mimeMap["html"] = "text/html";
|
{
|
||||||
mimeMap["htm"] = "text/html";
|
mimeMap["html"] = "text/html";
|
||||||
mimeMap["css"] = "text/css";
|
mimeMap["htm"] = "text/html";
|
||||||
mimeMap["js"] = "application/javascript";
|
mimeMap["css"] = "text/css";
|
||||||
mimeMap["json"] = "application/json";
|
mimeMap["js"] = "application/javascript";
|
||||||
mimeMap["png"] = "image/png";
|
mimeMap["json"] = "application/json";
|
||||||
mimeMap["jpg"] = "image/jpeg";
|
mimeMap["png"] = "image/png";
|
||||||
mimeMap["jpeg"] = "image/jpeg";
|
mimeMap["jpg"] = "image/jpeg";
|
||||||
mimeMap["gif"] = "image/gif";
|
mimeMap["jpeg"] = "image/jpeg";
|
||||||
mimeMap["svg"] = "image/svg+xml";
|
mimeMap["gif"] = "image/gif";
|
||||||
mimeMap["txt"] = "text/plain";
|
mimeMap["svg"] = "image/svg+xml";
|
||||||
mimeMap["xml"] = "application/xml";
|
mimeMap["txt"] = "text/plain";
|
||||||
mimeMap["pdf"] = "application/pdf";
|
mimeMap["xml"] = "application/xml";
|
||||||
// Add more default MIME types as needed
|
mimeMap["pdf"] = "application/pdf";
|
||||||
|
// Add more default MIME types as needed
|
||||||
}
|
}
|
||||||
@ -1,24 +1,24 @@
|
|||||||
#ifndef MIMETYPES_HPP
|
#ifndef MIMETYPES_HPP
|
||||||
#define MIMETYPES_HPP
|
#define MIMETYPES_HPP
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class MIMETypes {
|
class MIMETypes
|
||||||
public:
|
{
|
||||||
MIMETypes();
|
public:
|
||||||
|
MIMETypes();
|
||||||
|
|
||||||
|
// Returns the MIME type for a given file extension (e.g., "html" -> "text/html")
|
||||||
|
[[nodiscard]] std::string getType(const std::string &extension) const;
|
||||||
|
|
||||||
// Returns the MIME type for a given file extension (e.g., "html" -> "text/html")
|
// Adds or updates a MIME type mapping
|
||||||
[[nodiscard]] std::string getType(const std::string& extension) const;
|
void setType(const std::string &extension, const std::string &mimeType);
|
||||||
|
|
||||||
// Adds or updates a MIME type mapping
|
private:
|
||||||
void setType(const std::string& extension, const std::string& mimeType);
|
std::map<std::string, std::string> mimeMap;
|
||||||
|
|
||||||
private:
|
void initializeDefaults();
|
||||||
std::map<std::string, std::string> mimeMap;
|
|
||||||
|
|
||||||
void initializeDefaults();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MIMETYPES_HPP
|
#endif // MIMETYPES_HPP
|
||||||
@ -1,8 +1,13 @@
|
|||||||
#include <webserv/config/LocationConfig.hpp>
|
|
||||||
#include <webserv/config/ServerConfig.hpp>
|
|
||||||
#include <webserv/handler/URIParser.hpp>
|
#include <webserv/handler/URIParser.hpp>
|
||||||
|
|
||||||
#include <sys/stat.h> // for stat, S_ISREG, S_ISDIR
|
#include <webserv/config/LocationConfig.hpp> // for LocationConfig
|
||||||
|
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
|
||||||
|
|
||||||
|
#include <optional> // for optional
|
||||||
|
#include <vector> // for vector
|
||||||
|
|
||||||
|
#include <stddef.h> // for size_t
|
||||||
|
#include <sys/stat.h> // for stat, S_ISDIR, S_ISREG
|
||||||
|
|
||||||
URIParser::URIParser(const std::string &uri, const ServerConfig &serverConfig) : _locationConfig(nullptr)
|
URIParser::URIParser(const std::string &uri, const ServerConfig &serverConfig) : _locationConfig(nullptr)
|
||||||
{
|
{
|
||||||
@ -22,7 +27,7 @@ URIParser::URIParser(const std::string &uri, const ServerConfig &serverConfig) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
root_ = _locationConfig != nullptr ? _locationConfig->get<std::string>("root").value_or("") : "";
|
root_ = _locationConfig != nullptr ? _locationConfig->get<std::string>("root").value_or("") : "";
|
||||||
if (!root_.empty() && root_.back() == '/' )
|
if (!root_.empty() && root_.back() == '/')
|
||||||
{
|
{
|
||||||
root_.pop_back(); // Remove trailing slash to avoid double slashes in path
|
root_.pop_back(); // Remove trailing slash to avoid double slashes in path
|
||||||
}
|
}
|
||||||
@ -60,7 +65,6 @@ std::string URIParser::getExtension() const
|
|||||||
return filename.substr(lastDot + 1);
|
return filename.substr(lastDot + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LocationConfig const *URIParser::getLocation() const
|
LocationConfig const *URIParser::getLocation() const
|
||||||
{
|
{
|
||||||
return _locationConfig;
|
return _locationConfig;
|
||||||
@ -91,4 +95,3 @@ bool URIParser::isValid() const
|
|||||||
struct stat pathStat{};
|
struct stat pathStat{};
|
||||||
return stat(getFilePath().c_str(), &pathStat) == 0;
|
return stat(getFilePath().c_str(), &pathStat) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,21 +1,24 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "webserv/config/LocationConfig.hpp"
|
#include <webserv/config/LocationConfig.hpp>
|
||||||
#include "webserv/config/ServerConfig.hpp"
|
#include <webserv/config/ServerConfig.hpp>
|
||||||
#include "webserv/server/Server.hpp"
|
#include <webserv/server/Server.hpp>
|
||||||
|
|
||||||
|
#include <string> // for string, basic_string
|
||||||
|
|
||||||
|
class LocationConfig;
|
||||||
|
class ServerConfig;
|
||||||
|
|
||||||
class URIParser
|
class URIParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
URIParser(const std::string &uri, const ServerConfig &serverConfig);
|
URIParser(const std::string &uri, const ServerConfig &serverConfig);
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] std::string getFilePath() const;
|
[[nodiscard]] std::string getFilePath() const;
|
||||||
[[nodiscard]] std::string getFilename() const;
|
[[nodiscard]] std::string getFilename() const;
|
||||||
[[nodiscard]] std::string getExtension() const;
|
[[nodiscard]] std::string getExtension() const;
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] const LocationConfig *getLocation() const ;
|
[[nodiscard]] const LocationConfig *getLocation() const;
|
||||||
|
|
||||||
[[nodiscard]] bool isFile() const;
|
[[nodiscard]] bool isFile() const;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#include "HttpConstants.hpp"
|
#include <webserv/http/HttpConstants.hpp>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
#include <array> // for array
|
||||||
#include <cstdint>
|
#include <cstdint> // for uint16_t
|
||||||
#include <string_view>
|
#include <string> // for string
|
||||||
|
#include <string_view> // for string_view
|
||||||
|
|
||||||
|
#include <stddef.h> // for size_t
|
||||||
|
|
||||||
namespace Http
|
namespace Http
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include <webserv/http/HttpConstants.hpp> // for CRLF
|
|
||||||
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
|
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
|
||||||
|
|
||||||
|
#include <webserv/http/HttpConstants.hpp> // for CRLF
|
||||||
#include <webserv/log/Log.hpp>
|
#include <webserv/log/Log.hpp>
|
||||||
#include <webserv/utils/utils.hpp> // for trim
|
#include <webserv/utils/utils.hpp> // for trim
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
|
#include <webserv/http/HttpRequest.hpp>
|
||||||
|
|
||||||
#include <webserv/client/Client.hpp> // for Client
|
#include <webserv/client/Client.hpp> // for Client
|
||||||
#include <webserv/http/HttpConstants.hpp> // for CRLF, DOUBLE_CRLF, BAD_REQUEST
|
#include <webserv/http/HttpConstants.hpp> // for CRLF, DOUBLE_CRLF, BAD_REQUEST
|
||||||
#include <webserv/http/HttpRequest.hpp>
|
|
||||||
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
||||||
#include <webserv/utils/utils.hpp> // for stoul
|
#include <webserv/utils/utils.hpp> // for stoul
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#include "webserv/http/HttpConstants.hpp"
|
|
||||||
|
|
||||||
#include <webserv/http/HttpResponse.hpp>
|
#include <webserv/http/HttpResponse.hpp>
|
||||||
|
|
||||||
|
#include <webserv/http/HttpConstants.hpp>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "webserv/http/HttpHeaders.hpp"
|
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
|
||||||
#include "webserv/log/Log.hpp"
|
#include <webserv/log/Log.hpp> // for LOCATION, Log
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint> // for uint8_t
|
||||||
#include <memory>
|
#include <memory> // for unique_ptr
|
||||||
#include <string>
|
#include <string> // for string
|
||||||
#include <vector>
|
#include <vector> // for vector
|
||||||
|
|
||||||
class Client;
|
class Client;
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ class HttpResponse
|
|||||||
HttpResponse(HttpResponse &&other) noexcept = default; // Move constructor
|
HttpResponse(HttpResponse &&other) noexcept = default; // Move constructor
|
||||||
HttpResponse &operator=(HttpResponse &&other) noexcept = default; // Move assignment
|
HttpResponse &operator=(HttpResponse &&other) noexcept = default; // Move assignment
|
||||||
|
|
||||||
~HttpResponse() {Log::trace(LOCATION);};
|
~HttpResponse() { Log::trace(LOCATION); };
|
||||||
|
|
||||||
void addHeader(const std::string &key, const std::string &value);
|
void addHeader(const std::string &key, const std::string &value);
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
#include <webserv/config/ConfigManager.hpp> // for ConfigManager
|
#include <webserv/config/ConfigManager.hpp> // for ConfigManager
|
||||||
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
#include <webserv/config/validation/ConfigValidator.hpp> // for ConfigValidator
|
||||||
#include <webserv/server/Server.hpp> // for Server
|
#include <webserv/config/validation/ValidationResult.hpp> // for ValidationResult
|
||||||
#include <webserv/config/config_validator/ConfigValidator.hpp> // for ConfigValidator
|
#include <webserv/log/Log.hpp> // for Log
|
||||||
|
#include <webserv/server/Server.hpp> // for Server
|
||||||
|
|
||||||
#include <iostream> // for basic_ostream, operator<<, cerr, ios_base
|
#include <iostream> // for ios_base
|
||||||
#include <string> // for basic_string, char_traits, allocator, operator+, operator<=>
|
#include <string> // for allocator, basic_string, char_traits, operator+, string
|
||||||
|
#include <vector> // for vector
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,16 +1,18 @@
|
|||||||
#include "webserv/config/AConfig.hpp"
|
|
||||||
#include "webserv/config/ConfigManager.hpp"
|
|
||||||
#include "webserv/config/ServerConfig.hpp"
|
|
||||||
#include "webserv/handler/ErrorHandler.hpp"
|
|
||||||
#include "webserv/handler/FileHandler.hpp"
|
|
||||||
#include "webserv/handler/URIParser.hpp"
|
|
||||||
#include "webserv/http/HttpResponse.hpp"
|
|
||||||
#include "webserv/log/Log.hpp"
|
|
||||||
|
|
||||||
#include <webserv/router/Router.hpp>
|
#include <webserv/router/Router.hpp>
|
||||||
|
|
||||||
#include <memory>
|
#include <webserv/config/ConfigManager.hpp> // for ConfigManager
|
||||||
#include <string>
|
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
|
||||||
|
#include <webserv/handler/ErrorHandler.hpp> // for ErrorHandler
|
||||||
|
#include <webserv/handler/FileHandler.hpp> // for FileHandler
|
||||||
|
#include <webserv/handler/URIParser.hpp> // for URIParser
|
||||||
|
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
|
||||||
|
#include <webserv/log/Log.hpp> // for LOCATION, Log
|
||||||
|
|
||||||
|
#include <memory> // for unique_ptr
|
||||||
|
#include <optional> // for optional
|
||||||
|
#include <string> // for basic_string, string
|
||||||
|
|
||||||
|
class LocationConfig;
|
||||||
|
|
||||||
Router::Router() {}
|
Router::Router() {}
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "webserv/config/LocationConfig.hpp"
|
#include <webserv/config/LocationConfig.hpp>
|
||||||
|
#include <webserv/http/HttpRequest.hpp> // for HttpRequest
|
||||||
|
#include <webserv/http/HttpResponse.hpp> // for HttpResponse
|
||||||
|
|
||||||
#include <webserv/http/HttpRequest.hpp>
|
#include <memory> // for unique_ptr
|
||||||
#include <webserv/http/HttpResponse.hpp>
|
#include <string> // for string
|
||||||
|
|
||||||
#include <memory>
|
class LocationConfig;
|
||||||
#include <string>
|
class ServerConfig;
|
||||||
|
|
||||||
class Router
|
class Router
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,17 +1,19 @@
|
|||||||
|
#include <webserv/server/Server.hpp>
|
||||||
|
|
||||||
#include <webserv/client/Client.hpp> // for Client
|
#include <webserv/client/Client.hpp> // for Client
|
||||||
#include <webserv/config/ConfigManager.hpp> // for ConfigManager
|
#include <webserv/config/ConfigManager.hpp> // for ConfigManager
|
||||||
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
|
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
|
||||||
#include <webserv/log/Log.hpp> // for Log
|
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
||||||
#include <webserv/server/Server.hpp>
|
|
||||||
#include <webserv/socket/Socket.hpp> // for Socket
|
#include <webserv/socket/Socket.hpp> // for Socket
|
||||||
|
|
||||||
#include <cerrno> // for errno
|
#include <cerrno> // for errno
|
||||||
#include <cstring> // for strerror, strlen
|
#include <cstring> // for strerror
|
||||||
#include <exception> // for exception
|
#include <exception> // for exception
|
||||||
#include <memory> // for unique_ptr, allocator, make_unique
|
#include <memory> // for unique_ptr, allocator, make_unique
|
||||||
|
#include <optional> // for optional
|
||||||
#include <stdexcept> // for runtime_error
|
#include <stdexcept> // for runtime_error
|
||||||
#include <string> // for basic_string, operator+, to_string, char_traits, string
|
#include <string> // for basic_string, operator+, to_string, char_traits, string
|
||||||
#include <unordered_map> // for unordered_map, unordered_map<>::container_type
|
#include <unordered_map> // for unordered_map, operator==
|
||||||
#include <utility> // for move, pair
|
#include <utility> // for move, pair
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
|
|
||||||
@ -20,6 +22,8 @@
|
|||||||
#include <sys/types.h> // for ssize_t
|
#include <sys/types.h> // for ssize_t
|
||||||
#include <unistd.h> // for close
|
#include <unistd.h> // for close
|
||||||
|
|
||||||
|
class Router;
|
||||||
|
|
||||||
Server::Server(const ConfigManager &configManager)
|
Server::Server(const ConfigManager &configManager)
|
||||||
: epoll_fd_(epoll_create1(0)), configManager_(configManager), router_()
|
: epoll_fd_(epoll_create1(0)), configManager_(configManager), router_()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "webserv/router/Router.hpp"
|
|
||||||
|
|
||||||
#include <webserv/client/Client.hpp>
|
#include <webserv/client/Client.hpp>
|
||||||
#include <webserv/config/ConfigManager.hpp>
|
#include <webserv/config/ConfigManager.hpp>
|
||||||
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
|
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
|
||||||
|
#include <webserv/router/Router.hpp> // for Router
|
||||||
#include <webserv/socket/Socket.hpp> // for Socket
|
#include <webserv/socket/Socket.hpp> // for Socket
|
||||||
|
|
||||||
#include <cstdint> // for uint32_t
|
#include <cstdint> // for uint32_t
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
#include "webserv/log/Log.hpp"
|
|
||||||
|
|
||||||
#include <webserv/utils/FileUtils.hpp>
|
#include <webserv/utils/FileUtils.hpp>
|
||||||
|
|
||||||
#include <cstring> // for strlen
|
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
||||||
#include <fstream>
|
|
||||||
#include <string> // for string
|
|
||||||
|
|
||||||
#include <sys/stat.h> // for stat, S_ISREG, S_ISDIR
|
#include <cstring> // for size_t
|
||||||
|
#include <fstream> // for basic_ifstream, basic_ios, basic_istream, ios, ifstream, operator|, basic_istream::read, basic_istream::seekg, basic_istream::tellg, streamsize
|
||||||
|
#include <iterator> // for istreambuf_iterator, operator==
|
||||||
|
#include <string> // for basic_string, string, char_traits, operator+
|
||||||
|
|
||||||
|
#include <sys/stat.h> // for stat, S_ISDIR, S_ISREG
|
||||||
|
|
||||||
namespace FileUtils
|
namespace FileUtils
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user