mirror of
https://github.com/weechat/weechat.git
synced 2026-07-03 00:03:12 +02:00
irc, buflist: add bar item "tls_version" with options for colors, add buflist format "${format_tls_version}" (issue #1622)
This commit is contained in:
committed by
Sébastien Helleu
parent
670c5cd745
commit
94c902adfc
@@ -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);
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user