Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
255 commits
Select commit Hold shift + click to select a range
5ad6ba3
style(examples): fix weird .clang-format formatting by adding trailin…
lcsmuller Nov 12, 2021
746c352
chore(.clang-format): update for ease of switching between configs
lcsmuller Nov 12, 2021
5cb7fd8
wip(user-agent): add ua_enqueue() for multiplexing requests
lcsmuller Nov 12, 2021
ad30f96
wip(test): add test-discord-multiplex.c
lcsmuller Nov 12, 2021
55e66f8
fix(user-agent): CURLOPT_POSTFIELDSIZE must be called first than CURL…
lcsmuller Nov 12, 2021
40222d4
docs(websockets.c): typo
lcsmuller Nov 12, 2021
8c4b396
chore(common/third-party): add pqueue to and update licenses
lcsmuller Nov 13, 2021
e1c1a54
style(websockets): '_ws_' function prefixing for consistency
lcsmuller Nov 13, 2021
20f1d9b
wip: generic worker thread implementation
lcsmuller Nov 15, 2021
2307c14
feat(types.h): add ORCA_GLOBAL_INIT error type
lcsmuller Nov 15, 2021
20df0cb
chore(user-agent): remove unnecessary functions
lcsmuller Nov 15, 2021
4dea22c
chore: change some comments
lcsmuller Nov 15, 2021
244e069
feat: check to initialize globals once
lcsmuller Nov 15, 2021
acedd5b
wip: replace discord's threadpool with generic implementation
lcsmuller Nov 15, 2021
5351f87
fix(test-discord-ws.c): setenv() should be called before threadpool i…
lcsmuller Nov 15, 2021
ddb3652
chore(work.c): minimum size of 8 slots per threadpool's queue
lcsmuller Nov 15, 2021
dc5cb8d
feat(user-agent): add ua_set_curl_multi()
lcsmuller Nov 16, 2021
648942a
docs(user-agent.h): document all functions and datatypes
lcsmuller Nov 16, 2021
8366a31
refactor(work.c): remove libpqueue from dependencies and code
lcsmuller Nov 16, 2021
4bfabbb
feat: add libuv's queue.h
lcsmuller Nov 16, 2021
4707391
wip(user-agent): queue functions for asynchronous IO implementation
lcsmuller Nov 17, 2021
b348697
chore(common): move queue.h to common/third-party/
lcsmuller Nov 17, 2021
93a1f2b
docs: improve explanation for ua_clone() and discord_clone()
lcsmuller Nov 20, 2021
08b395d
refactor(user-agent): move internal _ua_conn_setup() logging to outsi…
lcsmuller Nov 20, 2021
83b1cc7
feat(discord): add discord_timestamp()
lcsmuller Nov 20, 2021
4c3eb14
refactor(websockets): move cleanup logic from ws_perform() to ws_end()
lcsmuller Nov 20, 2021
796881e
chore: update to match 4c3eb149
lcsmuller Nov 20, 2021
d39924c
refactor(examples): replace cee_timestamp_ms() with discord_timestamp()
lcsmuller Nov 20, 2021
656da47
refactor(websockets): expose CURLM and CURL handles used internally
lcsmuller Nov 20, 2021
b13b465
chore: update to match 656da47
lcsmuller Nov 20, 2021
87d3110
refactor(user-agent): ua_init() expect a struct ua_attr
lcsmuller Nov 20, 2021
7ea8dcf
chore: update to match 87d3110
lcsmuller Nov 20, 2021
84e8f74
docs(user-agent.c): fix comment
lcsmuller Nov 20, 2021
217da6e
fix(discord-ratelimit): don't rely on system time for 'X-Ratelimit-Re…
lcsmuller Nov 21, 2021
a01fd7f
chore: remove ua_block_ms(), there are better solutions for global ra…
lcsmuller Nov 21, 2021
26339ec
fix(user-agent.c): no need to let libcurl create its unique copy for …
lcsmuller Nov 21, 2021
b7658f7
chore(third-party): add libuv's heap-inl.h for min-max heap
lcsmuller Nov 22, 2021
94e43bd
fix(discord-adapter): JSON error callback being ignored for functions…
lcsmuller Nov 22, 2021
e560413
wip(discord): use custom CURLM handle for websockets
lcsmuller Nov 22, 2021
073b476
chore(user-agent): remove unnecessary queue functionalities
lcsmuller Nov 22, 2021
541863f
feat(user-agent): make ua_conn_get() and ua_conn_setup() public
lcsmuller Nov 22, 2021
5b13bfc
chore: remove pqueue from codebase
lcsmuller Nov 22, 2021
a5a4045
refactor(user-agent): replace connection pool logic with queue.h
lcsmuller Nov 22, 2021
e898c92
fix: undefined behavior mentioned at libuv/libuv#565
lcsmuller Nov 22, 2021
6b7e066
chore(user-agent.c): fix typo
lcsmuller Nov 22, 2021
02638ec
wip(discord): isolate ratelimit logic
lcsmuller Nov 24, 2021
f5342f0
feat(discord-ratelimit): all requests will be assigned to a bucket, t…
lcsmuller Nov 24, 2021
4401851
fix(discord-ratelimit): memory leak
lcsmuller Nov 24, 2021
f2b036a
chore(.clang-format): break before non-assignment operators
lcsmuller Nov 26, 2021
cd077be
fix(discord-adapter.c): major parameter buckets must be decided on a …
lcsmuller Nov 26, 2021
359013c
chore(discord-adapter.c): fix minor typo
lcsmuller Nov 26, 2021
2946744
chore(discord-adapter.c): correct buffer size
lcsmuller Nov 26, 2021
8a38f37
refactor(discord-adapter.c): simplify major param selector
lcsmuller Nov 26, 2021
1815979
chore(discord-ratelimit.c): null bucket tags should be [null] instead…
lcsmuller Nov 27, 2021
68d640b
refactor(discord-adapter.c): modularize 8a38f37
lcsmuller Nov 27, 2021
7c52130
refactor(discord-gateway.c): remove repetitive shutdown logging
lcsmuller Nov 27, 2021
dedf1f4
refactor(discord-ratelimit.c): unnecessary tmp buffer for holding hash
lcsmuller Nov 27, 2021
6d661d1
docs(discord-internal.h): brief explanation for 'struct discord_route'
lcsmuller Nov 27, 2021
905c678
refactor: prefix singleton buckets with 'b_'
lcsmuller Nov 27, 2021
fbc48c2
refactor(discord-gateway): simplify event scheduling logic
lcsmuller Nov 27, 2021
7ff605f
wip(discord-adapter.c): add discord_adapter_enqueue() for asynchronou…
lcsmuller Nov 27, 2021
8c59dfe
fix(discord): move request queues to 'struct discord_adapter'
lcsmuller Nov 27, 2021
ac95469
wip(discord-adapter): check for IO polling results with discord_adapt…
lcsmuller Nov 27, 2021
8f1a453
chore(.clang-format): don't allow single-line for case label
lcsmuller Nov 28, 2021
5259357
feat(discord-ratelimit.c): add discord_route_get() and improve docs f…
lcsmuller Nov 28, 2021
3c91ead
wip(discord-adapter.c): asynchronous IO request enqueueing logic
lcsmuller Nov 28, 2021
cc75b8f
fix(discord-adapter.c): wrong info
lcsmuller Nov 28, 2021
fad5f5d
feat!(user-agent): replace request timestamp with libcurl provided el…
lcsmuller Nov 28, 2021
5e57989
chore(js_user-agent.c): match fad5f changes
lcsmuller Nov 28, 2021
45bbf17
refactor(discord-ratelimit.c): checking for bucket's update timestamp…
lcsmuller Nov 28, 2021
4768962
refactor(discord-internal.h): 'struct discord_request_cxt' stores
lcsmuller Nov 28, 2021
0bd95b5
feat(discord-adapter.c): get and assign 'struct ua_conn' to the reque…
lcsmuller Nov 28, 2021
6eb0740
feat(user-agent): add discord_conn_get_results()
lcsmuller Nov 28, 2021
8e594ed
chore(js_user-agent.c): update to match 6eb0740
lcsmuller Nov 28, 2021
44e0b49
fix(user-agent.h): declare ua_conn_get_results(), change docs regardi…
lcsmuller Nov 28, 2021
cc40f9f
wip(discord-adapter.c): make async layout similar to _discord_adapter…
lcsmuller Nov 28, 2021
4d8744e
wip(discord): discord_set_async() for performing requests asynchronously
lcsmuller Nov 29, 2021
8727711
refactor(user-agent): remove redundant callbacks (use ua_info instead)
lcsmuller Nov 29, 2021
294bd92
chore(discord-gateway.c): rewrite compound literals and move variable…
lcsmuller Nov 29, 2021
ad923f6
refactor(discord-client.c): discord_timestamp() shall use ws_timestam…
lcsmuller Nov 29, 2021
500418b
fix(discord-adapter.c): struct discord_request should hold a bucket f…
lcsmuller Nov 29, 2021
ac9d174
wip(test-discord-async.c): test first prototype
lcsmuller Nov 29, 2021
21935dc
fix: _ws_curl_tls_check() should only trigger ws_close() if the user …
lcsmuller Nov 30, 2021
458dc33
wip(discord-adapter.c): async trigger user callback, use discord_time…
lcsmuller Nov 30, 2021
9220b91
refactor(discord): share only whats necessary, shorten a couple fields
lcsmuller Nov 30, 2021
1751357
refactor(discord-gateway.c): apply 9220b changes, add close reason, f…
lcsmuller Nov 30, 2021
0b4c620
fix(discord-ratelimit.c): shouldn't skip discord_bucket_build() on un…
lcsmuller Nov 30, 2021
f165f9f
chore(discord-voice-connections.c): apply 9220b changes
lcsmuller Nov 30, 2021
e99e72f
feat(test-discord-ws.c): add reconnect test"
lcsmuller Nov 30, 2021
85e5d20
feat(test-discord-async.c): test asynchronous vs synchronous
lcsmuller Nov 30, 2021
e6d0a8a
feat(discord-adapter.c): queues cleanup logic
lcsmuller Nov 30, 2021
cf3cb9f
feat(discord-ratelimit.c): support out-of-order ratelimiting (for mul…
lcsmuller Nov 30, 2021
860fc79
chore(test): remove test-discord-multiplex.c
lcsmuller Dec 1, 2021
cf27d4f
wip(discord): request timeout logic
lcsmuller Dec 1, 2021
dd742fd
refactor(discord-ratelimit.c): split a couple functions
lcsmuller Dec 1, 2021
b682b61
fix(discord-gateway.c): send CLOSE_REASON_NO_REASON if a reconnect at…
lcsmuller Dec 1, 2021
20ca67d
refactor(discord-gateway.c): replace cee_timestamp_ms() with ws_times…
lcsmuller Dec 1, 2021
350e484
refactor(discord-voice-connections.c): match discord-gateway.c logic
lcsmuller Dec 1, 2021
4ca426d
chore(bot-elitebgs.c): update to latest
lcsmuller Dec 1, 2021
d9cb243
refactor(user-agent.c): add _ua_info_reset() and _ua_info_populate()
lcsmuller Dec 3, 2021
834227b
feat(discord): functional ratelimiting for async
lcsmuller Dec 3, 2021
2c4404c
chore(test-discord-async.c): update test
lcsmuller Dec 3, 2021
d4a0792
chore(discord): rename discord-ratelimit.c to discord-adapter-ratelim…
lcsmuller Dec 3, 2021
ff7cd0c
refactor(discord-adapter-request.c): split request handling logic fro…
lcsmuller Dec 3, 2021
cd22413
refactor(discord-adapter-request.c): consistent naming and descriptiv…
lcsmuller Dec 3, 2021
d7ce68c
feat(user-agent): add ua_conn_reset()
lcsmuller Dec 3, 2021
d6f3d35
feat(discord-adapter-ratelimit.c): add discord_bucket_get_timeout() and
lcsmuller Dec 3, 2021
b344acf
fix(discord-adapter-ratelimit.c): in case multiple requests with unde…
lcsmuller Dec 3, 2021
98fe948
fix(discord): ratelimit per-route, not per-hash
lcsmuller Dec 4, 2021
c490393
feat(discord): set priority of async request
lcsmuller Dec 4, 2021
2e3ab92
chore(test-discord-async.c): update
lcsmuller Dec 4, 2021
fd81f44
fix(user-agent.c): move HTTP_SEND logging to ua_conn_setup() so that …
lcsmuller Dec 4, 2021
9f0e1ae
feat(discord): stop on-going requests with discord_request_stop_all()
lcsmuller Dec 4, 2021
34fc8fd
fix(user-agent.c): typo us_conn_perform() -> ua_conn_perform()
lcsmuller Dec 4, 2021
6f1208d
fix(discord-adapter-request.c): req_body recycling logic, memsize sho…
lcsmuller Dec 4, 2021
3e88c81
chore(test-discord-async.c): add ordered spamming test
lcsmuller Dec 4, 2021
2c311ba
refactor(discord-adapter-ratelimit.c): alter a couple logging levels
lcsmuller Dec 5, 2021
d638d46
fix(discord-adapter-request.c): don't force decrease remaining bucket…
lcsmuller Dec 5, 2021
2dee78d
fix(discord-adapter-ratelimit.c): skip when current timestamp is less…
lcsmuller Dec 5, 2021
8d4e337
fix(discord-gateway.c): no need to run request checks if connection h…
lcsmuller Dec 5, 2021
9b8973f
refactor(discord-internal.h): remove unused 'server' field
lcsmuller Dec 5, 2021
961bb15
feat: added discord_set_on_commands (#750)
Dec 6, 2021
ae77482
chore(discord-adapter-ratelimit.c): reduce scope
lcsmuller Dec 5, 2021
891c537
refactor(discord-gateway.c): add _discord_gateway_close()
lcsmuller Dec 6, 2021
478483e
fix: freeze bucket on any request timed out, unfreeze after it time o…
lcsmuller Dec 6, 2021
38b52cb
chore(test-discord-async.c): asynchronous infinite spamming
lcsmuller Dec 6, 2021
bee337f
style(discord-channel.c): ANSI
lcsmuller Dec 6, 2021
6618c1a
feat(specs/discord/gateway.json): add DISCORD_GATEWAY_CLOSE_REASON_RE…
lcsmuller Dec 6, 2021
81bae31
chore(specs-code): update to match 6618c1a2
lcsmuller Dec 6, 2021
d6b2e57
fix(discord-gateway.c): use opcode 4900 for reconnect
lcsmuller Dec 6, 2021
681ceaf
fix(user-agent.c): curl_mime_free() should be called on conn's stop
lcsmuller Dec 6, 2021
84f0a9a
refactor(websockets): ws_start() initialize the multi handle, ws_end()
lcsmuller Dec 6, 2021
7f4bb04
chore: update to match 84f0a9a8
lcsmuller Dec 6, 2021
37970be
feat(discord-adapter-request.c): add discord_request_pause_all() for …
lcsmuller Dec 6, 2021
98a8764
wip: support ANSI syntax
lcsmuller Dec 6, 2021
3009a01
fix(discord-emoji.c): wrong parameter address
lcsmuller Dec 7, 2021
7012a5a
chore: delete stale/redundant/unused files
lcsmuller Dec 7, 2021
5357711
chore(test-slack-ws.c): move from 'tmp'
lcsmuller Dec 7, 2021
0185a29
fix(test-slack-ws.c): incompatible callback signature
lcsmuller Dec 7, 2021
334fdb2
refactor: shorten user-agent.c symbols
lcsmuller Dec 7, 2021
1226126
refactor(user-agent): consistency with function naming
lcsmuller Dec 7, 2021
d7feb2f
feat(discord-adapter-request.c): if set, async callback receive respo…
lcsmuller Dec 7, 2021
5af0a43
refactor: improve naming consistency and get rid of unintuitive NTL_T…
lcsmuller Dec 7, 2021
9034ce3
refactor(discord-adapter-request.c): change discord_async_cb signatur…
lcsmuller Dec 7, 2021
672d1a4
fix(discord): idle queue must be heap-allocated to ensure its shared …
lcsmuller Dec 7, 2021
b6186de
docs(discord): move 'Event Scheduling' functions into its own doxygen…
lcsmuller Dec 7, 2021
540489c
refactor(discord): move discord_set_async() to discord-adapter.c and …
lcsmuller Dec 7, 2021
82a9a40
feat(discord-adapter-request.c): use recycleable buffer for callback …
lcsmuller Dec 7, 2021
8783f66
refactor(discord): reorg
lcsmuller Dec 7, 2021
a066ea0
feat(discord): add discord_create_message_async()
lcsmuller Dec 8, 2021
7288f49
chore(test-discord-async.c): update to match a066ea0f
lcsmuller Dec 8, 2021
55ad445
fix(discord-adapter-ratelimit.c): obtaining length of major parameter
lcsmuller Dec 8, 2021
ad42e63
refactor(user-agent): remove ua_reqheader_del(), make code ANSI C com…
lcsmuller Dec 8, 2021
8fc765a
style(common): ANSI
lcsmuller Dec 8, 2021
3fa4daa
wip: stackful ua_conn
lcsmuller Dec 8, 2021
e9d0650
refactor(common): rename ORCA_NO_RESPONSE to ORCA_CURL_NO_RESPONSE
lcsmuller Dec 9, 2021
3fcdae6
fix(discord-adapter-ratelimit.c): UB for types with system-dependent …
lcsmuller Dec 9, 2021
62f557d
fix(discord-adapter-request.c): 3fcdae and reset 'conn' values after …
lcsmuller Dec 9, 2021
9c6517d
fix(websockets.c): don't free multi handle at ws_end(), in case we mi…
lcsmuller Dec 9, 2021
831e905
fix(discord-adapter-request.c): enqueue again on read error, build bu…
lcsmuller Dec 9, 2021
ee2d80d
chore(test-discord-async.c): update
lcsmuller Dec 9, 2021
234f6c8
refactor(user-agent): rename ua_conn_get_results() to ua_info_extract…
lcsmuller Dec 10, 2021
ae9ed41
feat(discord): replace struct ua_resp_handle with the more flexible s…
lcsmuller Dec 10, 2021
2b595b0
chore(test-discord-async.c): match ae9ed
lcsmuller Dec 10, 2021
561eb2b
fix(bot-fetch-messages.c): dereferencing null-pointer
lcsmuller Dec 10, 2021
29db8c0
feat(user-agent): struct ua_info stores the request error code
lcsmuller Dec 10, 2021
37a9b44
refactor(discord-internal): move 'struct discord_adapter' components …
lcsmuller Dec 10, 2021
9431393
refactor(bot-shell.c): simplify and use async
lcsmuller Dec 10, 2021
c6c5af2
chore(.clang-format): add comment
lcsmuller Dec 10, 2021
6076bf1
feat(discord): enable sending files over the multiplexer
lcsmuller Dec 10, 2021
6b64e30
chore(bot-shell.c): redundant check
lcsmuller Dec 10, 2021
9ee7601
docs(discord.h): improve discord_set_on_command() and discord_set_on_…
lcsmuller Dec 10, 2021
2b9df8c
refactor(bot-shell.c): move attachments outside of embed and use disc…
lcsmuller Dec 10, 2021
1888b31
style(bot-shell.c): .clang-format
lcsmuller Dec 10, 2021
22d231c
feat(types.h): add CONTAINEROF() macro
lcsmuller Dec 12, 2021
a10583d
refactor(websockets.c): remove misleading error
lcsmuller Dec 12, 2021
f40c391
refactor(discord): rename 'discord_request' to 'discord_context'
lcsmuller Dec 12, 2021
7a3cd42
refactor(types): add ORCA_EXPECT() macro, remove ORCA_MISSING_PARAMET…
lcsmuller Dec 12, 2021
30dcfb2
refactor: make use of ORCA_EXPECT() to improve consistency and readab…
lcsmuller Dec 12, 2021
d7dafca
refactor(discord): replace exposed 'ja_u64**' type with 'u64_snowflak…
lcsmuller Dec 12, 2021
7475497
chore(bot-echo.c): simplify
lcsmuller Dec 12, 2021
2366a28
chore(bot-echo.c): should be discord_create_message_async()
lcsmuller Dec 12, 2021
aa380c3
chore(discord-user.c): remove sb_discord_get_current_user()
lcsmuller Dec 12, 2021
657f3ae
chore(test-discord-async.c): match to most recent
lcsmuller Dec 12, 2021
ad16125
fix(discord-channel.c): UB when iterating over a list without checkin…
lcsmuller Dec 12, 2021
85f2d66
refactor(websockets): rename cws_reqheader_add() -> cws_add_header(),…
lcsmuller Dec 12, 2021
baa26dc
refactor(discord): keep ws_timestamp_update() value stored to save on…
lcsmuller Dec 12, 2021
27cdf1c
fix(discord-gateway): 'now' timestamp must be shared between copies *…
lcsmuller Dec 12, 2021
2140fbd
refactor!(discord): remove bot parameter from callbacks, instead call…
lcsmuller Dec 13, 2021
8631725
chore(discord): consolidate 2140f changes
lcsmuller Dec 13, 2021
24afd84
fix(user-agent.c): UB on _ua_conn_respheader_cb(), strings aren't nul…
lcsmuller Dec 13, 2021
d31a738
chore(discord-adapter-request.c): remove leftover asserts
lcsmuller Dec 13, 2021
c5b6401
fix(user-agent.c): skipping extra char
lcsmuller Dec 13, 2021
e14bca2
fix(discord): remove redundant const specifier on callback scalars
lcsmuller Dec 13, 2021
9c171f9
chore(examples): update to match e14bca
lcsmuller Dec 13, 2021
a0c3abc
feat(websockets): enable CURLOPT_NOSIGNAL, more descriptive errors, l…
lcsmuller Dec 13, 2021
cad4dd7
fix(websockets): macro typo
lcsmuller Dec 13, 2021
5b09631
docs(discord-adapter-request.c): add relevant TODO
lcsmuller Dec 13, 2021
e291bdd
refactor!(user-agent): rename ua_run() to ua_easy_run() and add discl…
lcsmuller Dec 13, 2021
1cfef9c
chore: match e291b
lcsmuller Dec 13, 2021
ccb2c89
fix(discord-adapter.c): fallback to read-only blank attr in case of NULL
lcsmuller Dec 13, 2021
ce31ed7
refactor(github): make it consistent with discord codebase
lcsmuller Dec 13, 2021
f80ef17
fix(bot-elitebgs.c): use ua_easy_run()
lcsmuller Dec 14, 2021
6befd44
fix(test-cee.c): use ua_easy_run()
lcsmuller Dec 14, 2021
787de66
added functionality for guild_on_(create/update/delete) (#751)
Anotra Dec 14, 2021
7936266
refactor(discord-adapter): rename discord_bucket_cooldown() to discor…
lcsmuller Dec 14, 2021
014c9dd
fix(discord-adapter-request.c): update 'now' timestamp before populat…
lcsmuller Dec 14, 2021
f412467
chore(test-discord-ws.c): test ratelimiting on single-threaded blocki…
lcsmuller Dec 14, 2021
ac1c2f9
refactor(discord): join 'discord_gateway' .status field to .session, …
lcsmuller Dec 14, 2021
bf1199b
refactor(discord): move bot structure (struct discord_gateway -> stru…
lcsmuller Dec 14, 2021
6d3d21f
chore(common): unnecessary do while (0) wrapping over macros
lcsmuller Dec 14, 2021
74543bd
refactor!(websockets): add extra field for obtaining timestamp, renam…
lcsmuller Dec 14, 2021
b179e66
chore: match 74543
lcsmuller Dec 14, 2021
b33c726
fix(discord-gateway.c): wrong bitwise op
lcsmuller Dec 14, 2021
22aafa3
refactor!(websockets): rid of ws_start() last arguments, ws_init() will
lcsmuller Dec 15, 2021
6e5d530
chore: match 22aaf
lcsmuller Dec 15, 2021
9844435
wip(discord): merge struct discord_request to struct discord_adapter
lcsmuller Dec 15, 2021
ef62177
refactor(discord): finish transitioning 'discord_request' references …
lcsmuller Dec 15, 2021
c77d54e
chore(bot-voice): include discord-internal.h instead
lcsmuller Dec 15, 2021
e39b112
wip(discord-gateway.c): disable possibly wrong ratelimiting logic
lcsmuller Dec 15, 2021
cc093aa
refactor(discord-gateway.c): simplify on_dispatch (#752)
Anotra Dec 15, 2021
3c3bfd0
fix(discord): discord_adapter_pause_all() is unnecessary after decoup…
lcsmuller Dec 15, 2021
9026d63
chore(discord-gateway.c): rollback from #752, my bad @Anotra
lcsmuller Dec 15, 2021
d431d1a
chore(cee-utils): get latest
lcsmuller Dec 15, 2021
c3f4ada
fix(discord): incomplete type
lcsmuller Dec 15, 2021
9310c4b
feat(user-agent): add 'struct ua_conn_attr' for setting connection at…
lcsmuller Dec 16, 2021
675ffc0
refactor(user-agent.c): simplify _ua_conn_set_url()
lcsmuller Dec 16, 2021
76c2a9f
refactor: match codebase to 9310c
lcsmuller Dec 16, 2021
164d0e0
chore(slack, github, reddit): move request functions to single file
lcsmuller Dec 16, 2021
c8f2270
chore(specs): shorten naming
lcsmuller Dec 16, 2021
eb72805
chore(specs-code): match latest
lcsmuller Dec 16, 2021
7949878
chore: reorg
lcsmuller Dec 16, 2021
f02e748
chore(specs): generate params for slack
lcsmuller Dec 16, 2021
5cfe339
chore(specs-code): update to f02e74
lcsmuller Dec 16, 2021
5c848a2
fix: undefined retry value
lcsmuller Dec 17, 2021
d697da3
feat: rename types.[c|h] to common.[c|h], add orca_global_init() and …
lcsmuller Dec 17, 2021
beeb814
chore(discord): match to d697d
lcsmuller Dec 17, 2021
4a0309b
refactor(js_user-agent): rename jsua_run() to jsua_easy_run()
lcsmuller Dec 17, 2021
3f51291
fix(discord-gateway.c): scheduler callback shouldn't be skipped
lcsmuller Dec 17, 2021
a6598e8
refactor!(slack): make it consistent with the codebase
lcsmuller Dec 17, 2021
4508eaf
chore: move initialization macro to single-file where it should be used
lcsmuller Dec 17, 2021
a16f288
chore(discord): merge request functions into a single file
lcsmuller Dec 17, 2021
3617c89
chore(discord): rename file
lcsmuller Dec 17, 2021
b00bbf2
refactor: move macros to discord-restapi.c
lcsmuller Dec 17, 2021
49b2b82
refactor(discord-misc): move discord_disconnect_member() to discord-r…
lcsmuller Dec 17, 2021
f03def6
chore: .
lcsmuller Dec 17, 2021
db54795
feat(discord): make discord_async_next() public
lcsmuller Dec 18, 2021
669227e
chore(discord): match to db547
lcsmuller Dec 18, 2021
bd1d6a5
refactor(examples): replace deprecated discord_global_init() and disc…
lcsmuller Dec 18, 2021
3ec6f8c
Merge branch 'master' into multiplex
lcsmuller Dec 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# ORCA-FORMATTING Starts here.
# ORCA-FORMATTING
# Requires clang-format 10 (at least)

Language: Cpp
# BasedOnStyle: Mozilla
AccessModifierOffset: -2
Expand All @@ -10,12 +12,12 @@ AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: false
# AlwaysBreakAfterDefinitionReturnType: TopLevel
AlwaysBreakAfterReturnType: TopLevelDefinitions
# AlwaysBreakAfterReturnType: None # enable for 'main' files
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
Expand All @@ -32,7 +34,7 @@ BraceWrapping:
BeforeCatch: false
BeforeElse: true
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ GITHUB_SRC := $(wildcard github-*.c $(SPECS_WDIR)/github/*.c)
GITHUB_OBJS := $(GITHUB_SRC:%.c=$(OBJDIR)/%.o)
REDDIT_SRC := $(wildcard reddit-*.c $(SPECS_WDIR)/reddit/*.c)
REDDIT_OBJS := $(REDDIT_SRC:%.c=$(OBJDIR)/%.o)
SLACK_SRC := $(wildcard slack-*.c)
SLACK_SRC := $(wildcard slack-*.c $(SPECS_WDIR)/slack/*.c)
SLACK_OBJS := $(SLACK_SRC:%.c=$(OBJDIR)/%.o)

# API libs cflags
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ Orca's implementation has minimum external dependencies to make bot deployment d
#include <string.h> // strcmp()
#include <orca/discord.h>

void on_ready(struct discord *client, const struct discord_user *bot)
void on_ready(struct discord *client)
{
const struct discord_user *bot = discord_get_self(client);
log_info("Logged in as %s!", bot->username);
}

void on_message(struct discord *client,
const struct discord_user *bot,
const struct discord_message *msg)
void on_message(struct discord *client, const struct discord_message *msg)
{
// if message content is equal to 'ping', then the bot will respond with 'pong'.
if (0 == strcmp(msg->content, "ping")) {
if (0 == strcmp(msg->content, "ping")) { // if 'ping' received, reply with 'pong'
struct discord_create_message_params params = { .content = "pong" };

discord_async_next(client, NULL); // make next request non-blocking (OPTIONAL)
discord_create_message(client, msg->channel_id, &params, NULL);
}
}
Expand Down Expand Up @@ -164,7 +164,6 @@ $ sudo make install
Included headers must be `orca/` prefixed:
```c
#include <orca/discord.h>
#include <orca/github.h>
```

### Standalone executable
Expand Down
105 changes: 63 additions & 42 deletions cee-utils/cee-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
#include "json-actor.h"
#include "clock.h"


char*
char *
cee_load_whole_file_fp(FILE *fp, size_t *len)
{
fseek(fp, 0, SEEK_END);
Expand All @@ -35,21 +34,20 @@ cee_load_whole_file_fp(FILE *fp, size_t *len)
return str;
}

char*
char *
cee_load_whole_file(const char filename[], size_t *len)
{
FILE *fp = fopen(filename,"rb");
FILE *fp = fopen(filename, "rb");
VASSERT_S(NULL != fp, "%s '%s'\n", strerror(errno), filename);
char *str = cee_load_whole_file_fp(fp, len);
fclose(fp);
return str;
}

int
cee_dati_from_fjson(
char filename[],
void *p_data,
void (from_json_cb)(char *str, size_t len, void *p_data))
cee_dati_from_fjson(char filename[],
void *p_data,
void(from_json_cb)(char *str, size_t len, void *p_data))
{
size_t len;
char *json = cee_load_whole_file(filename, &len);
Expand All @@ -62,13 +60,26 @@ cee_dati_from_fjson(
return 1;
}

void
cee_sized_buffer_from_json(char *str, size_t len, struct sized_buffer *buf)
{
char *dest = NULL;

cee_strndup(str, len, &dest);
buf->start = dest;
buf->size = len;
}

static char *
stat_to_type(const struct stat *st)
{
switch (st->st_mode & S_IFMT) {
case S_IFREG: return "file";
case S_IFDIR: return "folder";
default: return NULL;
case S_IFREG:
return "file";
case S_IFDIR:
return "folder";
default:
return NULL;
}
}

Expand All @@ -84,25 +95,25 @@ cee_iso8601_to_unix_ms(char *str, size_t len, uint64_t *p_value)
char tz_operator = 'Z';
int tz_hour = 0, tz_min = 0;
sscanf(str, "%d-%d-%dT%d:%d:%lf%c%d:%d", /* ISO-8601 complete format */
&tm.tm_year, &tm.tm_mon, &tm.tm_mday, /* Date */
&tm.tm_hour, &tm.tm_min, &seconds, /* Time */
&tz_operator, &tz_hour, &tz_min); /* Timezone */
&tm.tm_year, &tm.tm_mon, &tm.tm_mday, /* Date */
&tm.tm_hour, &tm.tm_min, &seconds, /* Time */
&tz_operator, &tz_hour, &tz_min); /* Timezone */

tm.tm_mon--; /* struct tm takes month from 0 to 11 */
tm.tm_year -= 1900; /* struct tm takes years from 1900 */

uint64_t res = (((uint64_t) mktime(&tm) - timezone) * 1000)
+ (uint64_t) round(seconds * 1000.0);
uint64_t res = (((uint64_t)mktime(&tm) - timezone) * 1000)
+ (uint64_t)round(seconds * 1000.0);
switch (tz_operator) {
case '+': /* Add hours and minutes */
res += (tz_hour * 60 + tz_min) * 60 * 1000;
break;
res += (tz_hour * 60 + tz_min) * 60 * 1000;
break;
case '-': /* Subtract hours and minutes */
res -= (tz_hour * 60 + tz_min) * 60 * 1000;
break;
res -= (tz_hour * 60 + tz_min) * 60 * 1000;
break;
case 'Z': /* UTC, don't do anything */
default: /* @todo should we check for error ? */
break;
break;
}

*p_value = res;
Expand All @@ -120,32 +131,35 @@ cee_unix_ms_to_iso8601(char *str, size_t len, uint64_t *p_value)
struct tm buf;
struct tm *tm = localtime_r(&seconds, &buf);

return snprintf(str, len,
"%d-%.2d-%dT%.2d:%.2d:%.2d.%.3dZ", /* ISO-8601 complete format */
return snprintf(
str, len, "%d-%.2d-%dT%.2d:%.2d:%.2d.%.3dZ", /* ISO-8601 complete format */
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, /* Date */
tm->tm_hour, tm->tm_min, tm->tm_sec, millis); /* Time */
}

int
cee_strtou64(char *str, size_t len, uint64_t *p_value)
cee_strtou64(char *str, size_t len, uint64_t *p_value)
{
char fmt[512];
int ret = snprintf(fmt, sizeof(fmt), "%%%zu"SCNu64, len);
int ret = snprintf(fmt, sizeof(fmt), "%%%zu" SCNu64, len);
if (ret >= sizeof(fmt)) return 0;
return sscanf(str, fmt, p_value) != EOF;
}

int
cee_u64tostr(char *str, size_t len, uint64_t *p_value) {
return snprintf(str, len, "%" PRIu64 , *p_value);
cee_u64tostr(char *str, size_t len, uint64_t *p_value)
{
return snprintf(str, len, "%" PRIu64, *p_value);
}

int
cee_strndup(char *src, size_t len, char **p_dest)
cee_strndup(char *src, size_t len, char **p_dest)
{
*p_dest = malloc(len + 1);

memcpy(*p_dest, src, len);
(*p_dest)[len] = '\0';

return 1;
}

Expand Down Expand Up @@ -173,12 +187,12 @@ cee_timestamp_ms(void)
{
struct PsnipClockTimespec t;
if (0 == psnip_clock_get_time(PSNIP_CLOCK_TYPE_WALL, &t)) {
return (uint64_t)t.seconds*1000 + (uint64_t)t.nanoseconds/1000000;
return (uint64_t)t.seconds * 1000 + (uint64_t)t.nanoseconds / 1000000;
}
return 0ULL;
}

char*
char *
cee_timestamp_str(char *p_str, int len)
{
time_t t = time(NULL);
Expand All @@ -199,31 +213,36 @@ cee_str_bounds_check(const char *str, const size_t threshold_len)
size_t i;
if (!str) return -1; /* Missing string */

for (i=0; i < threshold_len; ++i) {
for (i = 0; i < threshold_len; ++i) {
if ('\0' == str[i]) return i; /* bound check succeeded */
}
return 0; /* bound check failed */
}

char*
cee_join_strings(char** strings, const size_t nmemb, const char delim[], const size_t wordlen, const size_t maxlen)
char *
cee_join_strings(char **strings,
const size_t nmemb,
const char delim[],
const size_t wordlen,
const size_t maxlen)
{
size_t i;
char *buf = malloc(maxlen);
char *cur = buf, * const end = cur + maxlen;
char *cur = buf, *const end = cur + maxlen;

for (i=0; i < nmemb; ++i) {
VASSERT_S(cee_str_bounds_check(strings[i], wordlen) > 0, \
"'%s' exceeds threshold of %zu characters", strings[i], wordlen);
cur += snprintf(cur, end-cur, "%s%s", strings[i], delim);
for (i = 0; i < nmemb; ++i) {
VASSERT_S(cee_str_bounds_check(strings[i], wordlen) > 0,
"'%s' exceeds threshold of %zu characters", strings[i], wordlen);
cur += snprintf(cur, end - cur, "%s%s", strings[i], delim);
ASSERT_S(cur < end, "Out of bounds write attempt");
}
*(cur - strlen(delim)) = '\0';

return buf;
}

void cee_gen_readlink(char *linkbuf, size_t linkbuf_size)
void
cee_gen_readlink(char *linkbuf, size_t linkbuf_size)
{
ssize_t r;
r = readlink("/proc/self/exe", linkbuf, linkbuf_size);
Expand All @@ -236,11 +255,13 @@ void cee_gen_readlink(char *linkbuf, size_t linkbuf_size)
fprintf(stderr, "symlink size is greater than %zu\n", linkbuf_size);
exit(EXIT_FAILURE);
}
linkbuf[r]='\0';
linkbuf[r] = '\0';

return;
}

void cee_gen_dirname(char *linkbuf) {
*strrchr(linkbuf, '/')='\0';
void
cee_gen_dirname(char *linkbuf)
{
*strrchr(linkbuf, '/') = '\0';
}
Loading