From bdf5ac37b45870e8b8e7d621334d7bd034bf7149 Mon Sep 17 00:00:00 2001 From: iphydf Date: Thu, 18 Aug 2016 00:37:45 +0100 Subject: [PATCH] Make friend_status_message callback stateless. See #40 for details. --- auto_tests/tox_test.c | 2 +- other/apidsl/tox.in.h | 2 +- testing/nTox.c | 2 +- toxcore/Messenger.c | 7 ++----- toxcore/Messenger.h | 4 +--- toxcore/tox.c | 4 ++-- toxcore/tox.h | 2 +- 7 files changed, 9 insertions(+), 14 deletions(-) diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index 00146318..2146bdcf 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c @@ -560,7 +560,7 @@ START_TEST(test_few_clients) tox_friend_get_name(tox3, 0, temp_name, 0); ck_assert_msg(memcmp(temp_name, "Gentoo", sizeof("Gentoo")) == 0, "Name not correct"); - tox_callback_friend_status_message(tox3, print_status_m_change, &to_compare); + tox_callback_friend_status_message(tox3, print_status_m_change); succ = tox_self_set_status_message(tox2, (uint8_t *)"Installing Gentoo", sizeof("Installing Gentoo"), &err_n); ck_assert_msg(succ && err_n == TOX_ERR_SET_INFO_OK, "tox_self_set_status_message failed because %u\n", err_n); diff --git a/other/apidsl/tox.in.h b/other/apidsl/tox.in.h index 2af19172..0aca1716 100644 --- a/other/apidsl/tox.in.h +++ b/other/apidsl/tox.in.h @@ -1240,7 +1240,7 @@ namespace friend { /** * This event is triggered when a friend changes their status message. */ - event status_message { + event status_message const { /** * @param friend_number The friend number of the friend whose status message * changed. diff --git a/testing/nTox.c b/testing/nTox.c index ba7c2399..5e70e728 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -1293,7 +1293,7 @@ int main(int argc, char *argv[]) tox_callback_friend_request(m, print_request, NULL); tox_callback_friend_message(m, print_message, NULL); tox_callback_friend_name(m, print_nickchange); - tox_callback_friend_status_message(m, print_statuschange, NULL); + tox_callback_friend_status_message(m, print_statuschange); tox_callback_group_invite(m, print_invite, NULL); tox_callback_group_message(m, print_groupmessage, NULL); tox_callback_file_recv_chunk(m, write_file, NULL); diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index e5779fb6..d7fa8e64 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -782,11 +782,9 @@ void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, uint32_t m->friend_namechange = function; } -void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *), - void *userdata) +void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *)) { m->friend_statusmessagechange = function; - m->friend_statusmessagechange_userdata = userdata; } void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *), void *userdata) @@ -1959,8 +1957,7 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len, void data_terminated[data_length] = 0; if (m->friend_statusmessagechange) - m->friend_statusmessagechange(m, i, data_terminated, data_length, - m->friend_statusmessagechange_userdata); + m->friend_statusmessagechange(m, i, data_terminated, data_length, userdata); set_friend_statusmessage(m, i, data_terminated, data_length); break; diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 5af9e274..9dae8446 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h @@ -241,7 +241,6 @@ struct Messenger { void *friend_message_userdata; void (*friend_namechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); void (*friend_statusmessagechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); - void *friend_statusmessagechange_userdata; void (*friend_userstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *); void *friend_userstatuschange_userdata; void (*friend_typingchange)(struct Messenger *m, uint32_t, _Bool, void *); @@ -491,8 +490,7 @@ void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, uint32_t * * You are not responsible for freeing newstatus */ -void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *), - void *userdata); +void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *)); /* Set the callback for status type changes. * Function(uint32_t friendnumber, USERSTATUS kind) diff --git a/toxcore/tox.c b/toxcore/tox.c index 2d3c97a9..51307fc1 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -761,10 +761,10 @@ bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8 return 1; } -void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *function, void *user_data) +void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *function) { Messenger *m = tox; - m_callback_statusmessage(m, function, user_data); + m_callback_statusmessage(m, function); } TOX_USER_STATUS tox_friend_get_status(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error) diff --git a/toxcore/tox.h b/toxcore/tox.h index 5e6de408..1bb98a76 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -1327,7 +1327,7 @@ typedef void tox_friend_status_message_cb(Tox *tox, uint32_t friend_number, cons * * This event is triggered when a friend changes their status message. */ -void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *callback, void *user_data); +void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *callback); /** * Return the friend's user status (away/busy/...). If the friend number is