Merge branch 'httpc' into online
This commit is contained in:
commit
cdbcd709d3
@ -95,6 +95,7 @@ option(USE_SYSTEM_OPENSSL "Use the system OpenSSL libs (instead of the bundled L
|
|||||||
option(USE_SYSTEM_LIBUSB "Use the system libusb (instead of the bundled libusb)" OFF)
|
option(USE_SYSTEM_LIBUSB "Use the system libusb (instead of the bundled libusb)" OFF)
|
||||||
option(USE_SYSTEM_CPP_JWT "Use the system cpp-jwt (instead of the bundled one)" OFF)
|
option(USE_SYSTEM_CPP_JWT "Use the system cpp-jwt (instead of the bundled one)" OFF)
|
||||||
option(USE_SYSTEM_SOUNDTOUCH "Use the system SoundTouch (instead of the bundled one)" OFF)
|
option(USE_SYSTEM_SOUNDTOUCH "Use the system SoundTouch (instead of the bundled one)" OFF)
|
||||||
|
option(USE_SYSTEM_CPP_HTTPLIB "Use the system cpp-httplib (instead of the bundled one)" OFF)
|
||||||
|
|
||||||
if (CITRA_USE_PRECOMPILED_HEADERS)
|
if (CITRA_USE_PRECOMPILED_HEADERS)
|
||||||
message(STATUS "Using Precompiled Headers.")
|
message(STATUS "Using Precompiled Headers.")
|
||||||
|
13
externals/CMakeLists.txt
vendored
13
externals/CMakeLists.txt
vendored
@ -190,7 +190,7 @@ if (NOT OPENSSL_FOUND)
|
|||||||
set(LIBRESSL_SKIP_INSTALL ON CACHE BOOL "")
|
set(LIBRESSL_SKIP_INSTALL ON CACHE BOOL "")
|
||||||
set(OPENSSLDIR "/etc/ssl/")
|
set(OPENSSLDIR "/etc/ssl/")
|
||||||
add_subdirectory(libressl EXCLUDE_FROM_ALL)
|
add_subdirectory(libressl EXCLUDE_FROM_ALL)
|
||||||
target_include_directories(ssl INTERFACE ./libressl/include)
|
target_include_directories(ssl SYSTEM INTERFACE ./libressl/include)
|
||||||
target_compile_definitions(ssl PRIVATE -DHAVE_INET_NTOP)
|
target_compile_definitions(ssl PRIVATE -DHAVE_INET_NTOP)
|
||||||
get_directory_property(OPENSSL_LIBRARIES
|
get_directory_property(OPENSSL_LIBRARIES
|
||||||
DIRECTORY libressl
|
DIRECTORY libressl
|
||||||
@ -199,8 +199,13 @@ endif()
|
|||||||
|
|
||||||
# httplib
|
# httplib
|
||||||
add_library(httplib INTERFACE)
|
add_library(httplib INTERFACE)
|
||||||
target_include_directories(httplib INTERFACE ./httplib)
|
if(USE_SYSTEM_CPP_HTTPLIB)
|
||||||
target_compile_options(httplib INTERFACE -DCPPHTTPLIB_OPENSSL_SUPPORT -DCPPHTTPLIB_NO_DEFAULT_USER_AGENT)
|
find_package(CppHttp REQUIRED)
|
||||||
|
target_link_libraries(httplib SYSTEM INTERFACE cpp-httplib::cpp-httplib)
|
||||||
|
else()
|
||||||
|
target_include_directories(httplib SYSTEM INTERFACE ./httplib)
|
||||||
|
endif()
|
||||||
|
target_compile_options(httplib INTERFACE -DCPPHTTPLIB_OPENSSL_SUPPORT)
|
||||||
target_link_libraries(httplib INTERFACE ${OPENSSL_LIBRARIES})
|
target_link_libraries(httplib INTERFACE ${OPENSSL_LIBRARIES})
|
||||||
|
|
||||||
if(ANDROID)
|
if(ANDROID)
|
||||||
@ -216,7 +221,7 @@ if (ENABLE_WEB_SERVICE)
|
|||||||
target_link_libraries(cpp-jwt INTERFACE cpp-jwt::cpp-jwt)
|
target_link_libraries(cpp-jwt INTERFACE cpp-jwt::cpp-jwt)
|
||||||
else()
|
else()
|
||||||
add_library(cpp-jwt INTERFACE)
|
add_library(cpp-jwt INTERFACE)
|
||||||
target_include_directories(cpp-jwt INTERFACE ./cpp-jwt/include)
|
target_include_directories(cpp-jwt SYSTEM INTERFACE ./cpp-jwt/include)
|
||||||
target_compile_definitions(cpp-jwt INTERFACE CPP_JWT_USE_VENDORED_NLOHMANN_JSON)
|
target_compile_definitions(cpp-jwt INTERFACE CPP_JWT_USE_VENDORED_NLOHMANN_JSON)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
35
externals/cmake-modules/FindCppHttp.cmake
vendored
Normal file
35
externals/cmake-modules/FindCppHttp.cmake
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
if(NOT CppHttp_FOUND)
|
||||||
|
pkg_check_modules(HTTP_TMP cpp-httplib)
|
||||||
|
|
||||||
|
find_path(CPP-HTTP_INCLUDE_DIR NAMES httplib.h
|
||||||
|
PATHS
|
||||||
|
${HTTP_TMP_INCLUDE_DIRS}
|
||||||
|
/usr/include
|
||||||
|
/usr/local/include
|
||||||
|
)
|
||||||
|
|
||||||
|
find_library(CPP-HTTP_LIBRARIES NAMES cpp-httplib
|
||||||
|
PATHS
|
||||||
|
${HTTP_TMP_LIBRARY_DIRS}
|
||||||
|
/usr/lib
|
||||||
|
/usr/local/lib
|
||||||
|
)
|
||||||
|
|
||||||
|
if(CPP-HTTP_INCLUDE_DIR AND CPP-HTTP_LIBRARIES)
|
||||||
|
set(CppHttp_FOUND TRUE CACHE INTERNAL "cpp-httplib found")
|
||||||
|
message(STATUS "Found cpp-httplib: ${CPP-HTTP_INCLUDE_DIR}, ${CPP-HTTP_LIBRARIES}")
|
||||||
|
else()
|
||||||
|
set(CppHttp_FOUND FALSE CACHE INTERNAL "cpp-httplib found")
|
||||||
|
message(STATUS "Cpp-httplib not found.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CppHttp_FOUND AND NOT TARGET cpp-httplib::cpp-httplib)
|
||||||
|
add_library(cpp-httplib::cpp-httplib INTERFACE IMPORTED)
|
||||||
|
set_target_properties(cpp-httplib::cpp-httplib PROPERTIES
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${CPP-HTTP_INCLUDE_DIR}"
|
||||||
|
INTERFACE_LINK_LIBRARIES "${CPP-HTTP_LIBRARIES}"
|
||||||
|
IMPORTED_LOCATION "${CPP-HTTP_LIBRARIES}"
|
||||||
|
)
|
||||||
|
endif()
|
6
externals/httplib/httplib.h
vendored
6
externals/httplib/httplib.h
vendored
@ -245,6 +245,12 @@ using socket_t = int;
|
|||||||
#undef X509_EXTENSIONS
|
#undef X509_EXTENSIONS
|
||||||
#undef PKCS7_SIGNER_INFO
|
#undef PKCS7_SIGNER_INFO
|
||||||
|
|
||||||
|
// libressl will warn without this, which becomes an error.
|
||||||
|
#undef OCSP_REQUEST
|
||||||
|
#undef OCSP_RESPONSE
|
||||||
|
#undef PKCS7_ISSUER_AND_SERIAL
|
||||||
|
#undef __WINCRYPT_H__
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma comment(lib, "crypt32.lib")
|
#pragma comment(lib, "crypt32.lib")
|
||||||
#pragma comment(lib, "cryptui.lib")
|
#pragma comment(lib, "cryptui.lib")
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#include "core/memory.h"
|
#include "core/memory.h"
|
||||||
|
|
||||||
namespace Service::DSP {
|
namespace Service::DSP {
|
||||||
class DSP_DSP;
|
enum class InterruptType : u32;
|
||||||
} // namespace Service::DSP
|
} // namespace Service::DSP
|
||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
@ -85,8 +85,9 @@ public:
|
|||||||
/// Returns a reference to the array backing DSP memory
|
/// Returns a reference to the array backing DSP memory
|
||||||
virtual std::array<u8, Memory::DSP_RAM_SIZE>& GetDspMemory() = 0;
|
virtual std::array<u8, Memory::DSP_RAM_SIZE>& GetDspMemory() = 0;
|
||||||
|
|
||||||
/// Sets the dsp class that we trigger interrupts for
|
/// Sets the handler for the interrupts we trigger
|
||||||
virtual void SetServiceToInterrupt(std::weak_ptr<Service::DSP::DSP_DSP> dsp) = 0;
|
virtual void SetInterruptHandler(
|
||||||
|
std::function<void(Service::DSP::InterruptType type, DspPipe pipe)> handler) = 0;
|
||||||
|
|
||||||
/// Loads the DSP program
|
/// Loads the DSP program
|
||||||
virtual void LoadComponent(std::span<const u8> buffer) = 0;
|
virtual void LoadComponent(std::span<const u8> buffer) = 0;
|
||||||
|
@ -34,8 +34,7 @@
|
|||||||
|
|
||||||
SERIALIZE_EXPORT_IMPL(AudioCore::DspHle)
|
SERIALIZE_EXPORT_IMPL(AudioCore::DspHle)
|
||||||
|
|
||||||
using InterruptType = Service::DSP::DSP_DSP::InterruptType;
|
using InterruptType = Service::DSP::InterruptType;
|
||||||
using Service::DSP::DSP_DSP;
|
|
||||||
|
|
||||||
namespace AudioCore {
|
namespace AudioCore {
|
||||||
|
|
||||||
@ -71,7 +70,8 @@ public:
|
|||||||
|
|
||||||
std::array<u8, Memory::DSP_RAM_SIZE>& GetDspMemory();
|
std::array<u8, Memory::DSP_RAM_SIZE>& GetDspMemory();
|
||||||
|
|
||||||
void SetServiceToInterrupt(std::weak_ptr<DSP_DSP> dsp);
|
void SetInterruptHandler(
|
||||||
|
std::function<void(Service::DSP::InterruptType type, DspPipe pipe)> handler);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ResetPipes();
|
void ResetPipes();
|
||||||
@ -105,7 +105,7 @@ private:
|
|||||||
|
|
||||||
std::unique_ptr<HLE::DecoderBase> decoder{};
|
std::unique_ptr<HLE::DecoderBase> decoder{};
|
||||||
|
|
||||||
std::weak_ptr<DSP_DSP> dsp_dsp{};
|
std::function<void(Service::DSP::InterruptType type, DspPipe pipe)> interrupt_handler{};
|
||||||
|
|
||||||
template <class Archive>
|
template <class Archive>
|
||||||
void serialize(Archive& ar, const unsigned int) {
|
void serialize(Archive& ar, const unsigned int) {
|
||||||
@ -114,7 +114,8 @@ private:
|
|||||||
ar& dsp_memory.raw_memory;
|
ar& dsp_memory.raw_memory;
|
||||||
ar& sources;
|
ar& sources;
|
||||||
ar& mixers;
|
ar& mixers;
|
||||||
ar& dsp_dsp;
|
// interrupt_handler is function pointer and cant be serialised, fortunately though, it
|
||||||
|
// should be registerd before the game has started
|
||||||
}
|
}
|
||||||
friend class boost::serialization::access;
|
friend class boost::serialization::access;
|
||||||
};
|
};
|
||||||
@ -320,10 +321,8 @@ void DspHle::Impl::PipeWrite(DspPipe pipe_number, std::span<const u8> buffer) {
|
|||||||
pipe_data[static_cast<u32>(pipe_number)].resize(sizeof(value));
|
pipe_data[static_cast<u32>(pipe_number)].resize(sizeof(value));
|
||||||
std::memcpy(pipe_data[static_cast<u32>(pipe_number)].data(), &value, sizeof(value));
|
std::memcpy(pipe_data[static_cast<u32>(pipe_number)].data(), &value, sizeof(value));
|
||||||
}
|
}
|
||||||
auto dsp = dsp_dsp.lock();
|
|
||||||
if (dsp) {
|
interrupt_handler(InterruptType::Pipe, DspPipe::Binary);
|
||||||
dsp->SignalInterrupt(InterruptType::Pipe, DspPipe::Binary);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -338,8 +337,9 @@ std::array<u8, Memory::DSP_RAM_SIZE>& DspHle::Impl::GetDspMemory() {
|
|||||||
return dsp_memory.raw_memory;
|
return dsp_memory.raw_memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DspHle::Impl::SetServiceToInterrupt(std::weak_ptr<DSP_DSP> dsp) {
|
void DspHle::Impl::SetInterruptHandler(
|
||||||
dsp_dsp = std::move(dsp);
|
std::function<void(Service::DSP::InterruptType type, DspPipe pipe)> handler) {
|
||||||
|
interrupt_handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DspHle::Impl::ResetPipes() {
|
void DspHle::Impl::ResetPipes() {
|
||||||
@ -386,9 +386,7 @@ void DspHle::Impl::AudioPipeWriteStructAddresses() {
|
|||||||
WriteU16(DspPipe::Audio, addr);
|
WriteU16(DspPipe::Audio, addr);
|
||||||
}
|
}
|
||||||
// Signal that we have data on this pipe.
|
// Signal that we have data on this pipe.
|
||||||
if (auto service = dsp_dsp.lock()) {
|
interrupt_handler(InterruptType::Pipe, DspPipe::Audio);
|
||||||
service->SignalInterrupt(InterruptType::Pipe, DspPipe::Audio);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t DspHle::Impl::CurrentRegionIndex() const {
|
size_t DspHle::Impl::CurrentRegionIndex() const {
|
||||||
@ -464,9 +462,7 @@ bool DspHle::Impl::Tick() {
|
|||||||
void DspHle::Impl::AudioTickCallback(s64 cycles_late) {
|
void DspHle::Impl::AudioTickCallback(s64 cycles_late) {
|
||||||
if (Tick()) {
|
if (Tick()) {
|
||||||
// TODO(merry): Signal all the other interrupts as appropriate.
|
// TODO(merry): Signal all the other interrupts as appropriate.
|
||||||
if (auto service = dsp_dsp.lock()) {
|
interrupt_handler(InterruptType::Pipe, DspPipe::Audio);
|
||||||
service->SignalInterrupt(InterruptType::Pipe, DspPipe::Audio);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reschedule recurrent event
|
// Reschedule recurrent event
|
||||||
@ -505,9 +501,10 @@ std::array<u8, Memory::DSP_RAM_SIZE>& DspHle::GetDspMemory() {
|
|||||||
return impl->GetDspMemory();
|
return impl->GetDspMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DspHle::SetServiceToInterrupt(std::weak_ptr<DSP_DSP> dsp) {
|
void DspHle::SetInterruptHandler(
|
||||||
impl->SetServiceToInterrupt(std::move(dsp));
|
std::function<void(Service::DSP::InterruptType type, DspPipe pipe)> handler) {
|
||||||
}
|
impl->SetInterruptHandler(handler);
|
||||||
|
};
|
||||||
|
|
||||||
void DspHle::LoadComponent(std::span<const u8> component_data) {
|
void DspHle::LoadComponent(std::span<const u8> component_data) {
|
||||||
// HLE doesn't need DSP program. Only log some info here
|
// HLE doesn't need DSP program. Only log some info here
|
||||||
|
@ -34,7 +34,8 @@ public:
|
|||||||
|
|
||||||
std::array<u8, Memory::DSP_RAM_SIZE>& GetDspMemory() override;
|
std::array<u8, Memory::DSP_RAM_SIZE>& GetDspMemory() override;
|
||||||
|
|
||||||
void SetServiceToInterrupt(std::weak_ptr<Service::DSP::DSP_DSP> dsp) override;
|
void SetInterruptHandler(
|
||||||
|
std::function<void(Service::DSP::InterruptType type, DspPipe pipe)> handler) override;
|
||||||
|
|
||||||
void LoadComponent(std::span<const u8> buffer) override;
|
void LoadComponent(std::span<const u8> buffer) override;
|
||||||
void UnloadComponent() override;
|
void UnloadComponent() override;
|
||||||
|
@ -408,29 +408,24 @@ std::array<u8, Memory::DSP_RAM_SIZE>& DspLle::GetDspMemory() {
|
|||||||
return impl->teakra.GetDspMemory();
|
return impl->teakra.GetDspMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DspLle::SetServiceToInterrupt(std::weak_ptr<Service::DSP::DSP_DSP> dsp) {
|
void DspLle::SetInterruptHandler(
|
||||||
impl->teakra.SetRecvDataHandler(0, [this, dsp]() {
|
std::function<void(Service::DSP::InterruptType type, DspPipe pipe)> handler) {
|
||||||
|
impl->teakra.SetRecvDataHandler(0, [this, handler]() {
|
||||||
if (!impl->loaded)
|
if (!impl->loaded)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::lock_guard lock(HLE::g_hle_lock);
|
std::lock_guard lock(HLE::g_hle_lock);
|
||||||
if (auto locked = dsp.lock()) {
|
handler(Service::DSP::InterruptType::Zero, static_cast<DspPipe>(0));
|
||||||
locked->SignalInterrupt(Service::DSP::DSP_DSP::InterruptType::Zero,
|
|
||||||
static_cast<DspPipe>(0));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
impl->teakra.SetRecvDataHandler(1, [this, dsp]() {
|
impl->teakra.SetRecvDataHandler(1, [this, handler]() {
|
||||||
if (!impl->loaded)
|
if (!impl->loaded)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::lock_guard lock(HLE::g_hle_lock);
|
std::lock_guard lock(HLE::g_hle_lock);
|
||||||
if (auto locked = dsp.lock()) {
|
handler(Service::DSP::InterruptType::One, static_cast<DspPipe>(0));
|
||||||
locked->SignalInterrupt(Service::DSP::DSP_DSP::InterruptType::One,
|
|
||||||
static_cast<DspPipe>(0));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
auto ProcessPipeEvent = [this, dsp](bool event_from_data) {
|
auto ProcessPipeEvent = [this, handler](bool event_from_data) {
|
||||||
if (!impl->loaded)
|
if (!impl->loaded)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -456,10 +451,7 @@ void DspLle::SetServiceToInterrupt(std::weak_ptr<Service::DSP::DSP_DSP> dsp) {
|
|||||||
impl->GetPipeReadableSize(static_cast<u8>(pipe)));
|
impl->GetPipeReadableSize(static_cast<u8>(pipe)));
|
||||||
} else {
|
} else {
|
||||||
std::lock_guard lock(HLE::g_hle_lock);
|
std::lock_guard lock(HLE::g_hle_lock);
|
||||||
if (auto locked = dsp.lock()) {
|
handler(Service::DSP::InterruptType::Pipe, static_cast<DspPipe>(pipe));
|
||||||
locked->SignalInterrupt(Service::DSP::DSP_DSP::InterruptType::Pipe,
|
|
||||||
static_cast<DspPipe>(pipe));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -468,14 +460,6 @@ void DspLle::SetServiceToInterrupt(std::weak_ptr<Service::DSP::DSP_DSP> dsp) {
|
|||||||
impl->teakra.SetSemaphoreHandler([ProcessPipeEvent]() { ProcessPipeEvent(false); });
|
impl->teakra.SetSemaphoreHandler([ProcessPipeEvent]() { ProcessPipeEvent(false); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void DspLle::SetSemaphoreHandler(std::function<void()> handler) {
|
|
||||||
impl->teakra.SetSemaphoreHandler(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DspLle::SetRecvDataHandler(u8 index, std::function<void()> handler) {
|
|
||||||
impl->teakra.SetRecvDataHandler(index, handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DspLle::LoadComponent(std::span<const u8> buffer) {
|
void DspLle::LoadComponent(std::span<const u8> buffer) {
|
||||||
impl->LoadComponent(buffer);
|
impl->LoadComponent(buffer);
|
||||||
}
|
}
|
||||||
|
@ -27,10 +27,8 @@ public:
|
|||||||
|
|
||||||
std::array<u8, Memory::DSP_RAM_SIZE>& GetDspMemory() override;
|
std::array<u8, Memory::DSP_RAM_SIZE>& GetDspMemory() override;
|
||||||
|
|
||||||
void SetServiceToInterrupt(std::weak_ptr<Service::DSP::DSP_DSP> dsp) override;
|
void SetInterruptHandler(
|
||||||
|
std::function<void(Service::DSP::InterruptType type, DspPipe pipe)> handler) override;
|
||||||
void SetSemaphoreHandler(std::function<void()> handler);
|
|
||||||
void SetRecvDataHandler(u8 index, std::function<void()> handler);
|
|
||||||
|
|
||||||
void LoadComponent(const std::span<const u8> buffer) override;
|
void LoadComponent(const std::span<const u8> buffer) override;
|
||||||
void UnloadComponent() override;
|
void UnloadComponent() override;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <span>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -84,6 +85,15 @@ std::string UTF16BufferToUTF8(const T& text) {
|
|||||||
return UTF16ToUTF8(buffer);
|
return UTF16ToUTF8(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes trailing null bytes from the string.
|
||||||
|
*/
|
||||||
|
inline void TruncateString(std::string& str) {
|
||||||
|
while (str.size() && str.back() == '\0') {
|
||||||
|
str.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a std::string from a fixed-size NUL-terminated char buffer. If the buffer isn't
|
* Creates a std::string from a fixed-size NUL-terminated char buffer. If the buffer isn't
|
||||||
* NUL-terminated then the string ends at max_len characters.
|
* NUL-terminated then the string ends at max_len characters.
|
||||||
|
@ -213,6 +213,11 @@ public:
|
|||||||
return {cmd_buf[0]};
|
return {cmd_buf[0]};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the command ID from the IPC command buffer.
|
||||||
|
u16 CommandID() const {
|
||||||
|
return static_cast<u16>(CommandHeader().command_id.Value());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the session through which this request was made. This can be used as a map key to
|
* Returns the session through which this request was made. This can be used as a map key to
|
||||||
* access per-client data on services.
|
* access per-client data on services.
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#include "core/hle/service/dsp/dsp_dsp.h"
|
#include "core/hle/service/dsp/dsp_dsp.h"
|
||||||
|
|
||||||
using DspPipe = AudioCore::DspPipe;
|
using DspPipe = AudioCore::DspPipe;
|
||||||
using InterruptType = Service::DSP::DSP_DSP::InterruptType;
|
using InterruptType = Service::DSP::InterruptType;
|
||||||
|
|
||||||
SERIALIZE_EXPORT_IMPL(Service::DSP::DSP_DSP)
|
SERIALIZE_EXPORT_IMPL(Service::DSP::DSP_DSP)
|
||||||
SERVICE_CONSTRUCT_IMPL(Service::DSP::DSP_DSP)
|
SERVICE_CONSTRUCT_IMPL(Service::DSP::DSP_DSP)
|
||||||
@ -235,7 +235,8 @@ void DSP_DSP::RegisterInterruptEvents(Kernel::HLERequestContext& ctx) {
|
|||||||
const u32 channel = rp.Pop<u32>();
|
const u32 channel = rp.Pop<u32>();
|
||||||
auto event = rp.PopObject<Kernel::Event>();
|
auto event = rp.PopObject<Kernel::Event>();
|
||||||
|
|
||||||
ASSERT_MSG(interrupt < NUM_INTERRUPT_TYPE && channel < AudioCore::num_dsp_pipe,
|
ASSERT_MSG(interrupt < static_cast<u32>(InterruptType::Count) &&
|
||||||
|
channel < AudioCore::num_dsp_pipe,
|
||||||
"Invalid type or pipe: interrupt = {}, channel = {}", interrupt, channel);
|
"Invalid type or pipe: interrupt = {}, channel = {}", interrupt, channel);
|
||||||
|
|
||||||
const InterruptType type = static_cast<InterruptType>(interrupt);
|
const InterruptType type = static_cast<InterruptType>(interrupt);
|
||||||
@ -326,6 +327,9 @@ std::shared_ptr<Kernel::Event>& DSP_DSP::GetInterruptEvent(InterruptType type, D
|
|||||||
ASSERT(pipe_index < AudioCore::num_dsp_pipe);
|
ASSERT(pipe_index < AudioCore::num_dsp_pipe);
|
||||||
return pipes[pipe_index];
|
return pipes[pipe_index];
|
||||||
}
|
}
|
||||||
|
case InterruptType::Count:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
UNREACHABLE_MSG("Invalid interrupt type = {}", type);
|
UNREACHABLE_MSG("Invalid interrupt type = {}", type);
|
||||||
}
|
}
|
||||||
@ -401,7 +405,12 @@ void InstallInterfaces(Core::System& system) {
|
|||||||
auto& service_manager = system.ServiceManager();
|
auto& service_manager = system.ServiceManager();
|
||||||
auto dsp = std::make_shared<DSP_DSP>(system);
|
auto dsp = std::make_shared<DSP_DSP>(system);
|
||||||
dsp->InstallAsService(service_manager);
|
dsp->InstallAsService(service_manager);
|
||||||
system.DSP().SetServiceToInterrupt(std::move(dsp));
|
system.DSP().SetInterruptHandler(
|
||||||
|
[dsp_ref = std::weak_ptr<DSP_DSP>(dsp)](InterruptType type, DspPipe pipe) {
|
||||||
|
if (auto locked = dsp_ref.lock()) {
|
||||||
|
locked->SignalInterrupt(type, pipe);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Service::DSP
|
} // namespace Service::DSP
|
||||||
|
@ -19,15 +19,14 @@ class System;
|
|||||||
|
|
||||||
namespace Service::DSP {
|
namespace Service::DSP {
|
||||||
|
|
||||||
|
/// There are three types of interrupts
|
||||||
|
enum class InterruptType : u32 { Zero = 0, One = 1, Pipe = 2, Count };
|
||||||
|
|
||||||
class DSP_DSP final : public ServiceFramework<DSP_DSP> {
|
class DSP_DSP final : public ServiceFramework<DSP_DSP> {
|
||||||
public:
|
public:
|
||||||
explicit DSP_DSP(Core::System& system);
|
explicit DSP_DSP(Core::System& system);
|
||||||
~DSP_DSP();
|
~DSP_DSP();
|
||||||
|
|
||||||
/// There are three types of interrupts
|
|
||||||
static constexpr std::size_t NUM_INTERRUPT_TYPE = 3;
|
|
||||||
enum class InterruptType : u32 { Zero = 0, One = 1, Pipe = 2 };
|
|
||||||
|
|
||||||
/// Actual service implementation only has 6 'slots' for interrupts.
|
/// Actual service implementation only has 6 'slots' for interrupts.
|
||||||
static constexpr std::size_t max_number_of_interrupt_events = 6;
|
static constexpr std::size_t max_number_of_interrupt_events = 6;
|
||||||
|
|
||||||
|
@ -6,10 +6,12 @@
|
|||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
|
#include <boost/url/src.hpp>
|
||||||
#include <cryptopp/aes.h>
|
#include <cryptopp/aes.h>
|
||||||
#include <cryptopp/modes.h>
|
#include <cryptopp/modes.h>
|
||||||
#include "common/archives.h"
|
#include "common/archives.h"
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
|
#include "common/string_util.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/file_sys/archive_ncch.h"
|
#include "core/file_sys/archive_ncch.h"
|
||||||
#include "core/file_sys/file_backend.h"
|
#include "core/file_sys/file_backend.h"
|
||||||
@ -63,8 +65,26 @@ const ResultCode ERROR_WRONG_CERT_HANDLE = // 0xD8A0A0C9
|
|||||||
const ResultCode ERROR_CERT_ALREADY_SET = // 0xD8A0A03D
|
const ResultCode ERROR_CERT_ALREADY_SET = // 0xD8A0A03D
|
||||||
ResultCode(61, ErrorModule::HTTP, ErrorSummary::InvalidState, ErrorLevel::Permanent);
|
ResultCode(61, ErrorModule::HTTP, ErrorSummary::InvalidState, ErrorLevel::Permanent);
|
||||||
|
|
||||||
static ssize_t write_headers(httplib::Stream& strm,
|
// Splits URL into its components. Example: https://citra-emu.org:443/index.html
|
||||||
const std::vector<Context::RequestHeader>& headers) {
|
// is_https: true; host: citra-emu.org; port: 443; path: /index.html
|
||||||
|
static URLInfo SplitUrl(const std::string& url) {
|
||||||
|
constexpr u16 default_http_port = 80;
|
||||||
|
constexpr u16 default_https_port = 443;
|
||||||
|
|
||||||
|
const auto result = boost::urls::parse_uri(url);
|
||||||
|
const bool is_https = result->scheme_id() == boost::urls::scheme::https;
|
||||||
|
const auto port = result->port_number();
|
||||||
|
const auto default_port = is_https ? default_https_port : default_http_port;
|
||||||
|
return URLInfo{
|
||||||
|
.is_https = is_https,
|
||||||
|
.host = std::string{result->encoded_host()},
|
||||||
|
.port = port == 0 ? default_port : port,
|
||||||
|
.path = std::string{result->encoded_path()},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssize_t WriteHeaders(httplib::Stream& strm,
|
||||||
|
std::span<const Context::RequestHeader> headers) {
|
||||||
ssize_t write_len = 0;
|
ssize_t write_len = 0;
|
||||||
for (const auto& x : headers) {
|
for (const auto& x : headers) {
|
||||||
auto len = strm.write_format("%s: %s\r\n", x.name.c_str(), x.value.c_str());
|
auto len = strm.write_format("%s: %s\r\n", x.name.c_str(), x.value.c_str());
|
||||||
@ -81,50 +101,50 @@ static ssize_t write_headers(httplib::Stream& strm,
|
|||||||
return write_len;
|
return write_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::tuple<std::string, int, std::string, bool> SplitUrl(const std::string& url) {
|
static size_t HandleHeaderWrite(std::vector<Context::RequestHeader>& pending_headers,
|
||||||
const std::string prefix = "://";
|
httplib::Stream& strm, httplib::Headers& httplib_headers) {
|
||||||
const auto scheme_end = url.find(prefix);
|
std::vector<Context::RequestHeader> final_headers;
|
||||||
const auto prefix_end = scheme_end == std::string::npos ? 0 : scheme_end + prefix.length();
|
std::vector<Context::RequestHeader>::iterator it_p;
|
||||||
|
httplib::Headers::iterator it_h;
|
||||||
|
|
||||||
bool is_https = scheme_end != std::string::npos && url.starts_with("https");
|
auto find_pending_header = [&pending_headers](const std::string& str) {
|
||||||
|
return std::find_if(pending_headers.begin(), pending_headers.end(),
|
||||||
|
[&str](Context::RequestHeader& rh) { return rh.name == str; });
|
||||||
|
};
|
||||||
|
|
||||||
const auto path_index = url.find("/", prefix_end);
|
// Watch out for header ordering!!
|
||||||
std::string host;
|
// First: Host
|
||||||
int port = -1;
|
it_p = find_pending_header("Host");
|
||||||
std::string path;
|
if (it_p != pending_headers.end()) {
|
||||||
if (path_index == std::string::npos) {
|
final_headers.push_back(Context::RequestHeader(it_p->name, it_p->value));
|
||||||
// If no path is specified after the host, set it to "/"
|
pending_headers.erase(it_p);
|
||||||
host = url.substr(prefix_end);
|
|
||||||
const auto port_start = host.find(":");
|
|
||||||
if (port_start != std::string::npos) {
|
|
||||||
std::string port_str = host.substr(port_start + 1);
|
|
||||||
host = host.substr(0, port_start);
|
|
||||||
char* pEnd = NULL;
|
|
||||||
port = std::strtol(port_str.c_str(), &pEnd, 10);
|
|
||||||
if (*pEnd) {
|
|
||||||
port = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
path = "/";
|
|
||||||
} else {
|
} else {
|
||||||
host = url.substr(prefix_end, path_index - prefix_end);
|
it_h = httplib_headers.find("Host");
|
||||||
const auto port_start = host.find(":");
|
if (it_h != httplib_headers.end()) {
|
||||||
if (port_start != std::string::npos) {
|
final_headers.push_back(Context::RequestHeader(it_h->first, it_h->second));
|
||||||
std::string port_str = host.substr(port_start + 1);
|
|
||||||
host = host.substr(0, port_start);
|
|
||||||
char* pEnd = NULL;
|
|
||||||
port = std::strtol(port_str.c_str(), &pEnd, 10);
|
|
||||||
if (*pEnd) {
|
|
||||||
port = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
path = url.substr(path_index);
|
|
||||||
}
|
}
|
||||||
if (port == -1) {
|
|
||||||
port = is_https ? 443 : 80;
|
// Second, user defined headers
|
||||||
|
// Third, Content-Type (optional, appended by MakeRequest)
|
||||||
|
for (const auto& header : pending_headers) {
|
||||||
|
final_headers.push_back(header);
|
||||||
}
|
}
|
||||||
return std::make_tuple(host, port, path, is_https);
|
|
||||||
}
|
// Fourth: Content-Length
|
||||||
|
it_p = find_pending_header("Content-Length");
|
||||||
|
if (it_p != pending_headers.end()) {
|
||||||
|
final_headers.push_back(Context::RequestHeader(it_p->name, it_p->value));
|
||||||
|
pending_headers.erase(it_p);
|
||||||
|
} else {
|
||||||
|
it_h = httplib_headers.find("Content-Length");
|
||||||
|
if (it_h != httplib_headers.end()) {
|
||||||
|
final_headers.push_back(Context::RequestHeader(it_h->first, it_h->second));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return WriteHeaders(strm, final_headers);
|
||||||
|
};
|
||||||
|
|
||||||
void Context::MakeRequest() {
|
void Context::MakeRequest() {
|
||||||
ASSERT(state == RequestState::NotStarted);
|
ASSERT(state == RequestState::NotStarted);
|
||||||
@ -136,13 +156,12 @@ void Context::MakeRequest() {
|
|||||||
{RequestMethod::PutEmpty, "PUT"},
|
{RequestMethod::PutEmpty, "PUT"},
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto& [host, port, path, is_https] = SplitUrl(url.c_str());
|
URLInfo url_info = SplitUrl(url);
|
||||||
|
|
||||||
httplib::Request request;
|
httplib::Request request;
|
||||||
httplib::Error error{-1};
|
|
||||||
std::vector<Context::RequestHeader> pending_headers;
|
std::vector<Context::RequestHeader> pending_headers;
|
||||||
request.method = request_method_strings.at(method);
|
request.method = request_method_strings.at(method);
|
||||||
request.path = path;
|
request.path = url_info.path;
|
||||||
|
|
||||||
request.progress = [this](u64 current, u64 total) -> bool {
|
request.progress = [this](u64 current, u64 total) -> bool {
|
||||||
// TODO(B3N30): Is there a state that shows response header are available
|
// TODO(B3N30): Is there a state that shows response header are available
|
||||||
@ -151,56 +170,9 @@ void Context::MakeRequest() {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Watch out for header ordering!
|
for (const auto& header : headers) {
|
||||||
auto header_writter = [&pending_headers](httplib::Stream& strm,
|
pending_headers.push_back(header);
|
||||||
httplib::Headers& httplib_headers) {
|
}
|
||||||
std::vector<Context::RequestHeader> final_headers;
|
|
||||||
std::vector<Context::RequestHeader>::iterator it_p;
|
|
||||||
httplib::Headers::iterator it_h;
|
|
||||||
|
|
||||||
auto find_pending_header = [&pending_headers](const std::string& str) {
|
|
||||||
return std::find_if(pending_headers.begin(), pending_headers.end(),
|
|
||||||
[&str](Context::RequestHeader& rh) { return rh.name == str; });
|
|
||||||
};
|
|
||||||
|
|
||||||
// First: Host
|
|
||||||
it_p = find_pending_header("Host");
|
|
||||||
if (it_p != pending_headers.end()) {
|
|
||||||
final_headers.push_back(Context::RequestHeader(it_p->name, it_p->value));
|
|
||||||
pending_headers.erase(it_p);
|
|
||||||
} else {
|
|
||||||
it_h = httplib_headers.find("Host");
|
|
||||||
if (it_h != httplib_headers.end()) {
|
|
||||||
final_headers.push_back(Context::RequestHeader(it_h->first, it_h->second));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Second: Content-Type (optional, ignore httplib)
|
|
||||||
it_p = find_pending_header("Content-Type");
|
|
||||||
if (it_p != pending_headers.end()) {
|
|
||||||
final_headers.push_back(Context::RequestHeader(it_p->name, it_p->value));
|
|
||||||
pending_headers.erase(it_p);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Third: Content-Length
|
|
||||||
it_p = find_pending_header("Content-Length");
|
|
||||||
if (it_p != pending_headers.end()) {
|
|
||||||
final_headers.push_back(Context::RequestHeader(it_p->name, it_p->value));
|
|
||||||
pending_headers.erase(it_p);
|
|
||||||
} else {
|
|
||||||
it_h = httplib_headers.find("Content-Length");
|
|
||||||
if (it_h != httplib_headers.end()) {
|
|
||||||
final_headers.push_back(Context::RequestHeader(it_h->first, it_h->second));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finally, user defined headers
|
|
||||||
for (const auto& header : pending_headers) {
|
|
||||||
final_headers.push_back(header);
|
|
||||||
}
|
|
||||||
|
|
||||||
return write_headers(strm, final_headers);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!post_data.empty()) {
|
if (!post_data.empty()) {
|
||||||
pending_headers.push_back(
|
pending_headers.push_back(
|
||||||
@ -209,68 +181,73 @@ void Context::MakeRequest() {
|
|||||||
boost::replace_all(request.body, "*", "%2A");
|
boost::replace_all(request.body, "*", "%2A");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& header : headers) {
|
|
||||||
pending_headers.push_back(header);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!post_data_raw.empty()) {
|
if (!post_data_raw.empty()) {
|
||||||
request.body = post_data_raw;
|
request.body = post_data_raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
state = RequestState::InProgress;
|
state = RequestState::InProgress;
|
||||||
|
|
||||||
// Sadly, we have to duplicate code, the class hierarchy in httplib is not very useful...
|
if (url_info.is_https) {
|
||||||
if (is_https) {
|
MakeRequestSSL(request, url_info, pending_headers);
|
||||||
X509* cert = nullptr;
|
|
||||||
EVP_PKEY* key = nullptr;
|
|
||||||
{
|
|
||||||
std::unique_ptr<httplib::SSLClient> client;
|
|
||||||
if (uses_default_client_cert) {
|
|
||||||
const unsigned char* tmpCertPtr = clcert_data->certificate.data();
|
|
||||||
const unsigned char* tmpKeyPtr = clcert_data->private_key.data();
|
|
||||||
cert = d2i_X509(nullptr, &tmpCertPtr, (long)clcert_data->certificate.size());
|
|
||||||
key = d2i_PrivateKey(EVP_PKEY_RSA, nullptr, &tmpKeyPtr,
|
|
||||||
(long)clcert_data->private_key.size());
|
|
||||||
client = std::make_unique<httplib::SSLClient>(host, port, cert, key);
|
|
||||||
} else {
|
|
||||||
if (auto client_cert = ssl_config.client_cert_ctx.lock()) {
|
|
||||||
const unsigned char* tmpCertPtr = client_cert->certificate.data();
|
|
||||||
const unsigned char* tmpKeyPtr = client_cert->private_key.data();
|
|
||||||
cert = d2i_X509(nullptr, &tmpCertPtr, (long)client_cert->certificate.size());
|
|
||||||
key = d2i_PrivateKey(EVP_PKEY_RSA, nullptr, &tmpKeyPtr,
|
|
||||||
(long)client_cert->private_key.size());
|
|
||||||
client = std::make_unique<httplib::SSLClient>(host, port, cert, key);
|
|
||||||
} else {
|
|
||||||
client = std::make_unique<httplib::SSLClient>(host, port);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(B3N30): Check for SSLOptions-Bits and set the verify method accordingly
|
|
||||||
// https://www.3dbrew.org/wiki/SSL_Services#SSLOpt
|
|
||||||
// Hack: Since for now RootCerts are not implemented we set the VerifyMode to None.
|
|
||||||
client->enable_server_certificate_verification(false);
|
|
||||||
|
|
||||||
client->set_header_writer(header_writter);
|
|
||||||
|
|
||||||
if (!client->send(request, response, error)) {
|
|
||||||
LOG_ERROR(Service_HTTP, "Request failed: {}: {}", error, httplib::to_string(error));
|
|
||||||
state = RequestState::TimedOut;
|
|
||||||
} else {
|
|
||||||
LOG_DEBUG(Service_HTTP, "Request successful");
|
|
||||||
// TODO(B3N30): Verify this state on HW
|
|
||||||
state = RequestState::ReadyToDownloadContent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (cert) {
|
|
||||||
X509_free(cert);
|
|
||||||
}
|
|
||||||
if (key) {
|
|
||||||
EVP_PKEY_free(key);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
std::unique_ptr<httplib::Client> client = std::make_unique<httplib::Client>(host, port);
|
MakeRequestNonSSL(request, url_info, pending_headers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
client->set_header_writer(header_writter);
|
void Context::MakeRequestNonSSL(httplib::Request& request, const URLInfo& url_info,
|
||||||
|
std::vector<Context::RequestHeader>& pending_headers) {
|
||||||
|
httplib::Error error{-1};
|
||||||
|
std::unique_ptr<httplib::Client> client =
|
||||||
|
std::make_unique<httplib::Client>(url_info.host, url_info.port);
|
||||||
|
|
||||||
|
client->set_header_writer(
|
||||||
|
[&pending_headers](httplib::Stream& strm, httplib::Headers& httplib_headers) {
|
||||||
|
return HandleHeaderWrite(pending_headers, strm, httplib_headers);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!client->send(request, response, error)) {
|
||||||
|
LOG_ERROR(Service_HTTP, "Request failed: {}: {}", error, httplib::to_string(error));
|
||||||
|
state = RequestState::TimedOut;
|
||||||
|
} else {
|
||||||
|
LOG_DEBUG(Service_HTTP, "Request successful");
|
||||||
|
// TODO(B3N30): Verify this state on HW
|
||||||
|
state = RequestState::ReadyToDownloadContent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void Context::MakeRequestSSL(httplib::Request& request, const URLInfo& url_info,
|
||||||
|
std::vector<Context::RequestHeader>& pending_headers) {
|
||||||
|
httplib::Error error{-1};
|
||||||
|
X509* cert = nullptr;
|
||||||
|
EVP_PKEY* key = nullptr;
|
||||||
|
{
|
||||||
|
std::unique_ptr<httplib::SSLClient> client;
|
||||||
|
if (uses_default_client_cert) {
|
||||||
|
const unsigned char* tmpCertPtr = clcert_data->certificate.data();
|
||||||
|
const unsigned char* tmpKeyPtr = clcert_data->private_key.data();
|
||||||
|
cert = d2i_X509(nullptr, &tmpCertPtr, (long)clcert_data->certificate.size());
|
||||||
|
key = d2i_PrivateKey(EVP_PKEY_RSA, nullptr, &tmpKeyPtr,
|
||||||
|
(long)clcert_data->private_key.size());
|
||||||
|
client = std::make_unique<httplib::SSLClient>(url_info.host, url_info.port, cert, key);
|
||||||
|
} else if (auto client_cert = ssl_config.client_cert_ctx.lock()) {
|
||||||
|
const unsigned char* tmpCertPtr = client_cert->certificate.data();
|
||||||
|
const unsigned char* tmpKeyPtr = client_cert->private_key.data();
|
||||||
|
cert = d2i_X509(nullptr, &tmpCertPtr, (long)client_cert->certificate.size());
|
||||||
|
key = d2i_PrivateKey(EVP_PKEY_RSA, nullptr, &tmpKeyPtr,
|
||||||
|
(long)client_cert->private_key.size());
|
||||||
|
client = std::make_unique<httplib::SSLClient>(url_info.host, url_info.port, cert, key);
|
||||||
|
} else {
|
||||||
|
client = std::make_unique<httplib::SSLClient>(url_info.host, url_info.port);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(B3N30): Check for SSLOptions-Bits and set the verify method accordingly
|
||||||
|
// https://www.3dbrew.org/wiki/SSL_Services#SSLOpt
|
||||||
|
// Hack: Since for now RootCerts are not implemented we set the VerifyMode to None.
|
||||||
|
client->enable_server_certificate_verification(false);
|
||||||
|
|
||||||
|
client->set_header_writer(
|
||||||
|
[&pending_headers](httplib::Stream& strm, httplib::Headers& httplib_headers) {
|
||||||
|
return HandleHeaderWrite(pending_headers, strm, httplib_headers);
|
||||||
|
});
|
||||||
|
|
||||||
if (!client->send(request, response, error)) {
|
if (!client->send(request, response, error)) {
|
||||||
LOG_ERROR(Service_HTTP, "Request failed: {}: {}", error, httplib::to_string(error));
|
LOG_ERROR(Service_HTTP, "Request failed: {}: {}", error, httplib::to_string(error));
|
||||||
@ -281,6 +258,12 @@ void Context::MakeRequest() {
|
|||||||
state = RequestState::ReadyToDownloadContent;
|
state = RequestState::ReadyToDownloadContent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (cert) {
|
||||||
|
X509_free(cert);
|
||||||
|
}
|
||||||
|
if (key) {
|
||||||
|
EVP_PKEY_free(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTP_C::Initialize(Kernel::HLERequestContext& ctx) {
|
void HTTP_C::Initialize(Kernel::HLERequestContext& ctx) {
|
||||||
@ -358,11 +341,11 @@ void HTTP_C::BeginRequest(Kernel::HLERequestContext& ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto itr = contexts.find(context_handle);
|
Context& http_context = GetContext(context_handle);
|
||||||
ASSERT(itr != contexts.end());
|
|
||||||
|
|
||||||
// This should never happen in real hardware, but can happen on citra.
|
// This should never happen in real hardware, but can happen on citra.
|
||||||
if (itr->second.uses_default_client_cert && !itr->second.clcert_data->init) {
|
if (http_context.uses_default_client_cert && !http_context.clcert_data->init) {
|
||||||
|
LOG_ERROR(Service_HTTP, "failed to begin HTTP request: client cert not found.");
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||||
rb.Push(ERROR_STATE_ERROR);
|
rb.Push(ERROR_STATE_ERROR);
|
||||||
return;
|
return;
|
||||||
@ -375,9 +358,9 @@ void HTTP_C::BeginRequest(Kernel::HLERequestContext& ctx) {
|
|||||||
// Then there are 3? worker threads that pop the requests from the queue and send them
|
// Then there are 3? worker threads that pop the requests from the queue and send them
|
||||||
// For now make every request async in it's own thread.
|
// For now make every request async in it's own thread.
|
||||||
|
|
||||||
itr->second.request_future =
|
http_context.request_future =
|
||||||
std::async(std::launch::async, &Context::MakeRequest, std::ref(itr->second));
|
std::async(std::launch::async, &Context::MakeRequest, std::ref(http_context));
|
||||||
itr->second.current_copied_data = 0;
|
http_context.current_copied_data = 0;
|
||||||
|
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
@ -393,11 +376,11 @@ void HTTP_C::BeginRequestAsync(Kernel::HLERequestContext& ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto itr = contexts.find(context_handle);
|
Context& http_context = GetContext(context_handle);
|
||||||
ASSERT(itr != contexts.end());
|
|
||||||
|
|
||||||
// This should never happen in real hardware, but can happen on citra.
|
// This should never happen in real hardware, but can happen on citra.
|
||||||
if (itr->second.uses_default_client_cert && !itr->second.clcert_data->init) {
|
if (http_context.uses_default_client_cert && !http_context.clcert_data->init) {
|
||||||
|
LOG_ERROR(Service_HTTP, "failed to begin HTTP request: client cert not found.");
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||||
rb.Push(ERROR_STATE_ERROR);
|
rb.Push(ERROR_STATE_ERROR);
|
||||||
return;
|
return;
|
||||||
@ -410,9 +393,9 @@ void HTTP_C::BeginRequestAsync(Kernel::HLERequestContext& ctx) {
|
|||||||
// Then there are 3? worker threads that pop the requests from the queue and send them
|
// Then there are 3? worker threads that pop the requests from the queue and send them
|
||||||
// For now make every request async in it's own thread.
|
// For now make every request async in it's own thread.
|
||||||
|
|
||||||
itr->second.request_future =
|
http_context.request_future =
|
||||||
std::async(std::launch::async, &Context::MakeRequest, std::ref(itr->second));
|
std::async(std::launch::async, &Context::MakeRequest, std::ref(http_context));
|
||||||
itr->second.current_copied_data = 0;
|
http_context.current_copied_data = 0;
|
||||||
|
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
@ -462,10 +445,7 @@ void HTTP_C::ReceiveDataImpl(Kernel::HLERequestContext& ctx, bool timeout) {
|
|||||||
|
|
||||||
ctx.RunAsync(
|
ctx.RunAsync(
|
||||||
[async_data](Kernel::HLERequestContext& ctx) {
|
[async_data](Kernel::HLERequestContext& ctx) {
|
||||||
auto itr = async_data->own->contexts.find(async_data->context_handle);
|
Context& http_context = async_data->own->GetContext(async_data->context_handle);
|
||||||
ASSERT(itr != async_data->own->contexts.end());
|
|
||||||
|
|
||||||
Context& http_context = itr->second;
|
|
||||||
|
|
||||||
if (async_data->timeout) {
|
if (async_data->timeout) {
|
||||||
auto wait_res = http_context.request_future.wait_for(
|
auto wait_res = http_context.request_future.wait_for(
|
||||||
@ -482,16 +462,12 @@ void HTTP_C::ReceiveDataImpl(Kernel::HLERequestContext& ctx, bool timeout) {
|
|||||||
return 1'000'000;
|
return 1'000'000;
|
||||||
},
|
},
|
||||||
[async_data](Kernel::HLERequestContext& ctx) {
|
[async_data](Kernel::HLERequestContext& ctx) {
|
||||||
IPC::RequestBuilder rb(ctx, static_cast<u16>(ctx.CommandHeader().command_id.Value()), 1,
|
IPC::RequestBuilder rb(ctx, ctx.CommandID(), 1, 0);
|
||||||
0);
|
|
||||||
if (async_data->async_res != RESULT_SUCCESS) {
|
if (async_data->async_res != RESULT_SUCCESS) {
|
||||||
rb.Push(async_data->async_res);
|
rb.Push(async_data->async_res);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto itr = async_data->own->contexts.find(async_data->context_handle);
|
Context& http_context = async_data->own->GetContext(async_data->context_handle);
|
||||||
ASSERT(itr != async_data->own->contexts.end());
|
|
||||||
|
|
||||||
Context& http_context = itr->second;
|
|
||||||
|
|
||||||
size_t remaining_data =
|
size_t remaining_data =
|
||||||
http_context.response.body.size() - http_context.current_copied_data;
|
http_context.response.body.size() - http_context.current_copied_data;
|
||||||
@ -638,8 +614,7 @@ void HTTP_C::CancelConnection(Kernel::HLERequestContext& ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto itr = contexts.find(context_handle);
|
[[maybe_unused]] Context& http_context = GetContext(context_handle);
|
||||||
ASSERT(itr != contexts.end());
|
|
||||||
|
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
@ -667,10 +642,9 @@ void HTTP_C::AddRequestHeader(Kernel::HLERequestContext& ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto itr = contexts.find(context_handle);
|
Context& http_context = GetContext(context_handle);
|
||||||
ASSERT(itr != contexts.end());
|
|
||||||
|
|
||||||
if (itr->second.state != RequestState::NotStarted) {
|
if (http_context.state != RequestState::NotStarted) {
|
||||||
LOG_ERROR(Service_HTTP,
|
LOG_ERROR(Service_HTTP,
|
||||||
"Tried to add a request header on a context that has already been started.");
|
"Tried to add a request header on a context that has already been started.");
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
||||||
@ -680,7 +654,7 @@ void HTTP_C::AddRequestHeader(Kernel::HLERequestContext& ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
itr->second.headers.emplace_back(name, value);
|
http_context.headers.emplace_back(name, value);
|
||||||
|
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
@ -709,10 +683,9 @@ void HTTP_C::AddPostDataAscii(Kernel::HLERequestContext& ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto itr = contexts.find(context_handle);
|
Context& http_context = GetContext(context_handle);
|
||||||
ASSERT(itr != contexts.end());
|
|
||||||
|
|
||||||
if (itr->second.state != RequestState::NotStarted) {
|
if (http_context.state != RequestState::NotStarted) {
|
||||||
LOG_ERROR(Service_HTTP,
|
LOG_ERROR(Service_HTTP,
|
||||||
"Tried to add post data on a context that has already been started.");
|
"Tried to add post data on a context that has already been started.");
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
||||||
@ -722,7 +695,7 @@ void HTTP_C::AddPostDataAscii(Kernel::HLERequestContext& ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
itr->second.post_data.emplace(name, value);
|
http_context.post_data.emplace(name, value);
|
||||||
|
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
@ -741,10 +714,9 @@ void HTTP_C::AddPostDataRaw(Kernel::HLERequestContext& ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto itr = contexts.find(context_handle);
|
Context& http_context = GetContext(context_handle);
|
||||||
ASSERT(itr != contexts.end());
|
|
||||||
|
|
||||||
if (itr->second.state != RequestState::NotStarted) {
|
if (http_context.state != RequestState::NotStarted) {
|
||||||
LOG_ERROR(Service_HTTP,
|
LOG_ERROR(Service_HTTP,
|
||||||
"Tried to add post data on a context that has already been started.");
|
"Tried to add post data on a context that has already been started.");
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
||||||
@ -754,8 +726,8 @@ void HTTP_C::AddPostDataRaw(Kernel::HLERequestContext& ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
itr->second.post_data_raw.resize(buffer.GetSize());
|
http_context.post_data_raw.resize(buffer.GetSize());
|
||||||
buffer.Read(itr->second.post_data_raw.data(), 0, buffer.GetSize());
|
buffer.Read(http_context.post_data_raw.data(), 0, buffer.GetSize());
|
||||||
|
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
@ -770,7 +742,7 @@ void HTTP_C::GetResponseHeader(Kernel::HLERequestContext& ctx) {
|
|||||||
u32 context_handle;
|
u32 context_handle;
|
||||||
u32 name_len;
|
u32 name_len;
|
||||||
u32 value_max_len;
|
u32 value_max_len;
|
||||||
const std::vector<u8>* header_name;
|
std::span<const u8> header_name;
|
||||||
Kernel::MappedBuffer* value_buffer;
|
Kernel::MappedBuffer* value_buffer;
|
||||||
};
|
};
|
||||||
std::shared_ptr<AsyncData> async_data = std::make_shared<AsyncData>();
|
std::shared_ptr<AsyncData> async_data = std::make_shared<AsyncData>();
|
||||||
@ -779,7 +751,7 @@ void HTTP_C::GetResponseHeader(Kernel::HLERequestContext& ctx) {
|
|||||||
async_data->context_handle = rp.Pop<u32>();
|
async_data->context_handle = rp.Pop<u32>();
|
||||||
async_data->name_len = rp.Pop<u32>();
|
async_data->name_len = rp.Pop<u32>();
|
||||||
async_data->value_max_len = rp.Pop<u32>();
|
async_data->value_max_len = rp.Pop<u32>();
|
||||||
async_data->header_name = &rp.PopStaticBuffer();
|
async_data->header_name = rp.PopStaticBuffer();
|
||||||
async_data->value_buffer = &rp.PopMappedBuffer();
|
async_data->value_buffer = &rp.PopMappedBuffer();
|
||||||
|
|
||||||
if (!PerformStateChecks(ctx, rp, async_data->context_handle)) {
|
if (!PerformStateChecks(ctx, rp, async_data->context_handle)) {
|
||||||
@ -788,24 +760,19 @@ void HTTP_C::GetResponseHeader(Kernel::HLERequestContext& ctx) {
|
|||||||
|
|
||||||
ctx.RunAsync(
|
ctx.RunAsync(
|
||||||
[async_data](Kernel::HLERequestContext& ctx) {
|
[async_data](Kernel::HLERequestContext& ctx) {
|
||||||
auto itr = async_data->own->contexts.find(async_data->context_handle);
|
Context& http_context = async_data->own->GetContext(async_data->context_handle);
|
||||||
ASSERT(itr != async_data->own->contexts.end());
|
http_context.request_future.wait();
|
||||||
|
|
||||||
itr->second.request_future.wait();
|
|
||||||
return 0;
|
return 0;
|
||||||
},
|
},
|
||||||
[async_data](Kernel::HLERequestContext& ctx) {
|
[async_data](Kernel::HLERequestContext& ctx) {
|
||||||
std::string header_name_str(
|
std::string header_name_str(
|
||||||
reinterpret_cast<const char*>(async_data->header_name->data()),
|
reinterpret_cast<const char*>(async_data->header_name.data()),
|
||||||
async_data->name_len);
|
async_data->name_len);
|
||||||
while (header_name_str.size() && header_name_str.back() == '\0') {
|
Common::TruncateString(header_name_str);
|
||||||
header_name_str.pop_back();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto itr = async_data->own->contexts.find(async_data->context_handle);
|
Context& http_context = async_data->own->GetContext(async_data->context_handle);
|
||||||
ASSERT(itr != async_data->own->contexts.end());
|
|
||||||
|
|
||||||
auto& headers = itr->second.response.headers;
|
auto& headers = http_context.response.headers;
|
||||||
u32 copied_size = 0;
|
u32 copied_size = 0;
|
||||||
|
|
||||||
LOG_DEBUG(Service_HTTP, "header={}, max_len={}", header_name_str,
|
LOG_DEBUG(Service_HTTP, "header={}, max_len={}", header_name_str,
|
||||||
@ -822,13 +789,13 @@ void HTTP_C::GetResponseHeader(Kernel::HLERequestContext& ctx) {
|
|||||||
async_data->value_buffer->Write(header_value.data(), 0, header_value.size());
|
async_data->value_buffer->Write(header_value.data(), 0, header_value.size());
|
||||||
} else {
|
} else {
|
||||||
LOG_DEBUG(Service_HTTP, "header={} not found", header_name_str);
|
LOG_DEBUG(Service_HTTP, "header={} not found", header_name_str);
|
||||||
IPC::RequestBuilder rb(ctx, 0x001E, 1, 2);
|
IPC::RequestBuilder rb(ctx, ctx.CommandID(), 1, 2);
|
||||||
rb.Push(ERROR_HEADER_NOT_FOUND);
|
rb.Push(ERROR_HEADER_NOT_FOUND);
|
||||||
rb.PushMappedBuffer(*async_data->value_buffer);
|
rb.PushMappedBuffer(*async_data->value_buffer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IPC::RequestBuilder rb(ctx, 0x001E, 2, 2);
|
IPC::RequestBuilder rb(ctx, ctx.CommandID(), 2, 2);
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
rb.Push(copied_size);
|
rb.Push(copied_size);
|
||||||
rb.PushMappedBuffer(*async_data->value_buffer);
|
rb.PushMappedBuffer(*async_data->value_buffer);
|
||||||
@ -874,11 +841,10 @@ void HTTP_C::GetResponseStatusCodeImpl(Kernel::HLERequestContext& ctx, bool time
|
|||||||
|
|
||||||
ctx.RunAsync(
|
ctx.RunAsync(
|
||||||
[async_data](Kernel::HLERequestContext& ctx) {
|
[async_data](Kernel::HLERequestContext& ctx) {
|
||||||
auto itr = async_data->own->contexts.find(async_data->context_handle);
|
Context& http_context = async_data->own->GetContext(async_data->context_handle);
|
||||||
ASSERT(itr != async_data->own->contexts.end());
|
|
||||||
|
|
||||||
if (async_data->timeout) {
|
if (async_data->timeout) {
|
||||||
auto wait_res = itr->second.request_future.wait_for(
|
auto wait_res = http_context.request_future.wait_for(
|
||||||
std::chrono::nanoseconds(async_data->timeout_nanos));
|
std::chrono::nanoseconds(async_data->timeout_nanos));
|
||||||
if (wait_res == std::future_status::timeout) {
|
if (wait_res == std::future_status::timeout) {
|
||||||
LOG_DEBUG(Service_HTTP, "Status code: {}", "timeout");
|
LOG_DEBUG(Service_HTTP, "Status code: {}", "timeout");
|
||||||
@ -887,26 +853,23 @@ void HTTP_C::GetResponseStatusCodeImpl(Kernel::HLERequestContext& ctx, bool time
|
|||||||
ErrorLevel::Permanent);
|
ErrorLevel::Permanent);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
itr->second.request_future.wait();
|
http_context.request_future.wait();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
},
|
},
|
||||||
[async_data](Kernel::HLERequestContext& ctx) {
|
[async_data](Kernel::HLERequestContext& ctx) {
|
||||||
if (async_data->async_res != RESULT_SUCCESS) {
|
if (async_data->async_res != RESULT_SUCCESS) {
|
||||||
IPC::RequestBuilder rb(
|
IPC::RequestBuilder rb(ctx, ctx.CommandID(), 1, 0);
|
||||||
ctx, static_cast<u16>(ctx.CommandHeader().command_id.Value()), 1, 0);
|
|
||||||
rb.Push(async_data->async_res);
|
rb.Push(async_data->async_res);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto itr = async_data->own->contexts.find(async_data->context_handle);
|
Context& http_context = async_data->own->GetContext(async_data->context_handle);
|
||||||
ASSERT(itr != async_data->own->contexts.end());
|
|
||||||
|
|
||||||
const u32 response_code = itr->second.response.status;
|
const u32 response_code = http_context.response.status;
|
||||||
LOG_DEBUG(Service_HTTP, "Status code: {}, response_code={}", "good", response_code);
|
LOG_DEBUG(Service_HTTP, "Status code: {}, response_code={}", "good", response_code);
|
||||||
|
|
||||||
IPC::RequestBuilder rb(ctx, static_cast<u16>(ctx.CommandHeader().command_id.Value()), 2,
|
IPC::RequestBuilder rb(ctx, ctx.CommandID(), 2, 0);
|
||||||
0);
|
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
rb.Push(response_code);
|
rb.Push(response_code);
|
||||||
});
|
});
|
||||||
@ -940,7 +903,7 @@ void HTTP_C::AddDefaultCert(Kernel::HLERequestContext& ctx) {
|
|||||||
void HTTP_C::SetDefaultClientCert(Kernel::HLERequestContext& ctx) {
|
void HTTP_C::SetDefaultClientCert(Kernel::HLERequestContext& ctx) {
|
||||||
IPC::RequestParser rp(ctx);
|
IPC::RequestParser rp(ctx);
|
||||||
const Context::Handle context_handle = rp.Pop<u32>();
|
const Context::Handle context_handle = rp.Pop<u32>();
|
||||||
const u32 client_cert_id = rp.Pop<u32>();
|
const ClientCertID client_cert_id = static_cast<ClientCertID>(rp.Pop<u32>());
|
||||||
|
|
||||||
LOG_DEBUG(Service_HTTP, "client_cert_id={}", client_cert_id);
|
LOG_DEBUG(Service_HTTP, "client_cert_id={}", client_cert_id);
|
||||||
|
|
||||||
@ -948,17 +911,16 @@ void HTTP_C::SetDefaultClientCert(Kernel::HLERequestContext& ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto itr = contexts.find(context_handle);
|
Context& http_context = GetContext(context_handle);
|
||||||
ASSERT(itr != contexts.end());
|
|
||||||
|
|
||||||
if (client_cert_id != 0x40) {
|
if (client_cert_id != ClientCertID::Default) {
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||||
rb.Push(ERROR_WRONG_CERT_ID);
|
rb.Push(ERROR_WRONG_CERT_ID);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
itr->second.uses_default_client_cert = true;
|
http_context.uses_default_client_cert = true;
|
||||||
itr->second.clcert_data = &GetClCertA();
|
http_context.clcert_data = &GetClCertA();
|
||||||
|
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
@ -976,8 +938,7 @@ void HTTP_C::SetClientCertContext(Kernel::HLERequestContext& ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto http_context_itr = contexts.find(context_handle);
|
Context& http_context = GetContext(context_handle);
|
||||||
ASSERT(http_context_itr != contexts.end());
|
|
||||||
|
|
||||||
auto cert_context_itr = client_certs.find(client_cert_handle);
|
auto cert_context_itr = client_certs.find(client_cert_handle);
|
||||||
if (cert_context_itr == client_certs.end()) {
|
if (cert_context_itr == client_certs.end()) {
|
||||||
@ -987,7 +948,7 @@ void HTTP_C::SetClientCertContext(Kernel::HLERequestContext& ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (http_context_itr->second.ssl_config.client_cert_ctx.lock()) {
|
if (http_context.ssl_config.client_cert_ctx.lock()) {
|
||||||
LOG_ERROR(Service_HTTP,
|
LOG_ERROR(Service_HTTP,
|
||||||
"Tried to set a client cert to a context that already has a client cert");
|
"Tried to set a client cert to a context that already has a client cert");
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||||
@ -995,7 +956,7 @@ void HTTP_C::SetClientCertContext(Kernel::HLERequestContext& ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (http_context_itr->second.state != RequestState::NotStarted) {
|
if (http_context.state != RequestState::NotStarted) {
|
||||||
LOG_ERROR(Service_HTTP,
|
LOG_ERROR(Service_HTTP,
|
||||||
"Tried to set a client cert on a context that has already been started.");
|
"Tried to set a client cert on a context that has already been started.");
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||||
@ -1004,7 +965,7 @@ void HTTP_C::SetClientCertContext(Kernel::HLERequestContext& ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
http_context_itr->second.ssl_config.client_cert_ctx = cert_context_itr->second;
|
http_context.ssl_config.client_cert_ctx = cert_context_itr->second;
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
}
|
}
|
||||||
@ -1016,8 +977,7 @@ void HTTP_C::GetSSLError(Kernel::HLERequestContext& ctx) {
|
|||||||
|
|
||||||
LOG_WARNING(Service_HTTP, "(STUBBED) called, context_handle={}, unk={}", context_handle, unk);
|
LOG_WARNING(Service_HTTP, "(STUBBED) called, context_handle={}, unk={}", context_handle, unk);
|
||||||
|
|
||||||
auto http_context_itr = contexts.find(context_handle);
|
[[maybe_unused]] Context& http_context = GetContext(context_handle);
|
||||||
ASSERT(http_context_itr != contexts.end());
|
|
||||||
|
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
|
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
@ -1103,7 +1063,7 @@ void HTTP_C::OpenDefaultClientCertContext(Kernel::HLERequestContext& ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr u8 default_cert_id = 0x40;
|
constexpr u8 default_cert_id = static_cast<u8>(ClientCertID::Default);
|
||||||
if (cert_id != default_cert_id) {
|
if (cert_id != default_cert_id) {
|
||||||
LOG_ERROR(Service_HTTP, "called with invalid cert_id {}", cert_id);
|
LOG_ERROR(Service_HTTP, "called with invalid cert_id {}", cert_id);
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||||
@ -1210,28 +1170,27 @@ void HTTP_C::GetDownloadSizeState(Kernel::HLERequestContext& ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto itr = contexts.find(context_handle);
|
Context& http_context = GetContext(context_handle);
|
||||||
ASSERT(itr != contexts.end());
|
|
||||||
|
|
||||||
// On the real console, the current downloaded progress and the total size of the content gets
|
// On the real console, the current downloaded progress and the total size of the content gets
|
||||||
// returned. Since we do not support chunked downloads on the host, always return the content
|
// returned. Since we do not support chunked downloads on the host, always return the content
|
||||||
// length if the download is complete and 0 otherwise.
|
// length if the download is complete and 0 otherwise.
|
||||||
u32 content_length = 0;
|
u32 content_length = 0;
|
||||||
const bool is_complete = itr->second.request_future.wait_for(std::chrono::milliseconds(0)) ==
|
const bool is_complete = http_context.request_future.wait_for(std::chrono::milliseconds(0)) ==
|
||||||
std::future_status::ready;
|
std::future_status::ready;
|
||||||
if (is_complete) {
|
if (is_complete) {
|
||||||
const auto& headers = itr->second.response.headers;
|
const auto& headers = http_context.response.headers;
|
||||||
const auto& it = headers.find("Content-Length");
|
const auto& it = headers.find("Content-Length");
|
||||||
if (it != headers.end()) {
|
if (it != headers.end()) {
|
||||||
content_length = std::stoi(it->second);
|
content_length = std::stoi(it->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUG(Service_HTTP, "current={}, total={}", itr->second.current_copied_data,
|
LOG_DEBUG(Service_HTTP, "current={}, total={}", http_context.current_copied_data,
|
||||||
content_length);
|
content_length);
|
||||||
IPC::RequestBuilder rb = rp.MakeBuilder(3, 0);
|
IPC::RequestBuilder rb = rp.MakeBuilder(3, 0);
|
||||||
rb.Push(RESULT_SUCCESS);
|
rb.Push(RESULT_SUCCESS);
|
||||||
rb.Push(static_cast<u32>(itr->second.current_copied_data));
|
rb.Push(static_cast<u32>(http_context.current_copied_data));
|
||||||
rb.Push(content_length);
|
rb.Push(content_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +57,17 @@ enum class RequestState : u8 {
|
|||||||
TimedOut = 0xA, // Request timed out?
|
TimedOut = 0xA, // Request timed out?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class ClientCertID : u32 {
|
||||||
|
Default = 0x40, // Default client cert
|
||||||
|
};
|
||||||
|
|
||||||
|
struct URLInfo {
|
||||||
|
bool is_https;
|
||||||
|
std::string host;
|
||||||
|
int port;
|
||||||
|
std::string path;
|
||||||
|
};
|
||||||
|
|
||||||
/// Represents a client certificate along with its private key, stored as a byte array of DER data.
|
/// 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
|
/// There can only be at most one client certificate context attached to an HTTP context at any
|
||||||
/// given time.
|
/// given time.
|
||||||
@ -130,8 +141,6 @@ public:
|
|||||||
Context(const Context&) = delete;
|
Context(const Context&) = delete;
|
||||||
Context& operator=(const Context&) = delete;
|
Context& operator=(const Context&) = delete;
|
||||||
|
|
||||||
void MakeRequest();
|
|
||||||
|
|
||||||
struct Proxy {
|
struct Proxy {
|
||||||
std::string url;
|
std::string url;
|
||||||
std::string username;
|
std::string username;
|
||||||
@ -211,6 +220,12 @@ public:
|
|||||||
size_t current_copied_data;
|
size_t current_copied_data;
|
||||||
bool uses_default_client_cert{};
|
bool uses_default_client_cert{};
|
||||||
httplib::Response response;
|
httplib::Response response;
|
||||||
|
|
||||||
|
void MakeRequest();
|
||||||
|
void MakeRequestNonSSL(httplib::Request& request, const URLInfo& url_info,
|
||||||
|
std::vector<Context::RequestHeader>& pending_headers);
|
||||||
|
void MakeRequestSSL(httplib::Request& request, const URLInfo& url_info,
|
||||||
|
std::vector<Context::RequestHeader>& pending_headers);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SessionData : public Kernel::SessionRequestHandler::SessionDataBase {
|
struct SessionData : public Kernel::SessionRequestHandler::SessionDataBase {
|
||||||
@ -595,6 +610,13 @@ private:
|
|||||||
/// Global list of HTTP contexts currently opened.
|
/// Global list of HTTP contexts currently opened.
|
||||||
std::unordered_map<Context::Handle, Context> contexts;
|
std::unordered_map<Context::Handle, Context> contexts;
|
||||||
|
|
||||||
|
// Get context from its handle
|
||||||
|
inline Context& GetContext(const Context::Handle& handle) {
|
||||||
|
auto it = contexts.find(handle);
|
||||||
|
ASSERT(it != contexts.end());
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
/// Global list of ClientCert contexts currently opened.
|
/// Global list of ClientCert contexts currently opened.
|
||||||
std::unordered_map<ClientCertContext::Handle, std::shared_ptr<ClientCertContext>> client_certs;
|
std::unordered_map<ClientCertContext::Handle, std::shared_ptr<ClientCertContext>> client_certs;
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ TEST_CASE("DSP LLE vs HLE", "[audio_core][hle]") {
|
|||||||
AudioCore::DspHle hle(hle_memory, hle_core_timing);
|
AudioCore::DspHle hle(hle_memory, hle_core_timing);
|
||||||
AudioCore::DspLle lle(lle_memory, lle_core_timing, true);
|
AudioCore::DspLle lle(lle_memory, lle_core_timing, true);
|
||||||
|
|
||||||
// Initialiase LLE
|
// Initialise LLE
|
||||||
{
|
{
|
||||||
FileUtil::SetUserPath();
|
FileUtil::SetUserPath();
|
||||||
// see tests/audio_core/lle/lle.cpp for details on dspaudio.cdc
|
// see tests/audio_core/lle/lle.cpp for details on dspaudio.cdc
|
||||||
@ -41,25 +41,15 @@ TEST_CASE("DSP LLE vs HLE", "[audio_core][hle]") {
|
|||||||
std::vector<u8> firm_file_buf(firm_file.GetSize());
|
std::vector<u8> firm_file_buf(firm_file.GetSize());
|
||||||
firm_file.ReadArray(firm_file_buf.data(), firm_file_buf.size());
|
firm_file.ReadArray(firm_file_buf.data(), firm_file_buf.size());
|
||||||
lle.LoadComponent(firm_file_buf);
|
lle.LoadComponent(firm_file_buf);
|
||||||
lle.SetSemaphoreHandler([&lle]() {
|
lle.SetInterruptHandler([](Service::DSP::InterruptType type, AudioCore::DspPipe pipe) {
|
||||||
u16 slot = lle.RecvData(2);
|
fmt::print("LLE SetInterruptHandler type={} pipe={}\n", type, pipe);
|
||||||
u16 side = slot % 2;
|
});
|
||||||
u16 pipe = slot / 2;
|
}
|
||||||
fmt::print("SetSemaphoreHandler slot={}\n", slot);
|
// Initialise HLE
|
||||||
if (pipe > 15)
|
{
|
||||||
return;
|
hle.SetInterruptHandler([](Service::DSP::InterruptType type, AudioCore::DspPipe pipe) {
|
||||||
if (side != 0)
|
fmt::print("HLE SetInterruptHandler type={} pipe={}\n", type, pipe);
|
||||||
return;
|
|
||||||
if (pipe == 0) {
|
|
||||||
// pipe 0 is for debug. 3DS automatically drains this pipe and discards the
|
|
||||||
// data
|
|
||||||
lle.PipeRead(static_cast<AudioCore::DspPipe>(pipe),
|
|
||||||
lle.GetPipeReadableSize(static_cast<AudioCore::DspPipe>(pipe)));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
lle.SetRecvDataHandler(0, []() { fmt::print("SetRecvDataHandler 0\n"); });
|
|
||||||
lle.SetRecvDataHandler(1, []() { fmt::print("SetRecvDataHandler 1\n"); });
|
|
||||||
lle.SetRecvDataHandler(2, []() { fmt::print("SetRecvDataHandler 2\n"); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Initialise Audio Pipe") {
|
SECTION("Initialise Audio Pipe") {
|
||||||
|
@ -37,26 +37,11 @@ TEST_CASE("DSP LLE Sanity", "[audio_core][lle]") {
|
|||||||
std::vector<u8> firm_file_buf(firm_file.GetSize());
|
std::vector<u8> firm_file_buf(firm_file.GetSize());
|
||||||
firm_file.ReadArray(firm_file_buf.data(), firm_file_buf.size());
|
firm_file.ReadArray(firm_file_buf.data(), firm_file_buf.size());
|
||||||
lle.LoadComponent(firm_file_buf);
|
lle.LoadComponent(firm_file_buf);
|
||||||
|
|
||||||
|
lle.SetInterruptHandler([](Service::DSP::InterruptType type, AudioCore::DspPipe pipe) {
|
||||||
|
fmt::print("SetInterruptHandler type={} pipe={}\n", type, pipe);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
lle.SetSemaphoreHandler([&lle]() {
|
|
||||||
u16 slot = lle.RecvData(2);
|
|
||||||
u16 side = slot % 2;
|
|
||||||
u16 pipe = slot / 2;
|
|
||||||
fmt::print("SetSemaphoreHandler slot={}\n", slot);
|
|
||||||
if (pipe > 15)
|
|
||||||
return;
|
|
||||||
if (side != 0)
|
|
||||||
return;
|
|
||||||
if (pipe == 0) {
|
|
||||||
// pipe 0 is for debug. 3DS automatically drains this pipe and discards the
|
|
||||||
// data
|
|
||||||
lle.PipeRead(static_cast<AudioCore::DspPipe>(pipe),
|
|
||||||
lle.GetPipeReadableSize(static_cast<AudioCore::DspPipe>(pipe)));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
lle.SetRecvDataHandler(0, []() { fmt::print("SetRecvDataHandler 0\n"); });
|
|
||||||
lle.SetRecvDataHandler(1, []() { fmt::print("SetRecvDataHandler 1\n"); });
|
|
||||||
lle.SetRecvDataHandler(2, []() { fmt::print("SetRecvDataHandler 2\n"); });
|
|
||||||
SECTION("Initialise Audio Pipe") {
|
SECTION("Initialise Audio Pipe") {
|
||||||
std::vector<u8> buffer(4, 0);
|
std::vector<u8> buffer(4, 0);
|
||||||
buffer[0] = 0;
|
buffer[0] = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user