This commit is contained in:
georgemoralis 2025-04-19 17:43:34 +00:00 committed by GitHub
commit 4ca7d66c48
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 301 additions and 33 deletions

View file

@ -9,6 +9,26 @@
namespace Libraries::Http {
void NormalizeAndAppendPath(char* dest, char* src) {
char* lastSlash;
u64 length;
lastSlash = strrchr(dest, '/');
if (lastSlash == NULL) {
length = strlen(dest);
dest[length] = '/';
dest[length + 1] = '\0';
} else {
lastSlash[1] = '\0';
}
if (*src == '/') {
dest[0] = '\0';
}
length = strnlen(dest, 0x3fff);
strncat(dest, src, 0x3fff - length);
return;
}
int PS4_SYSV_ABI sceHttpAbortRequest() {
LOG_ERROR(Lib_Http, "(STUBBED) called");
return ORBIS_OK;
@ -184,7 +204,7 @@ int PS4_SYSV_ABI sceHttpGetAcceptEncodingGZIPEnabled() {
return ORBIS_OK;
}
int PS4_SYSV_ABI sceHttpGetAllResponseHeaders() {
int PS4_SYSV_ABI sceHttpGetAllResponseHeaders(int reqId, char** header, u64* headerSize) {
LOG_ERROR(Lib_Http, "(STUBBED) called");
return ORBIS_OK;
}
@ -254,12 +274,80 @@ int PS4_SYSV_ABI sceHttpGetResponseContentLength() {
return ORBIS_OK;
}
int PS4_SYSV_ABI sceHttpGetStatusCode() {
int PS4_SYSV_ABI sceHttpGetStatusCode(int reqId, int* statusCode) {
LOG_ERROR(Lib_Http, "(STUBBED) called");
#if 0
uint uVar1;
#endif
int returnCode;
#if 0
undefined8 uVar3;
long local_60;
undefined1 local_58 [8];
undefined1 local_50 [8];
long local_48;
undefined8 local_40;
long local_38;
local_38 = ___stack_chk_guard;
local_40 = 0;
local_48 = 0;
if (g_isHttpInitialized == 0) {
returnCode = -0x7fbcefff;
}
#endif
if (statusCode == nullptr) {
// returnCode = ORBIS_HTTP_ERROR_INVALID_VALUE; //TODO
return ORBIS_HTTP_ERROR_INVALID_VALUE;
}
#if 0
else {
uVar1 = getSdkVersion();
returnCode = scePthreadAttrInit(local_50);
if ((-1 < returnCode) || (uVar1 < 0x3000000)) {
uVar3 = scePthreadSelf();
returnCode = scePthreadAttrGet(uVar3,local_50);
if ((returnCode < 0) && (0x2ffffff < uVar1)) {
scePthreadAttrDestroy(local_50);
}
else {
returnCode = scePthreadAttrGetstack(local_50,&local_60,local_58);
scePthreadAttrDestroy(local_50);
if (((-1 < returnCode) || (uVar1 < 0x3000000)) &&
((uVar1 < 0x1000000 ||
(returnCode = -0x7fbcef8a, 0x3fcf < (ulong)((long)&local_40 - local_60))))) {
returnCode = FUN_01018c20(&local_48,reqId);
if ((-1 < returnCode) && (returnCode = scePthreadMutexLock(local_48 + 0x530), -1 < returnCode)) {
returnCode = -0x7fbcef9b;
if (0x11 < *(int *)(local_48 + 0x20)) {
if (*(int *)(local_48 + 0x20) == 0x16) {
returnCode = *(int *)(local_48 + 0x28);
}
else {
returnCode = 0;
*statusCode = *(int *)(local_48 + 0x20c);
}
}
scePthreadMutexUnlock(local_48 + 0x530);
}
if (local_48 != 0) {
FUN_010195c0();
}
}
}
}
}
if (___stack_chk_guard != local_38) {
/* WARNING: Subroutine does not return */
__stack_chk_fail();
}
return returnCode;
#endif
*statusCode = 404; // not found
return ORBIS_OK;
}
int PS4_SYSV_ABI sceHttpInit(int libnetMemId, int libsslCtxId, std::size_t poolSize) {
int PS4_SYSV_ABI sceHttpInit(int libnetMemId, int libsslCtxId, u64 poolSize) {
LOG_ERROR(Lib_Http, "(DUMMY) called libnetMemId = {} libsslCtxId = {} poolSize = {}",
libnetMemId, libsslCtxId, poolSize);
// return a value >1
@ -267,14 +355,104 @@ int PS4_SYSV_ABI sceHttpInit(int libnetMemId, int libsslCtxId, std::size_t poolS
return ++id;
}
int PS4_SYSV_ABI sceHttpParseResponseHeader() {
int PS4_SYSV_ABI sceHttpParseResponseHeader(const char* header, u64 headerLen, const char* fieldStr,
const char** fieldValue, u64* valueLen) {
LOG_ERROR(Lib_Http, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceHttpParseStatusLine() {
LOG_ERROR(Lib_Http, "(STUBBED) called");
return ORBIS_OK;
int PS4_SYSV_ABI sceHttpParseStatusLine(const char* statusLine, u64 lineLen, int32_t* httpMajorVer,
int32_t* httpMinorVer, int32_t* responseCode,
const char** reasonPhrase, u64* phraseLen) {
if (!statusLine) {
LOG_ERROR(Lib_Http, "Invalid response");
return ORBIS_HTTP_ERROR_PARSE_HTTP_INVALID_RESPONSE;
}
if (!httpMajorVer || !httpMinorVer || !responseCode || !reasonPhrase || !phraseLen) {
LOG_ERROR(Lib_Http, "Invalid value");
return ORBIS_HTTP_ERROR_PARSE_HTTP_INVALID_VALUE;
}
*httpMajorVer = 0;
*httpMinorVer = 0;
if (lineLen < 8) {
LOG_ERROR(Lib_Http, "Linelen is smaller than 8");
return ORBIS_HTTP_ERROR_PARSE_HTTP_INVALID_RESPONSE;
}
if (strncmp(statusLine, "HTTP/", 5) != 0) {
LOG_ERROR(Lib_Http, "statusLine doesn't start with HTTP/");
return ORBIS_HTTP_ERROR_PARSE_HTTP_INVALID_RESPONSE;
}
u64 index = 5;
if (!isdigit(statusLine[index])) {
LOG_ERROR(Lib_Http, "Invalid response");
return ORBIS_HTTP_ERROR_PARSE_HTTP_INVALID_RESPONSE;
}
while (isdigit(statusLine[index])) {
*httpMajorVer = *httpMajorVer * 10 + (statusLine[index] - '0');
index++;
}
if (statusLine[index] != '.') {
LOG_ERROR(Lib_Http, "Invalid response");
return ORBIS_HTTP_ERROR_PARSE_HTTP_INVALID_RESPONSE;
}
index++;
if (!isdigit(statusLine[index])) {
LOG_ERROR(Lib_Http, "Invalid response");
return ORBIS_HTTP_ERROR_PARSE_HTTP_INVALID_RESPONSE;
}
while (isdigit(statusLine[index])) {
*httpMinorVer = *httpMinorVer * 10 + (statusLine[index] - '0');
index++;
}
if (statusLine[index] != ' ') {
LOG_ERROR(Lib_Http, "Invalid response");
return ORBIS_HTTP_ERROR_PARSE_HTTP_INVALID_RESPONSE;
}
index++;
// Validate and parse the 3-digit HTTP response code
if (lineLen - index < 3 || !isdigit(statusLine[index]) || !isdigit(statusLine[index + 1]) ||
!isdigit(statusLine[index + 2])) {
LOG_ERROR(Lib_Http, "Invalid response");
return ORBIS_HTTP_ERROR_PARSE_HTTP_INVALID_RESPONSE;
}
*responseCode = (statusLine[index] - '0') * 100 + (statusLine[index + 1] - '0') * 10 +
(statusLine[index + 2] - '0');
index += 3;
if (statusLine[index] != ' ') {
LOG_ERROR(Lib_Http, "Invalid response");
return ORBIS_HTTP_ERROR_PARSE_HTTP_INVALID_RESPONSE;
}
index++;
// Set the reason phrase start position
*reasonPhrase = &statusLine[index];
u64 phraseStart = index;
while (index < lineLen && statusLine[index] != '\n') {
index++;
}
// Determine the length of the reason phrase, excluding trailing \r if present
if (index == phraseStart) {
*phraseLen = 0;
} else {
*phraseLen =
(statusLine[index - 1] == '\r') ? (index - phraseStart - 1) : (index - phraseStart);
}
// Return the number of bytes processed
return index + 1;
}
int PS4_SYSV_ABI sceHttpReadData() {
@ -547,7 +725,8 @@ int PS4_SYSV_ABI sceHttpUnsetEpoll() {
return ORBIS_OK;
}
int PS4_SYSV_ABI sceHttpUriBuild() {
int PS4_SYSV_ABI sceHttpUriBuild(char* out, u64* require, u64 prepare,
const OrbisHttpUriElement* srcElement, u32 option) {
LOG_ERROR(Lib_Http, "(STUBBED) called");
return ORBIS_OK;
}
@ -562,13 +741,97 @@ int PS4_SYSV_ABI sceHttpUriEscape() {
return ORBIS_OK;
}
int PS4_SYSV_ABI sceHttpUriMerge() {
LOG_ERROR(Lib_Http, "(STUBBED) called");
return ORBIS_OK;
int PS4_SYSV_ABI sceHttpUriMerge(char* mergedUrl, char* url, char* relativeUri, u64* require,
u64 prepare, u32 option) {
u64 requiredLength;
int returnValue;
u64 baseUrlLength;
u64 relativeUriLength;
u64 totalLength;
u64 combinedLength;
int parseResult;
u64 localSizeRelativeUri;
u64 localSizeBaseUrl;
OrbisHttpUriElement parsedUriElement;
if (option != 0 || url == NULL || relativeUri == NULL) {
LOG_ERROR(Lib_Http, "Invalid value");
return ORBIS_HTTP_ERROR_INVALID_VALUE;
}
returnValue = sceHttpUriParse(NULL, url, NULL, &localSizeBaseUrl, 0);
if (returnValue < 0) {
LOG_ERROR(Lib_Http, "returning {:#x}", returnValue);
return returnValue;
}
returnValue = sceHttpUriParse(NULL, relativeUri, NULL, &localSizeRelativeUri, 0);
if (returnValue < 0) {
LOG_ERROR(Lib_Http, "returning {:#x}", returnValue);
return returnValue;
}
baseUrlLength = strnlen(url, 0x3fff);
relativeUriLength = strnlen(relativeUri, 0x3fff);
requiredLength = localSizeBaseUrl + 2 + (relativeUriLength + baseUrlLength) * 2;
if (require) {
*require = requiredLength;
}
if (mergedUrl == NULL) {
return ORBIS_OK;
}
if (prepare < requiredLength) {
LOG_ERROR(Lib_Http, "Error Out of memory");
return ORBIS_HTTP_ERROR_OUT_OF_MEMORY;
}
totalLength = strnlen(url, 0x3fff);
baseUrlLength = strnlen(relativeUri, 0x3fff);
combinedLength = totalLength + 1 + baseUrlLength;
relativeUriLength = prepare - combinedLength;
returnValue =
sceHttpUriParse(&parsedUriElement, relativeUri, mergedUrl + totalLength + baseUrlLength + 1,
&localSizeRelativeUri, relativeUriLength);
if (returnValue < 0) {
LOG_ERROR(Lib_Http, "returning {:#x}", returnValue);
return returnValue;
}
if (parsedUriElement.scheme == NULL) {
strncpy(mergedUrl, relativeUri, requiredLength);
if (require) {
*require = strnlen(relativeUri, 0x3fff) + 1;
}
return ORBIS_OK;
}
returnValue =
sceHttpUriParse(&parsedUriElement, url, mergedUrl + totalLength + baseUrlLength + 1,
&localSizeBaseUrl, relativeUriLength);
if (returnValue < 0) {
LOG_ERROR(Lib_Http, "returning {:#x}", returnValue);
return returnValue;
}
combinedLength += localSizeBaseUrl;
strncpy(mergedUrl + combinedLength, parsedUriElement.path, prepare - combinedLength);
NormalizeAndAppendPath(mergedUrl + combinedLength, relativeUri);
returnValue = sceHttpUriBuild(mergedUrl, 0, ~(baseUrlLength + totalLength) + prepare,
&parsedUriElement, 0x3f);
if (returnValue >= 0) {
return ORBIS_OK;
} else {
LOG_ERROR(Lib_Http, "returning {:#x}", returnValue);
return returnValue;
}
}
int PS4_SYSV_ABI sceHttpUriParse(OrbisHttpUriElement* out, const char* srcUri, void* pool,
size_t* require, size_t prepare) {
u64* require, u64 prepare) {
LOG_INFO(Lib_Http, "srcUri = {}", std::string(srcUri));
if (!srcUri) {
LOG_ERROR(Lib_Http, "invalid url");
@ -585,10 +848,10 @@ int PS4_SYSV_ABI sceHttpUriParse(OrbisHttpUriElement* out, const char* srcUri, v
}
// Track the total required buffer size
size_t requiredSize = 0;
u64 requiredSize = 0;
// Parse the scheme (e.g., "http:", "https:", "file:")
size_t schemeLength = 0;
u64 schemeLength = 0;
while (srcUri[schemeLength] && srcUri[schemeLength] != ':') {
if (!isalnum(srcUri[schemeLength])) {
LOG_ERROR(Lib_Http, "invalid url");
@ -610,7 +873,7 @@ int PS4_SYSV_ABI sceHttpUriParse(OrbisHttpUriElement* out, const char* srcUri, v
requiredSize += schemeLength + 1;
// Move past the scheme and ':' character
size_t offset = schemeLength + 1;
u64 offset = schemeLength + 1;
// Check if "//" appears after the scheme
if (strncmp(srcUri + offset, "//", 2) == 0) {
@ -637,7 +900,7 @@ int PS4_SYSV_ABI sceHttpUriParse(OrbisHttpUriElement* out, const char* srcUri, v
// Parse the path (everything after the slashes)
char* pathStart = (char*)srcUri + offset;
size_t pathLength = 0;
u64 pathLength = 0;
while (pathStart[pathLength] && pathStart[pathLength] != '?' &&
pathStart[pathLength] != '#') {
pathLength++;
@ -688,7 +951,7 @@ int PS4_SYSV_ABI sceHttpUriParse(OrbisHttpUriElement* out, const char* srcUri, v
hostStart++;
}
size_t hostLength = 0;
u64 hostLength = 0;
while (hostStart[hostLength] && hostStart[hostLength] != '/' &&
hostStart[hostLength] != '?' && hostStart[hostLength] != ':') {
hostLength++;
@ -713,7 +976,7 @@ int PS4_SYSV_ABI sceHttpUriParse(OrbisHttpUriElement* out, const char* srcUri, v
// Parse the port (if present)
if (hostStart[hostLength] == ':') {
char* portStart = hostStart + hostLength + 1;
size_t portLength = 0;
u64 portLength = 0;
while (portStart[portLength] && isdigit(portStart[portLength])) {
portLength++;
}
@ -753,7 +1016,7 @@ int PS4_SYSV_ABI sceHttpUriParse(OrbisHttpUriElement* out, const char* srcUri, v
// Parse the path (if present)
if (srcUri[offset] == '/') {
char* pathStart = (char*)srcUri + offset;
size_t pathLength = 0;
u64 pathLength = 0;
while (pathStart[pathLength] && pathStart[pathLength] != '?' &&
pathStart[pathLength] != '#') {
pathLength++;
@ -779,7 +1042,7 @@ int PS4_SYSV_ABI sceHttpUriParse(OrbisHttpUriElement* out, const char* srcUri, v
// Parse the query (if present)
if (srcUri[offset] == '?') {
char* queryStart = (char*)srcUri + offset + 1;
size_t queryLength = 0;
u64 queryLength = 0;
while (queryStart[queryLength] && queryStart[queryLength] != '#') {
queryLength++;
}
@ -804,7 +1067,7 @@ int PS4_SYSV_ABI sceHttpUriParse(OrbisHttpUriElement* out, const char* srcUri, v
// Parse the fragment (if present)
if (srcUri[offset] == '#') {
char* fragmentStart = (char*)srcUri + offset + 1;
size_t fragmentLength = 0;
u64 fragmentLength = 0;
while (fragmentStart[fragmentLength]) {
fragmentLength++;
}
@ -832,12 +1095,12 @@ int PS4_SYSV_ABI sceHttpUriParse(OrbisHttpUriElement* out, const char* srcUri, v
return ORBIS_OK;
}
int PS4_SYSV_ABI sceHttpUriSweepPath(char* dst, const char* src, size_t srcSize) {
int PS4_SYSV_ABI sceHttpUriSweepPath(char* dst, const char* src, u64 srcSize) {
LOG_ERROR(Lib_Http, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceHttpUriUnescape(char* out, size_t* require, size_t prepare, const char* in) {
int PS4_SYSV_ABI sceHttpUriUnescape(char* out, u64* require, u64 prepare, const char* in) {
LOG_ERROR(Lib_Http, "(STUBBED) called");
return ORBIS_OK;
}

View file

@ -59,7 +59,7 @@ int PS4_SYSV_ABI sceHttpDeleteRequest();
int PS4_SYSV_ABI sceHttpDeleteTemplate();
int PS4_SYSV_ABI sceHttpDestroyEpoll();
int PS4_SYSV_ABI sceHttpGetAcceptEncodingGZIPEnabled();
int PS4_SYSV_ABI sceHttpGetAllResponseHeaders();
int PS4_SYSV_ABI sceHttpGetAllResponseHeaders(int reqId, char** header, u64* headerSize);
int PS4_SYSV_ABI sceHttpGetAuthEnabled();
int PS4_SYSV_ABI sceHttpGetAutoRedirect();
int PS4_SYSV_ABI sceHttpGetConnectionStat();
@ -73,10 +73,13 @@ int PS4_SYSV_ABI sceHttpGetMemoryPoolStats();
int PS4_SYSV_ABI sceHttpGetNonblock();
int PS4_SYSV_ABI sceHttpGetRegisteredCtxIds();
int PS4_SYSV_ABI sceHttpGetResponseContentLength();
int PS4_SYSV_ABI sceHttpGetStatusCode();
int PS4_SYSV_ABI sceHttpInit(int libnetMemId, int libsslCtxId, std::size_t poolSize);
int PS4_SYSV_ABI sceHttpParseResponseHeader();
int PS4_SYSV_ABI sceHttpParseStatusLine();
int PS4_SYSV_ABI sceHttpGetStatusCode(int reqId, int* statusCode);
int PS4_SYSV_ABI sceHttpInit(int libnetMemId, int libsslCtxId, u64 poolSize);
int PS4_SYSV_ABI sceHttpParseResponseHeader(const char* header, u64 headerLen, const char* fieldStr,
const char** fieldValue, u64* valueLen);
int PS4_SYSV_ABI sceHttpParseStatusLine(const char* statusLine, u64 lineLen, int32_t* httpMajorVer,
int32_t* httpMinorVer, int32_t* responseCode,
const char** reasonPhrase, u64* phraseLen);
int PS4_SYSV_ABI sceHttpReadData();
int PS4_SYSV_ABI sceHttpRedirectCacheFlush();
int PS4_SYSV_ABI sceHttpRemoveRequestHeader();
@ -131,14 +134,16 @@ int PS4_SYSV_ABI sceHttpTerm();
int PS4_SYSV_ABI sceHttpTryGetNonblock();
int PS4_SYSV_ABI sceHttpTrySetNonblock();
int PS4_SYSV_ABI sceHttpUnsetEpoll();
int PS4_SYSV_ABI sceHttpUriBuild();
int PS4_SYSV_ABI sceHttpUriBuild(char* out, u64* require, u64 prepare,
const OrbisHttpUriElement* srcElement, u32 option);
int PS4_SYSV_ABI sceHttpUriCopy();
int PS4_SYSV_ABI sceHttpUriEscape();
int PS4_SYSV_ABI sceHttpUriMerge();
int PS4_SYSV_ABI sceHttpUriMerge(char* mergedUrl, char* url, char* relativeUri, u64* require,
u64 prepare, u32 option);
int PS4_SYSV_ABI sceHttpUriParse(OrbisHttpUriElement* out, const char* srcUri, void* pool,
size_t* require, size_t prepare);
int PS4_SYSV_ABI sceHttpUriSweepPath(char* dst, const char* src, size_t srcSize);
int PS4_SYSV_ABI sceHttpUriUnescape(char* out, size_t* require, size_t prepare, const char* in);
u64* require, u64 prepare);
int PS4_SYSV_ABI sceHttpUriSweepPath(char* dst, const char* src, u64 srcSize);
int PS4_SYSV_ABI sceHttpUriUnescape(char* out, u64* require, u64 prepare, const char* in);
int PS4_SYSV_ABI sceHttpWaitRequest();
void RegisterlibSceHttp(Core::Loader::SymbolsResolver* sym);