diff options
author | sudden6 <sudden6@gmx.at> | 2018-02-19 22:58:03 +0100 |
---|---|---|
committer | sudden6 <sudden6@gmx.at> | 2018-02-20 20:58:54 +0100 |
commit | 03b55cde1a98b02f9019f068340094b5062857d1 (patch) | |
tree | 3fd16d56a9546e458d03a47d9e8e8fa68e0f9c16 /toxcore/group.c | |
parent | c4a734e30462d59d7f9bfe4a865b33936907e0d5 (diff) |
make groupnumber uint32_t
fixes #606
Diffstat (limited to 'toxcore/group.c')
-rw-r--r-- | toxcore/group.c | 138 |
1 files changed, 78 insertions, 60 deletions
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 @@ | |||
32 | /* return 1 if the groupnumber is not valid. | 32 | /* return 1 if the groupnumber is not valid. |
33 | * return 0 if the groupnumber is valid. | 33 | * return 0 if the groupnumber is valid. |
34 | */ | 34 | */ |
35 | static uint8_t groupnumber_not_valid(const Group_Chats *g_c, int groupnumber) | 35 | static uint8_t groupnumber_not_valid(const Group_Chats *g_c, uint32_t groupnumber) |
36 | { | 36 | { |
37 | if ((unsigned int)groupnumber >= g_c->num_chats) { | 37 | if (groupnumber >= g_c->num_chats) { |
38 | return 1; | 38 | return 1; |
39 | } | 39 | } |
40 | 40 | ||
@@ -106,7 +106,7 @@ static int create_group_chat(Group_Chats *g_c) | |||
106 | * return -1 on failure. | 106 | * return -1 on failure. |
107 | * return 0 on success. | 107 | * return 0 on success. |
108 | */ | 108 | */ |
109 | static int wipe_group_chat(Group_Chats *g_c, int groupnumber) | 109 | static int wipe_group_chat(Group_Chats *g_c, uint32_t groupnumber) |
110 | { | 110 | { |
111 | if (groupnumber_not_valid(g_c, groupnumber)) { | 111 | if (groupnumber_not_valid(g_c, groupnumber)) { |
112 | return -1; | 112 | return -1; |
@@ -129,7 +129,7 @@ static int wipe_group_chat(Group_Chats *g_c, int groupnumber) | |||
129 | return 0; | 129 | return 0; |
130 | } | 130 | } |
131 | 131 | ||
132 | static Group_c *get_group_c(const Group_Chats *g_c, int groupnumber) | 132 | static Group_c *get_group_c(const Group_Chats *g_c, uint32_t groupnumber) |
133 | { | 133 | { |
134 | if (groupnumber_not_valid(g_c, groupnumber)) { | 134 | if (groupnumber_not_valid(g_c, groupnumber)) { |
135 | return nullptr; | 135 | return nullptr; |
@@ -224,9 +224,10 @@ enum { | |||
224 | }; | 224 | }; |
225 | 225 | ||
226 | static int friend_in_close(Group_c *g, int friendcon_id); | 226 | static int friend_in_close(Group_c *g, int friendcon_id); |
227 | static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, int groupnumber, uint8_t closest, uint8_t lock); | 227 | static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, uint32_t groupnumber, uint8_t closest, |
228 | uint8_t lock); | ||
228 | 229 | ||
229 | static int add_to_closest(Group_Chats *g_c, int groupnumber, const uint8_t *real_pk, const uint8_t *temp_pk) | 230 | static int add_to_closest(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *real_pk, const uint8_t *temp_pk) |
230 | { | 231 | { |
231 | Group_c *g = get_group_c(g_c, groupnumber); | 232 | Group_c *g = get_group_c(g_c, groupnumber); |
232 | 233 | ||
@@ -328,7 +329,7 @@ static unsigned int pk_in_closest_peers(Group_c *g, uint8_t *real_pk) | |||
328 | 329 | ||
329 | static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16_t group_num, uint8_t *identifier); | 330 | static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16_t group_num, uint8_t *identifier); |
330 | 331 | ||
331 | static int connect_to_closest(Group_Chats *g_c, int groupnumber, void *userdata) | 332 | static int connect_to_closest(Group_Chats *g_c, uint32_t groupnumber, void *userdata) |
332 | { | 333 | { |
333 | Group_c *g = get_group_c(g_c, groupnumber); | 334 | Group_c *g = get_group_c(g_c, groupnumber); |
334 | 335 | ||
@@ -408,7 +409,7 @@ static int connect_to_closest(Group_Chats *g_c, int groupnumber, void *userdata) | |||
408 | * return peer_index if success or peer already in chat. | 409 | * return peer_index if success or peer already in chat. |
409 | * return -1 if error. | 410 | * return -1 if error. |
410 | */ | 411 | */ |
411 | static int addpeer(Group_Chats *g_c, int groupnumber, const uint8_t *real_pk, const uint8_t *temp_pk, | 412 | static int addpeer(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *real_pk, const uint8_t *temp_pk, |
412 | uint16_t peer_number, void *userdata, bool do_gc_callback) | 413 | uint16_t peer_number, void *userdata, bool do_gc_callback) |
413 | { | 414 | { |
414 | Group_c *g = get_group_c(g_c, groupnumber); | 415 | 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 | |||
465 | return (g->numpeers - 1); | 466 | return (g->numpeers - 1); |
466 | } | 467 | } |
467 | 468 | ||
468 | static int remove_close_conn(Group_Chats *g_c, int groupnumber, int friendcon_id) | 469 | static int remove_close_conn(Group_Chats *g_c, uint32_t groupnumber, int friendcon_id) |
469 | { | 470 | { |
470 | Group_c *g = get_group_c(g_c, groupnumber); | 471 | Group_c *g = get_group_c(g_c, groupnumber); |
471 | 472 | ||
@@ -497,7 +498,7 @@ static int remove_close_conn(Group_Chats *g_c, int groupnumber, int friendcon_id | |||
497 | * return 0 if success | 498 | * return 0 if success |
498 | * return -1 if error. | 499 | * return -1 if error. |
499 | */ | 500 | */ |
500 | static int delpeer(Group_Chats *g_c, int groupnumber, int peer_index, void *userdata) | 501 | static int delpeer(Group_Chats *g_c, uint32_t groupnumber, int peer_index, void *userdata) |
501 | { | 502 | { |
502 | Group_c *g = get_group_c(g_c, groupnumber); | 503 | Group_c *g = get_group_c(g_c, groupnumber); |
503 | 504 | ||
@@ -562,7 +563,7 @@ static int delpeer(Group_Chats *g_c, int groupnumber, int peer_index, void *user | |||
562 | * return 0 on success. | 563 | * return 0 on success. |
563 | * return -1 if error. | 564 | * return -1 if error. |
564 | */ | 565 | */ |
565 | static int setnick(Group_Chats *g_c, int groupnumber, int peer_index, const uint8_t *nick, uint16_t nick_len, | 566 | static int setnick(Group_Chats *g_c, uint32_t groupnumber, int peer_index, const uint8_t *nick, uint16_t nick_len, |
566 | void *userdata, bool do_gc_callback) | 567 | void *userdata, bool do_gc_callback) |
567 | { | 568 | { |
568 | if (nick_len > MAX_NAME_LENGTH) { | 569 | if (nick_len > MAX_NAME_LENGTH) { |
@@ -595,7 +596,7 @@ static int setnick(Group_Chats *g_c, int groupnumber, int peer_index, const uint | |||
595 | return 0; | 596 | return 0; |
596 | } | 597 | } |
597 | 598 | ||
598 | static int settitle(Group_Chats *g_c, int groupnumber, int peer_index, const uint8_t *title, uint8_t title_len, | 599 | static int settitle(Group_Chats *g_c, uint32_t groupnumber, int peer_index, const uint8_t *title, uint8_t title_len, |
599 | void *userdata) | 600 | void *userdata) |
600 | { | 601 | { |
601 | if (title_len > MAX_NAME_LENGTH || title_len == 0) { | 602 | 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 | |||
623 | return 0; | 624 | return 0; |
624 | } | 625 | } |
625 | 626 | ||
626 | static void set_conns_type_close(Group_Chats *g_c, int groupnumber, int friendcon_id, uint8_t type) | 627 | static void set_conns_type_close(Group_Chats *g_c, uint32_t groupnumber, int friendcon_id, uint8_t type) |
627 | { | 628 | { |
628 | Group_c *g = get_group_c(g_c, groupnumber); | 629 | Group_c *g = get_group_c(g_c, groupnumber); |
629 | 630 | ||
@@ -681,7 +682,8 @@ static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uin | |||
681 | * return close index on success | 682 | * return close index on success |
682 | * return -1 on failure. | 683 | * return -1 on failure. |
683 | */ | 684 | */ |
684 | static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, int groupnumber, uint8_t closest, uint8_t lock) | 685 | static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, uint32_t groupnumber, uint8_t closest, |
686 | uint8_t lock) | ||
685 | { | 687 | { |
686 | Group_c *g = get_group_c(g_c, groupnumber); | 688 | Group_c *g = get_group_c(g_c, groupnumber); |
687 | 689 | ||
@@ -755,13 +757,13 @@ int add_groupchat(Group_Chats *g_c, uint8_t type) | |||
755 | return groupnumber; | 757 | return groupnumber; |
756 | } | 758 | } |
757 | 759 | ||
758 | static int group_kill_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num); | 760 | static int group_kill_peer_send(const Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_num); |
759 | /* Delete a groupchat from the chats array. | 761 | /* Delete a groupchat from the chats array. |
760 | * | 762 | * |
761 | * return 0 on success. | 763 | * return 0 on success. |
762 | * return -1 if groupnumber is invalid. | 764 | * return -1 if groupnumber is invalid. |
763 | */ | 765 | */ |
764 | int del_groupchat(Group_Chats *g_c, int groupnumber) | 766 | int del_groupchat(Group_Chats *g_c, uint32_t groupnumber) |
765 | { | 767 | { |
766 | Group_c *g = get_group_c(g_c, groupnumber); | 768 | Group_c *g = get_group_c(g_c, groupnumber); |
767 | 769 | ||
@@ -804,7 +806,7 @@ int del_groupchat(Group_Chats *g_c, int groupnumber) | |||
804 | * return -1 if groupnumber is invalid. | 806 | * return -1 if groupnumber is invalid. |
805 | * return -2 if peernumber is invalid. | 807 | * return -2 if peernumber is invalid. |
806 | */ | 808 | */ |
807 | int group_peer_pubkey(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *pk) | 809 | int group_peer_pubkey(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, uint8_t *pk) |
808 | { | 810 | { |
809 | Group_c *g = get_group_c(g_c, groupnumber); | 811 | Group_c *g = get_group_c(g_c, groupnumber); |
810 | 812 | ||
@@ -826,7 +828,7 @@ int group_peer_pubkey(const Group_Chats *g_c, int groupnumber, int peernumber, u | |||
826 | * return -1 if groupnumber is invalid. | 828 | * return -1 if groupnumber is invalid. |
827 | * return -2 if peernumber is invalid. | 829 | * return -2 if peernumber is invalid. |
828 | */ | 830 | */ |
829 | int group_peername_size(const Group_Chats *g_c, int groupnumber, int peernumber) | 831 | int group_peername_size(const Group_Chats *g_c, uint32_t groupnumber, int peernumber) |
830 | { | 832 | { |
831 | Group_c *g = get_group_c(g_c, groupnumber); | 833 | Group_c *g = get_group_c(g_c, groupnumber); |
832 | 834 | ||
@@ -852,7 +854,7 @@ int group_peername_size(const Group_Chats *g_c, int groupnumber, int peernumber) | |||
852 | * return -1 if groupnumber is invalid. | 854 | * return -1 if groupnumber is invalid. |
853 | * return -2 if peernumber is invalid. | 855 | * return -2 if peernumber is invalid. |
854 | */ | 856 | */ |
855 | int group_peername(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *name) | 857 | int group_peername(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, uint8_t *name) |
856 | { | 858 | { |
857 | Group_c *g = get_group_c(g_c, groupnumber); | 859 | Group_c *g = get_group_c(g_c, groupnumber); |
858 | 860 | ||
@@ -883,7 +885,7 @@ int group_peername(const Group_Chats *g_c, int groupnumber, int peernumber, uint | |||
883 | * | 885 | * |
884 | * return -1 on failure. | 886 | * return -1 on failure. |
885 | */ | 887 | */ |
886 | int group_names(const Group_Chats *g_c, int groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[], | 888 | int group_names(const Group_Chats *g_c, uint32_t groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[], |
887 | uint16_t length) | 889 | uint16_t length) |
888 | { | 890 | { |
889 | Group_c *g = get_group_c(g_c, groupnumber); | 891 | 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 | |||
904 | /* Return the number of peers in the group chat on success. | 906 | /* Return the number of peers in the group chat on success. |
905 | * return -1 if groupnumber is invalid. | 907 | * return -1 if groupnumber is invalid. |
906 | */ | 908 | */ |
907 | int group_number_peers(const Group_Chats *g_c, int groupnumber) | 909 | int group_number_peers(const Group_Chats *g_c, uint32_t groupnumber) |
908 | { | 910 | { |
909 | Group_c *g = get_group_c(g_c, groupnumber); | 911 | Group_c *g = get_group_c(g_c, groupnumber); |
910 | 912 | ||
@@ -921,7 +923,7 @@ int group_number_peers(const Group_Chats *g_c, int groupnumber) | |||
921 | * return -2 if peernumber is invalid. | 923 | * return -2 if peernumber is invalid. |
922 | * return -3 if we are not connected to the group chat. | 924 | * return -3 if we are not connected to the group chat. |
923 | */ | 925 | */ |
924 | int group_peernumber_is_ours(const Group_Chats *g_c, int groupnumber, int peernumber) | 926 | int group_peernumber_is_ours(const Group_Chats *g_c, uint32_t groupnumber, int peernumber) |
925 | { | 927 | { |
926 | Group_c *g = get_group_c(g_c, groupnumber); | 928 | Group_c *g = get_group_c(g_c, groupnumber); |
927 | 929 | ||
@@ -945,7 +947,7 @@ int group_peernumber_is_ours(const Group_Chats *g_c, int groupnumber, int peernu | |||
945 | * return -1 on failure. | 947 | * return -1 on failure. |
946 | * return type on success. | 948 | * return type on success. |
947 | */ | 949 | */ |
948 | int group_get_type(const Group_Chats *g_c, int groupnumber) | 950 | int group_get_type(const Group_Chats *g_c, uint32_t groupnumber) |
949 | { | 951 | { |
950 | Group_c *g = get_group_c(g_c, groupnumber); | 952 | Group_c *g = get_group_c(g_c, groupnumber); |
951 | 953 | ||
@@ -1010,7 +1012,7 @@ static unsigned int send_lossy_group_peer(Friend_Connections *fr_c, int friendco | |||
1010 | * return -1 if groupnumber is invalid. | 1012 | * return -1 if groupnumber is invalid. |
1011 | * return -2 if invite packet failed to send. | 1013 | * return -2 if invite packet failed to send. |
1012 | */ | 1014 | */ |
1013 | int invite_friend(Group_Chats *g_c, int32_t friendnumber, int groupnumber) | 1015 | int invite_friend(Group_Chats *g_c, uint32_t friendnumber, uint32_t groupnumber) |
1014 | { | 1016 | { |
1015 | Group_c *g = get_group_c(g_c, groupnumber); | 1017 | Group_c *g = get_group_c(g_c, groupnumber); |
1016 | 1018 | ||
@@ -1046,7 +1048,7 @@ static unsigned int send_peer_query(Group_Chats *g_c, int friendcon_id, uint16_t | |||
1046 | * return -5 if group instance failed to initialize. | 1048 | * return -5 if group instance failed to initialize. |
1047 | * return -6 if join packet fails to send. | 1049 | * return -6 if join packet fails to send. |
1048 | */ | 1050 | */ |
1049 | int join_groupchat(Group_Chats *g_c, int32_t friendnumber, uint8_t expected_type, const uint8_t *data, uint16_t length) | 1051 | int join_groupchat(Group_Chats *g_c, uint32_t friendnumber, uint8_t expected_type, const uint8_t *data, uint16_t length) |
1050 | { | 1052 | { |
1051 | if (length != sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH) { | 1053 | if (length != sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH) { |
1052 | return -1; | 1054 | return -1; |
@@ -1109,9 +1111,10 @@ int join_groupchat(Group_Chats *g_c, int32_t friendnumber, uint8_t expected_type | |||
1109 | * | 1111 | * |
1110 | * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed. | 1112 | * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed. |
1111 | * | 1113 | * |
1112 | * 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) | 1114 | * 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) |
1113 | */ | 1115 | */ |
1114 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, int, int, void *, | 1116 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, uint32_t, uint32_t, |
1117 | void *, | ||
1115 | const uint8_t *, uint16_t)) | 1118 | const uint8_t *, uint16_t)) |
1116 | { | 1119 | { |
1117 | g_c->lossy_packethandlers[byte].function = function; | 1120 | 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 | |||
1119 | 1122 | ||
1120 | /* Set the callback for group invites. | 1123 | /* Set the callback for group invites. |
1121 | * | 1124 | * |
1122 | * Function(Group_Chats *g_c, int32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata) | 1125 | * Function(Group_Chats *g_c, int32_t friendnumber, uint8_t type, uint8_t *data, size_t length, void *userdata) |
1123 | * | 1126 | * |
1124 | * data of length is what needs to be passed to join_groupchat(). | 1127 | * data of length is what needs to be passed to join_groupchat(). |
1125 | */ | 1128 | */ |
@@ -1129,9 +1132,10 @@ void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, ui | |||
1129 | g_c->invite_callback = function; | 1132 | g_c->invite_callback = function; |
1130 | } | 1133 | } |
1131 | 1134 | ||
1135 | // TODO(sudden6): function signatures in comments are incorrect | ||
1132 | /* Set the callback for group messages. | 1136 | /* Set the callback for group messages. |
1133 | * | 1137 | * |
1134 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) | 1138 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * message, size_t length, void *userdata) |
1135 | */ | 1139 | */ |
1136 | void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, | 1140 | void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, |
1137 | size_t, void *)) | 1141 | size_t, void *)) |
@@ -1139,16 +1143,19 @@ void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, u | |||
1139 | g_c->message_callback = function; | 1143 | g_c->message_callback = function; |
1140 | } | 1144 | } |
1141 | 1145 | ||
1146 | // TODO(sudden6): function signatures in comments are incorrect | ||
1142 | /* Set callback function for peer name list changes. | 1147 | /* Set callback function for peer name list changes. |
1143 | * | 1148 | * |
1144 | * It gets called every time the name list changes(new peer/name, deleted peer) | 1149 | * It gets called every time the name list changes(new peer/name, deleted peer) |
1145 | * Function(Group_Chats *g_c, int groupnumber, int peernumber, TOX_CHAT_CHANGE change, void *userdata) | 1150 | * Function(Group_Chats *g_c, int groupnumber, int peernumber, TOX_CHAT_CHANGE change, void *userdata) |
1146 | */ | 1151 | */ |
1147 | void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *m, int, int, uint8_t, void *)) | 1152 | void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *, uint32_t, uint32_t, uint8_t, |
1153 | void *)) | ||
1148 | { | 1154 | { |
1149 | g_c->group_namelistchange = function; | 1155 | g_c->group_namelistchange = function; |
1150 | } | 1156 | } |
1151 | 1157 | ||
1158 | // TODO(sudden6): function signatures are incorrect | ||
1152 | /* Set callback function for title changes. | 1159 | /* Set callback function for title changes. |
1153 | * | 1160 | * |
1154 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) | 1161 | * 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 | |||
1162 | 1169 | ||
1163 | /* Set a function to be called when a new peer joins a group chat. | 1170 | /* Set a function to be called when a new peer joins a group chat. |
1164 | * | 1171 | * |
1165 | * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber) | 1172 | * Function(void *group object (set with group_set_object), uint32_t groupnumber, uint32_t friendgroupnumber) |
1166 | * | 1173 | * |
1167 | * return 0 on success. | 1174 | * return 0 on success. |
1168 | * return -1 on failure. | 1175 | * return -1 on failure. |
1169 | */ | 1176 | */ |
1170 | int callback_groupchat_peer_new(const Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int)) | 1177 | int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, |
1178 | uint32_t)) | ||
1171 | { | 1179 | { |
1172 | Group_c *g = get_group_c(g_c, groupnumber); | 1180 | Group_c *g = get_group_c(g_c, groupnumber); |
1173 | 1181 | ||
@@ -1181,12 +1189,13 @@ int callback_groupchat_peer_new(const Group_Chats *g_c, int groupnumber, void (* | |||
1181 | 1189 | ||
1182 | /* Set a function to be called when a peer leaves a group chat. | 1190 | /* Set a function to be called when a peer leaves a group chat. |
1183 | * | 1191 | * |
1184 | * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object)) | 1192 | * 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)) |
1185 | * | 1193 | * |
1186 | * return 0 on success. | 1194 | * return 0 on success. |
1187 | * return -1 on failure. | 1195 | * return -1 on failure. |
1188 | */ | 1196 | */ |
1189 | int callback_groupchat_peer_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int, void *)) | 1197 | int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, uint32_t, |
1198 | void *)) | ||
1190 | { | 1199 | { |
1191 | Group_c *g = get_group_c(g_c, groupnumber); | 1200 | Group_c *g = get_group_c(g_c, groupnumber); |
1192 | 1201 | ||
@@ -1205,7 +1214,7 @@ int callback_groupchat_peer_delete(Group_Chats *g_c, int groupnumber, void (*fun | |||
1205 | * return 0 on success. | 1214 | * return 0 on success. |
1206 | * return -1 on failure. | 1215 | * return -1 on failure. |
1207 | */ | 1216 | */ |
1208 | int callback_groupchat_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int)) | 1217 | int callback_groupchat_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t)) |
1209 | { | 1218 | { |
1210 | Group_c *g = get_group_c(g_c, groupnumber); | 1219 | Group_c *g = get_group_c(g_c, groupnumber); |
1211 | 1220 | ||
@@ -1217,11 +1226,11 @@ int callback_groupchat_delete(Group_Chats *g_c, int groupnumber, void (*function | |||
1217 | return 0; | 1226 | return 0; |
1218 | } | 1227 | } |
1219 | 1228 | ||
1220 | static int send_message_group(const Group_Chats *g_c, int groupnumber, uint8_t message_id, const uint8_t *data, | 1229 | static int send_message_group(const Group_Chats *g_c, uint32_t groupnumber, uint8_t message_id, const uint8_t *data, |
1221 | uint16_t len); | 1230 | uint16_t len); |
1222 | 1231 | ||
1223 | #define GROUP_MESSAGE_PING_ID 0 | 1232 | #define GROUP_MESSAGE_PING_ID 0 |
1224 | static int group_ping_send(const Group_Chats *g_c, int groupnumber) | 1233 | static int group_ping_send(const Group_Chats *g_c, uint32_t groupnumber) |
1225 | { | 1234 | { |
1226 | if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_PING_ID, nullptr, 0) > 0) { | 1235 | if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_PING_ID, nullptr, 0) > 0) { |
1227 | return 0; | 1236 | return 0; |
@@ -1236,7 +1245,7 @@ static int group_ping_send(const Group_Chats *g_c, int groupnumber) | |||
1236 | * return 0 on success | 1245 | * return 0 on success |
1237 | * return -1 on failure | 1246 | * return -1 on failure |
1238 | */ | 1247 | */ |
1239 | static int group_new_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num, const uint8_t *real_pk, | 1248 | static int group_new_peer_send(const Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_num, const uint8_t *real_pk, |
1240 | uint8_t *temp_pk) | 1249 | uint8_t *temp_pk) |
1241 | { | 1250 | { |
1242 | uint8_t packet[GROUP_MESSAGE_NEW_PEER_LENGTH]; | 1251 | 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 | |||
1260 | * return 0 on success | 1269 | * return 0 on success |
1261 | * return -1 on failure | 1270 | * return -1 on failure |
1262 | */ | 1271 | */ |
1263 | static int group_kill_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num) | 1272 | static int group_kill_peer_send(const Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_num) |
1264 | { | 1273 | { |
1265 | uint8_t packet[GROUP_MESSAGE_KILL_PEER_LENGTH]; | 1274 | uint8_t packet[GROUP_MESSAGE_KILL_PEER_LENGTH]; |
1266 | 1275 | ||
@@ -1280,7 +1289,7 @@ static int group_kill_peer_send(const Group_Chats *g_c, int groupnumber, uint16_ | |||
1280 | * return 0 on success | 1289 | * return 0 on success |
1281 | * return -1 on failure | 1290 | * return -1 on failure |
1282 | */ | 1291 | */ |
1283 | static int group_name_send(const Group_Chats *g_c, int groupnumber, const uint8_t *nick, uint16_t nick_len) | 1292 | static int group_name_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *nick, uint16_t nick_len) |
1284 | { | 1293 | { |
1285 | if (nick_len > MAX_NAME_LENGTH) { | 1294 | if (nick_len > MAX_NAME_LENGTH) { |
1286 | return -1; | 1295 | return -1; |
@@ -1301,7 +1310,7 @@ static int group_name_send(const Group_Chats *g_c, int groupnumber, const uint8_ | |||
1301 | * return -2 if title is too long or empty. | 1310 | * return -2 if title is too long or empty. |
1302 | * return -3 if packet fails to send. | 1311 | * return -3 if packet fails to send. |
1303 | */ | 1312 | */ |
1304 | int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *title, uint8_t title_len) | 1313 | int group_title_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *title, uint8_t title_len) |
1305 | { | 1314 | { |
1306 | Group_c *g = get_group_c(g_c, groupnumber); | 1315 | Group_c *g = get_group_c(g_c, groupnumber); |
1307 | 1316 | ||
@@ -1336,7 +1345,7 @@ int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *tit | |||
1336 | * return -1 of groupnumber is invalid. | 1345 | * return -1 of groupnumber is invalid. |
1337 | * return -2 if title is too long or empty. | 1346 | * return -2 if title is too long or empty. |
1338 | */ | 1347 | */ |
1339 | int group_title_get_size(const Group_Chats *g_c, int groupnumber) | 1348 | int group_title_get_size(const Group_Chats *g_c, uint32_t groupnumber) |
1340 | { | 1349 | { |
1341 | Group_c *g = get_group_c(g_c, groupnumber); | 1350 | Group_c *g = get_group_c(g_c, groupnumber); |
1342 | 1351 | ||
@@ -1358,7 +1367,7 @@ int group_title_get_size(const Group_Chats *g_c, int groupnumber) | |||
1358 | * return -1 if groupnumber is invalid. | 1367 | * return -1 if groupnumber is invalid. |
1359 | * return -2 if title is too long or empty. | 1368 | * return -2 if title is too long or empty. |
1360 | */ | 1369 | */ |
1361 | int group_title_get(const Group_Chats *g_c, int groupnumber, uint8_t *title) | 1370 | int group_title_get(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *title) |
1362 | { | 1371 | { |
1363 | Group_c *g = get_group_c(g_c, groupnumber); | 1372 | Group_c *g = get_group_c(g_c, groupnumber); |
1364 | 1373 | ||
@@ -1524,6 +1533,11 @@ static int handle_packet_online(Group_Chats *g_c, int friendcon_id, const uint8_ | |||
1524 | } | 1533 | } |
1525 | 1534 | ||
1526 | int groupnumber = get_group_num(g_c, data + sizeof(uint16_t)); | 1535 | int groupnumber = get_group_num(g_c, data + sizeof(uint16_t)); |
1536 | |||
1537 | if (groupnumber == -1) { | ||
1538 | return -1; | ||
1539 | } | ||
1540 | |||
1527 | uint16_t other_groupnum; | 1541 | uint16_t other_groupnum; |
1528 | memcpy(&other_groupnum, data, sizeof(uint16_t)); | 1542 | memcpy(&other_groupnum, data, sizeof(uint16_t)); |
1529 | other_groupnum = net_ntohs(other_groupnum); | 1543 | 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 | |||
1600 | /* return number of peers sent on success. | 1614 | /* return number of peers sent on success. |
1601 | * return 0 on failure. | 1615 | * return 0 on failure. |
1602 | */ | 1616 | */ |
1603 | static unsigned int send_peers(Group_Chats *g_c, int groupnumber, int friendcon_id, uint16_t group_num) | 1617 | static unsigned int send_peers(Group_Chats *g_c, uint32_t groupnumber, int friendcon_id, uint16_t group_num) |
1604 | { | 1618 | { |
1605 | Group_c *g = get_group_c(g_c, groupnumber); | 1619 | Group_c *g = get_group_c(g_c, groupnumber); |
1606 | 1620 | ||
1607 | if (!g) { | 1621 | if (!g) { |
1608 | return -1; | 1622 | return 0; |
1609 | } | 1623 | } |
1610 | 1624 | ||
1611 | uint8_t packet[MAX_CRYPTO_DATA_SIZE - (1 + sizeof(uint16_t))]; | 1625 | 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_ | |||
1655 | return sent; | 1669 | return sent; |
1656 | } | 1670 | } |
1657 | 1671 | ||
1658 | static int handle_send_peers(Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length, void *userdata) | 1672 | static int handle_send_peers(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length, |
1673 | void *userdata) | ||
1659 | { | 1674 | { |
1660 | if (length == 0) { | 1675 | if (length == 0) { |
1661 | return -1; | 1676 | return -1; |
@@ -1702,7 +1717,7 @@ static int handle_send_peers(Group_Chats *g_c, int groupnumber, const uint8_t *d | |||
1702 | return 0; | 1717 | return 0; |
1703 | } | 1718 | } |
1704 | 1719 | ||
1705 | static void handle_direct_packet(Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length, | 1720 | static void handle_direct_packet(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length, |
1706 | int close_index, void *userdata) | 1721 | int close_index, void *userdata) |
1707 | { | 1722 | { |
1708 | if (length == 0) { | 1723 | if (length == 0) { |
@@ -1758,7 +1773,7 @@ static void handle_direct_packet(Group_Chats *g_c, int groupnumber, const uint8_ | |||
1758 | * | 1773 | * |
1759 | * return number of messages sent. | 1774 | * return number of messages sent. |
1760 | */ | 1775 | */ |
1761 | static unsigned int send_message_all_close(const Group_Chats *g_c, int groupnumber, const uint8_t *data, | 1776 | static unsigned int send_message_all_close(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, |
1762 | uint16_t length, int receiver) | 1777 | uint16_t length, int receiver) |
1763 | { | 1778 | { |
1764 | Group_c *g = get_group_c(g_c, groupnumber); | 1779 | 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 | |||
1792 | * | 1807 | * |
1793 | * return number of messages sent. | 1808 | * return number of messages sent. |
1794 | */ | 1809 | */ |
1795 | static unsigned int send_lossy_all_close(const Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length, | 1810 | static unsigned int send_lossy_all_close(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, |
1811 | uint16_t length, | ||
1796 | int receiver) | 1812 | int receiver) |
1797 | { | 1813 | { |
1798 | Group_c *g = get_group_c(g_c, groupnumber); | 1814 | 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 | |||
1885 | * return -3 if we are not connected to the group. | 1901 | * return -3 if we are not connected to the group. |
1886 | * reutrn -4 if message failed to send. | 1902 | * reutrn -4 if message failed to send. |
1887 | */ | 1903 | */ |
1888 | static int send_message_group(const Group_Chats *g_c, int groupnumber, uint8_t message_id, const uint8_t *data, | 1904 | static int send_message_group(const Group_Chats *g_c, uint32_t groupnumber, uint8_t message_id, const uint8_t *data, |
1889 | uint16_t len) | 1905 | uint16_t len) |
1890 | { | 1906 | { |
1891 | Group_c *g = get_group_c(g_c, groupnumber); | 1907 | 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 | |||
1930 | * return 0 on success | 1946 | * return 0 on success |
1931 | * see: send_message_group() for error codes. | 1947 | * see: send_message_group() for error codes. |
1932 | */ | 1948 | */ |
1933 | int group_message_send(const Group_Chats *g_c, int groupnumber, const uint8_t *message, uint16_t length) | 1949 | int group_message_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *message, uint16_t length) |
1934 | { | 1950 | { |
1935 | int ret = send_message_group(g_c, groupnumber, PACKET_ID_MESSAGE, message, length); | 1951 | int ret = send_message_group(g_c, groupnumber, PACKET_ID_MESSAGE, message, length); |
1936 | 1952 | ||
@@ -1945,7 +1961,7 @@ int group_message_send(const Group_Chats *g_c, int groupnumber, const uint8_t *m | |||
1945 | * return 0 on success | 1961 | * return 0 on success |
1946 | * see: send_message_group() for error codes. | 1962 | * see: send_message_group() for error codes. |
1947 | */ | 1963 | */ |
1948 | int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *action, uint16_t length) | 1964 | int group_action_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *action, uint16_t length) |
1949 | { | 1965 | { |
1950 | int ret = send_message_group(g_c, groupnumber, PACKET_ID_ACTION, action, length); | 1966 | int ret = send_message_group(g_c, groupnumber, PACKET_ID_ACTION, action, length); |
1951 | 1967 | ||
@@ -1961,7 +1977,7 @@ int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *ac | |||
1961 | * return -1 on failure. | 1977 | * return -1 on failure. |
1962 | * return 0 on success. | 1978 | * return 0 on success. |
1963 | */ | 1979 | */ |
1964 | int send_group_lossy_packet(const Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length) | 1980 | int send_group_lossy_packet(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length) |
1965 | { | 1981 | { |
1966 | // TODO(irungentoo): length check here? | 1982 | // TODO(irungentoo): length check here? |
1967 | Group_c *g = get_group_c(g_c, groupnumber); | 1983 | 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 | |||
1985 | return 0; | 2001 | return 0; |
1986 | } | 2002 | } |
1987 | 2003 | ||
1988 | static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length, | 2004 | static void handle_message_packet_group(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length, |
1989 | int close_index, void *userdata) | 2005 | int close_index, void *userdata) |
1990 | { | 2006 | { |
1991 | if (length < sizeof(uint16_t) + sizeof(uint32_t) + 1) { | 2007 | 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, | |||
2186 | static unsigned int lossy_packet_not_received(Group_c *g, int peer_index, uint16_t message_number) | 2202 | static unsigned int lossy_packet_not_received(Group_c *g, int peer_index, uint16_t message_number) |
2187 | { | 2203 | { |
2188 | if (peer_index == -1) { | 2204 | if (peer_index == -1) { |
2205 | // TODO(sudden6): invalid return value | ||
2189 | return -1; | 2206 | return -1; |
2190 | } | 2207 | } |
2191 | 2208 | ||
@@ -2206,6 +2223,7 @@ static unsigned int lossy_packet_not_received(Group_c *g, int peer_index, uint16 | |||
2206 | } | 2223 | } |
2207 | 2224 | ||
2208 | if ((uint16_t)(message_number - g->group[peer_index].bottom_lossy_number) > (1 << 15)) { | 2225 | if ((uint16_t)(message_number - g->group[peer_index].bottom_lossy_number) > (1 << 15)) { |
2226 | // TODO(sudden6): invalid return value | ||
2209 | return -1; | 2227 | return -1; |
2210 | } | 2228 | } |
2211 | 2229 | ||
@@ -2304,7 +2322,7 @@ static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uin | |||
2304 | * return 0 on success. | 2322 | * return 0 on success. |
2305 | * return -1 on failure | 2323 | * return -1 on failure |
2306 | */ | 2324 | */ |
2307 | int group_set_object(const Group_Chats *g_c, int groupnumber, void *object) | 2325 | int group_set_object(const Group_Chats *g_c, uint32_t groupnumber, void *object) |
2308 | { | 2326 | { |
2309 | Group_c *g = get_group_c(g_c, groupnumber); | 2327 | Group_c *g = get_group_c(g_c, groupnumber); |
2310 | 2328 | ||
@@ -2321,7 +2339,7 @@ int group_set_object(const Group_Chats *g_c, int groupnumber, void *object) | |||
2321 | * return 0 on success. | 2339 | * return 0 on success. |
2322 | * return -1 on failure | 2340 | * return -1 on failure |
2323 | */ | 2341 | */ |
2324 | int group_peer_set_object(const Group_Chats *g_c, int groupnumber, int peernumber, void *object) | 2342 | int group_peer_set_object(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, void *object) |
2325 | { | 2343 | { |
2326 | Group_c *g = get_group_c(g_c, groupnumber); | 2344 | Group_c *g = get_group_c(g_c, groupnumber); |
2327 | 2345 | ||
@@ -2342,7 +2360,7 @@ int group_peer_set_object(const Group_Chats *g_c, int groupnumber, int peernumbe | |||
2342 | * return NULL on failure. | 2360 | * return NULL on failure. |
2343 | * return object on success. | 2361 | * return object on success. |
2344 | */ | 2362 | */ |
2345 | void *group_get_object(const Group_Chats *g_c, int groupnumber) | 2363 | void *group_get_object(const Group_Chats *g_c, uint32_t groupnumber) |
2346 | { | 2364 | { |
2347 | Group_c *g = get_group_c(g_c, groupnumber); | 2365 | Group_c *g = get_group_c(g_c, groupnumber); |
2348 | 2366 | ||
@@ -2358,7 +2376,7 @@ void *group_get_object(const Group_Chats *g_c, int groupnumber) | |||
2358 | * return NULL on failure. | 2376 | * return NULL on failure. |
2359 | * return object on success. | 2377 | * return object on success. |
2360 | */ | 2378 | */ |
2361 | void *group_peer_get_object(const Group_Chats *g_c, int groupnumber, int peernumber) | 2379 | void *group_peer_get_object(const Group_Chats *g_c, uint32_t groupnumber, int peernumber) |
2362 | { | 2380 | { |
2363 | Group_c *g = get_group_c(g_c, groupnumber); | 2381 | Group_c *g = get_group_c(g_c, groupnumber); |
2364 | 2382 | ||
@@ -2376,7 +2394,7 @@ void *group_peer_get_object(const Group_Chats *g_c, int groupnumber, int peernum | |||
2376 | /* Interval in seconds to send ping messages */ | 2394 | /* Interval in seconds to send ping messages */ |
2377 | #define GROUP_PING_INTERVAL 20 | 2395 | #define GROUP_PING_INTERVAL 20 |
2378 | 2396 | ||
2379 | static int ping_groupchat(Group_Chats *g_c, int groupnumber) | 2397 | static int ping_groupchat(Group_Chats *g_c, uint32_t groupnumber) |
2380 | { | 2398 | { |
2381 | Group_c *g = get_group_c(g_c, groupnumber); | 2399 | Group_c *g = get_group_c(g_c, groupnumber); |
2382 | 2400 | ||
@@ -2393,7 +2411,7 @@ static int ping_groupchat(Group_Chats *g_c, int groupnumber) | |||
2393 | return 0; | 2411 | return 0; |
2394 | } | 2412 | } |
2395 | 2413 | ||
2396 | static int groupchat_clear_timedout(Group_Chats *g_c, int groupnumber, void *userdata) | 2414 | static int groupchat_clear_timedout(Group_Chats *g_c, uint32_t groupnumber, void *userdata) |
2397 | { | 2415 | { |
2398 | Group_c *g = get_group_c(g_c, groupnumber); | 2416 | Group_c *g = get_group_c(g_c, groupnumber); |
2399 | 2417 | ||