Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for SimplyPrint cloud integration #13220

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5b0ff7b
Support for SimplyPrint cloud integration (SoftFever/OrcaSlicer#4525)
Noisyfox Mar 23, 2024
4dc221b
Various improvements to SimplyPrint integration (SoftFever/OrcaSlicer…
Noisyfox Jun 21, 2024
f11a32d
Try fixing build with gcc 13.3 (SoftFever/OrcaSlicer#5991) (#5992)
Noisyfox Jul 7, 2024
2683e9c
Port MIME logic from BBL/Orca
Ocraftyone Jul 27, 2024
3b5e567
Add WindowWorker.hpp
Ocraftyone Jul 27, 2024
1ec3886
Fix include statements
Ocraftyone Jul 27, 2024
15f127b
Revert "Fix issue caused by the fact that the backing widget of the `…
Ocraftyone Jul 27, 2024
5d6a7f5
Use WindowWorker for OAuthDialog
Ocraftyone Jul 27, 2024
2879be5
Modify HttpServer
Ocraftyone Jul 21, 2024
3163007
Remove remaining BBL specific code
Ocraftyone Jul 27, 2024
39b8db2
Port Http::url_decode from BBL/Orca
Ocraftyone Jul 21, 2024
9282f22
Add nlohmann library from BBL/Orca
Ocraftyone Jul 27, 2024
f57b574
Place SimplyPrint before PrusaConnectNew in PrintHostType enum
Ocraftyone Jul 27, 2024
e06f52a
Finish some of the update logic for SimplyPrint in PhysicalPrinterDialog
Ocraftyone Jul 29, 2024
9386c54
Add OpenSSL as target library
Ocraftyone Aug 5, 2024
3d2b8d5
Fix GUI issue
Ocraftyone Aug 5, 2024
01b37d0
Take advantage of Physical Printer WebView
Ocraftyone Aug 7, 2024
38dfc35
Update to correct Client ID and User-Agent
Ocraftyone Aug 7, 2024
65b96ad
Undo whitespace only changes
Ocraftyone Aug 7, 2024
18bbd5e
Revert "Add nlohmann library from BBL/Orca"
Ocraftyone Aug 8, 2024
33b0833
Use boost property trees in place of nlohmann json library
Ocraftyone Aug 8, 2024
9d3936a
Change PrintHostPostUploadAction to None
Ocraftyone Aug 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ slic3r_remap_configs(TBB::tbbmalloc RelWithDebInfo Release)
# The Intel TBB library will use the std::exception_ptr feature of C++11.
# add_definitions(-DTBB_USE_CAPTURED_EXCEPTION=0)

find_package(OpenSSL REQUIRED)
find_package(CURL REQUIRED)

add_library(libcurl INTERFACE)
Expand Down
51 changes: 35 additions & 16 deletions deps/+OpenSSL/OpenSSL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,43 @@
include(ProcessorCount)
ProcessorCount(NPROC)

set(_conf_cmd "./config")
set(_cross_arch "")
set(_cross_comp_prefix_line "")
if (CMAKE_CROSSCOMPILING)
set(_conf_cmd "./Configure")
set(_cross_comp_prefix_line "--cross-compile-prefix=${TOOLCHAIN_PREFIX}-")
if(DEFINED OPENSSL_ARCH)
set(_cross_arch ${OPENSSL_ARCH})
else()
if(WIN32)
set(_cross_arch "VC-WIN64A")
elseif(APPLE)
set(_cross_arch "darwin64-arm64-cc")
endif()
endif()

if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
set(_cross_arch "linux-aarch64")
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armhf") # For raspbian
# TODO: verify
set(_cross_arch "linux-armv4")
if(WIN32)
set(_conf_cmd perl Configure )
set(_cross_comp_prefix_line "")
set(_make_cmd nmake)
set(_install_cmd nmake install_sw )
else()
if(APPLE)
set(_conf_cmd export MACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} && ./Configure -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET})
else()
set(_conf_cmd "./config")
endif()
set(_cross_comp_prefix_line "")
set(_make_cmd make -j${NPROC})
set(_install_cmd make -j${NPROC} install_sw)
if (CMAKE_CROSSCOMPILING)
set(_cross_comp_prefix_line "--cross-compile-prefix=${TOOLCHAIN_PREFIX}-")

if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
set(_cross_arch "linux-aarch64")
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armhf") # For raspbian
# TODO: verify
set(_cross_arch "linux-armv4")
endif ()
endif ()
endif ()
endif()

ExternalProject_Add(dep_OpenSSL
EXCLUDE_FROM_ALL ON
URL "https://github.com/openssl/openssl/archive/OpenSSL_1_1_0l.tar.gz"
URL_HASH SHA256=e2acf0cf58d9bff2b42f2dc0aee79340c8ffe2c5e45d3ca4533dd5d4f5775b1d
DOWNLOAD_DIR ${${PROJECT_NAME}_DEP_DOWNLOAD_DIR}/OpenSSL
Expand All @@ -29,7 +49,6 @@ ExternalProject_Add(dep_OpenSSL
no-shared
no-ssl3-method
no-dynamic-engine
-Wa,--noexecstack
BUILD_COMMAND make depend && make "-j${NPROC}"
INSTALL_COMMAND make install_sw
BUILD_COMMAND ${_make_cmd}
INSTALL_COMMAND ${_install_cmd}
)
5 changes: 3 additions & 2 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ static const t_config_enum_values s_keys_map_PrintHostType {
{ "astrobox", htAstroBox },
{ "repetier", htRepetier },
{ "mks", htMKS },
{ "simplyprint", htSimplyPrint },
{ "prusaconnectnew", htPrusaConnectNew },

};
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(PrintHostType)

Expand Down Expand Up @@ -2223,7 +2223,8 @@ void PrintConfigDef::init_fff_params()
{ "flashair", "FlashAir" },
{ "astrobox", "AstroBox" },
{ "repetier", "Repetier" },
{ "mks", "MKS" }
{ "mks", "MKS" },
{ "simplyprint", "SimplyPrint" }
});
def->mode = comAdvanced;
def->cli = ConfigOptionDef::nocli;
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/PrintConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ enum class MachineLimitsUsage {
};

enum PrintHostType {
htPrusaLink, htPrusaConnect, htOctoPrint, htMoonraker, htDuet, htFlashAir, htAstroBox, htRepetier, htMKS, htPrusaConnectNew
htPrusaLink, htPrusaConnect, htOctoPrint, htMoonraker, htDuet, htFlashAir, htAstroBox, htRepetier, htMKS, htSimplyPrint, htPrusaConnectNew
};

enum AuthorizationType {
Expand Down
27 changes: 18 additions & 9 deletions src/slic3r/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@ set(SLIC3R_GUI_SOURCES
GUI/GLShadersManager.hpp
GUI/GLShadersManager.cpp
GUI/GLShader.cpp
GUI/GLShader.hpp
GUI/GLShader.hpp
GUI/GLCanvas3D.hpp
GUI/GLCanvas3D.cpp
GUI/SceneRaycaster.hpp
GUI/SceneRaycaster.cpp
GUI/SceneRaycaster.cpp
GUI/OpenGLManager.hpp
GUI/OpenGLManager.cpp
GUI/Selection.hpp
GUI/Selection.cpp
GUI/Selection.cpp
GUI/Gizmos/GLGizmosManager.cpp
GUI/Gizmos/GLGizmosManager.hpp
GUI/Gizmos/GLGizmosCommon.cpp
GUI/Gizmos/GLGizmosCommon.hpp
GUI/Gizmos/GLGizmoBase.cpp
GUI/Gizmos/GLGizmoBase.hpp
GUI/Gizmos/GLGizmoSlaBase.cpp
GUI/Gizmos/GLGizmoSlaBase.hpp
GUI/Gizmos/GLGizmoSlaBase.hpp
GUI/Gizmos/GLGizmoEmboss.cpp
GUI/Gizmos/GLGizmoEmboss.hpp
GUI/Gizmos/GLGizmoMove.cpp
Expand Down Expand Up @@ -103,7 +103,7 @@ set(SLIC3R_GUI_SOURCES
GUI/GLToolbar.hpp
GUI/GLToolbar.cpp
GUI/GCodeViewer.hpp
GUI/GCodeViewer.cpp
GUI/GCodeViewer.cpp
GUI/Preferences.cpp
GUI/Preferences.hpp
GUI/PresetHints.cpp
Expand Down Expand Up @@ -207,7 +207,7 @@ set(SLIC3R_GUI_SOURCES
Config/Snapshot.cpp
Config/Snapshot.hpp
Config/Version.cpp
Config/Version.hpp
Config/Version.hpp
Utils/ASCIIFolding.cpp
Utils/ASCIIFolding.hpp
Utils/Serial.cpp
Expand Down Expand Up @@ -235,6 +235,7 @@ set(SLIC3R_GUI_SOURCES
GUI/Jobs/BusyCursorJob.hpp
GUI/Jobs/CancellableJob.hpp
GUI/Jobs/PlaterWorker.hpp
GUI/Jobs/WindowWorker.hpp
GUI/Jobs/ArrangeJob2.hpp
GUI/Jobs/ArrangeJob2.cpp
GUI/Jobs/CreateFontNameImageJob.cpp
Expand Down Expand Up @@ -373,6 +374,14 @@ set(SLIC3R_GUI_SOURCES
Utils/Secrets.cpp
Utils/PrusaConnect.hpp
Utils/PrusaConnect.cpp
GUI/OAuthDialog.cpp
GUI/OAuthDialog.hpp
GUI/Jobs/OAuthJob.cpp
GUI/Jobs/OAuthJob.hpp
Utils/SimplyPrint.cpp
Utils/SimplyPrint.hpp
GUI/HttpServer.cpp
GUI/HttpServer.hpp
)

find_package(NanoSVG REQUIRED)
Expand Down Expand Up @@ -404,12 +413,12 @@ endforeach()

encoding_check(libslic3r_gui)

target_link_libraries(libslic3r_gui libslic3r avrdude libcereal imgui libvgcode GLEW::GLEW OpenGL::GL hidapi libcurl ${wxWidgets_LIBRARIES} NanoSVG::nanosvg NanoSVG::nanosvgrast)
target_link_libraries(libslic3r_gui libslic3r avrdude libcereal imgui libvgcode GLEW::GLEW OpenGL::GL hidapi libcurl ${wxWidgets_LIBRARIES} NanoSVG::nanosvg NanoSVG::nanosvgrast OpenSSL::SSL OpenSSL::Crypto)

if (MSVC)
target_link_libraries(libslic3r_gui Setupapi.lib)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(libslic3r_gui ${DBUS_LIBRARIES})
target_link_libraries(libslic3r_gui ${DBUS_LIBRARIES})
elseif (APPLE)
target_link_libraries(libslic3r_gui ${DISKARBITRATION_LIBRARY} ${COREWLAN_LIBRARY})
endif()
Expand All @@ -434,4 +443,4 @@ if (UNIX AND NOT APPLE)
endif ()

# Add a definition so that we can tell we are compiling slic3r.
target_compile_definitions(libslic3r_gui PRIVATE SLIC3R_CURRENTLY_COMPILING_GUI_MODULE)
target_compile_definitions(libslic3r_gui PRIVATE SLIC3R_CURRENTLY_COMPILING_GUI_MODULE)
199 changes: 199 additions & 0 deletions src/slic3r/GUI/HttpServer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
#include "HttpServer.hpp"
#include "GUI_App.hpp"
#include "slic3r/Utils/Http.hpp"
#include <boost/log/trivial.hpp>
#include <libslic3r/Thread.hpp>

namespace Slic3r {
namespace GUI {

std::string url_get_param(const std::string& url, const std::string& key)
{
size_t start = url.find(key);
if (start == std::string::npos) return "";
size_t eq = url.find('=', start);
if (eq == std::string::npos) return "";
std::string key_str = url.substr(start, eq - start);
if (key_str != key)
return "";
start += key.size() + 1;
size_t end = url.find('&', start);
if (end == std::string::npos) end = url.length(); // Last param
std::string result = url.substr(start, end - start);
return result;
}

void session::start()
{
read_first_line();
}

void session::stop()
{
boost::system::error_code ignored_ec;
socket.shutdown(boost::asio::socket_base::shutdown_both, ignored_ec);
socket.close(ignored_ec);
}

void session::read_first_line()
{
auto self(shared_from_this());

async_read_until(socket, buff, '\r', [this, self](const boost::beast::error_code& e, std::size_t s) {
if (!e) {
std::string line, ignore;
std::istream stream{&buff};
std::getline(stream, line, '\r');
std::getline(stream, ignore, '\n');
headers.on_read_request_line(line);
read_next_line();
} else if (e != boost::asio::error::operation_aborted) {
server.stop(self);
}
});
}

void session::read_body()
{
auto self(shared_from_this());

int nbuffer = 1000;
std::shared_ptr<std::vector<char>> bufptr = std::make_shared<std::vector<char>>(nbuffer);
async_read(socket, boost::asio::buffer(*bufptr, nbuffer),
[this, self](const boost::beast::error_code& e, std::size_t s) { server.stop(self); });
}

void session::read_next_line()
{
auto self(shared_from_this());

async_read_until(socket, buff, '\r', [this, self](const boost::beast::error_code& e, std::size_t s) {
if (!e) {
std::string line, ignore;
std::istream stream{&buff};
std::getline(stream, line, '\r');
std::getline(stream, ignore, '\n');
headers.on_read_header(line);

if (line.length() == 0) {
if (headers.content_length() == 0) {
const std::string url_str = Http::url_decode(headers.get_url());
const auto resp = server.server.m_request_handler(url_str);
std::stringstream ssOut;
resp->write_response(ssOut);
std::shared_ptr<std::string> str = std::make_shared<std::string>(ssOut.str());
async_write(socket, boost::asio::buffer(str->c_str(), str->length()),
[this, self](const boost::beast::error_code& e, std::size_t s) {
std::cout << "done" << std::endl;
server.stop(self);
});
} else {
read_body();
}
} else {
read_next_line();
}
} else if (e != boost::asio::error::operation_aborted) {
server.stop(self);
}
});
}

void HttpServer::IOServer::do_accept()
{
acceptor.async_accept([this](boost::system::error_code ec, boost::asio::ip::tcp::socket socket) {
if (!acceptor.is_open()) {
return;
}

if (!ec) {
const auto ss = std::make_shared<session>(*this, std::move(socket));
start(ss);
}

do_accept();
});
}

void HttpServer::IOServer::start(std::shared_ptr<session> session)
{
sessions.insert(session);
session->start();
}

void HttpServer::IOServer::stop(std::shared_ptr<session> session)
{
sessions.erase(session);
session->stop();
}

void HttpServer::IOServer::stop_all()
{
for (auto s : sessions) {
s->stop();
}
sessions.clear();
}


HttpServer::HttpServer(boost::asio::ip::port_type port) : port(port) {}

void HttpServer::start()
{
BOOST_LOG_TRIVIAL(info) << "start_http_service...";
if (!m_request_handler) {
BOOST_LOG_TRIVIAL(error) << "Http Server failed to start! Reason: Started without a request handler";
throw RuntimeError("Http Server failed to start! Reason: Started without a request handler");
}
start_http_server = true;
m_http_server_thread = create_thread([this] {
set_current_thread_name("http_server");
server_ = std::make_unique<IOServer>(*this);
server_->acceptor.listen();

server_->do_accept();

server_->io_service.run();
});
}

void HttpServer::stop()
{
start_http_server = false;
if (server_) {
server_->acceptor.close();
server_->stop_all();
}
if (m_http_server_thread.joinable())
m_http_server_thread.join();
server_.reset();
}

void HttpServer::set_request_handler(const std::function<std::shared_ptr<Response>(const std::string&)>& request_handler)
{
this->m_request_handler = request_handler;
}

void HttpServer::ResponseNotFound::write_response(std::stringstream& ssOut)
{
const std::string sHTML = "<html><body><h1>404 Not Found</h1><p>There's nothing here.</p></body></html>";
ssOut << "HTTP/1.1 404 Not Found" << std::endl;
ssOut << "content-type: text/html" << std::endl;
ssOut << "content-length: " << sHTML.length() << std::endl;
ssOut << std::endl;
ssOut << sHTML;
}

void HttpServer::ResponseRedirect::write_response(std::stringstream& ssOut)
{
const std::string sHTML = "<html><body><p>redirect to url </p></body></html>";
ssOut << "HTTP/1.1 302 Found" << std::endl;
ssOut << "Location: " << location_str << std::endl;
ssOut << "content-type: text/html" << std::endl;
ssOut << "content-length: " << sHTML.length() << std::endl;
ssOut << std::endl;
ssOut << sHTML;
}

} // GUI
} //Slic3r
Loading