wip cgi handling, client contains it's own privates functions to handle request headers and body
This commit is contained in:
@@ -5,25 +5,47 @@
|
||||
# include <iostream>
|
||||
# include <string>
|
||||
# include <map>
|
||||
# include <vector>
|
||||
# include "utils.hpp"
|
||||
|
||||
struct Client
|
||||
struct Request
|
||||
{
|
||||
// public:
|
||||
// Client(Placeholder);
|
||||
// Client();
|
||||
// Client(Client const &src);
|
||||
// ~Client();
|
||||
// Client &operator=(Client const &rhs);
|
||||
std::map<std::string, std::string> headers;
|
||||
std::string method;
|
||||
std::string path;
|
||||
std::string version;
|
||||
std::string body;
|
||||
};
|
||||
|
||||
int fd;
|
||||
std::string raw_request;
|
||||
std::map<std::string, std::string> request;
|
||||
// std::map<std::string, std::string> response;
|
||||
class Client
|
||||
{
|
||||
public:
|
||||
Client();
|
||||
~Client();
|
||||
//Client(Client const &src);
|
||||
//Client &operator=(Client const &rhs);
|
||||
|
||||
int fd;
|
||||
std::string raw_request;
|
||||
std::string response;
|
||||
unsigned int status;
|
||||
|
||||
// private:
|
||||
std::string get_method();
|
||||
std::string get_path();
|
||||
std::string get_version();
|
||||
std::string get_body();
|
||||
std::string get_headers(std::string key);
|
||||
|
||||
void parse_request();
|
||||
|
||||
private:
|
||||
struct Request _request;
|
||||
|
||||
void _parse_request_line( std::string rline );
|
||||
void _parse_request_headers( std::vector<std::string> list );
|
||||
void _parse_request_body( size_t pos );
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,14 +1,3 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ServerConfig.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: me <erlazo@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/23 15:55:16 by me #+# #+# */
|
||||
/* Updated: 2022/07/23 16:19:43 by me ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef SERVERCONFIG_HPP
|
||||
# define SERVERCONFIG_HPP
|
||||
@@ -27,7 +16,6 @@ public:
|
||||
// i mean i guess i need some canonic stuff?
|
||||
// although maybe if i make it a struct i can barebones it?
|
||||
|
||||
|
||||
std::string server_name;
|
||||
std::string root;
|
||||
|
||||
@@ -54,10 +42,8 @@ public:
|
||||
std::string host;
|
||||
std::string port;
|
||||
|
||||
|
||||
// do i need a print all for testing?
|
||||
|
||||
|
||||
void print_all()
|
||||
{
|
||||
std::cout << "PRINTING A FULL SERVER CONFIG\n\n";
|
||||
@@ -87,18 +73,7 @@ public:
|
||||
|
||||
std::cout << "\n----------\n";
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -76,9 +76,9 @@ class Webserv
|
||||
|
||||
private:
|
||||
int _epfd;
|
||||
std::vector<int> _listen_sockets;
|
||||
std::vector<int> _listen_sockets;
|
||||
std::vector<ServerConfig> _servers;
|
||||
std::vector<Client> _clients;
|
||||
std::vector<Client> _clients;
|
||||
|
||||
// accept.cpp
|
||||
void _accept_connection(int fd);
|
||||
@@ -91,6 +91,13 @@ class Webserv
|
||||
void _construct_response(Client *client);
|
||||
void _insert_status_line(Client *client);
|
||||
void _get_ressource(Client *client);
|
||||
// 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);
|
||||
@@ -102,18 +109,6 @@ class Webserv
|
||||
// init.cpp
|
||||
void _bind(int socket_fd, in_port_t port, std::string host);
|
||||
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(Client *client);
|
||||
void _parse_request_line(Client *client, std::string rline);
|
||||
void _parse_request_headers
|
||||
( Client *client
|
||||
, std::vector<std::string> list);
|
||||
//
|
||||
// END TMP HUGO TEST CGI
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
# include <vector>
|
||||
|
||||
std::vector<std::string> split(std::string input, char delimiter);
|
||||
std::string itoa(int n);
|
||||
std::string itos(int n);
|
||||
std::string trim(std::string str, char c);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user