From 8abc0a346209512901254f981dab62c67a632f4a Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Thu, 1 Aug 2013 15:27:08 -0400 Subject: added error code for no message on friend add & updated nTox.c/nTox_win32.c --- core/Messenger.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'core/Messenger.c') diff --git a/core/Messenger.c b/core/Messenger.c index 49f638df..f8a794ce 100644 --- a/core/Messenger.c +++ b/core/Messenger.c @@ -94,25 +94,31 @@ int getclient_id(int friend_id, uint8_t *client_id) return -1; } -/* add a friend - set the data that will be sent along with friend request - client_id is the client id of the friend - data is the data and length is the length - returns the friend number if success - return -1 if message length is too long - return -2 if user's own key - return -3 if already a friend - return -4 for other*/ +/* + * add a friend + * set the data that will be sent along with friend request + * client_id is the client id of the friend + * data is the data and length is the length + * returns the friend number if success + * return -1 if message length is too long + * return -2 if no message (message length must be >= 1 byte) + * return -3 if user's own key + * return -4 if friend request already sent or already a friend + * return -5 for unknown error + */ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length) { if (length >= (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES)) return -1; - if (memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) + if (length < 1) return -2; - if (getfriend_id(client_id) != -1) + if (memcmp(client_id, self_public_key, crypto_box_PUBLICKEYBYTES) == 0) return -3; + if (getfriend_id(client_id) != -1) + return -4; + uint32_t i; for (i = 0; i <= numfriends; ++i) { /*TODO: dynamic memory allocation, this will segfault if there are more than MAX_NUM_FRIENDS*/ if(friendlist[i].status == 0) { @@ -130,7 +136,7 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length) return i; } } - return -4; + return -5; } int m_addfriend_norequest(uint8_t * client_id) -- cgit v1.2.3