stub cellHttp

This commit is contained in:
Megamouse 2022-06-16 20:54:04 +02:00
parent 6bdf415adb
commit 0b14d785ca
6 changed files with 2914 additions and 249 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1087,3 +1087,128 @@ enum CellHttpErrorNet
CELL_HTTP_ERROR_NET_SSL_RECV_ENOSTR = 0x80710d5b,
CELL_HTTP_ERROR_NET_SSL_RECV_ETIME = 0x80710d5c,
};
enum
{
CELL_HTTP_TRANSACTION_STATE_GETTING_CONNECTION = 1,
CELL_HTTP_TRANSACTION_STATE_PREPARING_REQUEST = 2,
CELL_HTTP_TRANSACTION_STATE_SENDING_REQUEST = 3,
CELL_HTTP_TRANSACTION_STATE_SENDING_BODY = 4,
CELL_HTTP_TRANSACTION_STATE_WAITING_FOR_REPLY = 5,
CELL_HTTP_TRANSACTION_STATE_READING_REPLY = 6,
CELL_HTTP_TRANSACTION_STATE_SETTING_REDIRECTION = 7,
CELL_HTTP_TRANSACTION_STATE_SETTING_AUTHENTICATION = 8,
};
enum
{
CELL_HTTP_STATUS_CODE_Continue = 100,
CELL_HTTP_STATUS_CODE_Switching_Protocols = 101,
CELL_HTTP_STATUS_CODE_Processing = 102,
// Success codes
CELL_HTTP_STATUS_CODE_OK = 200,
CELL_HTTP_STATUS_CODE_Created = 201,
CELL_HTTP_STATUS_CODE_Accepted = 202,
CELL_HTTP_STATUS_CODE_NonAuthoritive_Information = 203,
CELL_HTTP_STATUS_CODE_No_Content = 204,
CELL_HTTP_STATUS_CODE_Reset_Content = 205,
CELL_HTTP_STATUS_CODE_Partial_Content = 206,
CELL_HTTP_STATUS_CODE_MultiStatus = 207,
/* Redirection 3xx */
CELL_HTTP_STATUS_CODE_Multiple_Choices = 300,
CELL_HTTP_STATUS_CODE_Moved_Permanently = 301,
CELL_HTTP_STATUS_CODE_Moved_Temporarily = 302,
CELL_HTTP_STATUS_CODE_Found = CELL_HTTP_STATUS_CODE_Moved_Temporarily,
CELL_HTTP_STATUS_CODE_See_Other = 303,
CELL_HTTP_STATUS_CODE_Not_Modified = 304,
CELL_HTTP_STATUS_CODE_Use_Proxy = 305,
//CELL_HTTP_STATUS_CODE_UNUSED = 306,
CELL_HTTP_STATUS_CODE_Temporary_Redirect = 307,
// Client errors
CELL_HTTP_STATUS_CODE_Bad_Request = 400,
CELL_HTTP_STATUS_CODE_Unauthorized = 401,
CELL_HTTP_STATUS_CODE_Payment_Required = 402,
CELL_HTTP_STATUS_CODE_Forbidden = 403,
CELL_HTTP_STATUS_CODE_Not_Found = 404,
CELL_HTTP_STATUS_CODE_Method_Not_Allowed = 405,
CELL_HTTP_STATUS_CODE_Not_Acceptable = 406,
CELL_HTTP_STATUS_CODE_Proxy_Authentication_Required = 407,
CELL_HTTP_STATUS_CODE_Request_Timeout = 408,
CELL_HTTP_STATUS_CODE_Conflict = 409,
CELL_HTTP_STATUS_CODE_Gone = 410,
CELL_HTTP_STATUS_CODE_Length_Required = 411,
CELL_HTTP_STATUS_CODE_Precondition_Failed = 412,
CELL_HTTP_STATUS_CODE_Request_Entity_Too_Large = 413,
CELL_HTTP_STATUS_CODE_RequestURI_Too_Long = 414,
CELL_HTTP_STATUS_CODE_Unsupported_Media_Type = 415,
CELL_HTTP_STATUS_CODE_Requested_Range_Not_Satisfiable = 416,
CELL_HTTP_STATUS_CODE_Expectation_Failed = 417,
CELL_HTTP_STATUS_CODE_Unprocessable_Entity = 422,
CELL_HTTP_STATUS_CODE_Locked = 423,
CELL_HTTP_STATUS_CODE_Failed_Dependency = 424,
CELL_HTTP_STATUS_CODE_Upgrade_Required = 426,
// Server error
CELL_HTTP_STATUS_CODE_Internal_Server_Error = 500,
CELL_HTTP_STATUS_CODE_Not_Implemented = 501,
CELL_HTTP_STATUS_CODE_Bad_Gateway = 502,
CELL_HTTP_STATUS_CODE_Service_Unavailable = 503,
CELL_HTTP_STATUS_CODE_Gateway_Timeout = 504,
CELL_HTTP_STATUS_CODE_HTTP_Version_Not_Supported = 505,
CELL_HTTP_STATUS_CODE_Insufficient_Storage = 507,
};
enum
{
CELL_HTTPS_VERIFY_ERROR_NONE = 0x00000000U,
CELL_HTTPS_VERIFY_ERROR_NO_CERT = 0x00000001U,
CELL_HTTPS_VERIFY_ERROR_BAD_SSL = 0x00000002U,
CELL_HTTPS_VERIFY_ERROR_BAD_CLIENT = 0x00000004U,
CELL_HTTPS_VERIFY_ERROR_UNKNOWN_CA = 0x00000008U,
CELL_HTTPS_VERIFY_ERROR_BAD_CHAIN = 0x00000010U,
CELL_HTTPS_VERIFY_ERROR_NO_MEMORY = 0x00000020U,
CELL_HTTPS_VERIFY_ERROR_NOT_VERIFIABLE = 0x00000040U,
CELL_HTTPS_VERIFY_ERROR_INVALID_CERT = 0x00000080U,
CELL_HTTPS_VERIFY_ERROR_BAD_CONSTRAINT = 0x00000100U,
CELL_HTTPS_VERIFY_ERROR_VERIFY_FAILED = 0x00000200U,
CELL_HTTPS_VERIFY_ERROR_COMMON_NAME = 0x00000400U,
CELL_HTTPS_VERIFY_ERROR_EXPIRED = 0x00000800U,
CELL_HTTPS_VERIFY_ERROR_NOT_YET_VALID = 0x00001000U,
};
static constexpr const char* CELL_HTTP_METHOD_OPTIONS = "OPTIONS";
static constexpr const char* CELL_HTTP_METHOD_GET = "GET";
static constexpr const char* CELL_HTTP_METHOD_HEAD = "HEAD";
static constexpr const char* CELL_HTTP_METHOD_POST = "POST";
static constexpr const char* CELL_HTTP_METHOD_PUT = "PUT";
static constexpr const char* CELL_HTTP_METHOD_DELETE = "DELETE";
static constexpr const char* CELL_HTTP_METHOD_TRACE = "TRACE";
typedef u32 CellHttpClientId; //typedef struct CellHttpClient* CellHttpClientId;
typedef u32 CellHttpTransId; //typedef struct CellHttpTransaction* CellHttpTransId;
typedef const void* CellHttpSslId;
using CellHttpAuthenticationCallback = s32(CellHttpTransId transId, vm::cptr<char> realm, vm::cptr<CellHttpUri> uri, vm::ptr<char> username, vm::ptr<char> password, vm::ptr<bool> save, vm::ptr<void> userArg);
using CellHttpTransactionStateCallback = s32(CellHttpTransId transId, s32 state, vm::ptr<void> userArg);
using CellHttpRedirectCallback = s32(CellHttpTransId transId, vm::cptr<CellHttpStatusLine> response, vm::cptr<CellHttpUri> from, vm::cptr<CellHttpUri> to, vm::ptr<void> userArg);
using CellHttpsSslCallback = s32(u32 verifyErr, vm::cpptr<void> sslCerts, s32 certNum, vm::cptr<char> hostname, vm::cptr<void> id, vm::ptr<void> userArg);
using CellHttpCookieSendCallback = s32(CellHttpTransId transId, vm::cptr<CellHttpUri> uri, vm::cptr<char> cookieValue, vm::ptr<void> userArg);
using CellHttpCookieRecvCallback = s32(CellHttpTransId transId, vm::cptr<CellHttpUri> uri, vm::cptr<char> cookieValue, vm::ptr<void> userArg);
struct CellHttpsData
{
vm::bptr<char> ptr;
be_t<u32> size;
};
struct http_manager
{
shared_mutex mtx;
bool initialized = false;
bool cookie_initialized = false;
bool cache_initialized = false;
bool ext_cache_initialized = false;
bool https_initialized = false;
};

View File

@ -38,6 +38,20 @@ void fmt_class_string<CellHttpUtilError>::format(std::string& out, u64 arg)
error_code cellHttpUtilParseUri(vm::ptr<CellHttpUri> uri, vm::cptr<char> str, vm::ptr<void> pool, u32 size, vm::ptr<u32> required)
{
cellHttpUtil.trace("cellHttpUtilParseUri(uri=*0x%x, str=%s, pool=*0x%x, size=%d, required=*0x%x)", uri, str, pool, size, required);
if (!str)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!pool || !uri)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
LUrlParser::clParseURL URL = LUrlParser::clParseURL::ParseURL(str.get_ptr());
if ( URL.IsValid() )
{
@ -127,55 +141,144 @@ error_code cellHttpUtilParseUri(vm::ptr<CellHttpUri> uri, vm::cptr<char> str, vm
error_code cellHttpUtilParseUriPath(vm::ptr<CellHttpUriPath> path, vm::cptr<char> str, vm::ptr<void> pool, u32 size, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilParseUriPath(path=*0x%x, str=%s, pool=*0x%x, size=%d, required=*0x%x)", path, str, pool, size, required);
if (!str)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!pool || !path)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpUtilParseProxy(vm::ptr<CellHttpUri> uri, vm::cptr<char> str, vm::ptr<void> pool, u32 size, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilParseProxy(uri=*0x%x, str=%s, pool=*0x%x, size=%d, required=*0x%x)", uri, str, pool, size, required);
if (!str)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!pool || !uri)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpUtilParseStatusLine(vm::ptr<CellHttpStatusLine> resp, vm::cptr<char> str, u32 len, vm::ptr<void> pool, u32 size, vm::ptr<u32> required, vm::ptr<u32> parsedLength)
{
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);
if (!str)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!pool || !resp)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpUtilParseHeader(vm::ptr<CellHttpHeader> header, vm::cptr<char> str, u32 len, vm::ptr<void> pool, u32 size, vm::ptr<u32> required, vm::ptr<u32> parsedLength)
{
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);
if (!str)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!pool || !header)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpUtilBuildRequestLine(vm::cptr<CellHttpRequestLine> req, vm::ptr<char> buf, u32 len, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilBuildRequestLine(req=*0x%x, buf=*0x%x, len=%d, required=*0x%x)", req, buf, len, required);
cellHttpUtil.notice("cellHttpUtilBuildRequestLine(req=*0x%x, buf=*0x%x, len=%d, required=*0x%x)", req, buf, len, required);
if (!req->method || !req->path || !req->protocol) {
if (!req || !req->method || !req->path || !req->protocol)
{
return CELL_HTTP_UTIL_ERROR_INVALID_REQUEST;
}
// TODO
std::string path = fmt::format("%s", req->path);
if (path.empty())
{
path = "/";
}
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);
// TODO: are the numbers properly formatted ?
const std::string result = fmt::format("%s %s %s/%d.%d\r\n", req->method, path, req->protocol, req->majorVersion, req->minorVersion);
if (buf)
{
if (len < result.size())
{
return CELL_HTTP_UTIL_ERROR_INSUFFICIENT;
}
std::memcpy(buf.get_ptr(), result.c_str(), result.size());
}
if (required)
{
*required = result.size();
}
return CELL_OK;
}
error_code cellHttpUtilBuildHeader(vm::cptr<CellHttpHeader> header, vm::ptr<char> buf, u32 len, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilBuildHeader(header=*0x%x, buf=*0x%x, len=%d, required=*0x%x)", header, buf, len, required);
cellHttpUtil.notice("cellHttpUtilBuildHeader(header=*0x%x, buf=*0x%x, len=%d, required=*0x%x)", header, buf, len, required);
if (!header->name || !header->value) {
if (!header || !header->name)
{
return CELL_HTTP_UTIL_ERROR_INVALID_HEADER;
}
// TODO
const std::string result = fmt::format("%s: %s\r\n", header->name, header->value);
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);
if (buf)
{
if (len < result.size())
{
return CELL_HTTP_UTIL_ERROR_INSUFFICIENT;
}
std::memcpy(buf.get_ptr(), result.c_str(), result.size());
}
if (required)
{
*required = result.size();
}
return CELL_OK;
}
@ -184,10 +287,71 @@ error_code cellHttpUtilBuildUri(vm::cptr<CellHttpUri> uri, vm::ptr<char> buf, u3
{
cellHttpUtil.todo("cellHttpUtilBuildUri(uri=*0x%x, buf=*0x%x, len=%d, required=*0x%x, flags=%d)", uri, buf, len, required, flags);
// TODO
if (!uri || !uri->hostname)
{
return CELL_HTTP_UTIL_ERROR_INVALID_URI;
}
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);
std::string result;
if (!(flags & CELL_HTTP_UTIL_URI_FLAG_NO_SCHEME))
{
if (uri->scheme && uri->scheme[0])
{
result = fmt::format("%s", uri->scheme);
}
else if (uri->port == 443u)
{
result = "https"; // TODO: confirm
}
else
{
result = "http"; // TODO: confirm
}
fmt::append(result, "://");
}
if (!(flags & CELL_HTTP_UTIL_URI_FLAG_NO_CREDENTIALS) && uri->username && uri->username[0])
{
fmt::append(result, "%s", uri->username);
if (!(flags & CELL_HTTP_UTIL_URI_FLAG_NO_PASSWORD) && uri->password && uri->password[0])
{
fmt::append(result, ":%s", uri->password);
}
fmt::append(result, "@");
}
fmt::append(result, "%s", uri->hostname);
if (true) // TODO: there seems to be a case where the port isn't added
{
fmt::append(result, ":%d", uri->port);
}
if (!(flags & CELL_HTTP_UTIL_URI_FLAG_NO_PATH) && uri->path && uri->path[0])
{
fmt::append(result, "%s", uri->path);
}
const u32 size_needed = result.size() + 1; // Including '\0'
if (buf)
{
if (len < size_needed)
{
return CELL_HTTP_UTIL_ERROR_INSUFFICIENT;
}
std::memcpy(buf.get_ptr(), result.c_str(), size_needed);
}
if (required)
{
*required = size_needed;
}
return CELL_OK;
}
@ -195,72 +359,469 @@ error_code cellHttpUtilBuildUri(vm::cptr<CellHttpUri> uri, vm::ptr<char> buf, u3
error_code cellHttpUtilCopyUri(vm::ptr<CellHttpUri> dest, vm::cptr<CellHttpUri> src, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilCopyUri(dest=*0x%x, src=*0x%x, pool=*0x%x, poolSize=%d, required=*0x%x)", dest, src, pool, poolSize, required);
if (!src)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
if (!pool || !dest)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpUtilMergeUriPath(vm::ptr<CellHttpUri> uri, vm::cptr<CellHttpUri> src, vm::cptr<char> path, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
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);
if (!path)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!src)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
if (!pool || !uri)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpUtilSweepPath(vm::ptr<char> dst, vm::cptr<char> src, u32 srcSize)
{
cellHttpUtil.todo("cellHttpUtilSweepPath(dst=*0x%x, src=%s, srcSize=%d)", dst, src, srcSize);
if (!dst || !src)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
if (!srcSize)
{
return CELL_OK;
}
u32 pos = 0;
if (src[pos] != '/')
{
std::memcpy(dst.get_ptr(), src.get_ptr(), srcSize - 1);
dst[srcSize - 1] = '\0';
return CELL_OK;
}
// TODO
return CELL_OK;
}
error_code cellHttpUtilCopyStatusLine(vm::ptr<CellHttpStatusLine> dest, vm::cptr<CellHttpStatusLine> src, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilCopyStatusLine(dest=*0x%x, src=*0x%x, pool=*0x%x, poolSize=%d, required=*0x%x)", dest, src, pool, poolSize, required);
if (!src)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
if (!pool || !dest)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpUtilCopyHeader(vm::ptr<CellHttpHeader> dest, vm::cptr<CellHttpHeader> src, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilCopyHeader(dest=*0x%x, src=*0x%x, pool=*0x%x, poolSize=%d, required=*0x%x)", dest, src, pool, poolSize, required);
if (!src)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
if (!pool || !dest)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpUtilAppendHeaderValue(vm::ptr<CellHttpHeader> dest, vm::cptr<CellHttpHeader> src, vm::cptr<char> value, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
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);
if (!src)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
if (!pool || !dest)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpUtilEscapeUri(vm::ptr<char> out, u32 outSize, vm::cptr<u8> in, u32 inSize, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilEscapeUri(out=*0x%x, outSize=%d, in=*0x%x, inSize=%d, required=*0x%x)", out, outSize, in, inSize, required);
if (!in || !inSize)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!out && !required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
u32 size_needed = 0;
u32 out_pos = 0;
s32 rindex = 0;
if (const u32 end = in.addr() + inSize; end && end >= in.addr())
{
rindex = inSize;
}
for (u32 pos = 0; rindex >= 0; rindex--, pos++)
{
char c1 = in[pos];
if (false) // DAT[c1] == '\x03') // TODO
{
size_needed += 3;
if (out)
{
if (outSize < size_needed)
{
return CELL_HTTP_UTIL_ERROR_NO_MEMORY;
}
const char* chars = "0123456789ABCDEF";
out[out_pos++] = '%'; // 0x25
out[out_pos++] = chars[c1 >> 4];
out[out_pos++] = chars[c1 & 0xf];
}
}
else
{
size_needed++;
if (out)
{
if (outSize < size_needed)
{
return CELL_HTTP_UTIL_ERROR_NO_MEMORY;
}
out[out_pos++] = c1;
}
}
}
size_needed++;
if (out)
{
if (outSize < size_needed)
{
return CELL_HTTP_UTIL_ERROR_NO_MEMORY;
}
out[out_pos] = '\0';
}
if (required)
{
*required = size_needed;
}
return CELL_OK;
}
error_code cellHttpUtilUnescapeUri(vm::ptr<u8> out, u32 size, vm::cptr<char> in, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilUnescapeUri(out=*0x%x, size=%d, in=*0x%x, required=*0x%x)", out, size, in, required);
if (!in)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!out && !required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
if (required)
{
*required = 0; // TODO
}
return CELL_OK;
}
error_code cellHttpUtilFormUrlEncode(vm::ptr<char> out, u32 outSize, vm::cptr<u8> in, u32 inSize, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilFormUrlEncode(out=*0x%x, outSize=%d, in=*0x%x, inSize=%d, required=*0x%x)", out, outSize, in, inSize, required);
if (!in || !inSize)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!out && !required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
u32 size_needed = 0;
u32 out_pos = 0;
s32 rindex = 0;
if (const u32 end = in.addr() + inSize; end && end >= in.addr())
{
rindex = inSize;
}
for (u32 pos = 0; rindex >= 0; rindex--, pos++)
{
char c1 = in[pos];
if (c1 == ' ')
{
size_needed++;
if (out)
{
if (outSize < size_needed)
{
return CELL_HTTP_UTIL_ERROR_NO_MEMORY;
}
out[out_pos++] = '+';
}
}
else if (false) // DAT[c1] == '\x03') // TODO
{
size_needed += 3;
if (out)
{
if (outSize < size_needed)
{
return CELL_HTTP_UTIL_ERROR_NO_MEMORY;
}
const char* chars = "0123456789ABCDEF";
out[out_pos++] = '%'; // 0x25
out[out_pos++] = chars[c1 >> 4];
out[out_pos++] = chars[c1 & 0xf];
}
}
else
{
size_needed++;
if (out)
{
if (outSize < size_needed)
{
return CELL_HTTP_UTIL_ERROR_NO_MEMORY;
}
out[out_pos++] = c1;
}
}
}
size_needed++;
if (out)
{
if (outSize < size_needed)
{
return CELL_HTTP_UTIL_ERROR_NO_MEMORY;
}
out[out_pos++] = '\0';
}
if (required)
{
*required = size_needed;
}
return CELL_OK;
}
error_code cellHttpUtilFormUrlDecode(vm::ptr<u8> out, u32 size, vm::cptr<char> in, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilFormUrlDecode(out=*0x%x, size=%d, in=%s, required=*0x%x)", out, size, in, required);
if (!in)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!out && !required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
u32 size_needed = 0;
u32 out_pos = 0;
for (s32 index = 0, pos = 0;; index++)
{
size_needed = index + 1;
char c1 = in[pos++];
if (!c1)
{
break;
}
if (out && (size < size_needed))
{
return CELL_HTTP_UTIL_ERROR_NO_MEMORY;
}
if (c1 == '%')
{
const char c2 = in[pos++];
const char c3 = in[pos++];
if (!c2 || !c3)
{
return CELL_HTTP_UTIL_ERROR_INVALID_URI;
}
const auto FUN_00036710 = [](b8 c)
{
u32 utmp = static_cast<u32>(c);
s32 stmp = utmp - 48;
if (static_cast<u8>(c - 48) > 9)
{
stmp = utmp - 55;
if (static_cast<u8>(c + 191) > 5)
{
stmp = -1;
if (static_cast<u8>(c + 159) < 6)
{
stmp = utmp - 87;
}
}
}
return stmp;
};
const s32 tmp1 = FUN_00036710(c2);
const s32 tmp2 = FUN_00036710(c3);
if (tmp1 < 0 || tmp2 < 0)
{
return CELL_HTTP_UTIL_ERROR_INVALID_URI;
}
if (out)
{
out[out_pos++] = static_cast<char>((tmp1 & 0xffffffff) << 4) + static_cast<char>(tmp2);
}
}
else
{
if (out)
{
out[out_pos++] = (c1 == '+' ? ' ' : c1);
}
}
}
if (out)
{
if (size < size_needed)
{
return CELL_HTTP_UTIL_ERROR_NO_MEMORY;
}
out[out_pos] = '\0';
}
if (required)
{
*required = size_needed;
}
return CELL_OK;
}
error_code cellHttpUtilBase64Encoder(vm::ptr<char> out, vm::cptr<void> input, u32 len)
{
cellHttpUtil.todo("cellHttpUtilBase64Encoder(out=*0x%x, input=*0x%x, len=%d)", out, input, len);
if (!input || !len)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!out)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpUtilBase64Decoder(vm::ptr<char> output, vm::cptr<void> in, u32 len)
{
cellHttpUtil.todo("cellHttpUtilBase64Decoder(output=*0x%x, in=*0x%x, len=%d)", output, in, len);
cellHttpUtil.todo("cellHttpUtilBase64Decoder(output=*0x%x, in=*0x%x, len=%d)", output, in, len);
if (!in)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if ((len & 3) != 0)
{
return CELL_HTTP_UTIL_ERROR_INVALID_LENGTH;
}
if (!output)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
return CELL_OK;
}

View File

@ -70,3 +70,5 @@ struct CellHttpHeader
vm::bcptr<char> name;
vm::bcptr<char> value;
};
error_code cellHttpUtilCopyUri(vm::ptr<CellHttpUri> dest, vm::cptr<CellHttpUri> src, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required);

View File

@ -326,10 +326,10 @@ error_code _cellSslConvertSslVersion()
return CELL_OK;
}
error_code _cellSslIsInitd()
b8 _cellSslIsInitd()
{
UNIMPLEMENTED_FUNC(cellSsl);
return CELL_OK;
return false;
}
error_code _cellSslPemReadPrivateKey()

View File

@ -203,3 +203,5 @@ struct ssl_manager
{
atomic_t<bool> is_init{ false };
};
b8 _cellSslIsInitd();