From c4c220f0a32d27836871c55d5fc77b30ddef7781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 30 Mar 2024 11:02:22 +0100 Subject: [PATCH] relay: add proxy option in remote (issue #2066) --- src/plugins/relay/relay-command.c | 21 +++++++++++---------- src/plugins/relay/relay-config.c | 9 +++++++++ src/plugins/relay/relay-remote.c | 11 +++++++---- src/plugins/relay/relay-remote.h | 2 ++ 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/plugins/relay/relay-command.c b/src/plugins/relay/relay-command.c index edcbdffab..0279b9b07 100644 --- a/src/plugins/relay/relay-command.c +++ b/src/plugins/relay/relay-command.c @@ -427,7 +427,7 @@ relay_command_remote (const void *pointer, void *data, { struct t_relay_remote *ptr_remote, *ptr_remote2; int i, detailed_list, one_remote_found; - const char *ptr_password, *ptr_totp_secret; + const char *ptr_proxy, *ptr_password, *ptr_totp_secret; char *remote_name; /* make C compiler happy */ @@ -533,12 +533,17 @@ relay_command_remote (const void *pointer, void *data, return WEECHAT_RC_OK; } + ptr_proxy = NULL; ptr_password = NULL; ptr_totp_secret = NULL; for (i = 4; i < argc; i++) { - if (strncmp (argv[i], "-password=", 10) == 0) + if (strncmp (argv[i], "-proxy=", 7) == 0) + { + ptr_proxy = argv[i] + 7; + } + else if (strncmp (argv[i], "-password=", 10) == 0) { ptr_password = argv[i] + 10; } @@ -557,12 +562,8 @@ relay_command_remote (const void *pointer, void *data, } } - ptr_remote = relay_remote_new ( - argv[2], - argv[3], - (ptr_password) ? ptr_password : "", - (ptr_totp_secret) ? ptr_totp_secret : ""); - + ptr_remote = relay_remote_new (argv[2], argv[3], ptr_proxy, + ptr_password, ptr_totp_secret); if (ptr_remote) { weechat_printf (NULL, _("Remote \"%s\" created"), argv[2]); @@ -790,7 +791,7 @@ relay_command_init () "options: relay.remote.name.xxx"), N_("url: URL of the remote, format is https://example.com:9000 " "or http://example.com:9000 (plain-text connection, not recommended)"), - N_("option: set option for remote: password or totp_secret"), + N_("option: set option for remote: proxy, password or totp_secret"), N_("raw[connect]: connect to a remote relay server"), N_("raw[rename]: rename a remote relay server"), N_("raw[del]: delete a remote relay server"), @@ -806,7 +807,7 @@ relay_command_init () "list %(relay_remotes)" " || listfull %(relay_remotes)" " || add %(relay_remotes) https://localhost:9000 " - "-password=${xxx}|-totp_secret=${xxx}|%*" + "-password=${xxx}|-proxy=xxx|-totp_secret=${xxx}|%*" " || connect %(relay_remotes)" " || rename %(relay_remotes) %(relay_remotes)" " || del %(relay_remotes)", diff --git a/src/plugins/relay/relay-config.c b/src/plugins/relay/relay-config.c index c37669af3..e0f6aacae 100644 --- a/src/plugins/relay/relay-config.c +++ b/src/plugins/relay/relay-config.c @@ -997,6 +997,15 @@ relay_config_create_remote_option (const char *remote_name, int index_option, NULL, 0, 0, value, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); break; + case RELAY_REMOTE_OPTION_PROXY: + ptr_option = weechat_config_new_option ( + relay_config_file, relay_config_section_remote, + option_name, "string", + N_("name of proxy used for this remote (optional, proxy must " + "be defined with command /proxy)"), + NULL, 0, 0, value, NULL, 0, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + break; case RELAY_REMOTE_OPTION_PASSWORD: ptr_option = weechat_config_new_option ( relay_config_file, relay_config_section_remote, diff --git a/src/plugins/relay/relay-remote.c b/src/plugins/relay/relay-remote.c index b10222977..6924b76ab 100644 --- a/src/plugins/relay/relay-remote.c +++ b/src/plugins/relay/relay-remote.c @@ -38,9 +38,9 @@ char *relay_remote_option_string[RELAY_REMOTE_NUM_OPTIONS] = -{ "url", "password", "totp_secret" }; +{ "url", "proxy", "password", "totp_secret" }; char *relay_remote_option_default[RELAY_REMOTE_NUM_OPTIONS] = -{ "", "", "" }; +{ "", "", "", "" }; struct t_relay_remote *relay_remotes = NULL; struct t_relay_remote *last_relay_remote = NULL; @@ -362,8 +362,8 @@ relay_remote_new_with_options (const char *name, struct t_config_option **option */ struct t_relay_remote * -relay_remote_new (const char *name, const char *url, const char *password, - const char *totp_secret) +relay_remote_new (const char *name, const char *url, const char *proxy, + const char *password, const char *totp_secret) { struct t_config_option *option[RELAY_REMOTE_NUM_OPTIONS]; const char *value[RELAY_REMOTE_NUM_OPTIONS]; @@ -378,6 +378,7 @@ relay_remote_new (const char *name, const char *url, const char *password, return NULL; value[RELAY_REMOTE_OPTION_URL] = url; + value[RELAY_REMOTE_OPTION_PROXY] = proxy; value[RELAY_REMOTE_OPTION_PASSWORD] = password; value[RELAY_REMOTE_OPTION_TOTP_SECRET] = totp_secret; @@ -659,6 +660,8 @@ relay_remote_print_log () weechat_log_printf (" name. . . . . . . . . : '%s'", ptr_remote->name); weechat_log_printf (" url . . . . . . . . . : '%s'", weechat_config_string (ptr_remote->options[RELAY_REMOTE_OPTION_URL])); + weechat_log_printf (" proxy . . . . . . . . : '%s'", + weechat_config_string (ptr_remote->options[RELAY_REMOTE_OPTION_PROXY])); weechat_log_printf (" password. . . . . . . : '%s'", weechat_config_string (ptr_remote->options[RELAY_REMOTE_OPTION_PASSWORD])); weechat_log_printf (" totp_secret . . . . . : '%s'", diff --git a/src/plugins/relay/relay-remote.h b/src/plugins/relay/relay-remote.h index aa7b69e6e..2e6b938dc 100644 --- a/src/plugins/relay/relay-remote.h +++ b/src/plugins/relay/relay-remote.h @@ -25,6 +25,7 @@ enum t_relay_remote_option { RELAY_REMOTE_OPTION_URL = 0, /* remote URL */ + RELAY_REMOTE_OPTION_PROXY, /* proxy used for remote (optional) */ RELAY_REMOTE_OPTION_PASSWORD, /* password for remote relay */ RELAY_REMOTE_OPTION_TOTP_SECRET, /* TOTP secret for remote relay */ /* number of relay remote options */ @@ -68,6 +69,7 @@ extern void relay_remote_add (struct t_relay_remote *remote, extern struct t_relay_remote *relay_remote_new_with_options (const char *name, struct t_config_option **options); extern struct t_relay_remote *relay_remote_new (const char *name, + const char *proxy, const char *url, const char *password, const char *totp_secret);