1
0
Fork 0

Services/HTTP: Added structures to represent an HTTP context.

More fields will probably need to be added to these structures in the future.
This commit is contained in:
B3n30 2018-07-21 19:10:00 -05:00 committed by Subv
parent fe5a3d22c5
commit 87ec3934a6
2 changed files with 73 additions and 0 deletions

View File

@ -2,7 +2,9 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <string>
#include <vector>
#include <boost/optional.hpp>
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/ipc.h"
#include "core/hle/service/http_c.h"
@ -10,6 +12,24 @@
namespace Service {
namespace HTTP {
enum class RequestMethod : u8 {
Get = 0x1,
Post = 0x2,
Head = 0x3,
Put = 0x4,
Delete = 0x5,
PostEmpty = 0x6,
PutEmpty = 0x7,
};
enum class RequestState : u8 {
NotStarted = 0x1, // Request has not started yet.
InProgress = 0x5, // Request in progress, sending request over the network.
ReadyToDownloadContent = 0x7, // Ready to download the content. (needs verification)
ReadyToDownload = 0x8, // Ready to download?
TimedOut = 0xA, // Request timed out?
};
/// Represents a client certificate along with its private key, stored as a byte array of DER data.
/// There can only be at most one client certificate context attached to an HTTP context at any
/// given time.
@ -32,6 +52,49 @@ struct RootCertChain {
std::vector<RootCACert> certificates;
};
/// Represents an HTTP context.
struct Context {
struct Proxy {
std::string url;
std::string username;
std::string password;
u16 port;
};
struct BasicAuth {
std::string username;
std::string password;
};
struct RequestHeader {
std::string name;
std::string value;
};
struct PostData {
// TODO(Subv): Support Binary and Raw POST elements.
std::string name;
std::string value;
};
struct SSLConfig {
u32 options;
std::weak_ptr<ClientCertContext> client_cert_ctx;
std::weak_ptr<RootCertChain> root_ca_chain;
};
u32 handle;
std::string url;
RequestMethod method;
RequestState state = RequestState::NotStarted;
boost::optional<Proxy> proxy;
boost::optional<BasicAuth> basic_auth;
SSLConfig ssl_config{};
u32 socket_buffer_size;
std::vector<RequestHeader> headers;
std::vector<PostData> post_data;
};
void HTTP_C::Initialize(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x1, 1, 4);
const u32 shmem_size = rp.Pop<u32>();

View File

@ -4,12 +4,16 @@
#pragma once
#include <unordered_map>
#include "core/hle/kernel/shared_memory.h"
#include "core/hle/service/service.h"
namespace Service {
namespace HTTP {
struct Context;
struct ClientCertContext;
class HTTP_C final : public ServiceFramework<HTTP_C> {
public:
HTTP_C();
@ -29,6 +33,12 @@ private:
void Initialize(Kernel::HLERequestContext& ctx);
Kernel::SharedPtr<Kernel::SharedMemory> shared_memory = nullptr;
std::unordered_map<u32, Context> contexts;
u32 context_counter = 0;
std::unordered_map<u32, ClientCertContext> client_certs;
u32 client_certs_counter = 0;
};
void InstallInterfaces(SM::ServiceManager& service_manager);