LeftHookRoll
An HTTP/1.0 compliant web server, as specified by RFC1945
Loading...
Searching...
No Matches
ServerConf.hpp
Go to the documentation of this file.
1/**
2 * @file ServerConf.hpp
3 * @brief Stores per-server configuration directives.
4 * This class encapsulates the configuration for a specific server block
5 * parsed from the webserv.conf file.
6 */
7#pragma once
8
9#include <string>
10#include <vector>
11#include <map>
12#include <netinet/in.h>
13#include "LocationConf.hpp"
14#include <cstring>
15#include <iostream>
16#include <arpa/inet.h>
17#include "Request.hpp"
18
20{
21 public:
22 // Canonical Form
23 ServerConf();
24 ServerConf(const ServerConf& other);
25 ServerConf& operator=(const ServerConf& other);
27
28 // Getters
29
30 const std::string& getServerName() const;
31 const struct sockaddr_in& getInterfacePortPair() const;
32 size_t getMaxBodySize() const;
33 const std::vector<LocationConf>& getLocations() const;
34 const std::map<std::string, std::string>& getErrorPages() const;
35
36 // Setters
37 void setServerName(const std::string& name);
38 void setInterfacePortPair(const struct sockaddr_in& address);
39 void setMaxBodySize(size_t size);
40
41 /**
42 * @brief Adds a parsed LocationConf block to this server.
43 */
44 void addLocation(const LocationConf& location);
45
46 /**
47 * @brief Adds a custom error page mapping (e.g., "404" -> "/errors/404.html").
48 */
49 void addErrorPage(const std::string& errorCode, const std::string& errorPagePath);
50
51 // Utils
52
53 /**
54 * @brief Retrieves the path to a custom error page if one exists.
55 * @param errorCode The HTTP error code as a string (e.g., "404").
56 * @return The path to the custom error page, or an empty string if none is defined.
57 */
58 std::string getErrorPagePath(const std::string& errorCode) const;
59 /**
60 * @brief Set the Defaults config directives.
61 *
62 */
64 {
65 _serverName = "LeftHookRoll";
66 _maxBodySize = 1024 * 1024;
67 _interfacePortPair.sin_family = AF_INET;
68 _interfacePortPair.sin_addr.s_addr = INADDR_ANY;
69 _interfacePortPair.sin_port = htons(8080);
70 std::cout << "Default " << _serverName << " Listening on "
72 << ntohs(_interfacePortPair.sin_port) << std::endl;
73 }
74 private:
75 // Identity
76 std::string _serverName;
77 struct sockaddr_in _interfacePortPair;
78
79 // Data
81 std::vector<LocationConf> _locations;
82 std::map<std::string, std::string> _errorPages;
83};
Stores per-route configuration directives. This class encapsulates the configuration for a specific l...
Parses and stores the entire HTTP request entity (headers, body). Utilizes a State Machine to handle ...
size_t getMaxBodySize() const
std::string getErrorPagePath(const std::string &errorCode) const
Retrieves the path to a custom error page if one exists.
const struct sockaddr_in & getInterfacePortPair() const
std::string _serverName
void setInterfacePortPair(const struct sockaddr_in &address)
std::vector< LocationConf > _locations
struct sockaddr_in _interfacePortPair
void addErrorPage(const std::string &errorCode, const std::string &errorPagePath)
Adds a custom error page mapping (e.g., "404" -> "/errors/404.html").
std::map< std::string, std::string > _errorPages
void addLocation(const LocationConf &location)
Adds a parsed LocationConf block to this server.
size_t _maxBodySize
const std::vector< LocationConf > & getLocations() const
void setDefaults()
Set the Defaults config directives.
void setServerName(const std::string &name)
const std::string & getServerName() const
void setMaxBodySize(size_t size)
const std::map< std::string, std::string > & getErrorPages() const
ServerConf & operator=(const ServerConf &other)
std::string ipv4ToString(const struct ::sockaddr_in &addr)
Definition Request.cpp:29