mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-21 11:26:56 +02:00
+54
-21
@@ -654,6 +654,8 @@ namespace LibHttp2 {
|
|||||||
LIB_VERSION("Http2", 1, "Http2", 1, 1);
|
LIB_VERSION("Http2", 1, "Http2", 1, 1);
|
||||||
|
|
||||||
constexpr int HTTP2_ERROR_INVALID_ID = -2122641152; /* 0x817B1100 */
|
constexpr int HTTP2_ERROR_INVALID_ID = -2122641152; /* 0x817B1100 */
|
||||||
|
constexpr int HTTP2_ERROR_BEFORE_SEND = -2122641307; /* 0x817B1065 */
|
||||||
|
constexpr int HTTP2_ERROR_TIMEOUT = -2122641304; /* 0x817B1068 */
|
||||||
constexpr int HTTP2_ERROR_NULL_POINTER = -2122640859; /* 0x817B1225 */
|
constexpr int HTTP2_ERROR_NULL_POINTER = -2122640859; /* 0x817B1225 */
|
||||||
|
|
||||||
struct Http2Options {
|
struct Http2Options {
|
||||||
@@ -694,14 +696,14 @@ struct Http2Request {
|
|||||||
std::string url;
|
std::string url;
|
||||||
uint64_t content_length = 0;
|
uint64_t content_length = 0;
|
||||||
std::vector<std::pair<std::string, std::string>> headers;
|
std::vector<std::pair<std::string, std::string>> headers;
|
||||||
bool sent = false;
|
int send_result = HTTP2_ERROR_BEFORE_SEND;
|
||||||
int status_code = 204;
|
int status_code = 0;
|
||||||
std::string response_headers = "HTTP/2 204 No Content\r\n\r\n";
|
std::string response_headers;
|
||||||
std::string response_body;
|
std::string response_body;
|
||||||
size_t read_offset = 0;
|
size_t read_offset = 0;
|
||||||
int async_result = 0;
|
int async_result = HTTP2_ERROR_BEFORE_SEND;
|
||||||
int async_event = 0;
|
int async_event = 0;
|
||||||
Http2Options options;
|
Http2Options options;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Http2AsyncResult {
|
struct Http2AsyncResult {
|
||||||
@@ -1114,9 +1116,9 @@ static int KYTY_SYSV_ABI Http2SendRequest(int req_id, const void* post_data, siz
|
|||||||
return HTTP2_ERROR_INVALID_ID;
|
return HTTP2_ERROR_INVALID_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
request->second.sent = true;
|
request->second.send_result = HTTP2_ERROR_TIMEOUT;
|
||||||
|
|
||||||
return 0;
|
return request->second.send_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int KYTY_SYSV_ABI Http2SendRequestAsync(int req_id, const void* post_data, size_t size,
|
static int KYTY_SYSV_ABI Http2SendRequestAsync(int req_id, const void* post_data, size_t size,
|
||||||
@@ -1136,8 +1138,8 @@ static int KYTY_SYSV_ABI Http2SendRequestAsync(int req_id, const void* post_data
|
|||||||
return HTTP2_ERROR_INVALID_ID;
|
return HTTP2_ERROR_INVALID_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
request->second.sent = true;
|
request->second.send_result = HTTP2_ERROR_TIMEOUT;
|
||||||
request->second.async_result = 0;
|
request->second.async_result = request->second.send_result;
|
||||||
request->second.async_event = 0;
|
request->second.async_event = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1159,11 +1161,10 @@ static int KYTY_SYSV_ABI Http2WaitAsync(int req_id, Http2AsyncResult* result, ui
|
|||||||
return HTTP2_ERROR_INVALID_ID;
|
return HTTP2_ERROR_INVALID_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
request->second.sent = true;
|
*result = {};
|
||||||
*result = {};
|
result->event_type = request->second.async_event;
|
||||||
result->event_type = request->second.async_event;
|
result->req_id = req_id;
|
||||||
result->req_id = req_id;
|
result->result = request->second.async_result;
|
||||||
result->result = request->second.async_result;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1178,13 +1179,19 @@ static int KYTY_SYSV_ABI Http2GetStatusCode(int req_id, int* status_code) {
|
|||||||
return HTTP2_ERROR_NULL_POINTER;
|
return HTTP2_ERROR_NULL_POINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*status_code = 0;
|
||||||
|
|
||||||
auto request = g_http2_requests.find(req_id);
|
auto request = g_http2_requests.find(req_id);
|
||||||
if (request == g_http2_requests.end()) {
|
if (request == g_http2_requests.end()) {
|
||||||
return HTTP2_ERROR_INVALID_ID;
|
return HTTP2_ERROR_INVALID_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
*status_code = request->second.status_code;
|
const int send_result = request->second.send_result;
|
||||||
|
if (send_result != 0) {
|
||||||
|
return send_result;
|
||||||
|
}
|
||||||
|
|
||||||
|
*status_code = request->second.status_code;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1200,14 +1207,21 @@ static int KYTY_SYSV_ABI Http2GetResponseContentLength(int req_id, int* result,
|
|||||||
return HTTP2_ERROR_NULL_POINTER;
|
return HTTP2_ERROR_NULL_POINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*result = 0;
|
||||||
|
*content_length = 0;
|
||||||
|
|
||||||
auto request = g_http2_requests.find(req_id);
|
auto request = g_http2_requests.find(req_id);
|
||||||
if (request == g_http2_requests.end()) {
|
if (request == g_http2_requests.end()) {
|
||||||
return HTTP2_ERROR_INVALID_ID;
|
return HTTP2_ERROR_INVALID_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
*result = 0; // SCE_HTTP2_CONTENTLEN_EXIST
|
const int send_result = request->second.send_result;
|
||||||
*content_length = request->second.response_body.size();
|
if (send_result != 0) {
|
||||||
|
*result = -1;
|
||||||
|
return send_result;
|
||||||
|
}
|
||||||
|
|
||||||
|
*content_length = request->second.response_body.size();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1223,14 +1237,21 @@ static int KYTY_SYSV_ABI Http2GetAllResponseHeaders(int req_id, char** header,
|
|||||||
return HTTP2_ERROR_NULL_POINTER;
|
return HTTP2_ERROR_NULL_POINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*header = nullptr;
|
||||||
|
*header_size = 0;
|
||||||
|
|
||||||
auto request = g_http2_requests.find(req_id);
|
auto request = g_http2_requests.find(req_id);
|
||||||
if (request == g_http2_requests.end()) {
|
if (request == g_http2_requests.end()) {
|
||||||
return HTTP2_ERROR_INVALID_ID;
|
return HTTP2_ERROR_INVALID_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int send_result = request->second.send_result;
|
||||||
|
if (send_result != 0) {
|
||||||
|
return send_result;
|
||||||
|
}
|
||||||
|
|
||||||
*header = const_cast<char*>(request->second.response_headers.c_str());
|
*header = const_cast<char*>(request->second.response_headers.c_str());
|
||||||
*header_size = request->second.response_headers.size();
|
*header_size = request->second.response_headers.size();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1250,6 +1271,11 @@ static int KYTY_SYSV_ABI Http2ReadData(int req_id, void* data, size_t size) {
|
|||||||
return HTTP2_ERROR_INVALID_ID;
|
return HTTP2_ERROR_INVALID_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int send_result = request->second.send_result;
|
||||||
|
if (send_result != 0) {
|
||||||
|
return send_result;
|
||||||
|
}
|
||||||
|
|
||||||
const auto& body = request->second.response_body;
|
const auto& body = request->second.response_body;
|
||||||
const auto remaining =
|
const auto remaining =
|
||||||
request->second.read_offset < body.size() ? body.size() - request->second.read_offset : 0;
|
request->second.read_offset < body.size() ? body.size() - request->second.read_offset : 0;
|
||||||
@@ -1280,6 +1306,13 @@ static int KYTY_SYSV_ABI Http2ReadDataAsync(int req_id, void* data, size_t size,
|
|||||||
return HTTP2_ERROR_INVALID_ID;
|
return HTTP2_ERROR_INVALID_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int send_result = request->second.send_result;
|
||||||
|
if (send_result != 0) {
|
||||||
|
request->second.async_result = send_result;
|
||||||
|
request->second.async_event = 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const auto& body = request->second.response_body;
|
const auto& body = request->second.response_body;
|
||||||
const auto remaining =
|
const auto remaining =
|
||||||
request->second.read_offset < body.size() ? body.size() - request->second.read_offset : 0;
|
request->second.read_offset < body.size() ? body.size() - request->second.read_offset : 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user