forked from belek666/Open-PS2-Loader
-
Notifications
You must be signed in to change notification settings - Fork 4
/
httpclient.c
79 lines (64 loc) · 3.32 KB
/
httpclient.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <string.h>
#include <kernel.h>
#include <sifrpc.h>
#include "httpclient.h"
#include "ioman.h"
static SifRpcClientData_t SifRpcClient;
static unsigned char RpcTxBuffer[256] ALIGNED(64);
static unsigned char RpcRxBuffer[64] ALIGNED(64);
int HttpInit(void)
{
while (SifBindRpc(&SifRpcClient, 0x00001B14, 0) < 0 || SifRpcClient.server == NULL) {
LOG("libhttpclient: bind failed\n");
nopdelay();
}
return 0;
}
void HttpDeinit(void)
{
memset(&SifRpcClient, 0, sizeof(SifRpcClientData_t));
}
int HttpEstabConnection(s8 *server, u16 port)
{
int result;
strncpy(((struct HttpClientConnEstabArgs *)RpcTxBuffer)->server, server, HTTP_CLIENT_SERVER_NAME_MAX - 1);
((struct HttpClientConnEstabArgs *)RpcTxBuffer)->server[HTTP_CLIENT_SERVER_NAME_MAX - 1] = '\0';
((struct HttpClientConnEstabArgs *)RpcTxBuffer)->port = port;
if ((result = SifCallRpc(&SifRpcClient, HTTP_CLIENT_CMD_CONN_ESTAB, 0, RpcTxBuffer, sizeof(struct HttpClientConnEstabArgs), RpcRxBuffer, sizeof(s32), NULL, NULL)) >= 0)
result = *(s32 *)RpcRxBuffer;
return result;
}
void HttpCloseConnection(s32 HttpSocket)
{
((struct HttpClientConnCloseArgs *)RpcTxBuffer)->socket = HttpSocket;
SifCallRpc(&SifRpcClient, HTTP_CLIENT_CMD_CONN_CLOSE, 0, RpcTxBuffer, sizeof(struct HttpClientConnCloseArgs), NULL, 0, NULL, NULL);
}
int HttpSendGetRequest(s32 HttpSocket, const s8 *UserAgent, const s8 *host, s8 *mode, const u8 *mtime, const s8 *uri, u8 *output, u16 *out_len)
{
int result;
((struct HttpClientSendGetArgs *)RpcTxBuffer)->socket = HttpSocket;
strncpy(((struct HttpClientSendGetArgs *)RpcTxBuffer)->UserAgent, UserAgent, HTTP_CLIENT_USER_AGENT_MAX - 1);
((struct HttpClientSendGetArgs *)RpcTxBuffer)->UserAgent[HTTP_CLIENT_USER_AGENT_MAX - 1] = '\0';
strncpy(((struct HttpClientSendGetArgs *)RpcTxBuffer)->host, host, HTTP_CLIENT_SERVER_NAME_MAX - 1);
((struct HttpClientSendGetArgs *)RpcTxBuffer)->host[HTTP_CLIENT_SERVER_NAME_MAX - 1] = '\0';
((struct HttpClientSendGetArgs *)RpcTxBuffer)->mode = *mode;
if (mtime != NULL) {
memcpy(((struct HttpClientSendGetArgs *)RpcTxBuffer)->mtime, mtime, sizeof(((struct HttpClientSendGetArgs *)RpcTxBuffer)->mtime));
((struct HttpClientSendGetArgs *)RpcTxBuffer)->hasMtime = 1;
} else {
memset(((struct HttpClientSendGetArgs *)RpcTxBuffer)->mtime, 0, sizeof(((struct HttpClientSendGetArgs *)RpcTxBuffer)->mtime));
((struct HttpClientSendGetArgs *)RpcTxBuffer)->hasMtime = 0;
}
strncpy(((struct HttpClientSendGetArgs *)RpcTxBuffer)->uri, uri, HTTP_CLIENT_URI_MAX - 1);
((struct HttpClientSendGetArgs *)RpcTxBuffer)->uri[HTTP_CLIENT_URI_MAX - 1] = '\0';
((struct HttpClientSendGetArgs *)RpcTxBuffer)->output = output;
((struct HttpClientSendGetArgs *)RpcTxBuffer)->out_len = *out_len;
if (!IS_UNCACHED_SEG(output))
SifWriteBackDCache(output, *out_len);
if ((result = SifCallRpc(&SifRpcClient, HTTP_CLIENT_CMD_SEND_GET_REQ, 0, RpcTxBuffer, sizeof(struct HttpClientSendGetArgs), RpcRxBuffer, sizeof(struct HttpClientSendGetResult), NULL, NULL)) >= 0) {
result = ((struct HttpClientSendGetResult *)RpcRxBuffer)->result;
*mode = ((struct HttpClientSendGetResult *)RpcRxBuffer)->mode;
*out_len = ((struct HttpClientSendGetResult *)RpcRxBuffer)->out_len;
}
return result;
}