You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

#include "webserv.hpp"
2 years ago
void *ft_memset(void *b, int c, size_t len) {
2 years ago
size_t i;
unsigned char *b_cpy;
2 years ago
2 years ago
b_cpy = (unsigned char *)b;
i = 0;
while (i < len)
*(unsigned char *)(b_cpy + i++) = (unsigned char)c;
return ((void *)b);
2 years ago
}
2 years ago
bool isInt(string str) {
for (string::iterator it = str.begin(); it < str.end(); it++)
2 years ago
if (*it < '0' || *it > '9')
return false;
2 years ago
return true;
}
std::vector<string> split(string str, char delim) {
std::vector<std::string> tokens;
std::string token;
std::stringstream ss(str);
while (getline(ss, token, delim)) {
tokens.push_back(token);
}
return tokens;
}
listen_t get_listen_t(string listen) {
listen_t ret;
size_t sep_pos = listen.rfind(':');
size_t ip6_endpos = listen.rfind(']');
string tmp = listen.substr(0, sep_pos);
if (ip6_endpos > sep_pos)
ret.ip = listen;
else
ret.ip = isInt(tmp) ? "0.0.0.0" : \
(tmp == "localhost" ? "127.0.0.1" : \
(tmp == "[::]" ? "[0000:0000:0000:0000:0000:0000:0000:0000]" : tmp));
tmp = listen.substr(sep_pos + 1, listen.length() - sep_pos - 1).c_str();
ret.port = !isInt(tmp) ? 80 : std::atoi(tmp.c_str());
if (ret.ip.at(0) == '[') {
ret.type = AF_INET6;
ret.ip.erase(ret.ip.length() - 1, ret.ip.length());
ret.ip.erase(0, 1);
}
else
ret.type = AF_INET;
return ret;
}