1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-08 18:53:12 +02:00

relay/remote: check that remote API is exactly the same version as local one upon connection

This commit is contained in:
Sébastien Helleu
2024-05-19 11:26:50 +02:00
parent cc544e3e3a
commit 44ca4b41f3
4 changed files with 43 additions and 7 deletions
@@ -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;
}
@@ -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
{