irc, buflist: add bar item "tls_version" with options for colors, add buflist format "${format_tls_version}" (issue #1622)

This commit is contained in:
Andrew Potter 2021-03-26 17:27:37 -07:00 committed by Sébastien Helleu
parent 670c5cd745
commit 94c902adfc
18 changed files with 187 additions and 3 deletions

View File

@ -868,6 +868,8 @@ andere Items die zur Verfügung stehen (die aber nicht standardmäßig in einer
| mouse_status | `M` | Status der Maus (keine Anzeige, falls Maus deaktiviert).
| spell_dict | `de,en` | zeigt an welche Wörterbücher für die Rechtschreibung im aktuellen Buffer genutzt werden.
| spell_suggest | `Glück,Glocke,Block` | Vorschläge für ein falsch geschriebenes Wort.
// TRANSLATION MISSING
| tls_version | `TLS1.3` | TLS version in use for current IRC server.
| window_number | `2` | Nummer des aktuellen Fensters.
|===

View File

@ -862,6 +862,7 @@ Other items available (not used in bars by default):
| mouse_status | `M` | Mouse status (empty if mouse is disabled).
| spell_dict | `fr,en` | Spelling dictionaries used on current buffer.
| spell_suggest | `print,prone,prune` | Spelling suggestions for word under cursor (if misspelled).
| tls_version | `TLS1.3` | TLS version in use for current IRC server.
| window_number | `2` | Current window number.
|===

View File

@ -882,6 +882,7 @@ Autres objets (non utilisés dans des barres par défaut) :
| mouse_status | `M` | Statut de la souris (vide si la souris est désactivée).
| spell_dict | `fr,en` | Dictionnaires utilisés pour la vérification de l'orthographe sur le tampon courant.
| spell_suggest | `print,prone,prune` | Suggestions pour le mot sous le curseur (si mal orthographié).
| tls_version | `TLS1.3` | Version de TLS utilisée sur le serveur IRC courant.
| window_number | `2` | Numéro de la fenêtre courante.
|===

View File

@ -940,6 +940,7 @@ Other items available (not used in bars by default):
| mouse_status | `M` | Mouse status (empty if mouse is disabled).
| spell_dict | `fr,en` | Spelling dictionaries used on current buffer.
| spell_suggest | `print,prone,prune` | Spelling suggestions for word under cursor (if misspelled).
| tls_version | `TLS1.3` | TLS version in use for current IRC server.
| window_number | `2` | Current window number.
|===

View File

@ -905,6 +905,8 @@ WeeChat を起動した端末の例:
| mouse_status | `M` | マウスの状態 (マウスが無効化されている場合は空文字列)
| spell_dict | `fr,en` | 現在のバッファにおけるスペリング辞書
| spell_suggest | `print,prone,prune` | カーソル下の単語に対するスペリング候補 (スペルが間違っている場合)
// TRANSLATION MISSING
| tls_version | `TLS1.3` | TLS version in use for current IRC server.
| window_number | `2` | 現在のウィンドウ番号
|===

View File

@ -880,6 +880,8 @@ Inne dostępne elementy (nie używane domyślnie w paskach):
| mouse_status | `M` | Status obsługi myszy (pusty jeśli obsługa myszy jest wyłączona).
| spell_dict | `fr,en` | Słowniki używane w obecnym buforze.
| spell_suggest | `print,prone,prune` | Sugestie dla słowa pod kursorem (jeśli zawiera błąd).
// TRANSLATION MISSING
| tls_version | `TLS1.3` | TLS version in use for current IRC server.
| window_number | `2` | Numer obecnego okna.
|===

View File

@ -312,7 +312,7 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data,
const char *hotlist_priority[4] = { "low", "message", "private",
"highlight" };
const char indent_empty[1] = { '\0' };
const char *ptr_lag, *ptr_item_name;
const char *ptr_lag, *ptr_item_name, *ptr_tls_version;
int item_index, num_buffers, is_channel, is_private;
int i, j, length_max_number, current_buffer, number, prev_number, priority;
int rc, count, line_number, line_number_current_buffer;
@ -596,6 +596,14 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data,
"format_lag", "");
}
/* tls version */
ptr_tls_version = weechat_buffer_get_string (ptr_buffer, "localvar_tls_version");
weechat_hashtable_set (
buflist_hashtable_extra_vars,
"format_tls_version",
(ptr_tls_version && ptr_tls_version[0]) ?
weechat_config_string (buflist_config_format_tls_version) : "");
/* check condition: if false, the buffer is not displayed */
condition = weechat_string_eval_expression (
weechat_config_string (buflist_config_look_display_conditions),

View File

@ -168,7 +168,10 @@ buflist_command_init ()
" - ${hotlist_priority}: \"none\", \"low\", \"message\", "
"\"private\" or \"highlight\"\n"
" - ${format_lag}: the lag for an IRC server buffer, empty if "
"there's no lag (evaluation of option buflist.format.lag)"),
"there's no lag (evaluation of option buflist.format.lag)\n"
" - ${format_tls_version}: indicator of TLS version for a server "
"buffer, empty for channels. (evaluation of option "
"buflist.format.tls_version)"),
"enable|disable|toggle || bar || refresh",
&buflist_command_buflist, NULL, NULL);
}

View File

@ -59,6 +59,7 @@ struct t_config_option *buflist_config_format_lag;
struct t_config_option *buflist_config_format_name;
struct t_config_option *buflist_config_format_nick_prefix;
struct t_config_option *buflist_config_format_number;
struct t_config_option *buflist_config_format_tls_version;
struct t_hook **buflist_config_signals_refresh = NULL;
int buflist_config_num_signals_refresh = 0;
@ -403,7 +404,7 @@ buflist_config_add_eval_for_formats (const char *string)
char *formats[] = { "format_buffer", "format_number", "indent",
"format_nick_prefix", "format_name",
"format_hotlist", "hotlist", "format_lag",
"color_hotlist", NULL };
"color_hotlist", "format_tls_version", NULL };
char *result, *tmp, format[512], format_eval[512];
int i;
@ -773,6 +774,19 @@ buflist_config_init ()
NULL, NULL, NULL,
&buflist_config_change_buflist, NULL, NULL,
NULL, NULL, NULL);
buflist_config_format_tls_version = weechat_config_new_option (
buflist_config_file, ptr_section,
"tls_version", "string",
N_("format for tls_version on an IRC server buffer "
"(note: content is evaluated, see /help buflist)"),
NULL, 0, 0,
" ${color:default}(${if:${tls_version}==TLS1.3?${color:green}:"
"${if:${tls_version}==TLS1.2?${color:yellow}:${color:red}}}"
"${tls_version}${color:default})",
NULL, 0,
NULL, NULL, NULL,
&buflist_config_change_buflist, NULL, NULL,
NULL, NULL, NULL);
return 1;
}

View File

@ -58,6 +58,7 @@ extern struct t_config_option *buflist_config_format_lag;
extern struct t_config_option *buflist_config_format_name;
extern struct t_config_option *buflist_config_format_nick_prefix;
extern struct t_config_option *buflist_config_format_number;
extern struct t_config_option *buflist_config_format_tls_version;
extern char **buflist_config_sort_fields[BUFLIST_BAR_NUM_ITEMS];
extern int buflist_config_sort_fields_count[BUFLIST_BAR_NUM_ITEMS];

View File

@ -23,6 +23,8 @@
#include <stdio.h>
#include <string.h>
#include <gnutls/gnutls.h>
#include "../weechat-plugin.h"
#include "irc.h"
#include "irc-buffer.h"
@ -519,6 +521,65 @@ irc_bar_item_lag (const void *pointer, void *data,
return NULL;
}
/*
* Returns content of bar item "tls_version": bar item with TLS version value.
*/
char *
irc_bar_item_tls_version (const void *pointer, void *data,
struct t_gui_bar_item *item,
struct t_gui_window *window, struct t_gui_buffer *buffer,
struct t_hashtable *extra_info)
{
char buf[128];
struct t_irc_server *server;
gnutls_protocol_t version;
const char *color;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) item;
(void) window;
(void) extra_info;
if (!buffer)
return NULL;
irc_buffer_get_server_and_channel (buffer, &server, NULL);
if (server && server->is_connected)
{
if (server->ssl_connected)
{
version = gnutls_protocol_get_version (server->gnutls_sess);
switch (version)
{
case GNUTLS_TLS1_3:
color = IRC_COLOR_ITEM_TLS_VERSION_OK;
break;
case GNUTLS_TLS1_2:
color = IRC_COLOR_ITEM_TLS_VERSION_DEPRECATED;
break;
default:
color = IRC_COLOR_ITEM_TLS_VERSION_INSECURE;
}
snprintf (buf, sizeof (buf), "%s%s", color,
gnutls_protocol_get_name (version));
return strdup (buf);
}
else
{
snprintf (buf, sizeof (buf), "%s%s",
IRC_COLOR_ITEM_TLS_VERSION_INSECURE,
_("cleartext"));
return strdup (buf);
}
}
return NULL;
}
/*
* Returns content of bar item "input_prompt": bar item with input prompt.
*/
@ -775,6 +836,7 @@ irc_bar_item_buffer_switch (const void *pointer, void *data,
weechat_bar_item_update ("irc_nick");
weechat_bar_item_update ("irc_host");
weechat_bar_item_update ("irc_nick_host");
weechat_bar_item_update ("tls_version");
return WEECHAT_RC_OK;
}
@ -822,6 +884,8 @@ irc_bar_item_init ()
&irc_bar_item_nick_modes, NULL, NULL);
weechat_bar_item_new ("irc_nick_prefix",
&irc_bar_item_nick_prefix, NULL, NULL);
weechat_bar_item_new ("tls_version",
&irc_bar_item_tls_version, NULL, NULL);
weechat_hook_focus ("buffer_nicklist",
&irc_bar_item_focus_buffer_nicklist, NULL, NULL);

View File

@ -99,6 +99,9 @@
#define IRC_COLOR_ITEM_LAG_COUNTING weechat_color(weechat_config_string(irc_config_color_item_lag_counting))
#define IRC_COLOR_ITEM_LAG_FINISHED weechat_color(weechat_config_string(irc_config_color_item_lag_finished))
#define IRC_COLOR_ITEM_NICK_MODES weechat_color(weechat_config_string(irc_config_color_item_nick_modes))
#define IRC_COLOR_ITEM_TLS_VERSION_OK weechat_color(weechat_config_string(irc_config_color_item_tls_version_ok))
#define IRC_COLOR_ITEM_TLS_VERSION_DEPRECATED weechat_color(weechat_config_string(irc_config_color_item_tls_version_deprecated))
#define IRC_COLOR_ITEM_TLS_VERSION_INSECURE weechat_color(weechat_config_string(irc_config_color_item_tls_version_insecure))
struct t_irc_color_ansi_state
{

View File

@ -116,6 +116,9 @@ struct t_config_option *irc_config_color_item_channel_modes;
struct t_config_option *irc_config_color_item_lag_counting;
struct t_config_option *irc_config_color_item_lag_finished;
struct t_config_option *irc_config_color_item_nick_modes;
struct t_config_option *irc_config_color_item_tls_version_ok;
struct t_config_option *irc_config_color_item_tls_version_deprecated;
struct t_config_option *irc_config_color_item_tls_version_insecure;
struct t_config_option *irc_config_color_message_account;
struct t_config_option *irc_config_color_message_join;
struct t_config_option *irc_config_color_message_chghost;
@ -698,6 +701,22 @@ irc_config_change_color_item_nick_modes (const void *pointer, void *data,
weechat_bar_item_update ("irc_nick_modes");
}
/*
* Callback for changes on options "irc.color.item_tls_version_*".
*/
void
irc_config_change_color_item_tls_version (const void *pointer, void *data,
struct t_config_option *option)
{
/* make C compiler happy */
(void) pointer;
(void) data;
(void) option;
weechat_bar_item_update ("tls_version");
}
/*
* Callback for changes on option "irc.color.mirc_remap".
*/
@ -3228,6 +3247,30 @@ irc_config_init ()
NULL, NULL, NULL,
&irc_config_change_color_item_nick_modes, NULL, NULL,
NULL, NULL, NULL);
irc_config_color_item_tls_version_ok = weechat_config_new_option (
irc_config_file, ptr_section,
"item_tls_version_ok", "color",
N_("color for max supported TLS version in bar item \"tls_version\""),
NULL, -1, 0, "green", NULL, 0,
NULL, NULL, NULL,
&irc_config_change_color_item_tls_version, NULL, NULL,
NULL, NULL, NULL);
irc_config_color_item_tls_version_deprecated = weechat_config_new_option (
irc_config_file, ptr_section,
"item_tls_version_deprecated", "color",
N_("color for deprecated TLS versions in bar item \"tls_version\""),
NULL, -1, 0, "yellow", NULL, 0,
NULL, NULL, NULL,
&irc_config_change_color_item_tls_version, NULL, NULL,
NULL, NULL, NULL);
irc_config_color_item_tls_version_insecure = weechat_config_new_option (
irc_config_file, ptr_section,
"item_tls_version_insecure", "color",
N_("color for insecure TLS versions in bar item \"tls_version\""),
NULL, -1, 0, "red", NULL, 0,
NULL, NULL, NULL,
&irc_config_change_color_item_tls_version, NULL, NULL,
NULL, NULL, NULL);
irc_config_color_message_account = weechat_config_new_option (
irc_config_file, ptr_section,
"message_account", "color",

View File

@ -154,6 +154,9 @@ extern struct t_config_option *irc_config_color_item_channel_modes;
extern struct t_config_option *irc_config_color_item_lag_counting;
extern struct t_config_option *irc_config_color_item_lag_finished;
extern struct t_config_option *irc_config_color_item_nick_modes;
extern struct t_config_option *irc_config_color_item_tls_version_ok;
extern struct t_config_option *irc_config_color_item_tls_version_deprecated;
extern struct t_config_option *irc_config_color_item_tls_version_insecure;
extern struct t_config_option *irc_config_color_message_account;
extern struct t_config_option *irc_config_color_message_chghost;
extern struct t_config_option *irc_config_color_message_join;

View File

@ -2994,6 +2994,7 @@ IRC_PROTOCOL_CALLBACK(001)
server->is_connected = 1;
server->reconnect_delay = 0;
server->monitor_time = time (NULL) + 5;
irc_server_set_tls_version (server);
if (server->hook_timer_connection)
{

View File

@ -1118,6 +1118,37 @@ irc_server_set_lag (struct t_irc_server *server)
weechat_bar_item_update ("lag");
}
/*
* Sets tls_version in server buffer (local variable), update bar item
* "tls_version".
*/
void
irc_server_set_tls_version (struct t_irc_server *server)
{
gnutls_protocol_t version;
if (server->is_connected)
{
if (server->ssl_connected)
{
version = gnutls_protocol_get_version (server->gnutls_sess);
weechat_buffer_set (server->buffer, "localvar_set_tls_version",
gnutls_protocol_get_name (version));
}
else
{
weechat_buffer_set (server->buffer, "localvar_set_tls_version",
_("cleartext"));
}
}
else
{
weechat_buffer_set (server->buffer, "localvar_del_tls_version", "");
}
weechat_bar_item_update ("tls_version");
}
/*
* Gets prefix_modes for server (for example: "ohv").
*
@ -3732,6 +3763,8 @@ irc_server_close_connection (struct t_irc_server *server)
/* server is now disconnected */
server->is_connected = 0;
server->ssl_connected = 0;
irc_server_set_tls_version (server);
}
/*

View File

@ -323,6 +323,7 @@ extern const char *irc_server_get_chantypes (struct t_irc_server *server);
extern void irc_server_set_prefix_modes_chars (struct t_irc_server *server,
const char *prefix);
extern void irc_server_set_lag (struct t_irc_server *server);
extern void irc_server_set_tls_version (struct t_irc_server *server);
extern const char *irc_server_get_prefix_modes (struct t_irc_server *server);
extern const char *irc_server_get_prefix_chars (struct t_irc_server *server);
extern int irc_server_get_prefix_mode_index (struct t_irc_server *server,

View File

@ -391,6 +391,7 @@ xfer_chat_open_buffer (struct t_xfer *xfer)
weechat_buffer_set (xfer->buffer, "localvar_set_type", "private");
weechat_buffer_set (xfer->buffer, "localvar_set_nick", xfer->local_nick);
weechat_buffer_set (xfer->buffer, "localvar_set_channel", xfer->remote_nick);
weechat_buffer_set (xfer->buffer, "localvar_set_tls_version", _("cleartext"));
weechat_buffer_set (xfer->buffer, "highlight_words_add", "$nick");
}