diff --git a/auto_tests/Makefile.inc b/auto_tests/Makefile.inc index db22d7ff14..d55f714096 100644 --- a/auto_tests/Makefile.inc +++ b/auto_tests/Makefile.inc @@ -187,14 +187,14 @@ TCP_test_SOURCES = ../auto_tests/TCP_test.c TCP_test_CFLAGS = $(AUTOTEST_CFLAGS) TCP_test_LDADD = $(AUTOTEST_LDADD) -tox_events_test_SOURCES = ../auto_tests/tox_events_test.c -tox_events_test_CFLAGS = $(AUTOTEST_CFLAGS) -tox_events_test_LDADD = $(AUTOTEST_LDADD) - tox_dispatch_test_SOURCES = ../auto_tests/tox_dispatch_test.c tox_dispatch_test_CFLAGS = $(AUTOTEST_CFLAGS) tox_dispatch_test_LDADD = $(AUTOTEST_LDADD) +tox_events_test_SOURCES = ../auto_tests/tox_events_test.c +tox_events_test_CFLAGS = $(AUTOTEST_CFLAGS) +tox_events_test_LDADD = $(AUTOTEST_LDADD) + tox_many_tcp_test_SOURCES = ../auto_tests/tox_many_tcp_test.c tox_many_tcp_test_CFLAGS = $(AUTOTEST_CFLAGS) tox_many_tcp_test_LDADD = $(AUTOTEST_LDADD) diff --git a/auto_tests/tox_events_test.c b/auto_tests/tox_events_test.c index 918bc17ec0..1b7cb729aa 100644 --- a/auto_tests/tox_events_test.c +++ b/auto_tests/tox_events_test.c @@ -22,21 +22,23 @@ static bool await_message(Tox **toxes) Tox_Events *events = tox_events_iterate(toxes[1], false, nullptr); if (events != nullptr) { - ck_assert(tox_events_get_friend_message_size(events) == 1); - const Tox_Event_Friend_Message *msg_event = tox_events_get_friend_message(events, 0); + uint32_t events_size = tox_events_get_size(events); + ck_assert(events_size == 1); + + const Tox_Event_Friend_Message *msg_event = nullptr; + for (uint32_t j = 0; j < events_size; ++j) { + const Tox_Event *ev = tox_events_get(events, j); + if (tox_event_get_type(ev) == TOX_EVENT_FRIEND_MESSAGE) { + msg_event = tox_event_get_friend_message(ev); + } + } + + ck_assert(msg_event != nullptr); ck_assert(tox_event_friend_message_get_message_length(msg_event) == sizeof("hello")); const uint8_t *msg = tox_event_friend_message_get_message(msg_event); ck_assert_msg(memcmp(msg, "hello", sizeof("hello")) == 0, "message was not expected 'hello' but '%s'", (const char *)msg); - const uint32_t event_count = tox_events_get_size(events); - for (uint32_t j = 0; j < event_count; ++j) { - const Tox_Event *event = tox_events_get(events, j); - if (tox_event_get_type(event) == TOX_EVENT_FRIEND_MESSAGE) { - ck_assert(tox_event_get_friend_message(event) == msg_event); - } - } - tox_events_free(events); return true; } diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index e7b4e04d72..fec53be046 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -a25a42c612c89e7eab338f2cf330994d4334c7f9c8230eee3590c2f79c291bde /usr/local/bin/tox-bootstrapd +08fe68095b88c142e0c7f3369c5f297f1377e219d0e0f0ff6f30ca94d76fca98 /usr/local/bin/tox-bootstrapd diff --git a/other/event_tooling/generate_event_c.cpp b/other/event_tooling/generate_event_c.cpp index e338cb6012..b736b6f2a4 100644 --- a/other/event_tooling/generate_event_c.cpp +++ b/other/event_tooling/generate_event_c.cpp @@ -404,28 +404,6 @@ void generate_event_impl(const std::string& event_name, const std::vector index) {\n"; - f << " return nullptr;\n }\n\n"; - f << " if (events->events[i].type == TOX_EVENT_" << str_toupper(event_name) << ") {\n"; - f << " const Tox_Event_" << event_name << " *" << event_name_l << " = events->events[i].data." << event_name_l << ";\n"; - f << " if (" << event_name_l << "_index == index) {\n"; - f << " return " << event_name_l << ";\n }\n"; - f << " ++" << event_name_l << "_index;\n }\n }\n\n return nullptr;\n}\n\n"; - - // get size - f << "uint32_t tox_events_get_" << event_name_l << "_size(const Tox_Events *events)\n{\n"; - f << " uint32_t " << event_name_l << "_size = 0;\n"; - f << " const uint32_t size = tox_events_get_size(events);\n\n"; - f << " for (uint32_t i = 0; i < size; ++i) {\n"; - f << " if (events->events[i].type == TOX_EVENT_" << str_toupper(event_name) << ") {\n"; - f << " ++" << event_name_l << "_size;\n }\n }\n\n"; - f << " return " << event_name_l << "_size;\n}\n\n"; - // unpack f << "bool tox_event_" << event_name_l << "_unpack(\n"; f << " Tox_Event_" << event_name << " **event, Bin_Unpack *bu, const Memory *mem)\n{\n"; diff --git a/toxcore/BUILD.bazel b/toxcore/BUILD.bazel index 5916beaf10..a4f9c88f9f 100644 --- a/toxcore/BUILD.bazel +++ b/toxcore/BUILD.bazel @@ -936,6 +936,7 @@ cc_fuzz_test( srcs = ["tox_events_fuzz_test.cc"], corpus = ["//tools/toktok-fuzzer/corpus:tox_events_fuzz_test"], deps = [ + ":tox_dispatch", ":tox_events", "//c-toxcore/testing/fuzzing:fuzz_support", ], diff --git a/toxcore/events/conference_connected.c b/toxcore/events/conference_connected.c index 8fd6454170..39169abbc1 100644 --- a/toxcore/events/conference_connected.c +++ b/toxcore/events/conference_connected.c @@ -118,42 +118,6 @@ static Tox_Event_Conference_Connected *tox_events_add_conference_connected(Tox_E return conference_connected; } -const Tox_Event_Conference_Connected *tox_events_get_conference_connected(const Tox_Events *events, uint32_t index) -{ - uint32_t conference_connected_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (conference_connected_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_CONFERENCE_CONNECTED) { - const Tox_Event_Conference_Connected *conference_connected = events->events[i].data.conference_connected; - if (conference_connected_index == index) { - return conference_connected; - } - ++conference_connected_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_conference_connected_size(const Tox_Events *events) -{ - uint32_t conference_connected_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_CONFERENCE_CONNECTED) { - ++conference_connected_size; - } - } - - return conference_connected_size; -} - bool tox_event_conference_connected_unpack( Tox_Event_Conference_Connected **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/conference_invite.c b/toxcore/events/conference_invite.c index e02f2027f8..e48b0619a4 100644 --- a/toxcore/events/conference_invite.c +++ b/toxcore/events/conference_invite.c @@ -180,42 +180,6 @@ static Tox_Event_Conference_Invite *tox_events_add_conference_invite(Tox_Events return conference_invite; } -const Tox_Event_Conference_Invite *tox_events_get_conference_invite(const Tox_Events *events, uint32_t index) -{ - uint32_t conference_invite_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (conference_invite_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_CONFERENCE_INVITE) { - const Tox_Event_Conference_Invite *conference_invite = events->events[i].data.conference_invite; - if (conference_invite_index == index) { - return conference_invite; - } - ++conference_invite_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_conference_invite_size(const Tox_Events *events) -{ - uint32_t conference_invite_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_CONFERENCE_INVITE) { - ++conference_invite_size; - } - } - - return conference_invite_size; -} - bool tox_event_conference_invite_unpack( Tox_Event_Conference_Invite **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/conference_message.c b/toxcore/events/conference_message.c index 02bec35819..4939af7fff 100644 --- a/toxcore/events/conference_message.c +++ b/toxcore/events/conference_message.c @@ -196,42 +196,6 @@ static Tox_Event_Conference_Message *tox_events_add_conference_message(Tox_Event return conference_message; } -const Tox_Event_Conference_Message *tox_events_get_conference_message(const Tox_Events *events, uint32_t index) -{ - uint32_t conference_message_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (conference_message_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_CONFERENCE_MESSAGE) { - const Tox_Event_Conference_Message *conference_message = events->events[i].data.conference_message; - if (conference_message_index == index) { - return conference_message; - } - ++conference_message_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_conference_message_size(const Tox_Events *events) -{ - uint32_t conference_message_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_CONFERENCE_MESSAGE) { - ++conference_message_size; - } - } - - return conference_message_size; -} - bool tox_event_conference_message_unpack( Tox_Event_Conference_Message **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/conference_peer_list_changed.c b/toxcore/events/conference_peer_list_changed.c index 1bcb685d4f..9c9340c6f7 100644 --- a/toxcore/events/conference_peer_list_changed.c +++ b/toxcore/events/conference_peer_list_changed.c @@ -118,42 +118,6 @@ static Tox_Event_Conference_Peer_List_Changed *tox_events_add_conference_peer_li return conference_peer_list_changed; } -const Tox_Event_Conference_Peer_List_Changed *tox_events_get_conference_peer_list_changed(const Tox_Events *events, uint32_t index) -{ - uint32_t conference_peer_list_changed_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (conference_peer_list_changed_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_CONFERENCE_PEER_LIST_CHANGED) { - const Tox_Event_Conference_Peer_List_Changed *conference_peer_list_changed = events->events[i].data.conference_peer_list_changed; - if (conference_peer_list_changed_index == index) { - return conference_peer_list_changed; - } - ++conference_peer_list_changed_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_conference_peer_list_changed_size(const Tox_Events *events) -{ - uint32_t conference_peer_list_changed_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_CONFERENCE_PEER_LIST_CHANGED) { - ++conference_peer_list_changed_size; - } - } - - return conference_peer_list_changed_size; -} - bool tox_event_conference_peer_list_changed_unpack( Tox_Event_Conference_Peer_List_Changed **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/conference_peer_name.c b/toxcore/events/conference_peer_name.c index 511962f87b..ad6b9e1877 100644 --- a/toxcore/events/conference_peer_name.c +++ b/toxcore/events/conference_peer_name.c @@ -179,42 +179,6 @@ static Tox_Event_Conference_Peer_Name *tox_events_add_conference_peer_name(Tox_E return conference_peer_name; } -const Tox_Event_Conference_Peer_Name *tox_events_get_conference_peer_name(const Tox_Events *events, uint32_t index) -{ - uint32_t conference_peer_name_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (conference_peer_name_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_CONFERENCE_PEER_NAME) { - const Tox_Event_Conference_Peer_Name *conference_peer_name = events->events[i].data.conference_peer_name; - if (conference_peer_name_index == index) { - return conference_peer_name; - } - ++conference_peer_name_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_conference_peer_name_size(const Tox_Events *events) -{ - uint32_t conference_peer_name_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_CONFERENCE_PEER_NAME) { - ++conference_peer_name_size; - } - } - - return conference_peer_name_size; -} - bool tox_event_conference_peer_name_unpack( Tox_Event_Conference_Peer_Name **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/conference_title.c b/toxcore/events/conference_title.c index d401edf520..1532ba5de9 100644 --- a/toxcore/events/conference_title.c +++ b/toxcore/events/conference_title.c @@ -179,42 +179,6 @@ static Tox_Event_Conference_Title *tox_events_add_conference_title(Tox_Events *e return conference_title; } -const Tox_Event_Conference_Title *tox_events_get_conference_title(const Tox_Events *events, uint32_t index) -{ - uint32_t conference_title_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (conference_title_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_CONFERENCE_TITLE) { - const Tox_Event_Conference_Title *conference_title = events->events[i].data.conference_title; - if (conference_title_index == index) { - return conference_title; - } - ++conference_title_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_conference_title_size(const Tox_Events *events) -{ - uint32_t conference_title_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_CONFERENCE_TITLE) { - ++conference_title_size; - } - } - - return conference_title_size; -} - bool tox_event_conference_title_unpack( Tox_Event_Conference_Title **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/file_chunk_request.c b/toxcore/events/file_chunk_request.c index ae8269c6a7..0bf586424a 100644 --- a/toxcore/events/file_chunk_request.c +++ b/toxcore/events/file_chunk_request.c @@ -171,42 +171,6 @@ static Tox_Event_File_Chunk_Request *tox_events_add_file_chunk_request(Tox_Event return file_chunk_request; } -const Tox_Event_File_Chunk_Request *tox_events_get_file_chunk_request(const Tox_Events *events, uint32_t index) -{ - uint32_t file_chunk_request_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (file_chunk_request_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_FILE_CHUNK_REQUEST) { - const Tox_Event_File_Chunk_Request *file_chunk_request = events->events[i].data.file_chunk_request; - if (file_chunk_request_index == index) { - return file_chunk_request; - } - ++file_chunk_request_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_file_chunk_request_size(const Tox_Events *events) -{ - uint32_t file_chunk_request_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_FILE_CHUNK_REQUEST) { - ++file_chunk_request_size; - } - } - - return file_chunk_request_size; -} - bool tox_event_file_chunk_request_unpack( Tox_Event_File_Chunk_Request **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/file_recv.c b/toxcore/events/file_recv.c index 49f04d8040..25ea7039db 100644 --- a/toxcore/events/file_recv.c +++ b/toxcore/events/file_recv.c @@ -211,42 +211,6 @@ static Tox_Event_File_Recv *tox_events_add_file_recv(Tox_Events *events, const M return file_recv; } -const Tox_Event_File_Recv *tox_events_get_file_recv(const Tox_Events *events, uint32_t index) -{ - uint32_t file_recv_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (file_recv_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_FILE_RECV) { - const Tox_Event_File_Recv *file_recv = events->events[i].data.file_recv; - if (file_recv_index == index) { - return file_recv; - } - ++file_recv_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_file_recv_size(const Tox_Events *events) -{ - uint32_t file_recv_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_FILE_RECV) { - ++file_recv_size; - } - } - - return file_recv_size; -} - bool tox_event_file_recv_unpack( Tox_Event_File_Recv **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/file_recv_chunk.c b/toxcore/events/file_recv_chunk.c index 8ffc7b5f65..eda5818a49 100644 --- a/toxcore/events/file_recv_chunk.c +++ b/toxcore/events/file_recv_chunk.c @@ -195,42 +195,6 @@ static Tox_Event_File_Recv_Chunk *tox_events_add_file_recv_chunk(Tox_Events *eve return file_recv_chunk; } -const Tox_Event_File_Recv_Chunk *tox_events_get_file_recv_chunk(const Tox_Events *events, uint32_t index) -{ - uint32_t file_recv_chunk_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (file_recv_chunk_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_FILE_RECV_CHUNK) { - const Tox_Event_File_Recv_Chunk *file_recv_chunk = events->events[i].data.file_recv_chunk; - if (file_recv_chunk_index == index) { - return file_recv_chunk; - } - ++file_recv_chunk_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_file_recv_chunk_size(const Tox_Events *events) -{ - uint32_t file_recv_chunk_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_FILE_RECV_CHUNK) { - ++file_recv_chunk_size; - } - } - - return file_recv_chunk_size; -} - bool tox_event_file_recv_chunk_unpack( Tox_Event_File_Recv_Chunk **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/file_recv_control.c b/toxcore/events/file_recv_control.c index bfff9a05de..e9aac24d27 100644 --- a/toxcore/events/file_recv_control.c +++ b/toxcore/events/file_recv_control.c @@ -156,42 +156,6 @@ static Tox_Event_File_Recv_Control *tox_events_add_file_recv_control(Tox_Events return file_recv_control; } -const Tox_Event_File_Recv_Control *tox_events_get_file_recv_control(const Tox_Events *events, uint32_t index) -{ - uint32_t file_recv_control_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (file_recv_control_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_FILE_RECV_CONTROL) { - const Tox_Event_File_Recv_Control *file_recv_control = events->events[i].data.file_recv_control; - if (file_recv_control_index == index) { - return file_recv_control; - } - ++file_recv_control_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_file_recv_control_size(const Tox_Events *events) -{ - uint32_t file_recv_control_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_FILE_RECV_CONTROL) { - ++file_recv_control_size; - } - } - - return file_recv_control_size; -} - bool tox_event_file_recv_control_unpack( Tox_Event_File_Recv_Control **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/friend_connection_status.c b/toxcore/events/friend_connection_status.c index a84ac25e4a..9eded8b50c 100644 --- a/toxcore/events/friend_connection_status.c +++ b/toxcore/events/friend_connection_status.c @@ -140,42 +140,6 @@ static Tox_Event_Friend_Connection_Status *tox_events_add_friend_connection_stat return friend_connection_status; } -const Tox_Event_Friend_Connection_Status *tox_events_get_friend_connection_status(const Tox_Events *events, uint32_t index) -{ - uint32_t friend_connection_status_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (friend_connection_status_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_FRIEND_CONNECTION_STATUS) { - const Tox_Event_Friend_Connection_Status *friend_connection_status = events->events[i].data.friend_connection_status; - if (friend_connection_status_index == index) { - return friend_connection_status; - } - ++friend_connection_status_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_friend_connection_status_size(const Tox_Events *events) -{ - uint32_t friend_connection_status_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_FRIEND_CONNECTION_STATUS) { - ++friend_connection_status_size; - } - } - - return friend_connection_status_size; -} - bool tox_event_friend_connection_status_unpack( Tox_Event_Friend_Connection_Status **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/friend_lossless_packet.c b/toxcore/events/friend_lossless_packet.c index 6f2f9e7d42..2d5da3bf5a 100644 --- a/toxcore/events/friend_lossless_packet.c +++ b/toxcore/events/friend_lossless_packet.c @@ -163,42 +163,6 @@ static Tox_Event_Friend_Lossless_Packet *tox_events_add_friend_lossless_packet(T return friend_lossless_packet; } -const Tox_Event_Friend_Lossless_Packet *tox_events_get_friend_lossless_packet(const Tox_Events *events, uint32_t index) -{ - uint32_t friend_lossless_packet_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (friend_lossless_packet_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_FRIEND_LOSSLESS_PACKET) { - const Tox_Event_Friend_Lossless_Packet *friend_lossless_packet = events->events[i].data.friend_lossless_packet; - if (friend_lossless_packet_index == index) { - return friend_lossless_packet; - } - ++friend_lossless_packet_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_friend_lossless_packet_size(const Tox_Events *events) -{ - uint32_t friend_lossless_packet_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_FRIEND_LOSSLESS_PACKET) { - ++friend_lossless_packet_size; - } - } - - return friend_lossless_packet_size; -} - bool tox_event_friend_lossless_packet_unpack( Tox_Event_Friend_Lossless_Packet **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/friend_lossy_packet.c b/toxcore/events/friend_lossy_packet.c index ec84ac90ff..d7319f533c 100644 --- a/toxcore/events/friend_lossy_packet.c +++ b/toxcore/events/friend_lossy_packet.c @@ -163,42 +163,6 @@ static Tox_Event_Friend_Lossy_Packet *tox_events_add_friend_lossy_packet(Tox_Eve return friend_lossy_packet; } -const Tox_Event_Friend_Lossy_Packet *tox_events_get_friend_lossy_packet(const Tox_Events *events, uint32_t index) -{ - uint32_t friend_lossy_packet_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (friend_lossy_packet_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_FRIEND_LOSSY_PACKET) { - const Tox_Event_Friend_Lossy_Packet *friend_lossy_packet = events->events[i].data.friend_lossy_packet; - if (friend_lossy_packet_index == index) { - return friend_lossy_packet; - } - ++friend_lossy_packet_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_friend_lossy_packet_size(const Tox_Events *events) -{ - uint32_t friend_lossy_packet_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_FRIEND_LOSSY_PACKET) { - ++friend_lossy_packet_size; - } - } - - return friend_lossy_packet_size; -} - bool tox_event_friend_lossy_packet_unpack( Tox_Event_Friend_Lossy_Packet **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/friend_message.c b/toxcore/events/friend_message.c index 411cd85818..2149549784 100644 --- a/toxcore/events/friend_message.c +++ b/toxcore/events/friend_message.c @@ -180,42 +180,6 @@ static Tox_Event_Friend_Message *tox_events_add_friend_message(Tox_Events *event return friend_message; } -const Tox_Event_Friend_Message *tox_events_get_friend_message(const Tox_Events *events, uint32_t index) -{ - uint32_t friend_message_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (friend_message_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_FRIEND_MESSAGE) { - const Tox_Event_Friend_Message *friend_message = events->events[i].data.friend_message; - if (friend_message_index == index) { - return friend_message; - } - ++friend_message_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_friend_message_size(const Tox_Events *events) -{ - uint32_t friend_message_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_FRIEND_MESSAGE) { - ++friend_message_size; - } - } - - return friend_message_size; -} - bool tox_event_friend_message_unpack( Tox_Event_Friend_Message **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/friend_name.c b/toxcore/events/friend_name.c index f3d9a6bc44..53fa9d8550 100644 --- a/toxcore/events/friend_name.c +++ b/toxcore/events/friend_name.c @@ -163,42 +163,6 @@ static Tox_Event_Friend_Name *tox_events_add_friend_name(Tox_Events *events, con return friend_name; } -const Tox_Event_Friend_Name *tox_events_get_friend_name(const Tox_Events *events, uint32_t index) -{ - uint32_t friend_name_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (friend_name_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_FRIEND_NAME) { - const Tox_Event_Friend_Name *friend_name = events->events[i].data.friend_name; - if (friend_name_index == index) { - return friend_name; - } - ++friend_name_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_friend_name_size(const Tox_Events *events) -{ - uint32_t friend_name_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_FRIEND_NAME) { - ++friend_name_size; - } - } - - return friend_name_size; -} - bool tox_event_friend_name_unpack( Tox_Event_Friend_Name **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/friend_read_receipt.c b/toxcore/events/friend_read_receipt.c index bf53234fb5..8c88b4177d 100644 --- a/toxcore/events/friend_read_receipt.c +++ b/toxcore/events/friend_read_receipt.c @@ -139,42 +139,6 @@ static Tox_Event_Friend_Read_Receipt *tox_events_add_friend_read_receipt(Tox_Eve return friend_read_receipt; } -const Tox_Event_Friend_Read_Receipt *tox_events_get_friend_read_receipt(const Tox_Events *events, uint32_t index) -{ - uint32_t friend_read_receipt_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (friend_read_receipt_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_FRIEND_READ_RECEIPT) { - const Tox_Event_Friend_Read_Receipt *friend_read_receipt = events->events[i].data.friend_read_receipt; - if (friend_read_receipt_index == index) { - return friend_read_receipt; - } - ++friend_read_receipt_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_friend_read_receipt_size(const Tox_Events *events) -{ - uint32_t friend_read_receipt_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_FRIEND_READ_RECEIPT) { - ++friend_read_receipt_size; - } - } - - return friend_read_receipt_size; -} - bool tox_event_friend_read_receipt_unpack( Tox_Event_Friend_Read_Receipt **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/friend_request.c b/toxcore/events/friend_request.c index 1722c1d142..4a1936085d 100644 --- a/toxcore/events/friend_request.c +++ b/toxcore/events/friend_request.c @@ -158,44 +158,6 @@ static Tox_Event_Friend_Request *tox_events_add_friend_request(Tox_Events *event return friend_request; } -const Tox_Event_Friend_Request *tox_events_get_friend_request( - const Tox_Events *events, uint32_t index) -{ - uint32_t friend_request_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (friend_request_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_FRIEND_REQUEST) { - const Tox_Event_Friend_Request *friend_request = events->events[i].data.friend_request; - if (friend_request_index == index) { - return friend_request; - } - ++friend_request_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_friend_request_size( - const Tox_Events *events) -{ - uint32_t friend_request_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_FRIEND_REQUEST) { - ++friend_request_size; - } - } - - return friend_request_size; -} - bool tox_event_friend_request_unpack( Tox_Event_Friend_Request **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/friend_status.c b/toxcore/events/friend_status.c index 794aa66835..1b0a8a41b0 100644 --- a/toxcore/events/friend_status.c +++ b/toxcore/events/friend_status.c @@ -140,42 +140,6 @@ static Tox_Event_Friend_Status *tox_events_add_friend_status(Tox_Events *events, return friend_status; } -const Tox_Event_Friend_Status *tox_events_get_friend_status(const Tox_Events *events, uint32_t index) -{ - uint32_t friend_status_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (friend_status_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_FRIEND_STATUS) { - const Tox_Event_Friend_Status *friend_status = events->events[i].data.friend_status; - if (friend_status_index == index) { - return friend_status; - } - ++friend_status_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_friend_status_size(const Tox_Events *events) -{ - uint32_t friend_status_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_FRIEND_STATUS) { - ++friend_status_size; - } - } - - return friend_status_size; -} - bool tox_event_friend_status_unpack( Tox_Event_Friend_Status **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/friend_status_message.c b/toxcore/events/friend_status_message.c index 5de6f4008d..876a9f735f 100644 --- a/toxcore/events/friend_status_message.c +++ b/toxcore/events/friend_status_message.c @@ -163,42 +163,6 @@ static Tox_Event_Friend_Status_Message *tox_events_add_friend_status_message(Tox return friend_status_message; } -const Tox_Event_Friend_Status_Message *tox_events_get_friend_status_message(const Tox_Events *events, uint32_t index) -{ - uint32_t friend_status_message_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (friend_status_message_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_FRIEND_STATUS_MESSAGE) { - const Tox_Event_Friend_Status_Message *friend_status_message = events->events[i].data.friend_status_message; - if (friend_status_message_index == index) { - return friend_status_message; - } - ++friend_status_message_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_friend_status_message_size(const Tox_Events *events) -{ - uint32_t friend_status_message_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_FRIEND_STATUS_MESSAGE) { - ++friend_status_message_size; - } - } - - return friend_status_message_size; -} - bool tox_event_friend_status_message_unpack( Tox_Event_Friend_Status_Message **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/friend_typing.c b/toxcore/events/friend_typing.c index 563cbbc8a8..80458e78b2 100644 --- a/toxcore/events/friend_typing.c +++ b/toxcore/events/friend_typing.c @@ -139,42 +139,6 @@ static Tox_Event_Friend_Typing *tox_events_add_friend_typing(Tox_Events *events, return friend_typing; } -const Tox_Event_Friend_Typing *tox_events_get_friend_typing(const Tox_Events *events, uint32_t index) -{ - uint32_t friend_typing_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (friend_typing_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_FRIEND_TYPING) { - const Tox_Event_Friend_Typing *friend_typing = events->events[i].data.friend_typing; - if (friend_typing_index == index) { - return friend_typing; - } - ++friend_typing_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_friend_typing_size(const Tox_Events *events) -{ - uint32_t friend_typing_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_FRIEND_TYPING) { - ++friend_typing_size; - } - } - - return friend_typing_size; -} - bool tox_event_friend_typing_unpack( Tox_Event_Friend_Typing **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/group_custom_packet.c b/toxcore/events/group_custom_packet.c index 8bf1927e0a..a265ee4a38 100644 --- a/toxcore/events/group_custom_packet.c +++ b/toxcore/events/group_custom_packet.c @@ -179,42 +179,6 @@ static Tox_Event_Group_Custom_Packet *tox_events_add_group_custom_packet(Tox_Eve return group_custom_packet; } -const Tox_Event_Group_Custom_Packet *tox_events_get_group_custom_packet(const Tox_Events *events, uint32_t index) -{ - uint32_t group_custom_packet_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (group_custom_packet_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_GROUP_CUSTOM_PACKET) { - const Tox_Event_Group_Custom_Packet *group_custom_packet = events->events[i].data.group_custom_packet; - if (group_custom_packet_index == index) { - return group_custom_packet; - } - ++group_custom_packet_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_group_custom_packet_size(const Tox_Events *events) -{ - uint32_t group_custom_packet_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_GROUP_CUSTOM_PACKET) { - ++group_custom_packet_size; - } - } - - return group_custom_packet_size; -} - bool tox_event_group_custom_packet_unpack( Tox_Event_Group_Custom_Packet **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/group_custom_private_packet.c b/toxcore/events/group_custom_private_packet.c index 8e69712d5b..bcb7cb3ecd 100644 --- a/toxcore/events/group_custom_private_packet.c +++ b/toxcore/events/group_custom_private_packet.c @@ -179,42 +179,6 @@ static Tox_Event_Group_Custom_Private_Packet *tox_events_add_group_custom_privat return group_custom_private_packet; } -const Tox_Event_Group_Custom_Private_Packet *tox_events_get_group_custom_private_packet(const Tox_Events *events, uint32_t index) -{ - uint32_t group_custom_private_packet_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (group_custom_private_packet_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_GROUP_CUSTOM_PRIVATE_PACKET) { - const Tox_Event_Group_Custom_Private_Packet *group_custom_private_packet = events->events[i].data.group_custom_private_packet; - if (group_custom_private_packet_index == index) { - return group_custom_private_packet; - } - ++group_custom_private_packet_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_group_custom_private_packet_size(const Tox_Events *events) -{ - uint32_t group_custom_private_packet_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_GROUP_CUSTOM_PRIVATE_PACKET) { - ++group_custom_private_packet_size; - } - } - - return group_custom_private_packet_size; -} - bool tox_event_group_custom_private_packet_unpack( Tox_Event_Group_Custom_Private_Packet **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/group_invite.c b/toxcore/events/group_invite.c index f3eccb3f23..97fad95c83 100644 --- a/toxcore/events/group_invite.c +++ b/toxcore/events/group_invite.c @@ -202,42 +202,6 @@ static Tox_Event_Group_Invite *tox_events_add_group_invite(Tox_Events *events, c return group_invite; } -const Tox_Event_Group_Invite *tox_events_get_group_invite(const Tox_Events *events, uint32_t index) -{ - uint32_t group_invite_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (group_invite_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_GROUP_INVITE) { - const Tox_Event_Group_Invite *group_invite = events->events[i].data.group_invite; - if (group_invite_index == index) { - return group_invite; - } - ++group_invite_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_group_invite_size(const Tox_Events *events) -{ - uint32_t group_invite_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_GROUP_INVITE) { - ++group_invite_size; - } - } - - return group_invite_size; -} - bool tox_event_group_invite_unpack( Tox_Event_Group_Invite **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/group_join_fail.c b/toxcore/events/group_join_fail.c index 0e526131fb..10a9516dca 100644 --- a/toxcore/events/group_join_fail.c +++ b/toxcore/events/group_join_fail.c @@ -140,42 +140,6 @@ static Tox_Event_Group_Join_Fail *tox_events_add_group_join_fail(Tox_Events *eve return group_join_fail; } -const Tox_Event_Group_Join_Fail *tox_events_get_group_join_fail(const Tox_Events *events, uint32_t index) -{ - uint32_t group_join_fail_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (group_join_fail_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_GROUP_JOIN_FAIL) { - const Tox_Event_Group_Join_Fail *group_join_fail = events->events[i].data.group_join_fail; - if (group_join_fail_index == index) { - return group_join_fail; - } - ++group_join_fail_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_group_join_fail_size(const Tox_Events *events) -{ - uint32_t group_join_fail_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_GROUP_JOIN_FAIL) { - ++group_join_fail_size; - } - } - - return group_join_fail_size; -} - bool tox_event_group_join_fail_unpack( Tox_Event_Group_Join_Fail **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/group_message.c b/toxcore/events/group_message.c index 171816212e..06a04a763e 100644 --- a/toxcore/events/group_message.c +++ b/toxcore/events/group_message.c @@ -212,42 +212,6 @@ static Tox_Event_Group_Message *tox_events_add_group_message(Tox_Events *events, return group_message; } -const Tox_Event_Group_Message *tox_events_get_group_message(const Tox_Events *events, uint32_t index) -{ - uint32_t group_message_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (group_message_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_GROUP_MESSAGE) { - const Tox_Event_Group_Message *group_message = events->events[i].data.group_message; - if (group_message_index == index) { - return group_message; - } - ++group_message_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_group_message_size(const Tox_Events *events) -{ - uint32_t group_message_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_GROUP_MESSAGE) { - ++group_message_size; - } - } - - return group_message_size; -} - bool tox_event_group_message_unpack( Tox_Event_Group_Message **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/group_moderation.c b/toxcore/events/group_moderation.c index 74a5e9d0b3..f728a270e2 100644 --- a/toxcore/events/group_moderation.c +++ b/toxcore/events/group_moderation.c @@ -172,42 +172,6 @@ static Tox_Event_Group_Moderation *tox_events_add_group_moderation(Tox_Events *e return group_moderation; } -const Tox_Event_Group_Moderation *tox_events_get_group_moderation(const Tox_Events *events, uint32_t index) -{ - uint32_t group_moderation_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (group_moderation_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_GROUP_MODERATION) { - const Tox_Event_Group_Moderation *group_moderation = events->events[i].data.group_moderation; - if (group_moderation_index == index) { - return group_moderation; - } - ++group_moderation_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_group_moderation_size(const Tox_Events *events) -{ - uint32_t group_moderation_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_GROUP_MODERATION) { - ++group_moderation_size; - } - } - - return group_moderation_size; -} - bool tox_event_group_moderation_unpack( Tox_Event_Group_Moderation **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/group_password.c b/toxcore/events/group_password.c index 514e725bc8..6f19bd5a17 100644 --- a/toxcore/events/group_password.c +++ b/toxcore/events/group_password.c @@ -163,42 +163,6 @@ static Tox_Event_Group_Password *tox_events_add_group_password(Tox_Events *event return group_password; } -const Tox_Event_Group_Password *tox_events_get_group_password(const Tox_Events *events, uint32_t index) -{ - uint32_t group_password_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (group_password_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_GROUP_PASSWORD) { - const Tox_Event_Group_Password *group_password = events->events[i].data.group_password; - if (group_password_index == index) { - return group_password; - } - ++group_password_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_group_password_size(const Tox_Events *events) -{ - uint32_t group_password_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_GROUP_PASSWORD) { - ++group_password_size; - } - } - - return group_password_size; -} - bool tox_event_group_password_unpack( Tox_Event_Group_Password **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/group_peer_exit.c b/toxcore/events/group_peer_exit.c index dccd2c2a75..5a94cc2009 100644 --- a/toxcore/events/group_peer_exit.c +++ b/toxcore/events/group_peer_exit.c @@ -235,42 +235,6 @@ static Tox_Event_Group_Peer_Exit *tox_events_add_group_peer_exit(Tox_Events *eve return group_peer_exit; } -const Tox_Event_Group_Peer_Exit *tox_events_get_group_peer_exit(const Tox_Events *events, uint32_t index) -{ - uint32_t group_peer_exit_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (group_peer_exit_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_GROUP_PEER_EXIT) { - const Tox_Event_Group_Peer_Exit *group_peer_exit = events->events[i].data.group_peer_exit; - if (group_peer_exit_index == index) { - return group_peer_exit; - } - ++group_peer_exit_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_group_peer_exit_size(const Tox_Events *events) -{ - uint32_t group_peer_exit_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_GROUP_PEER_EXIT) { - ++group_peer_exit_size; - } - } - - return group_peer_exit_size; -} - bool tox_event_group_peer_exit_unpack( Tox_Event_Group_Peer_Exit **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/group_peer_join.c b/toxcore/events/group_peer_join.c index f19ab49296..ec366cfc8c 100644 --- a/toxcore/events/group_peer_join.c +++ b/toxcore/events/group_peer_join.c @@ -139,42 +139,6 @@ static Tox_Event_Group_Peer_Join *tox_events_add_group_peer_join(Tox_Events *eve return group_peer_join; } -const Tox_Event_Group_Peer_Join *tox_events_get_group_peer_join(const Tox_Events *events, uint32_t index) -{ - uint32_t group_peer_join_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (group_peer_join_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_GROUP_PEER_JOIN) { - const Tox_Event_Group_Peer_Join *group_peer_join = events->events[i].data.group_peer_join; - if (group_peer_join_index == index) { - return group_peer_join; - } - ++group_peer_join_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_group_peer_join_size(const Tox_Events *events) -{ - uint32_t group_peer_join_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_GROUP_PEER_JOIN) { - ++group_peer_join_size; - } - } - - return group_peer_join_size; -} - bool tox_event_group_peer_join_unpack( Tox_Event_Group_Peer_Join **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/group_peer_limit.c b/toxcore/events/group_peer_limit.c index 47cdb5b525..7e37cef3dd 100644 --- a/toxcore/events/group_peer_limit.c +++ b/toxcore/events/group_peer_limit.c @@ -139,42 +139,6 @@ static Tox_Event_Group_Peer_Limit *tox_events_add_group_peer_limit(Tox_Events *e return group_peer_limit; } -const Tox_Event_Group_Peer_Limit *tox_events_get_group_peer_limit(const Tox_Events *events, uint32_t index) -{ - uint32_t group_peer_limit_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (group_peer_limit_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_GROUP_PEER_LIMIT) { - const Tox_Event_Group_Peer_Limit *group_peer_limit = events->events[i].data.group_peer_limit; - if (group_peer_limit_index == index) { - return group_peer_limit; - } - ++group_peer_limit_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_group_peer_limit_size(const Tox_Events *events) -{ - uint32_t group_peer_limit_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_GROUP_PEER_LIMIT) { - ++group_peer_limit_size; - } - } - - return group_peer_limit_size; -} - bool tox_event_group_peer_limit_unpack( Tox_Event_Group_Peer_Limit **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/group_peer_name.c b/toxcore/events/group_peer_name.c index e99e79893a..e81ee04ccd 100644 --- a/toxcore/events/group_peer_name.c +++ b/toxcore/events/group_peer_name.c @@ -179,42 +179,6 @@ static Tox_Event_Group_Peer_Name *tox_events_add_group_peer_name(Tox_Events *eve return group_peer_name; } -const Tox_Event_Group_Peer_Name *tox_events_get_group_peer_name(const Tox_Events *events, uint32_t index) -{ - uint32_t group_peer_name_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (group_peer_name_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_GROUP_PEER_NAME) { - const Tox_Event_Group_Peer_Name *group_peer_name = events->events[i].data.group_peer_name; - if (group_peer_name_index == index) { - return group_peer_name; - } - ++group_peer_name_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_group_peer_name_size(const Tox_Events *events) -{ - uint32_t group_peer_name_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_GROUP_PEER_NAME) { - ++group_peer_name_size; - } - } - - return group_peer_name_size; -} - bool tox_event_group_peer_name_unpack( Tox_Event_Group_Peer_Name **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/group_peer_status.c b/toxcore/events/group_peer_status.c index cbf5f2cbb3..8bf456f1d1 100644 --- a/toxcore/events/group_peer_status.c +++ b/toxcore/events/group_peer_status.c @@ -156,42 +156,6 @@ static Tox_Event_Group_Peer_Status *tox_events_add_group_peer_status(Tox_Events return group_peer_status; } -const Tox_Event_Group_Peer_Status *tox_events_get_group_peer_status(const Tox_Events *events, uint32_t index) -{ - uint32_t group_peer_status_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (group_peer_status_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_GROUP_PEER_STATUS) { - const Tox_Event_Group_Peer_Status *group_peer_status = events->events[i].data.group_peer_status; - if (group_peer_status_index == index) { - return group_peer_status; - } - ++group_peer_status_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_group_peer_status_size(const Tox_Events *events) -{ - uint32_t group_peer_status_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_GROUP_PEER_STATUS) { - ++group_peer_status_size; - } - } - - return group_peer_status_size; -} - bool tox_event_group_peer_status_unpack( Tox_Event_Group_Peer_Status **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/group_privacy_state.c b/toxcore/events/group_privacy_state.c index 330ed224c6..e82e42382c 100644 --- a/toxcore/events/group_privacy_state.c +++ b/toxcore/events/group_privacy_state.c @@ -140,42 +140,6 @@ static Tox_Event_Group_Privacy_State *tox_events_add_group_privacy_state(Tox_Eve return group_privacy_state; } -const Tox_Event_Group_Privacy_State *tox_events_get_group_privacy_state(const Tox_Events *events, uint32_t index) -{ - uint32_t group_privacy_state_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (group_privacy_state_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_GROUP_PRIVACY_STATE) { - const Tox_Event_Group_Privacy_State *group_privacy_state = events->events[i].data.group_privacy_state; - if (group_privacy_state_index == index) { - return group_privacy_state; - } - ++group_privacy_state_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_group_privacy_state_size(const Tox_Events *events) -{ - uint32_t group_privacy_state_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_GROUP_PRIVACY_STATE) { - ++group_privacy_state_size; - } - } - - return group_privacy_state_size; -} - bool tox_event_group_privacy_state_unpack( Tox_Event_Group_Privacy_State **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/group_private_message.c b/toxcore/events/group_private_message.c index 8e171c4ddd..efa62fbcba 100644 --- a/toxcore/events/group_private_message.c +++ b/toxcore/events/group_private_message.c @@ -196,42 +196,6 @@ static Tox_Event_Group_Private_Message *tox_events_add_group_private_message(Tox return group_private_message; } -const Tox_Event_Group_Private_Message *tox_events_get_group_private_message(const Tox_Events *events, uint32_t index) -{ - uint32_t group_private_message_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (group_private_message_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_GROUP_PRIVATE_MESSAGE) { - const Tox_Event_Group_Private_Message *group_private_message = events->events[i].data.group_private_message; - if (group_private_message_index == index) { - return group_private_message; - } - ++group_private_message_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_group_private_message_size(const Tox_Events *events) -{ - uint32_t group_private_message_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_GROUP_PRIVATE_MESSAGE) { - ++group_private_message_size; - } - } - - return group_private_message_size; -} - bool tox_event_group_private_message_unpack( Tox_Event_Group_Private_Message **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/group_self_join.c b/toxcore/events/group_self_join.c index 5d23cdea35..ceca661ff3 100644 --- a/toxcore/events/group_self_join.c +++ b/toxcore/events/group_self_join.c @@ -118,42 +118,6 @@ static Tox_Event_Group_Self_Join *tox_events_add_group_self_join(Tox_Events *eve return group_self_join; } -const Tox_Event_Group_Self_Join *tox_events_get_group_self_join(const Tox_Events *events, uint32_t index) -{ - uint32_t group_self_join_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (group_self_join_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_GROUP_SELF_JOIN) { - const Tox_Event_Group_Self_Join *group_self_join = events->events[i].data.group_self_join; - if (group_self_join_index == index) { - return group_self_join; - } - ++group_self_join_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_group_self_join_size(const Tox_Events *events) -{ - uint32_t group_self_join_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_GROUP_SELF_JOIN) { - ++group_self_join_size; - } - } - - return group_self_join_size; -} - bool tox_event_group_self_join_unpack( Tox_Event_Group_Self_Join **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/group_topic.c b/toxcore/events/group_topic.c index 5a4fffead7..48f5ed7c26 100644 --- a/toxcore/events/group_topic.c +++ b/toxcore/events/group_topic.c @@ -179,42 +179,6 @@ static Tox_Event_Group_Topic *tox_events_add_group_topic(Tox_Events *events, con return group_topic; } -const Tox_Event_Group_Topic *tox_events_get_group_topic(const Tox_Events *events, uint32_t index) -{ - uint32_t group_topic_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (group_topic_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_GROUP_TOPIC) { - const Tox_Event_Group_Topic *group_topic = events->events[i].data.group_topic; - if (group_topic_index == index) { - return group_topic; - } - ++group_topic_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_group_topic_size(const Tox_Events *events) -{ - uint32_t group_topic_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_GROUP_TOPIC) { - ++group_topic_size; - } - } - - return group_topic_size; -} - bool tox_event_group_topic_unpack( Tox_Event_Group_Topic **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/group_topic_lock.c b/toxcore/events/group_topic_lock.c index 1f30166748..17d71028e8 100644 --- a/toxcore/events/group_topic_lock.c +++ b/toxcore/events/group_topic_lock.c @@ -140,42 +140,6 @@ static Tox_Event_Group_Topic_Lock *tox_events_add_group_topic_lock(Tox_Events *e return group_topic_lock; } -const Tox_Event_Group_Topic_Lock *tox_events_get_group_topic_lock(const Tox_Events *events, uint32_t index) -{ - uint32_t group_topic_lock_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (group_topic_lock_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_GROUP_TOPIC_LOCK) { - const Tox_Event_Group_Topic_Lock *group_topic_lock = events->events[i].data.group_topic_lock; - if (group_topic_lock_index == index) { - return group_topic_lock; - } - ++group_topic_lock_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_group_topic_lock_size(const Tox_Events *events) -{ - uint32_t group_topic_lock_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_GROUP_TOPIC_LOCK) { - ++group_topic_lock_size; - } - } - - return group_topic_lock_size; -} - bool tox_event_group_topic_lock_unpack( Tox_Event_Group_Topic_Lock **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/group_voice_state.c b/toxcore/events/group_voice_state.c index 8ed1982720..053c9ed89f 100644 --- a/toxcore/events/group_voice_state.c +++ b/toxcore/events/group_voice_state.c @@ -140,42 +140,6 @@ static Tox_Event_Group_Voice_State *tox_events_add_group_voice_state(Tox_Events return group_voice_state; } -const Tox_Event_Group_Voice_State *tox_events_get_group_voice_state(const Tox_Events *events, uint32_t index) -{ - uint32_t group_voice_state_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (group_voice_state_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_GROUP_VOICE_STATE) { - const Tox_Event_Group_Voice_State *group_voice_state = events->events[i].data.group_voice_state; - if (group_voice_state_index == index) { - return group_voice_state; - } - ++group_voice_state_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_group_voice_state_size(const Tox_Events *events) -{ - uint32_t group_voice_state_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_GROUP_VOICE_STATE) { - ++group_voice_state_size; - } - } - - return group_voice_state_size; -} - bool tox_event_group_voice_state_unpack( Tox_Event_Group_Voice_State **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/events/self_connection_status.c b/toxcore/events/self_connection_status.c index 60043a4b94..945f4bb6a2 100644 --- a/toxcore/events/self_connection_status.c +++ b/toxcore/events/self_connection_status.c @@ -119,42 +119,6 @@ static Tox_Event_Self_Connection_Status *tox_events_add_self_connection_status(T return self_connection_status; } -const Tox_Event_Self_Connection_Status *tox_events_get_self_connection_status(const Tox_Events *events, uint32_t index) -{ - uint32_t self_connection_status_index = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (self_connection_status_index > index) { - return nullptr; - } - - if (events->events[i].type == TOX_EVENT_SELF_CONNECTION_STATUS) { - const Tox_Event_Self_Connection_Status *self_connection_status = events->events[i].data.self_connection_status; - if (self_connection_status_index == index) { - return self_connection_status; - } - ++self_connection_status_index; - } - } - - return nullptr; -} - -uint32_t tox_events_get_self_connection_status_size(const Tox_Events *events) -{ - uint32_t self_connection_status_size = 0; - const uint32_t size = tox_events_get_size(events); - - for (uint32_t i = 0; i < size; ++i) { - if (events->events[i].type == TOX_EVENT_SELF_CONNECTION_STATUS) { - ++self_connection_status_size; - } - } - - return self_connection_status_size; -} - bool tox_event_self_connection_status_unpack( Tox_Event_Self_Connection_Status **event, Bin_Unpack *bu, const Memory *mem) { diff --git a/toxcore/tox_dispatch.c b/toxcore/tox_dispatch.c index 63b4eb0247..bbf09493c5 100644 --- a/toxcore/tox_dispatch.c +++ b/toxcore/tox_dispatch.c @@ -278,7 +278,7 @@ void tox_events_callback_group_moderation( dispatch->group_moderation_callback = callback; } -non_null(1, 2, 3) nullable(4) +non_null(1, 2) nullable(3, 4) static void tox_dispatch_invoke_event(const Tox_Dispatch *dispatch, const Tox_Event *event, Tox *tox, void *user_data) { switch (event->type) { diff --git a/toxcore/tox_events.h b/toxcore/tox_events.h index 4010848990..05edd4f4bb 100644 --- a/toxcore/tox_events.h +++ b/toxcore/tox_events.h @@ -497,125 +497,6 @@ typedef struct Tox_Events Tox_Events; uint32_t tox_events_get_size(const Tox_Events *events); const Tox_Event *tox_events_get(const Tox_Events *events, uint32_t index); -uint32_t tox_events_get_conference_connected_size(const Tox_Events *events); -uint32_t tox_events_get_conference_invite_size(const Tox_Events *events); -uint32_t tox_events_get_conference_message_size(const Tox_Events *events); -uint32_t tox_events_get_conference_peer_list_changed_size(const Tox_Events *events); -uint32_t tox_events_get_conference_peer_name_size(const Tox_Events *events); -uint32_t tox_events_get_conference_title_size(const Tox_Events *events); -uint32_t tox_events_get_file_chunk_request_size(const Tox_Events *events); -uint32_t tox_events_get_file_recv_chunk_size(const Tox_Events *events); -uint32_t tox_events_get_file_recv_control_size(const Tox_Events *events); -uint32_t tox_events_get_file_recv_size(const Tox_Events *events); -uint32_t tox_events_get_friend_connection_status_size(const Tox_Events *events); -uint32_t tox_events_get_friend_lossless_packet_size(const Tox_Events *events); -uint32_t tox_events_get_friend_lossy_packet_size(const Tox_Events *events); -uint32_t tox_events_get_friend_message_size(const Tox_Events *events); -uint32_t tox_events_get_friend_name_size(const Tox_Events *events); -uint32_t tox_events_get_friend_read_receipt_size(const Tox_Events *events); -uint32_t tox_events_get_friend_request_size(const Tox_Events *events); -uint32_t tox_events_get_friend_status_message_size(const Tox_Events *events); -uint32_t tox_events_get_friend_status_size(const Tox_Events *events); -uint32_t tox_events_get_friend_typing_size(const Tox_Events *events); -uint32_t tox_events_get_self_connection_status_size(const Tox_Events *events); -uint32_t tox_events_get_group_peer_name_size(const Tox_Events *events); -uint32_t tox_events_get_group_peer_status_size(const Tox_Events *events); -uint32_t tox_events_get_group_topic_size(const Tox_Events *events); -uint32_t tox_events_get_group_privacy_state_size(const Tox_Events *events); -uint32_t tox_events_get_group_voice_state_size(const Tox_Events *events); -uint32_t tox_events_get_group_topic_lock_size(const Tox_Events *events); -uint32_t tox_events_get_group_peer_limit_size(const Tox_Events *events); -uint32_t tox_events_get_group_password_size(const Tox_Events *events); -uint32_t tox_events_get_group_message_size(const Tox_Events *events); -uint32_t tox_events_get_group_private_message_size(const Tox_Events *events); -uint32_t tox_events_get_group_custom_packet_size(const Tox_Events *events); -uint32_t tox_events_get_group_custom_private_packet_size(const Tox_Events *events); -uint32_t tox_events_get_group_invite_size(const Tox_Events *events); -uint32_t tox_events_get_group_peer_join_size(const Tox_Events *events); -uint32_t tox_events_get_group_peer_exit_size(const Tox_Events *events); -uint32_t tox_events_get_group_self_join_size(const Tox_Events *events); -uint32_t tox_events_get_group_join_fail_size(const Tox_Events *events); -uint32_t tox_events_get_group_moderation_size(const Tox_Events *events); - -const Tox_Event_Conference_Connected *tox_events_get_conference_connected( - const Tox_Events *events, uint32_t index); -const Tox_Event_Conference_Invite *tox_events_get_conference_invite( - const Tox_Events *events, uint32_t index); -const Tox_Event_Conference_Message *tox_events_get_conference_message( - const Tox_Events *events, uint32_t index); -const Tox_Event_Conference_Peer_List_Changed *tox_events_get_conference_peer_list_changed( - const Tox_Events *events, uint32_t index); -const Tox_Event_Conference_Peer_Name *tox_events_get_conference_peer_name( - const Tox_Events *events, uint32_t index); -const Tox_Event_Conference_Title *tox_events_get_conference_title( - const Tox_Events *events, uint32_t index); -const Tox_Event_File_Chunk_Request *tox_events_get_file_chunk_request( - const Tox_Events *events, uint32_t index); -const Tox_Event_File_Recv_Chunk *tox_events_get_file_recv_chunk( - const Tox_Events *events, uint32_t index); -const Tox_Event_File_Recv_Control *tox_events_get_file_recv_control( - const Tox_Events *events, uint32_t index); -const Tox_Event_File_Recv *tox_events_get_file_recv( - const Tox_Events *events, uint32_t index); -const Tox_Event_Friend_Connection_Status *tox_events_get_friend_connection_status( - const Tox_Events *events, uint32_t index); -const Tox_Event_Friend_Lossless_Packet *tox_events_get_friend_lossless_packet( - const Tox_Events *events, uint32_t index); -const Tox_Event_Friend_Lossy_Packet *tox_events_get_friend_lossy_packet( - const Tox_Events *events, uint32_t index); -const Tox_Event_Friend_Message *tox_events_get_friend_message( - const Tox_Events *events, uint32_t index); -const Tox_Event_Friend_Name *tox_events_get_friend_name( - const Tox_Events *events, uint32_t index); -const Tox_Event_Friend_Read_Receipt *tox_events_get_friend_read_receipt( - const Tox_Events *events, uint32_t index); -const Tox_Event_Friend_Request *tox_events_get_friend_request( - const Tox_Events *events, uint32_t index); -const Tox_Event_Friend_Status_Message *tox_events_get_friend_status_message( - const Tox_Events *events, uint32_t index); -const Tox_Event_Friend_Status *tox_events_get_friend_status( - const Tox_Events *events, uint32_t index); -const Tox_Event_Friend_Typing *tox_events_get_friend_typing( - const Tox_Events *events, uint32_t index); -const Tox_Event_Self_Connection_Status *tox_events_get_self_connection_status( - const Tox_Events *events, uint32_t index); -const Tox_Event_Group_Peer_Name *tox_events_get_group_peer_name( - const Tox_Events *events, uint32_t index); -const Tox_Event_Group_Peer_Status *tox_events_get_group_peer_status( - const Tox_Events *events, uint32_t index); -const Tox_Event_Group_Topic *tox_events_get_group_topic( - const Tox_Events *events, uint32_t index); -const Tox_Event_Group_Privacy_State *tox_events_get_group_privacy_state( - const Tox_Events *events, uint32_t index); -const Tox_Event_Group_Voice_State *tox_events_get_group_voice_state( - const Tox_Events *events, uint32_t index); -const Tox_Event_Group_Topic_Lock *tox_events_get_group_topic_lock( - const Tox_Events *events, uint32_t index); -const Tox_Event_Group_Peer_Limit *tox_events_get_group_peer_limit( - const Tox_Events *events, uint32_t index); -const Tox_Event_Group_Password *tox_events_get_group_password( - const Tox_Events *events, uint32_t index); -const Tox_Event_Group_Message *tox_events_get_group_message( - const Tox_Events *events, uint32_t index); -const Tox_Event_Group_Private_Message *tox_events_get_group_private_message( - const Tox_Events *events, uint32_t index); -const Tox_Event_Group_Custom_Packet *tox_events_get_group_custom_packet( - const Tox_Events *events, uint32_t index); -const Tox_Event_Group_Custom_Private_Packet *tox_events_get_group_custom_private_packet( - const Tox_Events *events, uint32_t index); -const Tox_Event_Group_Invite *tox_events_get_group_invite( - const Tox_Events *events, uint32_t index); -const Tox_Event_Group_Peer_Join *tox_events_get_group_peer_join( - const Tox_Events *events, uint32_t index); -const Tox_Event_Group_Peer_Exit *tox_events_get_group_peer_exit( - const Tox_Events *events, uint32_t index); -const Tox_Event_Group_Self_Join *tox_events_get_group_self_join( - const Tox_Events *events, uint32_t index); -const Tox_Event_Group_Join_Fail *tox_events_get_group_join_fail( - const Tox_Events *events, uint32_t index); -const Tox_Event_Group_Moderation *tox_events_get_group_moderation( - const Tox_Events *events, uint32_t index); - /** * Initialise the events recording system. * diff --git a/toxcore/tox_events_fuzz_test.cc b/toxcore/tox_events_fuzz_test.cc index ab1acb64ca..993cf8128b 100644 --- a/toxcore/tox_events_fuzz_test.cc +++ b/toxcore/tox_events_fuzz_test.cc @@ -1,10 +1,12 @@ #include "tox_events.h" +#include #include #include #include #include "../testing/fuzzing/fuzz_support.h" +#include "tox_dispatch.h" namespace { @@ -27,12 +29,59 @@ void TestUnpack(Fuzz_Data data) // rest of the fuzz data is input for malloc Fuzz_System sys{data}; + Tox_Dispatch *dispatch = tox_dispatch_new(nullptr); + assert(dispatch != nullptr); + + auto ignore = [](Tox *tox, auto *event, void *user_data) {}; + tox_events_callback_conference_connected(dispatch, ignore); + tox_events_callback_conference_invite(dispatch, ignore); + tox_events_callback_conference_message(dispatch, ignore); + tox_events_callback_conference_peer_list_changed(dispatch, ignore); + tox_events_callback_conference_peer_name(dispatch, ignore); + tox_events_callback_conference_title(dispatch, ignore); + tox_events_callback_file_chunk_request(dispatch, ignore); + tox_events_callback_file_recv(dispatch, ignore); + tox_events_callback_file_recv_chunk(dispatch, ignore); + tox_events_callback_file_recv_control(dispatch, ignore); + tox_events_callback_friend_connection_status(dispatch, ignore); + tox_events_callback_friend_lossless_packet(dispatch, ignore); + tox_events_callback_friend_lossy_packet(dispatch, ignore); + tox_events_callback_friend_message(dispatch, ignore); + tox_events_callback_friend_name(dispatch, ignore); + tox_events_callback_friend_read_receipt(dispatch, ignore); + tox_events_callback_friend_request(dispatch, ignore); + tox_events_callback_friend_status(dispatch, ignore); + tox_events_callback_friend_status_message(dispatch, ignore); + tox_events_callback_friend_typing(dispatch, ignore); + tox_events_callback_self_connection_status(dispatch, ignore); + tox_events_callback_group_peer_name(dispatch, ignore); + tox_events_callback_group_peer_status(dispatch, ignore); + tox_events_callback_group_topic(dispatch, ignore); + tox_events_callback_group_privacy_state(dispatch, ignore); + tox_events_callback_group_voice_state(dispatch, ignore); + tox_events_callback_group_topic_lock(dispatch, ignore); + tox_events_callback_group_peer_limit(dispatch, ignore); + tox_events_callback_group_password(dispatch, ignore); + tox_events_callback_group_message(dispatch, ignore); + tox_events_callback_group_private_message(dispatch, ignore); + tox_events_callback_group_custom_packet(dispatch, ignore); + tox_events_callback_group_custom_private_packet(dispatch, ignore); + tox_events_callback_group_invite(dispatch, ignore); + tox_events_callback_group_peer_join(dispatch, ignore); + tox_events_callback_group_peer_exit(dispatch, ignore); + tox_events_callback_group_self_join(dispatch, ignore); + tox_events_callback_group_join_fail(dispatch, ignore); + tox_events_callback_group_moderation(dispatch, ignore); + Tox_Events *events = tox_events_load(sys.sys.get(), events_data, events_size); if (events) { std::vector packed(tox_events_bytes_size(events)); tox_events_get_bytes(events, packed.data()); + + tox_dispatch_invoke(dispatch, events, nullptr, nullptr); } tox_events_free(events); + tox_dispatch_free(dispatch); } } // namespace diff --git a/toxcore/tox_events_test.cc b/toxcore/tox_events_test.cc index 5de29b5e48..749d6768f3 100644 --- a/toxcore/tox_events_test.cc +++ b/toxcore/tox_events_test.cc @@ -33,7 +33,7 @@ TEST(ToxEvents, UnpackEmptyArrayCreatesEmptyEvents) std::array data{0x90}; // empty msgpack array Tox_Events *events = tox_events_load(&sys, data.data(), data.size()); ASSERT_NE(events, nullptr); - EXPECT_EQ(tox_events_get_conference_connected_size(events), 0); + EXPECT_EQ(tox_events_get_size(events), 0); tox_events_free(events); }