diff --git a/core/libs/prx/libSceHttp2/CMakeLists.txt b/core/libs/prx/libSceHttp2/CMakeLists.txt new file mode 100644 index 000000000..08d9a13c8 --- /dev/null +++ b/core/libs/prx/libSceHttp2/CMakeLists.txt @@ -0,0 +1,21 @@ +add_library(libSceHttp2 SHARED EXCLUDE_FROM_ALL Export.cpp) +target_include_directories(libSceHttp2 PRIVATE ${LIBS_INCLUDE_DIR}) +configure_windows_unwind(libSceHttp2) + +if(MINGW) + foreach(runtimeLinkFlag IN ITEMS -static-libgcc -static-libstdc++ -static) + string(REPLACE "${runtimeLinkFlag}" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") + endforeach() +endif() + +if(BUILD_TESTING) + add_test_executable(guest_http2_tests ${LIBS_INCLUDE_DIR}/tests/GuestHttp2.cpp) + target_include_directories(guest_http2_tests PRIVATE ${LIBS_INCLUDE_DIR}) + target_link_libraries(guest_http2_tests PRIVATE libSceHttp2 libc) + configure_windows_unwind(guest_http2_tests) + add_test(NAME guest_http2 COMMAND guest_http2_tests) + if(WIN32) + set_tests_properties(guest_http2 PROPERTIES ENVIRONMENT_MODIFICATION + "PATH=path_list_prepend:$") + endif() +endif() diff --git a/core/libs/prx/libSceHttp2/Export.cpp b/core/libs/prx/libSceHttp2/Export.cpp index adaa00e78..a90ecb83f 100644 --- a/core/libs/prx/libSceHttp2/Export.cpp +++ b/core/libs/prx/libSceHttp2/Export.cpp @@ -214,23 +214,24 @@ int APS5_VABI sceHttp2GetMemoryPoolStats() { return 0; } -int APS5_VABI sceHttp2CookieFlush(void) { - NotImplemented_nid_no_patch(__func__); +int APS5_VABI sceHttp2CookieFlush(int id) { + (void)id; return 0; } -int APS5_VABI sceHttp2CreateCookieBox(void) { - NotImplemented_nid_no_patch(__func__); +int APS5_VABI sceHttp2CreateCookieBox(int lib_http2_ctx_id) { + (void)lib_http2_ctx_id; + return g_nextHandle.fetch_add(1, std::memory_order_relaxed); +} + +int APS5_VABI sceHttp2SetCookieBox(int id, int cookie_box_id) { + (void)id; + (void)cookie_box_id; return 0; } -int APS5_VABI sceHttp2SetCookieBox(void) { - NotImplemented_nid_no_patch(__func__); - return 0; -} - -int APS5_VABI sceHttp2SetRequestNoContentLength(void) { - NotImplemented_nid_no_patch(__func__); +int APS5_VABI sceHttp2SetRequestNoContentLength(int id) { + (void)id; return 0; } diff --git a/core/libs/tests/GuestHttp2.cpp b/core/libs/tests/GuestHttp2.cpp new file mode 100644 index 000000000..7be4800b5 --- /dev/null +++ b/core/libs/tests/GuestHttp2.cpp @@ -0,0 +1,36 @@ +#include "SceTypes.hpp" +#include +#include + +extern "C" { +int APS5_VABI sceHttp2Init(int, int, std::size_t, int); +int APS5_VABI sceHttp2CreateTemplate(int, const char*, int, int); +int APS5_VABI sceHttp2CreateRequestWithURL(int, const char*, const char*, std::uint64_t); +int APS5_VABI sceHttp2CreateCookieBox(int); +int APS5_VABI sceHttp2SetCookieBox(int, int); +int APS5_VABI sceHttp2CookieFlush(int); +int APS5_VABI sceHttp2SetRequestNoContentLength(int); +int APS5_VABI sceHttp2SendRequest(int, const void*, std::size_t); +int APS5_VABI sceHttp2Term(int); +} + +static void Require(bool value) { if (!value) std::abort(); } + +int main() { + const int context = sceHttp2Init(1, 1, 0x10000, 4); + Require(context > 0); + const int box = sceHttp2CreateCookieBox(context); + const int other = sceHttp2CreateCookieBox(context); + Require(box > 0 && other > 0 && box != other && box != context); + const int tmpl = sceHttp2CreateTemplate(context, "agent", 2, 0); + Require(tmpl > 0 && tmpl != box && tmpl != other); + Require(sceHttp2SetCookieBox(tmpl, box) == 0); + Require(sceHttp2SetCookieBox(tmpl, 0) == 0); + const int request = sceHttp2CreateRequestWithURL(tmpl, "POST", "https://example.com/", 16); + Require(request > 0); + Require(sceHttp2SetCookieBox(request, other) == 0); + Require(sceHttp2SetRequestNoContentLength(request) == 0); + Require(sceHttp2CookieFlush(context) == 0); + Require(sceHttp2SendRequest(request, nullptr, 0) == static_cast(0x80436063)); + Require(sceHttp2Term(context) == 0); +} diff --git a/docs/dev/TechnicalDebt.md b/docs/dev/TechnicalDebt.md index 6daf2d0ed..8543e95d7 100644 --- a/docs/dev/TechnicalDebt.md +++ b/docs/dev/TechnicalDebt.md @@ -124,6 +124,7 @@ Throughout the project, every function at every stage either **does exactly what - [sceHttpUriSweepPath](../../core/libs/prx/libSceHttp/src/Uri.cpp) (libSceHttp) - behaviour follows the [shadPS4](https://github.com/shadps4-emu/shadPS4/blob/main/src/core/libraries/network/http.cpp) reimplementation of the PS4 library and its tests (including the PS4 SDK example), not confirmed on a PS5 title or hardware. It is not RFC 3986 5.2.4: a path that doesn't start with `/` is copied unchanged and a trailing `.` or `..` without a slash is kept. Unlike shadPS4, nothing at or past `srcSize - 1` is read, and `srcSize == 1` writes only the terminator - [sceHttpSetResponseHeaderMaxSize, sceHttpRedirectCacheFlush, sceHttpsUnloadCert](../../core/libs/prx/libSceHttp/Export.cpp) (libSceHttp) - signatures follow [shadPS4](https://github.com/shadps4-emu/shadPS4/blob/main/src/core/libraries/network/http.cpp) (PS4); no PS5 reference has them - [sceHttp2GetMemoryPoolStats](../../core/libs/prx/libSceHttp2/Export.cpp) (libSceHttp2) - unknown signature +- [libSceHttp2 cookie boxes](../../core/libs/prx/libSceHttp2/Export.cpp) (libSceHttp2) - `sceHttp2CreateCookieBox` is taken to take the library context id first, as in the [prosper](https://github.com/mattias800/prosper) reimplementation; further arguments are unknown and ignored. `sceHttp2SetRequestNoContentLength` is assumed to take only the request id. Cookies are never stored, so `sceHttp2CookieFlush` has nothing to discard - [sceNetGetMemoryPoolStats](../../core/libs/prx/libSceNet/Export.cpp) (libSceNet) - unknown signature - [sceHttpSetRequestStatusCallback](../../core/libs/prx/libSceHttp/Export.cpp) (libSceHttp) - no reference implements it (shadPS4 only logs and returns 0); when the callback runs and what status it gets is unknown - [sceNpSessionSignalingGetMemoryInfo](../../core/libs/prx/libSceNpSessionSignaling/Export.cpp) (libSceNpSessionSignaling) - unknown signature