Added name lengths to friend names.

This commit is contained in:
irungentoo 2013-09-06 09:45:39 -04:00
parent bb35305d94
commit 7ecd809a59
3 changed files with 11 additions and 8 deletions

View File

@ -399,7 +399,7 @@ uint16_t getself_name(Messenger *m, uint8_t *name, uint16_t nlen)
/* Get name of friendnumber and put it in name.
* name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes.
*
* return 0 if success.
* return length of name if success.
* return -1 if failure.
*/
int getname(Messenger *m, int friendnumber, uint8_t *name)
@ -407,8 +407,8 @@ int getname(Messenger *m, int friendnumber, uint8_t *name)
if (friend_not_valid(m, friendnumber))
return -1;
memcpy(name, m->friendlist[friendnumber].name, MAX_NAME_LENGTH);
return 0;
memcpy(name, m->friendlist[friendnumber].name, m->friendlist[friendnumber].name_length);
return m->friendlist[friendnumber].name_length;
}
int m_set_statusmessage(Messenger *m, uint8_t *status, uint16_t length)
@ -799,11 +799,13 @@ void doFriends(Messenger *m)
if (data_length >= MAX_NAME_LENGTH || data_length == 0)
break;
if (m->friend_namechange)
m->friend_namechange(m, i, data, data_length, m->friend_namechange_userdata);
memcpy(m->friendlist[i].name, data, data_length);
m->friendlist[i].name_length = data_length;
m->friendlist[i].name[data_length - 1] = 0; /* Make sure the NULL terminator is present. */
if (m->friend_namechange)
m->friend_namechange(m, i, m->friendlist[i].name, data_length, m->friend_namechange_userdata);
break;
}

View File

@ -101,6 +101,7 @@ typedef struct {
uint8_t status; // 0 if no friend, 1 if added, 2 if friend request sent, 3 if confirmed friend, 4 if online.
uint8_t info[MAX_DATA_SIZE]; // the data that is sent during the friend requests we do.
uint8_t name[MAX_NAME_LENGTH];
uint16_t name_length;
uint8_t name_sent; // 0 if we didn't send our name to this friend 1 if we have.
uint8_t *statusmessage;
uint16_t statusmessage_length;
@ -253,7 +254,7 @@ uint16_t getself_name(Messenger *m, uint8_t *name, uint16_t nlen);
/* Get name of friendnumber and 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 length of name if success.
* return -1 if failure.
*/
int getname(Messenger *m, int friendnumber, uint8_t *name);

View File

@ -182,7 +182,7 @@ uint16_t tox_getselfname(Tox *tox, uint8_t *name, uint16_t nlen);
/* Get name of friendnumber and 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 length of name (with the NULL terminator) if success.
* return -1 if failure.
*/
int tox_getname(Tox *tox, int friendnumber, uint8_t *name);