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
51
53#define CLIENT(ptr, path) CONTAINEROF(ptr, struct discord, path)
54
64#define CCORD_EXPECT(client, expect, code, reason) \
65 do { \
66 if (!(expect)) { \
67 logconf_error(&(client)->conf, "Expected: " #expect ": " reason); \
68 return code; \
69 } \
70 } while (0)
71
79#define ASSERT_NOT_OOB(nbytes, destsz) \
80 ASSERT_S((size_t)nbytes < (size_t)destsz, "Out of bounds write attempt");
81
83#define DISCORD_ENDPT_LEN 512
85#define DISCORD_ROUTE_LEN 256
86
93 struct io_poller *io;
94 struct {
96 pthread_t thread;
100 pthread_mutex_t lock;
101 pthread_cond_t cond;
102};
103
109void discord_timers_init(struct discord_timers *timers, struct io_poller *io);
110
117void discord_timers_cleanup(struct discord *client,
118 struct discord_timers *timers);
119
129int64_t discord_timers_get_next_trigger(struct discord_timers *const timers[],
130 size_t n,
131 int64_t now,
132 int64_t max_time);
133
140void discord_timers_run(struct discord *client, struct discord_timers *timers);
141
150unsigned _discord_timer_ctl(struct discord *client,
151 struct discord_timers *timers,
152 struct discord_timer *timer);
153
161unsigned discord_internal_timer_ctl(struct discord *client,
162 struct discord_timer *timer);
163
177unsigned discord_internal_timer(struct discord *client,
178 discord_ev_timer on_tick_cb,
179 discord_ev_timer on_status_changed_cb,
180 void *data,
181 int64_t delay);
182
201#define DISCORD_BUCKET_TIMEOUT (void *)(0xf)
202
209 struct logconf conf;
218 struct _discord_route *routes;
225
226 /* client-wide global ratelimiting */
228
230 struct {
232 QUEUE(struct discord_bucket) pending;
234};
235
244 struct logconf *conf);
245
253
263void discord_ratelimiter_build_key(enum http_method method,
264 char key[DISCORD_ROUTE_LEN],
265 const char endpoint_fmt[],
266 va_list args);
267
278 struct discord_bucket *bucket,
279 const char key[],
280 struct ua_info *info);
281
291 struct discord_bucket *bucket,
292 u64unix_ms wait_ms);
293
297 char hash[64];
299 long limit;
304
310
312 struct {
314 QUEUE(struct discord_request) next;
318};
319
327 u64unix_ms wait_ms);
328
337 const char key[]);
338
349 struct discord_bucket *b,
350 struct discord_request *req,
351 bool high_priority);
352
363 struct discord_ratelimiter *rl,
364 void *data,
365 void (*iter)(void *data, struct discord_request *req));
366
376 struct discord_bucket *b,
377 struct discord_request *req);
378
386
392 union {
393 void (*typed)(struct discord *client,
394 struct discord_response *resp,
395 const void *ret);
396 void (*typeless)(struct discord *client,
397 struct discord_response *resp);
399
403 void *sync;
404};
405
409 void *data;
411 size_t size;
413 void (*init)(void *data);
415 size_t (*from_json)(const char *json, size_t len, void *data);
417 void (*cleanup)(void *data);
418};
419
424#define DISCORD_ATTRIBUTES_FIELDS \
425 \
426 struct discord_ret_dispatch dispatch; \
427 \
428 struct discord_ret_response response; \
429 \
430 struct discord_attachments attachments; \
431 \
433 char *reason
434
438};
439
448
450 struct discord_bucket *b;
454 enum http_method method;
460 struct ua_conn *conn;
464 int retry_attempt;
466 pthread_cond_t *cond;
468 QUEUE entry;
469};
470
472struct discord_requestor {
474 struct logconf conf;
476 struct user_agent *ua;
478 CURLM *mhandle;
481
483 int retry_limit;
484
486 struct {
496 } * queues;
497
499 struct {
501 pthread_mutex_t recycling;
503 pthread_mutex_t pending;
505 pthread_mutex_t finished;
506 } * qlocks;
507};
508
519 struct logconf *conf,
520 const char token[]);
521
528
536
544
551
559 struct discord_request *req);
560
575 struct discord_attributes *req,
576 struct ccord_szbuf *body,
577 enum http_method method,
578 char endpoint[DISCORD_ENDPT_LEN],
579 char key[DISCORD_ROUTE_LEN]);
580
589struct discord_rest {
591 struct logconf conf;
595 struct discord_timers timers;
597 struct io_poller *io_poller;
599 struct threadpool_t *tpool;
600};
601
610void discord_rest_init(struct discord_rest *rest,
611 struct logconf *conf,
612 const char token[]);
613
619void discord_rest_cleanup(struct discord_rest *rest);
620
637 struct discord_attributes *req,
638 struct ccord_szbuf *body,
639 enum http_method method,
640 char endpoint_fmt[],
641 ...) PRINTF_LIKE(5, 6);
642
649void discord_rest_stop_buckets(struct discord_rest *rest);
650
661#define DISCORD_SESSION_OFFLINE 0u
663#define DISCORD_SESSION_RESUMABLE 1u << 0
665#define DISCORD_SESSION_SHUTDOWN 1u << 1
671 bool is_ready;
673 char id[64];
675 int shards;
677 char base_url[256];
679 char resume_url[256];
683 int concurrent;
685 int event_count;
687 unsigned status;
688
690 struct {
692 bool enable;
694 int attempt;
696 int limit;
697 } retry;
698};
699
703 struct {
705 char *start;
707 size_t size;
711 unsigned ntokens;
713 jsmnf_pair *pairs;
715 unsigned npairs;
716 } json;
717
721 int seq;
723 char name[32];
727 jsmnf_pair *data;
728};
729
731typedef void (*discord_ev_event)(struct discord *client, const void *event);
733typedef void (*discord_ev_message)(struct discord *client,
734 const struct discord_message *event);
735
737struct discord_gateway {
739 struct logconf conf;
741 struct websockets *ws;
743 CURLM *mhandle;
744
746 struct {
751 int64_t hbeat_interval;
779 unsigned hbeat_timer;
780
785 int ping_ms;
787 pthread_rwlock_t rwlock;
788 } * timer;
789
791 struct discord_identify id;
792
795
807};
808
818 struct logconf *conf,
819 const char token[]);
820
827
835
843bool discord_gateway_end(struct discord_gateway *gw);
844
852
859
867void discord_gateway_reconnect(struct discord_gateway *gw, bool resume);
868
876 struct discord_identify *event);
877
885 struct discord_resume *event);
886
894
903
913
921 struct discord_gateway *gw, struct discord_presence_update *event);
922
929
943struct discord_refcounter {
945 struct logconf conf;
947 int length;
949 int capacity;
954 struct _discord_ref *refs;
956 pthread_mutex_t *g_lock;
957};
958
967 struct logconf *conf);
968
979 void *data,
980 void (*cleanup)(void *data),
981 bool should_free);
982
993 void *data,
994 void (*cleanup)(struct discord *client,
995 void *data),
996 bool should_free);
997
1004
1018 const void *data);
1019
1033 void *data);
1034
1045
1060
1073 struct logconf conf;
1075 struct ccord_szbuf prefix;
1079 int length;
1081 int capacity;
1086 struct _discord_message_commands_entry *entries;
1087};
1088
1096 struct logconf *conf);
1097
1104
1114 struct discord_message_commands *cmds,
1115 const char command[],
1116 size_t length);
1117
1127 const char command[],
1128 size_t length,
1129 discord_ev_message callback);
1130
1142 const char prefix[],
1143 size_t length);
1144
1155 struct discord_message_commands *cmds,
1156 struct discord_gateway_payload *payload);
1157
1168 struct _discord_cache_data *data;
1169 void (*cleanup)(struct discord *client);
1170
1172 void (*on_shard_disconnected)(struct discord *client,
1173 const struct discord_identify *ident,
1174 bool resumable);
1176 void (*on_shard_resumed)(struct discord *client,
1177 const struct discord_identify *ident);
1179 void (*on_shard_reconnected)(struct discord *client,
1180 const struct discord_identify *ident);
1181};
1182
1191struct discord {
1193 struct logconf conf;
1195 bool is_original;
1197 char *token;
1199 struct io_poller *io_poller;
1200
1205
1207 struct discord_rest rest;
1209 struct discord_gateway gw;
1211 struct discord_user self;
1213 struct discord_cache cache;
1214
1216 int shutdown_fd;
1217
1218 struct {
1221 } timers;
1222
1224 struct {
1226 void (*cb)(struct discord *client);
1228 unsigned id;
1229 } wakeup_timer;
1230
1232 void (*on_idle)(struct discord *client);
1234 void (*on_cycle)(struct discord *client);
1235
1237 void *data;
1238
1240 struct {
1242 int count;
1244 pthread_mutex_t lock;
1246 pthread_cond_t cond;
1247 } * workers;
1248
1249#ifdef CCORD_VOICE
1250 struct discord_voice *vcs;
1251 struct discord_voice_evcallbacks voice_cbs;
1252#endif /* CCORD_VOICE */
1253};
1254
1257#ifdef __cplusplus
1258}
1259#endif /* __cplusplus */
1260
1261#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:732
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:730
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:424
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:85
#define DISCORD_ENDPT_LEN
Definition: discord-internal.h:83
int discord_dup_shutdown_fd(void)
dup shutdown fd to listen for ccord_shutdown_async()
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:435
The Discord bucket for handling per-group ratelimits.
Definition: discord-internal.h:295
u64unix_ms reset_tstamp
Definition: discord-internal.h:303
struct discord_request * busy_req
Definition: discord-internal.h:309
long limit
Definition: discord-internal.h:299
long remaining
Definition: discord-internal.h:301
char hash[64]
Definition: discord-internal.h:297
QUEUE entry
Definition: discord-internal.h:317
struct discord_bucket::@2 queues
The Discord Cache control handler.
Definition: discord-internal.h:1166
void(* on_shard_resumed)(struct discord *client, const struct discord_identify *ident)
Definition: discord-internal.h:1175
struct _discord_cache_data * data
Definition: discord-internal.h:1167
void(* on_shard_disconnected)(struct discord *client, const struct discord_identify *ident, bool resumable)
Definition: discord-internal.h:1171
void(* cleanup)(struct discord *client)
Definition: discord-internal.h:1168
void(* on_shard_reconnected)(struct discord *client, const struct discord_identify *ident)
Definition: discord-internal.h:1178
The handle for storing the Discord response payload.
Definition: discord-internal.h:700
jsmnf_pair * pairs
Definition: discord-internal.h:712
unsigned ntokens
Definition: discord-internal.h:710
size_t size
Definition: discord-internal.h:706
struct discord_gateway_payload::@7 json
int seq
Definition: discord-internal.h:720
jsmnf_pair * data
Definition: discord-internal.h:726
char * start
Definition: discord-internal.h:704
jsmntok_t * tokens
Definition: discord-internal.h:708
enum discord_gateway_events event
Definition: discord-internal.h:724
char name[32]
Definition: discord-internal.h:722
enum discord_gateway_opcodes opcode
Definition: discord-internal.h:718
unsigned npairs
Definition: discord-internal.h:714
The handle for storing the Discord Gateway session.
Definition: discord-internal.h:668
char base_url[256]
Definition: discord-internal.h:676
struct discord_session_start_limit start_limit
Definition: discord-internal.h:680
int limit
Definition: discord-internal.h:695
char resume_url[256]
Definition: discord-internal.h:678
int attempt
Definition: discord-internal.h:693
int shards
Definition: discord-internal.h:674
int event_count
Definition: discord-internal.h:684
struct discord_gateway_session::@6 retry
unsigned status
Definition: discord-internal.h:686
int concurrent
Definition: discord-internal.h:682
bool enable
Definition: discord-internal.h:691
bool is_ready
Definition: discord-internal.h:670
The handle used for interfacing with Discord's Gateway API.
Definition: discord-internal.h:736
struct websockets * ws
Definition: discord-internal.h:740
u64unix_ms hbeat_last
Definition: discord-internal.h:766
struct discord_gateway_payload payload
Definition: discord-internal.h:796
discord_ev_scheduler scheduler
Definition: discord-internal.h:805
unsigned hbeat_timer
Definition: discord-internal.h:778
u64unix_ms now
Definition: discord-internal.h:760
struct discord_gateway_session * session
Definition: discord-internal.h:793
int64_t hbeat_interval
Definition: discord-internal.h:750
pthread_rwlock_t rwlock
Definition: discord-internal.h:786
struct logconf conf
Definition: discord-internal.h:738
int ping_ms
Definition: discord-internal.h:784
u64unix_ms identify_last
Definition: discord-internal.h:771
u64unix_ms event
Definition: discord-internal.h:776
struct discord_gateway::@8 * timer
bool hbeat_acknowledged
Definition: discord-internal.h:755
CURLM * mhandle
Definition: discord-internal.h:742
struct discord_identify id
Definition: discord-internal.h:790
discord_ev_event cbs[2][DISCORD_EV_MAX]
Definition: discord-internal.h:803
Definition: gateway.h:259
The handle for storing user's message commands.
Definition: discord-internal.h:1070
struct _discord_message_commands_entry * entries
Definition: discord-internal.h:1085
discord_ev_message fallback
Definition: discord-internal.h:1076
int length
Definition: discord-internal.h:1078
struct logconf conf
Definition: discord-internal.h:1072
struct ccord_szbuf prefix
Definition: discord-internal.h:1074
int capacity
Definition: discord-internal.h:1080
Definition: channel.h:195
Definition: gateway.h:214
The ratelimiter struct for handling ratelimiting.
Definition: discord-internal.h:207
struct discord_bucket * null
Definition: discord-internal.h:221
u64unix_ms * global_wait_tstamp
Definition: discord-internal.h:227
int length
Definition: discord-internal.h:211
struct discord_ratelimiter::@1 queues
struct discord_bucket * miss
Definition: discord-internal.h:224
int capacity
Definition: discord-internal.h:213
struct logconf conf
Definition: discord-internal.h:209
struct _discord_route * routes
Definition: discord-internal.h:218
Automatically cleanup user data.
Definition: discord-internal.h:942
pthread_mutex_t * g_lock
Definition: discord-internal.h:955
struct logconf conf
Definition: discord-internal.h:944
struct _discord_ref * refs
Definition: discord-internal.h:953
int length
Definition: discord-internal.h:946
int capacity
Definition: discord-internal.h:948
Definition: gateway.h:299
Individual requests that are scheduled to run asynchronously.
Definition: discord-internal.h:445
struct ccord_szbuf_reusable body
Definition: discord-internal.h:451
QUEUE entry
Definition: discord-internal.h:467
pthread_cond_t * cond
Definition: discord-internal.h:465
enum http_method method
Definition: discord-internal.h:453
char endpoint[512]
Definition: discord-internal.h:455
int retry_attempt
Definition: discord-internal.h:463
char key[256]
Definition: discord-internal.h:457
struct discord_bucket * b
Definition: discord-internal.h:449
CCORDcode code
Definition: discord-internal.h:461
struct ua_conn * conn
Definition: discord-internal.h:459
The handle used for handling asynchronous requests.
Definition: discord-internal.h:471
pthread_mutex_t recycling
Definition: discord-internal.h:500
CURLM * mhandle
Definition: discord-internal.h:477
struct discord_requestor::@5 * qlocks
pthread_mutex_t finished
Definition: discord-internal.h:504
pthread_mutex_t pending
Definition: discord-internal.h:502
int retry_limit
Definition: discord-internal.h:482
struct user_agent * ua
Definition: discord-internal.h:475
struct logconf conf
Definition: discord-internal.h:473
struct discord_ratelimiter ratelimiter
Definition: discord-internal.h:479
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:588
struct threadpool_t * tpool
Definition: discord-internal.h:598
struct logconf conf
Definition: discord-internal.h:590
struct io_poller * io_poller
Definition: discord-internal.h:596
struct discord_requestor requestor
Definition: discord-internal.h:592
struct discord_timers timers
Definition: discord-internal.h:594
Definition: gateway.h:290
Generic request dispatcher.
Definition: discord-internal.h:382
DISCORD_RET_DEFAULT_FIELDS
Definition: discord-internal.h:383
union discord_ret_dispatch::@3 done
void(* typeless)(struct discord *client, struct discord_response *resp)
Definition: discord-internal.h:396
void * sync
Definition: discord-internal.h:403
bool has_type
Definition: discord-internal.h:385
void(* typed)(struct discord *client, struct discord_response *resp, const void *ret)
Definition: discord-internal.h:393
Attributes of response datatype.
Definition: discord-internal.h:407
size_t size
Definition: discord-internal.h:411
size_t(* from_json)(const char *json, size_t len, void *data)
Definition: discord-internal.h:415
void(* init)(void *data)
Definition: discord-internal.h:413
void * data
Definition: discord-internal.h:409
void(* cleanup)(void *data)
Definition: discord-internal.h:417
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:91
struct io_poller * io
Definition: discord-internal.h:93
pthread_mutex_t lock
Definition: discord-internal.h:100
bool skip_update_phase
Definition: discord-internal.h:98
bool is_active
Definition: discord-internal.h:95
priority_queue * q
Definition: discord-internal.h:92
struct discord_timers::@0 active
pthread_cond_t cond
Definition: discord-internal.h:101
struct discord_timer * timer
Definition: discord-internal.h:97
pthread_t thread
Definition: discord-internal.h:96
Definition: gateway.h:320
Definition: user.h:69
The Discord client handler.
Definition: discord-internal.h:1190
struct discord_user self
Definition: discord-internal.h:1210
unsigned id
Definition: discord-internal.h:1227
struct discord_cache cache
Definition: discord-internal.h:1212
void(* cb)(struct discord *client)
Definition: discord-internal.h:1225
void(* on_cycle)(struct discord *client)
Definition: discord-internal.h:1233
struct discord_message_commands commands
Definition: discord-internal.h:1201
struct discord_rest rest
Definition: discord-internal.h:1206
struct discord::@10 wakeup_timer
struct discord::@11 * workers
struct discord_refcounter refcounter
Definition: discord-internal.h:1203
struct io_poller * io_poller
Definition: discord-internal.h:1198
void(* on_idle)(struct discord *client)
Definition: discord-internal.h:1231
pthread_mutex_t lock
Definition: discord-internal.h:1243
bool is_original
Definition: discord-internal.h:1194
pthread_cond_t cond
Definition: discord-internal.h:1245
struct discord_timers internal
Definition: discord-internal.h:1218
struct logconf conf
Definition: discord-internal.h:1192
struct discord_gateway gw
Definition: discord-internal.h:1208
struct discord::@9 timers
void * data
Definition: discord-internal.h:1236
int shutdown_fd
Definition: discord-internal.h:1215
struct discord_timers user
Definition: discord-internal.h:1219
int count
Definition: discord-internal.h:1241
char * token
Definition: discord-internal.h:1196
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