diff --git a/auto_tests/tox_dispatch_test.c b/auto_tests/tox_dispatch_test.c index 209e1378..98634369 100644 --- a/auto_tests/tox_dispatch_test.c +++ b/auto_tests/tox_dispatch_test.c @@ -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; } diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 2ed9bd8e..7b49f7c4 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -8cb8b2f7bbc0ce71551365ed72ae468c731eafdce93e01d8c9a04ed5d904fcd9 /usr/local/bin/tox-bootstrapd +21cf23b1a2e46712663dc4f8daa322991af51b9e82626a127cf1bc8dc583b598 /usr/local/bin/tox-bootstrapd diff --git a/toxcore/tox_unpack.c b/toxcore/tox_unpack.c index e3a461d6..09f5de2a 100644 --- a/toxcore/tox_unpack.c +++ b/toxcore/tox_unpack.c @@ -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; +} diff --git a/toxcore/tox_unpack.h b/toxcore/tox_unpack.h index 5f0b18ad..69bb207b 100644 --- a/toxcore/tox_unpack.h +++ b/toxcore/tox_unpack.h @@ -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