1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-25 04:16:38 +02:00

relay: add check and change callbacks for remote option "url"

This commit is contained in:
Sébastien Helleu
2024-04-14 14:58:26 +02:00
parent 252787c457
commit e1b1946ee4
3 changed files with 87 additions and 4 deletions
+70 -1
View File
@@ -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 (
+15 -3
View File
@@ -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++;
+2
View File
@@ -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,