From e2c01e457bfb8a59537175c8fe17ca9ab1c9e3e1 Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 15 Jan 2024 17:15:17 +0000 Subject: [PATCH] refactor: Use enum-specific pack functions for enum values. It's more obvious this way. --- CMakeLists.txt | 2 + .../docker/tox-bootstrapd.sha256 | 2 +- other/event_tooling/generate_event_c.cpp | 46 ++++++++++++---- toxcore/BUILD.bazel | 14 +++++ toxcore/Makefile.inc | 2 + toxcore/events/conference_connected.c | 1 - toxcore/events/conference_invite.c | 6 +- toxcore/events/conference_message.c | 6 +- toxcore/events/conference_peer_list_changed.c | 1 - toxcore/events/conference_peer_name.c | 1 - toxcore/events/conference_title.c | 1 - toxcore/events/file_chunk_request.c | 1 - toxcore/events/file_recv.c | 1 - toxcore/events/file_recv_chunk.c | 1 - toxcore/events/file_recv_control.c | 6 +- toxcore/events/friend_connection_status.c | 6 +- toxcore/events/friend_lossless_packet.c | 1 - toxcore/events/friend_lossy_packet.c | 1 - toxcore/events/friend_message.c | 6 +- toxcore/events/friend_name.c | 1 - toxcore/events/friend_read_receipt.c | 1 - toxcore/events/friend_request.c | 1 - toxcore/events/friend_status.c | 6 +- toxcore/events/friend_status_message.c | 1 - toxcore/events/friend_typing.c | 1 - toxcore/events/group_custom_packet.c | 1 - toxcore/events/group_custom_private_packet.c | 1 - toxcore/events/group_invite.c | 1 - toxcore/events/group_join_fail.c | 6 +- toxcore/events/group_message.c | 6 +- toxcore/events/group_moderation.c | 6 +- toxcore/events/group_password.c | 1 - toxcore/events/group_peer_exit.c | 6 +- toxcore/events/group_peer_join.c | 1 - toxcore/events/group_peer_limit.c | 1 - toxcore/events/group_peer_name.c | 1 - toxcore/events/group_peer_status.c | 6 +- toxcore/events/group_privacy_state.c | 6 +- toxcore/events/group_private_message.c | 6 +- toxcore/events/group_self_join.c | 1 - toxcore/events/group_topic.c | 1 - toxcore/events/group_topic_lock.c | 6 +- toxcore/events/group_voice_state.c | 6 +- toxcore/events/self_connection_status.c | 6 +- toxcore/onion.c | 8 +-- toxcore/tox_pack.c | 55 +++++++++++++++++++ toxcore/tox_pack.h | 24 ++++++++ toxcore/tox_unpack.c | 22 ++++---- toxcore/tox_unpack.h | 22 ++++---- 49 files changed, 207 insertions(+), 109 deletions(-) create mode 100644 toxcore/tox_pack.c create mode 100644 toxcore/tox_pack.h diff --git a/CMakeLists.txt b/CMakeLists.txt index aaf6b375..5eefb821 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -338,6 +338,8 @@ set(toxcore_SOURCES toxcore/tox.h toxcore/tox_private.c toxcore/tox_private.h + toxcore/tox_pack.c + toxcore/tox_pack.h toxcore/tox_unpack.c toxcore/tox_unpack.h toxcore/util.c diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 512cf8de..fc02a5e4 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -50123098ff16637a19253e4ea24c0b7bc7d1ef35f6e7c9f2783bddd303a6c6f3 /usr/local/bin/tox-bootstrapd +0b904988d79b9576bb88c6c7316d107b5a61bd6119a0992ebd7c1fa43db70abf /usr/local/bin/tox-bootstrapd diff --git a/other/event_tooling/generate_event_c.cpp b/other/event_tooling/generate_event_c.cpp index 4161d138..92cab072 100644 --- a/other/event_tooling/generate_event_c.cpp +++ b/other/event_tooling/generate_event_c.cpp @@ -56,15 +56,31 @@ std::string bin_pack_name_from_type(const std::string& type) { return "bin_pack_u8"; } else if (type == "bool") { return "bin_pack_bool"; - // only unpack is special TODO(Green-Sky): should we change that? - //} else if (type == "Tox_User_Status") { - //return "tox_pack_user_status"; - //} else if (type == "Tox_Conference_Type") { - //return "tox_pack_conference_type"; + } else if (type == "Tox_User_Status") { + return "tox_user_status_pack"; + } else if (type == "Tox_Conference_Type") { + return "tox_conference_type_pack"; + } else if (type == "Tox_Message_Type") { + return "tox_message_type_pack"; + } else if (type == "Tox_File_Control") { + return "tox_file_control_pack"; + } else if (type == "Tox_Connection") { + return "tox_connection_pack"; + } else if (type == "Tox_Group_Privacy_State") { + return "tox_group_privacy_state_pack"; + } else if (type == "Tox_Group_Voice_State") { + return "tox_group_voice_state_pack"; + } else if (type == "Tox_Group_Topic_Lock") { + return "tox_group_topic_lock_pack"; + } else if (type == "Tox_Group_Join_Fail") { + return "tox_group_join_fail_pack"; + } else if (type == "Tox_Group_Mod_Event") { + return "tox_group_mod_event_pack"; + } else if (type == "Tox_Group_Exit_Type") { + return "tox_group_exit_type_pack"; } else { - //std::cerr << "unknown type " << type << "\n"; - //exit(1); - // assume enum -> u32 + std::cerr << "unknown type " << type << "\n"; + exit(1); return "bin_pack_u32"; } } @@ -164,6 +180,7 @@ void generate_event_impl(const std::string& event_name, const std::vector" << t.name << ")"; + if (t.type.rfind("Tox_", 0) == 0) { + f << "(event->" << t.name << ", bp)"; + } else { + f << "(bp, event->" << t.name << ")"; + } }, [&](const EventTypeByteRange& t) { f << "bin_pack_bin(bp, event->" << t.name_data << ", event->" << t.name_length << ")"; @@ -361,7 +381,11 @@ void generate_event_impl(const std::string& event_name, const std::vector" << t.name << ")"; + if (t.type.rfind("Tox_", 0) == 0) { + f << "(&event->" << t.name << ", bu)"; + } else { + f << "(bu, &event->" << t.name << ")"; + } }, [&](const EventTypeByteRange& t) { f << "bin_unpack_bin(bu, &event->" << t.name_data << ", &event->" << t.name_length << ")"; diff --git a/toxcore/BUILD.bazel b/toxcore/BUILD.bazel index 35139508..534ead32 100644 --- a/toxcore/BUILD.bazel +++ b/toxcore/BUILD.bazel @@ -892,6 +892,19 @@ cc_test( ], ) +cc_library( + name = "tox_pack", + srcs = ["tox_pack.c"], + hdrs = ["tox_pack.h"], + visibility = ["//c-toxcore:__subpackages__"], + deps = [ + ":attributes", + ":bin_pack", + ":ccompat", + ":tox", + ], +) + cc_library( name = "tox_unpack", srcs = ["tox_unpack.c"], @@ -926,6 +939,7 @@ cc_library( ":ccompat", ":mem", ":tox", + ":tox_pack", ":tox_unpack", "//c-toxcore/third_party:cmp", ], diff --git a/toxcore/Makefile.inc b/toxcore/Makefile.inc index 5783c91b..0663171f 100644 --- a/toxcore/Makefile.inc +++ b/toxcore/Makefile.inc @@ -94,6 +94,8 @@ libtoxcore_la_SOURCES = ../third_party/cmp/cmp.c \ ../toxcore/tox_event.c \ ../toxcore/tox_events.h \ ../toxcore/tox_events.c \ + ../toxcore/tox_pack.h \ + ../toxcore/tox_pack.c \ ../toxcore/tox_unpack.h \ ../toxcore/tox_unpack.c \ ../toxcore/tox_private.c \ diff --git a/toxcore/events/conference_connected.c b/toxcore/events/conference_connected.c index a43bccab..80834bf4 100644 --- a/toxcore/events/conference_connected.c +++ b/toxcore/events/conference_connected.c @@ -54,7 +54,6 @@ static void tox_event_conference_connected_destruct(Tox_Event_Conference_Connect bool tox_event_conference_connected_pack( const Tox_Event_Conference_Connected *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_u32(bp, event->conference_number); } diff --git a/toxcore/events/conference_invite.c b/toxcore/events/conference_invite.c index 9a0de842..30d9ff99 100644 --- a/toxcore/events/conference_invite.c +++ b/toxcore/events/conference_invite.c @@ -14,6 +14,7 @@ #include "../mem.h" #include "../tox.h" #include "../tox_events.h" +#include "../tox_pack.h" #include "../tox_unpack.h" @@ -107,10 +108,9 @@ static void tox_event_conference_invite_destruct(Tox_Event_Conference_Invite *co bool tox_event_conference_invite_pack( const Tox_Event_Conference_Invite *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 3) && bin_pack_u32(bp, event->friend_number) - && bin_pack_u32(bp, event->type) + && tox_conference_type_pack(event->type, bp) && bin_pack_bin(bp, event->cookie, event->cookie_length); } @@ -124,7 +124,7 @@ static bool tox_event_conference_invite_unpack_into( } return bin_unpack_u32(bu, &event->friend_number) - && tox_conference_type_unpack(bu, &event->type) + && tox_conference_type_unpack(&event->type, bu) && bin_unpack_bin(bu, &event->cookie, &event->cookie_length); } diff --git a/toxcore/events/conference_message.c b/toxcore/events/conference_message.c index 654c8b26..818f555d 100644 --- a/toxcore/events/conference_message.c +++ b/toxcore/events/conference_message.c @@ -14,6 +14,7 @@ #include "../mem.h" #include "../tox.h" #include "../tox_events.h" +#include "../tox_pack.h" #include "../tox_unpack.h" @@ -121,11 +122,10 @@ static void tox_event_conference_message_destruct(Tox_Event_Conference_Message * bool tox_event_conference_message_pack( const Tox_Event_Conference_Message *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 4) && bin_pack_u32(bp, event->conference_number) && bin_pack_u32(bp, event->peer_number) - && bin_pack_u32(bp, event->type) + && tox_message_type_pack(event->type, bp) && bin_pack_bin(bp, event->message, event->message_length); } @@ -140,7 +140,7 @@ static bool tox_event_conference_message_unpack_into( return bin_unpack_u32(bu, &event->conference_number) && bin_unpack_u32(bu, &event->peer_number) - && tox_message_type_unpack(bu, &event->type) + && tox_message_type_unpack(&event->type, bu) && bin_unpack_bin(bu, &event->message, &event->message_length); } diff --git a/toxcore/events/conference_peer_list_changed.c b/toxcore/events/conference_peer_list_changed.c index 8748c021..37b97568 100644 --- a/toxcore/events/conference_peer_list_changed.c +++ b/toxcore/events/conference_peer_list_changed.c @@ -54,7 +54,6 @@ static void tox_event_conference_peer_list_changed_destruct(Tox_Event_Conference bool tox_event_conference_peer_list_changed_pack( const Tox_Event_Conference_Peer_List_Changed *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_u32(bp, event->conference_number); } diff --git a/toxcore/events/conference_peer_name.c b/toxcore/events/conference_peer_name.c index 3f9d7c97..27cba5ac 100644 --- a/toxcore/events/conference_peer_name.c +++ b/toxcore/events/conference_peer_name.c @@ -106,7 +106,6 @@ static void tox_event_conference_peer_name_destruct(Tox_Event_Conference_Peer_Na bool tox_event_conference_peer_name_pack( const Tox_Event_Conference_Peer_Name *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 3) && bin_pack_u32(bp, event->conference_number) && bin_pack_u32(bp, event->peer_number) diff --git a/toxcore/events/conference_title.c b/toxcore/events/conference_title.c index 9e170059..1a00e644 100644 --- a/toxcore/events/conference_title.c +++ b/toxcore/events/conference_title.c @@ -106,7 +106,6 @@ static void tox_event_conference_title_destruct(Tox_Event_Conference_Title *conf bool tox_event_conference_title_pack( const Tox_Event_Conference_Title *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 3) && bin_pack_u32(bp, event->conference_number) && bin_pack_u32(bp, event->peer_number) diff --git a/toxcore/events/file_chunk_request.c b/toxcore/events/file_chunk_request.c index 7e02116d..a83bbd49 100644 --- a/toxcore/events/file_chunk_request.c +++ b/toxcore/events/file_chunk_request.c @@ -96,7 +96,6 @@ static void tox_event_file_chunk_request_destruct(Tox_Event_File_Chunk_Request * bool tox_event_file_chunk_request_pack( const Tox_Event_File_Chunk_Request *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 4) && bin_pack_u32(bp, event->friend_number) && bin_pack_u32(bp, event->file_number) diff --git a/toxcore/events/file_recv.c b/toxcore/events/file_recv.c index f18f064c..a870857c 100644 --- a/toxcore/events/file_recv.c +++ b/toxcore/events/file_recv.c @@ -134,7 +134,6 @@ static void tox_event_file_recv_destruct(Tox_Event_File_Recv *file_recv, const M bool tox_event_file_recv_pack( const Tox_Event_File_Recv *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 5) && bin_pack_u32(bp, event->friend_number) && bin_pack_u32(bp, event->file_number) diff --git a/toxcore/events/file_recv_chunk.c b/toxcore/events/file_recv_chunk.c index 7c1776d0..95731259 100644 --- a/toxcore/events/file_recv_chunk.c +++ b/toxcore/events/file_recv_chunk.c @@ -120,7 +120,6 @@ static void tox_event_file_recv_chunk_destruct(Tox_Event_File_Recv_Chunk *file_r bool tox_event_file_recv_chunk_pack( const Tox_Event_File_Recv_Chunk *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 4) && bin_pack_u32(bp, event->friend_number) && bin_pack_u32(bp, event->file_number) diff --git a/toxcore/events/file_recv_control.c b/toxcore/events/file_recv_control.c index 9e19b666..0fc26ae3 100644 --- a/toxcore/events/file_recv_control.c +++ b/toxcore/events/file_recv_control.c @@ -12,6 +12,7 @@ #include "../mem.h" #include "../tox.h" #include "../tox_events.h" +#include "../tox_pack.h" #include "../tox_unpack.h" @@ -83,11 +84,10 @@ static void tox_event_file_recv_control_destruct(Tox_Event_File_Recv_Control *fi bool tox_event_file_recv_control_pack( const Tox_Event_File_Recv_Control *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 3) && bin_pack_u32(bp, event->friend_number) && bin_pack_u32(bp, event->file_number) - && bin_pack_u32(bp, event->control); + && tox_file_control_pack(event->control, bp); } non_null() @@ -101,7 +101,7 @@ static bool tox_event_file_recv_control_unpack_into( return bin_unpack_u32(bu, &event->friend_number) && bin_unpack_u32(bu, &event->file_number) - && tox_file_control_unpack(bu, &event->control); + && tox_file_control_unpack(&event->control, bu); } diff --git a/toxcore/events/friend_connection_status.c b/toxcore/events/friend_connection_status.c index c6d577ae..4e158e0b 100644 --- a/toxcore/events/friend_connection_status.c +++ b/toxcore/events/friend_connection_status.c @@ -12,6 +12,7 @@ #include "../mem.h" #include "../tox.h" #include "../tox_events.h" +#include "../tox_pack.h" #include "../tox_unpack.h" @@ -69,10 +70,9 @@ static void tox_event_friend_connection_status_destruct(Tox_Event_Friend_Connect bool tox_event_friend_connection_status_pack( const Tox_Event_Friend_Connection_Status *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 2) && bin_pack_u32(bp, event->friend_number) - && bin_pack_u32(bp, event->connection_status); + && tox_connection_pack(event->connection_status, bp); } non_null() @@ -85,7 +85,7 @@ static bool tox_event_friend_connection_status_unpack_into( } return bin_unpack_u32(bu, &event->friend_number) - && tox_connection_unpack(bu, &event->connection_status); + && tox_connection_unpack(&event->connection_status, bu); } diff --git a/toxcore/events/friend_lossless_packet.c b/toxcore/events/friend_lossless_packet.c index ce8bedd0..a21af28c 100644 --- a/toxcore/events/friend_lossless_packet.c +++ b/toxcore/events/friend_lossless_packet.c @@ -92,7 +92,6 @@ static void tox_event_friend_lossless_packet_destruct(Tox_Event_Friend_Lossless_ bool tox_event_friend_lossless_packet_pack( const Tox_Event_Friend_Lossless_Packet *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 2) && bin_pack_u32(bp, event->friend_number) && bin_pack_bin(bp, event->data, event->data_length); diff --git a/toxcore/events/friend_lossy_packet.c b/toxcore/events/friend_lossy_packet.c index 13d328a1..efbf203b 100644 --- a/toxcore/events/friend_lossy_packet.c +++ b/toxcore/events/friend_lossy_packet.c @@ -92,7 +92,6 @@ static void tox_event_friend_lossy_packet_destruct(Tox_Event_Friend_Lossy_Packet bool tox_event_friend_lossy_packet_pack( const Tox_Event_Friend_Lossy_Packet *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 2) && bin_pack_u32(bp, event->friend_number) && bin_pack_bin(bp, event->data, event->data_length); diff --git a/toxcore/events/friend_message.c b/toxcore/events/friend_message.c index 8bb96747..ef917acb 100644 --- a/toxcore/events/friend_message.c +++ b/toxcore/events/friend_message.c @@ -14,6 +14,7 @@ #include "../mem.h" #include "../tox.h" #include "../tox_events.h" +#include "../tox_pack.h" #include "../tox_unpack.h" @@ -107,10 +108,9 @@ static void tox_event_friend_message_destruct(Tox_Event_Friend_Message *friend_m bool tox_event_friend_message_pack( const Tox_Event_Friend_Message *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 3) && bin_pack_u32(bp, event->friend_number) - && bin_pack_u32(bp, event->type) + && tox_message_type_pack(event->type, bp) && bin_pack_bin(bp, event->message, event->message_length); } @@ -124,7 +124,7 @@ static bool tox_event_friend_message_unpack_into( } return bin_unpack_u32(bu, &event->friend_number) - && tox_message_type_unpack(bu, &event->type) + && tox_message_type_unpack(&event->type, bu) && bin_unpack_bin(bu, &event->message, &event->message_length); } diff --git a/toxcore/events/friend_name.c b/toxcore/events/friend_name.c index f7483d6c..d371e657 100644 --- a/toxcore/events/friend_name.c +++ b/toxcore/events/friend_name.c @@ -92,7 +92,6 @@ static void tox_event_friend_name_destruct(Tox_Event_Friend_Name *friend_name, c bool tox_event_friend_name_pack( const Tox_Event_Friend_Name *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 2) && bin_pack_u32(bp, event->friend_number) && bin_pack_bin(bp, event->name, event->name_length); diff --git a/toxcore/events/friend_read_receipt.c b/toxcore/events/friend_read_receipt.c index be90affe..f52fc37a 100644 --- a/toxcore/events/friend_read_receipt.c +++ b/toxcore/events/friend_read_receipt.c @@ -68,7 +68,6 @@ static void tox_event_friend_read_receipt_destruct(Tox_Event_Friend_Read_Receipt bool tox_event_friend_read_receipt_pack( const Tox_Event_Friend_Read_Receipt *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 2) && bin_pack_u32(bp, event->friend_number) && bin_pack_u32(bp, event->message_id); diff --git a/toxcore/events/friend_request.c b/toxcore/events/friend_request.c index cba261b3..70f468cb 100644 --- a/toxcore/events/friend_request.c +++ b/toxcore/events/friend_request.c @@ -93,7 +93,6 @@ static void tox_event_friend_request_destruct(Tox_Event_Friend_Request *friend_r bool tox_event_friend_request_pack( const Tox_Event_Friend_Request *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 2) && bin_pack_bin(bp, event->public_key, TOX_PUBLIC_KEY_SIZE) && bin_pack_bin(bp, event->message, event->message_length); diff --git a/toxcore/events/friend_status.c b/toxcore/events/friend_status.c index 0fe938bb..55e60657 100644 --- a/toxcore/events/friend_status.c +++ b/toxcore/events/friend_status.c @@ -12,6 +12,7 @@ #include "../mem.h" #include "../tox.h" #include "../tox_events.h" +#include "../tox_pack.h" #include "../tox_unpack.h" @@ -69,10 +70,9 @@ static void tox_event_friend_status_destruct(Tox_Event_Friend_Status *friend_sta bool tox_event_friend_status_pack( const Tox_Event_Friend_Status *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 2) && bin_pack_u32(bp, event->friend_number) - && bin_pack_u32(bp, event->status); + && tox_user_status_pack(event->status, bp); } non_null() @@ -85,7 +85,7 @@ static bool tox_event_friend_status_unpack_into( } return bin_unpack_u32(bu, &event->friend_number) - && tox_user_status_unpack(bu, &event->status); + && tox_user_status_unpack(&event->status, bu); } diff --git a/toxcore/events/friend_status_message.c b/toxcore/events/friend_status_message.c index 7569f8c8..400f7ff8 100644 --- a/toxcore/events/friend_status_message.c +++ b/toxcore/events/friend_status_message.c @@ -92,7 +92,6 @@ static void tox_event_friend_status_message_destruct(Tox_Event_Friend_Status_Mes bool tox_event_friend_status_message_pack( const Tox_Event_Friend_Status_Message *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 2) && bin_pack_u32(bp, event->friend_number) && bin_pack_bin(bp, event->message, event->message_length); diff --git a/toxcore/events/friend_typing.c b/toxcore/events/friend_typing.c index 1bad7517..9b099974 100644 --- a/toxcore/events/friend_typing.c +++ b/toxcore/events/friend_typing.c @@ -68,7 +68,6 @@ static void tox_event_friend_typing_destruct(Tox_Event_Friend_Typing *friend_typ bool tox_event_friend_typing_pack( const Tox_Event_Friend_Typing *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 2) && bin_pack_u32(bp, event->friend_number) && bin_pack_bool(bp, event->typing); diff --git a/toxcore/events/group_custom_packet.c b/toxcore/events/group_custom_packet.c index ec35b439..acc8a391 100644 --- a/toxcore/events/group_custom_packet.c +++ b/toxcore/events/group_custom_packet.c @@ -106,7 +106,6 @@ static void tox_event_group_custom_packet_destruct(Tox_Event_Group_Custom_Packet bool tox_event_group_custom_packet_pack( const Tox_Event_Group_Custom_Packet *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 3) && bin_pack_u32(bp, event->group_number) && bin_pack_u32(bp, event->peer_id) diff --git a/toxcore/events/group_custom_private_packet.c b/toxcore/events/group_custom_private_packet.c index 150866f9..65d95a6f 100644 --- a/toxcore/events/group_custom_private_packet.c +++ b/toxcore/events/group_custom_private_packet.c @@ -106,7 +106,6 @@ static void tox_event_group_custom_private_packet_destruct(Tox_Event_Group_Custo bool tox_event_group_custom_private_packet_pack( const Tox_Event_Group_Custom_Private_Packet *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 3) && bin_pack_u32(bp, event->group_number) && bin_pack_u32(bp, event->peer_id) diff --git a/toxcore/events/group_invite.c b/toxcore/events/group_invite.c index 212eeadd..30e3429a 100644 --- a/toxcore/events/group_invite.c +++ b/toxcore/events/group_invite.c @@ -129,7 +129,6 @@ static void tox_event_group_invite_destruct(Tox_Event_Group_Invite *group_invite bool tox_event_group_invite_pack( const Tox_Event_Group_Invite *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 3) && bin_pack_u32(bp, event->friend_number) && bin_pack_bin(bp, event->invite_data, event->invite_data_length) diff --git a/toxcore/events/group_join_fail.c b/toxcore/events/group_join_fail.c index adbc5f78..88565680 100644 --- a/toxcore/events/group_join_fail.c +++ b/toxcore/events/group_join_fail.c @@ -12,6 +12,7 @@ #include "../mem.h" #include "../tox.h" #include "../tox_events.h" +#include "../tox_pack.h" #include "../tox_unpack.h" @@ -69,10 +70,9 @@ static void tox_event_group_join_fail_destruct(Tox_Event_Group_Join_Fail *group_ bool tox_event_group_join_fail_pack( const Tox_Event_Group_Join_Fail *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 2) && bin_pack_u32(bp, event->group_number) - && bin_pack_u32(bp, event->fail_type); + && tox_group_join_fail_pack(event->fail_type, bp); } non_null() @@ -85,7 +85,7 @@ static bool tox_event_group_join_fail_unpack_into( } return bin_unpack_u32(bu, &event->group_number) - && tox_group_join_fail_unpack(bu, &event->fail_type); + && tox_group_join_fail_unpack(&event->fail_type, bu); } diff --git a/toxcore/events/group_message.c b/toxcore/events/group_message.c index ff93001d..2bdad4ec 100644 --- a/toxcore/events/group_message.c +++ b/toxcore/events/group_message.c @@ -14,6 +14,7 @@ #include "../mem.h" #include "../tox.h" #include "../tox_events.h" +#include "../tox_pack.h" #include "../tox_unpack.h" @@ -135,11 +136,10 @@ static void tox_event_group_message_destruct(Tox_Event_Group_Message *group_mess bool tox_event_group_message_pack( const Tox_Event_Group_Message *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 5) && bin_pack_u32(bp, event->group_number) && bin_pack_u32(bp, event->peer_id) - && bin_pack_u32(bp, event->type) + && tox_message_type_pack(event->type, bp) && bin_pack_bin(bp, event->message, event->message_length) && bin_pack_u32(bp, event->message_id); } @@ -155,7 +155,7 @@ static bool tox_event_group_message_unpack_into( return bin_unpack_u32(bu, &event->group_number) && bin_unpack_u32(bu, &event->peer_id) - && tox_message_type_unpack(bu, &event->type) + && tox_message_type_unpack(&event->type, bu) && bin_unpack_bin(bu, &event->message, &event->message_length) && bin_unpack_u32(bu, &event->message_id); } diff --git a/toxcore/events/group_moderation.c b/toxcore/events/group_moderation.c index 91a2ff86..7ac46ffc 100644 --- a/toxcore/events/group_moderation.c +++ b/toxcore/events/group_moderation.c @@ -12,6 +12,7 @@ #include "../mem.h" #include "../tox.h" #include "../tox_events.h" +#include "../tox_pack.h" #include "../tox_unpack.h" @@ -97,12 +98,11 @@ static void tox_event_group_moderation_destruct(Tox_Event_Group_Moderation *grou bool tox_event_group_moderation_pack( const Tox_Event_Group_Moderation *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 4) && bin_pack_u32(bp, event->group_number) && bin_pack_u32(bp, event->source_peer_id) && bin_pack_u32(bp, event->target_peer_id) - && bin_pack_u32(bp, event->mod_type); + && tox_group_mod_event_pack(event->mod_type, bp); } non_null() @@ -117,7 +117,7 @@ static bool tox_event_group_moderation_unpack_into( return bin_unpack_u32(bu, &event->group_number) && bin_unpack_u32(bu, &event->source_peer_id) && bin_unpack_u32(bu, &event->target_peer_id) - && tox_group_mod_event_unpack(bu, &event->mod_type); + && tox_group_mod_event_unpack(&event->mod_type, bu); } diff --git a/toxcore/events/group_password.c b/toxcore/events/group_password.c index bdaa9244..cbfedd3c 100644 --- a/toxcore/events/group_password.c +++ b/toxcore/events/group_password.c @@ -92,7 +92,6 @@ static void tox_event_group_password_destruct(Tox_Event_Group_Password *group_pa bool tox_event_group_password_pack( const Tox_Event_Group_Password *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 2) && bin_pack_u32(bp, event->group_number) && bin_pack_bin(bp, event->password, event->password_length); diff --git a/toxcore/events/group_peer_exit.c b/toxcore/events/group_peer_exit.c index 2eed345e..fd56fd6c 100644 --- a/toxcore/events/group_peer_exit.c +++ b/toxcore/events/group_peer_exit.c @@ -14,6 +14,7 @@ #include "../mem.h" #include "../tox.h" #include "../tox_events.h" +#include "../tox_pack.h" #include "../tox_unpack.h" @@ -158,11 +159,10 @@ static void tox_event_group_peer_exit_destruct(Tox_Event_Group_Peer_Exit *group_ bool tox_event_group_peer_exit_pack( const Tox_Event_Group_Peer_Exit *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 5) && bin_pack_u32(bp, event->group_number) && bin_pack_u32(bp, event->peer_id) - && bin_pack_u32(bp, event->exit_type) + && tox_group_exit_type_pack(event->exit_type, bp) && bin_pack_bin(bp, event->name, event->name_length) && bin_pack_bin(bp, event->part_message, event->part_message_length); } @@ -178,7 +178,7 @@ static bool tox_event_group_peer_exit_unpack_into( return bin_unpack_u32(bu, &event->group_number) && bin_unpack_u32(bu, &event->peer_id) - && tox_group_exit_type_unpack(bu, &event->exit_type) + && tox_group_exit_type_unpack(&event->exit_type, bu) && bin_unpack_bin(bu, &event->name, &event->name_length) && bin_unpack_bin(bu, &event->part_message, &event->part_message_length); } diff --git a/toxcore/events/group_peer_join.c b/toxcore/events/group_peer_join.c index 43a1f19f..c587c179 100644 --- a/toxcore/events/group_peer_join.c +++ b/toxcore/events/group_peer_join.c @@ -68,7 +68,6 @@ static void tox_event_group_peer_join_destruct(Tox_Event_Group_Peer_Join *group_ bool tox_event_group_peer_join_pack( const Tox_Event_Group_Peer_Join *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 2) && bin_pack_u32(bp, event->group_number) && bin_pack_u32(bp, event->peer_id); diff --git a/toxcore/events/group_peer_limit.c b/toxcore/events/group_peer_limit.c index 9a256c15..9a2daa7e 100644 --- a/toxcore/events/group_peer_limit.c +++ b/toxcore/events/group_peer_limit.c @@ -68,7 +68,6 @@ static void tox_event_group_peer_limit_destruct(Tox_Event_Group_Peer_Limit *grou bool tox_event_group_peer_limit_pack( const Tox_Event_Group_Peer_Limit *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 2) && bin_pack_u32(bp, event->group_number) && bin_pack_u32(bp, event->peer_limit); diff --git a/toxcore/events/group_peer_name.c b/toxcore/events/group_peer_name.c index f0bfcc11..6d6f77db 100644 --- a/toxcore/events/group_peer_name.c +++ b/toxcore/events/group_peer_name.c @@ -106,7 +106,6 @@ static void tox_event_group_peer_name_destruct(Tox_Event_Group_Peer_Name *group_ bool tox_event_group_peer_name_pack( const Tox_Event_Group_Peer_Name *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 3) && bin_pack_u32(bp, event->group_number) && bin_pack_u32(bp, event->peer_id) diff --git a/toxcore/events/group_peer_status.c b/toxcore/events/group_peer_status.c index 90add7fa..2cfe32e0 100644 --- a/toxcore/events/group_peer_status.c +++ b/toxcore/events/group_peer_status.c @@ -12,6 +12,7 @@ #include "../mem.h" #include "../tox.h" #include "../tox_events.h" +#include "../tox_pack.h" #include "../tox_unpack.h" @@ -83,11 +84,10 @@ static void tox_event_group_peer_status_destruct(Tox_Event_Group_Peer_Status *gr bool tox_event_group_peer_status_pack( const Tox_Event_Group_Peer_Status *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 3) && bin_pack_u32(bp, event->group_number) && bin_pack_u32(bp, event->peer_id) - && bin_pack_u32(bp, event->status); + && tox_user_status_pack(event->status, bp); } non_null() @@ -101,7 +101,7 @@ static bool tox_event_group_peer_status_unpack_into( return bin_unpack_u32(bu, &event->group_number) && bin_unpack_u32(bu, &event->peer_id) - && tox_user_status_unpack(bu, &event->status); + && tox_user_status_unpack(&event->status, bu); } diff --git a/toxcore/events/group_privacy_state.c b/toxcore/events/group_privacy_state.c index 8267dc62..8623668b 100644 --- a/toxcore/events/group_privacy_state.c +++ b/toxcore/events/group_privacy_state.c @@ -12,6 +12,7 @@ #include "../mem.h" #include "../tox.h" #include "../tox_events.h" +#include "../tox_pack.h" #include "../tox_unpack.h" @@ -69,10 +70,9 @@ static void tox_event_group_privacy_state_destruct(Tox_Event_Group_Privacy_State bool tox_event_group_privacy_state_pack( const Tox_Event_Group_Privacy_State *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 2) && bin_pack_u32(bp, event->group_number) - && bin_pack_u32(bp, event->privacy_state); + && tox_group_privacy_state_pack(event->privacy_state, bp); } non_null() @@ -85,7 +85,7 @@ static bool tox_event_group_privacy_state_unpack_into( } return bin_unpack_u32(bu, &event->group_number) - && tox_group_privacy_state_unpack(bu, &event->privacy_state); + && tox_group_privacy_state_unpack(&event->privacy_state, bu); } diff --git a/toxcore/events/group_private_message.c b/toxcore/events/group_private_message.c index d8aabf8e..acd7a713 100644 --- a/toxcore/events/group_private_message.c +++ b/toxcore/events/group_private_message.c @@ -14,6 +14,7 @@ #include "../mem.h" #include "../tox.h" #include "../tox_events.h" +#include "../tox_pack.h" #include "../tox_unpack.h" @@ -121,11 +122,10 @@ static void tox_event_group_private_message_destruct(Tox_Event_Group_Private_Mes bool tox_event_group_private_message_pack( const Tox_Event_Group_Private_Message *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 4) && bin_pack_u32(bp, event->group_number) && bin_pack_u32(bp, event->peer_id) - && bin_pack_u32(bp, event->type) + && tox_message_type_pack(event->type, bp) && bin_pack_bin(bp, event->message, event->message_length); } @@ -140,7 +140,7 @@ static bool tox_event_group_private_message_unpack_into( return bin_unpack_u32(bu, &event->group_number) && bin_unpack_u32(bu, &event->peer_id) - && tox_message_type_unpack(bu, &event->type) + && tox_message_type_unpack(&event->type, bu) && bin_unpack_bin(bu, &event->message, &event->message_length); } diff --git a/toxcore/events/group_self_join.c b/toxcore/events/group_self_join.c index 7b01b966..904a3e53 100644 --- a/toxcore/events/group_self_join.c +++ b/toxcore/events/group_self_join.c @@ -54,7 +54,6 @@ static void tox_event_group_self_join_destruct(Tox_Event_Group_Self_Join *group_ bool tox_event_group_self_join_pack( const Tox_Event_Group_Self_Join *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_u32(bp, event->group_number); } diff --git a/toxcore/events/group_topic.c b/toxcore/events/group_topic.c index b943f49e..3a62024b 100644 --- a/toxcore/events/group_topic.c +++ b/toxcore/events/group_topic.c @@ -106,7 +106,6 @@ static void tox_event_group_topic_destruct(Tox_Event_Group_Topic *group_topic, c bool tox_event_group_topic_pack( const Tox_Event_Group_Topic *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 3) && bin_pack_u32(bp, event->group_number) && bin_pack_u32(bp, event->peer_id) diff --git a/toxcore/events/group_topic_lock.c b/toxcore/events/group_topic_lock.c index a7850409..82d37a15 100644 --- a/toxcore/events/group_topic_lock.c +++ b/toxcore/events/group_topic_lock.c @@ -12,6 +12,7 @@ #include "../mem.h" #include "../tox.h" #include "../tox_events.h" +#include "../tox_pack.h" #include "../tox_unpack.h" @@ -69,10 +70,9 @@ static void tox_event_group_topic_lock_destruct(Tox_Event_Group_Topic_Lock *grou bool tox_event_group_topic_lock_pack( const Tox_Event_Group_Topic_Lock *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 2) && bin_pack_u32(bp, event->group_number) - && bin_pack_u32(bp, event->topic_lock); + && tox_group_topic_lock_pack(event->topic_lock, bp); } non_null() @@ -85,7 +85,7 @@ static bool tox_event_group_topic_lock_unpack_into( } return bin_unpack_u32(bu, &event->group_number) - && tox_group_topic_lock_unpack(bu, &event->topic_lock); + && tox_group_topic_lock_unpack(&event->topic_lock, bu); } diff --git a/toxcore/events/group_voice_state.c b/toxcore/events/group_voice_state.c index 0ad85fc1..7bcfa556 100644 --- a/toxcore/events/group_voice_state.c +++ b/toxcore/events/group_voice_state.c @@ -12,6 +12,7 @@ #include "../mem.h" #include "../tox.h" #include "../tox_events.h" +#include "../tox_pack.h" #include "../tox_unpack.h" @@ -69,10 +70,9 @@ static void tox_event_group_voice_state_destruct(Tox_Event_Group_Voice_State *gr bool tox_event_group_voice_state_pack( const Tox_Event_Group_Voice_State *event, Bin_Pack *bp) { - assert(event != nullptr); return bin_pack_array(bp, 2) && bin_pack_u32(bp, event->group_number) - && bin_pack_u32(bp, event->voice_state); + && tox_group_voice_state_pack(event->voice_state, bp); } non_null() @@ -85,7 +85,7 @@ static bool tox_event_group_voice_state_unpack_into( } return bin_unpack_u32(bu, &event->group_number) - && tox_group_voice_state_unpack(bu, &event->voice_state); + && tox_group_voice_state_unpack(&event->voice_state, bu); } diff --git a/toxcore/events/self_connection_status.c b/toxcore/events/self_connection_status.c index adfc2a4d..417a3fe3 100644 --- a/toxcore/events/self_connection_status.c +++ b/toxcore/events/self_connection_status.c @@ -12,6 +12,7 @@ #include "../mem.h" #include "../tox.h" #include "../tox_events.h" +#include "../tox_pack.h" #include "../tox_unpack.h" @@ -55,8 +56,7 @@ static void tox_event_self_connection_status_destruct(Tox_Event_Self_Connection_ bool tox_event_self_connection_status_pack( const Tox_Event_Self_Connection_Status *event, Bin_Pack *bp) { - assert(event != nullptr); - return bin_pack_u32(bp, event->connection_status); + return tox_connection_pack(event->connection_status, bp); } non_null() @@ -64,7 +64,7 @@ static bool tox_event_self_connection_status_unpack_into( Tox_Event_Self_Connection_Status *event, Bin_Unpack *bu) { assert(event != nullptr); - return tox_connection_unpack(bu, &event->connection_status); + return tox_connection_unpack(&event->connection_status, bu); } diff --git a/toxcore/onion.c b/toxcore/onion.c index ae201cf7..0c4dfa58 100644 --- a/toxcore/onion.c +++ b/toxcore/onion.c @@ -48,7 +48,7 @@ static void change_symmetric_key(Onion *onion) /** packing and unpacking functions */ non_null() -static void ip_pack(uint8_t *data, const IP *source) +static void ip_pack_to_bytes(uint8_t *data, const IP *source) { data[0] = source->family.value; @@ -62,7 +62,7 @@ static void ip_pack(uint8_t *data, const IP *source) /** return 0 on success, -1 on failure. */ non_null() -static int ip_unpack(IP *target, const uint8_t *data, unsigned int data_size, bool disable_family_check) +static int ip_unpack_from_bytes(IP *target, const uint8_t *data, unsigned int data_size, bool disable_family_check) { if (data_size < (1 + SIZE_IP6)) { return -1; @@ -87,7 +87,7 @@ static int ip_unpack(IP *target, const uint8_t *data, unsigned int data_size, bo non_null() static void ipport_pack(uint8_t *data, const IP_Port *source) { - ip_pack(data, &source->ip); + ip_pack_to_bytes(data, &source->ip); memcpy(data + SIZE_IP, &source->port, SIZE_PORT); } @@ -99,7 +99,7 @@ static int ipport_unpack(IP_Port *target, const uint8_t *data, unsigned int data return -1; } - if (ip_unpack(&target->ip, data, data_size, disable_family_check) == -1) { + if (ip_unpack_from_bytes(&target->ip, data, data_size, disable_family_check) == -1) { return -1; } diff --git a/toxcore/tox_pack.c b/toxcore/tox_pack.c new file mode 100644 index 00000000..3d584ac7 --- /dev/null +++ b/toxcore/tox_pack.c @@ -0,0 +1,55 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later + * Copyright © 2022 The TokTok team. + */ + +#include "tox_pack.h" + +#include + +#include "bin_pack.h" +#include "tox.h" + +bool tox_conference_type_pack(Tox_Conference_Type val, Bin_Pack *bp) +{ + return bin_pack_u32(bp, (uint32_t)val); +} +bool tox_connection_pack(Tox_Connection val, Bin_Pack *bp) +{ + return bin_pack_u32(bp, (uint32_t)val); +} +bool tox_file_control_pack(Tox_File_Control val, Bin_Pack *bp) +{ + return bin_pack_u32(bp, (uint32_t)val); +} +bool tox_message_type_pack(Tox_Message_Type val, Bin_Pack *bp) +{ + return bin_pack_u32(bp, (uint32_t)val); +} +bool tox_user_status_pack(Tox_User_Status val, Bin_Pack *bp) +{ + return bin_pack_u32(bp, (uint32_t)val); +} +bool tox_group_privacy_state_pack(Tox_Group_Privacy_State val, Bin_Pack *bp) +{ + return bin_pack_u32(bp, (uint32_t)val); +} +bool tox_group_voice_state_pack(Tox_Group_Voice_State val, Bin_Pack *bp) +{ + return bin_pack_u32(bp, (uint32_t)val); +} +bool tox_group_topic_lock_pack(Tox_Group_Topic_Lock val, Bin_Pack *bp) +{ + return bin_pack_u32(bp, (uint32_t)val); +} +bool tox_group_join_fail_pack(Tox_Group_Join_Fail val, Bin_Pack *bp) +{ + return bin_pack_u32(bp, (uint32_t)val); +} +bool tox_group_mod_event_pack(Tox_Group_Mod_Event val, Bin_Pack *bp) +{ + return bin_pack_u32(bp, (uint32_t)val); +} +bool tox_group_exit_type_pack(Tox_Group_Exit_Type val, Bin_Pack *bp) +{ + return bin_pack_u32(bp, (uint32_t)val); +} diff --git a/toxcore/tox_pack.h b/toxcore/tox_pack.h new file mode 100644 index 00000000..4e554bce --- /dev/null +++ b/toxcore/tox_pack.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later + * Copyright © 2022 The TokTok team. + */ + +#ifndef C_TOXCORE_TOXCORE_TOX_PACK_H +#define C_TOXCORE_TOXCORE_TOX_PACK_H + +#include "attributes.h" +#include "bin_pack.h" +#include "tox.h" + +non_null() bool tox_conference_type_pack(Tox_Conference_Type val, Bin_Pack *bp); +non_null() bool tox_connection_pack(Tox_Connection val, Bin_Pack *bp); +non_null() bool tox_file_control_pack(Tox_File_Control val, Bin_Pack *bp); +non_null() bool tox_message_type_pack(Tox_Message_Type val, Bin_Pack *bp); +non_null() bool tox_user_status_pack(Tox_User_Status val, Bin_Pack *bp); +non_null() bool tox_group_privacy_state_pack(Tox_Group_Privacy_State val, Bin_Pack *bp); +non_null() bool tox_group_voice_state_pack(Tox_Group_Voice_State val, Bin_Pack *bp); +non_null() bool tox_group_topic_lock_pack(Tox_Group_Topic_Lock val, Bin_Pack *bp); +non_null() bool tox_group_join_fail_pack(Tox_Group_Join_Fail val, Bin_Pack *bp); +non_null() bool tox_group_mod_event_pack(Tox_Group_Mod_Event val, Bin_Pack *bp); +non_null() bool tox_group_exit_type_pack(Tox_Group_Exit_Type val, Bin_Pack *bp); + +#endif // C_TOXCORE_TOXCORE_TOX_PACK_H diff --git a/toxcore/tox_unpack.c b/toxcore/tox_unpack.c index 35bffb10..8f30824f 100644 --- a/toxcore/tox_unpack.c +++ b/toxcore/tox_unpack.c @@ -29,7 +29,7 @@ static bool tox_conference_type_from_int(uint32_t value, Tox_Conference_Type *ou } } } -bool tox_conference_type_unpack(Bin_Unpack *bu, Tox_Conference_Type *val) +bool tox_conference_type_unpack(Tox_Conference_Type *val, Bin_Unpack *bu) { uint32_t u32; return bin_unpack_u32(bu, &u32) @@ -62,7 +62,7 @@ static bool tox_connection_from_int(uint32_t value, Tox_Connection *out) } } -bool tox_connection_unpack(Bin_Unpack *bu, Tox_Connection *val) +bool tox_connection_unpack(Tox_Connection *val, Bin_Unpack *bu) { uint32_t u32; return bin_unpack_u32(bu, &u32) @@ -95,7 +95,7 @@ static bool tox_file_control_from_int(uint32_t value, Tox_File_Control *out) } } -bool tox_file_control_unpack(Bin_Unpack *bu, Tox_File_Control *val) +bool tox_file_control_unpack(Tox_File_Control *val, Bin_Unpack *bu) { uint32_t u32; return bin_unpack_u32(bu, &u32) @@ -123,7 +123,7 @@ static bool tox_message_type_from_int(uint32_t value, Tox_Message_Type *out) } } -bool tox_message_type_unpack(Bin_Unpack *bu, Tox_Message_Type *val) +bool tox_message_type_unpack(Tox_Message_Type *val, Bin_Unpack *bu) { uint32_t u32; return bin_unpack_u32(bu, &u32) @@ -156,7 +156,7 @@ static bool tox_user_status_from_int(uint32_t value, Tox_User_Status *out) } } -bool tox_user_status_unpack(Bin_Unpack *bu, Tox_User_Status *val) +bool tox_user_status_unpack(Tox_User_Status *val, Bin_Unpack *bu) { uint32_t u32; return bin_unpack_u32(bu, &u32) @@ -181,7 +181,7 @@ static bool tox_group_privacy_state_from_int(uint32_t value, Tox_Group_Privacy_S } } } -bool tox_group_privacy_state_unpack(Bin_Unpack *bu, Tox_Group_Privacy_State *val) +bool tox_group_privacy_state_unpack(Tox_Group_Privacy_State *val, Bin_Unpack *bu) { uint32_t u32; return bin_unpack_u32(bu, &u32) @@ -209,7 +209,7 @@ static bool tox_group_voice_state_from_int(uint32_t value, Tox_Group_Voice_State } } } -bool tox_group_voice_state_unpack(Bin_Unpack *bu, Tox_Group_Voice_State *val) +bool tox_group_voice_state_unpack(Tox_Group_Voice_State *val, Bin_Unpack *bu) { uint32_t u32; return bin_unpack_u32(bu, &u32) @@ -234,7 +234,7 @@ static bool tox_group_topic_lock_from_int(uint32_t value, Tox_Group_Topic_Lock * } } } -bool tox_group_topic_lock_unpack(Bin_Unpack *bu, Tox_Group_Topic_Lock *val) +bool tox_group_topic_lock_unpack(Tox_Group_Topic_Lock *val, Bin_Unpack *bu) { uint32_t u32; return bin_unpack_u32(bu, &u32) @@ -263,7 +263,7 @@ static bool tox_group_join_fail_from_int(uint32_t value, Tox_Group_Join_Fail *ou } } } -bool tox_group_join_fail_unpack(Bin_Unpack *bu, Tox_Group_Join_Fail *val) +bool tox_group_join_fail_unpack(Tox_Group_Join_Fail *val, Bin_Unpack *bu) { uint32_t u32; return bin_unpack_u32(bu, &u32) @@ -296,7 +296,7 @@ static bool tox_group_mod_event_from_int(uint32_t value, Tox_Group_Mod_Event *ou } } } -bool tox_group_mod_event_unpack(Bin_Unpack *bu, Tox_Group_Mod_Event *val) +bool tox_group_mod_event_unpack(Tox_Group_Mod_Event *val, Bin_Unpack *bu) { uint32_t u32; return bin_unpack_u32(bu, &u32) @@ -337,7 +337,7 @@ static bool tox_group_exit_type_from_int(uint32_t value, Tox_Group_Exit_Type *ou } } } -bool tox_group_exit_type_unpack(Bin_Unpack *bu, Tox_Group_Exit_Type *val) +bool tox_group_exit_type_unpack(Tox_Group_Exit_Type *val, Bin_Unpack *bu) { uint32_t u32; return bin_unpack_u32(bu, &u32) diff --git a/toxcore/tox_unpack.h b/toxcore/tox_unpack.h index af134ca5..1f2118cb 100644 --- a/toxcore/tox_unpack.h +++ b/toxcore/tox_unpack.h @@ -9,16 +9,16 @@ #include "bin_unpack.h" #include "tox.h" -non_null() bool tox_conference_type_unpack(Bin_Unpack *bu, Tox_Conference_Type *val); -non_null() bool tox_connection_unpack(Bin_Unpack *bu, Tox_Connection *val); -non_null() bool tox_file_control_unpack(Bin_Unpack *bu, Tox_File_Control *val); -non_null() bool tox_message_type_unpack(Bin_Unpack *bu, Tox_Message_Type *val); -non_null() bool tox_user_status_unpack(Bin_Unpack *bu, Tox_User_Status *val); -non_null() bool tox_group_privacy_state_unpack(Bin_Unpack *bu, Tox_Group_Privacy_State *val); -non_null() bool tox_group_voice_state_unpack(Bin_Unpack *bu, Tox_Group_Voice_State *val); -non_null() bool tox_group_topic_lock_unpack(Bin_Unpack *bu, Tox_Group_Topic_Lock *val); -non_null() bool tox_group_join_fail_unpack(Bin_Unpack *bu, Tox_Group_Join_Fail *val); -non_null() bool tox_group_mod_event_unpack(Bin_Unpack *bu, Tox_Group_Mod_Event *val); -non_null() bool tox_group_exit_type_unpack(Bin_Unpack *bu, Tox_Group_Exit_Type *val); +non_null() bool tox_conference_type_unpack(Tox_Conference_Type *val, Bin_Unpack *bu); +non_null() bool tox_connection_unpack(Tox_Connection *val, Bin_Unpack *bu); +non_null() bool tox_file_control_unpack(Tox_File_Control *val, Bin_Unpack *bu); +non_null() bool tox_message_type_unpack(Tox_Message_Type *val, Bin_Unpack *bu); +non_null() bool tox_user_status_unpack(Tox_User_Status *val, Bin_Unpack *bu); +non_null() bool tox_group_privacy_state_unpack(Tox_Group_Privacy_State *val, Bin_Unpack *bu); +non_null() bool tox_group_voice_state_unpack(Tox_Group_Voice_State *val, Bin_Unpack *bu); +non_null() bool tox_group_topic_lock_unpack(Tox_Group_Topic_Lock *val, Bin_Unpack *bu); +non_null() bool tox_group_join_fail_unpack(Tox_Group_Join_Fail *val, Bin_Unpack *bu); +non_null() bool tox_group_mod_event_unpack(Tox_Group_Mod_Event *val, Bin_Unpack *bu); +non_null() bool tox_group_exit_type_unpack(Tox_Group_Exit_Type *val, Bin_Unpack *bu); #endif // C_TOXCORE_TOXCORE_TOX_UNPACK_H