Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/dep/rcheevos/include/rc_api_request.h
4246 views
1
#ifndef RC_API_REQUEST_H
2
#define RC_API_REQUEST_H
3
4
#include "rc_error.h"
5
#include "rc_util.h"
6
7
#include <stddef.h>
8
9
RC_BEGIN_C_DECLS
10
11
/**
12
* Information about the server being connected to.
13
*/
14
typedef struct rc_api_host_t {
15
/* The host name for the API calls (retroachievements.org) */
16
const char* host;
17
/* The host name for media URLs (media.retroachievements.org) */
18
const char* media_host;
19
}
20
rc_api_host_t;
21
22
/**
23
* A constructed request to send to the retroachievements server.
24
*/
25
typedef struct rc_api_request_t {
26
/* The URL to send the request to (contains protocol, host, path, and query args) */
27
const char* url;
28
/* Additional query args that should be sent via a POST command. If null, GET may be used */
29
const char* post_data;
30
/* The HTTP Content-Type of the POST data. */
31
const char* content_type;
32
33
/* Storage for the url and post_data */
34
rc_buffer_t buffer;
35
}
36
rc_api_request_t;
37
38
/**
39
* Common attributes for all server responses.
40
*/
41
typedef struct rc_api_response_t {
42
/* Server-provided success indicator (non-zero on success, zero on failure) */
43
int succeeded;
44
/* Server-provided message associated to the failure */
45
const char* error_message;
46
/* Server-provided error code associated to the failure */
47
const char* error_code;
48
49
/* Storage for the response data */
50
rc_buffer_t buffer;
51
}
52
rc_api_response_t;
53
54
RC_EXPORT void RC_CCONV rc_api_destroy_request(rc_api_request_t* request);
55
56
/* [deprecated] use rc_api_init_*_hosted instead */
57
RC_EXPORT void RC_CCONV rc_api_set_host(const char* hostname);
58
/* [deprecated] use rc_api_init_*_hosted instead */
59
RC_EXPORT void RC_CCONV rc_api_set_image_host(const char* hostname);
60
61
typedef struct rc_api_server_response_t {
62
/* Pointer to the data returned from the server */
63
const char* body;
64
/* Length of data returned from the server (Content-Length) */
65
size_t body_length;
66
/* HTTP status code returned from the server */
67
int http_status_code;
68
} rc_api_server_response_t;
69
70
enum {
71
RC_API_SERVER_RESPONSE_CLIENT_ERROR = -1,
72
RC_API_SERVER_RESPONSE_RETRYABLE_CLIENT_ERROR = -2
73
};
74
75
RC_END_C_DECLS
76
77
#endif /* RC_API_REQUEST_H */
78
79