Webserv
Loading...
Searching...
No Matches
config::ServerConfig Class Reference

A strongly-typed data container for a server block's configuration. More...

#include <ServerConfig.hpp>

Public Member Functions

 ServerConfig ()
 ServerConfig (char const *fpath, bool perform_fs_checks=true)
 Constructs and builds the configuration from a file path.
 ServerConfig (std::string const &content, bool perform_fs_checks=true)
 Constructs and builds the configuration from a string.
ServerBlock const * getServer (int port, http::Request const &req) const
 Retrieves the server configuration that best matches a port and server name.
void addServer (ServerBlock const &server)
 Adds a ServerBlock to the configuration.
ServerBlockMap const & getServersMap () const
 Gets read-only access to the map of server blocks.

Private Member Functions

void build (std::string const &content, bool perform_fs_checks)

Private Attributes

ServerBlockMap servers_
 Map of server blocks, keyed by port number.

Detailed Description

A strongly-typed data container for a server block's configuration.

This class holds the final, validated settings for a single 'server' block after all parsing and semantic validation is complete. It is the definitive configuration used by the webserver at runtime.

Constructor & Destructor Documentation

◆ ServerConfig() [1/3]

config::ServerConfig::ServerConfig ( )

◆ ServerConfig() [2/3]

config::ServerConfig::ServerConfig ( char const * fpath,
bool perform_fs_checks = true )
explicit

Constructs and builds the configuration from a file path.

Parameters
fpathPath to the configuration file.
perform_fs_checksIf true, validates that file paths in the config exist.

◆ ServerConfig() [3/3]

config::ServerConfig::ServerConfig ( std::string const & content,
bool perform_fs_checks = true )
explicit

Constructs and builds the configuration from a string.

Parameters
contentA string containing the full configuration.
perform_fs_checksIf true, validates that file paths in the config exist.

Member Function Documentation

◆ addServer()

void config::ServerConfig::addServer ( ServerBlock const & server)

Adds a ServerBlock to the configuration.

Parameters
serverThe ServerBlock to add.

◆ build()

void config::ServerConfig::build ( std::string const & content,
bool perform_fs_checks )
private

◆ getServer()

ServerBlock const * config::ServerConfig::getServer ( int port,
http::Request const & req ) const

Retrieves the server configuration that best matches a port and server name.

Parameters
portThe port number of the incoming connection.
requestThe request
Returns
A const pointer to the matched ServerBlock, or NULL if no match is found.

◆ getServersMap()

ServerBlockMap const & config::ServerConfig::getServersMap ( ) const

Gets read-only access to the map of server blocks.

Returns
A constant reference to the server block map.

Member Data Documentation

◆ servers_

ServerBlockMap config::ServerConfig::servers_
private

Map of server blocks, keyed by port number.


The documentation for this class was generated from the following files: