Concord - C Discord API library
A Discord API wrapper library written in C
discord-internal.h
Go to the documentation of this file.
1
8#ifndef DISCORD_INTERNAL_H
9#define DISCORD_INTERNAL_H
10
11#ifdef __cplusplus
12extern "C" {
13#endif /* __cplusplus */
14
15#include <pthread.h>
16
17#define JSONB_HEADER
18#include "json-build.h"
19#define JSMN_STRICT
20#define JSMN_HEADER
21#include "jsmn.h"
22#include "jsmn-find.h"
23
24#include "logconf.h"
25#include "user-agent.h"
26#include "websockets.h"
27#include "cog-utils.h"
28#include "io_poller.h"
29#include "queue.h"
30#include "priority_queue.h"
31#include "attributes.h"
32
34#define NOT_EMPTY_STR(str) ((str) && *(str))
42#define CONTAINEROF(ptr, type, path) \
43 ((type *)((char *)(ptr)-offsetof(type, path)))
44
50#define CLIENT(ptr, path) CONTAINEROF(ptr, struct discord, path)
51
61#define CCORD_EXPECT(client, expect, code, reason) \
62 do { \
63 if (!(expect)) { \
64 logconf_error(&(client)->conf, "Expected: " #expect ": " reason); \
65 return code; \
66 } \
67 } while (0)
68
76#define ASSERT_NOT_OOB(nbytes, destsz) \
77 ASSERT_S((size_t)nbytes < (size_t)destsz, "Out of bounds write attempt");
78
80#define DISCORD_ENDPT_LEN 512
82#define DISCORD_ROUTE_LEN 256
83
90 struct io_poller *io;
91 struct {
93 pthread_t thread;
97 pthread_mutex_t lock;
98 pthread_cond_t cond;
99};
100
106void discord_timers_init(struct discord_timers *timers, struct io_poller *io);
107
114void discord_timers_cleanup(struct discord *client,
115 struct discord_timers *timers);
116
126int64_t discord_timers_get_next_trigger(struct discord_timers *const timers[],
127 size_t n,
128 int64_t now,
129 int64_t max_time);
130
137void discord_timers_run(struct discord *client, struct discord_timers *timers);
138
147unsigned _discord_timer_ctl(struct discord *client,
148 struct discord_timers *timers,
149 struct discord_timer *timer);
150
158unsigned discord_internal_timer_ctl(struct discord *client,
159 struct discord_timer *timer);
160
174unsigned discord_internal_timer(struct discord *client,
175 discord_ev_timer on_tick_cb,
176 discord_ev_timer on_status_changed_cb,
177 void *data,
178 int64_t delay);
179
198#define DISCORD_BUCKET_TIMEOUT (void *)(0xf)
199
206 struct logconf conf;
215 struct _discord_route *routes;
222
223 /* client-wide global ratelimiting */
225
227 struct {
229 QUEUE(struct discord_bucket) pending;
231};
232
241 struct logconf *conf);
242
250
260void discord_ratelimiter_build_key(enum http_method method,
261 char key[DISCORD_ROUTE_LEN],
262 const char endpoint_fmt[],
263 va_list args);
264
275 struct discord_bucket *bucket,
276 const char key[],
277 struct ua_info *info);
278
288 struct discord_bucket *bucket,
289 u64unix_ms wait_ms);
290
294 char hash[64];
296 long limit;
301
307
309 struct {
311 QUEUE(struct discord_request) next;
315};
316
324 u64unix_ms wait_ms);
325
334 const char key[]);
335
346 struct discord_bucket *b,
347 struct discord_request *req,
348 bool high_priority);
349
360 struct discord_ratelimiter *rl,
361 void *data,
362 void (*iter)(void *data, struct discord_request *req));
363
373 struct discord_bucket *b,
374 struct discord_request *req);
375
383
389 union {
390 void (*typed)(struct discord *client,
391 struct discord_response *resp,
392 const void *ret);
393 void (*typeless)(struct discord *client,
394 struct discord_response *resp);
396
400 void *sync;
401};
402
406 void *data;
408 size_t size;
410 void (*init)(void *data);
412 size_t (*from_json)(const char *json, size_t len, void *data);
414 void (*cleanup)(void *data);
415};
416
421#define DISCORD_ATTRIBUTES_FIELDS \
422 \
423 struct discord_ret_dispatch dispatch; \
424 \
425 struct discord_ret_response response; \
426 \
427 struct discord_attachments attachments; \
428 \
430 char *reason
431
435};
436
445
447 struct discord_bucket *b;
451 enum http_method method;
457 struct ua_conn *conn;
461 int retry_attempt;
463 pthread_cond_t *cond;
465 QUEUE entry;
466};
467
469struct discord_requestor {
471 struct logconf conf;
473 struct user_agent *ua;
475 CURLM *mhandle;
478
480 int retry_limit;
481
483 struct {
493 } * queues;
494
496 struct {
498 pthread_mutex_t recycling;
500 pthread_mutex_t pending;
502 pthread_mutex_t finished;
503 } * qlocks;
504};
505
516 struct logconf *conf,
517 const char token[]);
518
525
533
541
548
556 struct discord_request *req);
557
572 struct discord_attributes *req,
573 struct ccord_szbuf *body,
574 enum http_method method,
575 char endpoint[DISCORD_ENDPT_LEN],
576 char key[DISCORD_ROUTE_LEN]);
577
586struct discord_rest {
588 struct logconf conf;
592 struct discord_timers timers;
594 struct io_poller *io_poller;
596 struct threadpool_t *tpool;
597};
598
607void discord_rest_init(struct discord_rest *rest,
608 struct logconf *conf,
609 const char token[]);
610
616void discord_rest_cleanup(struct discord_rest *rest);
617
634 struct discord_attributes *req,
635 struct ccord_szbuf *body,
636 enum http_method method,
637 char endpoint_fmt[],
638 ...) PRINTF_LIKE(5, 6);
639
646void discord_rest_stop_buckets(struct discord_rest *rest);
647
658#define DISCORD_SESSION_OFFLINE 0u
660#define DISCORD_SESSION_RESUMABLE 1u << 0
662#define DISCORD_SESSION_SHUTDOWN 1u << 1
668 bool is_ready;
670 char id[64];
672 int shards;
674 char base_url[256];
676 char resume_url[256];
680 int concurrent;
682 int event_count;
684 unsigned status;
685
687 struct {
689 bool enable;
691 int attempt;
693 int limit;
694 } retry;
695};
696
700 struct {
702 char *start;
704 size_t size;
708 unsigned ntokens;
710 jsmnf_pair *pairs;
712 unsigned npairs;
713 } json;
714
718 int seq;
720 char name[32];
724 jsmnf_pair *data;
725};
726
728typedef void (*discord_ev_event)(struct discord *client, const void *event);
730typedef void (*discord_ev_message)(struct discord *client,
731 const struct discord_message *event);
732
734struct discord_gateway {
736 struct logconf conf;
738 struct websockets *ws;
740 CURLM *mhandle;
741
743 struct {
748 int64_t hbeat_interval;
771 unsigned hbeat_timer;
772
777 int ping_ms;
779 pthread_rwlock_t rwlock;
780 } * timer;
781
783 struct discord_identify id;
784
787
799};
800
810 struct logconf *conf,
811 const char token[]);
812
819
827
835bool discord_gateway_end(struct discord_gateway *gw);
836
844
851
859void discord_gateway_reconnect(struct discord_gateway *gw, bool resume);
860
868 struct discord_identify *event);
869
877 struct discord_resume *event);
878
886
895
905
913 struct discord_gateway *gw, struct discord_presence_update *event);
914
921
935struct discord_refcounter {
937 struct logconf conf;
939 int length;
941 int capacity;
946 struct _discord_ref *refs;
948 pthread_mutex_t *g_lock;
949};
950
959 struct logconf *conf);
960
971 void *data,
972 void (*cleanup)(void *data),
973 bool should_free);
974
985 void *data,
986 void (*cleanup)(struct discord *client,
987 void *data),
988 bool should_free);
989
996
1010 const void *data);
1011
1025 void *data);
1026
1037
1052
1065 struct logconf conf;
1067 struct ccord_szbuf prefix;
1071 int length;
1073 int capacity;
1078 struct _discord_message_commands_entry *entries;
1079};
1080
1088 struct logconf *conf);
1089
1096
1106 struct discord_message_commands *cmds,
1107 const char command[],
1108 size_t length);
1109
1119 const char command[],
1120 size_t length,
1121 discord_ev_message callback);
1122
1134 const char prefix[],
1135 size_t length);
1136
1147 struct discord_message_commands *cmds,
1148 struct discord_gateway_payload *payload);
1149
1160 struct _discord_cache_data *data;
1161 void (*cleanup)(struct discord *client);
1162
1164 void (*on_shard_disconnected)(struct discord *client,
1165 const struct discord_identify *ident,
1166 bool resumable);
1168 void (*on_shard_resumed)(struct discord *client,
1169 const struct discord_identify *ident);
1171 void (*on_shard_reconnected)(struct discord *client,
1172 const struct discord_identify *ident);
1173};
1174
1183struct discord {
1185 struct logconf conf;
1187 bool is_original;
1189 char *token;
1191 struct io_poller *io_poller;
1192
1197
1199 struct discord_rest rest;
1201 struct discord_gateway gw;
1203 struct discord_user self;
1205 struct discord_cache cache;
1206
1207 struct {
1210 } timers;
1211
1213 struct {
1215 void (*cb)(struct discord *client);
1217 unsigned id;
1218 } wakeup_timer;
1219
1221 void (*on_idle)(struct discord *client);
1223 void (*on_cycle)(struct discord *client);
1224
1226 void *data;
1227
1229 struct {
1231 int count;
1233 pthread_mutex_t lock;
1235 pthread_cond_t cond;
1236 } * workers;
1237
1238#ifdef CCORD_VOICE
1239 struct discord_voice *vcs;
1240 struct discord_voice_evcallbacks voice_cbs;
1241#endif /* CCORD_VOICE */
1242};
1243
1246#ifdef __cplusplus
1247}
1248#endif /* __cplusplus */
1249
1250#endif /* DISCORD_INTERNAL_H */
#define PRINTF_LIKE(a, b)
Definition: attributes.h:4
discord_gateway_opcodes
Definition: gateway.h:77
CCORDcode
Definition: error.h:12
uint64_t u64unix_ms
Unix time in milliseconds.
Definition: types.h:22
discord_gateway_events
Discord Gateway's events.
Definition: discord-events.h:65
enum discord_event_scheduler(* discord_ev_scheduler)(struct discord *client, const char data[], size_t size, enum discord_gateway_events event)
Event Handling Mode callback.
Definition: discord-events.h:155
@ DISCORD_EV_MAX
Definition: discord-events.h:129
void(* discord_ev_message)(struct discord *client, const struct discord_message *event)
Definition: discord-internal.h:729
void discord_gateway_reconnect(struct discord_gateway *gw, bool resume)
Gracefully reconnect a ongoing Discord connection over WebSockets.
void discord_gateway_send_update_voice_state(struct discord_gateway *gw, struct discord_update_voice_state *event)
Sent when a client wants to join, move or disconnect from a voice channel.
CCORDcode discord_gateway_start(struct discord_gateway *gw)
Initialize handle with the new session primitives.
void discord_gateway_dispatch(struct discord_gateway *gw)
Dispatch user callback matched to event.
bool discord_gateway_end(struct discord_gateway *gw)
Cleanup and reset gw session primitives.
void discord_gateway_init(struct discord_gateway *gw, struct logconf *conf, const char token[])
Initialize a Gateway handle.
void discord_gateway_shutdown(struct discord_gateway *gw)
Gracefully shutdown a ongoing Discord connection over WebSockets.
CCORDcode discord_gateway_perform(struct discord_gateway *gw)
Check and manage on-going Gateway session.
void discord_gateway_send_resume(struct discord_gateway *gw, struct discord_resume *event)
Replay missed events when a disconnected client resumes.
void discord_gateway_send_request_guild_members(struct discord_gateway *gw, struct discord_request_guild_members *event)
Request all members for a guild or a list of guilds.
void discord_gateway_cleanup(struct discord_gateway *gw)
Free a Gateway handle.
void discord_gateway_send_presence_update(struct discord_gateway *gw, struct discord_presence_update *event)
Send client's presence status update payload.
void discord_gateway_send_heartbeat(struct discord_gateway *gw, int seq)
Maintain an active gateway connection.
void discord_gateway_send_identify(struct discord_gateway *gw, struct discord_identify *event)
Trigger the initial handshake with the gateway.
void(* discord_ev_event)(struct discord *client, const void *event)
Definition: discord-internal.h:727
void discord_message_commands_set_prefix(struct discord_message_commands *cmds, const char prefix[], size_t length)
Set a mandatory prefix before commands.
void discord_message_commands_append(struct discord_message_commands *cmds, const char command[], size_t length, discord_ev_message callback)
Add a new command/callback pair, or update an existing command.
void discord_message_commands_init(struct discord_message_commands *cmds, struct logconf *conf)
Initialize a Message Commands handle.
discord_ev_message discord_message_commands_find(struct discord_message_commands *cmds, const char command[], size_t length)
Search for a callback matching the command.
bool discord_message_commands_try_perform(struct discord_message_commands *cmds, struct discord_gateway_payload *payload)
Read the current DISCORD_EV_MESSAGE_CREATE payload and attempt to perform its matching callback.
void discord_message_commands_cleanup(struct discord_message_commands *cmds)
Free a Message Commands handle.
void discord_ratelimiter_set_global_timeout(struct discord_ratelimiter *rl, struct discord_bucket *bucket, u64unix_ms wait_ms)
Update global ratelimiting value.
void discord_ratelimiter_init(struct discord_ratelimiter *rl, struct logconf *conf)
Initialize ratelimiter handle.
void discord_ratelimiter_build(struct discord_ratelimiter *rl, struct discord_bucket *bucket, const char key[], struct ua_info *info)
Update the bucket with response header data.
void discord_ratelimiter_build_key(enum http_method method, char key[256], const char endpoint_fmt[], va_list args)
Build unique key formed from the HTTP method and endpoint.
void discord_bucket_request_unselect(struct discord_ratelimiter *rl, struct discord_bucket *b, struct discord_request *req)
Unselect a request provided at discord_ratelimiter_request_selector()
void discord_bucket_insert(struct discord_ratelimiter *rl, struct discord_bucket *b, struct discord_request *req, bool high_priority)
Insert into bucket's next requests queue.
void discord_ratelimiter_cleanup(struct discord_ratelimiter *rl)
Cleanup all buckets that have been discovered.
void discord_bucket_set_timeout(struct discord_bucket *bucket, u64unix_ms wait_ms)
Set bucket timeout.
struct discord_bucket * discord_bucket_get(struct discord_ratelimiter *rl, const char key[])
Get a struct discord_bucket assigned to key
void discord_bucket_request_selector(struct discord_ratelimiter *rl, void *data, void(*iter)(void *data, struct discord_request *req))
Iterate and select next requests.
void discord_requestor_dispatch_responses(struct discord_requestor *rqtor)
Run pending callbacks from completed requests.
CCORDcode discord_requestor_start_pending(struct discord_requestor *rqtor)
Check for and start pending bucket's requests.
#define DISCORD_ATTRIBUTES_FIELDS
Macro containing discord_attributes fields.
Definition: discord-internal.h:421
CCORDcode discord_requestor_info_read(struct discord_requestor *rqtor)
Poll for request's completion.
void discord_request_cancel(struct discord_requestor *rqtor, struct discord_request *req)
Mark request as canceled and move it to the recycling queue.
void discord_requestor_cleanup(struct discord_requestor *rqtor)
Free the request handler.
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.
void discord_requestor_init(struct discord_requestor *rqtor, struct logconf *conf, const char token[])
Initialize the request handler.
CCORDcode discord_rest_run(struct discord_rest *rest, struct discord_attributes *req, struct ccord_szbuf *body, enum http_method method, char endpoint_fmt[],...) PRINTF_LIKE(5
Perform a request to Discord.
void discord_rest_cleanup(struct discord_rest *rest)
Free an REST handle.
CCORDcode void discord_rest_stop_buckets(struct discord_rest *rest)
Stop all bucket's on-going, pending and timed-out requests.
void discord_rest_init(struct discord_rest *rest, struct logconf *conf, const char token[])
Initialize an REST handle.
CCORDcode discord_refcounter_unclaim(struct discord_refcounter *rc, void *data)
Unclaim ownership of data
CCORDcode discord_refcounter_claim(struct discord_refcounter *rc, const void *data)
Claim ownership of data
void discord_refcounter_cleanup(struct discord_refcounter *rc)
Cleanup refcounter and all user data currently held.
CCORDcode discord_refcounter_incr(struct discord_refcounter *rc, void *data)
Increment the reference counter for ret->data
void discord_refcounter_add_internal(struct discord_refcounter *rc, void *data, void(*cleanup)(void *data), bool should_free)
Add a new internal reference to the reference counter.
CCORDcode discord_refcounter_decr(struct discord_refcounter *rc, void *data)
Decrement the reference counter for data
void discord_refcounter_init(struct discord_refcounter *rc, struct logconf *conf)
Initialize reference counter handle.
void discord_refcounter_add_client(struct discord_refcounter *rc, void *data, void(*cleanup)(struct discord *client, void *data), bool should_free)
Add a new client reference to the reference counter.
int64_t discord_timers_get_next_trigger(struct discord_timers *const timers[], size_t n, int64_t now, int64_t max_time)
Get earliest trigger time from a group of timers.
void discord_timers_init(struct discord_timers *timers, struct io_poller *io)
Prepare timers for usage.
unsigned discord_internal_timer_ctl(struct discord *client, struct discord_timer *timer)
Modifies or creates a timer.
unsigned _discord_timer_ctl(struct discord *client, struct discord_timers *timers, struct discord_timer *timer)
Modifies or creates a timer.
void discord_timers_cleanup(struct discord *client, struct discord_timers *timers)
Cleanup timers and call cancel any running ones.
void discord_timers_run(struct discord *client, struct discord_timers *timers)
Run all timers that are due.
unsigned discord_internal_timer(struct discord *client, discord_ev_timer on_tick_cb, discord_ev_timer on_status_changed_cb, void *data, int64_t delay)
Creates a one shot timer that automatically deletes itself upon completion.
#define DISCORD_ROUTE_LEN
Definition: discord-internal.h:82
#define DISCORD_ENDPT_LEN
Definition: discord-internal.h:80
void(* discord_ev_timer)(struct discord *client, struct discord_timer *ev)
callback to be used with struct discord_timer
Definition: discord.h:349
struct priority_queue priority_queue
Definition: priority_queue.h:13
void * QUEUE[2]
Definition: queue.h:21
Reusable generic sized buffer.
Definition: types.h:63
Generic sized buffer.
Definition: types.h:47
Request to be performed.
Definition: discord-internal.h:432
The Discord bucket for handling per-group ratelimits.
Definition: discord-internal.h:292
u64unix_ms reset_tstamp
Definition: discord-internal.h:300
struct discord_request * busy_req
Definition: discord-internal.h:306
long limit
Definition: discord-internal.h:296
long remaining
Definition: discord-internal.h:298
char hash[64]
Definition: discord-internal.h:294
QUEUE entry
Definition: discord-internal.h:314
struct discord_bucket::@2 queues
The Discord Cache control handler.
Definition: discord-internal.h:1158
void(* on_shard_resumed)(struct discord *client, const struct discord_identify *ident)
Definition: discord-internal.h:1167
struct _discord_cache_data * data
Definition: discord-internal.h:1159
void(* on_shard_disconnected)(struct discord *client, const struct discord_identify *ident, bool resumable)
Definition: discord-internal.h:1163
void(* cleanup)(struct discord *client)
Definition: discord-internal.h:1160
void(* on_shard_reconnected)(struct discord *client, const struct discord_identify *ident)
Definition: discord-internal.h:1170
The handle for storing the Discord response payload.
Definition: discord-internal.h:697
jsmnf_pair * pairs
Definition: discord-internal.h:709
unsigned ntokens
Definition: discord-internal.h:707
size_t size
Definition: discord-internal.h:703
struct discord_gateway_payload::@7 json
int seq
Definition: discord-internal.h:717
jsmnf_pair * data
Definition: discord-internal.h:723
char * start
Definition: discord-internal.h:701
jsmntok_t * tokens
Definition: discord-internal.h:705
enum discord_gateway_events event
Definition: discord-internal.h:721
char name[32]
Definition: discord-internal.h:719
enum discord_gateway_opcodes opcode
Definition: discord-internal.h:715
unsigned npairs
Definition: discord-internal.h:711
The handle for storing the Discord Gateway session.
Definition: discord-internal.h:665
char base_url[256]
Definition: discord-internal.h:673
struct discord_session_start_limit start_limit
Definition: discord-internal.h:677
int limit
Definition: discord-internal.h:692
char resume_url[256]
Definition: discord-internal.h:675
int attempt
Definition: discord-internal.h:690
int shards
Definition: discord-internal.h:671
int event_count
Definition: discord-internal.h:681
struct discord_gateway_session::@6 retry
unsigned status
Definition: discord-internal.h:683
int concurrent
Definition: discord-internal.h:679
bool enable
Definition: discord-internal.h:688
bool is_ready
Definition: discord-internal.h:667
The handle used for interfacing with Discord's Gateway API.
Definition: discord-internal.h:733
struct websockets * ws
Definition: discord-internal.h:737
u64unix_ms hbeat_last
Definition: discord-internal.h:758
struct discord_gateway_payload payload
Definition: discord-internal.h:788
discord_ev_scheduler scheduler
Definition: discord-internal.h:797
unsigned hbeat_timer
Definition: discord-internal.h:770
u64unix_ms now
Definition: discord-internal.h:752
struct discord_gateway_session * session
Definition: discord-internal.h:785
int64_t hbeat_interval
Definition: discord-internal.h:747
pthread_rwlock_t rwlock
Definition: discord-internal.h:778
struct logconf conf
Definition: discord-internal.h:735
int ping_ms
Definition: discord-internal.h:776
u64unix_ms identify_last
Definition: discord-internal.h:763
u64unix_ms event
Definition: discord-internal.h:768
struct discord_gateway::@8 * timer
CURLM * mhandle
Definition: discord-internal.h:739
struct discord_identify id
Definition: discord-internal.h:782
discord_ev_event cbs[2][DISCORD_EV_MAX]
Definition: discord-internal.h:795
Definition: gateway.h:259
The handle for storing user's message commands.
Definition: discord-internal.h:1062
struct _discord_message_commands_entry * entries
Definition: discord-internal.h:1077
discord_ev_message fallback
Definition: discord-internal.h:1068
int length
Definition: discord-internal.h:1070
struct logconf conf
Definition: discord-internal.h:1064
struct ccord_szbuf prefix
Definition: discord-internal.h:1066
int capacity
Definition: discord-internal.h:1072
Definition: channel.h:195
Definition: gateway.h:214
The ratelimiter struct for handling ratelimiting.
Definition: discord-internal.h:204
struct discord_bucket * null
Definition: discord-internal.h:218
u64unix_ms * global_wait_tstamp
Definition: discord-internal.h:224
int length
Definition: discord-internal.h:208
struct discord_ratelimiter::@1 queues
struct discord_bucket * miss
Definition: discord-internal.h:221
int capacity
Definition: discord-internal.h:210
struct logconf conf
Definition: discord-internal.h:206
struct _discord_route * routes
Definition: discord-internal.h:215
Automatically cleanup user data.
Definition: discord-internal.h:934
pthread_mutex_t * g_lock
Definition: discord-internal.h:947
struct logconf conf
Definition: discord-internal.h:936
struct _discord_ref * refs
Definition: discord-internal.h:945
int length
Definition: discord-internal.h:938
int capacity
Definition: discord-internal.h:940
Definition: gateway.h:299
Individual requests that are scheduled to run asynchronously.
Definition: discord-internal.h:442
struct ccord_szbuf_reusable body
Definition: discord-internal.h:448
QUEUE entry
Definition: discord-internal.h:464
pthread_cond_t * cond
Definition: discord-internal.h:462
enum http_method method
Definition: discord-internal.h:450
char endpoint[512]
Definition: discord-internal.h:452
int retry_attempt
Definition: discord-internal.h:460
char key[256]
Definition: discord-internal.h:454
struct discord_bucket * b
Definition: discord-internal.h:446
CCORDcode code
Definition: discord-internal.h:458
struct ua_conn * conn
Definition: discord-internal.h:456
The handle used for handling asynchronous requests.
Definition: discord-internal.h:468
pthread_mutex_t recycling
Definition: discord-internal.h:497
CURLM * mhandle
Definition: discord-internal.h:474
struct discord_requestor::@5 * qlocks
pthread_mutex_t finished
Definition: discord-internal.h:501
pthread_mutex_t pending
Definition: discord-internal.h:499
int retry_limit
Definition: discord-internal.h:479
struct user_agent * ua
Definition: discord-internal.h:472
struct logconf conf
Definition: discord-internal.h:470
struct discord_ratelimiter ratelimiter
Definition: discord-internal.h:476
struct discord_requestor::@4 * queues
The response for the completed request.
Definition: discord-response.h:12
The handle used for interfacing with Discord's REST API.
Definition: discord-internal.h:585
struct threadpool_t * tpool
Definition: discord-internal.h:595
struct logconf conf
Definition: discord-internal.h:587
struct io_poller * io_poller
Definition: discord-internal.h:593
struct discord_requestor requestor
Definition: discord-internal.h:589
struct discord_timers timers
Definition: discord-internal.h:591
Definition: gateway.h:290
Generic request dispatcher.
Definition: discord-internal.h:379
DISCORD_RET_DEFAULT_FIELDS
Definition: discord-internal.h:380
union discord_ret_dispatch::@3 done
void(* typeless)(struct discord *client, struct discord_response *resp)
Definition: discord-internal.h:393
void * sync
Definition: discord-internal.h:400
bool has_type
Definition: discord-internal.h:382
void(* typed)(struct discord *client, struct discord_response *resp, const void *ret)
Definition: discord-internal.h:390
Attributes of response datatype.
Definition: discord-internal.h:404
size_t size
Definition: discord-internal.h:408
size_t(* from_json)(const char *json, size_t len, void *data)
Definition: discord-internal.h:412
void(* init)(void *data)
Definition: discord-internal.h:410
void * data
Definition: discord-internal.h:406
void(* cleanup)(void *data)
Definition: discord-internal.h:414
Definition: gateway.h:686
struct used for modifying, and getting info about a timer
Definition: discord.h:373
void * data
Definition: discord.h:384
int64_t delay
Definition: discord.h:386
Definition: discord-internal.h:88
struct io_poller * io
Definition: discord-internal.h:90
pthread_mutex_t lock
Definition: discord-internal.h:97
bool skip_update_phase
Definition: discord-internal.h:95
bool is_active
Definition: discord-internal.h:92
priority_queue * q
Definition: discord-internal.h:89
struct discord_timers::@0 active
pthread_cond_t cond
Definition: discord-internal.h:98
struct discord_timer * timer
Definition: discord-internal.h:94
pthread_t thread
Definition: discord-internal.h:93
Definition: gateway.h:320
Definition: user.h:69
The Discord client handler.
Definition: discord-internal.h:1182
struct discord_user self
Definition: discord-internal.h:1202
unsigned id
Definition: discord-internal.h:1216
struct discord_cache cache
Definition: discord-internal.h:1204
void(* cb)(struct discord *client)
Definition: discord-internal.h:1214
void(* on_cycle)(struct discord *client)
Definition: discord-internal.h:1222
struct discord_message_commands commands
Definition: discord-internal.h:1193
struct discord_rest rest
Definition: discord-internal.h:1198
struct discord::@10 wakeup_timer
struct discord::@11 * workers
struct discord_refcounter refcounter
Definition: discord-internal.h:1195
struct io_poller * io_poller
Definition: discord-internal.h:1190
void(* on_idle)(struct discord *client)
Definition: discord-internal.h:1220
pthread_mutex_t lock
Definition: discord-internal.h:1232
bool is_original
Definition: discord-internal.h:1186
pthread_cond_t cond
Definition: discord-internal.h:1234
struct discord_timers internal
Definition: discord-internal.h:1207
struct logconf conf
Definition: discord-internal.h:1184
struct discord_gateway gw
Definition: discord-internal.h:1200
struct discord::@9 timers
void * data
Definition: discord-internal.h:1225
struct discord_timers user
Definition: discord-internal.h:1208
int count
Definition: discord-internal.h:1230
char * token
Definition: discord-internal.h:1188
Definition: jsmn.h:69
A stackful and modularized wrapper over the popular 'log.c' facilities.
Definition: logconf.h:217
Opaque handler for WebSockets.
struct threadpool_t threadpool_t
Definition: threadpool.h:48