Messenger add friends functions error code fixes.

Removed unknown error.

norequest function now returns proper error codes.
This commit is contained in:
irungentoo 2015-02-17 10:29:18 -05:00
parent 3f11d106da
commit 99ee86b865
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
2 changed files with 10 additions and 16 deletions

View File

@ -194,7 +194,7 @@ static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t sta
int friendcon_id = new_friend_connection(m->fr_c, real_pk);
if (friendcon_id == -1)
return FAERR_UNKNOWN;
return FAERR_NOMEM;
uint32_t i;
@ -227,7 +227,7 @@ static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t sta
}
}
return FAERR_UNKNOWN;
return FAERR_NOMEM;
}
/*
@ -241,7 +241,6 @@ static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t sta
* return FAERR_NOMESSAGE if no message (message length must be >= 1 byte).
* return FAERR_OWNKEY if user's own key.
* return FAERR_ALREADYSENT if friend request already sent or already a friend.
* return FAERR_UNKNOWN for unknown error.
* return FAERR_BADCHECKSUM if bad checksum in address.
* return FAERR_SETNEWNOSPAM if the friend was already there but the nospam was different.
* (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
int32_t m_addfriend_norequest(Messenger *m, const uint8_t *real_pk)
{
if (getfriend_id(m, real_pk) != -1)
return -1;
return FAERR_ALREADYSENT;
if (!public_key_valid(real_pk))
return -1;
return FAERR_BADCHECKSUM;
if (id_equal(real_pk, m->net_crypto->self_public_key))
return -1;
return FAERR_OWNKEY;
int32_t ret = init_new_friend(m, real_pk, FRIEND_CONFIRMED);
if (ret < 0) {
return -1;
} else {
return ret;
}
return init_new_friend(m, real_pk, FRIEND_CONFIRMED);
}
/* Remove a friend.

View File

@ -95,7 +95,6 @@ enum {
FAERR_NOMESSAGE = -2,
FAERR_OWNKEY = -3,
FAERR_ALREADYSENT = -4,
FAERR_UNKNOWN = -5,
FAERR_BADCHECKSUM = -6,
FAERR_SETNEWNOSPAM = -7,
FAERR_NOMEM = -8
@ -329,7 +328,6 @@ void getaddress(const Messenger *m, uint8_t *address);
* 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.
* return -6 if bad checksum in address.
* return -7 if the friend was already there but the nospam was different.
* (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
/* Add a friend without sending a friendrequest.
* return the friend number if success.
* return -1 if failure.
* return -3 if user's own key.
* return -4 if friend request already sent or already a friend.
* return -6 if bad checksum in address.
* return -8 if increasing the friend list size fails.
*/
int32_t m_addfriend_norequest(Messenger *m, const uint8_t *real_pk);