add ngc related unpack functions

This commit is contained in:
Green Sky 2023-12-19 17:25:35 +01:00
parent b2315c50e0
commit 2b0dc0f46b
No known key found for this signature in database
4 changed files with 174 additions and 1 deletions

View File

@ -10,6 +10,7 @@
#include "../toxcore/tox.h"
#include "../toxcore/tox_dispatch.h"
#include "../toxcore/tox_events.h"
#include "../toxcore/tox_unpack.h"
#include "auto_test_support.h"
#include "check_compat.h"
@ -160,9 +161,22 @@ static void test_tox_events(void)
}
}
static void fake_test_unpack(void)
{
// TODO(Green-Sky): add proper unpack tests and/or implement ngc events
(void)tox_unpack_group_privacy_state;
(void)tox_unpack_group_privacy_state;
(void)tox_unpack_group_voice_state;
(void)tox_unpack_group_topic_lock;
(void)tox_unpack_group_join_fail;
(void)tox_unpack_group_mod_event;
(void)tox_unpack_group_exit_type;
}
int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);
test_tox_events();
fake_test_unpack();
return 0;
}

View File

@ -1 +1 @@
8cb8b2f7bbc0ce71551365ed72ae468c731eafdce93e01d8c9a04ed5d904fcd9 /usr/local/bin/tox-bootstrapd
21cf23b1a2e46712663dc4f8daa322991af51b9e82626a127cf1bc8dc583b598 /usr/local/bin/tox-bootstrapd

View File

@ -129,3 +129,156 @@ bool tox_unpack_user_status(Bin_Unpack *bu, Tox_User_Status *val)
*val = tox_user_status_from_int(u32);
return true;
}
static Tox_Group_Privacy_State tox_group_privacy_state_from_int(uint32_t value)
{
switch (value) {
case 0:
return TOX_GROUP_PRIVACY_STATE_PUBLIC;
case 1:
return TOX_GROUP_PRIVACY_STATE_PRIVATE;
default:
return TOX_GROUP_PRIVACY_STATE_PRIVATE;
}
}
bool tox_unpack_group_privacy_state(Bin_Unpack *bu, Tox_Group_Privacy_State *val)
{
uint32_t u32;
if (!bin_unpack_u32(bu, &u32)) {
return false;
}
*val = tox_group_privacy_state_from_int(u32);
return true;
}
static Tox_Group_Voice_State tox_group_voice_state_from_int(uint32_t value)
{
switch (value) {
case 0:
return TOX_GROUP_VOICE_STATE_ALL;
case 1:
return TOX_GROUP_VOICE_STATE_MODERATOR;
case 2:
return TOX_GROUP_VOICE_STATE_FOUNDER;
default:
return TOX_GROUP_VOICE_STATE_FOUNDER;
}
}
bool tox_unpack_group_voice_state(Bin_Unpack *bu, Tox_Group_Voice_State *val)
{
uint32_t u32;
if (!bin_unpack_u32(bu, &u32)) {
return false;
}
*val = tox_group_voice_state_from_int(u32);
return true;
}
static Tox_Group_Topic_Lock tox_group_topic_lock_from_int(uint32_t value)
{
switch (value) {
case 0:
return TOX_GROUP_TOPIC_LOCK_ENABLED;
case 1:
return TOX_GROUP_TOPIC_LOCK_DISABLED;
default:
return TOX_GROUP_TOPIC_LOCK_ENABLED;
}
}
bool tox_unpack_group_topic_lock(Bin_Unpack *bu, Tox_Group_Topic_Lock *val)
{
uint32_t u32;
if (!bin_unpack_u32(bu, &u32)) {
return false;
}
*val = tox_group_topic_lock_from_int(u32);
return true;
}
static Tox_Group_Join_Fail tox_group_join_fail_from_int(uint32_t value)
{
switch (value) {
case 0:
return TOX_GROUP_JOIN_FAIL_PEER_LIMIT;
case 1:
return TOX_GROUP_JOIN_FAIL_INVALID_PASSWORD;
case 2:
return TOX_GROUP_JOIN_FAIL_UNKNOWN;
default:
return TOX_GROUP_JOIN_FAIL_UNKNOWN;
}
}
bool tox_unpack_group_join_fail(Bin_Unpack *bu, Tox_Group_Join_Fail *val)
{
uint32_t u32;
if (!bin_unpack_u32(bu, &u32)) {
return false;
}
*val = tox_group_join_fail_from_int(u32);
return true;
}
static Tox_Group_Mod_Event tox_group_mod_event_from_int(uint32_t value)
{
switch (value) {
case 0:
return TOX_GROUP_MOD_EVENT_KICK;
case 1:
return TOX_GROUP_MOD_EVENT_OBSERVER;
case 2:
return TOX_GROUP_MOD_EVENT_USER;
case 3:
return TOX_GROUP_MOD_EVENT_MODERATOR;
default:
return TOX_GROUP_MOD_EVENT_MODERATOR;
}
}
bool tox_unpack_group_mod_event(Bin_Unpack *bu, Tox_Group_Mod_Event *val)
{
uint32_t u32;
if (!bin_unpack_u32(bu, &u32)) {
return false;
}
*val = tox_group_mod_event_from_int(u32);
return true;
}
static Tox_Group_Exit_Type tox_group_exit_type_from_int(uint32_t value)
{
switch (value) {
case 0:
return TOX_GROUP_EXIT_TYPE_QUIT;
case 1:
return TOX_GROUP_EXIT_TYPE_TIMEOUT;
case 2:
return TOX_GROUP_EXIT_TYPE_DISCONNECTED;
case 3:
return TOX_GROUP_EXIT_TYPE_SELF_DISCONNECTED;
case 4:
return TOX_GROUP_EXIT_TYPE_KICK;
case 5:
return TOX_GROUP_EXIT_TYPE_SYNC_ERROR;
default:
return TOX_GROUP_EXIT_TYPE_QUIT;
}
}
bool tox_unpack_group_exit_type(Bin_Unpack *bu, Tox_Group_Exit_Type *val)
{
uint32_t u32;
if (!bin_unpack_u32(bu, &u32)) {
return false;
}
*val = tox_group_exit_type_from_int(u32);
return true;
}

View File

@ -14,5 +14,11 @@ non_null() bool tox_unpack_connection(Bin_Unpack *bu, Tox_Connection *val);
non_null() bool tox_unpack_file_control(Bin_Unpack *bu, Tox_File_Control *val);
non_null() bool tox_unpack_message_type(Bin_Unpack *bu, Tox_Message_Type *val);
non_null() bool tox_unpack_user_status(Bin_Unpack *bu, Tox_User_Status *val);
non_null() bool tox_unpack_group_privacy_state(Bin_Unpack *bu, Tox_Group_Privacy_State *val);
non_null() bool tox_unpack_group_voice_state(Bin_Unpack *bu, Tox_Group_Voice_State *val);
non_null() bool tox_unpack_group_topic_lock(Bin_Unpack *bu, Tox_Group_Topic_Lock *val);
non_null() bool tox_unpack_group_join_fail(Bin_Unpack *bu, Tox_Group_Join_Fail *val);
non_null() bool tox_unpack_group_mod_event(Bin_Unpack *bu, Tox_Group_Mod_Event *val);
non_null() bool tox_unpack_group_exit_type(Bin_Unpack *bu, Tox_Group_Exit_Type *val);
#endif // C_TOXCORE_TOXCORE_TOX_UNPACK_H