Skip to content
Snippets Groups Projects
_httpoprequest.cpp 29.8 KiB
Newer Older
	// 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;
}


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);
}



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);
	}
}

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';
			}
		}
	}
	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;

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;