diff options
Diffstat (limited to 'src/plugins/relay')
-rw-r--r-- | src/plugins/relay/relay-command.c | 22 | ||||
-rw-r--r-- | src/plugins/relay/relay-config.c | 8 | ||||
-rw-r--r-- | src/plugins/relay/relay-remote.c | 50 | ||||
-rw-r--r-- | src/plugins/relay/relay-remote.h | 3 | ||||
-rw-r--r-- | src/plugins/relay/relay.c | 15 |
5 files changed, 87 insertions, 11 deletions
diff --git a/src/plugins/relay/relay-command.c b/src/plugins/relay/relay-command.c index 85c36341d..98b7150a9 100644 --- a/src/plugins/relay/relay-command.c +++ b/src/plugins/relay/relay-command.c @@ -397,6 +397,9 @@ relay_command_display_remote (struct t_relay_remote *remote, int with_detail) weechat_printf (NULL, _("Remote: %s"), remote->name); weechat_printf (NULL, " url. . . . . . . . . : '%s'", weechat_config_string (remote->options[RELAY_REMOTE_OPTION_URL])); + weechat_printf (NULL, " autoconnect. . . . . : %s", + (weechat_config_string (remote->options[RELAY_REMOTE_OPTION_AUTOCONNECT])) ? + "on" : "off"); weechat_printf (NULL, " proxy. . . . . . . . : '%s'", weechat_config_string (remote->options[RELAY_REMOTE_OPTION_PROXY])); weechat_printf (NULL, " tls_verify . . . . . : %s", @@ -428,7 +431,8 @@ 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_proxy, *ptr_tls_verify, *ptr_password, *ptr_totp_secret; + const char *ptr_autoconnect, *ptr_proxy, *ptr_tls_verify, *ptr_password; + const char *ptr_totp_secret; char *remote_name; /* make C compiler happy */ @@ -529,13 +533,18 @@ relay_command_remote (const void *pointer, void *data, argv[3]); return WEECHAT_RC_OK; } + ptr_autoconnect = NULL; ptr_proxy = NULL; ptr_tls_verify = NULL; ptr_password = NULL; ptr_totp_secret = NULL; for (i = 4; i < argc; i++) { - if (strncmp (argv[i], "-proxy=", 7) == 0) + if (strncmp (argv[i], "-autoconnect=", 13) == 0) + { + ptr_autoconnect = argv[i] + 13; + } + else if (strncmp (argv[i], "-proxy=", 7) == 0) { ptr_proxy = argv[i] + 7; } @@ -561,8 +570,8 @@ relay_command_remote (const void *pointer, void *data, return WEECHAT_RC_OK; } } - ptr_remote = relay_remote_new (argv[2], argv[3], ptr_proxy, - ptr_tls_verify, ptr_password, + ptr_remote = relay_remote_new (argv[2], argv[3], ptr_autoconnect, + ptr_proxy, ptr_tls_verify, ptr_password, ptr_totp_secret); if (ptr_remote) { @@ -835,7 +844,7 @@ relay_command_init () "remote relay options: relay.remote.name.xxx"), N_("url: URL of the remote relay, format is https://example.com:9000 " "or http://example.com:9000 (plain-text connection, not recommended)"), - N_("option: set option for remote relay: proxy, password or totp_secret"), + N_("option: set option for remote relay"), N_("raw[connect]: connect to a remote relay server"), N_("raw[send]: send JSON data to a remote relay server"), N_("raw[disconnect]: disconnect from a remote relay server"), @@ -850,7 +859,8 @@ relay_command_init () "list %(relay_remotes)" " || listfull %(relay_remotes)" " || add %(relay_remotes) https://localhost:9000 " - "-password=${xxx}|-proxy=xxx|-tls_verify=xxx|-totp_secret=${xxx}|%*" + "-autoconnect=on|-password=${xxx}|-proxy=xxx|-tls_verify=off|" + "-totp_secret=${xxx}|%*" " || connect %(relay_remotes)" " || send %(relay_remotes) {\"request\":\"\"}" " || disconnect %(relay_remotes)" diff --git a/src/plugins/relay/relay-config.c b/src/plugins/relay/relay-config.c index e58d29d6c..33276081e 100644 --- a/src/plugins/relay/relay-config.c +++ b/src/plugins/relay/relay-config.c @@ -1067,6 +1067,14 @@ relay_config_create_remote_option (const char *remote_name, int index_option, &relay_config_remote_url_change_cb, NULL, NULL, NULL, NULL, NULL); break; + case RELAY_REMOTE_OPTION_AUTOCONNECT: + ptr_option = weechat_config_new_option ( + relay_config_file, relay_config_section_remote, + option_name, "boolean", + N_("auto-connect to the remote relay"), + 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, diff --git a/src/plugins/relay/relay-remote.c b/src/plugins/relay/relay-remote.c index 6e686e118..36866662c 100644 --- a/src/plugins/relay/relay-remote.c +++ b/src/plugins/relay/relay-remote.c @@ -42,9 +42,9 @@ char *relay_remote_option_string[RELAY_REMOTE_NUM_OPTIONS] = -{ "url", "proxy", "tls_verify", "password", "totp_secret" }; +{ "url", "autoconnect", "proxy", "tls_verify", "password", "totp_secret" }; char *relay_remote_option_default[RELAY_REMOTE_NUM_OPTIONS] = -{ "", "", "on", "", "" }; +{ "", "off", "", "on", "", "" }; struct t_relay_remote *relay_remotes = NULL; struct t_relay_remote *last_relay_remote = NULL; @@ -464,9 +464,9 @@ 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 *proxy, - const char *tls_verify, const char *password, - const char *totp_secret) +relay_remote_new (const char *name, const char *url, const char *autoconnect, + const char *proxy, const char *tls_verify, + const char *password, const char *totp_secret) { struct t_config_option *option[RELAY_REMOTE_NUM_OPTIONS]; const char *value[RELAY_REMOTE_NUM_OPTIONS]; @@ -477,6 +477,7 @@ relay_remote_new (const char *name, const char *url, const char *proxy, return NULL; value[RELAY_REMOTE_OPTION_URL] = url; + value[RELAY_REMOTE_OPTION_AUTOCONNECT] = autoconnect; value[RELAY_REMOTE_OPTION_PROXY] = proxy; value[RELAY_REMOTE_OPTION_TLS_VERIFY] = tls_verify; value[RELAY_REMOTE_OPTION_PASSWORD] = password; @@ -650,6 +651,42 @@ relay_remote_connect (struct t_relay_remote *remote) } /* + * Callback for auto-connect to remotes (called at startup). + */ + +int +relay_remote_auto_connect_timer_cb (const void *pointer, void *data, + int remaining_calls) +{ + struct t_relay_remote *ptr_remote; + + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) remaining_calls; + + for (ptr_remote = relay_remotes; ptr_remote; + ptr_remote = ptr_remote->next_remote) + { + if (weechat_config_boolean (ptr_remote->options[RELAY_REMOTE_OPTION_AUTOCONNECT])) + relay_remote_connect (ptr_remote); + } + + return WEECHAT_RC_OK; +} + +/* + * Auto-connects to all remotes with option autoconnect to "on". + */ + +void +relay_remote_auto_connect () +{ + weechat_hook_timer (1, 0, 1, + &relay_remote_auto_connect_timer_cb, NULL, NULL); +} + +/* * Sends JSON data to a remote WeeChat relay/api. * * Returns: @@ -927,6 +964,9 @@ 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 (" autoconnect . . . . . . : %s", + (weechat_config_boolean (ptr_remote->options[RELAY_REMOTE_OPTION_AUTOCONNECT])) ? + "on" : "off"); weechat_log_printf (" proxy . . . . . . . . . : '%s'", weechat_config_string (ptr_remote->options[RELAY_REMOTE_OPTION_PROXY])); weechat_log_printf (" tls_verify. . . . . . . : %s", diff --git a/src/plugins/relay/relay-remote.h b/src/plugins/relay/relay-remote.h index 87db6583e..4689c86c9 100644 --- a/src/plugins/relay/relay-remote.h +++ b/src/plugins/relay/relay-remote.h @@ -27,6 +27,7 @@ enum t_relay_remote_option { RELAY_REMOTE_OPTION_URL = 0, /* remote URL */ + RELAY_REMOTE_OPTION_AUTOCONNECT, /* auto-connect */ RELAY_REMOTE_OPTION_PROXY, /* proxy used for remote (optional) */ RELAY_REMOTE_OPTION_TLS_VERIFY, /* check if the connection is trusted */ RELAY_REMOTE_OPTION_PASSWORD, /* password for remote relay */ @@ -86,6 +87,7 @@ extern void relay_remote_set_url (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 *autoconnect, const char *proxy, const char *tls_verify, const char *url, @@ -95,6 +97,7 @@ extern struct t_relay_remote *relay_remote_new_with_infolist (struct t_infolist extern void relay_remote_set_status (struct t_relay_remote *remote, enum t_relay_status status); extern int relay_remote_connect (struct t_relay_remote *remote); +extern void relay_remote_auto_connect (); extern int relay_remote_send (struct t_relay_remote *remote, const char *json); extern void relay_remote_disconnect (struct t_relay_remote *remote); extern void relay_remote_disconnect_all (); diff --git a/src/plugins/relay/relay.c b/src/plugins/relay/relay.c index b81d08ac7..026a5fa4d 100644 --- a/src/plugins/relay/relay.c +++ b/src/plugins/relay/relay.c @@ -245,6 +245,9 @@ relay_debug_dump_cb (const void *pointer, void *data, int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) { + int auto_connect; + char *info_auto_connect; + /* make C compiler happy */ (void) argc; (void) argv; @@ -282,7 +285,19 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) relay_info_init (); if (weechat_relay_plugin->upgrading) + { relay_upgrade_load (); + } + else + { + /* check if auto-connect is enabled */ + info_auto_connect = weechat_info_get ("auto_connect", NULL); + auto_connect = (info_auto_connect && (strcmp (info_auto_connect, "1") == 0)) ? + 1 : 0; + free (info_auto_connect); + if (auto_connect) + relay_remote_auto_connect (); + } relay_hook_timer = weechat_hook_timer (1 * 1000, 0, 0, &relay_client_timer_cb, NULL, NULL); |