mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-13 02:03:03 +01:00
don't send null terminated strings, and null terminate all incoming strings
This commit is contained in:
parent
15815bf4bb
commit
3b7e161149
56
src/chat.c
56
src/chat.c
@ -119,11 +119,15 @@ static void chat_onMessage(ToxWindow *self, Tox *m, int32_t num, uint8_t *msg, u
|
||||
if (self->num != num)
|
||||
return;
|
||||
|
||||
msg[len] = '\0';
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_get_name(m, num, nick);
|
||||
nick[TOXIC_MAX_NAME_LENGTH] = '\0';
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH];
|
||||
uint16_t n_len = tox_get_name(m, num, nick);
|
||||
|
||||
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH);
|
||||
nick[n_len] = '\0';
|
||||
|
||||
uint8_t timefrmt[TIME_STR_SIZE];
|
||||
get_time_str(timefrmt);
|
||||
@ -163,11 +167,16 @@ static void chat_onAction(ToxWindow *self, Tox *m, int32_t num, uint8_t *action,
|
||||
if (self->num != num)
|
||||
return;
|
||||
|
||||
|
||||
action[len] = '\0';
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_get_name(m, num, nick);
|
||||
nick[TOXIC_MAX_NAME_LENGTH] = '\0';
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH];
|
||||
int n_len = tox_get_name(m, num, nick);
|
||||
|
||||
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH);;
|
||||
nick[n_len] = '\0';
|
||||
|
||||
uint8_t timefrmt[TIME_STR_SIZE];
|
||||
get_time_str(timefrmt);
|
||||
@ -182,10 +191,9 @@ static void chat_onNickChange(ToxWindow *self, Tox *m, int32_t num, uint8_t *nic
|
||||
if (self->num != num)
|
||||
return;
|
||||
|
||||
nick[TOXIC_MAX_NAME_LENGTH] = '\0';
|
||||
len = strlen(nick) + 1;
|
||||
len = MIN(len, TOXIC_MAX_NAME_LENGTH);
|
||||
nick[len] = '\0';
|
||||
strcpy(self->name, nick);
|
||||
self->name[len-1] = '\0';
|
||||
}
|
||||
|
||||
static void chat_onStatusChange(ToxWindow *self, Tox *m, int32_t num, uint8_t status)
|
||||
@ -205,7 +213,7 @@ static void chat_onStatusMessageChange(ToxWindow *self, int32_t num, uint8_t *st
|
||||
StatusBar *statusbar = self->stb;
|
||||
statusbar->statusmsg_len = len;
|
||||
strcpy(statusbar->statusmsg, status);
|
||||
statusbar->statusmsg[len-1] = '\0';
|
||||
statusbar->statusmsg[len] = '\0';
|
||||
}
|
||||
|
||||
static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum,
|
||||
@ -485,14 +493,15 @@ static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t *acti
|
||||
return;
|
||||
|
||||
uint8_t selfname[TOX_MAX_NAME_LENGTH];
|
||||
tox_get_self_name(m, selfname);
|
||||
uint16_t len = tox_get_self_name(m, selfname);
|
||||
selfname[len] = '\0';
|
||||
|
||||
uint8_t timefrmt[TIME_STR_SIZE];
|
||||
get_time_str(timefrmt);
|
||||
|
||||
line_info_add(self, timefrmt, selfname, NULL, action, ACTION, 0, 0);
|
||||
|
||||
if (tox_send_action(m, self->num, action, strlen(action) + 1) == 0) {
|
||||
if (tox_send_action(m, self->num, action, strlen(action)) == 0) {
|
||||
uint8_t *errmsg = " * Failed to send action.";
|
||||
line_info_add(self, NULL, selfname, NULL, errmsg, SYS_MSG, 0, RED);
|
||||
} else {
|
||||
@ -675,14 +684,15 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
||||
}
|
||||
} else if (!string_is_empty(line)) {
|
||||
uint8_t selfname[TOX_MAX_NAME_LENGTH];
|
||||
tox_get_self_name(m, selfname);
|
||||
uint16_t len = tox_get_self_name(m, selfname);
|
||||
selfname[len] = '\0';
|
||||
|
||||
uint8_t timefrmt[TIME_STR_SIZE];
|
||||
get_time_str(timefrmt);
|
||||
|
||||
line_info_add(self, timefrmt, selfname, NULL, line, OUT_MSG, 0, 0);
|
||||
|
||||
if (!statusbar->is_online || tox_send_message(m, self->num, line, strlen(line) + 1) == 0) {
|
||||
if (!statusbar->is_online || tox_send_message(m, self->num, line, strlen(line)) == 0) {
|
||||
uint8_t *errmsg = " * Failed to send message.";
|
||||
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED);
|
||||
} else {
|
||||
@ -782,10 +792,12 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
|
||||
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'};
|
||||
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
tox_get_status_message(m, self->num, statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
|
||||
uint16_t s_len = tox_get_status_message(m, self->num, statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
|
||||
pthread_mutex_unlock(&Winthread.lock);
|
||||
statusmsg[s_len] = '\0';
|
||||
|
||||
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
||||
statusbar->statusmsg_len = tox_get_status_message_size(m, self->num);
|
||||
statusbar->statusmsg_len = s_len;
|
||||
}
|
||||
|
||||
self->x = x2;
|
||||
@ -827,9 +839,10 @@ static void chat_onInit(ToxWindow *self, Tox *m)
|
||||
statusbar->is_online = tox_get_friend_connection_status(m, self->num) == 1;
|
||||
|
||||
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'};
|
||||
tox_get_status_message(m, self->num, statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
|
||||
uint16_t s_len = tox_get_status_message(m, self->num, statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
|
||||
statusmsg[s_len] = '\0';
|
||||
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
||||
statusbar->statusmsg_len = tox_get_status_message_size(m, self->num);
|
||||
statusbar->statusmsg_len = s_len;
|
||||
|
||||
/* Init subwindows */
|
||||
ChatContext *ctx = self->chatwin;
|
||||
@ -901,8 +914,11 @@ ToxWindow new_chat(Tox *m, int32_t friendnum)
|
||||
|
||||
uint8_t name[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
uint16_t len = tox_get_name(m, friendnum, name);
|
||||
memcpy(ret.name, name, len);
|
||||
ret.name[TOXIC_MAX_NAME_LENGTH] = '\0';
|
||||
|
||||
len = MIN(len, TOXIC_MAX_NAME_LENGTH);
|
||||
|
||||
name[len] = '\0';
|
||||
strcpy(ret.name, name);
|
||||
|
||||
ChatContext *chatwin = calloc(1, sizeof(ChatContext));
|
||||
memset(chatwin, 0, sizeof(ChatContext));
|
||||
|
@ -102,9 +102,13 @@ static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, uint8_t *
|
||||
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
||||
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
|
||||
} else {
|
||||
str[len] = '\0';
|
||||
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_get_name(m, num, nick);
|
||||
nick[TOXIC_MAX_NAME_LENGTH] = '\0';
|
||||
uint16_t n_len = tox_get_name(m, num, nick);
|
||||
|
||||
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH);
|
||||
nick[n_len] = '\0';
|
||||
|
||||
uint8_t timefrmt[TIME_STR_SIZE];
|
||||
get_time_str(timefrmt);
|
||||
@ -134,10 +138,10 @@ static void friendlist_onNickChange(ToxWindow *self, Tox *m, int32_t num, uint8_
|
||||
if (len > TOX_MAX_NAME_LENGTH || num >= max_friends_index)
|
||||
return;
|
||||
|
||||
str[TOXIC_MAX_NAME_LENGTH] = '\0';
|
||||
len = MIN(len, TOXIC_MAX_NAME_LENGTH);
|
||||
|
||||
str[len] = '\0';
|
||||
strcpy(friends[num].name, str);
|
||||
len = strlen(str) + 1;
|
||||
friends[num].name[len-1] = '\0';
|
||||
friends[num].namelength = len;
|
||||
sort_friendlist_index();
|
||||
}
|
||||
@ -156,7 +160,7 @@ static void friendlist_onStatusMessageChange(ToxWindow *self, int32_t num, uint8
|
||||
return;
|
||||
|
||||
strcpy(friends[num].statusmsg, str);
|
||||
friends[num].statusmsg[len-1] = '\0';
|
||||
friends[num].statusmsg[len] = '\0';
|
||||
friends[num].statusmsg_len = len;
|
||||
}
|
||||
|
||||
@ -180,10 +184,10 @@ void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int32_t num, bool sort)
|
||||
|
||||
if (friends[i].namelength == -1 || friends[i].name[0] == '\0') {
|
||||
strcpy(friends[i].name, (uint8_t *) UNKNOWN_NAME);
|
||||
friends[i].namelength = strlen(UNKNOWN_NAME) + 1;
|
||||
friends[i].namelength = strlen(UNKNOWN_NAME);
|
||||
} else { /* Enforce toxic's maximum name length */
|
||||
friends[i].name[TOXIC_MAX_NAME_LENGTH] = '\0';
|
||||
friends[i].namelength = strlen(friends[i].name) + 1;
|
||||
friends[i].namelength = MIN(friends[i].namelength, TOXIC_MAX_NAME_LENGTH);
|
||||
friends[i].name[friends[i].namelength] = '\0';
|
||||
}
|
||||
|
||||
num_friends = tox_count_friendlist(m);
|
||||
@ -211,9 +215,9 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, u
|
||||
} else {
|
||||
tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
|
||||
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_get_name(m, num, nick);
|
||||
nick[TOXIC_MAX_NAME_LENGTH] = '\0';
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH];
|
||||
uint16_t n_len = tox_get_name(m, num, nick);
|
||||
nick[n_len] = '\0';
|
||||
|
||||
uint8_t msg[MAX_STR_SIZE];
|
||||
snprintf(msg, sizeof(msg), "* File transfer from %s failed: too many windows are open.", nick);
|
||||
@ -233,9 +237,9 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, uint8
|
||||
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
||||
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
|
||||
} else {
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_get_name(m, num, nick);
|
||||
nick[TOXIC_MAX_NAME_LENGTH] = '\0';
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH];
|
||||
uint16_t n_len = tox_get_name(m, num, nick);
|
||||
nick[n_len] = '\0';
|
||||
|
||||
uint8_t msg[MAX_STR_SIZE];
|
||||
snprintf(msg, sizeof(msg), "* Group chat invite from %s failed: too many windows are open.", nick);
|
||||
@ -456,10 +460,12 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
|
||||
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'};
|
||||
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
tox_get_status_message(m, friends[f].num, statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
|
||||
friends[f].statusmsg_len = tox_get_status_message_size(m, f);
|
||||
uint16_t s_len = tox_get_status_message(m, friends[f].num, statusmsg,
|
||||
TOX_MAX_STATUSMESSAGE_LENGTH);
|
||||
pthread_mutex_unlock(&Winthread.lock);
|
||||
|
||||
friends[f].statusmsg_len = s_len;
|
||||
friends[f].statusmsg[s_len] = '\0';
|
||||
snprintf(friends[f].statusmsg, sizeof(friends[f].statusmsg), "%s", statusmsg);
|
||||
}
|
||||
|
||||
@ -538,8 +544,10 @@ static void friendlist_onAv(ToxWindow *self, ToxAv *av)
|
||||
friends[id].chatwin = add_window(m, new_chat(m, friends[id].num));
|
||||
} else {
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_get_name(m, id, nick);
|
||||
nick[TOXIC_MAX_NAME_LENGTH] = '\0';
|
||||
uint16_t n_len = tox_get_name(m, id, nick);
|
||||
|
||||
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH);
|
||||
nick[n_len] = '\0';
|
||||
|
||||
uint8_t msg[MAX_STR_SIZE];
|
||||
snprintf(msg, sizeof(msg), "Audio action from: %s!", nick);
|
||||
|
@ -114,7 +114,8 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
|
||||
snprintf(msg, sizeof(msg), "%s", temp);
|
||||
} else {
|
||||
uint8_t selfname[TOX_MAX_NAME_LENGTH];
|
||||
tox_get_self_name(m, selfname);
|
||||
uint16_t n_len = tox_get_self_name(m, selfname);
|
||||
selfname[n_len] = '\0';
|
||||
snprintf(msg, sizeof(msg), "Hello, my name is %s. Care to Tox?", selfname);
|
||||
}
|
||||
|
||||
@ -147,7 +148,7 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
|
||||
id[i] = toupper(id[i]);
|
||||
}
|
||||
|
||||
int32_t f_num = tox_add_friend(m, id_bin, msg, strlen(msg) + 1);
|
||||
int32_t f_num = tox_add_friend(m, id_bin, msg, strlen(msg));
|
||||
|
||||
switch (f_num) {
|
||||
case TOX_FAERR_TOOLONG:
|
||||
@ -334,13 +335,13 @@ void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
|
||||
return;
|
||||
}
|
||||
|
||||
if (len >= TOXIC_MAX_NAME_LENGTH) {
|
||||
if (len >= TOXIC_MAX_NAME_LENGTH)
|
||||
len = TOXIC_MAX_NAME_LENGTH;
|
||||
nick[len-1] = L'\0';
|
||||
}
|
||||
|
||||
tox_set_name(m, nick, len+1);
|
||||
prompt_update_nick(prompt, nick, len+1);
|
||||
nick[len] = L'\0';
|
||||
|
||||
tox_set_name(m, nick, len);
|
||||
prompt_update_nick(prompt, nick, len);
|
||||
|
||||
store_data(m, DATA_FILE);
|
||||
}
|
||||
@ -364,9 +365,8 @@ void cmd_note(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
|
||||
}
|
||||
|
||||
msg[strlen(++msg)-1] = L'\0';
|
||||
uint16_t len = strlen(msg) + 1;
|
||||
uint16_t len = strlen(msg);
|
||||
tox_set_status_message(m, msg, len);
|
||||
|
||||
prompt_update_statusmessage(prompt, msg, len);
|
||||
}
|
||||
|
||||
@ -468,7 +468,7 @@ void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
|
||||
|
||||
if (msg != NULL) {
|
||||
msg[strlen(++msg)-1] = L'\0'; /* remove opening and closing quotes */
|
||||
uint16_t len = strlen(msg) + 1;
|
||||
uint16_t len = strlen(msg);
|
||||
tox_set_status_message(m, msg, len);
|
||||
prompt_update_statusmessage(prompt, msg, len);
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum)
|
||||
groupchats[i].num_peers = 0;
|
||||
groupchats[i].peer_names = malloc(sizeof(uint8_t) * TOX_MAX_NAME_LENGTH);
|
||||
groupchats[i].oldpeer_names = malloc(sizeof(uint8_t) * TOX_MAX_NAME_LENGTH);
|
||||
groupchats[i].peer_name_lengths = malloc(sizeof(uint16_t));
|
||||
|
||||
/* temp fix */
|
||||
memcpy(&groupchats[i].oldpeer_names[0], UNKNOWN_NAME, sizeof(UNKNOWN_NAME));
|
||||
@ -93,6 +94,7 @@ static void close_groupchat(ToxWindow *self, Tox *m, int groupnum)
|
||||
|
||||
free(groupchats[groupnum].peer_names);
|
||||
free(groupchats[groupnum].oldpeer_names);
|
||||
free(groupchats[groupnum].peer_name_lengths);
|
||||
memset(&groupchats[groupnum], 0, sizeof(GroupChat));
|
||||
|
||||
int i;
|
||||
@ -152,18 +154,24 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
|
||||
if (self->num != groupnum)
|
||||
return;
|
||||
|
||||
msg[len] = '\0';
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_group_peername(m, groupnum, peernum, nick);
|
||||
nick[TOXIC_MAX_NAME_LENGTH] = '\0'; /* enforce client max name length */
|
||||
uint16_t n_len = tox_group_peername(m, groupnum, peernum, nick);
|
||||
|
||||
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH); /* enforce client max name length */
|
||||
nick[n_len] = '\0';
|
||||
|
||||
/* check if message contains own name and alert appropriately */
|
||||
int alert_type = WINDOW_ALERT_1;
|
||||
bool beep = false;
|
||||
|
||||
uint8_t selfnick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_get_self_name(m, selfnick);
|
||||
uint8_t selfnick[TOX_MAX_NAME_LENGTH];
|
||||
n_len = tox_get_self_name(m, selfnick);
|
||||
selfnick[n_len] = '\0';
|
||||
|
||||
int nick_clr = strcmp(nick, selfnick) == 0 ? GREEN : CYAN;
|
||||
|
||||
bool nick_match = strcasestr(msg, selfnick) && strncmp(selfnick, nick, TOXIC_MAX_NAME_LENGTH);
|
||||
@ -189,14 +197,17 @@ static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int p
|
||||
if (self->num != groupnum)
|
||||
return;
|
||||
|
||||
action[len] = '\0';
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
/* check if message contains own name and alert appropriately */
|
||||
int alert_type = WINDOW_ALERT_1;
|
||||
bool beep = false;
|
||||
|
||||
uint8_t selfnick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_get_self_name(m, selfnick);
|
||||
uint8_t selfnick[TOX_MAX_NAME_LENGTH];
|
||||
uint16_t n_len = tox_get_self_name(m, selfnick);
|
||||
selfnick[n_len] = '\0';
|
||||
|
||||
bool nick_match = strcasestr(action, selfnick);
|
||||
|
||||
@ -208,8 +219,10 @@ static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int p
|
||||
alert_window(self, alert_type, beep);
|
||||
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_group_peername(m, groupnum, peernum, nick);
|
||||
nick[TOXIC_MAX_NAME_LENGTH] = '\0'; /* enforce client max name length */
|
||||
n_len = tox_group_peername(m, groupnum, peernum, nick);
|
||||
|
||||
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH);
|
||||
nick[n_len] = '\0';
|
||||
|
||||
uint8_t timefrmt[TIME_STR_SIZE];
|
||||
get_time_str(timefrmt);
|
||||
@ -218,36 +231,50 @@ static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int p
|
||||
write_to_log(action, nick, ctx->log, true);
|
||||
}
|
||||
|
||||
/* Puts two copies of peerlist in chat instance */
|
||||
static void copy_peernames(int gnum, int npeers, uint8_t tmp_peerlist[][TOX_MAX_NAME_LENGTH])
|
||||
/* Puts two copies of peerlist/lengths in chat instance */
|
||||
static void copy_peernames(int gnum, uint8_t peerlist[][TOX_MAX_NAME_LENGTH], uint16_t lengths[], int npeers)
|
||||
{
|
||||
/* Assumes these are initiated in init_groupchat_win */
|
||||
free(groupchats[gnum].peer_names);
|
||||
free(groupchats[gnum].oldpeer_names);
|
||||
free(groupchats[gnum].peer_name_lengths);
|
||||
free(groupchats[gnum].oldpeer_name_lengths);
|
||||
|
||||
int N = TOX_MAX_NAME_LENGTH;
|
||||
|
||||
groupchats[gnum].peer_names = malloc(sizeof(uint8_t) * npeers * N);
|
||||
groupchats[gnum].oldpeer_names = malloc(sizeof(uint8_t) * npeers * N);
|
||||
groupchats[gnum].peer_name_lengths = malloc(sizeof(uint16_t) * npeers);
|
||||
groupchats[gnum].oldpeer_name_lengths = malloc(sizeof(uint16_t) * npeers);
|
||||
|
||||
if (groupchats[gnum].peer_names == NULL || groupchats[gnum].oldpeer_names == NULL) {
|
||||
if (groupchats[gnum].peer_names == NULL || groupchats[gnum].oldpeer_names == NULL
|
||||
|| groupchats[gnum].peer_name_lengths == NULL || groupchats[gnum].oldpeer_name_lengths == NULL) {
|
||||
endwin();
|
||||
fprintf(stderr, "malloc() failed. Aborting...\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
uint16_t unknown_len = strlen(UNKNOWN_NAME);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < npeers; ++i) {
|
||||
if (string_is_empty(tmp_peerlist[i])) {
|
||||
if (string_is_empty(peerlist[i])) {
|
||||
memcpy(&groupchats[gnum].peer_names[i*N], UNKNOWN_NAME, sizeof(UNKNOWN_NAME));
|
||||
groupchats[gnum].peer_name_lengths[i] = unknown_len;
|
||||
} else {
|
||||
memcpy(&groupchats[gnum].peer_names[i*N], tmp_peerlist[i], N);
|
||||
groupchats[gnum].peer_names[i*N+TOXIC_MAX_NAME_LENGTH] = '\0';
|
||||
memcpy(&groupchats[gnum].peer_names[i*N], peerlist[i], N);
|
||||
uint16_t n_len = lengths[i];
|
||||
|
||||
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH);
|
||||
|
||||
groupchats[gnum].peer_names[i*N+n_len] = '\0';
|
||||
groupchats[gnum].peer_name_lengths[i] = n_len;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(groupchats[gnum].oldpeer_names, groupchats[gnum].peer_names, N*npeers);
|
||||
memcpy(groupchats[gnum].oldpeer_name_lengths, groupchats[gnum].peer_name_lengths,
|
||||
sizeof(uint16_t) * npeers);
|
||||
}
|
||||
|
||||
static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnum, int peernum,
|
||||
@ -260,20 +287,26 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
|
||||
int num_peers = groupchats[groupnum].num_peers;
|
||||
|
||||
/* get old peer name before updating name list */
|
||||
uint8_t oldpeername[TOX_MAX_NAME_LENGTH] = {0};
|
||||
uint8_t oldpeername[TOX_MAX_NAME_LENGTH];
|
||||
|
||||
if (change != TOX_CHAT_CHANGE_PEER_ADD)
|
||||
if (change != TOX_CHAT_CHANGE_PEER_ADD) {
|
||||
memcpy(oldpeername, &groupchats[groupnum].oldpeer_names[peernum*TOX_MAX_NAME_LENGTH],
|
||||
sizeof(oldpeername));
|
||||
uint16_t old_n_len = groupchats[groupnum].oldpeer_name_lengths[peernum];
|
||||
oldpeername[old_n_len] = '\0';
|
||||
}
|
||||
|
||||
/* Update name lists */
|
||||
/* Update name/len lists */
|
||||
uint8_t tmp_peerlist[num_peers][TOX_MAX_NAME_LENGTH];
|
||||
tox_group_get_names(m, groupnum, tmp_peerlist, num_peers);
|
||||
copy_peernames(groupnum, num_peers, tmp_peerlist);
|
||||
uint16_t tmp_peerlens[num_peers];
|
||||
tox_group_get_names(m, groupnum, tmp_peerlist, tmp_peerlens, num_peers);
|
||||
copy_peernames(groupnum, tmp_peerlist, tmp_peerlens, num_peers);
|
||||
|
||||
/* get current peername then sort namelist */
|
||||
uint8_t peername[TOX_MAX_NAME_LENGTH] = {0};
|
||||
uint8_t peername[TOX_MAX_NAME_LENGTH];
|
||||
uint16_t n_len = groupchats[groupnum].peer_name_lengths[peernum];
|
||||
memcpy(peername, &groupchats[groupnum].peer_names[peernum*TOX_MAX_NAME_LENGTH], sizeof(peername));
|
||||
peername[n_len] = '\0';
|
||||
|
||||
qsort(groupchats[groupnum].peer_names, groupchats[groupnum].num_peers, TOX_MAX_NAME_LENGTH, qsort_strcasecmp_hlpr);
|
||||
|
||||
@ -319,7 +352,7 @@ static void send_group_action(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t
|
||||
return;
|
||||
}
|
||||
|
||||
if (tox_group_action_send(m, self->num, action, strlen(action) + 1) == -1) {
|
||||
if (tox_group_action_send(m, self->num, action, strlen(action)) == -1) {
|
||||
uint8_t *errmsg = " * Failed to send action.";
|
||||
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED);
|
||||
}
|
||||
@ -517,7 +550,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
||||
execute(ctx->history, self, m, line, GROUPCHAT_COMMAND_MODE);
|
||||
}
|
||||
} else if (!string_is_empty(line)) {
|
||||
if (tox_group_message_send(m, self->num, line, strlen(line) + 1) == -1) {
|
||||
if (tox_group_message_send(m, self->num, line, strlen(line)) == -1) {
|
||||
uint8_t *errmsg = " * Failed to send message.";
|
||||
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED);
|
||||
}
|
||||
|
@ -28,8 +28,10 @@ typedef struct {
|
||||
bool active;
|
||||
int num_peers;
|
||||
int side_pos; /* current position of the sidebar - used for scrolling up and down */
|
||||
uint8_t *peer_names;
|
||||
uint8_t *oldpeer_names;
|
||||
uint8_t *peer_names;
|
||||
uint8_t *oldpeer_names;
|
||||
uint16_t *peer_name_lengths;
|
||||
uint16_t *oldpeer_name_lengths;
|
||||
} GroupChat;
|
||||
|
||||
void kill_groupchat_window(ToxWindow *self);
|
||||
|
@ -20,7 +20,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define MAX_HISTORY 1000
|
||||
#define MAX_HISTORY 100
|
||||
|
||||
enum {
|
||||
SYS_MSG,
|
||||
|
12
src/main.c
12
src/main.c
@ -157,20 +157,20 @@ static Tox *init_tox(int ipv4)
|
||||
tox_callback_file_data(m, on_file_data, NULL);
|
||||
|
||||
#ifdef __linux__
|
||||
tox_set_name(m, (uint8_t *) "Cool guy", sizeof("Cool guy"));
|
||||
tox_set_name(m, (uint8_t *) "Cool guy", strlen("Cool guy"));
|
||||
#elif defined(_WIN32)
|
||||
tox_set_name(m, (uint8_t *) "I should install GNU/Linux", sizeof("I should install GNU/Linux"));
|
||||
tox_set_name(m, (uint8_t *) "I should install GNU/Linux", strlen("I should install GNU/Linux"));
|
||||
#elif defined(__APPLE__)
|
||||
tox_set_name(m, (uint8_t *) "Hipster", sizeof("Hipster")); /* This used to users of other Unixes are hipsters */
|
||||
tox_set_name(m, (uint8_t *) "Hipster", strlen("Hipster")); /* This used to users of other Unixes are hipsters */
|
||||
#else
|
||||
tox_set_name(m, (uint8_t *) "Registered Minix user #4", sizeof("Registered Minix user #4"));
|
||||
tox_set_name(m, (uint8_t *) "Registered Minix user #4", strlen("Registered Minix user #4"));
|
||||
#endif
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
#define MINLINE 50 /* IP: 7 + port: 5 + key: 38 + spaces: 2 = 70. ! (& e.g. tox.im = 6) */
|
||||
#define MAXLINE 256 /* Approx max number of chars in a sever line (name + port + key) */
|
||||
#define MINLINE 50 /* IP: 7 + port: 5 + key: 38 + spaces: 2 = 70. ! (& e.g. tox.im = 6) */
|
||||
#define MAXLINE 256 /* Approx max number of chars in a sever line (name + port + key) */
|
||||
#define MAXNODES 50
|
||||
#define NODELEN (MAXLINE - TOX_CLIENT_ID_SIZE - 7)
|
||||
|
||||
|
21
src/prompt.c
21
src/prompt.c
@ -395,8 +395,8 @@ static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int32_t friendnum
|
||||
|
||||
static void prompt_onFriendRequest(ToxWindow *self, Tox *m, uint8_t *key, uint8_t *data, uint16_t length)
|
||||
{
|
||||
/* make sure message data is null-terminated */
|
||||
data[length - 1] = 0;
|
||||
data[length] = '\0';
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
uint8_t timefrmt[TIME_STR_SIZE];
|
||||
@ -431,27 +431,32 @@ void prompt_init_statusbar(ToxWindow *self, Tox *m)
|
||||
statusbar->status = TOX_USERSTATUS_NONE;
|
||||
statusbar->is_online = false;
|
||||
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH];
|
||||
uint8_t statusmsg[MAX_STR_SIZE];
|
||||
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
tox_get_self_name(m, nick);
|
||||
tox_get_self_status_message(m, statusmsg, MAX_STR_SIZE);
|
||||
uint16_t n_len = tox_get_self_name(m, nick);
|
||||
uint16_t s_len = tox_get_self_status_message(m, statusmsg, MAX_STR_SIZE);
|
||||
uint8_t status = tox_get_self_user_status(m);
|
||||
pthread_mutex_unlock(&Winthread.lock);
|
||||
|
||||
snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick);
|
||||
nick[n_len] = '\0';
|
||||
statusmsg[s_len] = '\0';
|
||||
|
||||
/* load prev status message or show toxic version if it has never been set */
|
||||
uint8_t ver[strlen(TOXICVER) + 1];
|
||||
strcpy(ver, TOXICVER);
|
||||
const uint8_t *toxic_ver = strtok(ver, "_");
|
||||
|
||||
if ( (!strcmp("Online", statusmsg) || !strncmp("Toxing on Toxic", statusmsg, 15)) && toxic_ver != NULL)
|
||||
if ( (!strcmp("Online", statusmsg) || !strncmp("Toxing on Toxic", statusmsg, 15)) && toxic_ver != NULL) {
|
||||
snprintf(statusmsg, MAX_STR_SIZE, "Toxing on Toxic v.%s", toxic_ver);
|
||||
s_len = strlen(statusmsg);
|
||||
statusmsg[s_len] = '\0';
|
||||
}
|
||||
|
||||
prompt_update_statusmessage(prompt, statusmsg, strlen(statusmsg) + 1);
|
||||
prompt_update_statusmessage(prompt, statusmsg, s_len);
|
||||
prompt_update_status(prompt, status);
|
||||
prompt_update_nick(prompt, nick, n_len);
|
||||
|
||||
/* Init statusbar subwindow */
|
||||
statusbar->topline = subwin(self->window, 2, x2, 0, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user