File: rc_api_request.h

package info (click to toggle)
rcheevos 11.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,092 kB
  • sloc: ansic: 66,545; makefile: 516
file content (64 lines) | stat: -rw-r--r-- 1,743 bytes parent folder | download | duplicates (3)
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
#ifndef RC_API_REQUEST_H
#define RC_API_REQUEST_H

#include "rc_error.h"
#include "rc_util.h"

#include <stddef.h>

RC_BEGIN_C_DECLS

/**
 * 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;

  /* Storage for the url and post_data */
  rc_buffer_t buffer;
}
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) */
  int succeeded;
  /* Server-provided message associated to the failure */
  const char* error_message;
  /* Server-provided error code associated to the failure */
  const char* error_code;

  /* Storage for the response data */
  rc_buffer_t buffer;
}
rc_api_response_t;

RC_EXPORT void RC_CCONV rc_api_destroy_request(rc_api_request_t* request);

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);

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;

enum {
  RC_API_SERVER_RESPONSE_CLIENT_ERROR = -1,
  RC_API_SERVER_RESPONSE_RETRYABLE_CLIENT_ERROR = -2
};

RC_END_C_DECLS

#endif /* RC_API_REQUEST_H */