Diarkis C++Client Library API Document
http.h
Go to the documentation of this file.
1 // © 2019-2024 Diarkis Inc. All rights reserved.
2 
3 #pragma once
4 
5 #include "diarkis/common.h"
6 #include "diarkis/config.h"
8 #include "diarkis/network/tcp.h"
9 
10 #include "logging/LoggerFactory.h"
11 
12 // Parse a String value in Json response starting from offset.
13 Diarkis::System::Result ParseKeyValue(std::shared_ptr<IDiarkisLogger> logger, const Diarkis::StdString& response, size_t offset, const Diarkis::StdString& key, Diarkis::StdString& value);
14 Diarkis::System::Result ParseKeyValue(std::shared_ptr<IDiarkisLogger> logger, const char* response, size_t offset, const char* key, char* value, size_t valueBufSize);
15 
17  std::shared_ptr<IDiarkisLogger> logger,
18  const Diarkis::StdString& authEndpoint, const char* clientKey, const char* serverType,
19  char* endpoint, size_t endpointBuf, struct AuthInfo* auth
20 );
21 
23  std::shared_ptr<IDiarkisLogger> logger,
24  const char* host, const char* clientKey, const uint64_t& uid, const char* serverType,
25  char* endpoint, size_t endpointBuf, struct AuthInfo* auth
26 );
27 
29  std::shared_ptr<IDiarkisLogger> logger,
30  const char* host, const char* clientKey, const char* uid, const char* serverType,
31  char* endpoint, size_t endpointBuf, struct AuthInfo* auth
32 );
33 
34 bool CheckContentType(Diarkis::StdString headerValue, std::initializer_list<Diarkis::StdString> expected);
35 
36 Diarkis::System::Result TryParse(std::shared_ptr<IDiarkisLogger> logger, const Diarkis::StdString& response,
37  const Diarkis::StdString& serverType, Diarkis::StdString& endpoint, Diarkis::StdVector<uint8_t>& sid,
39 
40 Diarkis::System::Result TryParse(std::shared_ptr<IDiarkisLogger> logger, const char* response, const char* serverType,
41  char* endpoint, size_t endpointBuf, struct AuthInfo* auth);
42 
43 #ifdef DIARKIS_PLATFORM_NINTENDO_SWITCH
44 
45 Diarkis::System::Result FetchAuthInfoNX64(
46  std::shared_ptr<IDiarkisLogger> logger,
47  const Diarkis::StdString& authEndpoint, const char* clientKey, const char* serverType,
48  char* endpoint, size_t endpointBuf, struct AuthInfo* auth
49 );
50 
51 void initNetwork(std::shared_ptr<IDiarkisLogger> logger);
52 
53 void finishNetwork(void);
54 
55 #elif defined(DIARKIS_PLATFORM_PS4)
56 
57 Diarkis::System::Result FetchAuthInfoPS4(
58  std::shared_ptr<IDiarkisLogger> logger,
59  const Diarkis::StdString& authEndpoint, const char* clientKey, const char* serverType,
60  char* endpoint, size_t endpointBuf, struct AuthInfo* auth
61 );
62 
63 void initNetwork(std::shared_ptr<IDiarkisLogger> logger);
64 
65 void finishNetwork(std::shared_ptr<IDiarkisLogger> logger);
66 
67 #elif defined(DIARKIS_PLATFORM_PS5)
68 
69 Diarkis::System::Result FetchAuthInfoPS5(
70  std::shared_ptr<IDiarkisLogger> logger,
71  const Diarkis::StdString& authEndpoint, const char* clientKey, const char* serverType,
72  char* endpoint, size_t endpointBuf, struct AuthInfo* auth
73 );
74 
75 void initNetwork(std::shared_ptr<IDiarkisLogger> logger);
76 
77 void finishNetwork(std::shared_ptr<IDiarkisLogger> logger);
78 
79 #elif defined(DIARKIS_PLATFORM_XBOX_XDK)
80 
81 Diarkis::System::Result FetchAuthInfoXdk(
82  std::shared_ptr<IDiarkisLogger> logger,
83  const char* authEndpoint, const char* clientKey, const char* serverType,
84  char* endpoint, size_t endpointBuf, struct AuthInfo* auth
85 );
86 
87 void initNetwork(std::shared_ptr<IDiarkisLogger> logger);
88 
89 void finishNetwork(std::shared_ptr<IDiarkisLogger> logger);
90 
91 #elif defined(DIARKIS_PLATFORM_ANDROID)
92 
93 Diarkis::System::Result FetchAuthInfoAndroid(
94  std::shared_ptr<IDiarkisLogger> logger,
95  const Diarkis::StdString& authEndpoint, const char* clientKey, const char* serverType,
96  char* endpoint, size_t endpointBuf, struct AuthInfo* auth
97 );
98 
99 #elif defined(DIARKIS_PLATFORM_IOS)
100 
101 Diarkis::System::Result FetchAuthInfoIOS(
102  std::shared_ptr<IDiarkisLogger> logger,
103  const Diarkis::StdString& authEndpoint, const char* clientKey, const char* serverType,
104  char* endpoint, size_t endpointBuf, struct AuthInfo* auth
105 );
106 
107 #endif
Diarkis::System::Result::GetStatusString
const char * GetStatusString() const
Gets a string representation of the status of the result value.
FetchAuthInfo
Result FetchAuthInfo(std::shared_ptr< IDiarkisLogger > logger, const Diarkis::StdString &authEndpoint, const char *clientKey, const char *serverType, char *endpoint, size_t endpointBuf, struct AuthInfo *auth)
Definition: http.cpp:464
Diarkis::Results::Network::Http::CONTENT_TYPE_HEADER_NOT_FOUND
DIARKIS_EXPORT System::Result CONTENT_TYPE_HEADER_NOT_FOUND
The Content-Type header could not be found in the HTTP response. (status: FATAL, value: 0x065627D3)
CheckHttpURL
bool CheckHttpURL(Diarkis::StdString &url)
Definition: http.cpp:285
CreateFolder
bool CreateFolder(Diarkis::StdString absolutePath)
fs.h
ParseKeyValue
Result ParseKeyValue(std::shared_ptr< IDiarkisLogger > logger, const Diarkis::StdString &response, size_t offset, const Diarkis::StdString &key, Diarkis::StdString &value)
Definition: http.cpp:84
Credentials::iv
uint8_t iv[DIARKIS_AUTHKEY_LEN]
Definition: common.h:62
Diarkis::Results
Definition: results.autogen.h:10
Credentials::key
uint8_t key[DIARKIS_AUTHKEY_LEN]
Definition: common.h:61
string.h
CheckContentType
bool CheckContentType(Diarkis::StdString headerValue, std::initializer_list< Diarkis::StdString > expected)
Definition: http.cpp:153
Diarkis::StdString
Definition: common.h:432
HttpAccessType::Get
@ Get
Diarkis::Results::Network::Http::NOT_2XX_STATUS_CODE
DIARKIS_EXPORT System::Result NOT_2XX_STATUS_CODE
Server responded with a status code outside of the 2XX success range. (status: FATAL,...
AuthInfo::cred
struct Credentials cred
Definition: common.h:67
Diarkis::System::Result
Contains information about a specific result value. Can be compared against another Result structure....
Definition: result.h:37
Logger.h
Diarkis::Results::Network::Http::INVALID_RESPONSE_CONTENT
DIARKIS_EXPORT System::Result INVALID_RESPONSE_CONTENT
A required information is missing from the HTTP response content. (status: FATAL, value: 0xFF88DFF3)
Diarkis::StdVector< uint8_t >
HexadecimalStringToByteArray
Result HexadecimalStringToByteArray(const Diarkis::StdString &input, Diarkis::StdVector< uint8_t > &output)
Definition: string.cpp:245
Diarkis::DiarkisLoggerSeverity::Info
@ Info
Displays info, warning, error, and fatal level.
Diarkis::Results::Network::Http::CONTENT_TYPE_NOT_JSON
DIARKIS_EXPORT System::Result CONTENT_TYPE_NOT_JSON
The Content-Type header value is not application/json nor text/json. (status: FATAL,...
AuthInfo::sid
uint8_t sid[DIARKIS_AUTHKEY_LEN]
Definition: common.h:66
ByteArrayToHexadecimalString
Diarkis::StdString ByteArrayToHexadecimalString(const Diarkis::StdVector< uint8_t > &byteArray, Diarkis::StdString spacing)
Definition: string.cpp:329
misc.h
HttpConnect
Result HttpConnect(std::shared_ptr< IDiarkisLogger > logger, const char *host, const char *clientKey, const char *uid, const char *serverType, char *endpoint, size_t endpointBuf, struct AuthInfo *auth)
Definition: http.cpp:492
Diarkis::System
Definition: result.h:11
ParseKeyValue
Diarkis::System::Result ParseKeyValue(std::shared_ptr< IDiarkisLogger > logger, const Diarkis::StdString &response, size_t offset, const Diarkis::StdString &key, Diarkis::StdString &value)
Definition: http.cpp:84
DIARKIS_AUTHKEY_LEN
#define DIARKIS_AUTHKEY_LEN
Definition: common.h:57
DiarkisHttpAccess
Result DiarkisHttpAccess(const std::shared_ptr< IDiarkisLogger > &logger, const Diarkis::StdString &authEndpoint, const Diarkis::StdString &clientKey, HttpAccessType type, const Diarkis::StdString &postRequestBody, const Diarkis::StdString &contentType, Diarkis::StdString &outResult)
Definition: http.cpp:402
FetchAuthInfo
Diarkis::System::Result FetchAuthInfo(std::shared_ptr< IDiarkisLogger > logger, const Diarkis::StdString &authEndpoint, const char *clientKey, const char *serverType, char *endpoint, size_t endpointBuf, struct AuthInfo *auth)
Definition: http.cpp:464
Diarkis
Definition: commands.h:9
Diarkis::Results::Network::Http
Definition: results.autogen.h:150
AuthInfo
Definition: common.h:65
Diarkis::Results::Network::Http::MACKEY_NOT_FOUND
DIARKIS_EXPORT System::Result MACKEY_NOT_FOUND
Could not retrieve the MAC key from HTTP auth response. (status: FATAL, value: 0xB5FF6420)
Diarkis::Results::Network::Http::HTTP_SYSTEM_ERROR
DIARKIS_EXPORT System::Result HTTP_SYSTEM_ERROR
HTTP library error. (status: FATAL, value: 0x5864352D)
result.h
TryParse
Result TryParse(std::shared_ptr< IDiarkisLogger > logger, const Diarkis::StdString &response, const Diarkis::StdString &serverType, Diarkis::StdString &endpoint, Diarkis::StdVector< uint8_t > &sid, Diarkis::StdVector< uint8_t > &key, Diarkis::StdVector< uint8_t > &iv, Diarkis::StdVector< uint8_t > &mackey)
Definition: http.cpp:173
StringFormat
Diarkis::StdString StringFormat(const Diarkis::StdString &format, Args &&... args)
Definition: stringFormat.h:57
Diarkis::Results::Network::Http::KEY_NOT_FOUND
DIARKIS_EXPORT System::Result KEY_NOT_FOUND
Could not retrieve the session key from HTTP auth response. (status: FATAL, value: 0xBB820DA1)
Diarkis::Results::Network::Http::IV_NOT_FOUND
DIARKIS_EXPORT System::Result IV_NOT_FOUND
Could not retrieve the IV from HTTP auth response. (status: FATAL, value: 0x60B44EC5)
common.h
tcp.h
Find
size_t Find(const char *str, const char *subStr, size_t pos)
Definition: string.cpp:391
HttpAccessType::Post
@ Post
std
Definition: common.h:604
Diarkis::Results::Network::MISCELLANEOUS_ERROR
DIARKIS_EXPORT System::Result MISCELLANEOUS_ERROR
FIXME placeholder (status: FATAL, value: 0x681E68DD)
Diarkis::Results::SUCCESS
DIARKIS_EXPORT System::Result SUCCESS
Everything went according to plan. (status: NONE, value: 0)
results.autogen.h
Diarkis::DiarkisLoggerSeverity::Error
@ Error
Displays fatal and error level.
Diarkis::Results::Network::Http::SID_NOT_FOUND
DIARKIS_EXPORT System::Result SID_NOT_FOUND
Could not retrieve the SID from HTTP auth response. (status: FATAL, value: 0x35EEBC5B)
HttpConnect
Diarkis::System::Result HttpConnect(std::shared_ptr< IDiarkisLogger > logger, const char *host, const char *clientKey, const uint64_t &uid, const char *serverType, char *endpoint, size_t endpointBuf, struct AuthInfo *auth)
stringFormat.h
DIARKIS_LOG
#define DIARKIS_LOG(logger, severity,...)
Definition: Logger.h:8
Substr
bool Substr(char *dst, size_t dstSize, const char *src, size_t count)
Definition: string.cpp:402
HttpAccessType
HttpAccessType
Definition: http.cpp:57
Diarkis::Results::General::DESTINATION_BUFFER_TOO_SMALL_ERROR
DIARKIS_EXPORT System::Result DESTINATION_BUFFER_TOO_SMALL_ERROR
The destination buffer is too small. (status: FATAL, value: 0x95582D3C)
CheckContentType
bool CheckContentType(Diarkis::StdString headerValue, std::initializer_list< Diarkis::StdString > expected)
Definition: http.cpp:153
Credentials::mac
uint8_t mac[DIARKIS_AUTHKEY_LEN]
Definition: common.h:63
Diarkis::Results::Network::Http::ENDPOINT_NOT_FOUND
DIARKIS_EXPORT System::Result ENDPOINT_NOT_FOUND
Could not retrieve the UDP endpoint from HTTP auth response. (status: FATAL, value: 0x61D38C8E)
http.h
Diarkis::Results::Network::Http::SERVER_PORT_NOT_FOUND
DIARKIS_EXPORT System::Result SERVER_PORT_NOT_FOUND
Could not retrieve the Server Port from HTTP auth response. (status: FATAL, value: 0xBEEF4BC8)
TryParse
Diarkis::System::Result TryParse(std::shared_ptr< IDiarkisLogger > logger, const Diarkis::StdString &response, const Diarkis::StdString &serverType, Diarkis::StdString &endpoint, Diarkis::StdVector< uint8_t > &sid, Diarkis::StdVector< uint8_t > &key, Diarkis::StdVector< uint8_t > &iv, Diarkis::StdVector< uint8_t > &mackey)
Definition: http.cpp:173