Merge branch 'master' into zma_to_thread

This commit is contained in:
Isaac Connor
2020-07-21 17:38:32 -04:00
210 changed files with 3521 additions and 4636 deletions

View File

@@ -403,28 +403,46 @@ void timespec_diff(struct timespec *start, struct timespec *end, struct timespec
char *timeval_to_string( struct timeval tv ) {
time_t nowtime;
struct tm *nowtm;
static char tmbuf[64], buf[64];
static char tmbuf[20], buf[28];
nowtime = tv.tv_sec;
nowtm = localtime(&nowtime);
strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S", nowtm);
snprintf(buf, sizeof buf, "%s.%06ld", tmbuf, tv.tv_usec);
snprintf(buf, sizeof buf-1, "%s.%06ld", tmbuf, tv.tv_usec);
return buf;
}
std::string UriDecode( const std::string &encoded ) {
#ifdef HAVE_LIBCURL
CURL *curl = curl_easy_init();
int outlength;
char *cres = curl_easy_unescape(curl, encoded.c_str(), encoded.length(), &outlength);
std::string res(cres, cres + outlength);
curl_free(cres);
curl_easy_cleanup(curl);
return res;
#else
Warning("ZM Compiled without LIBCURL. UriDecoding not implemented.");
return encoded;
#endif
char a, b;
const char *src = encoded.c_str();
std::string retbuf;
retbuf.resize(encoded.length() + 1);
char *dst = &retbuf[0];
while (*src) {
if ((*src == '%') && ((a = src[1]) && (b = src[2])) && (isxdigit(a) && isxdigit(b))) {
if (a >= 'a')
a -= 'a'-'A';
if (a >= 'A')
a -= ('A' - 10);
else
a -= '0';
if (b >= 'a')
b -= 'a'-'A';
if (b >= 'A')
b -= ('A' - 10);
else
b -= '0';
*dst++ = 16*a+b;
src+=3;
} else if (*src == '+') {
*dst++ = ' ';
src++;
} else {
*dst++ = *src++;
}
}
*dst++ = '\0';
return retbuf;
}
void string_toupper( std::string& str) {