1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-06-29 15:07:46 +02:00

fix a few formatting bugs and simplify code a bit

This commit is contained in:
Jfreegman 2014-08-02 15:35:57 -04:00
parent fa023c6a99
commit 3cbe61e111
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
12 changed files with 48 additions and 83 deletions

View File

@ -104,7 +104,7 @@ void write_device_callback(ToxAv* av, int32_t call_index, int16_t* data, int siz
static void print_err (ToxWindow *self, const char *error_str) static void print_err (ToxWindow *self, const char *error_str)
{ {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, error_str); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", error_str);
} }
ToxAv *init_audio(ToxWindow *self, Tox *tox) ToxAv *init_audio(ToxWindow *self, Tox *tox)
@ -338,7 +338,6 @@ void callback_media_change(void* av, int32_t call_index, void* arg)
*/ */
void cmd_call(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_call(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
const char *msg;
const char *error_str; const char *error_str;
if (argc != 0) { if (argc != 0) {
@ -365,8 +364,7 @@ void cmd_call(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
goto on_error; goto on_error;
} }
msg = "Calling... idx: %d"; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Calling... idx: %d", self->call_idx);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, self->call_idx);
return; return;
on_error: on_error:
@ -502,7 +500,6 @@ on_error:
void cmd_list_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_list_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
const char *msg;
const char *error_str; const char *error_str;
if ( argc != 1 ) { if ( argc != 1 ) {
@ -521,8 +518,7 @@ void cmd_list_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*
type = output; type = output;
else { else {
msg = "Invalid type: %s"; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid type: %s", argv[1]);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, argv[1]);
return; return;
} }
@ -536,7 +532,6 @@ on_error:
/* This changes primary device only */ /* This changes primary device only */
void cmd_change_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_change_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
const char *msg;
const char *error_str; const char *error_str;
if ( argc != 2 ) { if ( argc != 2 ) {
@ -556,8 +551,7 @@ void cmd_change_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (
type = output; type = output;
else { else {
msg = "Invalid type: %s"; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid type: %s", argv[1]);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, argv[1]);
return; return;
} }
@ -581,8 +575,7 @@ on_error:
} }
void cmd_ccur_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_ccur_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
const char *msg;
const char *error_str; const char *error_str;
if ( argc != 2 ) { if ( argc != 2 ) {
@ -602,8 +595,7 @@ void cmd_ccur_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
type = output; type = output;
else { else {
msg = "Invalid type: %s"; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid type: %s", argv[1]);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, argv[1]);
return; return;
} }
@ -656,8 +648,7 @@ void cmd_ccur_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
} }
void cmd_mute(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_mute(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
const char *msg;
const char *error_str; const char *error_str;
if ( argc != 1 ) { if ( argc != 1 ) {
@ -676,8 +667,7 @@ void cmd_mute(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
type = output; type = output;
else { else {
msg = "Invalid type: %s"; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid type: %s", argv[1]);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, argv[1]);
return; return;
} }

View File

@ -47,7 +47,7 @@ static void print_matches(ToxWindow *self, Tox *m, const void *list, int n_items
int i; int i;
for (i = 0; i < n_items; ++i) for (i = 0; i < n_items; ++i)
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, &L[i * size]); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", &L[i * size]);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, ""); /* formatting */ line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, ""); /* formatting */
} }

View File

@ -163,7 +163,7 @@ static void chat_onMessage(ToxWindow *self, Tox *m, int32_t num, const char *msg
char timefrmt[TIME_STR_SIZE]; char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt)); get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, nick, NULL, IN_MSG, 0, 0, msg); line_info_add(self, timefrmt, nick, NULL, IN_MSG, 0, 0, "%s", msg);
write_to_log(msg, nick, ctx->log, false); write_to_log(msg, nick, ctx->log, false);
if (self->active_box != -1) if (self->active_box != -1)
@ -215,7 +215,7 @@ static void chat_onAction(ToxWindow *self, Tox *m, int32_t num, const char *acti
char timefrmt[TIME_STR_SIZE]; char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt)); get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, nick, NULL, ACTION, 0, 0, action); line_info_add(self, timefrmt, nick, NULL, ACTION, 0, 0, "%s", action);
write_to_log(action, nick, ctx->log, true); write_to_log(action, nick, ctx->log, true);
if (self->active_box != -1) if (self->active_box != -1)
@ -269,7 +269,6 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t
if (self->num != num) if (self->num != num)
return; return;
const char *msg;
const char *errmsg; const char *errmsg;
/* holds the filename appended to the user specified path */ /* holds the filename appended to the user specified path */
@ -279,9 +278,8 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t
char filename_nopath[MAX_STR_SIZE]; char filename_nopath[MAX_STR_SIZE];
get_file_name(filename_nopath, sizeof(filename_nopath), pathname); get_file_name(filename_nopath, sizeof(filename_nopath), pathname);
int len = strlen(filename_nopath); int len = strlen(filename_nopath);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer request for '%s' (%llu bytes).",
msg = "File transfer request for '%s' (%llu bytes)."; filename_nopath, (long long unsigned int) filesize);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, filename_nopath, (long long unsigned int) filesize);
if (filenum >= MAX_FILES) { if (filenum >= MAX_FILES) {
errmsg = "Too many pending file requests; discarding."; errmsg = "Too many pending file requests; discarding.";
@ -333,8 +331,7 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t
} }
} }
msg = "Type '/savefile %d' to accept the file transfer."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Type '/savefile %d' to accept the file transfer.", filenum);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, filenum);
friends[num].file_receiver.pending[filenum] = true; friends[num].file_receiver.pending[filenum] = true;
friends[num].file_receiver.size[filenum] = filesize; friends[num].file_receiver.size[filenum] = filesize;
@ -382,13 +379,12 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
switch (control_type) { switch (control_type) {
case TOX_FILECONTROL_ACCEPT: case TOX_FILECONTROL_ACCEPT:
if (receive_send == 1) { if (receive_send == 1) {
const char *r_msg = "File transfer for '%s' accepted."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "File transfer for '%s' accepted.", filename);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, r_msg, filename);
/* prep progress bar line */ /* prep progress bar line */
char progline[MAX_STR_SIZE]; char progline[MAX_STR_SIZE];
prep_prog_line(progline); prep_prog_line(progline);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, progline); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", progline);
file_senders[i].line_id = self->chatwin->hst->line_end->id + 2; file_senders[i].line_id = self->chatwin->hst->line_end->id + 2;
sound_notify(self, silent, NT_NOFOCUS | NT_BEEP | NT_WNDALERT_2, NULL); sound_notify(self, silent, NT_NOFOCUS | NT_BEEP | NT_WNDALERT_2, NULL);
} }
@ -427,7 +423,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
} }
if (msg[0]) if (msg[0])
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", msg);
} }
static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum, const char *data, static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum, const char *data,
@ -465,13 +461,10 @@ static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, co
if (self->num != friendnumber) if (self->num != friendnumber)
return; return;
const char *msg;
char name[TOX_MAX_NAME_LENGTH]; char name[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, name, friendnumber); get_nick_truncate(m, name, friendnumber);
msg = "%s has invited you to a group chat."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s has invited you to a group chat.", name);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, name);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Type \"/join\" to join the chat."); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Type \"/join\" to join the chat.");
memcpy(friends[friendnumber].groupchat_key, group_pub_key, memcpy(friends[friendnumber].groupchat_key, group_pub_key,
@ -739,11 +732,10 @@ static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, char *action)
char timefrmt[TIME_STR_SIZE]; char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt)); get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, selfname, NULL, ACTION, 0, 0, action); line_info_add(self, timefrmt, selfname, NULL, ACTION, 0, 0, "%s", action);
if (tox_send_action(m, self->num, (uint8_t *) action, strlen(action)) == 0) { if (tox_send_action(m, self->num, (uint8_t *) action, strlen(action)) == 0) {
const char *errmsg = " * Failed to send action."; line_info_add(self, NULL, selfname, NULL, SYS_MSG, 0, RED, " * Failed to send action.");
line_info_add(self, NULL, selfname, NULL, SYS_MSG, 0, RED, errmsg);
} else { } else {
write_to_log(action, selfname, ctx->log, true); write_to_log(action, selfname, ctx->log, true);
} }
@ -826,7 +818,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
char timefrmt[TIME_STR_SIZE]; char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt)); get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, selfname, NULL, OUT_MSG, 0, 0, line); line_info_add(self, timefrmt, selfname, NULL, OUT_MSG, 0, 0, "%s", line);
if (!statusbar->is_online || tox_send_message(m, self->num, (uint8_t *) line, strlen(line)) == 0) { if (!statusbar->is_online || tox_send_message(m, self->num, (uint8_t *) line, strlen(line)) == 0) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Failed to send message."); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Failed to send message.");

View File

@ -63,8 +63,7 @@ void cmd_groupinvite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
return; return;
} }
const char *msg = "Invited contact to Group %d."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invited contact to Group %d.", groupnum);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, groupnum);
} }
void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
@ -128,13 +127,12 @@ void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
const char *filename = friends[self->num].file_receiver.filenames[filenum]; const char *filename = friends[self->num].file_receiver.filenames[filenum];
if (tox_file_send_control(m, self->num, 1, filenum, TOX_FILECONTROL_ACCEPT, 0, 0) == 0) { if (tox_file_send_control(m, self->num, 1, filenum, TOX_FILECONTROL_ACCEPT, 0, 0) == 0) {
const char *msg = "Saving file as: '%s'"; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Saving file as: '%s'", filename);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, filename);
/* prep progress bar line */ /* prep progress bar line */
char progline[MAX_STR_SIZE]; char progline[MAX_STR_SIZE];
prep_prog_line(progline); prep_prog_line(progline);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, progline); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", progline);
friends[self->num].file_receiver.line_id[filenum] = self->chatwin->hst->line_end->id + 2; friends[self->num].file_receiver.line_id[filenum] = self->chatwin->hst->line_end->id + 2;
if ((friends[self->num].file_receiver.files[filenum] = fopen(filename, "a")) == NULL) { if ((friends[self->num].file_receiver.files[filenum] = fopen(filename, "a")) == NULL) {
@ -222,8 +220,7 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
file_senders[i].piecelen = fread(file_senders[i].nextpiece, 1, file_senders[i].piecelen = fread(file_senders[i].nextpiece, 1,
tox_file_data_size(m, self->num), file_to_send); tox_file_data_size(m, self->num), file_to_send);
const char *msg = "Sending file: '%s'"; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Sending file: '%s'", path);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, path);
++num_active_file_senders; ++num_active_file_senders;

View File

@ -85,10 +85,8 @@ static struct _dns_thread {
static int dns_error(ToxWindow *self, const char *errmsg) static int dns_error(ToxWindow *self, const char *errmsg)
{ {
const char *msg = "User lookup failed: %s";
pthread_mutex_lock(&Winthread.lock); pthread_mutex_lock(&Winthread.lock);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, errmsg); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "User lookup failed: %s", errmsg);
pthread_mutex_unlock(&Winthread.lock); pthread_mutex_unlock(&Winthread.lock);
return -1; return -1;

View File

@ -119,10 +119,10 @@ static void set_max_file_senders_index(void)
max_file_senders_index = j; max_file_senders_index = j;
} }
static void close_file_sender(ToxWindow *self, Tox *m, int i, char *msg, int CTRL, int filenum, int32_t friendnum) static void close_file_sender(ToxWindow *self, Tox *m, int i, const char *msg, int CTRL, int filenum, int32_t friendnum)
{ {
if (self->chatwin != NULL) if (self->chatwin != NULL)
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", msg);
tox_file_send_control(m, friendnum, 0, filenum, CTRL, 0, 0); tox_file_send_control(m, friendnum, 0, filenum, CTRL, 0, 0);

View File

@ -261,7 +261,7 @@ static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, const cha
char timefrmt[TIME_STR_SIZE]; char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt)); get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(prompt, timefrmt, nick, NULL, IN_MSG, 0, 0, str); line_info_add(prompt, timefrmt, nick, NULL, IN_MSG, 0, 0, "%s", str);
const char *msg = "* Warning: Too many windows are open."; const char *msg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, msg); line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, msg);
@ -410,8 +410,8 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, u
char nick[TOX_MAX_NAME_LENGTH]; char nick[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, nick, num); get_nick_truncate(m, nick, num);
const char *msg = "* File transfer from %s failed: too many windows are open."; line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED,
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, msg, nick); "* File transfer from %s failed: too many windows are open.", nick);
sound_notify(prompt, error, NT_WNDALERT_1, NULL); sound_notify(prompt, error, NT_WNDALERT_1, NULL);
} }
@ -437,10 +437,8 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, const
} else { } else {
char nick[TOX_MAX_NAME_LENGTH]; char nick[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, nick, num); get_nick_truncate(m, nick, num);
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED,
const char *msg = "* Group chat invite from %s failed: too many windows are open."; "* Group chat invite from %s failed: too many windows are open.", nick);
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, msg, nick);
sound_notify(prompt, error, NT_WNDALERT_1, NULL); sound_notify(prompt, error, NT_WNDALERT_1, NULL);
} }
} }
@ -974,9 +972,7 @@ static void friendlist_onAv(ToxWindow *self, ToxAv *av, int call_index)
} else { } else {
char nick[TOX_MAX_NAME_LENGTH]; char nick[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, nick, friends[id].num); get_nick_truncate(m, nick, friends[id].num);
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Audio action from: %s!", nick);
const char *msg = "Audio action from: %s!";
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, nick);
const char *errmsg = "* Warning: Too many windows are open."; const char *errmsg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg); line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);

View File

@ -87,7 +87,7 @@ void cmd_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
} }
num_frnd_requests = i; num_frnd_requests = i;
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", msg);
} }
void cmd_add_helper(ToxWindow *self, Tox *m, char *id_bin, char *msg) void cmd_add_helper(ToxWindow *self, Tox *m, char *id_bin, char *msg)
@ -254,8 +254,7 @@ void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
return; return;
} }
const char *msg = "Group chat created as %d."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat created as %d.", groupnum);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, groupnum);
} }
void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
@ -320,7 +319,7 @@ void cmd_myid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
strcat(id, xx); strcat(id, xx);
} }
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, id); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", id);
} }
void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])

View File

@ -159,7 +159,7 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
char timefrmt[TIME_STR_SIZE]; char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt)); get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, nick, NULL, IN_MSG, 0, nick_clr, msg); line_info_add(self, timefrmt, nick, NULL, IN_MSG, 0, nick_clr, "%s", msg);
write_to_log(msg, nick, ctx->log, false); write_to_log(msg, nick, ctx->log, false);
} }
@ -198,7 +198,7 @@ static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int p
char timefrmt[TIME_STR_SIZE]; char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt)); get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, nick, NULL, ACTION, 0, 0, action); line_info_add(self, timefrmt, nick, NULL, ACTION, 0, 0, "%s", action);
write_to_log(action, nick, ctx->log, true); write_to_log(action, nick, ctx->log, true);
} }

View File

@ -147,15 +147,10 @@ void line_info_add(ToxWindow *self, char *tmstmp, char *name1, char *name2, uint
char frmt_msg[MAX_STR_SIZE] = {0}; char frmt_msg[MAX_STR_SIZE] = {0};
/* WARNING: SYS_MSG lines must not contain untrusted input */ va_list args;
if (type == SYS_MSG) { va_start(args, msg);
va_list args; vsnprintf(frmt_msg, sizeof(frmt_msg), msg, args);
va_start(args, msg); va_end(args);
vsnprintf(frmt_msg, sizeof(frmt_msg), msg, args);
va_end(args);
} else {
snprintf(frmt_msg, sizeof(frmt_msg), "%s", msg);
}
int len = 1; /* there will always be a newline */ int len = 1; /* there will always be a newline */

View File

@ -26,7 +26,7 @@
#include "windows.h" #include "windows.h"
#include "toxic.h" #include "toxic.h"
#define MAX_HISTORY 10000 #define MAX_HISTORY 100000
#define MIN_HISTORY 40 #define MIN_HISTORY 40
#define MAX_QUEUE 128 #define MAX_QUEUE 128

View File

@ -201,7 +201,7 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
if (!string_is_empty(line)) if (!string_is_empty(line))
add_line_to_hist(ctx); add_line_to_hist(ctx);
line_info_add(self, NULL, NULL, NULL, PROMPT, 0, 0, line); line_info_add(self, NULL, NULL, NULL, PROMPT, 0, 0, "%s", line);
execute(ctx->history, self, m, line, GLOBAL_COMMAND_MODE); execute(ctx->history, self, m, line, GLOBAL_COMMAND_MODE);
wclear(ctx->linewin); wclear(ctx->linewin);
@ -337,9 +337,8 @@ static void prompt_onFriendRequest(ToxWindow *self, Tox *m, const char *key, con
char timefrmt[TIME_STR_SIZE]; char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt)); get_time_str(timefrmt, sizeof(timefrmt));
const char *msg = "Friend request with the message '%s'"; line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 0, 0, "Friend request with the message '%s'", data);
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 0, 0, msg, data); write_to_log("Friend request with the message '%s'", "", ctx->log, true);
write_to_log(msg, "", ctx->log, true);
int n = add_friend_request(key); int n = add_friend_request(key);
@ -350,8 +349,7 @@ static void prompt_onFriendRequest(ToxWindow *self, Tox *m, const char *key, con
return; return;
} }
msg = "Type \"/accept %d\" to accept it."; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Type \"/accept %d\" to accept it.", n);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, n);
sound_notify(self, generic_message, NT_WNDALERT_1 | NT_NOTIFWND, NULL); sound_notify(self, generic_message, NT_WNDALERT_1 | NT_NOTIFWND, NULL);
} }