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
33#define NOT_EMPTY_STR(str) ((str) && *(str))
41#define CONTAINEROF(ptr, type, path) \
42 ((type *)((char *)(ptr)-offsetof(type, path)))
43
49#define CLIENT(ptr, path) CONTAINEROF(ptr, struct discord, path)
50
60#define CCORD_EXPECT(client, expect, code, reason) \
61 do { \
62 if (!(expect)) { \
63 logconf_error(&(client)->conf, "Expected: " #expect ": " reason); \
64 return code; \
65 } \
66 } while (0)
67
75#define ASSERT_NOT_OOB(nbytes, destsz) \
76 ASSERT_S((size_t)nbytes < (size_t)destsz, "Out of bounds write attempt");
77
79#define DISCORD_ENDPT_LEN 512
81#define DISCORD_ROUTE_LEN 256
82
89 struct io_poller *io;
90 struct {
92 pthread_t thread;
96 pthread_mutex_t lock;
97 pthread_cond_t cond;
98};
99
105void discord_timers_init(struct discord_timers *timers, struct io_poller *io);
106
113void discord_timers_cleanup(struct discord *client,
114 struct discord_timers *timers);
115
125int64_t discord_timers_get_next_trigger(struct discord_timers *const timers[],
126 size_t n,
127 int64_t now,
128 int64_t max_time);
129
136void discord_timers_run(struct discord *client, struct discord_timers *timers);
137
146unsigned _discord_timer_ctl(struct discord *client,
147 struct discord_timers *timers,
148 struct discord_timer *timer);
149
157unsigned discord_internal_timer_ctl(struct discord *client,
158 struct discord_timer *timer);
159
173unsigned discord_internal_timer(struct discord *client,
174 discord_ev_timer on_tick_cb,
175 discord_ev_timer on_status_changed_cb,
176 void *data,
177 int64_t delay);
178
197#define DISCORD_BUCKET_TIMEOUT (void *)(0xf)
198
205 struct logconf conf;
214 struct _discord_route *routes;
221
222 /* client-wide global ratelimiting */
224
226 struct {
228 QUEUE(struct discord_bucket) pending;
230};
231
240 struct logconf *conf);
241
249
259void discord_ratelimiter_build_key(enum http_method method,
260 char key[DISCORD_ROUTE_LEN],
261 const char endpoint_fmt[],
262 va_list args);
263
274 struct discord_bucket *bucket,
275 const char key[],
276 struct ua_info *info);
277
287 struct discord_bucket *bucket,
288 u64unix_ms wait_ms);
289
293 char hash[64];
295 long limit;
300
306
308 struct {
310 QUEUE(struct discord_request) next;
314};
315
323 u64unix_ms wait_ms);
324
333 const char key[]);
334
345 struct discord_bucket *b,
346 struct discord_request *req,
347 bool high_priority);
348
359 struct discord_ratelimiter *rl,
360 void *data,
361 void (*iter)(void *data, struct discord_request *req));
362
372 struct discord_bucket *b,
373 struct discord_request *req);
374
382
388 union {
389 void (*typed)(struct discord *client,
390 struct discord_response *resp,
391 const void *ret);
392 void (*typeless)(struct discord *client,
393 struct discord_response *resp);
395
399 void *sync;
400};
401
405 void *data;
407 size_t size;
409 void (*init)(void *data);
411 size_t (*from_json)(const char *json, size_t len, void *data);
413 void (*cleanup)(void *data);
414};
415
420#define DISCORD_ATTRIBUTES_FIELDS \
421 \
422 struct discord_ret_dispatch dispatch; \
423 \
424 struct discord_ret_response response; \
425 \
426 struct discord_attachments attachments; \
427 \
429 char *reason
430
434};
435
444
446 struct discord_bucket *b;
450 enum http_method method;
456 struct ua_conn *conn;
460 int retry_attempt;
462 pthread_cond_t *cond;
464 QUEUE entry;
465};
466
468struct discord_requestor {
470 struct logconf conf;
472 struct user_agent *ua;
474 CURLM *mhandle;
477
479 int retry_limit;
480
482 struct {
492 } * queues;
493
495 struct {
497 pthread_mutex_t recycling;
499 pthread_mutex_t pending;
501 pthread_mutex_t finished;
502 } * qlocks;
503};
504
515 struct logconf *conf,
516 const char token[]);
517
524
532
540
547
555 struct discord_request *req);
556
571 struct discord_attributes *req,
572 struct ccord_szbuf *body,
573 enum http_method method,
574 char endpoint[DISCORD_ENDPT_LEN],
575 char key[DISCORD_ROUTE_LEN]);
576
585struct discord_rest {
587 struct logconf conf;
591 struct discord_timers timers;
593 struct io_poller *io_poller;
595 struct threadpool_t *tpool;
596};
597
606void discord_rest_init(struct discord_rest *rest,
607 struct logconf *conf,
608 const char token[]);
609
615void discord_rest_cleanup(struct discord_rest *rest);
616
633 struct discord_attributes *req,
634 struct ccord_szbuf *body,
635 enum http_method method,
636 char endpoint_fmt[],
637 ...);
638
645void discord_rest_stop_buckets(struct discord_rest *rest);
646
657#define DISCORD_SESSION_OFFLINE 0u
659#define DISCORD_SESSION_RESUMABLE 1u << 0
661#define DISCORD_SESSION_SHUTDOWN 1u << 1
667 bool is_ready;
669 char id[64];
671 int shards;
673 char base_url[256];
675 char resume_url[256];
679 int concurrent;
681 int event_count;
683 unsigned status;
684
686 struct {
688 bool enable;
690 int attempt;
692 int limit;
693 } retry;
694};
695
699 struct {
701 char *start;
703 size_t size;
707 unsigned ntokens;
711 unsigned npairs;
712 } json;
713
717 int seq;
719 char name[32];
724};
725
727typedef void (*discord_ev_event)(struct discord *client, const void *event);
729typedef void (*discord_ev_message)(struct discord *client,
730 const struct discord_message *event);
731
733struct discord_gateway {
735 struct logconf conf;
737 struct websockets *ws;
739 CURLM *mhandle;
740
742 struct {
747 int64_t hbeat_interval;
770 unsigned hbeat_timer;
771
776 int ping_ms;
778 pthread_rwlock_t rwlock;
779 } * timer;
780
782 struct discord_identify id;
783
786
798};
799
809 struct logconf *conf,
810 const char token[]);
811
818
826
834bool discord_gateway_end(struct discord_gateway *gw);
835
843
850
858void discord_gateway_reconnect(struct discord_gateway *gw, bool resume);
859
867 struct discord_identify *event);
868
876 struct discord_resume *event);
877
885
894
904
912 struct discord_gateway *gw, struct discord_presence_update *event);
913
920
934struct discord_refcounter {
936 struct logconf conf;
938 int length;
940 int capacity;
945 struct _discord_ref *refs;
947 pthread_mutex_t *g_lock;
948};
949
958 struct logconf *conf);
959
970 void *data,
971 void (*cleanup)(void *data),
972 bool should_free);
973
984 void *data,
985 void (*cleanup)(struct discord *client,
986 void *data),
987 bool should_free);
988
995
1009 const void *data);
1010
1024 void *data);
1025
1036
1050
1063 struct logconf conf;
1065 struct ccord_szbuf prefix;
1069 int length;
1071 int capacity;
1076 struct _discord_message_commands_entry *entries;
1077};
1078
1086 struct logconf *conf);
1087
1094
1104 struct discord_message_commands *cmds,
1105 const char command[],
1106 size_t length);
1107
1117 const char command[],
1118 size_t length,
1119 discord_ev_message callback);
1120
1132 const char prefix[],
1133 size_t length);
1134
1145 struct discord_message_commands *cmds,
1146 struct discord_gateway_payload *payload);
1147
1158 struct _discord_cache_data *data;
1159 void (*cleanup)(struct discord *client);
1160
1162 void (*on_shard_disconnected)(struct discord *client,
1163 const struct discord_identify *ident,
1164 bool resumable);
1166 void (*on_shard_resumed)(struct discord *client,
1167 const struct discord_identify *ident);
1169 void (*on_shard_reconnected)(struct discord *client,
1170 const struct discord_identify *ident);
1171};
1172
1181struct discord {
1183 struct logconf conf;
1185 bool is_original;
1187 char *token;
1189 struct io_poller *io_poller;
1190
1195
1197 struct discord_rest rest;
1199 struct discord_gateway gw;
1201 struct discord_user self;
1203 struct discord_cache cache;
1204
1205 struct {
1208 } timers;
1209
1211 struct {
1213 void (*cb)(struct discord *client);
1215 unsigned id;
1216 } wakeup_timer;
1217
1219 void (*on_idle)(struct discord *client);
1221 void (*on_cycle)(struct discord *client);
1222
1224 void *data;
1225
1227 struct {
1229 int count;
1231 pthread_mutex_t lock;
1233 pthread_cond_t cond;
1234 } * workers;
1235
1236#ifdef CCORD_VOICE
1237 struct discord_voice *vcs;
1238 struct discord_voice_evcallbacks voice_cbs;
1239#endif /* CCORD_VOICE */
1240};
1241
1244#ifdef __cplusplus
1245}
1246#endif /* __cplusplus */
1247
1248#endif /* DISCORD_INTERNAL_H */
discord_gateway_opcodes
Definition: gateway.h:77
CCORDcode
Definition: error.h:10
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:728
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:726
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:420
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[],...)
Perform a request to Discord.
void discord_rest_stop_buckets(struct discord_rest *rest)
Stop all bucket's on-going, pending and timed-out requests.
void discord_rest_cleanup(struct discord_rest *rest)
Free an REST handle.
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:81
#define DISCORD_ENDPT_LEN
Definition: discord-internal.h:79
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:431
The Discord bucket for handling per-group ratelimits.
Definition: discord-internal.h:291
u64unix_ms reset_tstamp
Definition: discord-internal.h:299
struct discord_request * busy_req
Definition: discord-internal.h:305
long limit
Definition: discord-internal.h:295
long remaining
Definition: discord-internal.h:297
char hash[64]
Definition: discord-internal.h:293
QUEUE entry
Definition: discord-internal.h:313
struct discord_bucket::@2 queues
The Discord Cache control handler.
Definition: discord-internal.h:1156
void(* on_shard_resumed)(struct discord *client, const struct discord_identify *ident)
Definition: discord-internal.h:1165
struct _discord_cache_data * data
Definition: discord-internal.h:1157
void(* on_shard_disconnected)(struct discord *client, const struct discord_identify *ident, bool resumable)
Definition: discord-internal.h:1161
void(* cleanup)(struct discord *client)
Definition: discord-internal.h:1158
void(* on_shard_reconnected)(struct discord *client, const struct discord_identify *ident)
Definition: discord-internal.h:1168
The handle for storing the Discord response payload.
Definition: discord-internal.h:696
jsmnf_pair * pairs
Definition: discord-internal.h:708
unsigned ntokens
Definition: discord-internal.h:706
size_t size
Definition: discord-internal.h:702
struct discord_gateway_payload::@7 json
int seq
Definition: discord-internal.h:716
jsmnf_pair * data
Definition: discord-internal.h:722
char * start
Definition: discord-internal.h:700
jsmntok_t * tokens
Definition: discord-internal.h:704
enum discord_gateway_events event
Definition: discord-internal.h:720
char name[32]
Definition: discord-internal.h:718
enum discord_gateway_opcodes opcode
Definition: discord-internal.h:714
unsigned npairs
Definition: discord-internal.h:710
The handle for storing the Discord Gateway session.
Definition: discord-internal.h:664
char base_url[256]
Definition: discord-internal.h:672
struct discord_session_start_limit start_limit
Definition: discord-internal.h:676
int limit
Definition: discord-internal.h:691
char resume_url[256]
Definition: discord-internal.h:674
int attempt
Definition: discord-internal.h:689
int shards
Definition: discord-internal.h:670
int event_count
Definition: discord-internal.h:680
struct discord_gateway_session::@6 retry
unsigned status
Definition: discord-internal.h:682
int concurrent
Definition: discord-internal.h:678
bool enable
Definition: discord-internal.h:687
bool is_ready
Definition: discord-internal.h:666
The handle used for interfacing with Discord's Gateway API.
Definition: discord-internal.h:732
struct websockets * ws
Definition: discord-internal.h:736
u64unix_ms hbeat_last
Definition: discord-internal.h:757
struct discord_gateway_payload payload
Definition: discord-internal.h:787
discord_ev_scheduler scheduler
Definition: discord-internal.h:796
unsigned hbeat_timer
Definition: discord-internal.h:769
u64unix_ms now
Definition: discord-internal.h:751
struct discord_gateway_session * session
Definition: discord-internal.h:784
int64_t hbeat_interval
Definition: discord-internal.h:746
pthread_rwlock_t rwlock
Definition: discord-internal.h:777
struct logconf conf
Definition: discord-internal.h:734
int ping_ms
Definition: discord-internal.h:775
u64unix_ms identify_last
Definition: discord-internal.h:762
u64unix_ms event
Definition: discord-internal.h:767
struct discord_gateway::@8 * timer
CURLM * mhandle
Definition: discord-internal.h:738
struct discord_identify id
Definition: discord-internal.h:781
discord_ev_event cbs[2][DISCORD_EV_MAX]
Definition: discord-internal.h:794
Definition: gateway.h:259
The handle for storing user's message commands.
Definition: discord-internal.h:1060
struct _discord_message_commands_entry * entries
Definition: discord-internal.h:1075
discord_ev_message fallback
Definition: discord-internal.h:1066
int length
Definition: discord-internal.h:1068
struct logconf conf
Definition: discord-internal.h:1062
struct ccord_szbuf prefix
Definition: discord-internal.h:1064
int capacity
Definition: discord-internal.h:1070
Definition: channel.h:191
Definition: gateway.h:214
The ratelimiter struct for handling ratelimiting.
Definition: discord-internal.h:203
struct discord_bucket * null
Definition: discord-internal.h:217
u64unix_ms * global_wait_tstamp
Definition: discord-internal.h:223
int length
Definition: discord-internal.h:207
struct discord_ratelimiter::@1 queues
struct discord_bucket * miss
Definition: discord-internal.h:220
int capacity
Definition: discord-internal.h:209
struct logconf conf
Definition: discord-internal.h:205
struct _discord_route * routes
Definition: discord-internal.h:214
Automatically cleanup user data.
Definition: discord-internal.h:933
pthread_mutex_t * g_lock
Definition: discord-internal.h:946
struct logconf conf
Definition: discord-internal.h:935
struct _discord_ref * refs
Definition: discord-internal.h:944
int length
Definition: discord-internal.h:937
int capacity
Definition: discord-internal.h:939
Definition: gateway.h:299
Individual requests that are scheduled to run asynchronously.
Definition: discord-internal.h:441
struct ccord_szbuf_reusable body
Definition: discord-internal.h:447
QUEUE entry
Definition: discord-internal.h:463
pthread_cond_t * cond
Definition: discord-internal.h:461
enum http_method method
Definition: discord-internal.h:449
char endpoint[512]
Definition: discord-internal.h:451
int retry_attempt
Definition: discord-internal.h:459
char key[256]
Definition: discord-internal.h:453
struct discord_bucket * b
Definition: discord-internal.h:445
CCORDcode code
Definition: discord-internal.h:457
struct ua_conn * conn
Definition: discord-internal.h:455
The handle used for handling asynchronous requests.
Definition: discord-internal.h:467
pthread_mutex_t recycling
Definition: discord-internal.h:496
CURLM * mhandle
Definition: discord-internal.h:473
struct discord_requestor::@5 * qlocks
pthread_mutex_t finished
Definition: discord-internal.h:500
pthread_mutex_t pending
Definition: discord-internal.h:498
int retry_limit
Definition: discord-internal.h:478
struct user_agent * ua
Definition: discord-internal.h:471
struct logconf conf
Definition: discord-internal.h:469
struct discord_ratelimiter ratelimiter
Definition: discord-internal.h:475
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:584
struct threadpool_t * tpool
Definition: discord-internal.h:594
struct logconf conf
Definition: discord-internal.h:586
struct io_poller * io_poller
Definition: discord-internal.h:592
struct discord_requestor requestor
Definition: discord-internal.h:588
struct discord_timers timers
Definition: discord-internal.h:590
Definition: gateway.h:290
Generic request dispatcher.
Definition: discord-internal.h:378
DISCORD_RET_DEFAULT_FIELDS
Definition: discord-internal.h:379
union discord_ret_dispatch::@3 done
void(* typeless)(struct discord *client, struct discord_response *resp)
Definition: discord-internal.h:392
void * sync
Definition: discord-internal.h:399
bool has_type
Definition: discord-internal.h:381
void(* typed)(struct discord *client, struct discord_response *resp, const void *ret)
Definition: discord-internal.h:389
Attributes of response datatype.
Definition: discord-internal.h:403
size_t size
Definition: discord-internal.h:407
size_t(* from_json)(const char *json, size_t len, void *data)
Definition: discord-internal.h:411
void(* init)(void *data)
Definition: discord-internal.h:409
void * data
Definition: discord-internal.h:405
void(* cleanup)(void *data)
Definition: discord-internal.h:413
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:87
struct io_poller * io
Definition: discord-internal.h:89
pthread_mutex_t lock
Definition: discord-internal.h:96
bool skip_update_phase
Definition: discord-internal.h:94
bool is_active
Definition: discord-internal.h:91
priority_queue * q
Definition: discord-internal.h:88
struct discord_timers::@0 active
pthread_cond_t cond
Definition: discord-internal.h:97
struct discord_timer * timer
Definition: discord-internal.h:93
pthread_t thread
Definition: discord-internal.h:92
Definition: gateway.h:320
Definition: user.h:69
The Discord client handler.
Definition: discord-internal.h:1180
struct discord_user self
Definition: discord-internal.h:1200
unsigned id
Definition: discord-internal.h:1214
struct discord_cache cache
Definition: discord-internal.h:1202
void(* cb)(struct discord *client)
Definition: discord-internal.h:1212
void(* on_cycle)(struct discord *client)
Definition: discord-internal.h:1220
struct discord_message_commands commands
Definition: discord-internal.h:1191
struct discord_rest rest
Definition: discord-internal.h:1196
struct discord::@10 wakeup_timer
struct discord::@11 * workers
struct discord_refcounter refcounter
Definition: discord-internal.h:1193
struct io_poller * io_poller
Definition: discord-internal.h:1188
void(* on_idle)(struct discord *client)
Definition: discord-internal.h:1218
pthread_mutex_t lock
Definition: discord-internal.h:1230
bool is_original
Definition: discord-internal.h:1184
pthread_cond_t cond
Definition: discord-internal.h:1232
struct discord_timers internal
Definition: discord-internal.h:1205
struct logconf conf
Definition: discord-internal.h:1182
struct discord_gateway gw
Definition: discord-internal.h:1198
struct discord::@9 timers
void * data
Definition: discord-internal.h:1223
struct discord_timers user
Definition: discord-internal.h:1206
int count
Definition: discord-internal.h:1228
char * token
Definition: discord-internal.h:1186
JSON object.
Definition: jsmn-find.h:21
Definition: jsmn.h:69
A stackful and modularized wrapper over the popular 'log.c' facilities.
Definition: logconf.h:216
Opaque handler for WebSockets.
struct threadpool_t threadpool_t
Definition: threadpool.h:48