fix errors from pedantic
This commit is contained in:
parent
5215edbb45
commit
cc2ed7af56
@ -22,13 +22,13 @@ ValidationResult validateUniversal(const AConfig *config, std::string configType
|
||||
|
||||
for (const auto &directive : DirectiveFactory::supportedDirectives)
|
||||
{
|
||||
if (directive.context.find(std::toupper(configType[0])) != std::string::npos &&
|
||||
if (directive.context.find(static_cast<char>(std::toupper(configType[0]))) != std::string::npos &&
|
||||
!config->owns(std::string(directive.name)))
|
||||
{
|
||||
missingDirectives.emplace_back(directive.name);
|
||||
}
|
||||
if ((directive.context.find(std::toupper(configType[0])) == std::string::npos &&
|
||||
directive.context.find(std::tolower(configType[0])) == std::string::npos) &&
|
||||
if ((directive.context.find(static_cast<char>(std::toupper(static_cast<unsigned char>(configType[0])))) == std::string::npos &&
|
||||
directive.context.find(static_cast<char>(std::tolower(static_cast<unsigned char>(configType[0])))) == std::string::npos) &&
|
||||
config->owns(std::string(directive.name)))
|
||||
{
|
||||
prohibitedDirectives.emplace_back(directive.name);
|
||||
|
||||
@ -4,14 +4,15 @@
|
||||
#include <webserv/http/HttpResponse.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <sys/types.h>
|
||||
|
||||
class ErrorHandler
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr<HttpResponse> getErrorResponse(int statusCode, const AConfig *config = nullptr);
|
||||
static std::unique_ptr<HttpResponse> getErrorResponse(uint16_t statusCode, const AConfig *config = nullptr);
|
||||
|
||||
private:
|
||||
static std::string generateErrorPage(int statusCode, const AConfig *config = nullptr);
|
||||
static std::string generateDefaultErrorPage(int statusCode);
|
||||
static std::string generateErrorPage(uint16_t statusCode, const AConfig *config = nullptr);
|
||||
static std::string generateDefaultErrorPage(uint16_t statusCode);
|
||||
static std::string getErrorPageFile(const std::string &path);
|
||||
};
|
||||
@ -10,8 +10,9 @@
|
||||
#include <memory>
|
||||
#include <sstream> // for basic_stringstream
|
||||
#include <string> // for basic_string, operator+, allocator, char_traits, string, to_string
|
||||
#include <sys/types.h>
|
||||
|
||||
std::unique_ptr<HttpResponse> ErrorHandler::getErrorResponse(int statusCode, const AConfig *config)
|
||||
std::unique_ptr<HttpResponse> ErrorHandler::getErrorResponse(uint16_t statusCode, const AConfig *config)
|
||||
{
|
||||
std::string statusMessage = Http::getStatusCodeReason(statusCode);
|
||||
Log::warning("Generating error response: " + std::to_string(statusCode) + " " + statusMessage);
|
||||
@ -25,7 +26,7 @@ std::unique_ptr<HttpResponse> ErrorHandler::getErrorResponse(int statusCode, con
|
||||
return response;
|
||||
}
|
||||
|
||||
std::string ErrorHandler::generateErrorPage(int statusCode, const AConfig *config)
|
||||
std::string ErrorHandler::generateErrorPage(uint16_t statusCode, const AConfig *config)
|
||||
{
|
||||
Log::trace(LOCATION);
|
||||
if (config == nullptr)
|
||||
@ -46,7 +47,7 @@ std::string ErrorHandler::generateErrorPage(int statusCode, const AConfig *confi
|
||||
return generateDefaultErrorPage(statusCode);
|
||||
}
|
||||
|
||||
std::string ErrorHandler::generateDefaultErrorPage(int statusCode)
|
||||
std::string ErrorHandler::generateDefaultErrorPage(uint16_t statusCode)
|
||||
{
|
||||
Log::info("Generating default error page");
|
||||
std::string statusMessage = Http::getStatusCodeReason(statusCode);
|
||||
|
||||
@ -8,8 +8,7 @@
|
||||
|
||||
#include <optional> // for optional
|
||||
|
||||
#include <stddef.h> // for size_t
|
||||
#include <sys/stat.h> // for stat, S_ISDIR, S_ISREG
|
||||
#include <cstddef> // for size_t
|
||||
|
||||
URI::URI(const HttpRequest &request, const ServerConfig &serverConfig)
|
||||
: uriTrimmed_(utils::trim(request.getTarget(), "/")), config_(matchConfig(uriTrimmed_, serverConfig))
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sys/types.h>
|
||||
|
||||
HttpResponse::HttpResponse() : headers_(std::make_unique<HttpHeaders>()) {}
|
||||
|
||||
@ -34,7 +35,7 @@ void HttpResponse::setBody(const std::string &body)
|
||||
setComplete();
|
||||
}
|
||||
|
||||
void HttpResponse::setStatus(int statusCode)
|
||||
void HttpResponse::setStatus(uint16_t statusCode)
|
||||
{
|
||||
statusCode_ = statusCode;
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ class HttpResponse
|
||||
|
||||
void setComplete();
|
||||
|
||||
void setStatus(int statusCode);
|
||||
void setStatus(uint16_t statusCode);
|
||||
|
||||
[[nodiscard]] bool isComplete() const;
|
||||
|
||||
@ -47,5 +47,5 @@ class HttpResponse
|
||||
std::vector<uint8_t> body_;
|
||||
std::unique_ptr<HttpHeaders> headers_;
|
||||
bool complete_ = false;
|
||||
int statusCode_ = 200;
|
||||
uint16_t statusCode_ = 200;
|
||||
};
|
||||
@ -15,7 +15,7 @@ std::string Channel::printContext(const std::map<std::string, std::string> &cont
|
||||
if (value.find('\n') != std::string::npos)
|
||||
{
|
||||
|
||||
ss << "\t| " << std::right << std::setfill(' ') << "\e[1m" << key << "\e[0m" << " : \n";
|
||||
ss << "\t| " << std::right << std::setfill(' ') << "\033[1m" << key << "\033[0m" << " : \n";
|
||||
std::istringstream valueStream(value);
|
||||
std::string line;
|
||||
while (std::getline(valueStream, line))
|
||||
@ -24,7 +24,7 @@ std::string Channel::printContext(const std::map<std::string, std::string> &cont
|
||||
}
|
||||
continue;
|
||||
}
|
||||
ss << "\t| " << std::right << std::setfill(' ') << "\e[1m" << key << "\e[0m" << " : " << value << "\n";
|
||||
ss << "\t| " << std::right << std::setfill(' ') << "\033[1m" << key << "\033[0m" << " : " << value << "\n";
|
||||
}
|
||||
ss << "\n";
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ void Socket::bind(const std::string &host, const int port) const
|
||||
address.sin_addr.s_addr = inet_addr(host.c_str());
|
||||
address.sin_port = htons(port);
|
||||
|
||||
if (::bind(fd_, (struct sockaddr *)&address, sizeof(address)) < 0) // NOLINT(cppcoreguidelines-pro-type-cstyle-cast
|
||||
if (::bind(fd_, reinterpret_cast<struct sockaddr *>(&address), sizeof(address)) < 0) //NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
|
||||
{
|
||||
Log::fatal("Cannot bind to " + host + ":" + std::to_string(port) +
|
||||
" - address already in use or permission denied");
|
||||
|
||||
@ -80,9 +80,14 @@ std::vector<char> readBinaryFile(const std::string &filepath)
|
||||
}
|
||||
|
||||
std::streamsize size = file.tellg();
|
||||
if (size < 0)
|
||||
{
|
||||
Log::error("Failed to determine file size: " + filepath);
|
||||
return {};
|
||||
}
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
std::vector<char> buffer(size);
|
||||
std::vector<char> buffer(static_cast<size_t>(size));
|
||||
if (!file.read(buffer.data(), size))
|
||||
{
|
||||
Log::error("Failed to read file: " + filepath);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user