2016-11-21 04:50:55 -05:00
|
|
|
#include "STDInclude.hpp"
|
|
|
|
|
|
|
|
namespace Utils
|
|
|
|
{
|
2016-11-21 14:49:33 -05:00
|
|
|
const char* Cache::Urls[] =
|
2016-11-21 04:50:55 -05:00
|
|
|
{
|
|
|
|
"https://iw4xcachep26muba.onion.to"/*,
|
|
|
|
"https://iw4xcachejnetuln.onion.to",
|
|
|
|
"https://iw4xcachedjodc4y.onion.to",
|
|
|
|
*/
|
|
|
|
};
|
2016-11-21 14:49:33 -05:00
|
|
|
std::string Cache::ValidUrl;
|
2016-11-21 05:09:42 -05:00
|
|
|
std::mutex Cache::CacheMutex;
|
2016-11-21 04:50:55 -05:00
|
|
|
|
2016-11-25 08:16:07 -05:00
|
|
|
std::string Cache::GetStaticUrl(std::string path)
|
2016-11-21 04:50:55 -05:00
|
|
|
{
|
2016-11-25 08:16:07 -05:00
|
|
|
return Cache::Urls[0] + path;
|
2016-11-21 04:50:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Cache::GetUrl(std::string url, std::string path)
|
|
|
|
{
|
|
|
|
return url + path;
|
|
|
|
}
|
|
|
|
|
2016-11-21 14:49:33 -05:00
|
|
|
std::string Cache::GetFile(std::string path, int timeout, std::string useragent)
|
2016-11-21 04:50:55 -05:00
|
|
|
{
|
2016-11-21 14:49:33 -05:00
|
|
|
std::lock_guard<std::mutex> _(Cache::CacheMutex);
|
|
|
|
|
|
|
|
if (Cache::ValidUrl.empty())
|
2016-11-21 04:50:55 -05:00
|
|
|
{
|
2016-11-21 14:49:33 -05:00
|
|
|
for (int i = 0; i < ARRAY_SIZE(Cache::Urls); i++)
|
2016-11-21 04:50:55 -05:00
|
|
|
{
|
2016-11-21 14:49:33 -05:00
|
|
|
std::string result = Utils::WebIO(useragent, Cache::GetUrl(Cache::Urls[i], path)).setTimeout(timeout)->get();
|
|
|
|
|
2016-11-21 05:09:42 -05:00
|
|
|
if (!result.empty())
|
|
|
|
{
|
2016-11-21 14:49:33 -05:00
|
|
|
Cache::ValidUrl = Cache::Urls[i];
|
2016-11-21 05:09:42 -05:00
|
|
|
return result;
|
|
|
|
}
|
2016-11-21 04:50:55 -05:00
|
|
|
}
|
2016-11-21 14:49:33 -05:00
|
|
|
|
|
|
|
return "";
|
2016-11-21 04:50:55 -05:00
|
|
|
}
|
2016-11-21 05:09:42 -05:00
|
|
|
else
|
|
|
|
{
|
2016-11-21 14:49:33 -05:00
|
|
|
return Utils::WebIO(useragent, Cache::GetUrl(Cache::ValidUrl, path)).setTimeout(timeout)->get();
|
2016-11-21 05:09:42 -05:00
|
|
|
}
|
2016-11-21 04:50:55 -05:00
|
|
|
}
|
|
|
|
}
|