diff --git a/TODO b/TODO index 51cbc627c..f72330fd1 100644 --- a/TODO +++ b/TODO @@ -84,7 +84,7 @@ ✔ GSP @done(19-12-30 12:45) ☐ Fix the global weak_ptr to gsp ✔ HID @done(19-12-30 14:46) - ☐ HTTP + ✔ HTTP @done(19-12-30 15:18) ☐ IR ☐ LDR_RO ☐ MIC diff --git a/externals/boost b/externals/boost index 1c857c041..65dc954e9 160000 --- a/externals/boost +++ b/externals/boost @@ -1 +1 @@ -Subproject commit 1c857c04195db89c66c347ddfad93a7f3666f2d3 +Subproject commit 65dc954e93b22870b8423701e225147c75e3b31b diff --git a/src/core/hle/service/http_c.cpp b/src/core/hle/service/http_c.cpp index 221f3cc20..768dd3bd8 100644 --- a/src/core/hle/service/http_c.cpp +++ b/src/core/hle/service/http_c.cpp @@ -4,6 +4,7 @@ #include #include +#include "common/archives.h" #include "core/core.h" #include "core/file_sys/archive_ncch.h" #include "core/file_sys/file_backend.h" @@ -14,6 +15,9 @@ #include "core/hle/service/http_c.h" #include "core/hw/aes/key.h" +SERIALIZE_EXPORT_IMPL(Service::HTTP::HTTP_C) +SERIALIZE_EXPORT_IMPL(Service::HTTP::SessionData) + namespace Service::HTTP { namespace ErrCodes { diff --git a/src/core/hle/service/http_c.h b/src/core/hle/service/http_c.h index 91a455820..a3aa62ae0 100644 --- a/src/core/hle/service/http_c.h +++ b/src/core/hle/service/http_c.h @@ -5,10 +5,16 @@ #pragma once #include -#include #include #include #include +#include +#include +#include +#include +#include +#include +#include #include "core/hle/kernel/shared_memory.h" #include "core/hle/service/service.h" @@ -50,6 +56,17 @@ struct ClientCertContext { u8 cert_id; std::vector certificate; std::vector private_key; + +private: + template + void serialize(Archive& ar, const unsigned int) { + ar& handle; + ar& session_id; + ar& cert_id; + ar& certificate; + ar& private_key; + } + friend class boost::serialization::access; }; /// Represents a root certificate chain, it contains a list of DER-encoded certificates for @@ -61,12 +78,30 @@ struct RootCertChain { Handle handle; u32 session_id; std::vector certificate; + + private: + template + void serialize(Archive& ar, const unsigned int) { + ar& handle; + ar& session_id; + ar& certificate; + } + friend class boost::serialization::access; }; using Handle = u32; Handle handle; u32 session_id; std::vector certificates; + +private: + template + void serialize(Archive& ar, const unsigned int) { + ar& handle; + ar& session_id; + ar& certificates; + } + friend class boost::serialization::access; }; /// Represents an HTTP context. @@ -86,30 +121,74 @@ public: std::string username; std::string password; u16 port; + + private: + template + void serialize(Archive& ar, const unsigned int) { + ar& url; + ar& username; + ar& password; + ar& port; + } + friend class boost::serialization::access; }; struct BasicAuth { std::string username; std::string password; + + private: + template + void serialize(Archive& ar, const unsigned int) { + ar& username; + ar& password; + } + friend class boost::serialization::access; }; struct RequestHeader { RequestHeader(std::string name, std::string value) : name(name), value(value){}; std::string name; std::string value; + + private: + template + void serialize(Archive& ar, const unsigned int) { + ar& name; + ar& value; + } + friend class boost::serialization::access; }; struct PostData { // TODO(Subv): Support Binary and Raw POST elements. PostData(std::string name, std::string value) : name(name), value(value){}; + PostData() = default; std::string name; std::string value; + + private: + template + void serialize(Archive& ar, const unsigned int) { + ar& name; + ar& value; + } + friend class boost::serialization::access; }; struct SSLConfig { u32 options; std::weak_ptr client_cert_ctx; std::weak_ptr root_ca_chain; + + private: + template + void serialize(Archive& ar, const unsigned int) { + ar& options; + ar& client_cert_ctx; + ar& root_ca_chain; + } + friend class boost::serialization::access; }; Handle handle; @@ -117,18 +196,35 @@ public: std::string url; RequestMethod method; RequestState state = RequestState::NotStarted; - std::optional proxy; - std::optional basic_auth; + boost::optional proxy; + boost::optional basic_auth; SSLConfig ssl_config{}; u32 socket_buffer_size; std::vector headers; std::vector post_data; + +private: + template + void serialize(Archive& ar, const unsigned int) { + ar& handle; + ar& session_id; + ar& url; + ar& method; + ar& state; + ar& proxy; + ar& basic_auth; + ar& ssl_config; + ar& socket_buffer_size; + ar& headers; + ar& post_data; + } + friend class boost::serialization::access; }; struct SessionData : public Kernel::SessionRequestHandler::SessionDataBase { /// The HTTP context that is currently bound to this session, this can be empty if no context /// has been bound. Certain commands can only be called on a session with a bound context. - std::optional current_http_context; + boost::optional current_http_context; u32 session_id; @@ -140,6 +236,17 @@ struct SessionData : public Kernel::SessionRequestHandler::SessionDataBase { /// Whether this session has been initialized in some way, be it via Initialize or /// InitializeConnectionSession. bool initialized = false; + +private: + template + void serialize(Archive& ar, const unsigned int) { + ar& current_http_context; + ar& session_id; + ar& num_http_contexts; + ar& num_client_certs; + ar& initialized; + } + friend class boost::serialization::access; }; class HTTP_C final : public ServiceFramework { @@ -326,8 +433,21 @@ private: std::vector private_key; bool init = false; } ClCertA; + +private: + template + void serialize(Archive& ar, const unsigned int) { + ar& boost::serialization::base_object(*this); + ar& ClCertA.certificate; + ar& ClCertA.private_key; + ar& ClCertA.init; + } + friend class boost::serialization::access; }; void InstallInterfaces(Core::System& system); } // namespace Service::HTTP + +BOOST_CLASS_EXPORT_KEY(Service::HTTP::HTTP_C) +BOOST_CLASS_EXPORT_KEY(Service::HTTP::SessionData)