mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-28 21:07:59 +03:00
upstream changes (src)
This commit is contained in:
@@ -23,7 +23,7 @@ std::string Autoindex::getPage(std::string path, std::string allpath, std::strin
|
|||||||
<p>\n";
|
<p>\n";
|
||||||
if (dir == NULL)
|
if (dir == NULL)
|
||||||
{
|
{
|
||||||
DBOUT << WARNING << getDebugTime() << FAIL << " AutoindexError: could not open \""
|
DBOUT << WARNING << getDebugTime() << FAIL << "AutoindexError: could not open \""
|
||||||
<< allpath << "\" directory." << ZERO_C << std::endl;
|
<< allpath << "\" directory." << ZERO_C << std::endl;
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ void CgiHandle::printSSmap(std::map<std::string, std::string> &m)
|
|||||||
{
|
{
|
||||||
std::map<std::string, std::string>::iterator it;
|
std::map<std::string, std::string>::iterator it;
|
||||||
|
|
||||||
DBOUT << WARNING << getDebugTime() << FAIL << " Print MAP" << ENDL;
|
DBOUT << WARNING << getDebugTime() << FAIL << "Print MAP" << ENDL;
|
||||||
|
|
||||||
it = m.begin();
|
it = m.begin();
|
||||||
for (; it != m.end(); it++)
|
for (; it != m.end(); it++)
|
||||||
@@ -68,7 +68,7 @@ void CgiHandle::printSSmap(std::map<std::string, std::string> &m)
|
|||||||
|
|
||||||
void printenv(char **env)
|
void printenv(char **env)
|
||||||
{
|
{
|
||||||
DBOUT << WARNING << getDebugTime() << FAIL << " Print env" << ENDL;
|
DBOUT << WARNING << getDebugTime() << FAIL << "Print env" << ENDL;
|
||||||
for(size_t i = 0; env[i]; i++)
|
for(size_t i = 0; env[i]; i++)
|
||||||
{
|
{
|
||||||
DBOUT << RED << env[i] << ENDL;
|
DBOUT << RED << env[i] << ENDL;
|
||||||
@@ -92,7 +92,7 @@ std::string CgiHandle::executeCgi()
|
|||||||
}
|
}
|
||||||
catch(const std::bad_alloc& e)
|
catch(const std::bad_alloc& e)
|
||||||
{
|
{
|
||||||
std::cerr << WARNING << getDebugTime() << FAIL << " " << e.what() << ENDL;
|
std::cerr << WARNING << getDebugTime() << FAIL << e.what() << ENDL;
|
||||||
}
|
}
|
||||||
sI = dup(STDIN_FILENO);
|
sI = dup(STDIN_FILENO);
|
||||||
sO = dup(STDOUT_FILENO);
|
sO = dup(STDOUT_FILENO);
|
||||||
@@ -108,7 +108,7 @@ std::string CgiHandle::executeCgi()
|
|||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid == -1)
|
if (pid == -1)
|
||||||
{
|
{
|
||||||
std::cerr << WARNING << getDebugTime() << FAIL << " Pid = -1. Fork error."<< ENDL;
|
std::cerr << WARNING << getDebugTime() << FAIL << "Pid = -1. Fork error."<< ENDL;
|
||||||
}
|
}
|
||||||
else if (pid == 0)
|
else if (pid == 0)
|
||||||
{
|
{
|
||||||
@@ -116,7 +116,7 @@ std::string CgiHandle::executeCgi()
|
|||||||
dup2(fdOut, STDOUT_FILENO);
|
dup2(fdOut, STDOUT_FILENO);
|
||||||
execve(_response.getCgiPass().c_str(), argv, env);
|
execve(_response.getCgiPass().c_str(), argv, env);
|
||||||
std::cerr << getDebugTime() << FAIL;
|
std::cerr << getDebugTime() << FAIL;
|
||||||
perror(" Execve error");
|
perror("Execve error");
|
||||||
std::cerr << RESET;
|
std::cerr << RESET;
|
||||||
write(STDOUT_FILENO, "Status: 500\r\n\r\n", 15);
|
write(STDOUT_FILENO, "Status: 500\r\n\r\n", 15);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|||||||
@@ -185,10 +185,10 @@ std::string Client::generateRespons(std::vector<ServerConfig *> &configs)
|
|||||||
std::memcpy(_to_send_char, _toSend->c_str(), len + 1);
|
std::memcpy(_to_send_char, _toSend->c_str(), len + 1);
|
||||||
|
|
||||||
//print request
|
//print request
|
||||||
std::cerr << WARNING << getDebugTime() << GREEN;
|
std::cerr << WARNING << getDebugTime() << TURGUOISE;
|
||||||
if (_request.getCode() != 200)
|
if (_request.getCode() != 200)
|
||||||
std::cerr << FAIL ;
|
std::cerr << FAIL ;
|
||||||
std::cerr << " [ request ] : "
|
std::cerr << "[ request ] : "
|
||||||
<< "[method: " << _request.getMethod() << "] "
|
<< "[method: " << _request.getMethod() << "] "
|
||||||
<< "[URI: " << _request.getURI() << " ]";
|
<< "[URI: " << _request.getURI() << " ]";
|
||||||
if (_response.getLocation() != NULL)
|
if (_response.getLocation() != NULL)
|
||||||
@@ -201,7 +201,7 @@ std::string Client::generateRespons(std::vector<ServerConfig *> &configs)
|
|||||||
std::cerr << WARNING << getDebugTime() << GREEN;
|
std::cerr << WARNING << getDebugTime() << GREEN;
|
||||||
if (_response.getCode() >= 400)
|
if (_response.getCode() >= 400)
|
||||||
std::cerr << FAIL ;
|
std::cerr << FAIL ;
|
||||||
std::cerr << " [ response ] : " << "[status: " << _response.getCode()
|
std::cerr << "[ response ] : " << "[status: " << _response.getCode()
|
||||||
<< " " << _response.getReasonPhrase(_response.getCode())
|
<< " " << _response.getReasonPhrase(_response.getCode())
|
||||||
<< " ] [Content-Length: " << _response.getBodySize() << " ]";
|
<< " ] [Content-Length: " << _response.getBodySize() << " ]";
|
||||||
if (_response.isRedirect())
|
if (_response.isRedirect())
|
||||||
|
|||||||
@@ -302,7 +302,7 @@ int Request::parseClientfield(std::string str)
|
|||||||
value = str.erase(0, distance + 1);
|
value = str.erase(0, distance + 1);
|
||||||
if (_headerField.find(key) != _headerField.end())
|
if (_headerField.find(key) != _headerField.end())
|
||||||
{
|
{
|
||||||
DBOUT << WARNING << getDebugTime() << FAIL << " [Pars-error] : [double header-field: " << key << " ] [method: "
|
DBOUT << WARNING << getDebugTime() << FAIL << "[Pars-error] : [double header-field: " << key << " ] [method: "
|
||||||
<< _method << " ]" << " [target: " << _URI << " ]" << ENDL;
|
<< _method << " ]" << " [target: " << _URI << " ]" << ENDL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ std::string Response::getContentType(void)
|
|||||||
else if (type == "pdf")
|
else if (type == "pdf")
|
||||||
return ("application/pdf");
|
return ("application/pdf");
|
||||||
else
|
else
|
||||||
return ("application/octet-stream");
|
return ("text/plain");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,7 +303,7 @@ std::string Response::getFullURI(void)
|
|||||||
ret = tmp;
|
ret = tmp;
|
||||||
if (_upload_dir.empty())
|
if (_upload_dir.empty())
|
||||||
_upload_dir = ret;
|
_upload_dir = ret;
|
||||||
DBOUT << WARNING << getDebugTime() << OKCYAN << " [fullURI: " << ret << " ]" << ENDL;
|
DBOUT << WARNING << getDebugTime() << OKCYAN << "[fullURI: " << ret << " ]" << ENDL;
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,7 +442,7 @@ void Response::invalidClient(void)
|
|||||||
setHeaderBlocks();
|
setHeaderBlocks();
|
||||||
generateHeader();
|
generateHeader();
|
||||||
|
|
||||||
DBOUT << WARNING << getDebugTime() << FAIL << " Error Method called" << ENDL;
|
DBOUT << WARNING << getDebugTime() << FAIL << "Error Method called" << ENDL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -472,7 +472,7 @@ void Response::methodGet(void)
|
|||||||
generateBody();
|
generateBody();
|
||||||
setHeaderBlocks();
|
setHeaderBlocks();
|
||||||
generateHeader();
|
generateHeader();
|
||||||
DBOUT << WARNING << getDebugTime() << GREEN << " GET Method called" << ENDL;
|
DBOUT << WARNING << getDebugTime() << GREEN << "GET Method called" << ENDL;
|
||||||
|
|
||||||
}
|
}
|
||||||
void Response::methodPost(void)
|
void Response::methodPost(void)
|
||||||
@@ -500,7 +500,7 @@ void Response::methodPost(void)
|
|||||||
_code = 204;
|
_code = 204;
|
||||||
setHeaderBlocks();
|
setHeaderBlocks();
|
||||||
generateHeader();
|
generateHeader();
|
||||||
DBOUT << WARNING << getDebugTime() << GREEN << " POST Method called" << ENDL;
|
DBOUT << WARNING << getDebugTime() << GREEN << "POST Method called" << ENDL;
|
||||||
\
|
\
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,7 +525,7 @@ void Response::methodPut(void)
|
|||||||
}
|
}
|
||||||
setHeaderBlocks();
|
setHeaderBlocks();
|
||||||
generateHeader();
|
generateHeader();
|
||||||
DBOUT << WARNING << getDebugTime() << GREEN << " PUT Method called" << ENDL;
|
DBOUT << WARNING << getDebugTime() << GREEN << "PUT Method called" << ENDL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Response::methodDelete(void)
|
void Response::methodDelete(void)
|
||||||
@@ -543,7 +543,7 @@ void Response::methodDelete(void)
|
|||||||
OpenErrorFile(_code);
|
OpenErrorFile(_code);
|
||||||
setHeaderBlocks();
|
setHeaderBlocks();
|
||||||
generateHeader();
|
generateHeader();
|
||||||
DBOUT << WARNING << getDebugTime() << GREEN << " DELETE Method called" << ENDL;
|
DBOUT << WARNING << getDebugTime() << GREEN << "DELETE Method called" << ENDL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ void Server::sendData(Client &client, int fd)
|
|||||||
" to client " << fd << ENDL;
|
" to client " << fd << ENDL;
|
||||||
if (sent <= 0)
|
if (sent <= 0)
|
||||||
{
|
{
|
||||||
DBOUT << getDebugTime() << FAIL << " SEND FAILED" << ENDL;
|
DBOUT << getDebugTime() << FAIL << "SEND FAILED" << ENDL;
|
||||||
client.done = true;
|
client.done = true;
|
||||||
}
|
}
|
||||||
else if (sent > 0)
|
else if (sent > 0)
|
||||||
@@ -72,12 +72,12 @@ void Server::readSocket(Client &client, int fd)
|
|||||||
bytes_read = recv(fd, &stringBUF[0], BUFFSIZE, 0);
|
bytes_read = recv(fd, &stringBUF[0], BUFFSIZE, 0);
|
||||||
if (bytes_read == 0)
|
if (bytes_read == 0)
|
||||||
{
|
{
|
||||||
DBOUT << getDebugTime() << FAIL << " bytes_read 0" << ENDL;
|
DBOUT << getDebugTime() << FAIL << "bytes_read 0" << ENDL;
|
||||||
client.done = true;
|
client.done = true;
|
||||||
}
|
}
|
||||||
else if (bytes_read == -1)
|
else if (bytes_read == -1)
|
||||||
{
|
{
|
||||||
DBOUT << getDebugTime() << FAIL << " bytes_read -1" << ENDL;
|
DBOUT << getDebugTime() << FAIL << "bytes_read -1" << ENDL;
|
||||||
client.done = true;
|
client.done = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -94,7 +94,7 @@ void Server::readSocket(Client &client, int fd)
|
|||||||
inline int Server::delete_client_force(std::map<int, Client *> &client_map, int fd)
|
inline int Server::delete_client_force(std::map<int, Client *> &client_map, int fd)
|
||||||
{
|
{
|
||||||
DBOUT << WARNING << getDebugTime() << OKCYAN
|
DBOUT << WARNING << getDebugTime() << OKCYAN
|
||||||
<< " force deleting client "
|
<< "force deleting client "
|
||||||
<< fd
|
<< fd
|
||||||
<< ENDL;
|
<< ENDL;
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ inline int Server::delete_client(std::map<int, Client *> &client_map, int fd)
|
|||||||
if (client_map[fd]->getRequest().getConnection() == "close")
|
if (client_map[fd]->getRequest().getConnection() == "close")
|
||||||
{
|
{
|
||||||
DBOUT << WARNING << getDebugTime()
|
DBOUT << WARNING << getDebugTime()
|
||||||
<< " completely deleting client "
|
<< "completely deleting client "
|
||||||
<< fd
|
<< fd
|
||||||
<< ENDL;
|
<< ENDL;
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ inline int Server::delete_client(std::map<int, Client *> &client_map, int fd)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
DBOUT << WARNING << getDebugTime()
|
DBOUT << WARNING << getDebugTime()
|
||||||
<< " deleting only client "
|
<< "deleting only client "
|
||||||
<< fd
|
<< fd
|
||||||
<< ENDL;
|
<< ENDL;
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ inline int Server::delete_fd(std::map<int, t_fd_info *> &map,
|
|||||||
{
|
{
|
||||||
epoll_handle(EPOLL_CTL_DEL, it->first, 0);
|
epoll_handle(EPOLL_CTL_DEL, it->first, 0);
|
||||||
DBOUT << WARNING << getDebugTime()
|
DBOUT << WARNING << getDebugTime()
|
||||||
<< " deleting fd "
|
<< "deleting fd "
|
||||||
<< it->first
|
<< it->first
|
||||||
<< ENDL;
|
<< ENDL;
|
||||||
delete it->second;
|
delete it->second;
|
||||||
@@ -191,7 +191,7 @@ void Server::setup_server_socks(std::map<int, Socket> &configurations_map)
|
|||||||
add_to_epoll_list(server_sock.getFd(), server_events);
|
add_to_epoll_list(server_sock.getFd(), server_events);
|
||||||
|
|
||||||
std::cerr << getDebugTime() << GREEN
|
std::cerr << getDebugTime() << GREEN
|
||||||
<< " listening on "
|
<< "listening on "
|
||||||
<< config->getHost()
|
<< config->getHost()
|
||||||
<< ":"
|
<< ":"
|
||||||
<< config->getPort()
|
<< config->getPort()
|
||||||
@@ -330,7 +330,7 @@ void Server::run(void)
|
|||||||
client_map[fd]->generateRespons(_configs);
|
client_map[fd]->generateRespons(_configs);
|
||||||
|
|
||||||
epoll_handle(EPOLL_CTL_MOD, fd, EPOLLOUT);
|
epoll_handle(EPOLL_CTL_MOD, fd, EPOLLOUT);
|
||||||
DBOUT << getDebugTime() << " rearmed to EPOLLOUT" << ENDL;
|
DBOUT << getDebugTime() << "rearmed to EPOLLOUT" << ENDL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (events & EPOLLOUT)
|
else if (events & EPOLLOUT)
|
||||||
|
|||||||
@@ -22,17 +22,14 @@ std::string getDebugTime(void)
|
|||||||
{
|
{
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm *timeinfo;
|
struct tm *timeinfo;
|
||||||
|
char buf[32];
|
||||||
|
|
||||||
time(&rawtime);
|
time(&rawtime);
|
||||||
timeinfo = localtime(&rawtime);
|
timeinfo = localtime(&rawtime);
|
||||||
|
|
||||||
std::string ret = std::string(asctime(timeinfo));
|
int tmp = strftime(buf, 32, "%T", timeinfo);
|
||||||
for (size_t i = 0; i < 3; i++)
|
buf[tmp] = '\0';
|
||||||
{
|
std::string ret = std::string(buf);
|
||||||
ret.erase(0, ret.find(" ") + 1);
|
|
||||||
}
|
|
||||||
ret.erase(ret.find(" "));
|
|
||||||
|
|
||||||
ret = std::string(WARNING) + "[ " + ret + " ] "
|
ret = std::string(WARNING) + "[ " + ret + " ] "
|
||||||
+ std::string(RESET)
|
+ std::string(RESET)
|
||||||
+ std::string(OKCYAN);
|
+ std::string(OKCYAN);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ int main(int argc, char **argv)
|
|||||||
catch(const ConfigException& e)
|
catch(const ConfigException& e)
|
||||||
{
|
{
|
||||||
std::cerr << RED << "\n" << WARNING << getDebugTime()
|
std::cerr << RED << "\n" << WARNING << getDebugTime()
|
||||||
<< FAIL << " " << e.getMessage() << ENDL;
|
<< FAIL << e.getMessage() << ENDL;
|
||||||
}
|
}
|
||||||
catch (std::domain_error &e)
|
catch (std::domain_error &e)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user