55 lines
1.3 KiB
C++
55 lines
1.3 KiB
C++
|
|
#ifndef UTILS_HPP
|
|
# define UTILS_HPP
|
|
|
|
# include <vector>
|
|
# include <string>
|
|
# include <sstream>
|
|
# include <cstdlib> // atoi
|
|
# include <cctype> // tolower
|
|
# include <algorithm> // transform
|
|
|
|
# define CR "\r"
|
|
# define LF "\n"
|
|
# define CRLF CR LF
|
|
|
|
// enum http_method
|
|
// {
|
|
// UNKNOWN = 0b00000000,
|
|
// GET = 0b00000001,
|
|
// POST = 0b00000010,
|
|
// DELETE = 0b00000100,
|
|
// ANY_METHODS = 0b11111111,
|
|
// };
|
|
|
|
enum http_method
|
|
{
|
|
UNKNOWN = 0b0,
|
|
GET = 1 << 0,
|
|
POST = 1 << 1,
|
|
DELETE = 1 << 2,
|
|
ANY_METHODS = 0b11111111,
|
|
};
|
|
|
|
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);
|
|
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 c);
|
|
http_method str_to_http_method(std::string &str);
|
|
std::string http_methods_to_str(unsigned int methods);
|
|
void replace_all_substr(std::string &str, const std::string &ori_substr, const std::string &new_substr);
|
|
std::string str_tolower(std::string str);
|
|
void del_line_in_str(std::string * str, size_t pos, std::string delim);
|
|
|
|
#endif
|