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:
irungentoo 2014-03-31 20:37:03 -04:00
parent 27a7bf5b1e
commit 4f1e02bafa
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
8 changed files with 33 additions and 12 deletions

View File

@ -274,6 +274,16 @@ START_TEST(test_some)
ck_assert_msg(len == sizeof(test_packet), "wrong len %u", len); 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], 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]); 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 END_TEST

View File

@ -1020,7 +1020,8 @@ void print_groupchatpeers(Tox *m, int groupnumber)
} }
uint8_t names[num][TOX_MAX_NAME_LENGTH]; 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; int i;
char numstr[16]; char numstr[16];
char header[] = "[g]+ "; char header[] = "[g]+ ";
@ -1030,7 +1031,7 @@ void print_groupchatpeers(Tox *m, int groupnumber)
size_t len_total = header_len; size_t len_total = header_len;
for (i = 0; i < num; ++i) { 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); size_t len_num = sprintf(numstr, "%i: ", i);
if (len_num + len_name + len_total + 3 >= STRING_LENGTH) { 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); strcpy(msg + len_total, numstr);
len_total += len_num; len_total += len_num;
strcpy(msg + len_total, (char *)names[i]); memcpy(msg + len_total, (char *)names[i], len_name);
len_total += len_name; len_total += len_name;
if (i < num - 1) { if (i < num - 1) {

View File

@ -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 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. * returns the number of peers on success.
* *
* return -1 on failure. * 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)) if (groupnumber_not_valid(m, groupnumber))
return -1; 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) static int handle_group(void *object, IP_Port source, uint8_t *packet, uint32_t length)

View File

@ -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 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. * returns the number of peers on success.
* *
* return -1 on failure. * 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*****************/ /****************FILE SENDING*****************/

View File

@ -719,12 +719,12 @@ uint32_t group_numpeers(Group_Chat *chat)
return chat->numpeers; 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; uint32_t i;
for (i = 0; i < chat->numpeers && i < length; ++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; return i;

View File

@ -174,7 +174,7 @@ uint32_t group_numpeers(Group_Chat *chat);
* *
* returns the number of peers. * 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 /* Kill a group chat
* *

View File

@ -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 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. * returns the number of peers on success.
* *
* return -1 on failure. * 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; 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. /* Return the number of chats in the instance m.

View File

@ -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 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. * returns the number of peers on success.
* *
* return -1 on failure. * 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. /* Return the number of chats in the instance m.
* You should use this to determine how much memory to allocate * You should use this to determine how much memory to allocate