summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/Messenger.c57
-rw-r--r--toxcore/Messenger.h5
2 files changed, 4 insertions, 58 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 8cae2914..cdbb95f1 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -38,8 +38,6 @@
38static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status); 38static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status);
39static int write_cryptpacket_id(Messenger *m, int32_t friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length); 39static int write_cryptpacket_id(Messenger *m, int32_t friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length);
40 40
41static IP_Port get_friend_ipport(Messenger *m, int32_t friendnumber);
42
43// friend_not_valid determines if the friendnumber passed is valid in the Messenger object 41// friend_not_valid determines if the friendnumber passed is valid in the Messenger object
44static uint8_t friend_not_valid(Messenger *m, int32_t friendnumber) 42static uint8_t friend_not_valid(Messenger *m, int32_t friendnumber)
45{ 43{
@@ -51,27 +49,6 @@ static int add_online_friend(Messenger *m, int32_t friendnumber)
51 if (friend_not_valid(m, friendnumber)) 49 if (friend_not_valid(m, friendnumber))
52 return -1; 50 return -1;
53 51
54 IP_Port temp_ip_port = get_friend_ipport(m, friendnumber);
55
56 if (temp_ip_port.port == 0)
57 return -1;
58
59 uint32_t i;
60
61 for (i = 0; i < m->numonline_friends; ++i) {
62 if (m->online_friendlist[i].friend_num == (uint32_t)friendnumber)
63 return 0;
64 }
65
66 Online_Friend *temp;
67 temp = realloc(m->online_friendlist, sizeof(Online_Friend) * (m->numonline_friends + 1));
68
69 if (temp == NULL)
70 return -1;
71
72 m->online_friendlist = temp;
73 m->online_friendlist[m->numonline_friends].friend_num = friendnumber;
74 m->online_friendlist[m->numonline_friends].ip_port = temp_ip_port;
75 ++m->numonline_friends; 52 ++m->numonline_friends;
76 return 0; 53 return 0;
77} 54}
@@ -79,37 +56,11 @@ static int add_online_friend(Messenger *m, int32_t friendnumber)
79 56
80static int remove_online_friend(Messenger *m, int32_t friendnumber) 57static int remove_online_friend(Messenger *m, int32_t friendnumber)
81{ 58{
82 uint32_t i; 59 if (friend_not_valid(m, friendnumber))
83 Online_Friend *temp; 60 return -1;
84
85 for (i = 0; i < m->numonline_friends; ++i) {
86 /* Equal */
87 if (m->online_friendlist[i].friend_num == (uint32_t)friendnumber) {
88 --m->numonline_friends;
89
90 if (m->numonline_friends != i) {
91 memcpy( &m->online_friendlist[i],
92 &m->online_friendlist[m->numonline_friends],
93 sizeof(Online_Friend) );
94 }
95
96 if (m->numonline_friends == 0) {
97 free(m->online_friendlist);
98 m->online_friendlist = NULL;
99 return 0;
100 }
101
102 temp = realloc(m->online_friendlist, sizeof(Online_Friend) * (m->numonline_friends));
103
104 if (temp == NULL)
105 return -1;
106
107 m->online_friendlist = temp;
108 return 0;
109 }
110 }
111 61
112 return -1; 62 --m->numonline_friends;
63 return 0;
113} 64}
114/* Set the size of the friend list to numfriends. 65/* Set the size of the friend list to numfriends.
115 * 66 *
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 1f22f423..045bccde 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -173,10 +173,6 @@ typedef struct {
173 } packethandlers[PACKET_ID_LOSSY_RANGE_SIZE]; 173 } packethandlers[PACKET_ID_LOSSY_RANGE_SIZE];
174} Friend; 174} Friend;
175 175
176typedef struct {
177 uint32_t friend_num;
178 IP_Port ip_port;
179} Online_Friend;
180 176
181typedef struct Messenger { 177typedef struct Messenger {
182 178
@@ -200,7 +196,6 @@ typedef struct Messenger {
200 Friend *friendlist; 196 Friend *friendlist;
201 uint32_t numfriends; 197 uint32_t numfriends;
202 198
203 Online_Friend *online_friendlist;
204 uint32_t numonline_friends; 199 uint32_t numonline_friends;
205 200
206 Group_Chat **chats; 201 Group_Chat **chats;