Skip to content

Commit

Permalink
tox_group_get_names now returns a list of name lengths along with the…
Browse files Browse the repository at this point in the history
… list of names.

TCP test now also tests pings.
  • Loading branch information
irungentoo committed Apr 1, 2014
1 parent 27a7bf5 commit 4f1e02b
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 12 deletions.
10 changes: 10 additions & 0 deletions auto_tests/TCP_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions testing/nTox.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]+ ";
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions toxcore/Messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion toxcore/Messenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*****************/

Expand Down
4 changes: 2 additions & 2 deletions toxcore/group_chats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion toxcore/group_chats.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
7 changes: 5 additions & 2 deletions toxcore/tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion toxcore/tox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4f1e02b

Please sign in to comment.