106 lines
2.3 KiB
C++
106 lines
2.3 KiB
C++
|
|
#ifndef WEBSERV_HPP
|
|
# define WEBSERV_HPP
|
|
|
|
# include <iostream> // cout, cin
|
|
# include <string>
|
|
# include <map>
|
|
# include <vector>
|
|
# include <cerrno> // errno
|
|
# include <cstdio> // perror
|
|
# include <exception>
|
|
# include <stdexcept>
|
|
# include <unistd.h> // close
|
|
# include <cstring> // memset
|
|
# include <fstream>
|
|
# include <sstream>
|
|
|
|
# include <sys/socket.h> // socket, accept, listen, send, recv, bind, connect, setsockopt, getsockname
|
|
# include <netinet/in.h> // sockaddr_in
|
|
// # include <netinet/ip.h> // usefull for what ?
|
|
# include <arpa/inet.h> // htonl, htons, ntohl, ntohs, inet_addr
|
|
|
|
# include <sys/epoll.h> // epoll
|
|
# include <fcntl.h> // fcntl
|
|
|
|
# include "Client.hpp"
|
|
# include "Server.hpp"
|
|
# include "ConfigParser.hpp"
|
|
# include "ServerConfig.hpp"
|
|
# include "LocationConfig.hpp"
|
|
# include "MethodType.hpp"
|
|
# include <csignal> // signal
|
|
# include <unistd.h>
|
|
# include <string.h>
|
|
# include <stdio.h>
|
|
# include <stdlib.h>
|
|
|
|
# define BUFSIZE 8192
|
|
# define TIMEOUT 3000
|
|
# define MAX_EVENTS 42 // arbitrary
|
|
# define MSG_TEST "Le Webserv / 20 =D\n"
|
|
|
|
|
|
// ev.data.u32 filled with tag constant "SERVER_FD/CLIENT_FD"
|
|
// dont work because ev.data is an "union",
|
|
// so we can only use one variable (fd, ptr, u32 or u64)
|
|
// ev.data.u32 = SERVER_FD;
|
|
|
|
/* enum // WIP test
|
|
{
|
|
SERVER_FD = 1,
|
|
CLIENT_FD
|
|
};
|
|
|
|
struct s // WIP test
|
|
{
|
|
int fd;
|
|
Client *ptr;
|
|
};
|
|
*/
|
|
|
|
// these might only be TMP
|
|
# define FAILURE -1
|
|
# define SUCCESS 1
|
|
|
|
class Webserv
|
|
{
|
|
public:
|
|
|
|
Webserv();
|
|
// Webserv(Webserv const &src);
|
|
|
|
// what should it take as arg, *, &, ?
|
|
// Webserv(std::vector<ServerConfig>& servers);
|
|
|
|
~Webserv();
|
|
// Webserv &operator=(Webserv const &rhs);
|
|
|
|
void init_virtual_servers(); // ADD config param
|
|
void start();
|
|
|
|
private:
|
|
int _epfd;
|
|
int _socket_fd; // temp, to replace with std::vector<Server>
|
|
// std::vector<Server> _servers;
|
|
std::vector<Client> _clients;
|
|
|
|
void _accept_connection(int fd);
|
|
void _read_request(Client *client);
|
|
void _send_response(Client *client);
|
|
|
|
int _epoll_update(int fd, uint32_t events, int op);
|
|
int _epoll_update(int fd, uint32_t events, int op, void *ptr);
|
|
|
|
void _handle_last_signal();
|
|
// void _signal_handler(int signum); // invalide dans une class
|
|
Client* _actual_client;
|
|
void _close_client(int fd);
|
|
void _close_all_clients();
|
|
|
|
void _bind(int socket_fd, in_port_t port);
|
|
void _listen(int socket_fd, unsigned int max_connections);
|
|
};
|
|
|
|
#endif
|