mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
feat(libSceHttp): implement sceHttpUriMerge
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <charconv>
|
||||
#include <cstdint>
|
||||
@@ -19,6 +20,7 @@ constexpr uint32_t URI_BUILD_WITH_USERNAME = 0x10;
|
||||
constexpr uint32_t URI_BUILD_WITH_PASSWORD = 0x20;
|
||||
constexpr uint32_t URI_BUILD_WITH_QUERY = 0x40;
|
||||
constexpr uint32_t URI_BUILD_WITH_FRAGMENT = 0x80;
|
||||
constexpr size_t URI_MAX_LENGTH = 0x3FFF;
|
||||
|
||||
struct UriParts {
|
||||
bool opaque = false;
|
||||
@@ -140,6 +142,13 @@ int parseUri(std::string_view uri, UriParts& parts) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t poolSize(const UriParts& parts) {
|
||||
const std::string_view fields[] = {parts.scheme, parts.username, parts.password, parts.hostname, parts.path, parts.query, parts.fragment};
|
||||
size_t size = 0;
|
||||
for (const std::string_view field : fields) size += field.size() + 1;
|
||||
return size;
|
||||
}
|
||||
|
||||
int copyOut(const std::string& value, char* out, size_t* require, size_t prepare) {
|
||||
if (require) *require = value.size() + 1;
|
||||
if (!out) return 0;
|
||||
@@ -218,6 +227,47 @@ int APS5_VABI sceHttpUriUnescape(char* out, size_t* require, size_t prepare, con
|
||||
return copyOut(decoded, out, require, prepare);
|
||||
}
|
||||
|
||||
int APS5_VABI sceHttpUriMerge(char* merged_url, const char* url, const char* relative_uri, size_t* require, size_t prepare, uint32_t option) {
|
||||
if (option != 0 || !url || !relative_uri) return ERROR_INVALID_VALUE;
|
||||
|
||||
UriParts base;
|
||||
if (const int result = parseUri(url, base); result != 0) return result;
|
||||
UriParts relative;
|
||||
if (const int result = parseUri(relative_uri, relative); result != 0) return result;
|
||||
|
||||
const size_t urlLength = strnlen(url, URI_MAX_LENGTH);
|
||||
const size_t relativeLength = strnlen(relative_uri, URI_MAX_LENGTH);
|
||||
const size_t size = poolSize(base) + 2 + (urlLength + relativeLength) * 2;
|
||||
if (require) *require = size;
|
||||
if (!merged_url) return 0;
|
||||
if (prepare < size) return ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (!relative.opaque) {
|
||||
std::strncpy(merged_url, relative_uri, size);
|
||||
if (require) *require = relativeLength + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string path = base.path;
|
||||
const size_t slash = path.rfind('/');
|
||||
if (slash == std::string::npos) path.push_back('/');
|
||||
else path.erase(slash + 1);
|
||||
if (relative_uri[0] == '/') path.clear();
|
||||
path.append(relative_uri, std::min(relativeLength, URI_MAX_LENGTH - std::min(path.size(), URI_MAX_LENGTH)));
|
||||
|
||||
std::string scheme(base.scheme), username(base.username), password(base.password), hostname(base.hostname);
|
||||
SceHttpUriElement element;
|
||||
element.opaque = base.opaque;
|
||||
element.scheme = scheme.data();
|
||||
element.username = username.data();
|
||||
element.password = password.data();
|
||||
element.hostname = hostname.data();
|
||||
element.path = path.data();
|
||||
element.port = base.port;
|
||||
return sceHttpUriBuild(merged_url, nullptr, prepare - (urlLength + relativeLength + 1), &element,
|
||||
URI_BUILD_WITH_SCHEME | URI_BUILD_WITH_HOSTNAME | URI_BUILD_WITH_PORT | URI_BUILD_WITH_PATH | URI_BUILD_WITH_USERNAME | URI_BUILD_WITH_PASSWORD);
|
||||
}
|
||||
|
||||
int APS5_VABI sceHttpUriParse(SceHttpUriElement* out, const char* src_url, void* pool, size_t* require, size_t prepare) {
|
||||
if (!src_url) return ERROR_INVALID_URL;
|
||||
const bool write = out && pool;
|
||||
@@ -227,8 +277,7 @@ int APS5_VABI sceHttpUriParse(SceHttpUriElement* out, const char* src_url, void*
|
||||
if (const int result = parseUri(src_url, parts); result != 0) return result;
|
||||
|
||||
const std::string_view fields[] = {parts.scheme, parts.username, parts.password, parts.hostname, parts.path, parts.query, parts.fragment};
|
||||
size_t size = 0;
|
||||
for (const std::string_view field : fields) size += field.size() + 1;
|
||||
const size_t size = poolSize(parts);
|
||||
if (require) *require = size;
|
||||
if (!write) return 0;
|
||||
if (prepare < size) return ERROR_OUT_OF_MEMORY;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
extern "C" {
|
||||
int APS5_VABI sceHttpUriParse(SceHttpUriElement*, const char*, void*, std::size_t*, std::size_t);
|
||||
int APS5_VABI sceHttpUriMerge(char*, const char*, const char*, std::size_t*, std::size_t, std::uint32_t);
|
||||
int APS5_VABI sceHttpSetInflateGZIPEnabled(int, int);
|
||||
int APS5_VABI sceHttpUriBuild(char*, std::size_t*, std::size_t, const SceHttpUriElement*, std::uint32_t);
|
||||
int APS5_VABI sceHttpUriEscape(char*, std::size_t*, std::size_t, const char*);
|
||||
@@ -125,6 +126,53 @@ int main() {
|
||||
Require(sceHttpUriUnescape(decodedBytes, &required, sizeof(decodedBytes), encodedBytes) == 0);
|
||||
Require(required == sizeof(bytes) && std::memcmp(bytes, decodedBytes, sizeof(bytes)) == 0);
|
||||
|
||||
const char* base = "http://foo.com/foo/index.html";
|
||||
const std::size_t baseMergeSize = 5 + 1 + 1 + 8 + 16 + 1 + 1 + 2;
|
||||
char merged[512];
|
||||
auto merge = [&](const char* mergeBase, const char* relative, const char* expected) {
|
||||
std::memset(merged, 'Z', sizeof(merged));
|
||||
return sceHttpUriMerge(merged, mergeBase, relative, &required, sizeof(merged), 0) == 0 && Equal(merged, expected);
|
||||
};
|
||||
Require(merge(base, "./default.html", "http://foo.com/foo/./default.html"));
|
||||
Require(required == baseMergeSize + 2 * (29 + 14));
|
||||
Require(merge(base, "../sibling.html", "http://foo.com/foo/../sibling.html"));
|
||||
Require(merge(base, "", "http://foo.com/foo/"));
|
||||
Require(merge(base, "/root.html", "http://foo.com/root.html"));
|
||||
Require(merge(base, "a?q=1#f", "http://foo.com/foo/a?q=1#f"));
|
||||
Require(merge("https://u:p@foo.com:8443/a/b?x=1#top", "c", "https://u:p@foo.com:8443/a/c"));
|
||||
Require(merge("http://foo.com", "x", "http://foo.com/x"));
|
||||
Require(merge("http://foo.com:80/", "x", "http://foo.com/x"));
|
||||
Require(merge("http://foo.com/a/b", "mailto:x", "http://foo.com/a/mailto:x"));
|
||||
|
||||
Require(merge(base, "http://bar.com/other", "http://bar.com/other") && required == 21);
|
||||
const std::size_t absoluteSize = baseMergeSize + 2 * (29 + 20);
|
||||
for (std::size_t i = 21; i < absoluteSize; ++i) Require(merged[i] == '\0');
|
||||
Require(merged[absoluteSize] == 'Z');
|
||||
Require(merge(base, "//bar.com/x", "//bar.com/x") && required == 12);
|
||||
|
||||
required = 0;
|
||||
Require(sceHttpUriMerge(nullptr, base, "./default.html", &required, 0, 0) == 0);
|
||||
Require(required == baseMergeSize + 2 * (29 + 14));
|
||||
Require(sceHttpUriMerge(nullptr, base, "http://bar.com/other", &required, 0, 0) == 0);
|
||||
Require(required == absoluteSize);
|
||||
Require(sceHttpUriMerge(nullptr, base, "x", nullptr, 0, 0) == 0);
|
||||
std::memset(merged, 'Z', sizeof(merged));
|
||||
Require(sceHttpUriMerge(merged, base, "./default.html", &required, baseMergeSize + 2 * (29 + 14) - 1, 0) == outOfMemory);
|
||||
Require(required == baseMergeSize + 2 * (29 + 14) && merged[0] == 'Z');
|
||||
Require(sceHttpUriMerge(merged, base, "http://bar.com/other", &required, absoluteSize - 1, 0) == outOfMemory);
|
||||
Require(merged[0] == 'Z');
|
||||
Require(sceHttpUriMerge(merged, base, "./default.html", nullptr, baseMergeSize + 2 * (29 + 14), 0) == 0);
|
||||
Require(Equal(merged, "http://foo.com/foo/./default.html"));
|
||||
|
||||
required = 123;
|
||||
Require(sceHttpUriMerge(merged, nullptr, "./x", &required, sizeof(merged), 0) == invalidValue);
|
||||
Require(sceHttpUriMerge(merged, base, nullptr, &required, sizeof(merged), 0) == invalidValue);
|
||||
Require(sceHttpUriMerge(merged, base, "./x", &required, sizeof(merged), 1) == invalidValue);
|
||||
Require(sceHttpUriMerge(nullptr, nullptr, nullptr, &required, 0, 1) == invalidValue);
|
||||
Require(sceHttpUriMerge(merged, "http://bad host/", "./x", &required, sizeof(merged), 0) == invalidUrl);
|
||||
Require(sceHttpUriMerge(merged, base, "http://bad host/", &required, sizeof(merged), 0) == invalidUrl);
|
||||
Require(required == 123);
|
||||
|
||||
HttpEpollHandle epoll = nullptr;
|
||||
Require(sceHttpCreateEpoll(1, nullptr) == invalidValue);
|
||||
Require(sceHttpCreateEpoll(1, &epoll) == 0 && epoll != nullptr);
|
||||
|
||||
@@ -109,6 +109,7 @@ Throughout the project, every function at every stage either **does exactly what
|
||||
- [NGS2 custom submixer rack](../../core/libs/prx/libSceNgs2.native/src/Custom.cpp) (libSceNgs2.native, rack 0x4002) - structure layouts from [shadPS4](https://github.com/shadps4-emu/shadPS4)'s `ngs2_custom.h`; module id 0x1f for UserFx2, the voice parameter id `0x40001f00 | module index`, the process flags (1 on the first process call after setup, 2 after a parameter change, 0 otherwise) and the call order (setup per voice at rack creation, process after the inputs are mixed, cleanup at destruction) come only from [KytyPS5](https://github.com/KytyPS5/KytyPS5). Only UserFx2 modules on a single buffer are accepted: other module ids, more buffers, a module control handler, different input and output channel counts, setup flags and default rack options throw. Each module's state is a separate buffer, not the `state_offset` slice of the voice state, and `sceNgs2VoiceGetState` still throws for this rack. As in KytyPS5, process runs only on grains where an input produced samples, so an effect tail stops with the input and a pending flag 2 waits for the next audible grain
|
||||
- [sceHttpParseResponseHeader](../../core/libs/prx/libSceHttp/Export.cpp) (libSceHttp) - signature follows [SharpProspero](https://github.com/SvenGDK/SharpProspero/blob/main/src/SharpProspero/Interop/Net/Http.cs); parsing and error codes follow [shadPS4's reverse-engineered PS4 library](https://github.com/shadps4-emu/shadPS4/blob/main/src/core/libraries/network/http.cpp), not confirmed on a PS5 title or hardware. Folded values retain their line breaks and whitespace; an empty first line starts the value scan after its line feed. A consumed byte count above `INT_MAX` throws instead of wrapping.
|
||||
- [sceHttpParseStatusLine](../../core/libs/prx/libSceHttp/src/Parse.cpp) (libSceHttp) - behaviour and error codes follow the [shadPS4](https://github.com/shadps4-emu/shadPS4) reimplementation of the PS4 library, not confirmed on a PS5 title; unlike it, no byte past `lineLen` is read
|
||||
- [sceHttpUriMerge](../../core/libs/prx/libSceHttp/src/Uri.cpp) (libSceHttp) - signature follows [SharpProspero](https://github.com/SvenGDK/SharpProspero/blob/main/src/SharpProspero/Interop/Net/Http.cs); validation, size formula, absolute/relative split and path join follow the disassembly-like body in [shadPS4](https://github.com/shadps4-emu/shadPS4/blob/main/src/core/libraries/network/http.cpp), not confirmed on a PS5 title or hardware. The base URL goes through our `sceHttpUriParse`, which removes dot segments from the base path, while the relative part is appended unswept; base query and fragment are dropped.
|
||||
- [sceHttpUriUnescape](../../core/libs/prx/libSceHttp/src/Uri.cpp) (libSceHttp) - signature follows [SharpProspero](https://github.com/SvenGDK/SharpProspero/blob/main/src/SharpProspero/Interop/Net/Http.cs); percent decoding, invalid sequences and error codes follow [shadPS4](https://github.com/shadps4-emu/shadPS4/blob/main/src/core/libraries/network/http.cpp), not confirmed on a PS5 title or hardware. Size includes the final NUL; malformed escapes and `+` remain unchanged, and decoding runs once.
|
||||
- [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
|
||||
|
||||
Reference in New Issue
Block a user