1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-27 21:36:37 +02:00

relay: add handshake option "escape_commands" in weechat protocol

This commit is contained in:
Sébastien Helleu
2023-06-03 17:32:44 +02:00
parent 2660164118
commit 482fe6604c
8 changed files with 118 additions and 27 deletions
@@ -203,6 +203,10 @@ relay_weechat_protocol_handshake_reply (struct t_relay_client *client,
hashtable,
"compression",
relay_weechat_compression_string[RELAY_WEECHAT_DATA(client, compression)]);
weechat_hashtable_set (
hashtable,
"escape_commands",
RELAY_WEECHAT_DATA(client, escape_commands) ? "on" : "off");
msg = relay_weechat_msg_new (id);
if (msg)
@@ -315,6 +319,12 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(handshake)
weechat_string_free_split (compressions);
}
}
else if (strcmp (options[i], "escape_commands") == 0)
{
RELAY_WEECHAT_DATA(client, escape_commands) =
(weechat_strcmp (pos, "on") == 0) ?
1 : 0;
}
}
}
weechat_string_free_split_command (options);
@@ -1742,7 +1752,8 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(quit)
void
relay_weechat_protocol_recv (struct t_relay_client *client, const char *data)
{
char *pos, *id, *command, **argv, **argv_eol;
const char *ptr_data;
char *data_unescaped, *pos, *id, *command, **argv, **argv_eol;
int i, argc, return_code;
struct t_relay_weechat_protocol_cb protocol_cb[] =
{ { "handshake", &relay_weechat_protocol_cb_handshake },
@@ -1775,35 +1786,44 @@ relay_weechat_protocol_recv (struct t_relay_client *client, const char *data)
data);
}
/* extract id */
data_unescaped = NULL;
ptr_data = data;
id = NULL;
if (data[0] == '(')
command = NULL;
argv = NULL;
argv_eol = NULL;
if (RELAY_WEECHAT_DATA(client, escape_commands))
{
pos = strchr (data, ')');
data_unescaped = weechat_string_convert_escaped_chars (data);
if (data_unescaped)
ptr_data = data_unescaped;
}
/* extract id */
if (ptr_data[0] == '(')
{
pos = strchr (ptr_data, ')');
if (pos)
{
id = weechat_strndup (data + 1, pos - data - 1);
data = pos + 1;
while (data[0] == ' ')
id = weechat_strndup (ptr_data + 1, pos - ptr_data - 1);
ptr_data = pos + 1;
while (ptr_data[0] == ' ')
{
data++;
ptr_data++;
}
}
}
/* search end of data */
pos = strchr (data, ' ');
pos = strchr (ptr_data, ' ');
if (pos)
command = weechat_strndup (data, pos - data);
command = weechat_strndup (ptr_data, pos - ptr_data);
else
command = strdup (data);
command = strdup (ptr_data);
if (!command)
{
if (id)
free (id);
return;
}
goto end;
argc = 0;
argv = NULL;
@@ -1868,6 +1888,9 @@ relay_weechat_protocol_recv (struct t_relay_client *client, const char *data)
}
}
end:
if (data_unescaped)
free (data_unescaped);
if (id)
free (id);
free (command);
@@ -184,6 +184,7 @@ relay_weechat_alloc (struct t_relay_client *client)
RELAY_WEECHAT_DATA(client, password_ok) = 0;
RELAY_WEECHAT_DATA(client, totp_ok) = 0;
RELAY_WEECHAT_DATA(client, compression) = RELAY_WEECHAT_COMPRESSION_OFF;
RELAY_WEECHAT_DATA(client, escape_commands) = 0;
RELAY_WEECHAT_DATA(client, buffers_sync) =
weechat_hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
@@ -237,6 +238,8 @@ relay_weechat_alloc_with_infolist (struct t_relay_client *client,
RELAY_WEECHAT_DATA(client, totp_ok) = 1;
RELAY_WEECHAT_DATA(client, compression) = weechat_infolist_integer (
infolist, "compression");
RELAY_WEECHAT_DATA(client, escape_commands) = weechat_infolist_integer (
infolist, "escape_commands");
/* sync of buffers */
RELAY_WEECHAT_DATA(client, buffers_sync) = weechat_hashtable_new (
@@ -357,6 +360,8 @@ relay_weechat_add_to_infolist (struct t_infolist_item *item,
return 0;
if (!weechat_infolist_new_var_integer (item, "compression", RELAY_WEECHAT_DATA(client, compression)))
return 0;
if (!weechat_infolist_new_var_integer (item, "escape_commands", RELAY_WEECHAT_DATA(client, escape_commands)))
return 0;
if (!weechat_hashtable_add_to_infolist (RELAY_WEECHAT_DATA(client, buffers_sync), item, "buffers_sync"))
return 0;
@@ -376,6 +381,7 @@ relay_weechat_print_log (struct t_relay_client *client)
weechat_log_printf (" password_ok . . . . . . : %d", RELAY_WEECHAT_DATA(client, password_ok));
weechat_log_printf (" totp_ok . . . . . . . . : %d", RELAY_WEECHAT_DATA(client, totp_ok));
weechat_log_printf (" compression . . . . . . : %d", RELAY_WEECHAT_DATA(client, compression));
weechat_log_printf (" escape_commands . . . . : %d", RELAY_WEECHAT_DATA(client, escape_commands));
weechat_log_printf (" buffers_sync. . . . . . : 0x%lx (hashtable: '%s')",
RELAY_WEECHAT_DATA(client, buffers_sync),
weechat_hashtable_get_string (RELAY_WEECHAT_DATA(client, buffers_sync),
+5 -3
View File
@@ -44,13 +44,15 @@ struct t_relay_weechat_data
/* handshake status */
int handshake_done; /* 1 if handshake has been done */
/* handshake options */
enum t_relay_weechat_compression compression; /* compression type */
int escape_commands; /* 1 if backslashes are interpreted */
/* in commands sent by client */
/* authentication status (init command) */
int password_ok; /* password received and OK? */
int totp_ok; /* TOTP received and OK? */
/* options set by client (init command) */
enum t_relay_weechat_compression compression; /* compression type */
/* sync of buffers */
struct t_hashtable *buffers_sync; /* buffers synchronized (events */
/* received for these buffers) */