Services/HTTP: Implemented the CreateContext function handler.
This commit is contained in:
parent
87ec3934a6
commit
70e6979695
|
@ -13,6 +13,7 @@ namespace Service {
|
|||
namespace HTTP {
|
||||
|
||||
enum class RequestMethod : u8 {
|
||||
None = 0x0,
|
||||
Get = 0x1,
|
||||
Post = 0x2,
|
||||
Head = 0x3,
|
||||
|
@ -22,6 +23,9 @@ enum class RequestMethod : u8 {
|
|||
PutEmpty = 0x7,
|
||||
};
|
||||
|
||||
/// The number of request methods, any valid method must be less than this.
|
||||
constexpr u32 TotalRequestMethods = 8;
|
||||
|
||||
enum class RequestState : u8 {
|
||||
NotStarted = 0x1, // Request has not started yet.
|
||||
InProgress = 0x5, // Request in progress, sending request over the network.
|
||||
|
@ -112,10 +116,41 @@ void HTTP_C::Initialize(Kernel::HLERequestContext& ctx) {
|
|||
LOG_WARNING(Service_HTTP, "(STUBBED) called, shared memory size: {}", shmem_size);
|
||||
}
|
||||
|
||||
void HTTP_C::CreateContext(Kernel::HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp(ctx, 0x2, 2, 2);
|
||||
const u32 url_size = rp.Pop<u32>();
|
||||
std::string url(url_size, '\0');
|
||||
RequestMethod method = rp.PopEnum<RequestMethod>();
|
||||
|
||||
Kernel::MappedBuffer& buffer = rp.PopMappedBuffer();
|
||||
buffer.Read(&url[0], 0, url_size - 1);
|
||||
|
||||
LOG_DEBUG(Service_HTTP, "called, url_size={}, url={}, method={}", url_size, url,
|
||||
static_cast<u32>(method));
|
||||
|
||||
// TODO(Subv): Find the right error code for this case.
|
||||
ASSERT_MSG(method == RequestMethod::None && static_cast<u32>(method) < TotalRequestMethods,
|
||||
"Invalid request method {}", static_cast<u32>(method));
|
||||
|
||||
Context context{};
|
||||
context.url = std::move(url);
|
||||
context.method = method;
|
||||
context.state = RequestState::NotStarted;
|
||||
// TODO(Subv): Find a correct default value for this field.
|
||||
context.socket_buffer_size = 0;
|
||||
context.handle = ++context_counter;
|
||||
contexts[context_counter] = std::move(context);
|
||||
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(2, 2);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
rb.Push<u32>(context_counter);
|
||||
rb.PushMappedBuffer(buffer);
|
||||
}
|
||||
|
||||
HTTP_C::HTTP_C() : ServiceFramework("http:C", 32) {
|
||||
static const FunctionInfo functions[] = {
|
||||
{0x00010044, &HTTP_C::Initialize, "Initialize"},
|
||||
{0x00020082, nullptr, "CreateContext"},
|
||||
{0x00020082, &HTTP_C::CreateContext, "CreateContext"},
|
||||
{0x00030040, nullptr, "CloseContext"},
|
||||
{0x00040040, nullptr, "CancelConnection"},
|
||||
{0x00050040, nullptr, "GetRequestState"},
|
||||
|
|
|
@ -32,6 +32,19 @@ private:
|
|||
*/
|
||||
void Initialize(Kernel::HLERequestContext& ctx);
|
||||
|
||||
/**
|
||||
* HTTP_C::CreateContext service function
|
||||
* Inputs:
|
||||
* 1 : URL buffer size, including null-terminator
|
||||
* 2 : RequestMethod
|
||||
* 3 : (URLSize << 4) | 10
|
||||
* 4 : URL data pointer
|
||||
* Outputs:
|
||||
* 1 : Result of function, 0 on success, otherwise error code
|
||||
* 2 : HTTP context handle
|
||||
*/
|
||||
void CreateContext(Kernel::HLERequestContext& ctx);
|
||||
|
||||
Kernel::SharedPtr<Kernel::SharedMemory> shared_memory = nullptr;
|
||||
|
||||
std::unordered_map<u32, Context> contexts;
|
||||
|
|
Reference in New Issue