From 9c19e936b632c95723c2a0d29ea8a39666dcbfbe Mon Sep 17 00:00:00 2001 From: 3lswear Date: Sun, 16 Jan 2022 23:06:06 +0300 Subject: [PATCH] intermediate changes --- config/example.toml | 25 +++++++++++++++++++++++- includes/webserv.hpp | 2 +- src/config/TOMLNode.hpp | 41 +++++++++++++++++++++++++++++++++++++++ src/config/TOMLParser.hpp | 13 +++++++++++-- src/config/parse.cpp | 3 ++- 5 files changed, 79 insertions(+), 5 deletions(-) diff --git a/config/example.toml b/config/example.toml index 3246478..b2418f2 100644 --- a/config/example.toml +++ b/config/example.toml @@ -1,5 +1,5 @@ [[server]] - name = "jopaserver" + name = "serv1" host = "127.0.0.1" port = 8080 error_page = "error.html" @@ -20,3 +20,26 @@ methods = ["GET"] directory_list = false directory_fallback = "oops.html" + +[[server]] + name = "2222" + host = "10.0.0.1" + port = 8081 + error_page = "error2.html" + body_size_limit = 10 + [[server.location]] + location = "/root2/" + # redirection ??? + root = "/var/www/html/jopa.html" + methods = ["GET", "POST"] + directory_list = true + directory_fallback = "its_a_directory.html" + upload_accept = false + upload_dir = "/var/www/html/upload" + + [[server.location]] + location = "/secret2/" + root = "/var/www/html/secret.html" + methods = ["GET"] + directory_list = false + directory_fallback = "oops.html" diff --git a/includes/webserv.hpp b/includes/webserv.hpp index 2620e81..926a93e 100644 --- a/includes/webserv.hpp +++ b/includes/webserv.hpp @@ -26,7 +26,7 @@ class toml_node; /* typedef std::vector TOMLArray; */ /* typedef std::vector TOMLArrayOfMap; */ typedef std::map TOMLMap; // = JSONObject -typedef std::pair *> TOMLMapArray; +typedef std::vector TOMLMapArray; typedef std::vector TOMLArray; void display(TOMLMap *config); diff --git a/src/config/TOMLNode.hpp b/src/config/TOMLNode.hpp index b7b1175..c7de648 100644 --- a/src/config/TOMLNode.hpp +++ b/src/config/TOMLNode.hpp @@ -88,6 +88,25 @@ class toml_node value.map_array = map_array; type = MAPARRAY; } + + static std::string *TOMLMap_to_string(TOMLMap *map) + { + std::stringstream ss; + std::string *result = new std::string(); + TOMLMap::iterator it; + + for (it = map->begin(); it != map->end(); ++it) + { + ss << it->first + << ": " + << *(it->second->toString()) + << std::endl; + } + + ss >> *result; + return (result); + } + std::string *toString(void) const { switch (type) @@ -116,6 +135,28 @@ class toml_node *result += " ]"; return (result); } + case MAP: + { + return (TOMLMap_to_string(value.map)); + } + case MAPARRAY: + { + std::stringstream ss; + std::string *result = new std::string(); + TOMLMapArray::iterator it; + TOMLMapArray *map_array = value.map_array; + + ss << std::endl; + for (it = map_array->begin(); it != map_array->end(); ++it) + { + ss << (TOMLMap_to_string(*it)); + } + + ss << "-------" << std::endl; + + ss >> *result; + return (result); + } case BOOL: { std::string *result; diff --git a/src/config/TOMLParser.hpp b/src/config/TOMLParser.hpp index 6f423aa..361a032 100644 --- a/src/config/TOMLParser.hpp +++ b/src/config/TOMLParser.hpp @@ -36,6 +36,15 @@ namespace config std::cerr << e.what() << std::endl; break; } + if (nextToken.type == MAPARRAY_DECL) + { + parseMapArray(); + continue; + } + else + { + /* take key make decision */ + } std::string key = nextToken.value; std::cerr << key << std::endl; if (tokenizer.getToken().type != ASSIGN) @@ -257,8 +266,8 @@ namespace config std::string key; key = ""; - /* root = parseMap(); */ - root = parseMapArray(); + root = parseMap(); + /* root = parseMapArray(); */ return (root); /* while (tokenizer.hasMoreTokens()) */ diff --git a/src/config/parse.cpp b/src/config/parse.cpp index c9c31a0..965b6ce 100644 --- a/src/config/parse.cpp +++ b/src/config/parse.cpp @@ -23,7 +23,8 @@ /* } */ namespace config { - void display(toml_node *config) + + void display(toml_node *root_node) { std::cout << ">>> printing config: <<<" << std::endl; if (config->get_type() != toml_node::MAPARRAY)