diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2019-05-12 21:30:02 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2019-05-12 21:39:22 +0200 |
commit | ade52cdc7d7c7257a2f3970b8aac7e1ba1530da6 (patch) | |
tree | 6014b4c7d48f64d465b95841b2d5132b77f29fe2 /src/plugins/relay | |
parent | eacc08f2e1a8354e885f34b1105d87ec43bca9da (diff) | |
download | weechat-ade52cdc7d7c7257a2f3970b8aac7e1ba1530da6.zip |
relay: fix update of port/path variables in relay server when options relay.port.* and relay.path.* are changed with /set
Diffstat (limited to 'src/plugins/relay')
-rw-r--r-- | src/plugins/relay/relay-config.c | 45 | ||||
-rw-r--r-- | src/plugins/relay/relay-server.c | 22 | ||||
-rw-r--r-- | src/plugins/relay/relay-server.h | 2 |
3 files changed, 67 insertions, 2 deletions
diff --git a/src/plugins/relay/relay-config.c b/src/plugins/relay/relay-config.c index 6ee4b213d..85cd3057d 100644 --- a/src/plugins/relay/relay-config.c +++ b/src/plugins/relay/relay-config.c @@ -577,6 +577,47 @@ relay_config_check_path_cb (const void *pointer, void *data, } /* + * Callback for changes on options in section "path". + */ + +void +relay_config_change_path_cb (const void *pointer, void *data, + struct t_config_option *option) +{ + struct t_relay_server *ptr_server; + + /* make C compiler happy */ + (void) pointer; + (void) data; + + ptr_server = relay_server_search (weechat_config_option_get_pointer (option, "name")); + if (ptr_server) + { + relay_server_update_path (ptr_server, + (const char *)weechat_config_option_get_pointer (option, "value")); + } +} + +/* + * Callback called when an option is deleted in section "path". + */ + +void +relay_config_delete_path_cb (const void *pointer, void *data, + struct t_config_option *option) +{ + struct t_relay_server *ptr_server; + + /* make C compiler happy */ + (void) pointer; + (void) data; + + ptr_server = relay_server_search (weechat_config_option_get_pointer (option, "name")); + if (ptr_server) + relay_server_free (ptr_server); +} + +/* * Callback for changes on options in section "port". */ @@ -726,8 +767,8 @@ relay_config_create_option_port_path (const void *pointer, void *data, option_name, "string", NULL, NULL, 0, 0, "", value, 0, &relay_config_check_path_cb, NULL, NULL, - &relay_config_change_port_cb, NULL, NULL, - &relay_config_delete_port_cb, NULL, NULL); + &relay_config_change_path_cb, NULL, NULL, + &relay_config_delete_path_cb, NULL, NULL); } else { diff --git a/src/plugins/relay/relay-server.c b/src/plugins/relay/relay-server.c index 0a60b1fa5..838a50df5 100644 --- a/src/plugins/relay/relay-server.c +++ b/src/plugins/relay/relay-server.c @@ -742,16 +742,38 @@ relay_server_new (const char *protocol_string, enum t_relay_protocol protocol, } /* + * Updates path in a server. + */ + +void +relay_server_update_path (struct t_relay_server *server, const char *path) +{ + if (strcmp (path, server->path) != 0) + { + relay_server_close_socket (server); + free (server->path); + server->path = strdup (path); + server->port = -1; + relay_server_create_socket (server); + } +} + +/* * Updates port in a server. */ void relay_server_update_port (struct t_relay_server *server, int port) { + char str_path[128]; + if (port != server->port) { relay_server_close_socket (server); server->port = port; + snprintf (str_path, sizeof (str_path), "%d", port); + free (server->path); + server->path = strdup (str_path); relay_server_create_socket (server); } } diff --git a/src/plugins/relay/relay-server.h b/src/plugins/relay/relay-server.h index f5e42bd22..33294812c 100644 --- a/src/plugins/relay/relay-server.h +++ b/src/plugins/relay/relay-server.h @@ -67,6 +67,8 @@ extern struct t_relay_server *relay_server_new (const char *protocol_string, int port, const char *path, int ipv4, int ipv6, int ssl, int unix_socket); +extern void relay_server_update_path (struct t_relay_server *server, + const char *path); extern void relay_server_update_port (struct t_relay_server *server, int port); extern void relay_server_free (struct t_relay_server *server); extern void relay_server_free_all (); |