From b54ba478705fe8ceeee60aeb22f558261deac27a Mon Sep 17 00:00:00 2001 From: scribam Date: Sun, 2 Apr 2017 14:32:53 +0200 Subject: [PATCH] Stub cellHttpUtil (#2611) --- rpcs3/Emu/Cell/Modules/cellHttpUtil.cpp | 106 +++++++++++++++--------- rpcs3/Emu/Cell/Modules/cellHttpUtil.h | 70 ++++++++++++++-- 2 files changed, 127 insertions(+), 49 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellHttpUtil.cpp b/rpcs3/Emu/Cell/Modules/cellHttpUtil.cpp index 25eb5d6d73..d9ffae043f 100644 --- a/rpcs3/Emu/Cell/Modules/cellHttpUtil.cpp +++ b/rpcs3/Emu/Cell/Modules/cellHttpUtil.cpp @@ -5,123 +5,149 @@ logs::channel cellHttpUtil("cellHttpUtil", logs::level::notice); -s32 cellHttpUtilParseUri() +s32 cellHttpUtilParseUri(vm::ptr uri, vm::cptr str, vm::ptr pool, u32 size, vm::ptr required) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilParseUri(uri=*0x%x, str=%s, pool=*0x%x, size=%d, required=*0x%x)", uri, str, pool, size, required); return CELL_OK; } -s32 cellHttpUtilParseUriPath() +s32 cellHttpUtilParseUriPath(vm::ptr path, vm::cptr str, vm::ptr pool, u32 size, vm::ptr required) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilParseUriPath(path=*0x%x, str=%s, pool=*0x%x, size=%d, required=*0x%x)", path, str, pool, size, required); return CELL_OK; } -s32 cellHttpUtilParseProxy() +s32 cellHttpUtilParseProxy(vm::ptr uri, vm::cptr str, vm::ptr pool, u32 size, vm::ptr required) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilParseProxy(uri=*0x%x, str=%s, pool=*0x%x, size=%d, required=*0x%x)", uri, str, pool, size, required); return CELL_OK; } -s32 cellHttpUtilParseStatusLine() +s32 cellHttpUtilParseStatusLine(vm::ptr resp, vm::cptr str, u32 len, vm::ptr pool, u32 size, vm::ptr required, vm::ptr parsedLength) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilParseStatusLine(resp=*0x%x, str=%s, len=%d, pool=*0x%x, size=%d, required=*0x%x, parsedLength=*0x%x)", resp, str, len, pool, size, required, parsedLength); return CELL_OK; } -s32 cellHttpUtilParseHeader() +s32 cellHttpUtilParseHeader(vm::ptr header, vm::cptr str, u32 len, vm::ptr pool, u32 size, vm::ptr required, vm::ptr parsedLength) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilParseHeader(header=*0x%x, str=%s, len=%d, pool=*0x%x, size=%d, required=*0x%x, parsedLength=*0x%x)", header, str, len, pool, size, required, parsedLength); return CELL_OK; } -s32 cellHttpUtilBuildRequestLine() +s32 cellHttpUtilBuildRequestLine(vm::cptr req, vm::ptr buf, u32 len, vm::ptr required) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilBuildRequestLine(req=*0x%x, buf=*0x%x, len=%d, required=*0x%x)", req, buf, len, required); + + if (!req->method || !req->path || !req->protocol) { + return CELL_HTTP_UTIL_ERROR_INVALID_REQUEST; + } + + // TODO + + const std::string& result = fmt::format("%s %s %s/%d.%d\r\n", req->method, req->path, req->protocol, req->majorVersion, req->minorVersion); + std::memcpy(buf.get_ptr(), result.c_str(), result.size() + 1); + return CELL_OK; } -s32 cellHttpUtilBuildHeader() +s32 cellHttpUtilBuildHeader(vm::cptr header, vm::ptr buf, u32 len, vm::ptr required) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilBuildHeader(header=*0x%x, buf=*0x%x, len=%d, required=*0x%x)", header, buf, len, required); + + if (!header->name || !header->value) { + return CELL_HTTP_UTIL_ERROR_INVALID_HEADER; + } + + // TODO + + const std::string& result = fmt::format("%s: %s\r\n", header->name, header->value); + std::memcpy(buf.get_ptr(), result.c_str(), result.size() + 1); + return CELL_OK; } -s32 cellHttpUtilBuildUri() +s32 cellHttpUtilBuildUri(vm::cptr uri, vm::ptr buf, u32 len, vm::ptr required, s32 flags) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilBuildUri(uri=*0x%x, buf=*0x%x, len=%d, required=*0x%x, flags=%d)", uri, buf, len, required, flags); + + // TODO + + const std::string& result = fmt::format("%s://%s:%s@%s:%d/%s", uri->scheme, uri->username, uri->password, uri->hostname, uri->port, uri->path); + std::memcpy(buf.get_ptr(), result.c_str(), result.size() + 1); + return CELL_OK; } -s32 cellHttpUtilCopyUri() +s32 cellHttpUtilCopyUri(vm::ptr dest, vm::cptr src, vm::ptr pool, u32 poolSize, vm::ptr required) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilCopyUri(dest=*0x%x, src=*0x%x, pool=*0x%x, poolSize=%d, required=*0x%x)", dest, src, pool, poolSize, required); return CELL_OK; } -s32 cellHttpUtilMergeUriPath() +s32 cellHttpUtilMergeUriPath(vm::ptr uri, vm::cptr src, vm::cptr path, vm::ptr pool, u32 poolSize, vm::ptr required) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilMergeUriPath(uri=*0x%x, src=*0x%x, path=%s, pool=*0x%x, poolSize=%d, required=*0x%x)", uri, src, path, pool, poolSize, required); return CELL_OK; } -s32 cellHttpUtilSweepPath() +s32 cellHttpUtilSweepPath(vm::ptr dst, vm::cptr src, u32 srcSize) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilSweepPath(dst=*0x%x, src=%s, srcSize=%d)", dst, src, srcSize); return CELL_OK; } -s32 cellHttpUtilCopyStatusLine() +s32 cellHttpUtilCopyStatusLine(vm::ptr dest, vm::cptr src, vm::ptr pool, u32 poolSize, vm::ptr required) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilCopyStatusLine(dest=*0x%x, src=*0x%x, pool=*0x%x, poolSize=%d, required=*0x%x)", dest, src, pool, poolSize, required); return CELL_OK; } -s32 cellHttpUtilCopyHeader() +s32 cellHttpUtilCopyHeader(vm::ptr dest, vm::cptr src, vm::ptr pool, u32 poolSize, vm::ptr required) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilCopyHeader(dest=*0x%x, src=*0x%x, pool=*0x%x, poolSize=%d, required=*0x%x)", dest, src, pool, poolSize, required); return CELL_OK; } -s32 cellHttpUtilAppendHeaderValue() +s32 cellHttpUtilAppendHeaderValue(vm::ptr dest, vm::cptr src, vm::cptr value, vm::ptr pool, u32 poolSize, vm::ptr required) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilAppendHeaderValue(dest=*0x%x, src=*0x%x, value=%s, pool=*0x%x, poolSize=%d, required=*0x%x)", dest, src, value, pool, poolSize, required); return CELL_OK; } -s32 cellHttpUtilEscapeUri() +s32 cellHttpUtilEscapeUri(vm::ptr out, u32 outSize, vm::cptr in, u32 inSize, vm::ptr required) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilEscapeUri(out=*0x%x, outSize=%d, in=*0x%x, inSize=%d, required=*0x%x)", out, outSize, in, inSize, required); return CELL_OK; } -s32 cellHttpUtilUnescapeUri() +s32 cellHttpUtilUnescapeUri(vm::ptr out, u32 size, vm::cptr in, vm::ptr required) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilUnescapeUri(out=*0x%x, size=%d, in=*0x%x, required=*0x%x)", out, size, in, required); return CELL_OK; } -s32 cellHttpUtilFormUrlEncode() +s32 cellHttpUtilFormUrlEncode(vm::ptr out, u32 outSize, vm::cptr in, u32 inSize, vm::ptr required) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilFormUrlEncode(out=*0x%x, outSize=%d, in=*0x%x, inSize=%d, required=*0x%x)", out, outSize, in, inSize, required); return CELL_OK; } -s32 cellHttpUtilFormUrlDecode() +s32 cellHttpUtilFormUrlDecode(vm::ptr out, u32 size, vm::cptr in, vm::ptr required) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilFormUrlDecode(out=*0x%x, size=%d, in=%s, required=*0x%x)", out, size, in, required); return CELL_OK; } -s32 cellHttpUtilBase64Encoder() +s32 cellHttpUtilBase64Encoder(vm::ptr out, vm::cptr input, u32 len) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilBase64Encoder(out=*0x%x, input=*0x%x, len=%d)", out, input, len); return CELL_OK; } -s32 cellHttpUtilBase64Decoder() +s32 cellHttpUtilBase64Decoder(vm::ptr output, vm::cptr in, u32 len) { - UNIMPLEMENTED_FUNC(cellHttpUtil); + cellHttpUtil.todo("cellHttpUtilBase64Decoder(output=*0x%x, in=*0x%x, len=%d)", output, in, len); return CELL_OK; } diff --git a/rpcs3/Emu/Cell/Modules/cellHttpUtil.h b/rpcs3/Emu/Cell/Modules/cellHttpUtil.h index caac30340b..d6c10b5c7a 100644 --- a/rpcs3/Emu/Cell/Modules/cellHttpUtil.h +++ b/rpcs3/Emu/Cell/Modules/cellHttpUtil.h @@ -7,14 +7,66 @@ namespace vm { using namespace ps3; } // Error Codes enum { - CELL_HTTP_UTIL_ERROR_NO_MEMORY = 0x80711001, - CELL_HTTP_UTIL_ERROR_NO_BUFFER = 0x80711002, - CELL_HTTP_UTIL_ERROR_NO_STRING = 0x80711003, - CELL_HTTP_UTIL_ERROR_INSUFFICIENT = 0x80711004, - CELL_HTTP_UTIL_ERROR_INVALID_URI = 0x80711005, - CELL_HTTP_UTIL_ERROR_INVALID_HEADER = 0x80711006, - CELL_HTTP_UTIL_ERROR_INVALID_REQUEST = 0x80711007, - CELL_HTTP_UTIL_ERROR_INVALID_RESPONSE = 0x80711008, - CELL_HTTP_UTIL_ERROR_INVALID_LENGTH = 0x80711009, + CELL_HTTP_UTIL_ERROR_NO_MEMORY = 0x80711001, + CELL_HTTP_UTIL_ERROR_NO_BUFFER = 0x80711002, + CELL_HTTP_UTIL_ERROR_NO_STRING = 0x80711003, + CELL_HTTP_UTIL_ERROR_INSUFFICIENT = 0x80711004, + CELL_HTTP_UTIL_ERROR_INVALID_URI = 0x80711005, + CELL_HTTP_UTIL_ERROR_INVALID_HEADER = 0x80711006, + CELL_HTTP_UTIL_ERROR_INVALID_REQUEST = 0x80711007, + CELL_HTTP_UTIL_ERROR_INVALID_RESPONSE = 0x80711008, + CELL_HTTP_UTIL_ERROR_INVALID_LENGTH = 0x80711009, CELL_HTTP_UTIL_ERROR_INVALID_CHARACTER = 0x8071100a, }; + +enum +{ + CELL_HTTP_UTIL_URI_FLAG_FULL_URI = 0x00000000, + CELL_HTTP_UTIL_URI_FLAG_NO_SCHEME = 0x00000001, + CELL_HTTP_UTIL_URI_FLAG_NO_CREDENTIALS = 0x00000002, + CELL_HTTP_UTIL_URI_FLAG_NO_PASSWORD = 0x00000004, + CELL_HTTP_UTIL_URI_FLAG_NO_PATH = 0x00000008 +}; + +struct CellHttpUri +{ + vm::bcptr scheme; + vm::bcptr hostname; + vm::bcptr username; + vm::bcptr password; + vm::bcptr path; + be_t port; + u8 reserved[4]; +}; + +struct CellHttpUriPath +{ + vm::bcptr path; + vm::bcptr query; + vm::bcptr fragment; +}; + +struct CellHttpRequestLine +{ + vm::bcptr method; + vm::bcptr path; + vm::bcptr protocol; + be_t majorVersion; + be_t minorVersion; +}; + +struct CellHttpStatusLine +{ + vm::bcptr protocol; + be_t majorVersion; + be_t minorVersion; + vm::bcptr reasonPhrase; + be_t statusCode; + u8 reserved[4]; +}; + +struct CellHttpHeader +{ + vm::bcptr name; + vm::bcptr value; +};