Files
42_INT_12_webserv/srcs/utils.hpp
2022-08-11 00:28:01 +02:00

55 lines
1.5 KiB
C++

#ifndef UTILS_HPP
# define UTILS_HPP
# include <vector>
# include <string>
# include <sstream>
# include <cstdlib> // atoi
# include <sys/stat.h> // stat()
# include <cctype> // tolower
# include <algorithm> // transform
# define CR "\r"
# define LF "\n"
# define CRLF CR LF
enum http_method
{
UNKNOWN = 0b0,
GET = 1 << 0,
POST = 1 << 1,
DELETE = 1 << 2,
ANY_METHODS = 0b11111111,
// ALL_METHODS = 0b11111111,
// i would prefer this...
};
struct listen_socket
{
int fd;
std::string host;
std::string port;
};
bool operator==(const listen_socket& lhs, int fd);
bool operator==(int fd, const listen_socket& rhs);
std::vector<std::string> split(std::string input, char delimiter);
std::vector<std::string> split_trim(std::string s, std::string d, char c);
bool isNumeric(std::string str);
bool isNumeric_btw(int low, int high, std::string str);
std::string itos(int n);
std::string trim(std::string str, char del);
http_method str_to_http_method(std::string &str);
std::string http_methods_to_str(unsigned int methods);
int path_is_valid(std::string path);
void replace_all_substr(std::string &str, const std::string &ori_substr, const std::string &new_substr);
std::string str_tolower(std::string str);
std::string extract_line(std::string & s, size_t p, std::string d);
std::string get_line(std::string str, size_t pos, std::string del);
std::map<std::string, std::string>
parse_http_headers (std::string headers, std::map<std::string, std::string> fields );
void throw_test();
#endif