summaryrefslogtreecommitdiff
path: root/src/plugins/relay/irc/relay-irc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/relay/irc/relay-irc.c')
-rw-r--r--src/plugins/relay/irc/relay-irc.c91
1 files changed, 59 insertions, 32 deletions
diff --git a/src/plugins/relay/irc/relay-irc.c b/src/plugins/relay/irc/relay-irc.c
index 3facb21e0..502a7b6b9 100644
--- a/src/plugins/relay/irc/relay-irc.c
+++ b/src/plugins/relay/irc/relay-irc.c
@@ -1,7 +1,7 @@
/*
* relay-irc.c - IRC protocol for relay to client: IRC proxy/bouncer
*
- * Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org>
+ * Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org>
*
* This file is part of WeeChat, the extensible chat client.
*
@@ -158,8 +158,7 @@ relay_irc_message_parse (const char *message)
hash_msg = weechat_hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
- NULL,
- NULL);
+ NULL, NULL);
if (!hash_msg)
{
weechat_printf (NULL,
@@ -214,8 +213,7 @@ relay_irc_sendf (struct t_relay_client *client, const char *format, ...)
hashtable_in = weechat_hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
- NULL,
- NULL);
+ NULL, NULL);
if (hashtable_in)
{
weechat_hashtable_set (hashtable_in, "server", client->protocol_args);
@@ -236,7 +234,8 @@ relay_irc_sendf (struct t_relay_client *client, const char *format, ...)
if (message)
{
snprintf (message, length, "%s\r\n", str_message);
- relay_client_send (client, message, strlen (message), NULL);
+ relay_client_send (client, RELAY_CLIENT_MSG_STANDARD,
+ message, strlen (message), NULL);
free (message);
}
number++;
@@ -257,7 +256,8 @@ relay_irc_sendf (struct t_relay_client *client, const char *format, ...)
*/
int
-relay_irc_signal_irc_in2_cb (void *data, const char *signal,
+relay_irc_signal_irc_in2_cb (const void *pointer, void *data,
+ const char *signal,
const char *type_data, void *signal_data)
{
struct t_relay_client *client;
@@ -265,10 +265,11 @@ relay_irc_signal_irc_in2_cb (void *data, const char *signal,
struct t_hashtable *hash_parsed;
/* make C compiler happy */
+ (void) data;
(void) signal;
(void) type_data;
- client = (struct t_relay_client *)data;
+ client = (struct t_relay_client *)pointer;
ptr_msg = (const char *)signal_data;
if (weechat_relay_plugin->debug >= 2)
@@ -367,7 +368,8 @@ relay_irc_tag_relay_client_id (const char *tags)
*/
int
-relay_irc_signal_irc_outtags_cb (void *data, const char *signal,
+relay_irc_signal_irc_outtags_cb (const void *pointer, void *data,
+ const char *signal,
const char *type_data,
void *signal_data)
{
@@ -379,10 +381,11 @@ relay_irc_signal_irc_outtags_cb (void *data, const char *signal,
char str_infolist_args[256];
/* make C compiler happy */
+ (void) data;
(void) signal;
(void) type_data;
- client = (struct t_relay_client *)data;
+ client = (struct t_relay_client *)pointer;
tags = NULL;
@@ -482,17 +485,19 @@ end:
*/
int
-relay_irc_signal_irc_disc_cb (void *data, const char *signal,
+relay_irc_signal_irc_disc_cb (const void *pointer, void *data,
+ const char *signal,
const char *type_data, void *signal_data)
{
struct t_relay_client *client;
/* make C compiler happy */
+ (void) data;
(void) signal;
(void) type_data;
(void) signal_data;
- client = (struct t_relay_client *)data;
+ client = (struct t_relay_client *)pointer;
if (weechat_relay_plugin->debug >= 2)
{
@@ -515,7 +520,8 @@ relay_irc_signal_irc_disc_cb (void *data, const char *signal,
*/
int
-relay_irc_hsignal_irc_redir_cb (void *data, const char *signal,
+relay_irc_hsignal_irc_redir_cb (const void *pointer, void *data,
+ const char *signal,
struct t_hashtable *hashtable)
{
struct t_relay_client *client;
@@ -523,7 +529,10 @@ relay_irc_hsignal_irc_redir_cb (void *data, const char *signal,
char pattern[128], **messages;
const char *output;
- client = (struct t_relay_client *)data;
+ /* make C compiler happy */
+ (void) data;
+
+ client = (struct t_relay_client *)pointer;
if (weechat_relay_plugin->debug >= 2)
{
@@ -754,7 +763,7 @@ relay_irc_send_channel_backlog (struct t_relay_client *client,
void *ptr_own_lines, *ptr_line, *ptr_line_data;
void *ptr_hdata_line, *ptr_hdata_line_data;
char *tags, *message;
- const char *ptr_nick, *ptr_nick1, *ptr_nick2, *ptr_host;
+ const char *ptr_nick, *ptr_nick1, *ptr_nick2, *ptr_host, *localvar_nick;
int irc_command, irc_action, count, max_number, max_minutes;
time_t date_min, date_min2, date;
@@ -780,6 +789,10 @@ relay_irc_send_channel_backlog (struct t_relay_client *client,
if (!ptr_hdata_line_data)
return;
+ localvar_nick = NULL;
+ if (weechat_config_boolean (relay_config_irc_backlog_since_last_message))
+ localvar_nick = weechat_buffer_get_string (buffer, "localvar_nick");
+
max_number = weechat_config_integer (relay_config_irc_backlog_max_number);
max_minutes = weechat_config_integer (relay_config_irc_backlog_max_minutes);
date_min = (max_minutes > 0) ? time (NULL) - (max_minutes * 60) : 0;
@@ -810,7 +823,7 @@ relay_irc_send_channel_backlog (struct t_relay_client *client,
&irc_command,
NULL, /* irc_action */
&date,
- NULL, /* nick */
+ &ptr_nick,
NULL, /* nick1 */
NULL, /* nick2 */
NULL, /* host */
@@ -826,6 +839,17 @@ relay_irc_send_channel_backlog (struct t_relay_client *client,
/* if we have reached max number of messages, exit loop */
if ((max_number > 0) && (count > max_number))
break;
+
+ if (localvar_nick && localvar_nick[0]
+ && ptr_nick && (strcmp (ptr_nick, localvar_nick) == 0))
+ {
+ /*
+ * stop when we find a line sent by the current nick
+ * (and include this line)
+ */
+ ptr_line = weechat_hdata_move (ptr_hdata_line, ptr_line, -1);
+ break;
+ }
}
ptr_line = weechat_hdata_move (ptr_hdata_line, ptr_line, -1);
}
@@ -1102,7 +1126,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;
@@ -1112,10 +1136,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);
@@ -1163,7 +1187,7 @@ relay_irc_hook_signals (struct t_relay_client *client)
RELAY_IRC_DATA(client, hook_signal_irc_in2) =
weechat_hook_signal (str_signal_name,
&relay_irc_signal_irc_in2_cb,
- client);
+ client, NULL);
/*
* hook signal "xxx,irc_outtags_*" to catch IRC data sent to
@@ -1175,7 +1199,7 @@ relay_irc_hook_signals (struct t_relay_client *client)
RELAY_IRC_DATA(client, hook_signal_irc_outtags) =
weechat_hook_signal (str_signal_name,
&relay_irc_signal_irc_outtags_cb,
- client);
+ client, NULL);
/*
* hook signal "irc_server_disconnected" to disconnect client if
@@ -1184,7 +1208,7 @@ relay_irc_hook_signals (struct t_relay_client *client)
RELAY_IRC_DATA(client, hook_signal_irc_disc) =
weechat_hook_signal ("irc_server_disconnected",
&relay_irc_signal_irc_disc_cb,
- client);
+ client, NULL);
/*
* hook hsignal "irc_redirection_*" to redirect some messages
@@ -1192,7 +1216,7 @@ relay_irc_hook_signals (struct t_relay_client *client)
RELAY_IRC_DATA(client, hook_hsignal_irc_redir) =
weechat_hook_hsignal ("irc_redirection_relay_*",
&relay_irc_hsignal_irc_redir_cb,
- client);
+ client, NULL);
}
/*
@@ -1551,10 +1575,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);
}
}
@@ -1575,12 +1599,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);
}
@@ -1590,8 +1617,7 @@ relay_irc_recv (struct t_relay_client *client, const char *data)
hash_redirect = weechat_hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
- NULL,
- NULL);
+ NULL, NULL);
if (hash_redirect)
{
redirect_msg = 0;
@@ -1707,7 +1733,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);
}