1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-12-23 10:33:25 +01:00

handle errors for name functions

This commit is contained in:
Jfreegman 2014-11-15 22:39:24 -05:00
parent 4238c20e72
commit 141b36af04
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
2 changed files with 16 additions and 5 deletions

View File

@ -288,11 +288,9 @@ static void groupchat_onGroupTitleChange(ToxWindow *self, Tox *m, int groupnum,
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
/* announce title when we join the room */
if (!timed_out(groupchats[self->num].start_time, get_unix_time(), GROUP_EVENT_WAIT)) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Title is set to: %s", title);
/* don't announce title when we join the room */
if (!timed_out(groupchats[self->num].start_time, get_unix_time(), GROUP_EVENT_WAIT))
return;
}
char nick[TOX_MAX_NAME_LENGTH];
get_group_nick_truncate(m, nick, peernum, groupnum);

View File

@ -261,10 +261,17 @@ void str_to_lower(char *str)
}
/* puts friendnum's nick in buf, truncating at TOXIC_MAX_NAME_LENGTH if necessary.
Returns nick len on success, -1 on failure */
if toxcore API call fails, put UNKNOWN_NAME in buf
Returns nick len */
int get_nick_truncate(Tox *m, char *buf, int friendnum)
{
int len = tox_get_name(m, friendnum, (uint8_t *) buf);
if (len == -1) {
strcpy(buf, UNKNOWN_NAME);
len = strlen(UNKNOWN_NAME);
}
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
buf[len] = '\0';
filter_str(buf, len);
@ -275,6 +282,12 @@ int get_nick_truncate(Tox *m, char *buf, int friendnum)
int get_group_nick_truncate(Tox *m, char *buf, int peernum, int groupnum)
{
int len = tox_group_peername(m, groupnum, peernum, (uint8_t *) buf);
if (len == -1) {
strcpy(buf, UNKNOWN_NAME);
len = strlen(UNKNOWN_NAME);
}
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
buf[len] = '\0';
filter_str(buf, len);