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.

64 lines
1.2 KiB

12 months ago
#include "CtlUtil.hpp"
#ifdef ZT_CONTROLLER_USE_LIBPQ
#include <iomanip>
9 months ago
#include <sstream>
12 months ago
namespace ZeroTier {
9 months ago
const char* _timestr()
12 months ago
{
time_t t = time(0);
9 months ago
char* ts = ctime(&t);
char* p = ts;
if (! p)
12 months ago
return "";
while (*p) {
if (*p == '\n') {
*p = (char)0;
break;
}
++p;
}
return ts;
}
9 months ago
std::vector<std::string> split(std::string str, char delim)
{
12 months ago
std::istringstream iss(str);
std::vector<std::string> tokens;
std::string item;
9 months ago
while (std::getline(iss, item, delim)) {
12 months ago
tokens.push_back(item);
}
return tokens;
}
9 months ago
std::string url_encode(const std::string& value)
{
std::ostringstream escaped;
escaped.fill('0');
escaped << std::hex;
12 months ago
9 months ago
for (std::string::const_iterator i = value.begin(), n = value.end(); i != n; ++i) {
std::string::value_type c = (*i);
12 months ago
9 months ago
// Keep alphanumeric and other accepted characters intact
if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
escaped << c;
continue;
}
12 months ago
9 months ago
// Any other characters are percent-encoded
escaped << std::uppercase;
escaped << '%' << std::setw(2) << int((unsigned char)c);
escaped << std::nouppercase;
}
12 months ago
9 months ago
return escaped.str();
12 months ago
}
9 months ago
} // namespace ZeroTier
12 months ago
#endif