mirror of
https://github.com/PabloMK7/citra.git
synced 2024-11-27 01:44:04 +00:00
Services/HTTP: Added error handling to AddRequestHeader
This commit is contained in:
parent
03294ce6b4
commit
d19dbe8419
1 changed files with 38 additions and 7 deletions
|
@ -11,6 +11,7 @@ namespace HTTP {
|
||||||
|
|
||||||
namespace ErrCodes {
|
namespace ErrCodes {
|
||||||
enum {
|
enum {
|
||||||
|
InvalidRequestState = 22,
|
||||||
TooManyContexts = 26,
|
TooManyContexts = 26,
|
||||||
InvalidRequestMethod = 32,
|
InvalidRequestMethod = 32,
|
||||||
ContextNotFound = 100,
|
ContextNotFound = 100,
|
||||||
|
@ -209,19 +210,49 @@ void HTTP_C::AddRequestHeader(Kernel::HLERequestContext& ctx) {
|
||||||
// Copy the name_buffer into a string without the \0 at the end
|
// Copy the name_buffer into a string without the \0 at the end
|
||||||
const std::string name(name_buffer.begin(), name_buffer.end() - 1);
|
const std::string name(name_buffer.begin(), name_buffer.end() - 1);
|
||||||
|
|
||||||
// Copy thr value_buffer into a string without the \0 at the end
|
// Copy the value_buffer into a string without the \0 at the end
|
||||||
std::string value(value_size - 1, '\0');
|
std::string value(value_size - 1, '\0');
|
||||||
value_buffer.Read(&value[0], 0, value_size - 1);
|
value_buffer.Read(&value[0], 0, value_size - 1);
|
||||||
|
|
||||||
auto itr = contexts.find(context_handle);
|
auto* session_data = GetSessionData(ctx.Session());
|
||||||
if (itr == contexts.end()) {
|
ASSERT(session_data);
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
||||||
|
if (!session_data->initialized) {
|
||||||
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
||||||
rb.Push(ERROR_STATE_ERROR);
|
rb.Push(ERROR_STATE_ERROR);
|
||||||
LOG_ERROR(Service_HTTP, "called, context {} not found", context_handle);
|
rb.PushMappedBuffer(value_buffer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This command can only be called with a bound context
|
||||||
|
if (session_data->current_http_context == boost::none) {
|
||||||
|
LOG_ERROR(Service_HTTP, "Command called without a bound context");
|
||||||
|
|
||||||
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
||||||
|
rb.Push(ResultCode(ErrorDescription::NotImplemented, ErrorModule::HTTP,
|
||||||
|
ErrorSummary::Internal, ErrorLevel::Permanent));
|
||||||
|
rb.PushMappedBuffer(value_buffer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session_data->current_http_context != context_handle) {
|
||||||
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
||||||
|
rb.Push(ERROR_STATE_ERROR);
|
||||||
|
rb.PushMappedBuffer(value_buffer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto itr = contexts.find(context_handle);
|
||||||
|
ASSERT(itr != contexts.end());
|
||||||
|
|
||||||
|
if (itr->second.state != RequestState::NotStarted) {
|
||||||
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
||||||
|
rb.Push(ResultCode(ErrCodes::InvalidRequestState, ErrorModule::HTTP,
|
||||||
|
ErrorSummary::InvalidState, ErrorLevel::Permanent));
|
||||||
|
rb.PushMappedBuffer(value_buffer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(itr->second.state == RequestState::NotStarted);
|
|
||||||
ASSERT(std::find_if(itr->second.headers.begin(), itr->second.headers.end(),
|
ASSERT(std::find_if(itr->second.headers.begin(), itr->second.headers.end(),
|
||||||
[&name](const Context::RequestHeader& m) -> bool {
|
[&name](const Context::RequestHeader& m) -> bool {
|
||||||
return m.name == name;
|
return m.name == name;
|
||||||
|
@ -233,7 +264,7 @@ void HTTP_C::AddRequestHeader(Kernel::HLERequestContext& ctx) {
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
rb.PushMappedBuffer(value_buffer);
|
rb.PushMappedBuffer(value_buffer);
|
||||||
|
|
||||||
LOG_WARNING(Service_HTTP, "called, name={}, value={}, context_handle={}", name, value,
|
LOG_DEBUG(Service_HTTP, "called, name={}, value={}, context_handle={}", name, value,
|
||||||
context_handle);
|
context_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue