Newer
Older
Monty Brandenberg
committed
return 0;
}
#if LL_WINDOWS
Monty Brandenberg
committed
if (2 == sscanf_s(tok, "%u-%u/*", &lcl_first, &lcl_last))
#else
if (2 == sscanf(tok, "%u-%u/*", &lcl_first, &lcl_last))
#endif // LL_WINDOWS
Monty Brandenberg
committed
{
if (lcl_first > lcl_last)
return -1;
*first = lcl_first;
*last = lcl_last;
*length = 0;
return 0;
}
}
// Header is there but badly/unexpectedly formed, try to ignore it.
return 1;
}
Monty Brandenberg
committed
int parse_retry_after_header(char * buffer, int * time)
{
char * endptr(buffer);
long lcl_time(strtol(buffer, &endptr, 10));
if (*endptr == '\0' && endptr != buffer && lcl_time > 0)
{
*time = lcl_time;
return 0;
}
// Could attempt to parse HTTP time here but we're not really
// interested in it. Scheduling based on wallclock time on
// user hardware will lead to tears.
// Header is there but badly/unexpectedly formed, try to ignore it.
return 1;
}
Monty Brandenberg
committed
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
void escape_libcurl_debug_data(char * buffer, size_t len, bool scrub, std::string & safe_line)
{
std::string out;
len = (std::min)(len, size_t(200));
out.reserve(3 * len);
for (int i(0); i < len; ++i)
{
unsigned char uc(static_cast<unsigned char>(buffer[i]));
if (uc < 32 || uc > 126)
{
if (scrub)
{
out.append(1, ' ');
}
else
{
static const char hex[] = "0123456789ABCDEF";
char convert[4];
convert[0] = '%';
convert[1] = hex[(uc >> 4) % 16];
convert[2] = hex[uc % 16];
convert[3] = '\0';
out.append(convert);
}
}
else
{
out.append(1, buffer[i]);
}
}
safe_line.swap(out);
}
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
int os_strcasecmp(const char *s1, const char *s2)
{
#if LL_WINDOWS
return _stricmp(s1, s2);
#else
return strcasecmp(s1, s2);
#endif // LL_WINDOWS
}
char * os_strtok_r(char *str, const char *delim, char ** savestate)
{
#if LL_WINDOWS
return strtok_s(str, delim, savestate);
#else
return strtok_r(str, delim, savestate);
#endif
}
void os_strlower(char * str)
{
for (char c(0); (c = *str); ++str)
{
*str = tolower(c);
}
}
Monty Brandenberg
committed
char * os_strtrim(char * lstr)
{
while (' ' == *lstr || '\t' == *lstr)
{
++lstr;
}
if (*lstr)
{
char * rstr(lstr + strlen(lstr));
while (lstr < rstr && *--rstr)
{
if (' ' == *rstr || '\t' == *rstr)
{
*rstr = '\0';
}
}
llassert(lstr <= rstr);
}
return lstr;
}
char * os_strltrim(char * lstr)
{
while (' ' == *lstr || '\t' == *lstr)
{
++lstr;
}
return lstr;
}
void check_curl_easy_code(CURLcode code, int curl_setopt_option)
{
if (CURLE_OK != code)
{
// Comment from old llcurl code which may no longer apply:
//
// linux appears to throw a curl error once per session for a bad initialization
// at a pretty random time (when enabling cookies).
LL_WARNS(LOG_CORE) << "libcurl error detected: " << curl_easy_strerror(code)
<< ", curl_easy_setopt option: " << curl_setopt_option
<< LL_ENDL;
Monty Brandenberg
committed
void check_curl_easy_code(CURLcode code)
{
if (CURLE_OK != code)
{
// Comment from old llcurl code which may no longer apply:
//
// linux appears to throw a curl error once per session for a bad initialization
// at a pretty random time (when enabling cookies).
LL_WARNS(LOG_CORE) << "libcurl error detected: " << curl_easy_strerror(code)
<< LL_ENDL;
}
}
} // end anonymous namespace