diff options
-rwxr-xr-x | .travis/cmake-linux | 4 | ||||
-rw-r--r-- | toxcore/group.c | 63 | ||||
-rw-r--r-- | toxcore/group.h | 113 |
3 files changed, 95 insertions, 85 deletions
diff --git a/.travis/cmake-linux b/.travis/cmake-linux index e5874c19..48b72925 100755 --- a/.travis/cmake-linux +++ b/.travis/cmake-linux | |||
@@ -48,6 +48,8 @@ travis_script() { | |||
48 | # Coverage flags. | 48 | # Coverage flags. |
49 | add_flag -fprofile-arcs -ftest-coverage | 49 | add_flag -fprofile-arcs -ftest-coverage |
50 | 50 | ||
51 | other/astyle/format-source . "$ASTYLE" | ||
52 | |||
51 | cmake -B_build -H. \ | 53 | cmake -B_build -H. \ |
52 | -DCMAKE_C_FLAGS="$C_FLAGS" \ | 54 | -DCMAKE_C_FLAGS="$C_FLAGS" \ |
53 | -DCMAKE_CXX_FLAGS="$CXX_FLAGS" \ | 55 | -DCMAKE_CXX_FLAGS="$CXX_FLAGS" \ |
@@ -65,8 +67,6 @@ travis_script() { | |||
65 | make "-j$NPROC" test ARGS="-j50" || \ | 67 | make "-j$NPROC" test ARGS="-j50" || \ |
66 | make "-j$NPROC" test ARGS="-j50 --rerun-failed" CTEST_OUTPUT_ON_FAILURE=1 | 68 | make "-j$NPROC" test ARGS="-j50 --rerun-failed" CTEST_OUTPUT_ON_FAILURE=1 |
67 | cd - # popd | 69 | cd - # popd |
68 | |||
69 | other/astyle/format-source . "$ASTYLE" | ||
70 | } | 70 | } |
71 | 71 | ||
72 | if [ "-z" "$ACTION" ]; then | 72 | if [ "-z" "$ACTION" ]; then |
diff --git a/toxcore/group.c b/toxcore/group.c index 4942d872..a2ebca16 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -221,11 +221,11 @@ static uint64_t calculate_comp_value(const uint8_t *pk1, const uint8_t *pk2) | |||
221 | return (cmp1 - cmp2); | 221 | return (cmp1 - cmp2); |
222 | } | 222 | } |
223 | 223 | ||
224 | enum { | 224 | typedef enum Groupchat_Closest { |
225 | GROUPCHAT_CLOSEST_NONE, | 225 | GROUPCHAT_CLOSEST_NONE, |
226 | GROUPCHAT_CLOSEST_ADDED, | 226 | GROUPCHAT_CLOSEST_ADDED, |
227 | GROUPCHAT_CLOSEST_REMOVED | 227 | GROUPCHAT_CLOSEST_REMOVED |
228 | }; | 228 | } Groupchat_Closest; |
229 | 229 | ||
230 | static int friend_in_close(Group_c *g, int friendcon_id); | 230 | static int friend_in_close(Group_c *g, int friendcon_id); |
231 | static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, uint32_t groupnumber, uint8_t closest, | 231 | static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, uint32_t groupnumber, uint8_t closest, |
@@ -1114,9 +1114,7 @@ int join_groupchat(Group_Chats *g_c, uint32_t friendnumber, uint8_t expected_typ | |||
1114 | * | 1114 | * |
1115 | * 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) | 1115 | * 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) |
1116 | */ | 1116 | */ |
1117 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, uint32_t, uint32_t, | 1117 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, lossy_packet_cb *function) |
1118 | void *, | ||
1119 | const uint8_t *, uint16_t)) | ||
1120 | { | 1118 | { |
1121 | g_c->lossy_packethandlers[byte].function = function; | 1119 | g_c->lossy_packethandlers[byte].function = function; |
1122 | } | 1120 | } |
@@ -1127,8 +1125,7 @@ void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*fu | |||
1127 | * | 1125 | * |
1128 | * data of length is what needs to be passed to join_groupchat(). | 1126 | * data of length is what needs to be passed to join_groupchat(). |
1129 | */ | 1127 | */ |
1130 | void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, int, const uint8_t *, | 1128 | void g_callback_group_invite(Group_Chats *g_c, g_conference_invite_cb *function) |
1131 | size_t, void *)) | ||
1132 | { | 1129 | { |
1133 | g_c->invite_callback = function; | 1130 | g_c->invite_callback = function; |
1134 | } | 1131 | } |
@@ -1138,8 +1135,7 @@ void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, ui | |||
1138 | * | 1135 | * |
1139 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * message, size_t length, void *userdata) | 1136 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * message, size_t length, void *userdata) |
1140 | */ | 1137 | */ |
1141 | void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, | 1138 | void g_callback_group_message(Group_Chats *g_c, g_conference_message_cb *function) |
1142 | size_t, void *)) | ||
1143 | { | 1139 | { |
1144 | g_c->message_callback = function; | 1140 | g_c->message_callback = function; |
1145 | } | 1141 | } |
@@ -1149,8 +1145,7 @@ void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, u | |||
1149 | * It gets called every time a peer changes their nickname. | 1145 | * It gets called every time a peer changes their nickname. |
1150 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, const uint8_t *nick, size_t nick_len, void *userdata) | 1146 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, const uint8_t *nick, size_t nick_len, void *userdata) |
1151 | */ | 1147 | */ |
1152 | void g_callback_peer_name(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *, | 1148 | void g_callback_peer_name(Group_Chats *g_c, peer_name_cb *function) |
1153 | size_t, void *)) | ||
1154 | { | 1149 | { |
1155 | g_c->peer_name_callback = function; | 1150 | g_c->peer_name_callback = function; |
1156 | } | 1151 | } |
@@ -1160,7 +1155,7 @@ void g_callback_peer_name(Group_Chats *g_c, void (*function)(Messenger *m, uint3 | |||
1160 | * It gets called every time the name list changes(new peer, deleted peer) | 1155 | * It gets called every time the name list changes(new peer, deleted peer) |
1161 | * Function(Group_Chats *g_c, uint32_t groupnumber, void *userdata) | 1156 | * Function(Group_Chats *g_c, uint32_t groupnumber, void *userdata) |
1162 | */ | 1157 | */ |
1163 | void g_callback_peer_list_changed(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, void *)) | 1158 | void g_callback_peer_list_changed(Group_Chats *g_c, peer_list_changed_cb *function) |
1164 | { | 1159 | { |
1165 | g_c->peer_list_changed_callback = function; | 1160 | g_c->peer_list_changed_callback = function; |
1166 | } | 1161 | } |
@@ -1171,8 +1166,7 @@ void g_callback_peer_list_changed(Group_Chats *g_c, void (*function)(Messenger * | |||
1171 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) | 1166 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) |
1172 | * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group) | 1167 | * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group) |
1173 | */ | 1168 | */ |
1174 | void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *, | 1169 | void g_callback_group_title(Group_Chats *g_c, title_cb *function) |
1175 | size_t, void *)) | ||
1176 | { | 1170 | { |
1177 | g_c->title_callback = function; | 1171 | g_c->title_callback = function; |
1178 | } | 1172 | } |
@@ -1184,8 +1178,7 @@ void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, uin | |||
1184 | * return 0 on success. | 1178 | * return 0 on success. |
1185 | * return -1 on failure. | 1179 | * return -1 on failure. |
1186 | */ | 1180 | */ |
1187 | int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, | 1181 | int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, peer_on_join_cb *function) |
1188 | uint32_t)) | ||
1189 | { | 1182 | { |
1190 | Group_c *g = get_group_c(g_c, groupnumber); | 1183 | Group_c *g = get_group_c(g_c, groupnumber); |
1191 | 1184 | ||
@@ -1204,7 +1197,7 @@ int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, vo | |||
1204 | * return 0 on success. | 1197 | * return 0 on success. |
1205 | * return -1 on failure. | 1198 | * return -1 on failure. |
1206 | */ | 1199 | */ |
1207 | int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, void *)) | 1200 | int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, peer_on_leave_cb *function) |
1208 | { | 1201 | { |
1209 | Group_c *g = get_group_c(g_c, groupnumber); | 1202 | Group_c *g = get_group_c(g_c, groupnumber); |
1210 | 1203 | ||
@@ -1223,7 +1216,7 @@ int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, void | |||
1223 | * return 0 on success. | 1216 | * return 0 on success. |
1224 | * return -1 on failure. | 1217 | * return -1 on failure. |
1225 | */ | 1218 | */ |
1226 | int callback_groupchat_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t)) | 1219 | int callback_groupchat_delete(Group_Chats *g_c, uint32_t groupnumber, group_on_delete_cb *function) |
1227 | { | 1220 | { |
1228 | Group_c *g = get_group_c(g_c, groupnumber); | 1221 | Group_c *g = get_group_c(g_c, groupnumber); |
1229 | 1222 | ||
@@ -1414,7 +1407,7 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con | |||
1414 | 1407 | ||
1415 | if (groupnumber == -1) { | 1408 | if (groupnumber == -1) { |
1416 | if (g_c->invite_callback) { | 1409 | if (g_c->invite_callback) { |
1417 | g_c->invite_callback(m, friendnumber, *(invite_data + sizeof(uint16_t)), invite_data, invite_length, userdata); | 1410 | g_c->invite_callback(m, friendnumber, invite_data[sizeof(uint16_t)], invite_data, invite_length, userdata); |
1418 | } | 1411 | } |
1419 | 1412 | ||
1420 | return; | 1413 | return; |
@@ -1631,22 +1624,24 @@ static unsigned int send_peers(Group_Chats *g_c, uint32_t groupnumber, int frien | |||
1631 | return 0; | 1624 | return 0; |
1632 | } | 1625 | } |
1633 | 1626 | ||
1634 | uint8_t packet[MAX_CRYPTO_DATA_SIZE - (1 + sizeof(uint16_t))]; | 1627 | uint8_t response_packet[MAX_CRYPTO_DATA_SIZE - (1 + sizeof(uint16_t))]; |
1635 | packet[0] = PEER_RESPONSE_ID; | 1628 | response_packet[0] = PEER_RESPONSE_ID; |
1636 | uint8_t *p = packet + 1; | 1629 | uint8_t *p = response_packet + 1; |
1637 | 1630 | ||
1638 | uint16_t sent = 0; | 1631 | uint16_t sent = 0; |
1639 | unsigned int i; | 1632 | unsigned int i; |
1640 | 1633 | ||
1641 | for (i = 0; i < g->numpeers; ++i) { | 1634 | for (i = 0; i < g->numpeers; ++i) { |
1642 | if ((p - packet) + sizeof(uint16_t) + CRYPTO_PUBLIC_KEY_SIZE * 2 + 1 + g->group[i].nick_len > sizeof(packet)) { | 1635 | if ((p - response_packet) + sizeof(uint16_t) + CRYPTO_PUBLIC_KEY_SIZE * 2 + 1 + g->group[i].nick_len > sizeof( |
1643 | if (send_packet_group_peer(g_c->fr_c, friendcon_id, PACKET_ID_DIRECT_CONFERENCE, group_num, packet, (p - packet))) { | 1636 | response_packet)) { |
1637 | if (send_packet_group_peer(g_c->fr_c, friendcon_id, PACKET_ID_DIRECT_CONFERENCE, group_num, response_packet, | ||
1638 | (p - response_packet))) { | ||
1644 | sent = i; | 1639 | sent = i; |
1645 | } else { | 1640 | } else { |
1646 | return sent; | 1641 | return sent; |
1647 | } | 1642 | } |
1648 | 1643 | ||
1649 | p = packet + 1; | 1644 | p = response_packet + 1; |
1650 | } | 1645 | } |
1651 | 1646 | ||
1652 | uint16_t peer_num = net_htons(g->group[i].peer_number); | 1647 | uint16_t peer_num = net_htons(g->group[i].peer_number); |
@@ -1663,16 +1658,18 @@ static unsigned int send_peers(Group_Chats *g_c, uint32_t groupnumber, int frien | |||
1663 | } | 1658 | } |
1664 | 1659 | ||
1665 | if (sent != i) { | 1660 | if (sent != i) { |
1666 | if (send_packet_group_peer(g_c->fr_c, friendcon_id, PACKET_ID_DIRECT_CONFERENCE, group_num, packet, (p - packet))) { | 1661 | if (send_packet_group_peer(g_c->fr_c, friendcon_id, PACKET_ID_DIRECT_CONFERENCE, group_num, response_packet, |
1662 | (p - response_packet))) { | ||
1667 | sent = i; | 1663 | sent = i; |
1668 | } | 1664 | } |
1669 | } | 1665 | } |
1670 | 1666 | ||
1671 | if (g->title_len) { | 1667 | if (g->title_len) { |
1672 | VLA(uint8_t, Packet, 1 + g->title_len); | 1668 | VLA(uint8_t, title_packet, 1 + g->title_len); |
1673 | Packet[0] = PEER_TITLE_ID; | 1669 | title_packet[0] = PEER_TITLE_ID; |
1674 | memcpy(Packet + 1, g->title, g->title_len); | 1670 | memcpy(title_packet + 1, g->title, g->title_len); |
1675 | send_packet_group_peer(g_c->fr_c, friendcon_id, PACKET_ID_DIRECT_CONFERENCE, group_num, Packet, SIZEOF_VLA(Packet)); | 1671 | send_packet_group_peer(g_c->fr_c, friendcon_id, PACKET_ID_DIRECT_CONFERENCE, group_num, title_packet, |
1672 | SIZEOF_VLA(title_packet)); | ||
1676 | } | 1673 | } |
1677 | 1674 | ||
1678 | return sent; | 1675 | return sent; |
@@ -2528,9 +2525,9 @@ uint32_t count_chatlist(Group_Chats *g_c) | |||
2528 | uint32_t ret = 0; | 2525 | uint32_t ret = 0; |
2529 | uint32_t i; | 2526 | uint32_t i; |
2530 | 2527 | ||
2531 | for (i = 0; i < g_c->num_chats; i++) { | 2528 | for (i = 0; i < g_c->num_chats; ++i) { |
2532 | if (g_c->chats[i].status != GROUPCHAT_STATUS_NONE) { | 2529 | if (g_c->chats[i].status != GROUPCHAT_STATUS_NONE) { |
2533 | ret++; | 2530 | ++ret; |
2534 | } | 2531 | } |
2535 | } | 2532 | } |
2536 | 2533 | ||
@@ -2561,7 +2558,7 @@ uint32_t copy_chatlist(Group_Chats *g_c, uint32_t *out_list, uint32_t list_size) | |||
2561 | 2558 | ||
2562 | if (g_c->chats[i].status > GROUPCHAT_STATUS_NONE) { | 2559 | if (g_c->chats[i].status > GROUPCHAT_STATUS_NONE) { |
2563 | out_list[ret] = i; | 2560 | out_list[ret] = i; |
2564 | ret++; | 2561 | ++ret; |
2565 | } | 2562 | } |
2566 | } | 2563 | } |
2567 | 2564 | ||
diff --git a/toxcore/group.h b/toxcore/group.h index 6eeeeff8..947c7035 100644 --- a/toxcore/group.h +++ b/toxcore/group.h | |||
@@ -26,20 +26,20 @@ | |||
26 | 26 | ||
27 | #include "Messenger.h" | 27 | #include "Messenger.h" |
28 | 28 | ||
29 | enum { | 29 | typedef enum Groupchat_Status { |
30 | GROUPCHAT_STATUS_NONE, | 30 | GROUPCHAT_STATUS_NONE, |
31 | GROUPCHAT_STATUS_VALID, | 31 | GROUPCHAT_STATUS_VALID, |
32 | GROUPCHAT_STATUS_CONNECTED | 32 | GROUPCHAT_STATUS_CONNECTED |
33 | }; | 33 | } Groupchat_Status; |
34 | 34 | ||
35 | enum { | 35 | typedef enum Groupchat_Type { |
36 | GROUPCHAT_TYPE_TEXT, | 36 | GROUPCHAT_TYPE_TEXT, |
37 | GROUPCHAT_TYPE_AV | 37 | GROUPCHAT_TYPE_AV |
38 | }; | 38 | } Groupchat_Type; |
39 | 39 | ||
40 | #define MAX_LOSSY_COUNT 256 | 40 | #define MAX_LOSSY_COUNT 256 |
41 | 41 | ||
42 | typedef struct { | 42 | typedef struct Group_Peer { |
43 | uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; | 43 | uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; |
44 | uint8_t temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; | 44 | uint8_t temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; |
45 | 45 | ||
@@ -52,40 +52,49 @@ typedef struct { | |||
52 | uint16_t peer_number; | 52 | uint16_t peer_number; |
53 | 53 | ||
54 | uint8_t recv_lossy[MAX_LOSSY_COUNT]; | 54 | uint8_t recv_lossy[MAX_LOSSY_COUNT]; |
55 | uint16_t bottom_lossy_number, top_lossy_number; | 55 | uint16_t bottom_lossy_number; |
56 | uint16_t top_lossy_number; | ||
56 | 57 | ||
57 | void *object; | 58 | void *object; |
58 | } Group_Peer; | 59 | } Group_Peer; |
59 | 60 | ||
60 | #define DESIRED_CLOSE_CONNECTIONS 4 | 61 | #define DESIRED_CLOSE_CONNECTIONS 4 |
61 | #define MAX_GROUP_CONNECTIONS 16 | 62 | #define MAX_GROUP_CONNECTIONS 16 |
62 | #define GROUP_IDENTIFIER_LENGTH (1 + CRYPTO_SYMMETRIC_KEY_SIZE) /* type + CRYPTO_SYMMETRIC_KEY_SIZE so we can use new_symmetric_key(...) to fill it */ | 63 | #define GROUP_IDENTIFIER_LENGTH (1 + CRYPTO_SYMMETRIC_KEY_SIZE) // type + CRYPTO_SYMMETRIC_KEY_SIZE so we can use new_symmetric_key(...) to fill it |
63 | 64 | ||
64 | enum { | 65 | typedef enum Groupchat_Close_Type { |
65 | GROUPCHAT_CLOSE_NONE, | 66 | GROUPCHAT_CLOSE_NONE, |
66 | GROUPCHAT_CLOSE_CONNECTION, | 67 | GROUPCHAT_CLOSE_CONNECTION, |
67 | GROUPCHAT_CLOSE_ONLINE | 68 | GROUPCHAT_CLOSE_ONLINE |
68 | }; | 69 | } Groupchat_Close_Type; |
69 | 70 | ||
70 | typedef struct { | 71 | typedef struct Groupchat_Close { |
72 | uint8_t type; /* GROUPCHAT_CLOSE_* */ | ||
73 | uint8_t closest; | ||
74 | uint32_t number; | ||
75 | uint16_t group_number; | ||
76 | } Groupchat_Close; | ||
77 | |||
78 | typedef struct Groupchat_Close_Connection { | ||
79 | uint8_t entry; | ||
80 | uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; | ||
81 | uint8_t temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; | ||
82 | } Groupchat_Close_Connection; | ||
83 | |||
84 | typedef void peer_on_join_cb(void *object, uint32_t conference_number, uint32_t peer_number); | ||
85 | typedef void peer_on_leave_cb(void *object, uint32_t conference_number, void *peer_object); | ||
86 | typedef void group_on_delete_cb(void *object, uint32_t conference_number); | ||
87 | |||
88 | typedef struct Group_c { | ||
71 | uint8_t status; | 89 | uint8_t status; |
72 | 90 | ||
73 | Group_Peer *group; | 91 | Group_Peer *group; |
74 | uint32_t numpeers; | 92 | uint32_t numpeers; |
75 | 93 | ||
76 | struct { | 94 | Groupchat_Close close[MAX_GROUP_CONNECTIONS]; |
77 | uint8_t type; /* GROUPCHAT_CLOSE_* */ | ||
78 | uint8_t closest; | ||
79 | uint32_t number; | ||
80 | uint16_t group_number; | ||
81 | } close[MAX_GROUP_CONNECTIONS]; | ||
82 | 95 | ||
83 | uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; | 96 | uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; |
84 | struct { | 97 | Groupchat_Close_Connection closest_peers[DESIRED_CLOSE_CONNECTIONS]; |
85 | uint8_t entry; | ||
86 | uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; | ||
87 | uint8_t temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; | ||
88 | } closest_peers[DESIRED_CLOSE_CONNECTIONS]; | ||
89 | uint8_t changed; | 98 | uint8_t changed; |
90 | 99 | ||
91 | uint8_t identifier[GROUP_IDENTIFIER_LENGTH]; | 100 | uint8_t identifier[GROUP_IDENTIFIER_LENGTH]; |
@@ -103,15 +112,28 @@ typedef struct { | |||
103 | 112 | ||
104 | void *object; | 113 | void *object; |
105 | 114 | ||
106 | void (*peer_on_join)(void *, uint32_t, uint32_t); | 115 | peer_on_join_cb *peer_on_join; |
107 | void (*peer_on_leave)(void *, uint32_t, void *); | 116 | peer_on_leave_cb *peer_on_leave; |
108 | void (*group_on_delete)(void *, uint32_t); | 117 | group_on_delete_cb *group_on_delete; |
109 | } Group_c; | 118 | } Group_c; |
110 | 119 | ||
111 | typedef void g_conference_invite_cb(Messenger *, uint32_t, int, const uint8_t *, size_t, void *); | 120 | typedef void g_conference_invite_cb(Messenger *m, uint32_t friend_number, int type, const uint8_t *cookie, |
112 | typedef void g_conference_message_cb(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, size_t, void *); | 121 | size_t length, void *user_data); |
113 | 122 | typedef void g_conference_message_cb(Messenger *m, uint32_t conference_number, uint32_t peer_number, int type, | |
114 | typedef struct { | 123 | const uint8_t *message, size_t length, void *user_data); |
124 | typedef void peer_name_cb(Messenger *m, uint32_t conference_number, uint32_t peer_number, const uint8_t *name, | ||
125 | size_t length, void *user_data); | ||
126 | typedef void peer_list_changed_cb(Messenger *m, uint32_t conference_number, void *user_data); | ||
127 | typedef void title_cb(Messenger *m, uint32_t conference_number, uint32_t peer_number, const uint8_t *title, | ||
128 | size_t length, void *user_data); | ||
129 | typedef int lossy_packet_cb(void *object, uint32_t conference_number, uint32_t peer_number, void *peer_object, | ||
130 | const uint8_t *packet, uint16_t length); | ||
131 | |||
132 | typedef struct Group_Lossy_Handler { | ||
133 | lossy_packet_cb *function; | ||
134 | } Group_Lossy_Handler; | ||
135 | |||
136 | typedef struct Group_Chats { | ||
115 | Messenger *m; | 137 | Messenger *m; |
116 | Friend_Connections *fr_c; | 138 | Friend_Connections *fr_c; |
117 | 139 | ||
@@ -120,13 +142,11 @@ typedef struct { | |||
120 | 142 | ||
121 | g_conference_invite_cb *invite_callback; | 143 | g_conference_invite_cb *invite_callback; |
122 | g_conference_message_cb *message_callback; | 144 | g_conference_message_cb *message_callback; |
123 | void (*peer_name_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *); | 145 | peer_name_cb *peer_name_callback; |
124 | void (*peer_list_changed_callback)(Messenger *m, uint32_t, void *); | 146 | peer_list_changed_cb *peer_list_changed_callback; |
125 | void (*title_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *); | 147 | title_cb *title_callback; |
126 | 148 | ||
127 | struct { | 149 | Group_Lossy_Handler lossy_packethandlers[256]; |
128 | int (*function)(void *, uint32_t, uint32_t, void *, const uint8_t *, uint16_t); | ||
129 | } lossy_packethandlers[256]; | ||
130 | } Group_Chats; | 150 | } Group_Chats; |
131 | 151 | ||
132 | /* Set the callback for group invites. | 152 | /* Set the callback for group invites. |
@@ -135,15 +155,13 @@ typedef struct { | |||
135 | * | 155 | * |
136 | * data of length is what needs to be passed to join_groupchat(). | 156 | * data of length is what needs to be passed to join_groupchat(). |
137 | */ | 157 | */ |
138 | void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, int, const uint8_t *, | 158 | void g_callback_group_invite(Group_Chats *g_c, g_conference_invite_cb *function); |
139 | size_t, void *)); | ||
140 | 159 | ||
141 | /* Set the callback for group messages. | 160 | /* Set the callback for group messages. |
142 | * | 161 | * |
143 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) | 162 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) |
144 | */ | 163 | */ |
145 | void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, | 164 | void g_callback_group_message(Group_Chats *g_c, g_conference_message_cb *function); |
146 | size_t, void *)); | ||
147 | 165 | ||
148 | 166 | ||
149 | /* Set callback function for title changes. | 167 | /* Set callback function for title changes. |
@@ -151,23 +169,21 @@ void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, u | |||
151 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) | 169 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) |
152 | * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group) | 170 | * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group) |
153 | */ | 171 | */ |
154 | void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *, | 172 | void g_callback_group_title(Group_Chats *g_c, title_cb *function); |
155 | size_t, void *)); | ||
156 | 173 | ||
157 | /* Set callback function for peer nickname changes. | 174 | /* Set callback function for peer nickname changes. |
158 | * | 175 | * |
159 | * It gets called every time a peer changes their nickname. | 176 | * It gets called every time a peer changes their nickname. |
160 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, const uint8_t *nick, size_t nick_len, void *userdata) | 177 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, const uint8_t *nick, size_t nick_len, void *userdata) |
161 | */ | 178 | */ |
162 | void g_callback_peer_name(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *, | 179 | void g_callback_peer_name(Group_Chats *g_c, peer_name_cb *function); |
163 | size_t, void *)); | ||
164 | 180 | ||
165 | /* Set callback function for peer list changes. | 181 | /* Set callback function for peer list changes. |
166 | * | 182 | * |
167 | * It gets called every time the name list changes(new peer, deleted peer) | 183 | * It gets called every time the name list changes(new peer, deleted peer) |
168 | * Function(Group_Chats *g_c, uint32_t groupnumber, void *userdata) | 184 | * Function(Group_Chats *g_c, uint32_t groupnumber, void *userdata) |
169 | */ | 185 | */ |
170 | void g_callback_peer_list_changed(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, void *)); | 186 | void g_callback_peer_list_changed(Group_Chats *g_c, peer_list_changed_cb *function); |
171 | 187 | ||
172 | /* Creates a new groupchat and puts it in the chats array. | 188 | /* Creates a new groupchat and puts it in the chats array. |
173 | * | 189 | * |
@@ -302,9 +318,7 @@ int group_names(const Group_Chats *g_c, uint32_t groupnumber, uint8_t names[][MA | |||
302 | * | 318 | * |
303 | * 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) | 319 | * 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) |
304 | */ | 320 | */ |
305 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, uint32_t, uint32_t, | 321 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, lossy_packet_cb *function); |
306 | void *, | ||
307 | const uint8_t *, uint16_t)); | ||
308 | 322 | ||
309 | /* High level function to send custom lossy packets. | 323 | /* High level function to send custom lossy packets. |
310 | * | 324 | * |
@@ -372,8 +386,7 @@ void *group_peer_get_object(const Group_Chats *g_c, uint32_t groupnumber, int pe | |||
372 | * return 0 on success. | 386 | * return 0 on success. |
373 | * return -1 on failure. | 387 | * return -1 on failure. |
374 | */ | 388 | */ |
375 | int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, | 389 | int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, peer_on_join_cb *function); |
376 | uint32_t)); | ||
377 | 390 | ||
378 | /* Set a function to be called when a peer leaves a group chat. | 391 | /* Set a function to be called when a peer leaves a group chat. |
379 | * | 392 | * |
@@ -382,7 +395,7 @@ int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, vo | |||
382 | * return 0 on success. | 395 | * return 0 on success. |
383 | * return -1 on failure. | 396 | * return -1 on failure. |
384 | */ | 397 | */ |
385 | int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, void *)); | 398 | int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, peer_on_leave_cb *function); |
386 | 399 | ||
387 | /* Set a function to be called when the group chat is deleted. | 400 | /* Set a function to be called when the group chat is deleted. |
388 | * | 401 | * |
@@ -391,7 +404,7 @@ int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, void | |||
391 | * return 0 on success. | 404 | * return 0 on success. |
392 | * return -1 on failure. | 405 | * return -1 on failure. |
393 | */ | 406 | */ |
394 | int callback_groupchat_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t)); | 407 | int callback_groupchat_delete(Group_Chats *g_c, uint32_t groupnumber, group_on_delete_cb *function); |
395 | 408 | ||
396 | /* Create new groupchat instance. */ | 409 | /* Create new groupchat instance. */ |
397 | Group_Chats *new_groupchats(Messenger *m); | 410 | Group_Chats *new_groupchats(Messenger *m); |