mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
tox_group_get_names now returns a list of name lengths along with the list of names.
TCP test now also tests pings.
This commit is contained in:
parent
27a7bf5b1e
commit
4f1e02bafa
|
@ -274,6 +274,16 @@ START_TEST(test_some)
|
|||
ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len);
|
||||
ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
|
||||
data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
|
||||
|
||||
uint8_t ping_packet[1 + sizeof(uint64_t)] = {4, 8, 6, 9, 67};
|
||||
write_packet_TCP_secure_connection(con1, ping_packet, sizeof(ping_packet));
|
||||
c_sleep(50);
|
||||
do_TCP_server(tcp_s);
|
||||
c_sleep(50);
|
||||
len = read_packet_sec_TCP(con1, data, 2 + sizeof(ping_packet) + crypto_box_MACBYTES);
|
||||
ck_assert_msg(len == sizeof(ping_packet), "wrong len %u", len);
|
||||
ck_assert_msg(data[0] == 5, "wrong packet id %u", data[0]);
|
||||
ck_assert_msg(memcmp(ping_packet + 1, data + 1, sizeof(uint64_t)) == 0, "wrong packet data");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
|
|
@ -1020,7 +1020,8 @@ void print_groupchatpeers(Tox *m, int groupnumber)
|
|||
}
|
||||
|
||||
uint8_t names[num][TOX_MAX_NAME_LENGTH];
|
||||
tox_group_get_names(m, groupnumber, names, num);
|
||||
uint16_t lengths[num];
|
||||
tox_group_get_names(m, groupnumber, names, lengths, num);
|
||||
int i;
|
||||
char numstr[16];
|
||||
char header[] = "[g]+ ";
|
||||
|
@ -1030,7 +1031,7 @@ void print_groupchatpeers(Tox *m, int groupnumber)
|
|||
size_t len_total = header_len;
|
||||
|
||||
for (i = 0; i < num; ++i) {
|
||||
size_t len_name = strlen((char *)names[i]);
|
||||
size_t len_name = lengths[i];
|
||||
size_t len_num = sprintf(numstr, "%i: ", i);
|
||||
|
||||
if (len_num + len_name + len_total + 3 >= STRING_LENGTH) {
|
||||
|
@ -1042,7 +1043,7 @@ void print_groupchatpeers(Tox *m, int groupnumber)
|
|||
|
||||
strcpy(msg + len_total, numstr);
|
||||
len_total += len_num;
|
||||
strcpy(msg + len_total, (char *)names[i]);
|
||||
memcpy(msg + len_total, (char *)names[i], len_name);
|
||||
len_total += len_name;
|
||||
|
||||
if (i < num - 1) {
|
||||
|
|
|
@ -1243,16 +1243,18 @@ int group_number_peers(Messenger *m, int groupnumber)
|
|||
*
|
||||
* Copies the names of the peers to the name[length][MAX_NICK_BYTES] array.
|
||||
*
|
||||
* Copies the lengths of the names to lengths[length]
|
||||
*
|
||||
* returns the number of peers on success.
|
||||
*
|
||||
* return -1 on failure.
|
||||
*/
|
||||
int group_names(Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES], uint16_t length)
|
||||
int group_names(Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES], uint16_t lengths[], uint16_t length)
|
||||
{
|
||||
if (groupnumber_not_valid(m, groupnumber))
|
||||
return -1;
|
||||
|
||||
return group_client_names(m->chats[groupnumber], names, length);
|
||||
return group_client_names(m->chats[groupnumber], names, lengths, length);
|
||||
}
|
||||
|
||||
static int handle_group(void *object, IP_Port source, uint8_t *packet, uint32_t length)
|
||||
|
|
|
@ -596,11 +596,13 @@ int group_number_peers(Messenger *m, int groupnumber);
|
|||
*
|
||||
* Copies the names of the peers to the name[length][MAX_NICK_BYTES] array.
|
||||
*
|
||||
* Copies the lengths of the names to lengths[length]
|
||||
*
|
||||
* returns the number of peers on success.
|
||||
*
|
||||
* return -1 on failure.
|
||||
*/
|
||||
int group_names(Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES], uint16_t length);
|
||||
int group_names(Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES], uint16_t lengths[], uint16_t length);
|
||||
|
||||
/****************FILE SENDING*****************/
|
||||
|
||||
|
|
|
@ -719,12 +719,12 @@ uint32_t group_numpeers(Group_Chat *chat)
|
|||
return chat->numpeers;
|
||||
}
|
||||
|
||||
uint32_t group_client_names(Group_Chat *chat, uint8_t names[][MAX_NICK_BYTES], uint16_t length)
|
||||
uint32_t group_client_names(Group_Chat *chat, uint8_t names[][MAX_NICK_BYTES], uint16_t lengths[], uint16_t length)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < chat->numpeers && i < length; ++i) {
|
||||
group_peername(chat, i, names[i]);
|
||||
lengths[i] = group_peername(chat, i, names[i]);
|
||||
}
|
||||
|
||||
return i;
|
||||
|
|
|
@ -174,7 +174,7 @@ uint32_t group_numpeers(Group_Chat *chat);
|
|||
*
|
||||
* returns the number of peers.
|
||||
*/
|
||||
uint32_t group_client_names(Group_Chat *chat, uint8_t names[][MAX_NICK_BYTES], uint16_t length);
|
||||
uint32_t group_client_names(Group_Chat *chat, uint8_t names[][MAX_NICK_BYTES], uint16_t lengths[], uint16_t length);
|
||||
|
||||
/* Kill a group chat
|
||||
*
|
||||
|
|
|
@ -593,14 +593,17 @@ int tox_group_number_peers(Tox *tox, int groupnumber)
|
|||
*
|
||||
* Copies the names of the peers to the name[length][MAX_NICK_BYTES] array.
|
||||
*
|
||||
* Copies the lengths of the names to lengths[length]
|
||||
*
|
||||
* returns the number of peers on success.
|
||||
*
|
||||
* return -1 on failure.
|
||||
*/
|
||||
int tox_group_get_names(Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t length)
|
||||
int tox_group_get_names(Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t lengths[],
|
||||
uint16_t length)
|
||||
{
|
||||
Messenger *m = tox;
|
||||
return group_names(m, groupnumber, names, length);
|
||||
return group_names(m, groupnumber, names, lengths, length);
|
||||
}
|
||||
|
||||
/* Return the number of chats in the instance m.
|
||||
|
|
|
@ -462,11 +462,14 @@ int tox_group_number_peers(Tox *tox, int groupnumber);
|
|||
*
|
||||
* Copies the names of the peers to the name[length][TOX_MAX_NAME_LENGTH] array.
|
||||
*
|
||||
* Copies the lengths of the names to lengths[length]
|
||||
*
|
||||
* returns the number of peers on success.
|
||||
*
|
||||
* return -1 on failure.
|
||||
*/
|
||||
int tox_group_get_names(Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t length);
|
||||
int tox_group_get_names(Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t lengths[],
|
||||
uint16_t length);
|
||||
|
||||
/* Return the number of chats in the instance m.
|
||||
* You should use this to determine how much memory to allocate
|
||||
|
|
Loading…
Reference in New Issue
Block a user