Concord - C Discord API library
A Discord API wrapper library written in C

Store, manage and dispatch individual requests. More...

Collaboration diagram for Request's handling:

Modules

 Ratelimiting
 Enforce ratelimiting per the official Discord Documentation.
 

Data Structures

struct  discord_ret_dispatch
 Generic request dispatcher. More...
 
struct  discord_ret_response
 Attributes of response datatype. More...
 
struct  discord_attributes
 Request to be performed. More...
 
struct  discord_request
 Individual requests that are scheduled to run asynchronously. More...
 
struct  discord_requestor
 The handle used for handling asynchronous requests. More...
 

Macros

#define DISCORD_ATTRIBUTES_FIELDS
 Macro containing discord_attributes fields. More...
 

Functions

void discord_requestor_init (struct discord_requestor *rqtor, struct logconf *conf, const char token[])
 Initialize the request handler. More...
 
void discord_requestor_cleanup (struct discord_requestor *rqtor)
 Free the request handler. More...
 
CCORDcode discord_requestor_start_pending (struct discord_requestor *rqtor)
 Check for and start pending bucket's requests. More...
 
CCORDcode discord_requestor_info_read (struct discord_requestor *rqtor)
 Poll for request's completion. More...
 
void discord_requestor_dispatch_responses (struct discord_requestor *rqtor)
 Run pending callbacks from completed requests. More...
 
void discord_request_cancel (struct discord_requestor *rqtor, struct discord_request *req)
 Mark request as canceled and move it to the recycling queue. More...
 
CCORDcode discord_request_begin (struct discord_requestor *rqtor, struct discord_attributes *req, struct ccord_szbuf *body, enum http_method method, char endpoint[512], char key[256])
 Begin a new request. More...
 

Detailed Description

Store, manage and dispatch individual requests.

Macro Definition Documentation

◆ DISCORD_ATTRIBUTES_FIELDS

#define DISCORD_ATTRIBUTES_FIELDS
Value:
\
struct discord_ret_dispatch dispatch; \ \
struct discord_ret_response response; \ \
struct discord_attachments attachments; \ \
char *reason
Definition: channel.h:393
Generic request dispatcher.
Definition: discord-internal.h:379
Attributes of response datatype.
Definition: discord-internal.h:404

Macro containing discord_attributes fields.

Note
this exists for discord_request alignment purposes

Function Documentation

◆ discord_requestor_init()

void discord_requestor_init ( struct discord_requestor rqtor,
struct logconf conf,
const char  token[] 
)

Initialize the request handler.

This shall initialize a CURLM multi handle for performing requests asynchronously, and a queue for storing individual requests

Parameters
rqtorthe requestor handle to be initialized
confpointer to discord_rest logging module
tokenthe bot token

◆ discord_requestor_cleanup()

void discord_requestor_cleanup ( struct discord_requestor rqtor)

Free the request handler.

Parameters
rqtorthe handle initialized with discord_requestor_init()

◆ discord_requestor_start_pending()

CCORDcode discord_requestor_start_pending ( struct discord_requestor rqtor)

Check for and start pending bucket's requests.

Parameters
rqtorthe handle initialized with discord_requestor_init()
Returns
CCORDcode value for how the operation went, CCORD_OK means nothing out of the ordinary

◆ discord_requestor_info_read()

CCORDcode discord_requestor_info_read ( struct discord_requestor rqtor)

Poll for request's completion.

Parameters
rqtorthe handle initialized with discord_requestor_init()
Returns
CCORDcode value for how the operation went, CCORD_OK means nothing out of the ordinary

◆ discord_requestor_dispatch_responses()

void discord_requestor_dispatch_responses ( struct discord_requestor rqtor)

Run pending callbacks from completed requests.

Parameters
reqthe request containing preliminary information for its dispatch

◆ discord_request_cancel()

void discord_request_cancel ( struct discord_requestor rqtor,
struct discord_request req 
)

Mark request as canceled and move it to the recycling queue.

Parameters
rqtorthe requestor handle initialized with discord_requestor_init()
reqthe on-going request to be canceled

◆ discord_request_begin()

CCORDcode discord_request_begin ( struct discord_requestor rqtor,
struct discord_attributes req,
struct ccord_szbuf body,
enum http_method  method,
char  endpoint[512],
char  key[256] 
)

Begin a new request.

The returned request automatically be performed from the REST thread

Parameters
rqtorthe requestor handle initialized with discord_requestor_init()
reqthe request containing preliminary information for its dispatch and response's parsing
bodythe request's body
methodthe request's HTTP method
endpointthe request's endpoint
keythe request bucket's group for ratelimiting
Returns
CCORDcode value for how the operation went, CCORD_OK means nothing out of the ordinary