Files
OrcaSlicer/src/slic3r/Utils/UltiMaker.hpp
T
HanifKoh e40030cf81 Stop Malformed Network Responses from Crashing the App (#15947)
* Stop Malformed Network Responses from Crashing the App

Duet, MKS and UltiMaker parsed print host replies with boost read_json
inside the HTTP completion callback with no try, so an HTML or truncated
reply threw out of the Physical Printer Test button and terminated the app,
or killed the upload queue thread. The five identical copies of the parser
(ESP3D's and Flashforge's were unused) are replaced by one shared
PrintHost::get_err_code_from_body that reports a non-JSON reply as an error.
The upload queue now catches a failing job per job, so one bad upload no
longer leaves later jobs queued forever.

Flashforge read material station slots with nlohmann value(), which throws
on off-type fields or non-object entries. The parsing moves into
Flashforge::parse_material_slots, which reads fields leniently with the
existing try_parse_json_int and skips bad entries.

UserManager::parse_json parsed the payload before its try block; the parse
now happens inside it.

* Keep UploadFinished Paired with UploadStarted When an Upload Throws

The exception from a throwing upload was caught around perform_job, so
the UploadFinished lifecycle event was skipped and plugins saw an
upload start that never finished.

The catch now sits around the upload call. The error is reported
through the job's error callback and UploadFinished is fired with an
error code, as for any other failed upload. The worker keeps running
for the next job. The started, upload and finished sequence moved to
PrintHostJobQueue::upload_job so it can be tested without the dialog.
2026-09-30 00:39:01 +08:00

72 lines
2.1 KiB
C++

#ifndef slic3r_UltiMaker_hpp_
#define slic3r_UltiMaker_hpp_
#include <string>
#include <wx/string.h>
#include "PrintHost.hpp"
namespace Slic3r {
class DynamicPrintConfig;
class Http;
class UltiMaker : public PrintHost
{
public:
explicit UltiMaker(DynamicPrintConfig *config);
~UltiMaker() override = default;
const char* get_name() const override;
bool test(wxString &curl_msg) const override;
wxString get_test_ok_msg() const override;
wxString get_test_failed_msg(wxString &msg) const override;
bool has_auth_creds() const;
bool is_authorized() const;
std::string auth_status() const;
bool generate_auth_creds(wxString &msg) const;
std::string test_auth() const;
bool upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn) const override;
bool has_auto_discovery() const override { return false; }
bool can_test() const override { return true; }
PrintHostPostUploadActions get_post_upload_actions() const override { return PrintHostPostUploadAction::StartPrint; }
std::string get_host() const override { return host; }
const std::string& get_api_user() const { return m_api_username; }
const std::string& get_api_username() const { return m_api_username; }
const std::string& get_api_password() const { return m_api_password; }
int getPrintTime(std::string filepath) const;
protected:
std::string m_host;
// username and password for HTTP Digest Authentization (RFC RFC2617)
std::string m_api_username;
std::string m_api_password;
bool m_ssl_revoke_best_effort;
bool makeGriffinCompatible(std::string filepath) const;
private:
enum class ConnectionType { rrf, dsf, error };
std::string host;
std::string get_upload_url(const std::string &filename, ConnectionType connectionType) const;
std::string get_status_url() const;
std::string get_connect_url() const;
std::string get_base_url() const;
std::string timestamp_str() const;
ConnectionType connect(wxString &msg) const;
void set_auth(Http& http) const;
void disconnect(ConnectionType connectionType) const;
bool start_print(wxString &msg, const std::string &filename, ConnectionType connectionType) const;
};
}
#endif