From 03b55cde1a98b02f9019f068340094b5062857d1 Mon Sep 17 00:00:00 2001 From: sudden6 Date: Mon, 19 Feb 2018 22:58:03 +0100 Subject: [PATCH] make groupnumber uint32_t fixes #606 --- toxav/groupav.c | 43 +++++++-------- toxav/groupav.h | 13 ++--- toxav/toxav.api.h | 16 +++--- toxav/toxav.h | 18 +++--- toxav/toxav_old.c | 17 +++--- toxcore/group.c | 138 ++++++++++++++++++++++++++-------------------- toxcore/group.h | 77 ++++++++++++++------------ toxcore/tox.c | 3 +- 8 files changed, 174 insertions(+), 151 deletions(-) diff --git a/toxav/groupav.c b/toxav/groupav.c index c19c1b3c..e9595b4e 100644 --- a/toxav/groupav.c +++ b/toxav/groupav.c @@ -164,7 +164,7 @@ typedef struct { uint16_t audio_sequnum; - void (*audio_data)(Messenger *m, int groupnumber, int peernumber, const int16_t *pcm, unsigned int samples, + void (*audio_data)(Messenger *m, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, uint32_t samples, uint8_t channels, unsigned int sample_rate, void *userdata); void *userdata; } Group_AV; @@ -224,9 +224,8 @@ static int recreate_encoder(Group_AV *group_av) return 0; } -static Group_AV *new_group_av(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messenger *, int, int, - const int16_t *, - unsigned int, uint8_t, unsigned int, void *), void *userdata) +static Group_AV *new_group_av(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messenger *, uint32_t, uint32_t, + const int16_t *, unsigned int, uint8_t, uint32_t, void *), void *userdata) { if (!g_c) { return nullptr; @@ -247,7 +246,7 @@ static Group_AV *new_group_av(Logger *log, Group_Chats *g_c, void (*audio_callba return group_av; } -static void group_av_peer_new(void *object, int groupnumber, int friendgroupnumber) +static void group_av_peer_new(void *object, uint32_t groupnumber, uint32_t friendgroupnumber) { Group_AV *group_av = (Group_AV *)object; Group_Peer_AV *peer_av = (Group_Peer_AV *)calloc(1, sizeof(Group_Peer_AV)); @@ -260,7 +259,7 @@ static void group_av_peer_new(void *object, int groupnumber, int friendgroupnumb group_peer_set_object(group_av->g_c, groupnumber, friendgroupnumber, peer_av); } -static void group_av_peer_delete(void *object, int groupnumber, int friendgroupnumber, void *peer_object) +static void group_av_peer_delete(void *object, uint32_t groupnumber, uint32_t friendgroupnumber, void *peer_object) { Group_Peer_AV *peer_av = (Group_Peer_AV *)peer_object; @@ -276,14 +275,15 @@ static void group_av_peer_delete(void *object, int groupnumber, int friendgroupn free(peer_object); } -static void group_av_groupchat_delete(void *object, int groupnumber) +static void group_av_groupchat_delete(void *object, uint32_t groupnumber) { if (object) { kill_group_av((Group_AV *)object); } } -static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, int groupnumber, int friendgroupnumber) +static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, uint32_t groupnumber, + uint32_t friendgroupnumber) { if (!group_av || !peer_av) { return -1; @@ -388,7 +388,7 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, int g return -1; } -static int handle_group_audio_packet(void *object, int groupnumber, int friendgroupnumber, void *peer_object, +static int handle_group_audio_packet(void *object, uint32_t groupnumber, uint32_t friendgroupnumber, void *peer_object, const uint8_t *packet, uint16_t length) { if (!peer_object || !object || length <= sizeof(uint16_t)) { @@ -426,14 +426,10 @@ static int handle_group_audio_packet(void *object, int groupnumber, int friendgr * return 0 on success. * return -1 on failure. */ -static int groupchat_enable_av(Logger *log, Group_Chats *g_c, int groupnumber, void (*audio_callback)(Messenger *, int, - int, - const int16_t *, unsigned int, uint8_t, unsigned int, void *), void *userdata) +static int groupchat_enable_av(Logger *log, Group_Chats *g_c, uint32_t groupnumber, void (*audio_callback)(Messenger *, + uint32_t, + uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), void *userdata) { - if (groupnumber == -1) { - return -1; - } - Group_AV *group_av = new_group_av(log, g_c, audio_callback, userdata); if (group_av == nullptr) { @@ -457,9 +453,10 @@ static int groupchat_enable_av(Logger *log, Group_Chats *g_c, int groupnumber, v * return group number on success. * return -1 on failure. */ -int add_av_groupchat(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messenger *, int, int, const int16_t *, +int add_av_groupchat(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messenger *, uint32_t, uint32_t, + const int16_t *, unsigned int, - uint8_t, unsigned int, void *), void *userdata) + uint8_t, uint32_t, void *), void *userdata) { int groupnumber = add_groupchat(g_c, GROUPCHAT_TYPE_AV); @@ -480,8 +477,8 @@ int add_av_groupchat(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messe * returns group number on success * returns -1 on failure. */ -int join_av_groupchat(Logger *log, Group_Chats *g_c, int32_t friendnumber, const uint8_t *data, uint16_t length, - void (*audio_callback)(Messenger *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *), +int join_av_groupchat(Logger *log, Group_Chats *g_c, uint32_t friendnumber, const uint8_t *data, uint16_t length, + void (*audio_callback)(Messenger *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), void *userdata) { int groupnumber = join_groupchat(g_c, friendnumber, GROUPCHAT_TYPE_AV, data, length); @@ -503,7 +500,7 @@ int join_av_groupchat(Logger *log, Group_Chats *g_c, int32_t friendnumber, const * return 0 on success. * return -1 on failure. */ -static int send_audio_packet(Group_Chats *g_c, int groupnumber, uint8_t *packet, uint16_t length) +static int send_audio_packet(Group_Chats *g_c, uint32_t groupnumber, uint8_t *packet, uint16_t length) { if (!length) { return -1; @@ -530,8 +527,8 @@ static int send_audio_packet(Group_Chats *g_c, int groupnumber, uint8_t *packet, * return 0 on success. * return -1 on failure. */ -int group_send_audio(Group_Chats *g_c, int groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, - unsigned int sample_rate) +int group_send_audio(Group_Chats *g_c, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, + uint32_t sample_rate) { Group_AV *group_av = (Group_AV *)group_get_object(g_c, groupnumber); diff --git a/toxav/groupav.h b/toxav/groupav.h index 71b0f55a..142edb0e 100644 --- a/toxav/groupav.h +++ b/toxav/groupav.h @@ -29,17 +29,16 @@ * return group number on success. * return -1 on failure. */ -int add_av_groupchat(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messenger *, int, int, const int16_t *, - unsigned int, - uint8_t, unsigned int, void *), void *userdata); +int add_av_groupchat(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messenger *, uint32_t, uint32_t, + const int16_t *, unsigned int, uint8_t, uint32_t, void *), void *userdata); /* Join a AV group (you need to have been invited first.) * * returns group number on success * returns -1 on failure. */ -int join_av_groupchat(Logger *log, Group_Chats *g_c, int32_t friendnumber, const uint8_t *data, uint16_t length, - void (*audio_callback)(Messenger *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *), +int join_av_groupchat(Logger *log, Group_Chats *g_c, uint32_t friendnumber, const uint8_t *data, uint16_t length, + void (*audio_callback)(Messenger *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), void *userdata); @@ -48,6 +47,6 @@ int join_av_groupchat(Logger *log, Group_Chats *g_c, int32_t friendnumber, const * return 0 on success. * return -1 on failure. */ -int group_send_audio(Group_Chats *g_c, int groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, - unsigned int sample_rate); +int group_send_audio(Group_Chats *g_c, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, + uint32_t sample_rate); diff --git a/toxav/toxav.api.h b/toxav/toxav.api.h index 71cd5aec..9e6cea68 100644 --- a/toxav/toxav.api.h +++ b/toxav/toxav.api.h @@ -612,12 +612,12 @@ namespace video { * return -1 on failure. * * Audio data callback format: - * audio_callback(Tox *tox, int groupnumber, int peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, unsigned int sample_rate, void *userdata) + * audio_callback(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, uint32_t sample_rate, void *userdata) * * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). */ -int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, uint8_t, - unsigned int, void *), void *userdata); +int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, + uint32_t, void *), void *userdata); /* Join a AV group (you need to have been invited first.) * @@ -625,12 +625,12 @@ int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, int, int, co * returns -1 on failure. * * Audio data callback format (same as the one for toxav_add_av_groupchat()): - * audio_callback(Tox *tox, int groupnumber, int peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, unsigned int sample_rate, void *userdata) + * audio_callback(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, uint32_t sample_rate, void *userdata) * * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). */ -int toxav_join_av_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length, - void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *), void *userdata); +int toxav_join_av_groupchat(Tox *tox, uint32_t friendnumber, const uint8_t *data, uint16_t length, + void (*audio_callback)(void *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), void *userdata); /* Send audio to the group chat. * @@ -645,8 +645,8 @@ int toxav_join_av_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, * * Recommended values are: samples = 960, channels = 1, sample_rate = 48000 */ -int toxav_group_send_audio(Tox *tox, int groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, - unsigned int sample_rate); +int toxav_group_send_audio(Tox *tox, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, + uint32_t sample_rate); #ifdef __cplusplus } diff --git a/toxav/toxav.h b/toxav/toxav.h index 1f2d6860..911d6b49 100644 --- a/toxav/toxav.h +++ b/toxav/toxav.h @@ -740,12 +740,13 @@ void toxav_callback_video_receive_frame(ToxAV *av, toxav_video_receive_frame_cb * return -1 on failure. * * Audio data callback format: - * audio_callback(Tox *tox, int groupnumber, int peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, unsigned int sample_rate, void *userdata) + * audio_callback(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, uint32_t sample_rate, void *userdata) * * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). */ -int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, uint8_t, - unsigned int, void *), void *userdata); +int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, uint32_t, uint32_t, const int16_t *, unsigned int, + uint8_t, + uint32_t, void *), void *userdata); /* Join a AV group (you need to have been invited first.) * @@ -753,12 +754,13 @@ int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, int, int, co * returns -1 on failure. * * Audio data callback format (same as the one for toxav_add_av_groupchat()): - * audio_callback(Tox *tox, int groupnumber, int peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, unsigned int sample_rate, void *userdata) + * audio_callback(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, uint32_t sample_rate, void *userdata) * * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). */ -int toxav_join_av_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length, - void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *), void *userdata); +int toxav_join_av_groupchat(Tox *tox, uint32_t friendnumber, const uint8_t *data, uint16_t length, + void (*audio_callback)(void *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), + void *userdata); /* Send audio to the group chat. * @@ -773,8 +775,8 @@ int toxav_join_av_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, * * Recommended values are: samples = 960, channels = 1, sample_rate = 48000 */ -int toxav_group_send_audio(Tox *tox, int groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, - unsigned int sample_rate); +int toxav_group_send_audio(Tox *tox, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, + uint32_t sample_rate); #ifdef __cplusplus } diff --git a/toxav/toxav_old.c b/toxav/toxav_old.c index 10d1c72d..d5278623 100644 --- a/toxav/toxav_old.c +++ b/toxav/toxav_old.c @@ -35,12 +35,12 @@ * * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). */ -int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, - uint8_t, unsigned int, void *), void *userdata) +int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, uint32_t, uint32_t, const int16_t *, unsigned int, + uint8_t, uint32_t, void *), void *userdata) { Messenger *m = (Messenger *)tox; return add_av_groupchat(m->log, (Group_Chats *)m->conferences_object, - (void (*)(Messenger *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *))audio_callback, + (void (*)(Messenger *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *))audio_callback, userdata); } @@ -54,13 +54,14 @@ int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, int, int, co * * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). */ -int toxav_join_av_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length, - void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *), +int toxav_join_av_groupchat(Tox *tox, uint32_t friendnumber, const uint8_t *data, uint16_t length, + void (*audio_callback) + (void *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), void *userdata) { Messenger *m = (Messenger *)tox; return join_av_groupchat(m->log, (Group_Chats *)m->conferences_object, friendnumber, data, length, - (void (*)(Messenger *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *))audio_callback, + (void (*)(Messenger *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *))audio_callback, userdata); } @@ -77,8 +78,8 @@ int toxav_join_av_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, * * Recommended values are: samples = 960, channels = 1, sample_rate = 48000 */ -int toxav_group_send_audio(Tox *tox, int groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, - unsigned int sample_rate) +int toxav_group_send_audio(Tox *tox, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, + uint32_t sample_rate) { Messenger *m = (Messenger *)tox; return group_send_audio((Group_Chats *)m->conferences_object, groupnumber, pcm, samples, channels, sample_rate); diff --git a/toxcore/group.c b/toxcore/group.c index 2dc22501..c9e4feff 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -32,9 +32,9 @@ /* return 1 if the groupnumber is not valid. * return 0 if the groupnumber is valid. */ -static uint8_t groupnumber_not_valid(const Group_Chats *g_c, int groupnumber) +static uint8_t groupnumber_not_valid(const Group_Chats *g_c, uint32_t groupnumber) { - if ((unsigned int)groupnumber >= g_c->num_chats) { + if (groupnumber >= g_c->num_chats) { return 1; } @@ -106,7 +106,7 @@ static int create_group_chat(Group_Chats *g_c) * return -1 on failure. * return 0 on success. */ -static int wipe_group_chat(Group_Chats *g_c, int groupnumber) +static int wipe_group_chat(Group_Chats *g_c, uint32_t groupnumber) { if (groupnumber_not_valid(g_c, groupnumber)) { return -1; @@ -129,7 +129,7 @@ static int wipe_group_chat(Group_Chats *g_c, int groupnumber) return 0; } -static Group_c *get_group_c(const Group_Chats *g_c, int groupnumber) +static Group_c *get_group_c(const Group_Chats *g_c, uint32_t groupnumber) { if (groupnumber_not_valid(g_c, groupnumber)) { return nullptr; @@ -224,9 +224,10 @@ enum { }; static int friend_in_close(Group_c *g, int friendcon_id); -static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, int groupnumber, uint8_t closest, uint8_t lock); +static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, uint32_t groupnumber, uint8_t closest, + uint8_t lock); -static int add_to_closest(Group_Chats *g_c, int groupnumber, const uint8_t *real_pk, const uint8_t *temp_pk) +static int add_to_closest(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *real_pk, const uint8_t *temp_pk) { Group_c *g = get_group_c(g_c, groupnumber); @@ -328,7 +329,7 @@ static unsigned int pk_in_closest_peers(Group_c *g, uint8_t *real_pk) static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16_t group_num, uint8_t *identifier); -static int connect_to_closest(Group_Chats *g_c, int groupnumber, void *userdata) +static int connect_to_closest(Group_Chats *g_c, uint32_t groupnumber, void *userdata) { Group_c *g = get_group_c(g_c, groupnumber); @@ -408,7 +409,7 @@ static int connect_to_closest(Group_Chats *g_c, int groupnumber, void *userdata) * return peer_index if success or peer already in chat. * return -1 if error. */ -static int addpeer(Group_Chats *g_c, int groupnumber, const uint8_t *real_pk, const uint8_t *temp_pk, +static int addpeer(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *real_pk, const uint8_t *temp_pk, uint16_t peer_number, void *userdata, bool do_gc_callback) { Group_c *g = get_group_c(g_c, groupnumber); @@ -465,7 +466,7 @@ static int addpeer(Group_Chats *g_c, int groupnumber, const uint8_t *real_pk, co return (g->numpeers - 1); } -static int remove_close_conn(Group_Chats *g_c, int groupnumber, int friendcon_id) +static int remove_close_conn(Group_Chats *g_c, uint32_t groupnumber, int friendcon_id) { Group_c *g = get_group_c(g_c, groupnumber); @@ -497,7 +498,7 @@ static int remove_close_conn(Group_Chats *g_c, int groupnumber, int friendcon_id * return 0 if success * return -1 if error. */ -static int delpeer(Group_Chats *g_c, int groupnumber, int peer_index, void *userdata) +static int delpeer(Group_Chats *g_c, uint32_t groupnumber, int peer_index, void *userdata) { Group_c *g = get_group_c(g_c, groupnumber); @@ -562,7 +563,7 @@ static int delpeer(Group_Chats *g_c, int groupnumber, int peer_index, void *user * return 0 on success. * return -1 if error. */ -static int setnick(Group_Chats *g_c, int groupnumber, int peer_index, const uint8_t *nick, uint16_t nick_len, +static int setnick(Group_Chats *g_c, uint32_t groupnumber, int peer_index, const uint8_t *nick, uint16_t nick_len, void *userdata, bool do_gc_callback) { if (nick_len > MAX_NAME_LENGTH) { @@ -595,7 +596,7 @@ static int setnick(Group_Chats *g_c, int groupnumber, int peer_index, const uint return 0; } -static int settitle(Group_Chats *g_c, int groupnumber, int peer_index, const uint8_t *title, uint8_t title_len, +static int settitle(Group_Chats *g_c, uint32_t groupnumber, int peer_index, const uint8_t *title, uint8_t title_len, void *userdata) { if (title_len > MAX_NAME_LENGTH || title_len == 0) { @@ -623,7 +624,7 @@ static int settitle(Group_Chats *g_c, int groupnumber, int peer_index, const uin return 0; } -static void set_conns_type_close(Group_Chats *g_c, int groupnumber, int friendcon_id, uint8_t type) +static void set_conns_type_close(Group_Chats *g_c, uint32_t groupnumber, int friendcon_id, uint8_t type) { Group_c *g = get_group_c(g_c, groupnumber); @@ -681,7 +682,8 @@ static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uin * return close index on success * return -1 on failure. */ -static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, int groupnumber, uint8_t closest, uint8_t lock) +static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, uint32_t groupnumber, uint8_t closest, + uint8_t lock) { Group_c *g = get_group_c(g_c, groupnumber); @@ -755,13 +757,13 @@ int add_groupchat(Group_Chats *g_c, uint8_t type) return groupnumber; } -static int group_kill_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num); +static int group_kill_peer_send(const Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_num); /* Delete a groupchat from the chats array. * * return 0 on success. * return -1 if groupnumber is invalid. */ -int del_groupchat(Group_Chats *g_c, int groupnumber) +int del_groupchat(Group_Chats *g_c, uint32_t groupnumber) { Group_c *g = get_group_c(g_c, groupnumber); @@ -804,7 +806,7 @@ int del_groupchat(Group_Chats *g_c, int groupnumber) * return -1 if groupnumber is invalid. * return -2 if peernumber is invalid. */ -int group_peer_pubkey(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *pk) +int group_peer_pubkey(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, uint8_t *pk) { Group_c *g = get_group_c(g_c, groupnumber); @@ -826,7 +828,7 @@ int group_peer_pubkey(const Group_Chats *g_c, int groupnumber, int peernumber, u * return -1 if groupnumber is invalid. * return -2 if peernumber is invalid. */ -int group_peername_size(const Group_Chats *g_c, int groupnumber, int peernumber) +int group_peername_size(const Group_Chats *g_c, uint32_t groupnumber, int peernumber) { Group_c *g = get_group_c(g_c, groupnumber); @@ -852,7 +854,7 @@ int group_peername_size(const Group_Chats *g_c, int groupnumber, int peernumber) * return -1 if groupnumber is invalid. * return -2 if peernumber is invalid. */ -int group_peername(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *name) +int group_peername(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, uint8_t *name) { Group_c *g = get_group_c(g_c, groupnumber); @@ -883,7 +885,7 @@ int group_peername(const Group_Chats *g_c, int groupnumber, int peernumber, uint * * return -1 on failure. */ -int group_names(const Group_Chats *g_c, int groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[], +int group_names(const Group_Chats *g_c, uint32_t groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[], uint16_t length) { Group_c *g = get_group_c(g_c, groupnumber); @@ -904,7 +906,7 @@ int group_names(const Group_Chats *g_c, int groupnumber, uint8_t names[][MAX_NAM /* Return the number of peers in the group chat on success. * return -1 if groupnumber is invalid. */ -int group_number_peers(const Group_Chats *g_c, int groupnumber) +int group_number_peers(const Group_Chats *g_c, uint32_t groupnumber) { Group_c *g = get_group_c(g_c, groupnumber); @@ -921,7 +923,7 @@ int group_number_peers(const Group_Chats *g_c, int groupnumber) * return -2 if peernumber is invalid. * return -3 if we are not connected to the group chat. */ -int group_peernumber_is_ours(const Group_Chats *g_c, int groupnumber, int peernumber) +int group_peernumber_is_ours(const Group_Chats *g_c, uint32_t groupnumber, int peernumber) { Group_c *g = get_group_c(g_c, groupnumber); @@ -945,7 +947,7 @@ int group_peernumber_is_ours(const Group_Chats *g_c, int groupnumber, int peernu * return -1 on failure. * return type on success. */ -int group_get_type(const Group_Chats *g_c, int groupnumber) +int group_get_type(const Group_Chats *g_c, uint32_t groupnumber) { Group_c *g = get_group_c(g_c, groupnumber); @@ -1010,7 +1012,7 @@ static unsigned int send_lossy_group_peer(Friend_Connections *fr_c, int friendco * return -1 if groupnumber is invalid. * return -2 if invite packet failed to send. */ -int invite_friend(Group_Chats *g_c, int32_t friendnumber, int groupnumber) +int invite_friend(Group_Chats *g_c, uint32_t friendnumber, uint32_t groupnumber) { Group_c *g = get_group_c(g_c, groupnumber); @@ -1046,7 +1048,7 @@ static unsigned int send_peer_query(Group_Chats *g_c, int friendcon_id, uint16_t * return -5 if group instance failed to initialize. * return -6 if join packet fails to send. */ -int join_groupchat(Group_Chats *g_c, int32_t friendnumber, uint8_t expected_type, const uint8_t *data, uint16_t length) +int join_groupchat(Group_Chats *g_c, uint32_t friendnumber, uint8_t expected_type, const uint8_t *data, uint16_t length) { if (length != sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH) { return -1; @@ -1109,9 +1111,10 @@ int join_groupchat(Group_Chats *g_c, int32_t friendnumber, uint8_t expected_type * * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed. * - * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object), const uint8_t *packet, uint16_t length) + * Function(void *group object (set with group_set_object), uint32_t groupnumber, uint32_t friendgroupnumber, void *group peer object (set with group_peer_set_object), const uint8_t *packet, uint16_t length) */ -void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, int, int, void *, +void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, uint32_t, uint32_t, + void *, const uint8_t *, uint16_t)) { g_c->lossy_packethandlers[byte].function = function; @@ -1119,7 +1122,7 @@ void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*fu /* Set the callback for group invites. * - * Function(Group_Chats *g_c, int32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata) + * Function(Group_Chats *g_c, int32_t friendnumber, uint8_t type, uint8_t *data, size_t length, void *userdata) * * data of length is what needs to be passed to join_groupchat(). */ @@ -1129,9 +1132,10 @@ void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, ui g_c->invite_callback = function; } +// TODO(sudden6): function signatures in comments are incorrect /* Set the callback for group messages. * - * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) + * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * message, size_t length, void *userdata) */ void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, size_t, void *)) @@ -1139,16 +1143,19 @@ void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, u g_c->message_callback = function; } +// TODO(sudden6): function signatures in comments are incorrect /* Set callback function for peer name list changes. * * It gets called every time the name list changes(new peer/name, deleted peer) * Function(Group_Chats *g_c, int groupnumber, int peernumber, TOX_CHAT_CHANGE change, void *userdata) */ -void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *m, int, int, uint8_t, void *)) +void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *, uint32_t, uint32_t, uint8_t, + void *)) { g_c->group_namelistchange = function; } +// TODO(sudden6): function signatures are incorrect /* Set callback function for title changes. * * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) @@ -1162,12 +1169,13 @@ void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, uin /* Set a function to be called when a new peer joins a group chat. * - * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber) + * Function(void *group object (set with group_set_object), uint32_t groupnumber, uint32_t friendgroupnumber) * * return 0 on success. * return -1 on failure. */ -int callback_groupchat_peer_new(const Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int)) +int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, + uint32_t)) { Group_c *g = get_group_c(g_c, groupnumber); @@ -1181,12 +1189,13 @@ int callback_groupchat_peer_new(const Group_Chats *g_c, int groupnumber, void (* /* Set a function to be called when a peer leaves a group chat. * - * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object)) + * Function(void *group object (set with group_set_object), uint32_t groupnumber, uint32_t friendgroupnumber, void *group peer object (set with group_peer_set_object)) * * return 0 on success. * return -1 on failure. */ -int callback_groupchat_peer_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int, void *)) +int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, uint32_t, + void *)) { Group_c *g = get_group_c(g_c, groupnumber); @@ -1205,7 +1214,7 @@ int callback_groupchat_peer_delete(Group_Chats *g_c, int groupnumber, void (*fun * return 0 on success. * return -1 on failure. */ -int callback_groupchat_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int)) +int callback_groupchat_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t)) { Group_c *g = get_group_c(g_c, groupnumber); @@ -1217,11 +1226,11 @@ int callback_groupchat_delete(Group_Chats *g_c, int groupnumber, void (*function return 0; } -static int send_message_group(const Group_Chats *g_c, int groupnumber, uint8_t message_id, const uint8_t *data, +static int send_message_group(const Group_Chats *g_c, uint32_t groupnumber, uint8_t message_id, const uint8_t *data, uint16_t len); #define GROUP_MESSAGE_PING_ID 0 -static int group_ping_send(const Group_Chats *g_c, int groupnumber) +static int group_ping_send(const Group_Chats *g_c, uint32_t groupnumber) { if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_PING_ID, nullptr, 0) > 0) { return 0; @@ -1236,7 +1245,7 @@ static int group_ping_send(const Group_Chats *g_c, int groupnumber) * return 0 on success * return -1 on failure */ -static int group_new_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num, const uint8_t *real_pk, +static int group_new_peer_send(const Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_num, const uint8_t *real_pk, uint8_t *temp_pk) { uint8_t packet[GROUP_MESSAGE_NEW_PEER_LENGTH]; @@ -1260,7 +1269,7 @@ static int group_new_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t * return 0 on success * return -1 on failure */ -static int group_kill_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num) +static int group_kill_peer_send(const Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_num) { uint8_t packet[GROUP_MESSAGE_KILL_PEER_LENGTH]; @@ -1280,7 +1289,7 @@ static int group_kill_peer_send(const Group_Chats *g_c, int groupnumber, uint16_ * return 0 on success * return -1 on failure */ -static int group_name_send(const Group_Chats *g_c, int groupnumber, const uint8_t *nick, uint16_t nick_len) +static int group_name_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *nick, uint16_t nick_len) { if (nick_len > MAX_NAME_LENGTH) { return -1; @@ -1301,7 +1310,7 @@ static int group_name_send(const Group_Chats *g_c, int groupnumber, const uint8_ * return -2 if title is too long or empty. * return -3 if packet fails to send. */ -int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *title, uint8_t title_len) +int group_title_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *title, uint8_t title_len) { Group_c *g = get_group_c(g_c, groupnumber); @@ -1336,7 +1345,7 @@ int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *tit * return -1 of groupnumber is invalid. * return -2 if title is too long or empty. */ -int group_title_get_size(const Group_Chats *g_c, int groupnumber) +int group_title_get_size(const Group_Chats *g_c, uint32_t groupnumber) { Group_c *g = get_group_c(g_c, groupnumber); @@ -1358,7 +1367,7 @@ int group_title_get_size(const Group_Chats *g_c, int groupnumber) * return -1 if groupnumber is invalid. * return -2 if title is too long or empty. */ -int group_title_get(const Group_Chats *g_c, int groupnumber, uint8_t *title) +int group_title_get(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *title) { Group_c *g = get_group_c(g_c, groupnumber); @@ -1524,6 +1533,11 @@ static int handle_packet_online(Group_Chats *g_c, int friendcon_id, const uint8_ } int groupnumber = get_group_num(g_c, data + sizeof(uint16_t)); + + if (groupnumber == -1) { + return -1; + } + uint16_t other_groupnum; memcpy(&other_groupnum, data, sizeof(uint16_t)); other_groupnum = net_ntohs(other_groupnum); @@ -1600,12 +1614,12 @@ static unsigned int send_peer_query(Group_Chats *g_c, int friendcon_id, uint16_t /* return number of peers sent on success. * return 0 on failure. */ -static unsigned int send_peers(Group_Chats *g_c, int groupnumber, int friendcon_id, uint16_t group_num) +static unsigned int send_peers(Group_Chats *g_c, uint32_t groupnumber, int friendcon_id, uint16_t group_num) { Group_c *g = get_group_c(g_c, groupnumber); if (!g) { - return -1; + return 0; } uint8_t packet[MAX_CRYPTO_DATA_SIZE - (1 + sizeof(uint16_t))]; @@ -1655,7 +1669,8 @@ static unsigned int send_peers(Group_Chats *g_c, int groupnumber, int friendcon_ return sent; } -static int handle_send_peers(Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length, void *userdata) +static int handle_send_peers(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length, + void *userdata) { if (length == 0) { return -1; @@ -1702,7 +1717,7 @@ static int handle_send_peers(Group_Chats *g_c, int groupnumber, const uint8_t *d return 0; } -static void handle_direct_packet(Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length, +static void handle_direct_packet(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length, int close_index, void *userdata) { if (length == 0) { @@ -1758,7 +1773,7 @@ static void handle_direct_packet(Group_Chats *g_c, int groupnumber, const uint8_ * * return number of messages sent. */ -static unsigned int send_message_all_close(const Group_Chats *g_c, int groupnumber, const uint8_t *data, +static unsigned int send_message_all_close(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length, int receiver) { Group_c *g = get_group_c(g_c, groupnumber); @@ -1792,7 +1807,8 @@ static unsigned int send_message_all_close(const Group_Chats *g_c, int groupnumb * * return number of messages sent. */ -static unsigned int send_lossy_all_close(const Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length, +static unsigned int send_lossy_all_close(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, + uint16_t length, int receiver) { Group_c *g = get_group_c(g_c, groupnumber); @@ -1885,7 +1901,7 @@ static unsigned int send_lossy_all_close(const Group_Chats *g_c, int groupnumber * return -3 if we are not connected to the group. * reutrn -4 if message failed to send. */ -static int send_message_group(const Group_Chats *g_c, int groupnumber, uint8_t message_id, const uint8_t *data, +static int send_message_group(const Group_Chats *g_c, uint32_t groupnumber, uint8_t message_id, const uint8_t *data, uint16_t len) { Group_c *g = get_group_c(g_c, groupnumber); @@ -1930,7 +1946,7 @@ static int send_message_group(const Group_Chats *g_c, int groupnumber, uint8_t m * return 0 on success * see: send_message_group() for error codes. */ -int group_message_send(const Group_Chats *g_c, int groupnumber, const uint8_t *message, uint16_t length) +int group_message_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *message, uint16_t length) { int ret = send_message_group(g_c, groupnumber, PACKET_ID_MESSAGE, message, length); @@ -1945,7 +1961,7 @@ int group_message_send(const Group_Chats *g_c, int groupnumber, const uint8_t *m * return 0 on success * see: send_message_group() for error codes. */ -int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *action, uint16_t length) +int group_action_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *action, uint16_t length) { int ret = send_message_group(g_c, groupnumber, PACKET_ID_ACTION, action, length); @@ -1961,7 +1977,7 @@ int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *ac * return -1 on failure. * return 0 on success. */ -int send_group_lossy_packet(const Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length) +int send_group_lossy_packet(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length) { // TODO(irungentoo): length check here? Group_c *g = get_group_c(g_c, groupnumber); @@ -1985,7 +2001,7 @@ int send_group_lossy_packet(const Group_Chats *g_c, int groupnumber, const uint8 return 0; } -static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length, +static void handle_message_packet_group(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length, int close_index, void *userdata) { if (length < sizeof(uint16_t) + sizeof(uint32_t) + 1) { @@ -2186,6 +2202,7 @@ static int g_handle_packet(void *object, int friendcon_id, const uint8_t *data, static unsigned int lossy_packet_not_received(Group_c *g, int peer_index, uint16_t message_number) { if (peer_index == -1) { + // TODO(sudden6): invalid return value return -1; } @@ -2206,6 +2223,7 @@ static unsigned int lossy_packet_not_received(Group_c *g, int peer_index, uint16 } if ((uint16_t)(message_number - g->group[peer_index].bottom_lossy_number) > (1 << 15)) { + // TODO(sudden6): invalid return value return -1; } @@ -2304,7 +2322,7 @@ static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uin * return 0 on success. * return -1 on failure */ -int group_set_object(const Group_Chats *g_c, int groupnumber, void *object) +int group_set_object(const Group_Chats *g_c, uint32_t groupnumber, void *object) { Group_c *g = get_group_c(g_c, groupnumber); @@ -2321,7 +2339,7 @@ int group_set_object(const Group_Chats *g_c, int groupnumber, void *object) * return 0 on success. * return -1 on failure */ -int group_peer_set_object(const Group_Chats *g_c, int groupnumber, int peernumber, void *object) +int group_peer_set_object(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, void *object) { Group_c *g = get_group_c(g_c, groupnumber); @@ -2342,7 +2360,7 @@ int group_peer_set_object(const Group_Chats *g_c, int groupnumber, int peernumbe * return NULL on failure. * return object on success. */ -void *group_get_object(const Group_Chats *g_c, int groupnumber) +void *group_get_object(const Group_Chats *g_c, uint32_t groupnumber) { Group_c *g = get_group_c(g_c, groupnumber); @@ -2358,7 +2376,7 @@ void *group_get_object(const Group_Chats *g_c, int groupnumber) * return NULL on failure. * return object on success. */ -void *group_peer_get_object(const Group_Chats *g_c, int groupnumber, int peernumber) +void *group_peer_get_object(const Group_Chats *g_c, uint32_t groupnumber, int peernumber) { Group_c *g = get_group_c(g_c, groupnumber); @@ -2376,7 +2394,7 @@ void *group_peer_get_object(const Group_Chats *g_c, int groupnumber, int peernum /* Interval in seconds to send ping messages */ #define GROUP_PING_INTERVAL 20 -static int ping_groupchat(Group_Chats *g_c, int groupnumber) +static int ping_groupchat(Group_Chats *g_c, uint32_t groupnumber) { Group_c *g = get_group_c(g_c, groupnumber); @@ -2393,7 +2411,7 @@ static int ping_groupchat(Group_Chats *g_c, int groupnumber) return 0; } -static int groupchat_clear_timedout(Group_Chats *g_c, int groupnumber, void *userdata) +static int groupchat_clear_timedout(Group_Chats *g_c, uint32_t groupnumber, void *userdata) { Group_c *g = get_group_c(g_c, groupnumber); diff --git a/toxcore/group.h b/toxcore/group.h index af37f21e..4324613c 100644 --- a/toxcore/group.h +++ b/toxcore/group.h @@ -103,9 +103,9 @@ typedef struct { void *object; - void (*peer_on_join)(void *, int, int); - void (*peer_on_leave)(void *, int, int, void *); - void (*group_on_delete)(void *, int); + void (*peer_on_join)(void *, uint32_t, uint32_t); + void (*peer_on_leave)(void *, uint32_t, uint32_t, void *); + void (*group_on_delete)(void *, uint32_t); } Group_c; typedef struct { @@ -117,17 +117,17 @@ typedef struct { void (*invite_callback)(Messenger *m, uint32_t, int, const uint8_t *, size_t, void *); void (*message_callback)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, size_t, void *); - void (*group_namelistchange)(Messenger *m, int, int, uint8_t, void *); + void (*group_namelistchange)(Messenger *m, uint32_t, uint32_t, uint8_t, void *); void (*title_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *); struct { - int (*function)(void *, int, int, void *, const uint8_t *, uint16_t); + int (*function)(void *, uint32_t, uint32_t, void *, const uint8_t *, uint16_t); } lossy_packethandlers[256]; } Group_Chats; /* Set the callback for group invites. * - * Function(Group_Chats *g_c, int32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata) + * Function(Group_Chats *g_c, uint32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata) * * data of length is what needs to be passed to join_groupchat(). */ @@ -136,7 +136,7 @@ void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, ui /* Set the callback for group messages. * - * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) + * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) */ void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, size_t, void *)); @@ -144,7 +144,7 @@ void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, u /* Set callback function for title changes. * - * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) + * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group) */ void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *, @@ -159,7 +159,8 @@ enum { CHAT_CHANGE_OCCURRED, CHAT_CHANGE_PEER_NAME, }; -void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *m, int, int, uint8_t, void *)); +void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, uint8_t, + void *)); /* Creates a new groupchat and puts it in the chats array. * @@ -175,7 +176,7 @@ int add_groupchat(Group_Chats *g_c, uint8_t type); * return 0 on success. * return -1 if groupnumber is invalid. */ -int del_groupchat(Group_Chats *g_c, int groupnumber); +int del_groupchat(Group_Chats *g_c, uint32_t groupnumber); /* Copy the public key of peernumber who is in groupnumber to pk. * pk must be CRYPTO_PUBLIC_KEY_SIZE long. @@ -184,7 +185,7 @@ int del_groupchat(Group_Chats *g_c, int groupnumber); * return -1 if groupnumber is invalid. * return -2 if peernumber is invalid. */ -int group_peer_pubkey(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *pk); +int group_peer_pubkey(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, uint8_t *pk); /* * Return the size of peernumber's name. @@ -192,7 +193,7 @@ int group_peer_pubkey(const Group_Chats *g_c, int groupnumber, int peernumber, u * return -1 if groupnumber is invalid. * return -2 if peernumber is invalid. */ -int group_peername_size(const Group_Chats *g_c, int groupnumber, int peernumber); +int group_peername_size(const Group_Chats *g_c, uint32_t groupnumber, int32_t peernumber); /* Copy the name of peernumber who is in groupnumber to name. * name must be at least MAX_NAME_LENGTH long. @@ -201,7 +202,7 @@ int group_peername_size(const Group_Chats *g_c, int groupnumber, int peernumber) * return -1 if groupnumber is invalid. * return -2 if peernumber is invalid. */ -int group_peername(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *name); +int group_peername(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, uint8_t *name); /* invite friendnumber to groupnumber * @@ -209,7 +210,7 @@ int group_peername(const Group_Chats *g_c, int groupnumber, int peernumber, uint * return -1 if groupnumber is invalid. * return -2 if invite packet failed to send. */ -int invite_friend(Group_Chats *g_c, int32_t friendnumber, int groupnumber); +int invite_friend(Group_Chats *g_c, uint32_t friendnumber, uint32_t groupnumber); /* Join a group (you need to have been invited first.) * @@ -223,19 +224,20 @@ int invite_friend(Group_Chats *g_c, int32_t friendnumber, int groupnumber); * return -5 if group instance failed to initialize. * return -6 if join packet fails to send. */ -int join_groupchat(Group_Chats *g_c, int32_t friendnumber, uint8_t expected_type, const uint8_t *data, uint16_t length); +int join_groupchat(Group_Chats *g_c, uint32_t friendnumber, uint8_t expected_type, const uint8_t *data, + uint16_t length); /* send a group message * return 0 on success * see: send_message_group() for error codes. */ -int group_message_send(const Group_Chats *g_c, int groupnumber, const uint8_t *message, uint16_t length); +int group_message_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *message, uint16_t length); /* send a group action * return 0 on success * see: send_message_group() for error codes. */ -int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *action, uint16_t length); +int group_action_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *action, uint16_t length); /* set the group's title, limited to MAX_NAME_LENGTH * return 0 on success @@ -243,14 +245,14 @@ int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *ac * return -2 if title is too long or empty. * return -3 if packet fails to send. */ -int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *title, uint8_t title_len); +int group_title_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *title, uint8_t title_len); /* return the group's title size. * return -1 of groupnumber is invalid. * return -2 if title is too long or empty. */ -int group_title_get_size(const Group_Chats *g_c, int groupnumber); +int group_title_get_size(const Group_Chats *g_c, uint32_t groupnumber); /* Get group title from groupnumber and put it in title. * Title needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. @@ -259,12 +261,12 @@ int group_title_get_size(const Group_Chats *g_c, int groupnumber); * return -1 if groupnumber is invalid. * return -2 if title is too long or empty. */ -int group_title_get(const Group_Chats *g_c, int groupnumber, uint8_t *title); +int group_title_get(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *title); /* Return the number of peers in the group chat on success. * return -1 if groupnumber is invalid. */ -int group_number_peers(const Group_Chats *g_c, int groupnumber); +int group_number_peers(const Group_Chats *g_c, uint32_t groupnumber); /* return 1 if the peernumber corresponds to ours. * return 0 if the peernumber is not ours. @@ -272,7 +274,7 @@ int group_number_peers(const Group_Chats *g_c, int groupnumber); * return -2 if peernumber is invalid. * return -3 if we are not connected to the group chat. */ -int group_peernumber_is_ours(const Group_Chats *g_c, int groupnumber, int peernumber); +int group_peernumber_is_ours(const Group_Chats *g_c, uint32_t groupnumber, int peernumber); /* List all the peers in the group chat. * @@ -284,16 +286,17 @@ int group_peernumber_is_ours(const Group_Chats *g_c, int groupnumber, int peernu * * return -1 on failure. */ -int group_names(const Group_Chats *g_c, int groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[], +int group_names(const Group_Chats *g_c, uint32_t groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[], uint16_t length); /* Set handlers for custom lossy packets. * * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed. * - * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object), const uint8_t *packet, uint16_t length) + * Function(void *group object (set with group_set_object), uint32_t groupnumber, uint32_t friendgroupnumber, void *group peer object (set with group_peer_set_object), const uint8_t *packet, uint16_t length) */ -void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, int, int, void *, +void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, uint32_t, uint32_t, + void *, const uint8_t *, uint16_t)); /* High level function to send custom lossy packets. @@ -301,7 +304,7 @@ void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*fu * return -1 on failure. * return 0 on success. */ -int send_group_lossy_packet(const Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length); +int send_group_lossy_packet(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length); /* Return the number of chats in the instance m. * You should use this to determine how much memory to allocate @@ -321,7 +324,7 @@ uint32_t copy_chatlist(Group_Chats *g_c, uint32_t *out_list, uint32_t list_size) * return -1 on failure. * return type on success. */ -int group_get_type(const Group_Chats *g_c, int groupnumber); +int group_get_type(const Group_Chats *g_c, uint32_t groupnumber); /* Send current name (set in messenger) to all online groups. */ @@ -332,28 +335,28 @@ void send_name_all_groups(Group_Chats *g_c); * return 0 on success. * return -1 on failure */ -int group_set_object(const Group_Chats *g_c, int groupnumber, void *object); +int group_set_object(const Group_Chats *g_c, uint32_t groupnumber, void *object); /* Set the object that is tied to the group peer. * * return 0 on success. * return -1 on failure */ -int group_peer_set_object(const Group_Chats *g_c, int groupnumber, int peernumber, void *object); +int group_peer_set_object(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, void *object); /* Return the object tide to the group chat previously set by group_set_object. * * return NULL on failure. * return object on success. */ -void *group_get_object(const Group_Chats *g_c, int groupnumber); +void *group_get_object(const Group_Chats *g_c, uint32_t groupnumber); /* Return the object tide to the group chat peer previously set by group_peer_set_object. * * return NULL on failure. * return object on success. */ -void *group_peer_get_object(const Group_Chats *g_c, int groupnumber, int peernumber); +void *group_peer_get_object(const Group_Chats *g_c, uint32_t groupnumber, int peernumber); /* Set a function to be called when a new peer joins a group chat. * @@ -362,25 +365,27 @@ void *group_peer_get_object(const Group_Chats *g_c, int groupnumber, int peernum * return 0 on success. * return -1 on failure. */ -int callback_groupchat_peer_new(const Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int)); +int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, + uint32_t)); /* Set a function to be called when a peer leaves a group chat. * - * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object)) + * Function(void *group object (set with group_set_object), uint32_t groupnumber, uint32_t friendgroupnumber, void *group peer object (set with group_peer_set_object)) * * return 0 on success. * return -1 on failure. */ -int callback_groupchat_peer_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int, void *)); +int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, uint32_t, + void *)); /* Set a function to be called when the group chat is deleted. * - * Function(void *group object (set with group_set_object), int groupnumber) + * Function(void *group object (set with group_set_object), uint32_t groupnumber) * * return 0 on success. * return -1 on failure. */ -int callback_groupchat_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int)); +int callback_groupchat_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t)); /* Create new groupchat instance. */ Group_Chats *new_groupchats(Messenger *m); diff --git a/toxcore/tox.c b/toxcore/tox.c index c3bcb652..6ca52604 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -1106,7 +1106,8 @@ void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback) void tox_callback_conference_namelist_change(Tox *tox, tox_conference_namelist_change_cb *callback) { Messenger *m = tox; - g_callback_group_namelistchange((Group_Chats *)m->conferences_object, (void (*)(struct Messenger *, int, int, uint8_t, + g_callback_group_namelistchange((Group_Chats *)m->conferences_object, (void (*)(struct Messenger *, uint32_t, uint32_t, + uint8_t, void *))callback); }