1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-25 12:26:40 +02:00

Add IRC command redirection (task #6703)

This commit is contained in:
Sebastien Helleu
2010-10-23 09:54:31 +02:00
parent 0cf04dca7c
commit 868df21122
25 changed files with 1930 additions and 59 deletions
+1
View File
@@ -37,6 +37,7 @@ irc-msgbuffer.c irc-msgbuffer.h
irc-nick.c irc-nick.h
irc-protocol.c irc-protocol.h
irc-raw.c irc-raw.h
irc-redirect.c irc-redirect.h
irc-sasl.c irc-sasl.h
irc-server.c irc-server.h
irc-upgrade.c irc-upgrade.h)
+2
View File
@@ -61,6 +61,8 @@ irc_la_SOURCES = irc.c \
irc-protocol.h \
irc-raw.c \
irc-raw.h \
irc-redirect.c \
irc-redirect.h \
irc-sasl.c \
irc-sasl.h \
irc-server.c \
+1 -1
View File
@@ -920,7 +920,7 @@ irc_channel_print_log (struct t_irc_channel *channel)
struct t_irc_nick *ptr_nick;
weechat_log_printf ("");
weechat_log_printf (" => channel %s (addr:0x%lx)]", channel->name, channel);
weechat_log_printf (" => channel %s (addr:0x%lx):", channel->name, channel);
weechat_log_printf (" type . . . . . . . . . . : %d", channel->type);
weechat_log_printf (" topic. . . . . . . . . . : '%s'", channel->topic);
weechat_log_printf (" modes. . . . . . . . . . : '%s'", channel->modes);
+3
View File
@@ -27,6 +27,7 @@
#include "../weechat-plugin.h"
#include "irc.h"
#include "irc-debug.h"
#include "irc-redirect.h"
#include "irc-server.h"
@@ -52,6 +53,8 @@ irc_debug_signal_debug_dump_cb (void *data, const char *signal,
irc_server_print_log ();
irc_redirect_pattern_print_log ();
weechat_log_printf ("");
weechat_log_printf ("***** End of \"%s\" plugin dump *****",
weechat_plugin->name);
+35 -8
View File
@@ -211,10 +211,10 @@ irc_raw_message_add_to_list (time_t date, const char *prefix,
*/
struct t_irc_raw_message *
irc_raw_message_add (struct t_irc_server *server, int send, int modified,
irc_raw_message_add (struct t_irc_server *server, int flags,
const char *message)
{
char *buf, *buf2, prefix[256];
char *buf, *buf2, prefix[256], prefix_arrow[16];
const unsigned char *ptr_buf;
const char *hexa = "0123456789ABCDEF";
int pos_buf, pos_buf2, char_size, i;
@@ -247,16 +247,43 @@ irc_raw_message_add (struct t_irc_server *server, int send, int modified,
}
buf2[pos_buf2] = '\0';
}
/* build prefix with arrow */
prefix_arrow[0] = '\0';
switch (flags & (IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_SEND
| IRC_RAW_FLAG_MODIFIED | IRC_RAW_FLAG_REDIRECT))
{
case IRC_RAW_FLAG_RECV:
strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV);
break;
case IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_MODIFIED:
strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV_MODIFIED);
break;
case IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_REDIRECT:
strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV_REDIRECT);
break;
case IRC_RAW_FLAG_SEND:
strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND);
break;
case IRC_RAW_FLAG_SEND | IRC_RAW_FLAG_MODIFIED:
strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND_MODIFIED);
break;
default:
if (flags && IRC_RAW_FLAG_RECV)
strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV);
else
strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND);
break;
}
snprintf (prefix, sizeof (prefix), "%s%s%s%s%s",
(server) ? weechat_color ("chat_server") : "",
(server) ? server->name : "",
(server) ? " " : "",
(send) ?
(flags & IRC_RAW_FLAG_SEND) ?
weechat_color ("chat_prefix_quit") :
weechat_color ("chat_prefix_join"),
(send) ?
((modified) ? IRC_RAW_PREFIX_SEND_MOD : IRC_RAW_PREFIX_SEND) :
((modified) ? IRC_RAW_PREFIX_RECV_MOD : IRC_RAW_PREFIX_RECV));
prefix_arrow);
new_raw_message = irc_raw_message_add_to_list (time (NULL),
prefix,
@@ -275,7 +302,7 @@ irc_raw_message_add (struct t_irc_server *server, int send, int modified,
*/
void
irc_raw_print (struct t_irc_server *server, int send, int modified,
irc_raw_print (struct t_irc_server *server, int flags,
const char *message)
{
struct t_irc_raw_message *new_raw_message;
@@ -287,7 +314,7 @@ irc_raw_print (struct t_irc_server *server, int send, int modified,
if (!irc_raw_buffer && (weechat_irc_plugin->debug >= 1))
irc_raw_open (0);
new_raw_message = irc_raw_message_add (server, send, modified, message);
new_raw_message = irc_raw_message_add (server, flags, message);
if (new_raw_message)
{
if (irc_raw_buffer)
+14 -7
View File
@@ -20,11 +20,18 @@
#ifndef __WEECHAT_IRC_RAW_H
#define __WEECHAT_IRC_RAW_H 1
#define IRC_RAW_BUFFER_NAME "irc_raw"
#define IRC_RAW_PREFIX_RECV "-->"
#define IRC_RAW_PREFIX_RECV_MOD "==>"
#define IRC_RAW_PREFIX_SEND "<--"
#define IRC_RAW_PREFIX_SEND_MOD "<=="
#define IRC_RAW_BUFFER_NAME "irc_raw"
#define IRC_RAW_PREFIX_RECV "-->"
#define IRC_RAW_PREFIX_RECV_MODIFIED "==>"
#define IRC_RAW_PREFIX_RECV_REDIRECT "R>>"
#define IRC_RAW_PREFIX_SEND "<--"
#define IRC_RAW_PREFIX_SEND_MODIFIED "<=="
#define IRC_RAW_FLAG_RECV 1
#define IRC_RAW_FLAG_SEND 2
#define IRC_RAW_FLAG_MODIFIED 4
#define IRC_RAW_FLAG_REDIRECT 8
struct t_irc_raw_message
{
@@ -45,8 +52,8 @@ extern void irc_raw_open (int switch_to_buffer);
extern struct t_irc_raw_message *irc_raw_message_add_to_list (time_t date,
const char *prefix,
const char *message);
extern void irc_raw_print (struct t_irc_server *server, int send,
int modified, const char *message);
extern void irc_raw_print (struct t_irc_server *server, int flags,
const char *message);
extern void irc_raw_message_free_all ();
extern int irc_raw_add_to_infolist (struct t_infolist *infolist,
struct t_irc_raw_message *raw_message);
File diff suppressed because it is too large Load Diff
+116
View File
@@ -0,0 +1,116 @@
/*
* Copyright (C) 2010 Sebastien Helleu <flashcode@flashtux.org>
*
* This file is part of WeeChat, the extensible chat client.
*
* WeeChat is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* WeeChat is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WEECHAT_IRC_REDIRECT_H
#define __WEECHAT_IRC_REDIRECT_H 1
#define IRC_REDIRECT_TIMEOUT_DEFAULT 60
struct t_irc_server;
/* template for redirections (IRC plugin creates some templates at startup) */
struct t_irc_redirect_pattern
{
char *name; /* name */
int temp_pattern; /* temporary pattern (created by */
/* external plugin/script) */
int timeout; /* default timeout (in seconds) */
char *cmd_start; /* command(s) starting redirection */
/* (can be NULL or empty) */
char *cmd_stop; /* command(s) stopping redirection */
/* (not NULL, at least one command) */
char *cmd_extra; /* extra command(s) after end commands */
struct t_irc_redirect_pattern *prev_redirect; /* link to previous redir. */
struct t_irc_redirect_pattern *next_redirect; /* link to next redir. */
};
/* command redirection (created when a command is redirected) */
struct t_irc_redirect
{
struct t_irc_server *server; /* server for this redirection */
char *pattern; /* name of pattern used for this redir. */
char *signal; /* name of signal sent after redirection */
int count; /* how many times redirect is executed */
int current_count; /* current count */
char *string; /* we search this string in messages */
int timeout; /* timeout (in seconds) */
char *command; /* command sent to server, which is */
/* redirected */
time_t start_time; /* time when command is sent to server */
/* (this is begining of this redirect) */
struct t_hashtable *cmd_start; /* command(s) starting redirection */
/* (can be NULL or empty) */
struct t_hashtable *cmd_stop; /* command(s) stopping redirection */
/* (not NULL, at least one command) */
struct t_hashtable *cmd_extra; /* extra command(s) after end command(s) */
int cmd_start_received; /* one of start commands received ? */
int cmd_stop_received; /* one of stop commands received ? */
struct t_hashtable *cmd_filter; /* command(s) to add to output */
/* (if NULL or empty, all cmds are sent) */
char *output; /* output of IRC command (gradually */
/* filled with IRC messages) */
int output_size; /* size (in bytes) of output string */
struct t_irc_redirect *prev_redirect; /* link to previous redirect */
struct t_irc_redirect *next_redirect; /* link to next redirect */
};
extern struct t_irc_redirect_pattern *irc_redirect_patterns;
extern struct t_irc_redirect_pattern *last_irc_redirect_pattern;
extern struct t_irc_redirect_pattern *irc_redirect_pattern_new (const char *name,
int temp_pattern,
int timeout,
const char *cmd_start,
const char *cmd_stop,
const char *cmd_extra);
extern struct t_irc_redirect *irc_redirect_new_with_commands (struct t_irc_server *server,
const char *pattern,
const char *signal,
int count,
const char *string,
int timeout,
const char *cmd_start,
const char *cmd_stop,
const char *cmd_extra,
const char *cmd_filter);
extern struct t_irc_redirect *irc_redirect_search_available (struct t_irc_server *server);
extern void irc_redirect_init_command (struct t_irc_redirect *redirect,
const char *command);
extern void irc_redirect_stop (struct t_irc_redirect *redirect,
const char *error);
extern int irc_redirect_message (struct t_irc_server *server,
const char *message, const char *command);
extern void irc_redirect_free (struct t_irc_redirect *redirect);
extern void irc_redirect_free_all (struct t_irc_server *server);
extern int irc_redirect_pattern_add_to_infolist (struct t_infolist *infolist,
struct t_irc_redirect_pattern *redirect_pattern);
extern int irc_redirect_add_to_infolist (struct t_infolist *infolist,
struct t_irc_redirect *redirect);
extern void irc_redirect_pattern_print_log ();
extern void irc_redirect_print_log (struct t_irc_server *server);
extern int irc_redirect_pattern_hsignal_cb (void *data, const char *signal,
struct t_hashtable *hashtable);
extern int irc_redirect_command_hsignal_cb (void *data, const char *signal,
struct t_hashtable *hashtable);
extern void irc_redirect_init ();
extern void irc_redirect_end ();
#endif /* __WEECHAT_IRC_REDIRECT_H */
+96 -33
View File
@@ -52,6 +52,7 @@
#include "irc-nick.h"
#include "irc-protocol.h"
#include "irc-raw.h"
#include "irc-redirect.h"
#include "irc-sasl.h"
@@ -467,6 +468,8 @@ irc_server_alloc (const char *name)
new_server->outqueue[i] = NULL;
new_server->last_outqueue[i] = NULL;
}
new_server->redirects = NULL;
new_server->last_redirect = NULL;
new_server->buffer = NULL;
new_server->buffer_as_string = NULL;
new_server->channels = NULL;
@@ -768,7 +771,8 @@ irc_server_apply_command_line_options (struct t_irc_server *server,
void
irc_server_outqueue_add (struct t_irc_server *server, int priority,
const char *command, const char *msg1,
const char *msg2, int modified, const char *tags)
const char *msg2, int modified, const char *tags,
struct t_irc_redirect *redirect)
{
struct t_irc_outqueue *new_outqueue;
@@ -780,6 +784,7 @@ irc_server_outqueue_add (struct t_irc_server *server, int priority,
new_outqueue->message_after_mod = (msg2) ? strdup (msg2) : NULL;
new_outqueue->modified = modified;
new_outqueue->tags = (tags) ? strdup (tags) : NULL;
new_outqueue->redirect = redirect;
new_outqueue->prev_outqueue = server->last_outqueue[priority];
new_outqueue->next_outqueue = NULL;
@@ -902,6 +907,7 @@ irc_server_free_data (struct t_irc_server *server)
{
irc_server_outqueue_free_all (server, i);
}
irc_redirect_free_all (server);
if (server->channels)
irc_channel_free_all (server);
if (server->buffer_as_string)
@@ -1267,7 +1273,7 @@ irc_server_outqueue_send (struct t_irc_server *server)
'\r');
if (pos)
pos[0] = '\0';
irc_raw_print (server, 1, 0,
irc_raw_print (server, IRC_RAW_FLAG_SEND,
server->outqueue[priority]->message_before_mod);
if (pos)
pos[0] = '\r';
@@ -1278,7 +1284,8 @@ irc_server_outqueue_send (struct t_irc_server *server)
'\r');
if (pos)
pos[0] = '\0';
irc_raw_print (server, 1, server->outqueue[priority]->modified,
irc_raw_print (server, IRC_RAW_FLAG_SEND |
((server->outqueue[priority]->modified) ? IRC_RAW_FLAG_MODIFIED : 0),
server->outqueue[priority]->message_after_mod);
if (pos)
pos[0] = '\r';
@@ -1300,6 +1307,13 @@ irc_server_outqueue_send (struct t_irc_server *server)
irc_server_send (server, server->outqueue[priority]->message_after_mod,
strlen (server->outqueue[priority]->message_after_mod));
server->last_user_message = time_now;
/* start redirection if redirect is set */
if (server->outqueue[priority]->redirect)
{
irc_redirect_init_command (server->outqueue[priority]->redirect,
server->outqueue[priority]->message_after_mod);
}
}
irc_server_outqueue_free (server, priority,
server->outqueue[priority]);
@@ -1468,16 +1482,11 @@ irc_server_parse_message_to_hashtable (const char *message)
if (!hashtable)
return NULL;
weechat_hashtable_set (hashtable, "nick",
(nick) ? (void *)nick : (void *)empty_str);
weechat_hashtable_set (hashtable, "host",
(host) ? (void *)host : (void *)empty_str);
weechat_hashtable_set (hashtable, "command",
(command) ? (void *)command : (void *)empty_str);
weechat_hashtable_set (hashtable, "channel",
(channel) ? (void *)channel : (void *)empty_str);
weechat_hashtable_set (hashtable, "arguments",
(arguments) ? (void *)arguments : (void *)empty_str);
weechat_hashtable_set (hashtable, "nick", (nick) ? nick : empty_str);
weechat_hashtable_set (hashtable, "host", (host) ? host : empty_str);
weechat_hashtable_set (hashtable, "command", (command) ? command : empty_str);
weechat_hashtable_set (hashtable, "channel", (channel) ? channel : empty_str);
weechat_hashtable_set (hashtable, "arguments", (arguments) ? arguments : empty_str);
return hashtable;
}
@@ -1505,6 +1514,7 @@ irc_server_send_one_msg (struct t_irc_server *server, int flags,
char str_modifier[64], modifier_data[256];
int rc, queue_msg, add_to_queue, first_message, anti_flood;
time_t time_now;
struct t_irc_redirect *ptr_redirect;
rc = 1;
@@ -1596,6 +1606,8 @@ irc_server_send_one_msg (struct t_irc_server *server, int flags,
tags_to_send = irc_server_get_tags_to_send (tags);
ptr_redirect = irc_redirect_search_available (server);
if (add_to_queue > 0)
{
/* queue message (do not send anything now) */
@@ -1603,14 +1615,21 @@ irc_server_send_one_msg (struct t_irc_server *server, int flags,
(new_msg && first_message) ? message : NULL,
buffer,
(new_msg) ? 1 : 0,
tags_to_send);
tags_to_send,
ptr_redirect);
}
else
{
if (first_message)
irc_raw_print (server, 1, 0, message);
{
irc_raw_print (server, IRC_RAW_FLAG_SEND, message);
}
if (new_msg)
irc_raw_print (server, 1, 1, ptr_msg);
{
irc_raw_print (server,
IRC_RAW_FLAG_SEND | IRC_RAW_FLAG_MODIFIED,
ptr_msg);
}
/* send signal with command that will be sent to server */
irc_server_send_signal (server, "irc_out",
@@ -1629,6 +1648,8 @@ irc_server_send_one_msg (struct t_irc_server *server, int flags,
if (queue_msg > 0)
server->last_user_message = time_now;
}
if (ptr_redirect)
irc_redirect_init_command (ptr_redirect, buffer);
}
if (tags_to_send)
@@ -1648,7 +1669,10 @@ irc_server_send_one_msg (struct t_irc_server *server, int flags,
free (msg_encoded);
}
else
irc_raw_print (server, 1, 1, _("(message dropped)"));
{
irc_raw_print (server, IRC_RAW_FLAG_SEND | IRC_RAW_FLAG_MODIFIED,
_("(message dropped)"));
}
if (nick)
free (nick);
@@ -1849,7 +1873,8 @@ irc_server_msgq_flush ()
if (ptr_data[0])
{
irc_raw_print (irc_recv_msgq->server, 0, 0, ptr_data);
irc_raw_print (irc_recv_msgq->server, IRC_RAW_FLAG_RECV,
ptr_data);
irc_server_parse_message (ptr_data, NULL, NULL, &command,
NULL, NULL);
@@ -1882,8 +1907,11 @@ irc_server_msgq_flush ()
pos[0] = '\0';
if (new_msg)
irc_raw_print (irc_recv_msgq->server, 0, 1,
{
irc_raw_print (irc_recv_msgq->server,
IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_MODIFIED,
ptr_msg);
}
irc_server_parse_message (ptr_msg, &nick, &host,
&command, &channel,
@@ -1926,11 +1954,22 @@ irc_server_msgq_flush ()
"?");
/* parse and execute command */
irc_protocol_recv_command (irc_recv_msgq->server,
(msg_decoded_without_color) ?
msg_decoded_without_color : ((msg_decoded) ? msg_decoded : ptr_msg),
command,
channel);
if (irc_redirect_message (irc_recv_msgq->server,
(msg_decoded_without_color) ?
msg_decoded_without_color : ((msg_decoded) ? msg_decoded : ptr_msg),
command))
{
/* message redirected, we'll not display it! */
}
else
{
/* message not redirected, display it */
irc_protocol_recv_command (irc_recv_msgq->server,
(msg_decoded_without_color) ?
msg_decoded_without_color : ((msg_decoded) ? msg_decoded : ptr_msg),
command,
channel);
}
if (nick)
free (nick);
@@ -1956,7 +1995,8 @@ irc_server_msgq_flush ()
}
else
{
irc_raw_print (irc_recv_msgq->server, 0, 1,
irc_raw_print (irc_recv_msgq->server,
IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_MODIFIED,
_("(message dropped)"));
}
if (new_msg)
@@ -2125,7 +2165,8 @@ int
irc_server_timer_cb (void *data, int remaining_calls)
{
struct t_irc_server *ptr_server;
time_t new_time;
struct t_irc_redirect *ptr_redirect, *ptr_next_redirect;
time_t current_time;
static struct timeval tv;
int away_check;
@@ -2133,7 +2174,7 @@ irc_server_timer_cb (void *data, int remaining_calls)
(void) data;
(void) remaining_calls;
new_time = time (NULL);
current_time = time (NULL);
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
@@ -2141,7 +2182,7 @@ irc_server_timer_cb (void *data, int remaining_calls)
/* check if reconnection is pending */
if ((!ptr_server->is_connected)
&& (ptr_server->reconnect_start > 0)
&& (new_time >= (ptr_server->reconnect_start + ptr_server->reconnect_delay)))
&& (current_time >= (ptr_server->reconnect_start + ptr_server->reconnect_delay)))
{
irc_server_reconnect (ptr_server);
}
@@ -2155,7 +2196,7 @@ irc_server_timer_cb (void *data, int remaining_calls)
/* check for lag */
if ((weechat_config_integer (irc_config_network_lag_check) > 0)
&& (ptr_server->lag_check_time.tv_sec == 0)
&& (new_time >= ptr_server->lag_next_check))
&& (current_time >= ptr_server->lag_next_check))
{
irc_server_sendf (ptr_server, 0, NULL, "PING %s",
(ptr_server->current_address) ?
@@ -2171,7 +2212,7 @@ irc_server_timer_cb (void *data, int remaining_calls)
if (away_check > 0)
{
if ((ptr_server->last_away_check == 0)
|| (new_time >= ptr_server->last_away_check + (away_check * 60)))
|| (current_time >= ptr_server->last_away_check + (away_check * 60)))
{
irc_server_check_away (ptr_server);
}
@@ -2180,7 +2221,7 @@ irc_server_timer_cb (void *data, int remaining_calls)
/* check if it's time to autojoin channels (after command delay) */
if ((ptr_server->command_time != 0)
&& (new_time >= ptr_server->command_time +
&& (current_time >= ptr_server->command_time +
IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_COMMAND_DELAY)))
{
irc_server_autojoin_channels (ptr_server);
@@ -2195,10 +2236,10 @@ irc_server_timer_cb (void *data, int remaining_calls)
&tv);
/* refresh lag item if needed */
if (((ptr_server->lag_last_refresh == 0)
|| (new_time >= ptr_server->lag_last_refresh + weechat_config_integer (irc_config_network_lag_refresh_interval)))
|| (current_time >= ptr_server->lag_last_refresh + weechat_config_integer (irc_config_network_lag_refresh_interval)))
&& (ptr_server->lag >= weechat_config_integer (irc_config_network_lag_min_show)))
{
ptr_server->lag_last_refresh = new_time;
ptr_server->lag_last_refresh = current_time;
weechat_bar_item_update ("lag");
}
/* lag timeout? => disconnect */
@@ -2212,6 +2253,21 @@ irc_server_timer_cb (void *data, int remaining_calls)
irc_server_disconnect (ptr_server, 0, 1);
}
}
/* remove redirects if timeout occurs */
ptr_redirect = ptr_server->redirects;
while (ptr_redirect)
{
ptr_next_redirect = ptr_redirect->next_redirect;
if ((ptr_redirect->start_time > 0)
&& (ptr_redirect->start_time + ptr_redirect->timeout < current_time))
{
irc_redirect_stop (ptr_redirect, "timeout");
}
ptr_redirect = ptr_next_redirect;
}
}
}
}
@@ -2285,6 +2341,9 @@ irc_server_close_connection (struct t_irc_server *server)
irc_server_outqueue_free_all (server, i);
}
/* remove all redirects */
irc_redirect_free_all (server);
/* server is now disconnected */
server->is_connected = 0;
server->ssl_connected = 0;
@@ -4230,6 +4289,8 @@ irc_server_print_log ()
weechat_log_printf (" outqueue[%02d] . . . . : 0x%lx", i, ptr_server->outqueue[i]);
weechat_log_printf (" last_outqueue[%02d]. . : 0x%lx", i, ptr_server->last_outqueue[i]);
}
weechat_log_printf (" redirects. . . . . . : 0x%lx", ptr_server->redirects);
weechat_log_printf (" last_redirect. . . . : 0x%lx", ptr_server->last_redirect);
weechat_log_printf (" buffer . . . . . . . : 0x%lx", ptr_server->buffer);
weechat_log_printf (" buffer_as_string . . : 0x%lx", ptr_server->buffer_as_string);
weechat_log_printf (" channels . . . . . . : 0x%lx", ptr_server->channels);
@@ -4237,6 +4298,8 @@ irc_server_print_log ()
weechat_log_printf (" prev_server. . . . . : 0x%lx", ptr_server->prev_server);
weechat_log_printf (" next_server. . . . . : 0x%lx", ptr_server->next_server);
irc_redirect_print_log (ptr_server);
for (ptr_channel = ptr_server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
{
+3
View File
@@ -108,6 +108,7 @@ struct t_irc_outqueue
char *message_after_mod; /* msg after modifier(s) */
int modified; /* msg was modified by modifier(s) */
char *tags; /* tags (used by Relay plugin) */
struct t_irc_redirect *redirect; /* command redirection */
struct t_irc_outqueue *next_outqueue; /* link to next msg in queue */
struct t_irc_outqueue *prev_outqueue; /* link to prev msg in queue */
};
@@ -169,6 +170,8 @@ struct t_irc_server
struct t_irc_outqueue *outqueue[2]; /* queue for outgoing messages */
/* with 2 priorities (high/low) */
struct t_irc_outqueue *last_outqueue[2]; /* last outgoing message */
struct t_irc_redirect *redirects; /* command redirections */
struct t_irc_redirect *last_redirect; /* last command redirection */
struct t_gui_buffer *buffer; /* GUI buffer allocated for server */
char *buffer_as_string; /* used to return buffer info */
struct t_irc_channel *channels; /* opened channels on server */
+89
View File
@@ -34,6 +34,7 @@
#include "irc-channel.h"
#include "irc-nick.h"
#include "irc-raw.h"
#include "irc-redirect.h"
struct t_irc_server *irc_upgrade_current_server = NULL;
@@ -51,6 +52,8 @@ irc_upgrade_save_all_data (struct t_upgrade_file *upgrade_file)
struct t_irc_server *ptr_server;
struct t_irc_channel *ptr_channel;
struct t_irc_nick *ptr_nick;
struct t_irc_redirect *ptr_redirect;
struct t_irc_redirect_pattern *ptr_redirect_pattern;
struct t_irc_raw_message *ptr_raw_message;
int rc;
@@ -73,6 +76,7 @@ irc_upgrade_save_all_data (struct t_upgrade_file *upgrade_file)
if (!rc)
return 0;
/* save server channels and nicks */
for (ptr_channel = ptr_server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
{
@@ -112,6 +116,27 @@ irc_upgrade_save_all_data (struct t_upgrade_file *upgrade_file)
return 0;
}
}
/* save server redirects */
for (ptr_redirect = ptr_server->redirects; ptr_redirect;
ptr_redirect = ptr_redirect->next_redirect)
{
/* save channel */
infolist = weechat_infolist_new ();
if (!infolist)
return 0;
if (!irc_redirect_add_to_infolist (infolist, ptr_redirect))
{
weechat_infolist_free (infolist);
return 0;
}
rc = weechat_upgrade_write_object (upgrade_file,
IRC_UPGRADE_TYPE_REDIRECT,
infolist);
weechat_infolist_free (infolist);
if (!rc)
return 0;
}
}
/* save raw messages */
@@ -134,6 +159,30 @@ irc_upgrade_save_all_data (struct t_upgrade_file *upgrade_file)
return 0;
}
/* save redirect patterns */
for (ptr_redirect_pattern = irc_redirect_patterns; ptr_redirect_pattern;
ptr_redirect_pattern = ptr_redirect_pattern->next_redirect)
{
/* save only temporary patterns (created by other plugins/scripts) */
if (ptr_redirect_pattern->temp_pattern)
{
infolist = weechat_infolist_new ();
if (!infolist)
return 0;
if (!irc_redirect_pattern_add_to_infolist (infolist, ptr_redirect_pattern))
{
weechat_infolist_free (infolist);
return 0;
}
rc = weechat_upgrade_write_object (upgrade_file,
IRC_UPGRADE_TYPE_REDIRECT_PATTERN,
infolist);
weechat_infolist_free (infolist);
if (!rc)
return 0;
}
}
return 1;
}
@@ -204,6 +253,7 @@ irc_upgrade_read_cb (void *data,
char *buf, option_name[64];
const char *buffer_name, *str, *nick;
struct t_irc_nick *ptr_nick;
struct t_irc_redirect *ptr_redirect;
struct t_gui_buffer *ptr_buffer;
/* make C compiler happy */
@@ -382,6 +432,45 @@ irc_upgrade_read_cb (void *data,
}
}
break;
case IRC_UPGRADE_TYPE_REDIRECT:
if (irc_upgrade_current_server)
{
ptr_redirect = irc_redirect_new_with_commands (
irc_upgrade_current_server,
weechat_infolist_string (infolist, "pattern"),
weechat_infolist_string (infolist, "signal"),
weechat_infolist_integer (infolist, "count"),
weechat_infolist_string (infolist, "string"),
weechat_infolist_integer (infolist, "timeout"),
weechat_infolist_string (infolist, "cmd_start"),
weechat_infolist_string (infolist, "cmd_stop"),
weechat_infolist_string (infolist, "cmd_extra"),
weechat_infolist_string (infolist, "cmd_filter"));
if (ptr_redirect)
{
ptr_redirect->current_count = weechat_infolist_integer (infolist, "current_count");
str = weechat_infolist_string (infolist, "command");
if (str)
ptr_redirect->command = strdup (str);
ptr_redirect->start_time = weechat_infolist_time (infolist, "start_time");
ptr_redirect->cmd_start_received = weechat_infolist_integer (infolist, "cmd_start_received");
ptr_redirect->cmd_stop_received = weechat_infolist_integer (infolist, "cmd_stop_received");
str = weechat_infolist_string (infolist, "output");
if (str)
ptr_redirect->output = strdup (str);
ptr_redirect->output_size = weechat_infolist_integer (infolist, "output_size");
}
}
break;
case IRC_UPGRADE_TYPE_REDIRECT_PATTERN:
irc_redirect_pattern_new (
weechat_infolist_string (infolist, "name"),
weechat_infolist_integer (infolist, "temp_pattern"),
weechat_infolist_integer (infolist, "timeout"),
weechat_infolist_string (infolist, "cmd_start"),
weechat_infolist_string (infolist, "cmd_stop"),
weechat_infolist_string (infolist, "cmd_extra"));
break;
case IRC_UPGRADE_TYPE_RAW_MESSAGE:
irc_raw_message_add_to_list (weechat_infolist_time (infolist, "date"),
weechat_infolist_string (infolist, "prefix"),
+2
View File
@@ -30,6 +30,8 @@ enum t_irc_upgrade_type
IRC_UPGRADE_TYPE_CHANNEL,
IRC_UPGRADE_TYPE_NICK,
IRC_UPGRADE_TYPE_RAW_MESSAGE,
IRC_UPGRADE_TYPE_REDIRECT_PATTERN,
IRC_UPGRADE_TYPE_REDIRECT,
};
extern int irc_upgrade_save ();
+9
View File
@@ -40,6 +40,7 @@
#include "irc-channel.h"
#include "irc-nick.h"
#include "irc-raw.h"
#include "irc-redirect.h"
#include "irc-upgrade.h"
@@ -164,6 +165,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
irc_info_init ();
irc_redirect_init ();
/* hook some signals */
irc_debug_init ();
weechat_hook_signal ("quit", &irc_signal_quit_cb, NULL);
@@ -173,6 +176,10 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
weechat_hook_signal ("xfer_send_accept_resume", &irc_server_xfer_send_accept_resume_cb, NULL);
weechat_hook_signal ("irc_input_send", &irc_input_send_cb, NULL);
/* hook hsignals for redirection */
weechat_hook_hsignal ("irc_redirect_pattern", &irc_redirect_pattern_hsignal_cb, NULL);
weechat_hook_hsignal ("irc_redirect_command", &irc_redirect_command_hsignal_cb, NULL);
/* modifiers */
weechat_hook_modifier ("irc_color_decode", &irc_color_modifier_cb, NULL);
weechat_hook_modifier ("irc_color_encode", &irc_color_modifier_cb, NULL);
@@ -262,5 +269,7 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
irc_config_free ();
irc_redirect_end ();
return WEECHAT_RC_OK;
}