summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2016-03-05 10:59:37 +0100
committerSébastien Helleu <flashcode@flashtux.org>2016-03-05 10:59:37 +0100
commita4d1dfa8f436366dbe6544ae7480ba8986f81a05 (patch)
treec26c0f6b9ae2aaa52eefb6aaeec0a517ac34e2f3 /src
parent28737c9de173a24d5911501d56b612df1312d5bb (diff)
downloadweechat-a4d1dfa8f436366dbe6544ae7480ba8986f81a05.zip
relay: do not execute any command received from an irc relay client (closes #699)
Diffstat (limited to 'src')
-rw-r--r--src/plugins/irc/irc-input.c71
-rw-r--r--src/plugins/relay/irc/relay-irc.c24
2 files changed, 60 insertions, 35 deletions
diff --git a/src/plugins/irc/irc-input.c b/src/plugins/irc/irc-input.c
index 81cbcc044..caa330474 100644
--- a/src/plugins/irc/irc-input.c
+++ b/src/plugins/irc/irc-input.c
@@ -189,7 +189,8 @@ irc_input_send_user_message (struct t_gui_buffer *buffer, int flags,
*/
int
-irc_input_data (struct t_gui_buffer *buffer, const char *input_data, int flags)
+irc_input_data (struct t_gui_buffer *buffer, const char *input_data, int flags,
+ int force_user_message)
{
const char *ptr_data;
char *data_with_colors, *msg;
@@ -207,7 +208,8 @@ irc_input_data (struct t_gui_buffer *buffer, const char *input_data, int flags)
* if send unknown commands is enabled and that input data is a
* command, then send this command to IRC server
*/
- if (weechat_config_boolean (irc_config_network_send_unknown_commands)
+ if (!force_user_message
+ && weechat_config_boolean (irc_config_network_send_unknown_commands)
&& !weechat_string_input_for_buffer (input_data))
{
if (ptr_server)
@@ -220,9 +222,13 @@ irc_input_data (struct t_gui_buffer *buffer, const char *input_data, int flags)
if (ptr_channel)
{
- ptr_data = weechat_string_input_for_buffer (input_data);
- if (!ptr_data)
- ptr_data = input_data;
+ ptr_data = input_data;
+ if (!force_user_message)
+ {
+ ptr_data = weechat_string_input_for_buffer (input_data);
+ if (!ptr_data)
+ ptr_data = input_data;
+ }
data_with_colors = irc_color_encode (
ptr_data,
weechat_config_boolean (irc_config_network_colors_send));
@@ -259,7 +265,8 @@ irc_input_data_cb (void *data, struct t_gui_buffer *buffer,
/* make C compiler happy */
(void) data;
- return irc_input_data (buffer, input_data, IRC_SERVER_SEND_OUTQ_PRIO_HIGH);
+ return irc_input_data (buffer, input_data,
+ IRC_SERVER_SEND_OUTQ_PRIO_HIGH, 0);
}
/*
@@ -268,10 +275,13 @@ irc_input_data_cb (void *data, struct t_gui_buffer *buffer,
* This signal can be used by other plugins/scripts, it simulates input or
* command from user on an IRC buffer (it is used for example by Relay plugin).
*
- * Format of signal_data (string) is "server;channel;flags;tags;text"
+ * Format of signal_data (string) is "server;channel;options;tags;text"
* server: server name (required)
* channel: channel name (optional)
- * flags: flags for irc_server_sendf() (optional)
+ * options: comma-separated list of options (optional):
+ * "priority_high": send with high priority (default)
+ * "priority_low": send with low priority
+ * "user_message": force user message (don't execute a command)
* tags: tags for irc_server_sendf() (optional)
* text: text or command (required).
*/
@@ -281,10 +291,9 @@ irc_input_send_cb (void *data, const char *signal,
const char *type_data, void *signal_data)
{
const char *ptr_string, *ptr_message;
- char *pos_semicol1, *pos_semicol2, *pos_semicol3, *pos_semicol4, *error;
- char *server, *channel, *flags, *tags;
- long flags_value;
- char *data_with_colors;
+ char *pos_semicol1, *pos_semicol2, *pos_semicol3, *pos_semicol4;
+ char *server, *channel, *options, *tags, *data_with_colors, **list_options;
+ int i, num_options, flags, force_user_message;
struct t_irc_server *ptr_server;
struct t_irc_channel *ptr_channel;
struct t_gui_buffer *ptr_buffer;
@@ -298,7 +307,9 @@ irc_input_send_cb (void *data, const char *signal,
server = NULL;
channel = NULL;
- flags = NULL;
+ options = NULL;
+ flags = IRC_SERVER_SEND_OUTQ_PRIO_HIGH;
+ force_user_message = 0;
tags = NULL;
ptr_message = NULL;
ptr_server = NULL;
@@ -324,8 +335,8 @@ irc_input_send_cb (void *data, const char *signal,
{
if (pos_semicol3 > pos_semicol2 + 1)
{
- flags = weechat_strndup (pos_semicol2 + 1,
- pos_semicol3 - pos_semicol2 - 1);
+ options = weechat_strndup (pos_semicol2 + 1,
+ pos_semicol3 - pos_semicol2 - 1);
}
pos_semicol4 = strchr (pos_semicol3 + 1, ';');
if (pos_semicol4)
@@ -341,13 +352,22 @@ irc_input_send_cb (void *data, const char *signal,
}
}
- flags_value = IRC_SERVER_SEND_OUTQ_PRIO_HIGH;
- if (flags)
+ if (options && options[0])
{
- error = NULL;
- flags_value = strtol (flags, &error, 10);
- if (flags_value < 0)
- flags_value = IRC_SERVER_SEND_OUTQ_PRIO_HIGH;
+ list_options = weechat_string_split (options, ",", 0, 0, &num_options);
+ if (list_options)
+ {
+ for (i = 0; i < num_options; i++)
+ {
+ if (strcmp (list_options[i], "priority_high") == 0)
+ flags = IRC_SERVER_SEND_OUTQ_PRIO_HIGH;
+ else if (strcmp (list_options[i], "priority_low") == 0)
+ flags = IRC_SERVER_SEND_OUTQ_PRIO_LOW;
+ else if (strcmp (list_options[i], "user_message") == 0)
+ force_user_message = 1;
+ }
+ weechat_string_free_split (list_options);
+ }
}
if (server && ptr_message)
@@ -367,10 +387,11 @@ irc_input_send_cb (void *data, const char *signal,
irc_server_set_send_default_tags (tags);
/* send text to buffer, or execute command */
- if (weechat_string_input_for_buffer (ptr_message))
+ if (force_user_message
+ || weechat_string_input_for_buffer (ptr_message))
{
/* text as input */
- irc_input_data (ptr_buffer, ptr_message, flags_value);
+ irc_input_data (ptr_buffer, ptr_message, flags, 1);
}
else
{
@@ -394,8 +415,8 @@ irc_input_send_cb (void *data, const char *signal,
free (server);
if (channel)
free (channel);
- if (flags)
- free (flags);
+ if (options)
+ free (options);
if (tags)
free (tags);
diff --git a/src/plugins/relay/irc/relay-irc.c b/src/plugins/relay/irc/relay-irc.c
index 00754f45e..63c930bc8 100644
--- a/src/plugins/relay/irc/relay-irc.c
+++ b/src/plugins/relay/irc/relay-irc.c
@@ -1118,7 +1118,7 @@ relay_irc_send_join_channels (struct t_relay_client *client)
void
relay_irc_input_send (struct t_relay_client *client, const char *irc_channel,
- int flags, const char *format, ...)
+ char *options, const char *format, ...)
{
char buf_beginning[1024], *buf;
int length_beginning, length_vbuffer;
@@ -1128,10 +1128,10 @@ relay_irc_input_send (struct t_relay_client *client, const char *irc_channel,
return;
snprintf (buf_beginning, sizeof (buf_beginning),
- "%s;%s;%d;relay_client_%d;",
+ "%s;%s;%s;relay_client_%d;",
client->protocol_args,
(irc_channel) ? irc_channel : "",
- flags,
+ options,
client->id);
length_beginning = strlen (buf_beginning);
@@ -1567,10 +1567,10 @@ relay_irc_recv (struct t_relay_client *client, const char *data)
}
if (irc_args2[0] == ':')
irc_args2++;
- relay_irc_input_send (client, NULL, 1,
+ relay_irc_input_send (client, NULL,
+ "priority_high",
"/notice %s %s",
- target,
- irc_args2);
+ target, irc_args2);
free (target);
}
}
@@ -1591,12 +1591,15 @@ relay_irc_recv (struct t_relay_client *client, const char *data)
irc_is_channel = weechat_info_get ("irc_is_channel", irc_channel);
if (irc_is_channel && (strcmp (irc_is_channel, "1") == 0))
{
- relay_irc_input_send (client, irc_channel, 1,
- "%s", irc_args2);
+ relay_irc_input_send (client, irc_channel,
+ "priority_high,user_message",
+ "%s",
+ irc_args2);
}
else
{
- relay_irc_input_send (client, NULL, 1,
+ relay_irc_input_send (client, NULL,
+ "priority_high",
"/query %s %s",
irc_channel, irc_args2);
}
@@ -1723,7 +1726,8 @@ relay_irc_recv (struct t_relay_client *client, const char *data)
weechat_hashtable_free (hash_redirect);
}
/* send the IRC message to server */
- relay_irc_input_send (client, NULL, 1,
+ relay_irc_input_send (client, NULL,
+ "priority_high",
"/quote %s",
data);
}