summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-02-17 10:29:18 -0500
committerirungentoo <irungentoo@gmail.com>2015-02-17 10:29:18 -0500
commit99ee86b865950f9044f03b189b5dd946b617735c (patch)
treee9d10e4546b27e483bc15ad549efee9ba3f3a8b7 /toxcore
parent3f11d106daeeeacf13e6207a7042a90ece7c9325 (diff)
Messenger add friends functions error code fixes.
Removed unknown error. norequest function now returns proper error codes.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/Messenger.c19
-rw-r--r--toxcore/Messenger.h7
2 files changed, 10 insertions, 16 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 55464cb5..1809fc4c 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -194,7 +194,7 @@ static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t sta
194 int friendcon_id = new_friend_connection(m->fr_c, real_pk); 194 int friendcon_id = new_friend_connection(m->fr_c, real_pk);
195 195
196 if (friendcon_id == -1) 196 if (friendcon_id == -1)
197 return FAERR_UNKNOWN; 197 return FAERR_NOMEM;
198 198
199 uint32_t i; 199 uint32_t i;
200 200
@@ -227,7 +227,7 @@ static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t sta
227 } 227 }
228 } 228 }
229 229
230 return FAERR_UNKNOWN; 230 return FAERR_NOMEM;
231} 231}
232 232
233/* 233/*
@@ -241,7 +241,6 @@ static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t sta
241 * return FAERR_NOMESSAGE if no message (message length must be >= 1 byte). 241 * return FAERR_NOMESSAGE if no message (message length must be >= 1 byte).
242 * return FAERR_OWNKEY if user's own key. 242 * return FAERR_OWNKEY if user's own key.
243 * return FAERR_ALREADYSENT if friend request already sent or already a friend. 243 * return FAERR_ALREADYSENT if friend request already sent or already a friend.
244 * return FAERR_UNKNOWN for unknown error.
245 * return FAERR_BADCHECKSUM if bad checksum in address. 244 * return FAERR_BADCHECKSUM if bad checksum in address.
246 * return FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different. 245 * return FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different.
247 * (the nospam for that friend was set to the new one). 246 * (the nospam for that friend was set to the new one).
@@ -303,21 +302,15 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u
303int32_t m_addfriend_norequest(Messenger *m, const uint8_t *real_pk) 302int32_t m_addfriend_norequest(Messenger *m, const uint8_t *real_pk)
304{ 303{
305 if (getfriend_id(m, real_pk) != -1) 304 if (getfriend_id(m, real_pk) != -1)
306 return -1; 305 return FAERR_ALREADYSENT;
307 306
308 if (!public_key_valid(real_pk)) 307 if (!public_key_valid(real_pk))
309 return -1; 308 return FAERR_BADCHECKSUM;
310 309
311 if (id_equal(real_pk, m->net_crypto->self_public_key)) 310 if (id_equal(real_pk, m->net_crypto->self_public_key))
312 return -1; 311 return FAERR_OWNKEY;
313
314 int32_t ret = init_new_friend(m, real_pk, FRIEND_CONFIRMED);
315 312
316 if (ret < 0) { 313 return init_new_friend(m, real_pk, FRIEND_CONFIRMED);
317 return -1;
318 } else {
319 return ret;
320 }
321} 314}
322 315
323/* Remove a friend. 316/* Remove a friend.
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 1139fb74..b1f1c152 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -95,7 +95,6 @@ enum {
95 FAERR_NOMESSAGE = -2, 95 FAERR_NOMESSAGE = -2,
96 FAERR_OWNKEY = -3, 96 FAERR_OWNKEY = -3,
97 FAERR_ALREADYSENT = -4, 97 FAERR_ALREADYSENT = -4,
98 FAERR_UNKNOWN = -5,
99 FAERR_BADCHECKSUM = -6, 98 FAERR_BADCHECKSUM = -6,
100 FAERR_SETNEWNOSPAM = -7, 99 FAERR_SETNEWNOSPAM = -7,
101 FAERR_NOMEM = -8 100 FAERR_NOMEM = -8
@@ -329,7 +328,6 @@ void getaddress(const Messenger *m, uint8_t *address);
329 * return -2 if no message (message length must be >= 1 byte). 328 * return -2 if no message (message length must be >= 1 byte).
330 * return -3 if user's own key. 329 * return -3 if user's own key.
331 * return -4 if friend request already sent or already a friend. 330 * return -4 if friend request already sent or already a friend.
332 * return -5 for unknown error.
333 * return -6 if bad checksum in address. 331 * return -6 if bad checksum in address.
334 * return -7 if the friend was already there but the nospam was different. 332 * return -7 if the friend was already there but the nospam was different.
335 * (the nospam for that friend was set to the new one). 333 * (the nospam for that friend was set to the new one).
@@ -340,7 +338,10 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u
340 338
341/* Add a friend without sending a friendrequest. 339/* Add a friend without sending a friendrequest.
342 * return the friend number if success. 340 * return the friend number if success.
343 * return -1 if failure. 341 * return -3 if user's own key.
342 * return -4 if friend request already sent or already a friend.
343 * return -6 if bad checksum in address.
344 * return -8 if increasing the friend list size fails.
344 */ 345 */
345int32_t m_addfriend_norequest(Messenger *m, const uint8_t *real_pk); 346int32_t m_addfriend_norequest(Messenger *m, const uint8_t *real_pk);
346 347