mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-28 12:58:00 +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";
|
||||
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;
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ void CgiHandle::printSSmap(std::map<std::string, std::string> &m)
|
||||
{
|
||||
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();
|
||||
for (; it != m.end(); it++)
|
||||
@@ -68,7 +68,7 @@ void CgiHandle::printSSmap(std::map<std::string, std::string> &m)
|
||||
|
||||
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++)
|
||||
{
|
||||
DBOUT << RED << env[i] << ENDL;
|
||||
@@ -92,7 +92,7 @@ std::string CgiHandle::executeCgi()
|
||||
}
|
||||
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);
|
||||
sO = dup(STDOUT_FILENO);
|
||||
@@ -108,7 +108,7 @@ std::string CgiHandle::executeCgi()
|
||||
pid = fork();
|
||||
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)
|
||||
{
|
||||
@@ -116,7 +116,7 @@ std::string CgiHandle::executeCgi()
|
||||
dup2(fdOut, STDOUT_FILENO);
|
||||
execve(_response.getCgiPass().c_str(), argv, env);
|
||||
std::cerr << getDebugTime() << FAIL;
|
||||
perror(" Execve error");
|
||||
perror("Execve error");
|
||||
std::cerr << RESET;
|
||||
write(STDOUT_FILENO, "Status: 500\r\n\r\n", 15);
|
||||
exit(1);
|
||||
|
||||
@@ -185,10 +185,10 @@ std::string Client::generateRespons(std::vector<ServerConfig *> &configs)
|
||||
std::memcpy(_to_send_char, _toSend->c_str(), len + 1);
|
||||
|
||||
//print request
|
||||
std::cerr << WARNING << getDebugTime() << GREEN;
|
||||
std::cerr << WARNING << getDebugTime() << TURGUOISE;
|
||||
if (_request.getCode() != 200)
|
||||
std::cerr << FAIL ;
|
||||
std::cerr << " [ request ] : "
|
||||
std::cerr << "[ request ] : "
|
||||
<< "[method: " << _request.getMethod() << "] "
|
||||
<< "[URI: " << _request.getURI() << " ]";
|
||||
if (_response.getLocation() != NULL)
|
||||
@@ -201,7 +201,7 @@ std::string Client::generateRespons(std::vector<ServerConfig *> &configs)
|
||||
std::cerr << WARNING << getDebugTime() << GREEN;
|
||||
if (_response.getCode() >= 400)
|
||||
std::cerr << FAIL ;
|
||||
std::cerr << " [ response ] : " << "[status: " << _response.getCode()
|
||||
std::cerr << "[ response ] : " << "[status: " << _response.getCode()
|
||||
<< " " << _response.getReasonPhrase(_response.getCode())
|
||||
<< " ] [Content-Length: " << _response.getBodySize() << " ]";
|
||||
if (_response.isRedirect())
|
||||
|
||||
@@ -302,7 +302,7 @@ int Request::parseClientfield(std::string str)
|
||||
value = str.erase(0, distance + 1);
|
||||
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;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -239,7 +239,7 @@ std::string Response::getContentType(void)
|
||||
else if (type == "pdf")
|
||||
return ("application/pdf");
|
||||
else
|
||||
return ("application/octet-stream");
|
||||
return ("text/plain");
|
||||
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ std::string Response::getFullURI(void)
|
||||
ret = tmp;
|
||||
if (_upload_dir.empty())
|
||||
_upload_dir = ret;
|
||||
DBOUT << WARNING << getDebugTime() << OKCYAN << " [fullURI: " << ret << " ]" << ENDL;
|
||||
DBOUT << WARNING << getDebugTime() << OKCYAN << "[fullURI: " << ret << " ]" << ENDL;
|
||||
return (ret);
|
||||
}
|
||||
|
||||
@@ -442,7 +442,7 @@ void Response::invalidClient(void)
|
||||
setHeaderBlocks();
|
||||
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();
|
||||
setHeaderBlocks();
|
||||
generateHeader();
|
||||
DBOUT << WARNING << getDebugTime() << GREEN << " GET Method called" << ENDL;
|
||||
DBOUT << WARNING << getDebugTime() << GREEN << "GET Method called" << ENDL;
|
||||
|
||||
}
|
||||
void Response::methodPost(void)
|
||||
@@ -500,7 +500,7 @@ void Response::methodPost(void)
|
||||
_code = 204;
|
||||
setHeaderBlocks();
|
||||
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();
|
||||
generateHeader();
|
||||
DBOUT << WARNING << getDebugTime() << GREEN << " PUT Method called" << ENDL;
|
||||
DBOUT << WARNING << getDebugTime() << GREEN << "PUT Method called" << ENDL;
|
||||
}
|
||||
|
||||
void Response::methodDelete(void)
|
||||
@@ -543,7 +543,7 @@ void Response::methodDelete(void)
|
||||
OpenErrorFile(_code);
|
||||
setHeaderBlocks();
|
||||
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;
|
||||
if (sent <= 0)
|
||||
{
|
||||
DBOUT << getDebugTime() << FAIL << " SEND FAILED" << ENDL;
|
||||
DBOUT << getDebugTime() << FAIL << "SEND FAILED" << ENDL;
|
||||
client.done = true;
|
||||
}
|
||||
else if (sent > 0)
|
||||
@@ -72,12 +72,12 @@ void Server::readSocket(Client &client, int fd)
|
||||
bytes_read = recv(fd, &stringBUF[0], BUFFSIZE, 0);
|
||||
if (bytes_read == 0)
|
||||
{
|
||||
DBOUT << getDebugTime() << FAIL << " bytes_read 0" << ENDL;
|
||||
DBOUT << getDebugTime() << FAIL << "bytes_read 0" << ENDL;
|
||||
client.done = true;
|
||||
}
|
||||
else if (bytes_read == -1)
|
||||
{
|
||||
DBOUT << getDebugTime() << FAIL << " bytes_read -1" << ENDL;
|
||||
DBOUT << getDebugTime() << FAIL << "bytes_read -1" << ENDL;
|
||||
client.done = true;
|
||||
}
|
||||
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)
|
||||
{
|
||||
DBOUT << WARNING << getDebugTime() << OKCYAN
|
||||
<< " force deleting client "
|
||||
<< "force deleting client "
|
||||
<< fd
|
||||
<< 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")
|
||||
{
|
||||
DBOUT << WARNING << getDebugTime()
|
||||
<< " completely deleting client "
|
||||
<< "completely deleting client "
|
||||
<< fd
|
||||
<< ENDL;
|
||||
|
||||
@@ -125,7 +125,7 @@ inline int Server::delete_client(std::map<int, Client *> &client_map, int fd)
|
||||
else
|
||||
{
|
||||
DBOUT << WARNING << getDebugTime()
|
||||
<< " deleting only client "
|
||||
<< "deleting only client "
|
||||
<< fd
|
||||
<< 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);
|
||||
DBOUT << WARNING << getDebugTime()
|
||||
<< " deleting fd "
|
||||
<< "deleting fd "
|
||||
<< it->first
|
||||
<< ENDL;
|
||||
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);
|
||||
|
||||
std::cerr << getDebugTime() << GREEN
|
||||
<< " listening on "
|
||||
<< "listening on "
|
||||
<< config->getHost()
|
||||
<< ":"
|
||||
<< config->getPort()
|
||||
@@ -330,7 +330,7 @@ void Server::run(void)
|
||||
client_map[fd]->generateRespons(_configs);
|
||||
|
||||
epoll_handle(EPOLL_CTL_MOD, fd, EPOLLOUT);
|
||||
DBOUT << getDebugTime() << " rearmed to EPOLLOUT" << ENDL;
|
||||
DBOUT << getDebugTime() << "rearmed to EPOLLOUT" << ENDL;
|
||||
}
|
||||
}
|
||||
else if (events & EPOLLOUT)
|
||||
|
||||
@@ -22,17 +22,14 @@ std::string getDebugTime(void)
|
||||
{
|
||||
time_t rawtime;
|
||||
struct tm *timeinfo;
|
||||
char buf[32];
|
||||
|
||||
time(&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
|
||||
std::string ret = std::string(asctime(timeinfo));
|
||||
for (size_t i = 0; i < 3; i++)
|
||||
{
|
||||
ret.erase(0, ret.find(" ") + 1);
|
||||
}
|
||||
ret.erase(ret.find(" "));
|
||||
|
||||
int tmp = strftime(buf, 32, "%T", timeinfo);
|
||||
buf[tmp] = '\0';
|
||||
std::string ret = std::string(buf);
|
||||
ret = std::string(WARNING) + "[ " + ret + " ] "
|
||||
+ std::string(RESET)
|
||||
+ std::string(OKCYAN);
|
||||
|
||||
@@ -24,7 +24,7 @@ int main(int argc, char **argv)
|
||||
catch(const ConfigException& e)
|
||||
{
|
||||
std::cerr << RED << "\n" << WARNING << getDebugTime()
|
||||
<< FAIL << " " << e.getMessage() << ENDL;
|
||||
<< FAIL << e.getMessage() << ENDL;
|
||||
}
|
||||
catch (std::domain_error &e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user