Skip to content

Commit

Permalink
chore: added defaultServer flag to ServerConfig
Browse files Browse the repository at this point in the history
- cleaned up main and improved parser printing
  • Loading branch information
Taanviir committed May 2, 2024
1 parent e04a7e0 commit 7cd4bd7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
7 changes: 4 additions & 3 deletions sources/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ int main(int argc, char** argv)
string configFile = (argc == 2) ? argv[1] : "./configs/default.conf";

ConfigParser& parser = ConfigParser::get_instance(configFile);
vector<ServerConfig> configs = parser.parse();
vector<ServerConfig> servers = parser.parse();
Logger::log_message("Parsing " + configFile, INFO);

// configs[0].print();
Server& webserv = Server::get_instance(configs[0], 10);
// for (size_t i = 0; i < servers.size(); i++)
// servers[i].print();
Server& webserv = Server::get_instance(servers[0], 10);
#if defined(__LINUX__)
webserv.start(SELECT);
#elif defined(__MAC__)
Expand Down
16 changes: 9 additions & 7 deletions sources/server/ServerConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,31 @@ struct Location {
struct ServerConfig {
fd port;
in_addr_t host;
bool defaultServer;
string serverName;
string root;
string indexFile;
bool autoindex;
size_t maxBodySize;
map<STATUS_CODE, string> errorPages;
map<STATUS_CODE, string> errorPages; //! maybe need default values
vector<Location> locations;

ServerConfig()
: port(8080), host(htonl(INADDR_ANY)), indexFile("index.html"), autoindex(false),
maxBodySize(1000000)
: port(8080), host(htonl(INADDR_ANY)), defaultServer(false),
indexFile("index.html"), autoindex(false), maxBodySize(1000000)
{}

void print(void) const
{
cout << "ServerConfig {" << endl;
cout << " port: " << port << endl;
cout << " host: " << inet_ntoa(*(struct in_addr*) &host) << endl;
cout << " maxBodySize: " << maxBodySize << endl;
cout << " indexFile: " << indexFile << endl;
cout << " autoindex: " << autoindex << endl;
cout << " default_server: " << (defaultServer == true ? "yes" : "no") << endl;
cout << " serverName: [" << serverName << "]" << endl;
cout << " root: " << root << endl;
cout << " indexFile: " << indexFile << endl;
cout << " autoindex: " << (autoindex == true ? "yes" : "no") << endl;
cout << " maxBodySize: " << maxBodySize << endl;
cout << " locations: [" << endl;
for (vector<Location>::const_iterator itr = locations.begin();
itr != locations.end(); ++itr)
Expand All @@ -48,7 +50,7 @@ struct ServerConfig {
cout << " uri: " << itr->uri << endl;
cout << " root: " << itr->root << endl;
cout << " indexFile: " << indexFile << endl;
cout << " autoindex: " << itr->autoindex << endl;
cout << " autoindex: " << (autoindex == true ? "yes" : "no") << endl;
cout << " maxBodySize: " << itr->maxBodySize << endl;
cout << " methods: [";
for (vector<string>::const_iterator itr2 = itr->methods.begin();
Expand Down

0 comments on commit 7cd4bd7

Please sign in to comment.