Files
42_INT_12_webserv/srcs/Client.hpp
hugogogo 2a70c6b26d Merge branch 'hugo3'
+ script output verification works (field duplicate and status)
+ parsing_message_http :
  - the file is deleted
  - of the three functions it contained, only one still exist
  - 'parse_http_headers' is now in utils
+ changes in utils :
  - http headers parsing doesn't change key case itself
  - a new function change key case tolower case in map<str, str>
  - added split_trim() that perform a split and a trim at once
  - resolved pbm in trim
  - added print_special to print special char '\r' and '\n'
  - del_line became extract_line, because it returns the deleted line
  - added get line, that does the same without deleting
  - moved http_header in utils, and made it more consistent
+ in Client :
  - parse_request is now named parse_request_headers to work with parse body
  - private function _parse_request_headers is then now _parse_request_fields
    (because it doesn't take care of request first line, but only fields)
  - added a debug function 'print_client'
2022-08-12 14:05:11 +02:00

108 lines
2.9 KiB
C++

#ifndef CLIENT_HPP
# define CLIENT_HPP
# include <iostream>
# include <string>
# include <map>
# include <vector>
# include <string.h> // strdup
# include <netinet/in.h> // sockaddr_in, struct in_addr
# include <arpa/inet.h> // htonl, htons, ntohl, ntohs, inet_addr, inet_ntoa
# include "utils.hpp"
# include "ServerConfig.hpp"
struct Script
{
std::string path;
std::string info;
};
struct Request
{
http_method method;
std::string uri;
std::string abs_path;
std::string query;
std::string version;
std::map<std::string, std::string> headers;
std::string body;
std::string port;
std::string hostname;
struct Script script;
};
class Client
{
public:
Client();
Client(int afd, listen_socket *lsocket, std::string aport, std::string aip);
~Client();
// Client(Client const &src);
// Client &operator=(Client const &rhs);
std::string raw_request;
std::string response;
unsigned int status;
bool header_complete;
bool body_complete;
bool request_complete;
size_t read_body_size; // unused for now
ServerConfig *assigned_server; // cant be const cause of error_pages.operator[]
const LocationConfig *assigned_location;
// getters
int get_cl_fd() const;
const std::string & get_cl_port() const;
const std::string & get_cl_ip() const;
const listen_socket * get_cl_lsocket() const;
// requests getters
http_method get_rq_method() const;
std::string get_rq_method_str() const;
std::string get_rq_uri() const;
std::string get_rq_abs_path() const;
std::string get_rq_query() const;
std::string get_rq_version() const;
std::string get_rq_body() const;
std::string get_rq_port() const;
std::string get_rq_hostname() const;
std::string get_rq_script_path() const;
std::string get_rq_script_info() const;
std::string get_rq_headers(const std::string & key) const;
void parse_request_headers(std::vector<ServerConfig> &servers);
void parse_request_body();
void clear();
void clear_request();
void clear_script();
bool fill_script_path(std::string script);
// DEBUG
void print_client(std::string message = "");
private:
int _fd;
std::string _port;
std::string _ip;
listen_socket * _lsocket;
struct Request _request;
void _parse_request_line();
void _parse_request_fields();
void _parse_request_uri( std::string uri );
void _parse_port_hostname(std::string host);
void _check_request_errors();
};
bool operator==(const Client& lhs, const Client& rhs);
bool operator==(const Client& lhs, int fd);
bool operator==(int fd, const Client& rhs);
// Temporary Global Scope. Probably move to Client in the future.
ServerConfig *_determine_process_server(Client *client, std::vector<ServerConfig> &servers);
const LocationConfig *_determine_location(const ServerConfig &server, const std::string &path);
#endif