From e1417f182701858cc369a233096eb845d7a081f7 Mon Sep 17 00:00:00 2001 From: Martin Loidl Date: Tue, 4 Sep 2018 23:55:37 +0200 Subject: [PATCH] allow whitespaces for duet upload * now url_encoding characters which could not used for URLs --- xs/src/slic3r/Utils/Duet.cpp | 7 ++++--- xs/src/slic3r/Utils/Http.cpp | 12 ++++++++++++ xs/src/slic3r/Utils/Http.hpp | 3 +++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/xs/src/slic3r/Utils/Duet.cpp b/xs/src/slic3r/Utils/Duet.cpp index 82a42eb71..a3dc4a3bb 100644 --- a/xs/src/slic3r/Utils/Duet.cpp +++ b/xs/src/slic3r/Utils/Duet.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -197,7 +198,7 @@ std::string Duet::get_upload_url(const std::string &filename) const { return (boost::format("%1%rr_upload?name=0:/gcodes/%2%&%3%") % get_base_url() - % filename + % Http::url_encode(filename) % timestamp_str()).str(); } @@ -248,9 +249,10 @@ wxString Duet::format_error(const std::string &body, const std::string &error, u bool Duet::start_print(wxString &msg, const std::string &filename) const { bool res = false; + auto url = (boost::format("%1%rr_gcode?gcode=M32%%20\"%2%\"") % get_base_url() - % filename).str(); + % Http::url_encode(filename)).str(); auto http = Http::get(std::move(url)); http.on_error([&](std::string body, std::string error, unsigned status) { @@ -275,5 +277,4 @@ int Duet::get_err_code_from_body(const std::string &body) const return root.get("err", 0); } - } diff --git a/xs/src/slic3r/Utils/Http.cpp b/xs/src/slic3r/Utils/Http.cpp index a92e399a0..3024b08fe 100644 --- a/xs/src/slic3r/Utils/Http.cpp +++ b/xs/src/slic3r/Utils/Http.cpp @@ -421,6 +421,18 @@ bool Http::ca_file_supported() return res; } +std::string Http::url_encode(const std::string &str) +{ + ::CURL *curl = ::curl_easy_init(); + char *ce = ::curl_easy_escape(curl, str.c_str(), str.length()); + std::string encoded = std::string(ce); + + ::curl_free(ce); + if (curl != nullptr) { ::curl_easy_cleanup(curl); } + + return encoded; +} + std::ostream& operator<<(std::ostream &os, const Http::Progress &progress) { os << "Http::Progress(" diff --git a/xs/src/slic3r/Utils/Http.hpp b/xs/src/slic3r/Utils/Http.hpp index f1302b0ed..44580b7ea 100644 --- a/xs/src/slic3r/Utils/Http.hpp +++ b/xs/src/slic3r/Utils/Http.hpp @@ -98,6 +98,9 @@ public: // Tells whether current backend supports seting up a CA file using ca_file() static bool ca_file_supported(); + + // converts the given string to an url_encoded_string + static std::string url_encode(const std::string &str); private: Http(const std::string &url);