Files
42_INT_12_webserv/srcs/webserv/Webserv.hpp
LuckyLaszlo 6f5b28dd93 wip, need somes changes in ConfigParser.
+ _determine_location()
+ http_method changes
+ http_method switch in _construct_response()
+ ConfigParser::_str_to_method_type() moved to global utils.cpp
2022-08-03 18:39:22 +02:00

100 lines
3.1 KiB
C++

#ifndef WEBSERV_HPP
# define WEBSERV_HPP
# include <map>
# include <vector>
# include <exception> // exception, what
# include <stdexcept> // runtime_error, invalid_argument
# include <sys/epoll.h> // epoll
# include <fcntl.h> // fcntl
# include <sys/wait.h> // waitpid
# include <csignal> // signal
# include <fstream> // ifstream
# include <sstream> // stringstream
# include <cerrno> // errno
# include <unistd.h> // close, access
# include <iostream> // cout, cin
# include <cstring> // memset
# include <sys/socket.h> // socket, accept, listen, send, recv, bind, connect, setsockopt, getsockname
# include <arpa/inet.h> // htonl, htons, ntohl, ntohs, inet_addr
# include <netinet/in.h> // sockaddr_in
// # include <netinet/ip.h> // usefull for what ? -> 'man (7) ip' says it's a superset of 'netinet/in.h'
# include <algorithm> // find
# include <string> // string
# include <cstdio> // perror, remove
# include <cstdlib> // atoi (athough it's already cover by <string>)
# include "Client.hpp"
# include "ServerConfig.hpp"
# include "utils.hpp"
extern bool g_run;
extern int g_last_signal;
void signal_handler(int signum);
// these might only be TMP
# define FAILURE -1
# define SUCCESS 1
class Webserv
{
public:
// base.cpp
Webserv();
// Webserv(Webserv const &src);
// what should it take as arg, *, &, ?
// Webserv(std::vector<ServerConfig>& servers);
~Webserv();
// Webserv &operator=(Webserv const &rhs);
// init.cpp
void init_virtual_servers(std::vector<ServerConfig>* servers);
// run_loop.cpp
void run();
private:
int _epfd;
std::vector<int> _listen_sockets;
std::vector<ServerConfig> _servers;
std::vector<Client> _clients;
// accept.cpp
void _accept_connection(int fd);
// request.cpp
void _request(Client *client);
void _read_request(Client *client);
// response.cpp
void _response(Client *client);
void _send_response(Client *client, ServerConfig &server);
void _construct_response(Client *client, ServerConfig &server);
void _insert_status_line(Client *client, ServerConfig &server);
void _get_ressource(Client *client, ServerConfig &server, LocationConfig &location);
void _post(Client *client, ServerConfig &server, LocationConfig &location);
void _delete(Client *client, ServerConfig &server, LocationConfig &location);
ServerConfig &_determine_process_server(Client *client);
LocationConfig &_determine_location(ServerConfig &server, std::string &path);
// cgi_script.cpp
bool _is_cgi(Client *client);
void _exec_cgi(Client *client);
void _construct_client(Client *client);
char** _set_env(Client *client);
char* _dup_env(std::string var, std::string val);
void _exec_script(Client *client, char **env);
// epoll_update.cpp
int _epoll_update(int fd, uint32_t events, int op);
int _epoll_update(int fd, uint32_t events, int op, void *ptr);
// signal.cpp
void _handle_last_signal();
// close.cpp
void _close_client(int fd);
void _close_all_clients();
// init.cpp
void _bind(int socket_fd, in_port_t port, std::string host);
void _listen(int socket_fd, unsigned int max_connections);
};
#endif