Small fixes.

This commit is contained in:
irungentoo 2013-07-30 19:38:05 -04:00
parent f6d508735a
commit 1b4eea2186
2 changed files with 13 additions and 10 deletions

View File

@ -113,7 +113,7 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length)
if (getfriend_id(client_id) != -1) if (getfriend_id(client_id) != -1)
return -3; return -3;
uint32_t i; uint32_t i;
for (i = 0; i <= numfriends; ++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) { if(friendlist[i].status == 0) {
DHT_addfriend(client_id); DHT_addfriend(client_id);
friendlist[i].status = 1; friendlist[i].status = 1;
@ -137,7 +137,7 @@ int m_addfriend_norequest(uint8_t * client_id)
if (getfriend_id(client_id) != -1) if (getfriend_id(client_id) != -1)
return -1; return -1;
uint32_t i; uint32_t i;
for (i = 0; i <= numfriends; ++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) { if(friendlist[i].status == 0) {
DHT_addfriend(client_id); DHT_addfriend(client_id);
friendlist[i].status = 2; friendlist[i].status = 2;
@ -167,7 +167,7 @@ int m_delfriend(int friendnumber)
memset(&friendlist[friendnumber], 0, sizeof(Friend)); memset(&friendlist[friendnumber], 0, sizeof(Friend));
uint32_t i; uint32_t i;
for (i = numfriends; i != 0; --i) { for (i = numfriends; i != 0; --i) {
if (friendlist[i].status != 0) if (friendlist[i-1].status != 0)
break; break;
} }
numfriends = i; numfriends = i;
@ -181,7 +181,7 @@ int m_delfriend(int friendnumber)
return 0 if there is no friend with that number */ return 0 if there is no friend with that number */
int m_friendstatus(int friendnumber) int m_friendstatus(int friendnumber)
{ {
if (friendnumber < 0 || friendnumber >= MAX_NUM_FRIENDS) if (friendnumber < 0 || friendnumber >= numfriends)
return 0; return 0;
return friendlist[friendnumber].status; return friendlist[friendnumber].status;
} }
@ -191,7 +191,7 @@ int m_friendstatus(int friendnumber)
return 0 if it was not */ return 0 if it was not */
int m_sendmessage(int friendnumber, uint8_t *message, uint32_t length) int m_sendmessage(int friendnumber, uint8_t *message, uint32_t length)
{ {
if (friendnumber < 0 || friendnumber >= MAX_NUM_FRIENDS) if (friendnumber < 0 || friendnumber >= numfriends)
return 0; return 0;
if (length >= MAX_DATA_SIZE || friendlist[friendnumber].status != 4) if (length >= MAX_DATA_SIZE || friendlist[friendnumber].status != 4)
/* this does not mean the maximum message length is MAX_DATA_SIZE - 1, it is actually 17 bytes less. */ /* this does not mean the maximum message length is MAX_DATA_SIZE - 1, it is actually 17 bytes less. */

View File

@ -46,11 +46,14 @@ extern "C" {
to an absurdly large number later */ to an absurdly large number later */
/* add a friend /* add a friend
set the data that will be sent along with friend request set the data that will be sent along with friend request
client_id is the client id of the friend client_id is the client id of the friend
data is the data and length is the length data is the data and length is the length
returns the friend number if success returns the friend number if success
return -1 if failure. */ return -1 if key length is wrong.
return -2 if user's own key
return -3 if already a friend
return -4 for other*/
int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length); int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length);