summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/relay/relay-config.c28
-rw-r--r--src/plugins/relay/relay-config.h1
-rw-r--r--src/plugins/relay/relay-network.c6
-rw-r--r--src/plugins/relay/relay-network.h2
4 files changed, 37 insertions, 0 deletions
diff --git a/src/plugins/relay/relay-config.c b/src/plugins/relay/relay-config.c
index a4e916cc8..64336f68d 100644
--- a/src/plugins/relay/relay-config.c
+++ b/src/plugins/relay/relay-config.c
@@ -27,6 +27,7 @@
#include "relay-config.h"
#include "relay-client.h"
#include "relay-buffer.h"
+#include "relay-network.h"
struct t_config_file *relay_config_file = NULL;
@@ -44,6 +45,7 @@ struct t_config_option *relay_config_color_status[RELAY_NUM_STATUS];
/* relay config, network section */
+struct t_config_option *relay_config_network_enabled;
struct t_config_option *relay_config_network_listen_port_range;
@@ -64,6 +66,26 @@ relay_config_refresh_cb (void *data, struct t_config_option *option)
}
/*
+ * relay_config_change_network_enabled_cb: callback called when user
+ * enables/disables relay
+ */
+
+void
+relay_config_change_network_enabled_cb (void *data,
+ struct t_config_option *option)
+{
+ /* make C compiler happy */
+ (void) data;
+ (void) option;
+
+ if ((weechat_config_boolean(relay_config_network_enabled) && relay_network_sock < 0)
+ || (!weechat_config_boolean(relay_config_network_enabled) && relay_network_sock >= 0))
+ {
+ relay_network_init ();
+ }
+}
+
+/*
* relay_config_reload: reload relay configuration file
*/
@@ -179,6 +201,12 @@ relay_config_init ()
return 0;
}
+ relay_config_network_enabled = weechat_config_new_option (
+ relay_config_file, ptr_section,
+ "enabled", "boolean",
+ N_("enable relay"),
+ NULL, 0, 0, "off", NULL, 0, NULL, NULL,
+ &relay_config_change_network_enabled_cb, NULL, NULL, NULL);
relay_config_network_listen_port_range = weechat_config_new_option (
relay_config_file, ptr_section,
"listen_port_range", "string",
diff --git a/src/plugins/relay/relay-config.h b/src/plugins/relay/relay-config.h
index 30fe1a01a..6671127a4 100644
--- a/src/plugins/relay/relay-config.h
+++ b/src/plugins/relay/relay-config.h
@@ -31,6 +31,7 @@ extern struct t_config_option *relay_config_color_text_bg;
extern struct t_config_option *relay_config_color_text_selected;
extern struct t_config_option *relay_config_color_status[];
+extern struct t_config_option *relay_config_network_enabled;
extern struct t_config_option *relay_config_network_listen_port_range;
extern int relay_config_init ();
diff --git a/src/plugins/relay/relay-network.c b/src/plugins/relay/relay-network.c
index 8b48edacb..b5305193a 100644
--- a/src/plugins/relay/relay-network.c
+++ b/src/plugins/relay/relay-network.c
@@ -57,6 +57,9 @@ relay_network_close_socket ()
{
close (relay_network_sock);
relay_network_sock = -1;
+ weechat_printf (NULL,
+ _("%s: socket closed"),
+ RELAY_PLUGIN_NAME);
}
}
@@ -116,6 +119,9 @@ relay_network_init ()
relay_network_close_socket ();
+ if (!weechat_config_boolean (relay_config_network_enabled))
+ return 1;
+
port_range = weechat_config_string (relay_config_network_listen_port_range);
if (!port_range || !port_range[0])
{
diff --git a/src/plugins/relay/relay-network.h b/src/plugins/relay/relay-network.h
index 57f6ba9e1..1714256e0 100644
--- a/src/plugins/relay/relay-network.h
+++ b/src/plugins/relay/relay-network.h
@@ -20,6 +20,8 @@
#ifndef __WEECHAT_RELAY_NETWORK_H
#define __WEECHAT_RELAY_NETWORK_H 1
+extern int relay_network_sock;
+
extern int relay_network_init ();
extern void relay_network_end ();