diff --git a/src/plugins/relay/relay-config.c b/src/plugins/relay/relay-config.c index 51453a3cb..d2511267a 100644 --- a/src/plugins/relay/relay-config.c +++ b/src/plugins/relay/relay-config.c @@ -962,6 +962,73 @@ relay_config_create_option_port_path (const void *pointer, void *data, return rc; } +/* + * Gets remote pointer with name of option. + */ + +struct t_relay_remote * +relay_config_get_remote_from_option_name (const char *name) +{ + struct t_relay_remote *ptr_remote; + char *pos_option, *remote_name; + + ptr_remote = NULL; + + if (name) + { + pos_option = strrchr (name, '.'); + if (pos_option) + { + remote_name = weechat_strndup (name, pos_option - name); + if (remote_name) + { + ptr_remote = relay_remote_search (remote_name); + free (remote_name); + } + } + } + + return ptr_remote; +} + +/* + * Callback called to check a server option when it is modified. + */ + +int +relay_config_remote_url_check_value_cb (const void *pointer, void *data, + struct t_config_option *option, + const char *value) +{ + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) option; + + return relay_remote_url_valid (value); +} + +/* + * Callback called when a remote URL option is modified. + */ + +void +relay_config_remote_url_change_cb (const void *pointer, void *data, + struct t_config_option *option) +{ + struct t_relay_remote *ptr_remote; + char *name; + + /* make C compiler happy */ + (void) pointer; + (void) data; + + name = weechat_config_option_get_pointer (option, "name"); + ptr_remote = relay_config_get_remote_from_option_name (name); + if (ptr_remote) + relay_remote_set_url (ptr_remote, weechat_config_string (option)); +} + /* * Creates an option for a remote. * @@ -997,7 +1064,9 @@ relay_config_create_remote_option (const char *remote_name, int index_option, "examples: https://example.com:9000 or http://example.com:9000 " "(plain-text connection, not recommended)"), NULL, 0, 0, value, NULL, 0, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + &relay_config_remote_url_check_value_cb, NULL, NULL, + &relay_config_remote_url_change_cb, NULL, NULL, + NULL, NULL, NULL); break; case RELAY_REMOTE_OPTION_PROXY: ptr_option = weechat_config_new_option ( diff --git a/src/plugins/relay/relay-remote.c b/src/plugins/relay/relay-remote.c index 7fb67cd44..57a2760d8 100644 --- a/src/plugins/relay/relay-remote.c +++ b/src/plugins/relay/relay-remote.c @@ -392,6 +392,19 @@ relay_remote_add (struct t_relay_remote *remote, } } +/* + * Sets URL in a remote. + */ + +void +relay_remote_set_url (struct t_relay_remote *remote, const char *url) +{ + if (remote->address) + free (remote->address); + remote->address = relay_remote_get_address (url); + remote->port = relay_remote_get_port (url); +} + /* * Creates a new remote with options. * @@ -419,9 +432,8 @@ relay_remote_new_with_options (const char *name, struct t_config_option **option new_remote->options[i] = options[i]; } relay_remote_add (new_remote, &relay_remotes, &last_relay_remote); - new_remote->address = relay_remote_get_address ( - weechat_config_string (new_remote->options[RELAY_REMOTE_OPTION_URL])); - new_remote->port = relay_remote_get_port ( + relay_remote_set_url ( + new_remote, weechat_config_string (new_remote->options[RELAY_REMOTE_OPTION_URL])); relay_remotes_count++; diff --git a/src/plugins/relay/relay-remote.h b/src/plugins/relay/relay-remote.h index 2e3719867..30c408946 100644 --- a/src/plugins/relay/relay-remote.h +++ b/src/plugins/relay/relay-remote.h @@ -80,6 +80,8 @@ extern struct t_relay_remote *relay_remote_alloc (const char *name); extern void relay_remote_add (struct t_relay_remote *remote, struct t_relay_remote **list_remotes, struct t_relay_remote **last_list_remote); +extern void relay_remote_set_url (struct t_relay_remote *remote, + const char *url); 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,