Files
42_INT_12_webserv/headers/Webserv.hpp
2022-07-28 17:27:03 +02:00

61 lines
1.6 KiB
C++

#ifndef WEBSERV_HPP
# define WEBSERV_HPP
# include <string>
# include <map>
# include <cerrno> // errno
# include <cstdio> // perror
# include <exception>
# include <stdexcept>
# include <unistd.h> // close
# 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 <sstream> // stringstream
#define BUFSIZE 8192
#define TIMEOUT 10 * 1000
#define MAX_EVENTS 42 // arbitrary
#define MSG_TEST "Le Webserv / 20 =D\n"
#define MSG_BOUNCE "bounced properly ;)\n" // placeholder
class Webserv
{
public:
Webserv();
// Webserv(Webserv const &src);
~Webserv();
// Webserv &operator=(Webserv const &rhs);
void init_virtual_servers(); // ADD config param
void start();
private:
int _socket_fd; // TODO: replace with vector of "Server" struct
int _epfd;
// WIP global buffer. Need one variable set per "Client"
char _buf[BUFSIZE+1];
ssize_t _read_ret;
std::map<std::string, std::string> _request;
std::map<std::string, std::string> _response;
void _bind(int socket_fd, in_port_t port);
void _listen(int socket_fd, unsigned int max_connections);
void _accept_connection(int fd);
void _read_request(int fd);
void _send_response(int fd);
// TMP HUGO TEST CGI
void _serve_file(int fd, std::string page);
void _exec_cgi_script(int fd);
};
#endif