diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2024-05-19 11:26:50 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2024-05-19 11:26:50 +0200 |
commit | 44ca4b41f393a14bff15b7adde7baa134325ff47 (patch) | |
tree | b8b86cabb013ff60467f167d8e1c7d502bfa7b74 /src/plugins | |
parent | cc544e3e3a13d0772715fc096b366b148986ffb6 (diff) | |
download | weechat-44ca4b41f393a14bff15b7adde7baa134325ff47.zip |
relay/remote: check that remote API is exactly the same version as local one upon connection
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/relay/api/remote/relay-remote-event.c | 36 | ||||
-rw-r--r-- | src/plugins/relay/api/remote/relay-remote-network.c | 8 | ||||
-rw-r--r-- | src/plugins/relay/relay-remote.c | 5 | ||||
-rw-r--r-- | src/plugins/relay/relay-remote.h | 1 |
4 files changed, 43 insertions, 7 deletions
diff --git a/src/plugins/relay/api/remote/relay-remote-event.c b/src/plugins/relay/api/remote/relay-remote-event.c index 192178f9a..cdc36d376 100644 --- a/src/plugins/relay/api/remote/relay-remote-event.c +++ b/src/plugins/relay/api/remote/relay-remote-event.c @@ -33,6 +33,7 @@ #include "../../../weechat-plugin.h" #include "../../relay.h" #include "../../relay-auth.h" +#include "../../relay-config.h" #include "../../relay-http.h" #include "../../relay-raw.h" #include "../../relay-remote.h" @@ -804,6 +805,7 @@ RELAY_REMOTE_EVENT_CALLBACK(version) { cJSON *json_obj; const char *weechat_version, *weechat_version_git, *relay_api_version; + char *weechat_version_local, request[1024]; if (!event->json) return WEECHAT_RC_OK; @@ -819,6 +821,40 @@ RELAY_REMOTE_EVENT_CALLBACK(version) weechat_version_git, relay_api_version); + if (!event->remote->version_ok) + { + /* check version: the remote API must be exactly the same as local API */ + if (strcmp (relay_api_version, RELAY_API_VERSION_STR) != 0) + { + weechat_version_local = weechat_info_get ("version", NULL); + weechat_printf ( + NULL, + _("%sremote[%s]: API version mismatch: " + "remote API is %s (WeeChat %s), " + "local API %s (WeeChat %s)"), + weechat_prefix ("error"), + event->remote->name, + relay_api_version, + weechat_version, + RELAY_API_VERSION_STR, + weechat_version_local); + free (weechat_version_local); + relay_remote_network_disconnect (event->remote); + return WEECHAT_RC_OK; + } + + event->remote->version_ok = 1; + snprintf (request, sizeof (request), + "{\"request\": \"GET /api/buffers?" + "lines=-%d" + "&nicks=true" + "&colors=weechat" + "\"}", + weechat_config_integer (relay_config_api_remote_get_lines)); + relay_remote_network_send (event->remote, RELAY_MSG_STANDARD, + request, strlen (request)); + } + return WEECHAT_RC_OK; } diff --git a/src/plugins/relay/api/remote/relay-remote-network.c b/src/plugins/relay/api/remote/relay-remote-network.c index 12b05cd90..673096772 100644 --- a/src/plugins/relay/api/remote/relay-remote-network.c +++ b/src/plugins/relay/api/remote/relay-remote-network.c @@ -34,7 +34,6 @@ #include "../../../weechat-plugin.h" #include "../../relay.h" #include "../../relay-auth.h" -#include "../../relay-config.h" #include "../../relay-http.h" #include "../../relay-raw.h" #include "../../relay-remote.h" @@ -105,6 +104,7 @@ relay_remote_network_close_connection (struct t_relay_remote *remote) remote->sock = -1; } relay_websocket_deflate_reinit (remote->ws_deflate); + remote->version_ok = 0; remote->synced = 0; if (remote->partial_ws_frame) { @@ -383,12 +383,6 @@ relay_remote_network_recv_text (struct t_relay_remote *remote, "{\"request\": \"GET /api/version\"}"); relay_remote_network_send (remote, RELAY_MSG_STANDARD, request, strlen (request)); - snprintf (request, sizeof (request), - "{\"request\": \"GET /api/buffers?" - "lines=-%d&nicks=true&colors=weechat\"}", - weechat_config_integer (relay_config_api_remote_get_lines)); - relay_remote_network_send (remote, RELAY_MSG_STANDARD, - request, strlen (request)); } else { diff --git a/src/plugins/relay/relay-remote.c b/src/plugins/relay/relay-remote.c index 36866662c..6d4c1b4d7 100644 --- a/src/plugins/relay/relay-remote.c +++ b/src/plugins/relay/relay-remote.c @@ -340,6 +340,7 @@ relay_remote_alloc (const char *name) new_remote->hook_fd = NULL; new_remote->gnutls_sess = NULL; new_remote->ws_deflate = relay_websocket_deflate_alloc (); + new_remote->version_ok = 0; new_remote->synced = 0; new_remote->partial_ws_frame = NULL; new_remote->partial_ws_frame_size = 0; @@ -577,6 +578,7 @@ relay_remote_new_with_infolist (struct t_infolist *infolist) } } } + new_remote->version_ok = weechat_infolist_integer (infolist, "version_ok"); new_remote->synced = weechat_infolist_integer (infolist, "synced"); ptr_ws_frame = weechat_infolist_buffer (infolist, "partial_ws_frame", &ws_frame_size); if (ptr_ws_frame && (ws_frame_size > 0)) @@ -941,6 +943,8 @@ relay_remote_add_to_infolist (struct t_infolist *infolist, free (dict); } } + if (!weechat_infolist_new_var_integer (ptr_item, "version_ok", remote->version_ok)) + return 0; if (!weechat_infolist_new_var_integer (ptr_item, "synced", remote->synced)) return 0; @@ -992,6 +996,7 @@ relay_remote_print_log () weechat_log_printf (" hook_fd . . . . . . . . : 0x%lx", ptr_remote->hook_fd); weechat_log_printf (" gnutls_sess . . . . . . : 0x%lx", ptr_remote->gnutls_sess); relay_websocket_deflate_print_log (ptr_remote->ws_deflate, ""); + weechat_log_printf (" version_ok. . . . . . . : %d", ptr_remote->version_ok); weechat_log_printf (" synced. . . . . . . . . : %d", ptr_remote->synced); weechat_log_printf (" partial_ws_frame. . . . : %p (%d bytes)", ptr_remote->partial_ws_frame, diff --git a/src/plugins/relay/relay-remote.h b/src/plugins/relay/relay-remote.h index 4689c86c9..9dc1b09bd 100644 --- a/src/plugins/relay/relay-remote.h +++ b/src/plugins/relay/relay-remote.h @@ -57,6 +57,7 @@ struct t_relay_remote struct t_hook *hook_fd; /* hook for socket */ gnutls_session_t gnutls_sess; /* gnutls session (only if TLS used) */ struct t_relay_websocket_deflate *ws_deflate; /* websocket deflate data */ + int version_ok; /* remote API version is OK? */ int synced; /* 1 if synced with remote */ char *partial_ws_frame; /* part. binary websocket frame recv */ int partial_ws_frame_size; /* size of partial websocket frame */ |