Fixed tox_get_num_online_friends function.

Removed useless code.
This commit is contained in:
irungentoo 2014-05-26 13:22:53 -04:00
parent 0239f79f23
commit da3b6a04a9
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
2 changed files with 4 additions and 58 deletions

View File

@ -38,8 +38,6 @@
static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status); static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status);
static int write_cryptpacket_id(Messenger *m, int32_t friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length); static int write_cryptpacket_id(Messenger *m, int32_t friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length);
static IP_Port get_friend_ipport(Messenger *m, int32_t friendnumber);
// friend_not_valid determines if the friendnumber passed is valid in the Messenger object // friend_not_valid determines if the friendnumber passed is valid in the Messenger object
static uint8_t friend_not_valid(Messenger *m, int32_t friendnumber) static uint8_t friend_not_valid(Messenger *m, int32_t friendnumber)
{ {
@ -51,27 +49,6 @@ static int add_online_friend(Messenger *m, int32_t friendnumber)
if (friend_not_valid(m, friendnumber)) if (friend_not_valid(m, friendnumber))
return -1; return -1;
IP_Port temp_ip_port = get_friend_ipport(m, friendnumber);
if (temp_ip_port.port == 0)
return -1;
uint32_t i;
for (i = 0; i < m->numonline_friends; ++i) {
if (m->online_friendlist[i].friend_num == (uint32_t)friendnumber)
return 0;
}
Online_Friend *temp;
temp = realloc(m->online_friendlist, sizeof(Online_Friend) * (m->numonline_friends + 1));
if (temp == NULL)
return -1;
m->online_friendlist = temp;
m->online_friendlist[m->numonline_friends].friend_num = friendnumber;
m->online_friendlist[m->numonline_friends].ip_port = temp_ip_port;
++m->numonline_friends; ++m->numonline_friends;
return 0; return 0;
} }
@ -79,37 +56,11 @@ static int add_online_friend(Messenger *m, int32_t friendnumber)
static int remove_online_friend(Messenger *m, int32_t friendnumber) static int remove_online_friend(Messenger *m, int32_t friendnumber)
{ {
uint32_t i; if (friend_not_valid(m, friendnumber))
Online_Friend *temp; return -1;
for (i = 0; i < m->numonline_friends; ++i) { --m->numonline_friends;
/* Equal */ return 0;
if (m->online_friendlist[i].friend_num == (uint32_t)friendnumber) {
--m->numonline_friends;
if (m->numonline_friends != i) {
memcpy( &m->online_friendlist[i],
&m->online_friendlist[m->numonline_friends],
sizeof(Online_Friend) );
}
if (m->numonline_friends == 0) {
free(m->online_friendlist);
m->online_friendlist = NULL;
return 0;
}
temp = realloc(m->online_friendlist, sizeof(Online_Friend) * (m->numonline_friends));
if (temp == NULL)
return -1;
m->online_friendlist = temp;
return 0;
}
}
return -1;
} }
/* Set the size of the friend list to numfriends. /* Set the size of the friend list to numfriends.
* *

View File

@ -173,10 +173,6 @@ typedef struct {
} packethandlers[PACKET_ID_LOSSY_RANGE_SIZE]; } packethandlers[PACKET_ID_LOSSY_RANGE_SIZE];
} Friend; } Friend;
typedef struct {
uint32_t friend_num;
IP_Port ip_port;
} Online_Friend;
typedef struct Messenger { typedef struct Messenger {
@ -200,7 +196,6 @@ typedef struct Messenger {
Friend *friendlist; Friend *friendlist;
uint32_t numfriends; uint32_t numfriends;
Online_Friend *online_friendlist;
uint32_t numonline_friends; uint32_t numonline_friends;
Group_Chat **chats; Group_Chat **chats;