mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-16 11:05:58 +08:00
Printables.com subdomain check
This commit is contained in:
parent
f43c493731
commit
66fa18a11e
@ -146,8 +146,7 @@ void Downloader::start_download(const std::string& full_url)
|
|||||||
#else
|
#else
|
||||||
std::string escaped_url = FileGet::escape_url(full_url.substr(24));
|
std::string escaped_url = FileGet::escape_url(full_url.substr(24));
|
||||||
#endif
|
#endif
|
||||||
|
if (!boost::starts_with(escaped_url, "https://") || !FileGet::is_subdomain(escaped_url, "printables.com")) {
|
||||||
if (!boost::starts_with(escaped_url, "https://files.printables.com") && !boost::starts_with(escaped_url, "https://dev-files.printables.com")) {
|
|
||||||
std::string msg = format(_L("Download won't start. Download URL doesn't point to https://files.printables.com : %1%"), escaped_url);
|
std::string msg = format(_L("Download won't start. Download URL doesn't point to https://files.printables.com : %1%"), escaped_url);
|
||||||
BOOST_LOG_TRIVIAL(error) << msg;
|
BOOST_LOG_TRIVIAL(error) << msg;
|
||||||
NotificationManager* ntf_mngr = wxGetApp().notification_manager();
|
NotificationManager* ntf_mngr = wxGetApp().notification_manager();
|
||||||
|
@ -30,6 +30,42 @@ std::string FileGet::escape_url(const std::string& unescaped)
|
|||||||
}
|
}
|
||||||
return ret_val;
|
return ret_val;
|
||||||
}
|
}
|
||||||
|
bool FileGet::is_subdomain(const std::string& url, const std::string& domain)
|
||||||
|
{
|
||||||
|
// domain should be f.e. printables.com (.com including)
|
||||||
|
char* host;
|
||||||
|
std::string host_string;
|
||||||
|
CURLUcode rc;
|
||||||
|
CURLU* curl = curl_url();
|
||||||
|
if (!curl) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "Failed to init Curl library in function is_domain.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
rc = curl_url_set(curl, CURLUPART_URL, url.c_str(), 0);
|
||||||
|
if (rc != CURLUE_OK) {
|
||||||
|
curl_url_cleanup(curl);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
rc = curl_url_get(curl, CURLUPART_HOST, &host, 0);
|
||||||
|
if (rc != CURLUE_OK || !host) {
|
||||||
|
curl_url_cleanup(curl);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
host_string = std::string(host);
|
||||||
|
curl_free(host);
|
||||||
|
// now host should be subdomain.domain or just domain
|
||||||
|
if (domain == host_string) {
|
||||||
|
curl_url_cleanup(curl);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(boost::ends_with(host_string, "." + domain)) {
|
||||||
|
curl_url_cleanup(curl);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
curl_url_cleanup(curl);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
unsigned get_current_pid()
|
unsigned get_current_pid()
|
||||||
{
|
{
|
||||||
|
@ -23,7 +23,8 @@ public:
|
|||||||
void cancel();
|
void cancel();
|
||||||
void pause();
|
void pause();
|
||||||
void resume();
|
void resume();
|
||||||
static std::string escape_url(const std::string& url);
|
static std::string escape_url(const std::string& url);
|
||||||
|
static bool is_subdomain(const std::string& url, const std::string& domain);
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<priv> p;
|
std::unique_ptr<priv> p;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user