OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::anonymous_namespace{GUI_App.cpp} Namespace Reference

Classes

struct  UpdaterQuery

Functions

void stop_orca_health_check (NetworkAgent *agent)
std::string detect_updater_os_info ()
std::string detect_updater_version ()
std::string detect_updater_iid (AppConfig *config)
std::string encode_uri_component (const std::string &value)
std::string build_updater_query (const UpdaterQuery &query)
std::string base64url_encode (const unsigned char *data, std::size_t length)
std::optional< std::vector< unsigned char > > load_signature_key ()
const std::optional< std::vector< unsigned char > > & get_signature_key ()
std::string extract_path_from_url (const std::string &url)
void maybe_attach_updater_signature (Http &http, const std::string &canonical_query, const std::string &request_url)
ConfigOptionMode saved_mode_from_string (const std::string &mode)
std::string saved_mode_to_string (ConfigOptionMode mode)
std::string effective_mode_to_string (ConfigOptionMode mode)

Variables

constexpr int CALLBACK_DRAIN_TIMEOUT_MS = 200
constexpr int NETWORK_IDLE_TIMEOUT_MS = 500
constexpr int FINAL_DRAIN_TIMEOUT_MS = 100
constexpr int POLL_INTERVAL_MS = 50
constexpr int MAX_YIELD_ITERATIONS = 20

Class Documentation

◆ Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::UpdaterQuery

struct Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::UpdaterQuery
Collaboration diagram for Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::UpdaterQuery:
Class Members
string arch
string iid
string os
string os_info
string version

Function Documentation

◆ base64url_encode()

std::string Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::base64url_encode ( const unsigned char * data,
std::size_t length )
6412{
6413 std::string encoded;
6414 encoded.resize(boost::beast::detail::base64::encoded_size(length));
6415 encoded.resize(boost::beast::detail::base64::encode(encoded.data(), data, length));
6416 std::replace(encoded.begin(), encoded.end(), '+', '-');
6417 std::replace(encoded.begin(), encoded.end(), '/', '_');
6418 while (!encoded.empty() && encoded.back() == '=')
6419 encoded.pop_back();
6420 return encoded;
6421}
double length(const Points &pts)
Definition MultiPoint.hpp:181

References base64url_encode(), and Slic3r::length().

Referenced by base64url_encode(), and maybe_attach_updater_signature().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ build_updater_query()

std::string Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::build_updater_query ( const UpdaterQuery & query)
6379{
6380 std::vector<std::pair<std::string, std::string>> params;
6381
6382 auto add_param = [&params](const char* key, const std::string& value) {
6383 if (!value.empty())
6384 params.emplace_back(key, encode_uri_component(value));
6385 };
6386
6387 add_param("iid", query.iid);
6388 add_param("v", query.version);
6389 add_param("os", query.os);
6390 add_param("arch", query.arch);
6391 add_param("os_info", query.os_info);
6392
6393 std::sort(params.begin(), params.end(), [](const auto& lhs, const auto& rhs) {
6394 return lhs.first < rhs.first;
6395 });
6396
6397 if (params.empty())
6398 return {};
6399
6400 std::string encoded;
6401 for (size_t idx = 0; idx < params.size(); ++idx) {
6402 if (idx > 0)
6403 encoded.push_back('&');
6404 encoded += params[idx].first;
6405 encoded.push_back('=');
6406 encoded += params[idx].second;
6407 }
6408 return encoded;
6409}
std::string os_info
Definition GUI_App.cpp:6303
std::string encode_uri_component(const std::string &value)
Definition GUI_App.cpp:6357
std::string version
Definition GUI_App.cpp:6300

References Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::UpdaterQuery::arch, build_updater_query(), encode_uri_component(), Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::UpdaterQuery::iid, Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::UpdaterQuery::os, Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::UpdaterQuery::os_info, and Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::UpdaterQuery::version.

Referenced by build_updater_query().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ detect_updater_iid()

std::string Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::detect_updater_iid ( AppConfig * config)
6351{
6352 if (config == nullptr)
6353 return {};
6354 return instance_id::ensure(*config);
6355}
std::string ensure(AppConfig &config)
Definition InstanceID.cpp:170

References detect_updater_iid(), and Slic3r::instance_id::ensure().

Referenced by detect_updater_iid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ detect_updater_os_info()

std::string Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::detect_updater_os_info ( )
6307{
6308 wxString description = wxPlatformInfo::Get().GetOperatingSystemDescription();
6309#if defined(__LINUX__) || defined(__linux__)
6310 wxLinuxDistributionInfo distro = wxGetLinuxDistributionInfo();
6311 if (!distro.Id.empty()) {
6312 wxString normalized = distro.Id;
6313 if (!distro.Release.empty())
6314 normalized << " " << distro.Release;
6315 normalized.Trim(true);
6316 normalized.Trim(false);
6317 if (!normalized.empty())
6318 description = normalized;
6319 }
6320#endif
6321 if (description.empty())
6322 description = wxGetOsDescription();
6323
6324 //Orca: workaround: wxGetOsVersion can't recognize Windows 11
6325 // For Windows, use actual version numbers to properly detect Windows 11
6326 // Windows 11 starts at build 22000
6327#if defined(_WIN32)
6328 int major = 0, minor = 0, micro = 0;
6329 wxGetOsVersion(&major, &minor, &micro);
6330 if (micro >= 22000) {
6331 // replace Windows 10 with Windows 11
6332 description.Replace("Windows 10", "Windows 11");
6333 }
6334#endif
6335 std::string os_info = description.ToStdString();
6336 boost::replace_all(os_info, "\r", " ");
6337 boost::replace_all(os_info, "\n", " ");
6338 boost::algorithm::trim(os_info);
6339 if (os_info.size() > 120)
6340 os_info.resize(120);
6341 boost::algorithm::to_lower(os_info);
6342 return os_info;
6343}

References detect_updater_os_info().

Referenced by detect_updater_os_info().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ detect_updater_version()

std::string Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::detect_updater_version ( )
6346{
6347 return SoftFever_VERSION;
6348}

References detect_updater_version().

Referenced by detect_updater_version().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ effective_mode_to_string()

std::string Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::effective_mode_to_string ( ConfigOptionMode mode)
8721{
8722 return mode == comDevelop ? "develop" : saved_mode_to_string(mode);
8723}
std::string saved_mode_to_string(ConfigOptionMode mode)
Definition GUI_App.cpp:8713
@ comDevelop
Definition Config.hpp:225

References Slic3r::comDevelop, effective_mode_to_string(), and saved_mode_to_string().

Referenced by effective_mode_to_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_uri_component()

std::string Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::encode_uri_component ( const std::string & value)
6358{
6359 static constexpr const char* hex = "0123456789ABCDEF";
6360 std::string out;
6361 out.reserve(value.size());
6362 for (unsigned char ch : value) {
6363 if ((ch >= 'A' && ch <= 'Z') ||
6364 (ch >= 'a' && ch <= 'z') ||
6365 (ch >= '0' && ch <= '9') ||
6366 ch == '-' || ch == '_' || ch == '.' || ch == '~' ||
6367 ch == '!' || ch == '*' || ch == '(' || ch == ')' || ch == '\'') {
6368 out.push_back(static_cast<char>(ch));
6369 } else {
6370 out.push_back('%');
6371 out.push_back(hex[(ch >> 4) & 0xF]);
6372 out.push_back(hex[ch & 0xF]);
6373 }
6374 }
6375 return out;
6376}

References encode_uri_component().

Referenced by build_updater_query(), and encode_uri_component().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_path_from_url()

std::string Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::extract_path_from_url ( const std::string & url)
6462{
6463 if (url.empty())
6464 return "/latest";
6465
6466 std::string path;
6467 const auto scheme_pos = url.find("://");
6468 if (scheme_pos != std::string::npos) {
6469 const auto path_pos = url.find('/', scheme_pos + 3);
6470 if (path_pos != std::string::npos)
6471 path = url.substr(path_pos);
6472 else
6473 path = "/";
6474 } else {
6475 path = url;
6476 }
6477
6478 const auto fragment_pos = path.find('#');
6479 if (fragment_pos != std::string::npos)
6480 path = path.substr(0, fragment_pos);
6481
6482 const auto query_pos = path.find('?');
6483 if (query_pos != std::string::npos)
6484 path = path.substr(0, query_pos);
6485
6486 if (path.empty())
6487 path = "/";
6488 return path;
6489}

References extract_path_from_url().

Referenced by extract_path_from_url(), and maybe_attach_updater_signature().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_signature_key()

const std::optional< std::vector< unsigned char > > & Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::get_signature_key ( )
6451{
6452 static std::optional<std::vector<unsigned char>> cached;
6453 static bool loaded = false;
6454 if (!loaded) {
6455 cached = load_signature_key();
6456 loaded = true;
6457 }
6458 return cached;
6459}
std::optional< std::vector< unsigned char > > load_signature_key()
Definition GUI_App.cpp:6423

References get_signature_key(), and load_signature_key().

Referenced by get_signature_key(), and maybe_attach_updater_signature().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_signature_key()

std::optional< std::vector< unsigned char > > Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::load_signature_key ( )
6424{
6425#if ORCA_UPDATER_SIG_KEY_AVAILABLE
6426 std::string key = ORCA_UPDATER_SIG_KEY_B64;
6427 boost::algorithm::trim(key);
6428 if (key.empty())
6429 return std::nullopt;
6430
6431 key.erase(std::remove_if(key.begin(), key.end(), [](unsigned char ch) { return std::isspace(ch); }), key.end());
6432 std::replace(key.begin(), key.end(), '-', '+');
6433 std::replace(key.begin(), key.end(), '_', '/');
6434 while (key.size() % 4 != 0)
6435 key.push_back('=');
6436
6437 std::string decoded;
6438 decoded.resize(boost::beast::detail::base64::decoded_size(key.size()));
6439 auto decode_result = boost::beast::detail::base64::decode(decoded.data(), key.data(), key.size());
6440 if (!decode_result.second)
6441 return std::nullopt;
6442 decoded.resize(decode_result.first);
6443
6444 return std::vector<unsigned char>(decoded.begin(), decoded.end());
6445#else
6446 return std::nullopt;
6447#endif
6448}

References load_signature_key().

Referenced by get_signature_key(), and load_signature_key().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ maybe_attach_updater_signature()

void Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::maybe_attach_updater_signature ( Http & http,
const std::string & canonical_query,
const std::string & request_url )
6492{
6493 if (canonical_query.empty())
6494 return;
6495
6496 const auto& key = get_signature_key();
6497 if (!key || key->empty())
6498 return;
6499
6500 const auto now = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now());
6501 const std::string timestamp = std::to_string(now.time_since_epoch().count());
6502 const std::string path = extract_path_from_url(request_url);
6503
6504 std::string string_to_sign = "GET\n";
6505 string_to_sign += path;
6506 string_to_sign += "\n";
6507 string_to_sign += canonical_query;
6508 string_to_sign += "\n";
6509 string_to_sign += timestamp;
6510
6511 unsigned int digest_length = 0;
6512 unsigned char digest[EVP_MAX_MD_SIZE] = {};
6513 if (HMAC(EVP_sha256(), key->data(), static_cast<int>(key->size()),
6514 reinterpret_cast<const unsigned char*>(string_to_sign.data()),
6515 string_to_sign.size(), digest, &digest_length) == nullptr || digest_length == 0)
6516 return;
6517
6518 const std::string signature = base64url_encode(digest, digest_length);
6519 http.header("X-Orca-Ts", timestamp);
6520 http.header("X-Orca-Sig", "v1:" + signature);
6521}
std::string extract_path_from_url(const std::string &url)
Definition GUI_App.cpp:6461
const std::optional< std::vector< unsigned char > > & get_signature_key()
Definition GUI_App.cpp:6450
std::string base64url_encode(const unsigned char *data, std::size_t length)
Definition GUI_App.cpp:6411
@ http
Definition IPrinterAgent.hpp:64

References base64url_encode(), extract_path_from_url(), get_signature_key(), Slic3r::http, and maybe_attach_updater_signature().

Referenced by maybe_attach_updater_signature().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ saved_mode_from_string()

ConfigOptionMode Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::saved_mode_from_string ( const std::string & mode)
8706{
8707 return mode == "expert" ? comExpert :
8708 mode == "advanced" ? comAdvanced :
8709 mode == "develop" ? comAdvanced :
8710 comSimple;
8711}
@ comSimple
Definition Config.hpp:222
@ comAdvanced
Definition Config.hpp:223
@ comExpert
Definition Config.hpp:224

References Slic3r::comAdvanced, Slic3r::comExpert, Slic3r::comSimple, and saved_mode_from_string().

Referenced by saved_mode_from_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ saved_mode_to_string()

std::string Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::saved_mode_to_string ( ConfigOptionMode mode)
8714{
8715 return mode == comExpert ? "expert" :
8716 mode == comAdvanced ? "advanced" :
8717 "simple";
8718}

References Slic3r::comAdvanced, Slic3r::comExpert, and saved_mode_to_string().

Referenced by effective_mode_to_string(), and saved_mode_to_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop_orca_health_check()

void Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::stop_orca_health_check ( NetworkAgent * agent)
1917 {
1918 if (!agent)
1919 return;
1920 if (auto orca_agent = std::dynamic_pointer_cast<OrcaCloudServiceAgent>(agent->get_cloud_agent()))
1921 orca_agent->stop_health_check();
1922 }
std::shared_ptr< ICloudServiceAgent > get_cloud_agent(const std::string &provider=ORCA_CLOUD_PROVIDER) const
Definition NetworkAgent.cpp:189

References Slic3r::NetworkAgent::get_cloud_agent(), and stop_orca_health_check().

Referenced by stop_orca_health_check().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ CALLBACK_DRAIN_TIMEOUT_MS

int Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::CALLBACK_DRAIN_TIMEOUT_MS = 200
constexpr

◆ FINAL_DRAIN_TIMEOUT_MS

int Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::FINAL_DRAIN_TIMEOUT_MS = 100
constexpr

◆ MAX_YIELD_ITERATIONS

int Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::MAX_YIELD_ITERATIONS = 20
constexpr

◆ NETWORK_IDLE_TIMEOUT_MS

int Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::NETWORK_IDLE_TIMEOUT_MS = 500
constexpr

◆ POLL_INTERVAL_MS

int Slic3r::GUI::anonymous_namespace{GUI_App.cpp}::POLL_INTERVAL_MS = 50
constexpr