From 7e898fdcf4ab2d89977b2ef8db448986b8b68a37 Mon Sep 17 00:00:00 2001 From: vague666 Date: Thu, 12 Mar 2020 22:52:12 +0100 Subject: [PATCH 1/7] Make sure witem exists --- src/fe-common/core/fe-core-commands.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c index 9a2c547f..ea162e08 100644 --- a/src/fe-common/core/fe-core-commands.c +++ b/src/fe-common/core/fe-core-commands.c @@ -155,7 +155,9 @@ static void cmd_cat(const char *data, SERVER_REC *server, WI_ITEM_REC *item) return; } - target = g_hash_table_lookup(optlist, "window") != NULL ? item->name : NULL; + target = item != NULL && g_hash_table_lookup(optlist, "window") != NULL + ? item->name + : NULL; g_io_channel_set_encoding(handle, NULL, NULL); g_io_channel_seek_position(handle, fpos, G_SEEK_SET, NULL); From 22851686f5b88ac83ca49e80e743ed50d18c57af Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Tue, 17 Mar 2020 00:58:48 +0000 Subject: [PATCH 2/7] simplify logic --- src/fe-common/core/fe-core-commands.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c index ea162e08..c9ca93ce 100644 --- a/src/fe-common/core/fe-core-commands.c +++ b/src/fe-common/core/fe-core-commands.c @@ -117,7 +117,8 @@ static void cmd_version(char *data) /* SYNTAX: CAT [-window] [] */ static void cmd_cat(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { - char *fname, *fposstr, *target; + char *fname, *fposstr; + gboolean target; GHashTable *optlist; void *free_arg; int fpos; @@ -155,16 +156,14 @@ static void cmd_cat(const char *data, SERVER_REC *server, WI_ITEM_REC *item) return; } - target = item != NULL && g_hash_table_lookup(optlist, "window") != NULL - ? item->name - : NULL; + target = g_hash_table_lookup(optlist, "window") != NULL; g_io_channel_set_encoding(handle, NULL, NULL); g_io_channel_seek_position(handle, fpos, G_SEEK_SET, NULL); buf = g_string_sized_new(512); while (g_io_channel_read_line_string(handle, buf, &tpos, NULL) == G_IO_STATUS_NORMAL) { buf->str[tpos] = '\0'; - printtext(target != NULL ? server : NULL, target, MSGLEVEL_CLIENTCRAP | + printtext(target ? server : NULL, target && item != NULL ? item->name : NULL, MSGLEVEL_CLIENTCRAP | MSGLEVEL_NEVER, "%s", buf->str); } g_string_free(buf, TRUE); From a0544571a80196e5b7705f56e6e2cbcdf7b4d80e Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Thu, 23 Apr 2020 21:45:15 +0200 Subject: [PATCH 3/7] manually handle NUL unicode in g_utf8_get_next_char_validated A change in GLib 2.63 broke some assumptions in Irssi that the null-byte NUL / U+0000 is a valid Unicode character. This would occur when the user types Ctrl+Space. As a result, the input loop never manages to process the NUL-byte (and any other user input that follows, ever). This patch adds a manual check that properly advances the input loop if GLib returns -2 (incomplete character) despite the length being positive and a NUL is in first position. Fixes #1180 https://gitlab.gnome.org/GNOME/glib/-/merge_requests/967 https://gitlab.gnome.org/GNOME/glib/-/issues/2093 --- src/fe-text/term-terminfo.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/fe-text/term-terminfo.c b/src/fe-text/term-terminfo.c index 5235f72d..78496a64 100644 --- a/src/fe-text/term-terminfo.c +++ b/src/fe-text/term-terminfo.c @@ -672,7 +672,11 @@ void term_stop(void) static int input_utf8(const unsigned char *buffer, int size, unichar *result) { - unichar c = g_utf8_get_char_validated((char *)buffer, size); + unichar c = g_utf8_get_char_validated((char *) buffer, size); + + /* GLib >= 2.63 do not accept Unicode NUL anymore */ + if (c == (unichar) -2 && *buffer == 0 && size > 0) + c = 0; switch (c) { case (unichar)-1: From 108f57ac7bc31bf0139dbdbbc0125c554d852bb7 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Sat, 4 Jul 2020 12:15:25 +0200 Subject: [PATCH 4/7] fix extended bg colours --- src/fe-text/textbuffer-view.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/fe-text/textbuffer-view.c b/src/fe-text/textbuffer-view.c index 0bbb3655..bc7cc5a8 100644 --- a/src/fe-text/textbuffer-view.c +++ b/src/fe-text/textbuffer-view.c @@ -189,30 +189,32 @@ static inline void unformat(const unsigned char **ptr, int *color, unsigned int break; case FORMAT_STYLE_CLRTOEOL: break; +#define SET_COLOR_EXT_FG_BITS(base, pc) \ + *color &= ~ATTR_FGCOLOR24; \ + *color = (*color & BGATTR) | (base + *pc - FORMAT_COLOR_NOCHANGE) +#define SET_COLOR_EXT_BG_BITS(base, pc) \ + *color &= ~ATTR_BGCOLOR24; \ + *color = (*color & FGATTR) | ((base + *pc - FORMAT_COLOR_NOCHANGE) << BG_SHIFT) case FORMAT_COLOR_EXT1: - *color &= ~ATTR_FGCOLOR24; - *color = (*color & BGATTR) | (0x10 + *++*ptr - FORMAT_COLOR_NOCHANGE); + SET_COLOR_EXT_FG_BITS(0x10, ++*ptr); break; case FORMAT_COLOR_EXT1_BG: - *color &= ~ATTR_BGCOLOR24; - *color = (*color & FGATTR) | (0x10 + *++*ptr - FORMAT_COLOR_NOCHANGE); + SET_COLOR_EXT_BG_BITS(0x10, ++*ptr); break; case FORMAT_COLOR_EXT2: - *color &= ~ATTR_FGCOLOR24; - *color = (*color & BGATTR) | (0x60 + *++*ptr - FORMAT_COLOR_NOCHANGE); + SET_COLOR_EXT_FG_BITS(0x60, ++*ptr); break; case FORMAT_COLOR_EXT2_BG: - *color &= ~ATTR_BGCOLOR24; - *color = (*color & FGATTR) | (0x60 + *++*ptr - FORMAT_COLOR_NOCHANGE); + SET_COLOR_EXT_BG_BITS(0x60, ++*ptr); break; case FORMAT_COLOR_EXT3: - *color &= ~ATTR_FGCOLOR24; - *color = (*color & BGATTR) | (0xb0 + *++*ptr - FORMAT_COLOR_NOCHANGE); + SET_COLOR_EXT_FG_BITS(0xb0, ++*ptr); break; case FORMAT_COLOR_EXT3_BG: - *color &= ~ATTR_BGCOLOR24; - *color = (*color & FGATTR) | (0xb0 + *++*ptr - FORMAT_COLOR_NOCHANGE); + SET_COLOR_EXT_BG_BITS(0xb0, ++*ptr); break; +#undef SET_COLOR_EXT_BG_BITS +#undef SET_COLOR_EXT_FG_BITS #ifdef TERM_TRUECOLOR case FORMAT_COLOR_24: unformat_24bit_line_color(ptr, 1, color, fg24, bg24); From 0cc1e4b7cd4eb8881f58d03a5ab5d321f4ae12e8 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Sat, 4 Jul 2020 18:19:37 +0200 Subject: [PATCH 5/7] properly restore the saved text dest --- docs/signals.txt | 4 +-- src/common.h | 2 +- src/fe-common/core/printtext.c | 2 +- src/fe-text/gui-printtext.c | 5 ++-- src/fe-text/textbuffer-formats.c | 44 ++++++++++++++++++++------------ src/fe-text/textbuffer-formats.h | 1 + 6 files changed, 36 insertions(+), 22 deletions(-) diff --git a/docs/signals.txt b/docs/signals.txt index ff600cd3..1eefc7e0 100644 --- a/docs/signals.txt +++ b/docs/signals.txt @@ -246,7 +246,7 @@ FE common "gui print text", WINDOW_REC, int fg, int bg, int flags, char *text, TEXT_DEST_REC (Can be used to determine when all "gui print text"s are sent (not required)) - "gui print text finished", WINDOW_REC + "gui print text finished", WINDOW_REC, TEXT_DEST_REC * Provides signals: @@ -353,7 +353,7 @@ gui-readline.c: gui-printtext.c: "beep" - "gui print text after finished", WINDOW_REC, LINE_REC *line, LINE_REC *prev_line + "gui print text after finished", WINDOW_REC, LINE_REC *line, LINE_REC *prev_line, TEXT_DEST_REC textbuffer-view.c "gui textbuffer line removed", TEXTBUFFER_VIEW_REC *view, LINE_REC *line, LINE_REC *prev_line diff --git a/src/common.h b/src/common.h index c9c4e545..73de4b78 100644 --- a/src/common.h +++ b/src/common.h @@ -6,7 +6,7 @@ #define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */ #define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */ -#define IRSSI_ABI_VERSION 29 +#define IRSSI_ABI_VERSION 30 #define DEFAULT_SERVER_ADD_PORT 6667 #define DEFAULT_SERVER_ADD_TLS_PORT 6697 diff --git a/src/fe-common/core/printtext.c b/src/fe-common/core/printtext.c index 06c22a4c..6869fba3 100644 --- a/src/fe-common/core/printtext.c +++ b/src/fe-common/core/printtext.c @@ -442,7 +442,7 @@ static void sig_print_text(TEXT_DEST_REC *dest, const char *text) format_send_to_gui(dest, str); g_free(str); - signal_emit_id(signal_gui_print_text_finished, 1, dest->window); + signal_emit_id(signal_gui_print_text_finished, 2, dest->window, dest); } static void sig_print_format(THEME_REC *theme, const char *module, TEXT_DEST_REC *dest, diff --git a/src/fe-text/gui-printtext.c b/src/fe-text/gui-printtext.c index 872c73c4..a92c6f3b 100644 --- a/src/fe-text/gui-printtext.c +++ b/src/fe-text/gui-printtext.c @@ -158,7 +158,8 @@ void gui_printtext_after_time(TEXT_DEST_REC *dest, LINE_REC *prev, const char *s gui->insert_after_time = time; format_send_to_gui(dest, str); gui->use_insert_after = FALSE; - signal_emit("gui print text after finished", 3, dest->window, gui->insert_after, prev); + signal_emit("gui print text after finished", 4, dest->window, gui->insert_after, prev, + dest); } void gui_printtext_after(TEXT_DEST_REC *dest, LINE_REC *prev, const char *str) @@ -376,7 +377,7 @@ static void sig_gui_print_text(WINDOW_REC *window, void *fgcolor, gui->insert_after = insert_after; } -static void sig_gui_printtext_finished(WINDOW_REC *window) +static void sig_gui_printtext_finished(WINDOW_REC *window, TEXT_DEST_REC *dest) { TEXT_BUFFER_VIEW_REC *view; LINE_REC *insert_after; diff --git a/src/fe-text/textbuffer-formats.c b/src/fe-text/textbuffer-formats.c index 47f1735a..84aaebb9 100644 --- a/src/fe-text/textbuffer-formats.c +++ b/src/fe-text/textbuffer-formats.c @@ -42,6 +42,7 @@ void textbuffer_format_rec_free(TEXT_BUFFER_FORMAT_REC *rec) i_refstr_release(rec->server_tag); i_refstr_release(rec->target); i_refstr_release(rec->nick); + i_refstr_release(rec->address); if (rec->nargs >= 1) { i_refstr_release(rec->args[0]); } @@ -54,17 +55,13 @@ void textbuffer_format_rec_free(TEXT_BUFFER_FORMAT_REC *rec) g_slice_free(TEXT_BUFFER_FORMAT_REC, rec); } -static TEXT_BUFFER_FORMAT_REC *format_rec_new(const char *module, const char *format_tag, - const char *server_tag, const char *target, - const char *nick, int nargs, const char **args) +static TEXT_BUFFER_FORMAT_REC *format_rec_new(const char *module, const char *format_tag, int nargs, + const char **args) { int n; TEXT_BUFFER_FORMAT_REC *ret = g_slice_new0(TEXT_BUFFER_FORMAT_REC); ret->module = i_refstr_intern(module); ret->format = i_refstr_intern(format_tag); - ret->server_tag = i_refstr_intern(server_tag); - ret->target = i_refstr_intern(target); - ret->nick = i_refstr_intern(nick); ret->nargs = nargs; ret->args = g_new0(char *, nargs); if (nargs >= 1) { @@ -76,6 +73,19 @@ static TEXT_BUFFER_FORMAT_REC *format_rec_new(const char *module, const char *fo return ret; } +static void format_rec_set_dest(TEXT_BUFFER_FORMAT_REC *rec, const TEXT_DEST_REC *dest) +{ + i_refstr_release(rec->server_tag); + i_refstr_release(rec->target); + i_refstr_release(rec->nick); + i_refstr_release(rec->address); + rec->server_tag = i_refstr_intern(dest->server_tag); + rec->target = i_refstr_intern(dest->target); + rec->nick = i_refstr_intern(dest->nick); + rec->address = i_refstr_intern(dest->address); + rec->flags = dest->flags & ~PRINT_FLAG_FORMAT; +} + static LINE_INFO_REC *store_lineinfo_tmp(TEXT_DEST_REC *dest) { GUI_WINDOW_REC *gui; @@ -132,11 +142,10 @@ static void sig_print_format(THEME_REC *theme, const char *module, TEXT_DEST_REC formatnum = GPOINTER_TO_INT(formatnump); formats = g_hash_table_lookup(default_formats, module); - info->format = format_rec_new(module, formats[formatnum].tag, dest->server_tag, - dest->target, dest->nick, formats[formatnum].params, args); + info->format = + format_rec_new(module, formats[formatnum].tag, formats[formatnum].params, args); special_push_collector(&info->format->expando_cache); - info->format->flags = dest->flags; dest->flags |= PRINT_FLAG_FORMAT; signal_continue(5, theme, module, dest, formatnump, args); @@ -155,11 +164,9 @@ static void sig_print_noformat(TEXT_DEST_REC *dest, const char *text) special_push_collector(NULL); info = store_lineinfo_tmp(dest); - info->format = format_rec_new(NULL, NULL, dest->server_tag, dest->target, dest->nick, 2, - (const char *[]){ NULL, text }); + info->format = format_rec_new(NULL, NULL, 2, (const char *[]){ NULL, text }); special_push_collector(&info->format->expando_cache); - info->format->flags = dest->flags; dest->flags |= PRINT_FLAG_FORMAT; signal_continue(2, dest, text); @@ -182,7 +189,7 @@ static GSList *reverse_collector(GSList *a1) return c1; } -static void sig_gui_print_text_finished(WINDOW_REC *window) +static void sig_gui_print_text_finished(WINDOW_REC *window, TEXT_DEST_REC *dest) { GUI_WINDOW_REC *gui; LINE_REC *insert_after; @@ -202,6 +209,7 @@ static void sig_gui_print_text_finished(WINDOW_REC *window) return; info->format->expando_cache = reverse_collector(info->format->expando_cache); + format_rec_set_dest(info->format, dest); info->level |= MSGLEVEL_FORMAT; @@ -290,12 +298,16 @@ char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line) curr = line; line = NULL; - format_rec = curr->info.format; - format_create_dest( + format_rec = curr->info.format; + format_create_dest_tag( &dest, format_rec->server_tag != NULL ? server_find_tag(format_rec->server_tag) : NULL, - format_rec->target, curr->info.level & ~MSGLEVEL_FORMAT, buffer->window); + format_rec->server_tag, format_rec->target, curr->info.level & ~MSGLEVEL_FORMAT, + buffer->window); + dest.nick = format_rec->nick; + dest.address = format_rec->address; + dest.flags = format_rec->flags; theme = window_get_theme(dest.window); diff --git a/src/fe-text/textbuffer-formats.h b/src/fe-text/textbuffer-formats.h index 45e4ce1b..b57f61c9 100644 --- a/src/fe-text/textbuffer-formats.h +++ b/src/fe-text/textbuffer-formats.h @@ -9,6 +9,7 @@ typedef struct _TEXT_BUFFER_FORMAT_REC { char *server_tag; char *target; char *nick; + char *address; char **args; int nargs; GSList *expando_cache; From 9593be14f5fb93be937a5c67426402757b528909 Mon Sep 17 00:00:00 2001 From: vague666 Date: Mon, 6 Jul 2020 12:22:16 +0200 Subject: [PATCH 6/7] print to active window when -window is specified --- src/fe-common/core/fe-core-commands.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c index c9ca93ce..78c136dc 100644 --- a/src/fe-common/core/fe-core-commands.c +++ b/src/fe-common/core/fe-core-commands.c @@ -163,8 +163,10 @@ static void cmd_cat(const char *data, SERVER_REC *server, WI_ITEM_REC *item) buf = g_string_sized_new(512); while (g_io_channel_read_line_string(handle, buf, &tpos, NULL) == G_IO_STATUS_NORMAL) { buf->str[tpos] = '\0'; - printtext(target ? server : NULL, target && item != NULL ? item->name : NULL, MSGLEVEL_CLIENTCRAP | - MSGLEVEL_NEVER, "%s", buf->str); + if (target) + printtext_window(active_win, MSGLEVEL_CLIENTCRAP | MSGLEVEL_NEVER, "%s", buf->str); + else + printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP | MSGLEVEL_NEVER, "%s", buf->str); } g_string_free(buf, TRUE); cmd_params_free(free_arg); From 357beb91f547051f1c3161df9081f632fcb2acd4 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Tue, 7 Jul 2020 09:28:41 +0200 Subject: [PATCH 7/7] make clang-format happy --- src/fe-common/core/fe-core-commands.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c index 78c136dc..c314c405 100644 --- a/src/fe-common/core/fe-core-commands.c +++ b/src/fe-common/core/fe-core-commands.c @@ -164,7 +164,8 @@ static void cmd_cat(const char *data, SERVER_REC *server, WI_ITEM_REC *item) while (g_io_channel_read_line_string(handle, buf, &tpos, NULL) == G_IO_STATUS_NORMAL) { buf->str[tpos] = '\0'; if (target) - printtext_window(active_win, MSGLEVEL_CLIENTCRAP | MSGLEVEL_NEVER, "%s", buf->str); + printtext_window(active_win, MSGLEVEL_CLIENTCRAP | MSGLEVEL_NEVER, "%s", + buf->str); else printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP | MSGLEVEL_NEVER, "%s", buf->str); }