diff --git a/src/Client/Client.cpp b/src/Client/Client.cpp index dfc6599..b4b437d 100644 --- a/src/Client/Client.cpp +++ b/src/Client/Client.cpp @@ -189,8 +189,7 @@ std::string Client::generateRespons(std::vector &configs) std::cout << GREEN << "Response Header\n{" << ENDL; std::cout << BLUE << _response.getHeader() << GREEN << "}" << PINK << "]]\n"<< ENDL; delete _toSend; - if (_request.getBody() != NULL) - _request.freeData(); + _request.freeData(); _response.freeData(); return (_headerToSend); } @@ -267,7 +266,12 @@ void Client::clear(void) _bodyToSend = ""; _headerToSend = ""; if (_to_send_char) + { delete[] _to_send_char; + _to_send_char = NULL; + } + _request.freeData(); + _response.freeData(); } Client::~Client() diff --git a/src/Client/Request.cpp b/src/Client/Request.cpp index cf74ab5..bc5e41c 100644 --- a/src/Client/Request.cpp +++ b/src/Client/Request.cpp @@ -36,7 +36,11 @@ Request::Request(char *str) void Request::freeData(void) { - delete _body; + if (_body != NULL) + { + delete _body; + _body = NULL; + } } std::string &Request::getURI(void) diff --git a/src/Client/Response.cpp b/src/Client/Response.cpp index a39a609..6ffb65a 100644 --- a/src/Client/Response.cpp +++ b/src/Client/Response.cpp @@ -16,8 +16,15 @@ Response::Response() void Response::freeData(void) { if (_body != NULL) + { delete _body; - delete _header; + _body = NULL; + } + else if (_header != NULL) + { + delete _header; + _header = NULL; + } } std::string Response::getHeader(void) diff --git a/src/Server/Server.cpp b/src/Server/Server.cpp index c7b009c..1a3afcd 100644 --- a/src/Server/Server.cpp +++ b/src/Server/Server.cpp @@ -27,10 +27,13 @@ void Server::readConfig(char *filename) arr = parser.root->find("server")->second->getMapArray(); it = arr->begin(); + ServerConfig *tmp; while (it != arr->end()) { - _configs.push_back(new ServerConfig(*it)); + tmp = new ServerConfig(*it); + _configs.push_back(tmp); + tmp->fillFields(); ++it; } diff --git a/src/Server/ServerConfig.cpp b/src/Server/ServerConfig.cpp index 7c2b61b..8e74041 100644 --- a/src/Server/ServerConfig.cpp +++ b/src/Server/ServerConfig.cpp @@ -14,7 +14,7 @@ ServerConfig::ServerConfig(TOMLMap *map) _clientBodySize = -1; _port = 0; - fillFields(); + // fillFields(); } //--------------------------------------------------GET/SET--------------------------------------- @@ -199,61 +199,91 @@ int ServerConfig::putLocation(toml_node *node) if (it1->first == "location") { if (it1->second->get_type() != toml_node::STRING) + { + delete tmp; throw ConfigException(getWrongTypeErrorMSG("location", toml_node::STRING, it1->second->get_type())); + } tmp->location = *it1->second->getString(); } else if (it1->first == "root") { if (it1->second->get_type() != toml_node::STRING) + { + delete tmp; throw ConfigException(getWrongTypeErrorMSG("root", toml_node::STRING, it1->second->get_type())); + } tmp->root = *it1->second->getString(); } else if (it1->first == "autoindex") { if (it1->second->get_type() != toml_node::BOOL) + { + delete tmp; throw ConfigException(getWrongTypeErrorMSG("autoindex", toml_node::BOOL, it1->second->get_type())); + } tmp->autoindex = it1->second->getBool(); } else if (it1->first == "upload_accept") { if (it1->second->get_type() != toml_node::BOOL) + { + delete tmp; throw ConfigException(getWrongTypeErrorMSG("upload_accept", toml_node::BOOL, it1->second->get_type())); + } tmp->uploadAccept = it1->second->getBool(); } else if (it1->first == "upload_dir") { if (it1->second->get_type() != toml_node::STRING) + { + delete tmp; throw ConfigException(getWrongTypeErrorMSG("upload_dir", toml_node::STRING, it1->second->get_type())); + } tmp->uploadDir = *it1->second->getString(); } else if (it1->first == "cgi_pass") { if (it1->second->get_type() != toml_node::STRING) + { + delete tmp; throw ConfigException(getWrongTypeErrorMSG("cgi_pass", toml_node::STRING, it1->second->get_type())); + } tmp->cgi_pass = *it1->second->getString(); } else if (it1->first == "body_size_limit") { if (it1->second->get_type() != toml_node::NUM) + { + delete tmp; throw ConfigException(getWrongTypeErrorMSG("body_size_limit", toml_node::NUM, it1->second->get_type())); + } tmp->clientBodySize = it1->second->getNum(); } else if (it1->first == "directory_file") { if (it1->second->get_type() != toml_node::STRING) + { + delete tmp; throw ConfigException(getWrongTypeErrorMSG("directory_file", toml_node::STRING, it1->second->get_type())); + } tmp->directoryFile = *it1->second->getString(); } else if (it1->first == "methods") { if (it1->second->get_type() != toml_node::ARRAY) + { + delete tmp; throw ConfigException(getWrongTypeErrorMSG("methods", toml_node::ARRAY, it1->second->get_type())); + } Array = *it1->second->getArray(); it2 = Array.begin(); while (it2 != Array.end()) { if ((*it2)->get_type() != toml_node::STRING) + { + delete tmp; throw ConfigException(getWrongTypeErrorMSG("methods elem", toml_node::STRING, (*it2)->get_type())); + } tmp->methods.push_back(*((*it2)->getString())); ++it2; } @@ -261,17 +291,29 @@ int ServerConfig::putLocation(toml_node *node) else if (it1->first == "redirect") { if (it1->second->get_type() != toml_node::ARRAY) + { + delete tmp; throw ConfigException(getWrongTypeErrorMSG("redirect", toml_node::ARRAY, it1->second->get_type())); + } Array = *it1->second->getArray(); if (Array.size() != 2) + { + delete tmp; throw ConfigException("The redirect field specified the wrong number of arguments!"); + } it2 = Array.begin(); if ((*it2)->get_type() != toml_node::STRING) + { + delete tmp; throw ConfigException(getWrongTypeErrorMSG("redirect elem", toml_node::STRING, (*it2)->get_type())); + } str = *(*it2)->getString(); ++it2; if ((*it2)->get_type() != toml_node::STRING) + { + delete tmp; throw ConfigException(getWrongTypeErrorMSG("redirect elem", toml_node::STRING, (*it2)->get_type())); + } tmp->redirect.insert(std::make_pair(atoi(str.c_str()), *(*it2)->getString())); } else