mirror of
https://github.com/weechat/weechat.git
synced 2026-07-07 02:03:13 +02:00
irc: add option "cap" in servers to enable capabilities on connection
This commit is contained in:
@@ -1446,6 +1446,21 @@ irc_config_server_new_option (struct t_config_file *config_file,
|
||||
callback_change, callback_change_data,
|
||||
NULL, NULL);
|
||||
break;
|
||||
case IRC_SERVER_OPTION_CAP:
|
||||
new_option = weechat_config_new_option (
|
||||
config_file, section,
|
||||
option_name, "string",
|
||||
/* TRANSLATORS: please keep word "capabilities" between brackets if translation is different (see fr.po) */
|
||||
N_("comma-separated list of capabilities to enable for server "
|
||||
"if they are available (example: "
|
||||
"\"multi-prefix,extended-join\")"),
|
||||
NULL, 0, 0,
|
||||
default_value, value,
|
||||
null_value_allowed,
|
||||
callback_check_value, callback_check_value_data,
|
||||
callback_change, callback_change_data,
|
||||
NULL, NULL);
|
||||
break;
|
||||
case IRC_SERVER_OPTION_SASL_MECHANISM:
|
||||
new_option = weechat_config_new_option (
|
||||
config_file, section,
|
||||
|
||||
@@ -253,6 +253,14 @@ irc_display_server (struct t_irc_server *server, int with_detail)
|
||||
weechat_printf (NULL, " password . . . . . . : %s%s",
|
||||
IRC_COLOR_CHAT_VALUE,
|
||||
_("(hidden)"));
|
||||
/* cap (capabilities) */
|
||||
if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_CAP]))
|
||||
weechat_printf (NULL, " cap. . . . . . . . . : ('%s')",
|
||||
IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_CAP));
|
||||
else
|
||||
weechat_printf (NULL, " cap. . . . . . . . . : %s'%s'",
|
||||
IRC_COLOR_CHAT_VALUE,
|
||||
weechat_config_string (server->options[IRC_SERVER_OPTION_CAP]));
|
||||
/* sasl_mechanism */
|
||||
if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_SASL_MECHANISM]))
|
||||
weechat_printf (NULL, " sasl_mechanism . . . : ('%s')",
|
||||
|
||||
@@ -196,8 +196,10 @@ IRC_PROTOCOL_CALLBACK(authenticate)
|
||||
|
||||
IRC_PROTOCOL_CALLBACK(cap)
|
||||
{
|
||||
char *ptr_caps, **items;
|
||||
int num_items, sasl, i, timeout;
|
||||
char *ptr_caps, **caps_supported, **caps_requested, *cap_option, *cap_req;
|
||||
const char *ptr_cap_option;
|
||||
int num_caps_supported, num_caps_requested, sasl_requested, sasl_to_do;
|
||||
int i, j, timeout, length;
|
||||
|
||||
/*
|
||||
* CAP message looks like:
|
||||
@@ -218,35 +220,79 @@ IRC_PROTOCOL_CALLBACK(cap)
|
||||
weechat_prefix ("network"),
|
||||
IRC_PLUGIN_NAME,
|
||||
ptr_caps);
|
||||
sasl = 0;
|
||||
items = weechat_string_split (ptr_caps, " ", 0, 0, &num_items);
|
||||
if (items)
|
||||
|
||||
/* auto-enable capabilities only when connecting to server */
|
||||
if (!server->is_connected)
|
||||
{
|
||||
for (i = 0; i < num_items; i++)
|
||||
sasl_requested = irc_server_sasl_enabled (server);
|
||||
sasl_to_do = 0;
|
||||
ptr_cap_option = IRC_SERVER_OPTION_STRING(server,
|
||||
IRC_SERVER_OPTION_CAP);
|
||||
length = ((ptr_cap_option && ptr_cap_option[0]) ? strlen (ptr_cap_option) : 0) + 16;
|
||||
cap_option = malloc (length);
|
||||
cap_req = malloc (length);
|
||||
if (cap_option && cap_req)
|
||||
{
|
||||
if (strcmp (items[i], "sasl") == 0)
|
||||
cap_option[0] = '\0';
|
||||
if (ptr_cap_option && ptr_cap_option[0])
|
||||
strcat (cap_option, ptr_cap_option);
|
||||
if (sasl_requested)
|
||||
{
|
||||
sasl = 1;
|
||||
break;
|
||||
if (cap_option[0])
|
||||
strcat (cap_option, ",");
|
||||
strcat (cap_option, "sasl");
|
||||
}
|
||||
cap_req[0] = '\0';
|
||||
caps_requested = weechat_string_split (cap_option, ",", 0, 0,
|
||||
&num_caps_requested);
|
||||
caps_supported = weechat_string_split (ptr_caps, " ", 0, 0,
|
||||
&num_caps_supported);
|
||||
if (caps_requested && caps_supported)
|
||||
{
|
||||
for (i = 0; i < num_caps_requested; i++)
|
||||
{
|
||||
for (j = 0; j < num_caps_supported; j++)
|
||||
{
|
||||
if (weechat_strcasecmp (caps_requested[i],
|
||||
caps_supported[j]) == 0)
|
||||
{
|
||||
if (strcmp (caps_requested[i], "sasl") == 0)
|
||||
sasl_to_do = 1;
|
||||
if (cap_req[0])
|
||||
strcat (cap_req, " ");
|
||||
strcat (cap_req, caps_supported[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (caps_requested)
|
||||
weechat_string_free_split (caps_requested);
|
||||
if (caps_supported)
|
||||
weechat_string_free_split (caps_supported);
|
||||
if (cap_req[0])
|
||||
{
|
||||
weechat_printf (server->buffer,
|
||||
_("%s%s: client capability, requesting: %s"),
|
||||
weechat_prefix ("network"),
|
||||
IRC_PLUGIN_NAME,
|
||||
cap_req);
|
||||
irc_server_sendf (server, 0, NULL,
|
||||
"CAP REQ :%s", cap_req);
|
||||
}
|
||||
if (!sasl_to_do)
|
||||
irc_server_sendf (server, 0, NULL, "CAP END");
|
||||
if (sasl_requested && !sasl_to_do)
|
||||
{
|
||||
weechat_printf (server->buffer,
|
||||
_("%s%s: client capability: sasl not supported"),
|
||||
weechat_prefix ("network"),
|
||||
IRC_PLUGIN_NAME);
|
||||
}
|
||||
}
|
||||
weechat_string_free_split (items);
|
||||
}
|
||||
if (sasl)
|
||||
{
|
||||
weechat_printf (server->buffer,
|
||||
_("%s%s: client capability, requesting: sasl"),
|
||||
weechat_prefix ("network"),
|
||||
IRC_PLUGIN_NAME);
|
||||
irc_server_sendf (server, 0, NULL, "CAP REQ :sasl");
|
||||
}
|
||||
else
|
||||
{
|
||||
weechat_printf (server->buffer,
|
||||
_("%s%s: client capability: sasl not supported"),
|
||||
weechat_prefix ("network"),
|
||||
IRC_PLUGIN_NAME);
|
||||
irc_server_sendf (server, 0, NULL, "CAP END");
|
||||
if (cap_option)
|
||||
free (cap_option);
|
||||
if (cap_req)
|
||||
free (cap_req);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -259,7 +305,22 @@ IRC_PROTOCOL_CALLBACK(cap)
|
||||
_("%s%s: client capability, enabled: %s"),
|
||||
weechat_prefix ("network"), IRC_PLUGIN_NAME,
|
||||
ptr_caps);
|
||||
if (strcmp (ptr_caps, "sasl") == 0)
|
||||
sasl_to_do = 0;
|
||||
caps_supported = weechat_string_split (ptr_caps, " ", 0, 0,
|
||||
&num_caps_supported);
|
||||
if (caps_supported)
|
||||
{
|
||||
for (i = 0; i < num_caps_supported; i++)
|
||||
{
|
||||
if (strcmp (caps_supported[i], "sasl") == 0)
|
||||
{
|
||||
sasl_to_do = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
weechat_string_free_split (caps_supported);
|
||||
}
|
||||
if (sasl_to_do)
|
||||
{
|
||||
switch (IRC_SERVER_OPTION_INTEGER(server,
|
||||
IRC_SERVER_OPTION_SASL_MECHANISM))
|
||||
|
||||
@@ -68,7 +68,8 @@ struct t_irc_message *irc_msgq_last_msg = NULL;
|
||||
char *irc_server_option_string[IRC_SERVER_NUM_OPTIONS] =
|
||||
{ "addresses", "proxy", "ipv6",
|
||||
"ssl", "ssl_cert", "ssl_priorities", "ssl_dhkey_size", "ssl_verify",
|
||||
"password", "sasl_mechanism", "sasl_username", "sasl_password", "sasl_timeout",
|
||||
"password", "cap",
|
||||
"sasl_mechanism", "sasl_username", "sasl_password", "sasl_timeout",
|
||||
"autoconnect", "autoreconnect", "autoreconnect_delay",
|
||||
"nicks", "username", "realname", "local_hostname",
|
||||
"command", "command_delay", "autojoin", "autorejoin", "autorejoin_delay",
|
||||
@@ -82,7 +83,8 @@ char *irc_server_option_string[IRC_SERVER_NUM_OPTIONS] =
|
||||
char *irc_server_option_default[IRC_SERVER_NUM_OPTIONS] =
|
||||
{ "", "", "off",
|
||||
"off", "", "NORMAL", "2048", "on",
|
||||
"", "plain", "", "", "15",
|
||||
"", "",
|
||||
"plain", "", "", "15",
|
||||
"off", "on", "10",
|
||||
"", "", "", "",
|
||||
"", "0", "", "off", "30",
|
||||
@@ -2707,11 +2709,12 @@ irc_server_reconnect_schedule (struct t_irc_server *server)
|
||||
void
|
||||
irc_server_login (struct t_irc_server *server)
|
||||
{
|
||||
const char *password, *username, *realname;
|
||||
const char *password, *username, *realname, *cap;
|
||||
|
||||
password = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PASSWORD);
|
||||
username = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_USERNAME);
|
||||
realname = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_REALNAME);
|
||||
cap = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_CAP);
|
||||
|
||||
if (password && password[0])
|
||||
irc_server_sendf (server, 0, NULL, "PASS %s", password);
|
||||
@@ -2726,7 +2729,7 @@ irc_server_login (struct t_irc_server *server)
|
||||
else
|
||||
server->nick_first_tried = irc_server_get_nick_index (server);
|
||||
|
||||
if (irc_server_sasl_enabled (server))
|
||||
if (irc_server_sasl_enabled (server) || (cap && cap[0]))
|
||||
{
|
||||
irc_server_sendf (server, 0, NULL, "CAP LS");
|
||||
}
|
||||
@@ -4305,6 +4308,9 @@ irc_server_add_to_infolist (struct t_infolist *infolist,
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "password",
|
||||
IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PASSWORD)))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "cap",
|
||||
IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_CAP)))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "sasl_mechanism",
|
||||
IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_SASL_MECHANISM)))
|
||||
return 0;
|
||||
@@ -4522,6 +4528,13 @@ irc_server_print_log ()
|
||||
weechat_log_printf (" password . . . . . . : null");
|
||||
else
|
||||
weechat_log_printf (" password . . . . . . : (hidden)");
|
||||
/* cap (capabilities) */
|
||||
if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_CAP]))
|
||||
weechat_log_printf (" cap. . . . . . . . . : null ('%s')",
|
||||
IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_CAP));
|
||||
else
|
||||
weechat_log_printf (" cap. . . . . . . . . : '%s'",
|
||||
weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_CAP]));
|
||||
/* sasl_mechanism */
|
||||
if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_SASL_MECHANISM]))
|
||||
weechat_log_printf (" sasl_mechanism . . . : null ('%s')",
|
||||
|
||||
@@ -42,6 +42,7 @@ enum t_irc_server_option
|
||||
IRC_SERVER_OPTION_SSL_DHKEY_SIZE, /* Diffie Hellman key size */
|
||||
IRC_SERVER_OPTION_SSL_VERIFY, /* check if the connection is trusted */
|
||||
IRC_SERVER_OPTION_PASSWORD, /* password for server */
|
||||
IRC_SERVER_OPTION_CAP, /* capabilities to enable on server */
|
||||
IRC_SERVER_OPTION_SASL_MECHANISM,/* mechanism for SASL authentication */
|
||||
IRC_SERVER_OPTION_SASL_USERNAME, /* username for SASL authentication */
|
||||
IRC_SERVER_OPTION_SASL_PASSWORD, /* password for SASL authentication */
|
||||
|
||||
Reference in New Issue
Block a user