92 lines
2.3 KiB
C++
92 lines
2.3 KiB
C++
|
|
#ifndef WEBSERV_HPP
|
|
# define WEBSERV_HPP
|
|
|
|
# include <map>
|
|
# include <vector>
|
|
# include <exception>
|
|
# include <stdexcept>
|
|
# include <string>
|
|
# include <sstream> // stringstream
|
|
# include <cerrno> // errno
|
|
# include <cstdio> // perror
|
|
# 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 <netinet/in.h> // sockaddr_in
|
|
# include <arpa/inet.h> // htonl, htons, ntohl, ntohs, inet_addr
|
|
# include <sys/epoll.h> // epoll
|
|
# include <fcntl.h> // fcntl
|
|
# include <sys/wait.h> // waitpid
|
|
# include <csignal> // signal
|
|
# include <cstdlib> // itoa
|
|
char *ft_itoa(int n);
|
|
# include <fstream> // ifstream
|
|
|
|
# include "Client.hpp"
|
|
# include "Server.hpp"
|
|
|
|
//# define BUFSIZE 8192
|
|
//# define TIMEOUT 10 * 1000
|
|
//# define MAX_EVENTS 42 // arbitrary
|
|
//# define MSG_TEST "Le Webserv / 20 =D\n"
|
|
|
|
extern bool g_run;
|
|
extern int g_last_signal;
|
|
void signal_handler(int signum);
|
|
|
|
class Webserv
|
|
{
|
|
public:
|
|
// base.cpp
|
|
Webserv();
|
|
// Webserv(Webserv const &src);
|
|
~Webserv();
|
|
// Webserv &operator=(Webserv const &rhs);
|
|
|
|
// init.cpp
|
|
void init_virtual_servers(); // ADD config param
|
|
// run_loop.cpp
|
|
void run();
|
|
|
|
private:
|
|
int _epfd;
|
|
int _socket_fd; // temp, to replace with std::vector<Server>
|
|
// std::vector<Server> _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);
|
|
void _construct_response(Client *client);
|
|
void _insert_status_line(Client *client);
|
|
void _get_ressource(Client *client);
|
|
// 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);
|
|
void _listen(int socket_fd, unsigned int max_connections);
|
|
|
|
// TMP HUGO TEST CGI
|
|
//
|
|
void _serve_file(Client *client, std::string page);
|
|
void _exec_cgi_script(Client *client);
|
|
void _parse_request();
|
|
//
|
|
// END TMP HUGO TEST CGI
|
|
};
|
|
|
|
#endif
|