mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 21:23:01 +01:00
filter escape sequences from all inbound nicks and status messages
This commit is contained in:
parent
1f2bd44dce
commit
9f0daca5eb
@ -1013,9 +1013,10 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
|
||||
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'};
|
||||
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
tox_get_status_message(m, self->num, (uint8_t *) statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
|
||||
int s_len = tox_get_status_message(m, self->num, (uint8_t *) statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
|
||||
pthread_mutex_unlock(&Winthread.lock);
|
||||
|
||||
filter_str(statusmsg, s_len);
|
||||
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
||||
statusbar->statusmsg_len = strlen(statusbar->statusmsg);
|
||||
}
|
||||
@ -1082,8 +1083,10 @@ static void chat_onInit(ToxWindow *self, Tox *m)
|
||||
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'};
|
||||
uint16_t s_len = tox_get_status_message(m, self->num, (uint8_t *) statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
|
||||
statusmsg[s_len] = '\0';
|
||||
|
||||
filter_str(statusmsg, s_len);
|
||||
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
||||
statusbar->statusmsg_len = s_len;
|
||||
statusbar->statusmsg_len = strlen(statusbar->statusmsg);
|
||||
|
||||
char nick[TOX_MAX_NAME_LENGTH + 1];
|
||||
int n_len = get_nick_truncate(m, nick, self->num);
|
||||
|
@ -935,9 +935,11 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
|
||||
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
|
||||
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
tox_get_status_message(m, Friends.list[f].num, (uint8_t *) statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
|
||||
int s_len = tox_get_status_message(m, Friends.list[f].num, (uint8_t *) statusmsg,
|
||||
TOX_MAX_STATUSMESSAGE_LENGTH);
|
||||
pthread_mutex_unlock(&Winthread.lock);
|
||||
|
||||
filter_str(statusmsg, s_len);
|
||||
snprintf(Friends.list[f].statusmsg, sizeof(Friends.list[f].statusmsg), "%s", statusmsg);
|
||||
Friends.list[f].statusmsg_len = strlen(Friends.list[f].statusmsg);
|
||||
}
|
||||
|
@ -140,6 +140,7 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
|
||||
int n_len = tox_group_peername(m, groupnum, peernum, (uint8_t *) nick);
|
||||
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1); /* enforce client max name length */
|
||||
nick[n_len] = '\0';
|
||||
filter_str(nick, n_len);
|
||||
|
||||
char selfnick[TOX_MAX_NAME_LENGTH];
|
||||
uint16_t sn_len = tox_get_self_name(m, (uint8_t *) selfnick);
|
||||
@ -239,12 +240,12 @@ static void copy_peernames(int gnum, uint8_t peerlist[][TOX_MAX_NAME_LENGTH], ui
|
||||
memcpy(&groupchats[gnum].peer_names[i * N], UNKNOWN_NAME, u_len);
|
||||
groupchats[gnum].peer_names[i * N + u_len] = '\0';
|
||||
groupchats[gnum].peer_name_lengths[i] = u_len;
|
||||
|
||||
} else {
|
||||
uint16_t n_len = MIN(lengths[i], TOXIC_MAX_NAME_LENGTH - 1);
|
||||
memcpy(&groupchats[gnum].peer_names[i * N], peerlist[i], n_len);
|
||||
groupchats[gnum].peer_names[i * N + n_len] = '\0';
|
||||
groupchats[gnum].peer_name_lengths[i] = n_len;
|
||||
filter_str((char *) &groupchats[gnum].peer_names[i * N], n_len);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,6 +202,7 @@ int valid_nick(const char *nick)
|
||||
|| nick[i] == '/'
|
||||
|| nick[i] == '\n'
|
||||
|| nick[i] == '\t'
|
||||
|| nick[i] == '\v'
|
||||
|| nick[i] == '\r')
|
||||
|
||||
return 0;
|
||||
@ -211,12 +212,12 @@ int valid_nick(const char *nick)
|
||||
}
|
||||
|
||||
/* Converts all newline/tab chars to spaces (use for strings that should be contained to a single line) */
|
||||
void escape_newline_str(char *str, int len)
|
||||
void filter_str(char *str, int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
if (str[i] == '\n' || str[i] == '\r' || str[i] == '\t')
|
||||
if (str[i] == '\n' || str[i] == '\r' || str[i] == '\t' || str[i] == '\v')
|
||||
str[i] = ' ';
|
||||
}
|
||||
}
|
||||
@ -266,6 +267,7 @@ int get_nick_truncate(Tox *m, char *buf, int friendnum)
|
||||
int len = tox_get_name(m, friendnum, (uint8_t *) buf);
|
||||
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
|
||||
buf[len] = '\0';
|
||||
filter_str(buf, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ int qsort_strcasecmp_hlpr(const void *str1, const void *str2);
|
||||
int valid_nick(const char *nick);
|
||||
|
||||
/* Converts all newline/tab chars to spaces (use for strings that should be contained to a single line) */
|
||||
void escape_newline_str(char *str, int len);
|
||||
void filter_str(char *str, int len);
|
||||
|
||||
/* gets base file name from path or original file name if no path is supplied */
|
||||
void get_file_name(char *namebuf, int bufsize, const char *pathname);
|
||||
|
@ -112,7 +112,7 @@ void on_nickchange(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t
|
||||
{
|
||||
char nick[TOXIC_MAX_NAME_LENGTH + 1];
|
||||
length = copy_tox_str(nick, sizeof(nick), (const char *) string, length);
|
||||
escape_newline_str(nick, length);
|
||||
filter_str(nick, length);
|
||||
|
||||
int i;
|
||||
|
||||
@ -128,7 +128,7 @@ void on_statusmessagechange(Tox *m, int32_t friendnumber, const uint8_t *string,
|
||||
{
|
||||
char msg[TOX_MAX_STATUSMESSAGE_LENGTH + 1];
|
||||
length = copy_tox_str(msg, sizeof(msg), (const char *) string, length);
|
||||
escape_newline_str(msg, length);
|
||||
filter_str(msg, length);
|
||||
|
||||
int i;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user