From bd7b7fadbacbb84144ed2160109befa106623d5d Mon Sep 17 00:00:00 2001 From: iphydf Date: Sat, 7 Mar 2020 14:21:54 +0000 Subject: [PATCH] Pass packet ID to custom packet handlers. We don't expose this to the user code, yet, because it would break the API, but this is useful for future internal code. --- toxcore/Messenger.c | 4 ++-- toxcore/Messenger.h | 8 ++++---- toxcore/tox.c | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index b745d99b..a702793c 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -1824,7 +1824,7 @@ static int m_handle_lossy_packet(void *object, int friend_num, const uint8_t *pa } if (m->lossy_packethandler) { - m->lossy_packethandler(m, friend_num, packet, length, userdata); + m->lossy_packethandler(m, friend_num, packet[0], packet, length, userdata); } return 1; @@ -1900,7 +1900,7 @@ static int handle_custom_lossless_packet(void *object, int friend_num, const uin } if (m->lossless_packethandler) { - m->lossless_packethandler(m, friend_num, packet, length, userdata); + m->lossless_packethandler(m, friend_num, packet[0], packet, length, userdata); } return 1; diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index a3376e23..f6fb3d56 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h @@ -200,10 +200,10 @@ typedef void m_file_chunk_request_cb(Messenger *m, uint32_t friend_number, uint3 size_t length, void *user_data); typedef void m_file_recv_chunk_cb(Messenger *m, uint32_t friend_number, uint32_t file_number, uint64_t position, const uint8_t *data, size_t length, void *user_data); -typedef void m_friend_lossy_packet_cb(Messenger *m, uint32_t friend_number, const uint8_t *data, size_t length, - void *user_data); -typedef void m_friend_lossless_packet_cb(Messenger *m, uint32_t friend_number, const uint8_t *data, size_t length, - void *user_data); +typedef void m_friend_lossy_packet_cb(Messenger *m, uint32_t friend_number, uint8_t packet_id, const uint8_t *data, + size_t length, void *user_data); +typedef void m_friend_lossless_packet_cb(Messenger *m, uint32_t friend_number, uint8_t packet_id, const uint8_t *data, + size_t length, void *user_data); typedef void m_friend_connectionstatuschange_internal_cb(Messenger *m, uint32_t friend_number, uint8_t connection_status, void *user_data); typedef void m_conference_invite_cb(Messenger *m, uint32_t friend_number, const uint8_t *cookie, uint16_t length, diff --git a/toxcore/tox.c b/toxcore/tox.c index 0a575dbf..530035f7 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -302,8 +302,8 @@ static void tox_conference_peer_list_changed_handler(Messenger *m, uint32_t conf } } -static void tox_friend_lossy_packet_handler(Messenger *m, uint32_t friend_number, const uint8_t *data, size_t length, - void *user_data) +static void tox_friend_lossy_packet_handler(Messenger *m, uint32_t friend_number, uint8_t packet_id, + const uint8_t *data, size_t length, void *user_data) { struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; @@ -312,8 +312,8 @@ static void tox_friend_lossy_packet_handler(Messenger *m, uint32_t friend_number } } -static void tox_friend_lossless_packet_handler(Messenger *m, uint32_t friend_number, const uint8_t *data, size_t length, - void *user_data) +static void tox_friend_lossless_packet_handler(Messenger *m, uint32_t friend_number, uint8_t packet_id, + const uint8_t *data, size_t length, void *user_data) { struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data;