1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

core: convert proxy option ipv6 from boolean to enum (disable, auto, force) (issue #2164)

This commit is contained in:
Sébastien Helleu
2024-08-04 23:43:05 +02:00
parent 5fe3b38892
commit 4e1a0731e7
7 changed files with 102 additions and 13 deletions
+1
View File
@@ -10,6 +10,7 @@
- **breaking:** irc: rename parameter `-re` to `-raw` in command `/list` ([#2124](https://github.com/weechat/weechat/issues/2124))
- **breaking:** api: add constants for IPv6 and allow force of IPv6 in function hook_connect ([#2164](https://github.com/weechat/weechat/issues/2164))
- **breaking:** irc: convert server option `ipv6` from boolean to enum (disable, auto, force) ([#2164](https://github.com/weechat/weechat/issues/2164))
- **breaking:** core: convert proxy option `ipv6` from boolean to enum (disable, auto, force) ([#2164](https://github.com/weechat/weechat/issues/2164))
- core: add option `addreplace` in commands `/bar` and `/proxy` ([#2095](https://github.com/weechat/weechat/issues/2095))
- irc: add option `addreplace` in commands `/ignore`, `/notify` and `/server` ([#2095](https://github.com/weechat/weechat/issues/2095))
- relay: add option `addreplace` in commands `/relay` and `/remote` ([#2095](https://github.com/weechat/weechat/issues/2095))
+20 -4
View File
@@ -5492,6 +5492,7 @@ void
command_proxy_list ()
{
struct t_proxy *ptr_proxy;
const char *ipv6_status;
if (weechat_proxies)
{
@@ -5500,6 +5501,21 @@ command_proxy_list ()
for (ptr_proxy = weechat_proxies; ptr_proxy;
ptr_proxy = ptr_proxy->next_proxy)
{
switch (CONFIG_ENUM(ptr_proxy->options[PROXY_OPTION_IPV6]))
{
case PROXY_IPV6_DISABLE:
ipv6_status = _("IPv6: disabled");
break;
case PROXY_IPV6_AUTO:
ipv6_status = _("IPv6: automatic");
break;
case PROXY_IPV6_FORCE:
ipv6_status = _("IPv6: forced");
break;
default:
ipv6_status = NULL;
break;
}
gui_chat_printf (NULL,
_(" %s%s%s: %s, %s/%d (%s), username: %s, "
"password: %s"),
@@ -5509,7 +5525,7 @@ command_proxy_list ()
proxy_type_string[CONFIG_ENUM(ptr_proxy->options[PROXY_OPTION_TYPE])],
CONFIG_STRING(ptr_proxy->options[PROXY_OPTION_ADDRESS]),
CONFIG_INTEGER(ptr_proxy->options[PROXY_OPTION_PORT]),
(CONFIG_INTEGER(ptr_proxy->options[PROXY_OPTION_IPV6])) ? "IPv6" : "IPv4",
(ipv6_status) ? ipv6_status : "?",
(CONFIG_STRING(ptr_proxy->options[PROXY_OPTION_USERNAME]) &&
CONFIG_STRING(ptr_proxy->options[PROXY_OPTION_USERNAME])[0]) ?
CONFIG_STRING(ptr_proxy->options[PROXY_OPTION_USERNAME]) : _("(none)"),
@@ -5583,7 +5599,7 @@ COMMAND_CALLBACK(proxy)
if (error && !error[0])
{
/* add proxy */
if (proxy_new (argv[2], argv[3], "off", argv[4], argv[5],
if (proxy_new (argv[2], argv[3], "disable", argv[4], argv[5],
(argc >= 7) ? argv[6] : NULL,
(argc >= 8) ? argv_eol[7] : NULL))
{
@@ -9185,9 +9201,9 @@ command_init ()
N_("Examples:"),
N_(" add a http proxy, running on local host, port 8888:"),
AI(" /proxy add local http 127.0.0.1 8888"),
N_(" add a http proxy using IPv6 protocol:"),
N_(" add a http proxy using IPv6 protocol only:"),
AI(" /proxy add local http ::1 8888"),
AI(" /proxy set local ipv6 on"),
AI(" /proxy set local ipv6 force"),
N_(" add a socks5 proxy with username/password:"),
AI(" /proxy add myproxy socks5 sample.host.org 3128 myuser mypass"),
N_(" delete a proxy:"),
+42 -1
View File
@@ -1652,7 +1652,7 @@ config_weechat_update_cb (const void *pointer, void *data,
{ "number_desc" "-buffer.number" },
{ NULL, NULL },
};
char *new_option;
char *new_option, *new_value, *pos_option;
int changes, i;
/* make C compiler happy */
@@ -1806,6 +1806,47 @@ config_weechat_update_cb (const void *pointer, void *data,
}
}
if (version_read < 4)
{
/*
* changes in v4 (WeeChat 4.4.0):
* - proxy option "ipv6" is converted from boolean to enum:
* - "on" -> "auto"
* - "off" -> "disable"
* (new possible value "force" is not set by this function)
*/
ptr_config = hashtable_get (data_read, "config");
ptr_section = hashtable_get (data_read, "section");
ptr_option = hashtable_get (data_read, "option");
ptr_value = hashtable_get (data_read, "value");
if (ptr_section
&& ptr_option
&& (strcmp (ptr_section, "proxy") == 0)
&& ptr_value)
{
pos_option = strrchr (ptr_option, '.');
if (pos_option && (strcmp (pos_option + 1, "ipv6") == 0))
{
new_value = (strcmp (ptr_value, "off") == 0) ?
strdup ("disable") : strdup ("auto");
if (new_value)
{
gui_chat_printf (
NULL,
_("Value of option \"%s.%s.%s\" has been converted: \"%s\" => \"%s\""),
ptr_config,
ptr_section,
ptr_option,
ptr_value,
new_value);
hashtable_set (data_read, "value", new_value);
changes++;
free (new_value);
}
}
}
}
return (changes) ? data_read : NULL;
}
+1 -1
View File
@@ -31,7 +31,7 @@ struct t_gui_buffer;
#define WEECHAT_CONFIG_NAME "weechat"
#define WEECHAT_CONFIG_PRIO_NAME "110000|weechat"
#define WEECHAT_CONFIG_VERSION 3
#define WEECHAT_CONFIG_VERSION 4
#define TAB_MAX_WIDTH 64
+19 -2
View File
@@ -994,8 +994,25 @@ network_connect_child (struct t_hook *hook_connect)
res_init ();
if (ptr_proxy)
{
hints.ai_family = (CONFIG_BOOLEAN(ptr_proxy->options[PROXY_OPTION_IPV6])) ?
AF_UNSPEC : AF_INET;
switch (CONFIG_ENUM(ptr_proxy->options[PROXY_OPTION_IPV6]))
{
case PROXY_IPV6_DISABLE:
/* force IPv4 */
hints.ai_family = AF_INET;
break;
case PROXY_IPV6_AUTO:
/* auto: IPv6 / IPv4 */
hints.ai_family = AF_UNSPEC;
break;
case PROXY_IPV6_FORCE:
/* force IPv6 */
hints.ai_family = AF_INET6;
break;
default:
/* auto by default */
hints.ai_family = AF_UNSPEC;
break;
}
snprintf (port, sizeof (port), "%d", CONFIG_INTEGER(ptr_proxy->options[PROXY_OPTION_PORT]));
rc = getaddrinfo (CONFIG_STRING(ptr_proxy->options[PROXY_OPTION_ADDRESS]),
port, &hints, &res_remote);
+9 -5
View File
@@ -40,9 +40,11 @@
char *proxy_option_string[PROXY_NUM_OPTIONS] =
{ "type", "ipv6", "address", "port", "username", "password" };
char *proxy_option_default[PROXY_NUM_OPTIONS] =
{ "http", "off", "127.0.0.1", "3128", "", "" };
{ "http", "auto", "127.0.0.1", "3128", "", "" };
char *proxy_type_string[PROXY_NUM_TYPES] =
{ "http", "socks4", "socks5" };
char *proxy_ipv6_string[PROXY_NUM_IPV6] =
{ "disable", "auto", "force" };
struct t_proxy *weechat_proxies = NULL; /* first proxy */
struct t_proxy *last_weechat_proxy = NULL; /* last proxy */
@@ -279,9 +281,9 @@ proxy_create_option (const char *proxy_name, int index_option,
case PROXY_OPTION_IPV6:
ptr_option = config_file_new_option (
weechat_config_file, weechat_config_section_proxy,
option_name, "boolean",
N_("connect to proxy using ipv6"),
NULL, 0, 0, value, NULL, 0,
option_name, "enum",
N_("connect to proxy using IPv6"),
"disable|auto|force", 0, 0, value, NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
break;
case PROXY_OPTION_ADDRESS:
@@ -660,7 +662,9 @@ proxy_print_log ()
log_printf (" type . . . . . . . . . : %d (%s)",
CONFIG_ENUM(ptr_proxy->options[PROXY_OPTION_TYPE]),
proxy_type_string[CONFIG_ENUM(ptr_proxy->options[PROXY_OPTION_TYPE])]);
log_printf (" ipv6 . . . . . . . . . : %d", CONFIG_INTEGER(ptr_proxy->options[PROXY_OPTION_IPV6]));
log_printf (" ipv6 . . . . . . . . . : %d (%s)",
CONFIG_ENUM(ptr_proxy->options[PROXY_OPTION_IPV6]),
proxy_ipv6_string[CONFIG_ENUM(ptr_proxy->options[PROXY_OPTION_IPV6])]);
log_printf (" address. . . . . . . . : '%s'", CONFIG_STRING(ptr_proxy->options[PROXY_OPTION_ADDRESS]));
log_printf (" port . . . . . . . . . : %d", CONFIG_INTEGER(ptr_proxy->options[PROXY_OPTION_PORT]));
log_printf (" username . . . . . . . : '%s'", CONFIG_STRING(ptr_proxy->options[PROXY_OPTION_USERNAME]));
+10
View File
@@ -43,6 +43,15 @@ enum t_proxy_type
PROXY_NUM_TYPES,
};
enum t_proxy_ipv6
{
PROXY_IPV6_DISABLE = 0,
PROXY_IPV6_AUTO,
PROXY_IPV6_FORCE,
/* number of IPv6 options */
PROXY_NUM_IPV6,
};
struct t_proxy
{
char *name; /* proxy name */
@@ -56,6 +65,7 @@ struct t_proxy
extern char *proxy_option_string[];
extern char *proxy_type_string[];
extern char *proxy_ipv6_string[];
extern struct t_proxy *weechat_proxies;
extern struct t_proxy *last_weechat_proxy;
extern struct t_proxy *weechat_temp_proxies;