From 12b19f691072b7cf292329953a9f8516dc6bf0a1 Mon Sep 17 00:00:00 2001 From: Peter Maatman Date: Tue, 30 Jul 2013 17:09:09 +0200 Subject: renamed getname to getfriendname and added a getname function to get the name of our client --- core/Messenger.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'core/Messenger.h') diff --git a/core/Messenger.h b/core/Messenger.h index 7263901c..08f6de2a 100644 --- a/core/Messenger.h +++ b/core/Messenger.h @@ -92,12 +92,16 @@ int m_sendmessage(int friendnumber, uint8_t *message, uint32_t length); return -1 if failure */ int setname(uint8_t *name, uint16_t length); +/* Get our own nickname + Set's name to the our own nickname */ +int getname(uint8_t *name); + /* get name of friendnumber put it in name name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. return 0 if success return -1 if failure */ -int getname(int friendnumber, uint8_t *name); +int getfriendname(int friendnumber, uint8_t *name); /* set our user status you are responsible for freeing status after -- cgit v1.2.3 From 1b4eea2186580bb77c2ad2a13d4263757c192c43 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Tue, 30 Jul 2013 19:38:05 -0400 Subject: Small fixes. --- core/Messenger.c | 10 +++++----- core/Messenger.h | 13 ++++++++----- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'core/Messenger.h') diff --git a/core/Messenger.c b/core/Messenger.c index 641dbf8e..872d7407 100644 --- a/core/Messenger.c +++ b/core/Messenger.c @@ -113,7 +113,7 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length) if (getfriend_id(client_id) != -1) return -3; 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) { DHT_addfriend(client_id); friendlist[i].status = 1; @@ -137,7 +137,7 @@ int m_addfriend_norequest(uint8_t * client_id) if (getfriend_id(client_id) != -1) return -1; 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) { DHT_addfriend(client_id); friendlist[i].status = 2; @@ -167,7 +167,7 @@ int m_delfriend(int friendnumber) memset(&friendlist[friendnumber], 0, sizeof(Friend)); uint32_t i; for (i = numfriends; i != 0; --i) { - if (friendlist[i].status != 0) + if (friendlist[i-1].status != 0) break; } numfriends = i; @@ -181,7 +181,7 @@ int m_delfriend(int friendnumber) return 0 if there is no friend with that number */ int m_friendstatus(int friendnumber) { - if (friendnumber < 0 || friendnumber >= MAX_NUM_FRIENDS) + if (friendnumber < 0 || friendnumber >= numfriends) return 0; return friendlist[friendnumber].status; } @@ -191,7 +191,7 @@ int m_friendstatus(int friendnumber) return 0 if it was not */ 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; 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. */ diff --git a/core/Messenger.h b/core/Messenger.h index 6ab50175..9ce96fb4 100644 --- a/core/Messenger.h +++ b/core/Messenger.h @@ -46,11 +46,14 @@ extern "C" { to an absurdly large number later */ /* 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 failure. */ + 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 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); -- cgit v1.2.3