Merge remote-tracking branch 'origin/fara' into roman

This commit is contained in:
3lswear
2022-02-20 16:18:44 +03:00
5 changed files with 66 additions and 6 deletions

View File

@@ -189,7 +189,6 @@ std::string Client::generateRespons(std::vector<ServerConfig *> &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();
_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()

View File

@@ -35,8 +35,12 @@ Request::Request(char *str)
//-------------------------------------------------Get/Set---------------------------------------
void Request::freeData(void)
{
if (_body != NULL)
{
delete _body;
_body = NULL;
}
}
std::string &Request::getURI(void)

View File

@@ -16,8 +16,15 @@ Response::Response()
void Response::freeData(void)
{
if (_body != NULL)
{
delete _body;
_body = NULL;
}
else if (_header != NULL)
{
delete _header;
_header = NULL;
}
}
std::string Response::getHeader(void)

View File

@@ -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;
}

View File

@@ -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