Duckstation/dep/rcheevos/include/rc_api_request.h

65 lines
1.7 KiB
C
Raw Normal View History

2022-07-18 12:46:12 +00:00
#ifndef RC_API_REQUEST_H
#define RC_API_REQUEST_H
#include "rc_error.h"
2023-11-06 09:41:10 +00:00
#include "../src/rc_util.h"
2022-07-18 12:46:12 +00:00
#include <stddef.h>
2024-01-13 04:24:04 +00:00
RC_BEGIN_C_DECLS
2022-07-18 12:46:12 +00:00
/**
* A constructed request to send to the retroachievements server.
*/
typedef struct rc_api_request_t {
/* The URL to send the request to (contains protocol, host, path, and query args) */
const char* url;
/* Additional query args that should be sent via a POST command. If null, GET may be used */
const char* post_data;
/* The HTTP Content-Type of the POST data. */
const char* content_type;
2022-07-18 12:46:12 +00:00
/* Storage for the url and post_data */
2023-11-06 09:41:10 +00:00
rc_buffer_t buffer;
2022-07-18 12:46:12 +00:00
}
rc_api_request_t;
/**
* Common attributes for all server responses.
*/
typedef struct rc_api_response_t {
/* Server-provided success indicator (non-zero on success, zero on failure) */
2022-07-18 12:46:12 +00:00
int succeeded;
/* Server-provided message associated to the failure */
const char* error_message;
2023-11-06 09:41:10 +00:00
/* Server-provided error code associated to the failure */
const char* error_code;
2022-07-18 12:46:12 +00:00
/* Storage for the response data */
2023-11-06 09:41:10 +00:00
rc_buffer_t buffer;
2022-07-18 12:46:12 +00:00
}
rc_api_response_t;
2024-01-13 04:24:04 +00:00
RC_EXPORT void RC_CCONV rc_api_destroy_request(rc_api_request_t* request);
2022-07-18 12:46:12 +00:00
2024-01-13 04:24:04 +00:00
RC_EXPORT void RC_CCONV rc_api_set_host(const char* hostname);
RC_EXPORT void RC_CCONV rc_api_set_image_host(const char* hostname);
2022-07-18 12:46:12 +00:00
typedef struct rc_api_server_response_t {
/* Pointer to the data returned from the server */
const char* body;
/* Length of data returned from the server (Content-Length) */
size_t body_length;
/* HTTP status code returned from the server */
int http_status_code;
} rc_api_server_response_t;
2023-11-06 09:41:10 +00:00
enum {
RC_API_SERVER_RESPONSE_CLIENT_ERROR = -1,
RC_API_SERVER_RESPONSE_RETRYABLE_CLIENT_ERROR = -2
};
2024-01-13 04:24:04 +00:00
RC_END_C_DECLS
2022-07-18 12:46:12 +00:00
#endif /* RC_API_REQUEST_H */