summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2008-07-18 11:16:20 +0200
committerSebastien Helleu <flashcode@flashtux.org>2008-07-18 11:16:20 +0200
commit7f7765f7cf700b0fe99df0cc9cf860da2f7d9fdb (patch)
tree99c41f388dee79342c0ae45cccc8556388eef95f
parentfe302c1722bd9af65c78a43e3b4bab279f5026b4 (diff)
downloadweechat-7f7765f7cf700b0fe99df0cc9cf860da2f7d9fdb.zip
Add signals for IRC messages (recv/sent)
-rw-r--r--src/plugins/irc/irc-protocol.c3
-rw-r--r--src/plugins/irc/irc-server.c50
-rw-r--r--src/plugins/irc/irc-server.h10
3 files changed, 56 insertions, 7 deletions
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index a1e3c99a9..a8777965b 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -4115,6 +4115,9 @@ irc_protocol_recv_command (struct t_irc_server *server, const char *entire_line,
if (!command)
return;
+ /* send signal with received command */
+ irc_server_send_signal (server, "irc_in", command, entire_line);
+
/* look for IRC command */
cmd_found = -1;
for (i = 0; irc_protocol_messages[i].name; i++)
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index c0739c9f0..2f5413893 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -491,14 +491,15 @@ irc_server_alloc_with_url (const char *irc_url)
*/
void
-irc_server_outqueue_add (struct t_irc_server *server, const char *msg1,
- const char *msg2, int modified)
+irc_server_outqueue_add (struct t_irc_server *server, const char *command,
+ const char *msg1, const char *msg2, int modified)
{
struct t_irc_outqueue *new_outqueue;
new_outqueue = malloc (sizeof (*new_outqueue));
if (new_outqueue)
{
+ new_outqueue->command = (command) ? strdup (command) : strdup ("unknown");
new_outqueue->message_before_mod = (msg1) ? strdup (msg1) : NULL;
new_outqueue->message_after_mod = (msg2) ? strdup (msg2) : NULL;
new_outqueue->modified = modified;
@@ -536,7 +537,10 @@ irc_server_outqueue_free (struct t_irc_server *server,
if (outqueue->next_outqueue)
(outqueue->next_outqueue)->prev_outqueue = outqueue->prev_outqueue;
-
+
+ /* free data */
+ if (outqueue->command)
+ free (outqueue->command);
if (outqueue->message_before_mod)
free (outqueue->message_before_mod);
if (outqueue->message_after_mod)
@@ -553,7 +557,9 @@ void
irc_server_outqueue_free_all (struct t_irc_server *server)
{
while (server->outqueue)
+ {
irc_server_outqueue_free (server, server->outqueue);
+ }
}
/*
@@ -813,6 +819,29 @@ irc_server_rename (struct t_irc_server *server, const char *new_name)
}
/*
+ * irc_server_send_signal: send a signal for an IRC message (received or sent)
+ */
+
+void
+irc_server_send_signal (struct t_irc_server *server, const char *signal,
+ const char *command, const char *full_message)
+{
+ int length;
+ char *str_signal;
+
+ length = strlen (server->name) + 1 + strlen (signal) + 1 + strlen (command) + 1;
+ str_signal = malloc (length);
+ if (str_signal)
+ {
+ snprintf (str_signal, length,
+ "%s,%s_%s", server->name, signal, command);
+ weechat_hook_signal_send (str_signal, WEECHAT_HOOK_SIGNAL_STRING,
+ (void *)full_message);
+ free (str_signal);
+ }
+}
+
+/*
* irc_server_send: send data to IRC server
* return number of bytes sent, -1 if error
*/
@@ -894,6 +923,13 @@ irc_server_outqueue_send (struct t_irc_server *server)
server->outqueue->message_after_mod);
if (pos)
pos[0] = '\r';
+
+ /* send signal with command that will be sent to server */
+ irc_server_send_signal (server, "irc_out",
+ server->outqueue->command,
+ server->outqueue->message_after_mod);
+
+ /* send command */
irc_server_send (server, server->outqueue->message_after_mod,
strlen (server->outqueue->message_after_mod));
server->last_user_message = time_now;
@@ -1106,7 +1142,7 @@ irc_server_send_one_msg (struct t_irc_server *server, const char *message)
/* if queue, then only queue message and send nothing now */
if (queue)
{
- irc_server_outqueue_add (server,
+ irc_server_outqueue_add (server, command,
(new_msg && first_message) ? message : NULL,
buffer,
(new_msg) ? 1 : 0);
@@ -1117,6 +1153,12 @@ irc_server_send_one_msg (struct t_irc_server *server, const char *message)
irc_debug_printf (server, 1, 0, message);
if (new_msg)
irc_debug_printf (server, 1, 1, ptr_msg);
+
+ /* send signal with command that will be sent to server */
+ irc_server_send_signal (server, "irc_out",
+ (command) ? command : "unknown",
+ ptr_msg);
+
if (irc_server_send (server, buffer, strlen (buffer)) <= 0)
rc = 0;
else
diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h
index 0271eb418..9486192ee 100644
--- a/src/plugins/irc/irc-server.h
+++ b/src/plugins/irc/irc-server.h
@@ -47,6 +47,7 @@
struct t_irc_outqueue
{
+ char *command; /* IRC command */
char *message_before_mod; /* msg before any modifier */
char *message_after_mod; /* msg after modifier(s) */
int modified; /* msg was modified by modifier(s) */
@@ -141,9 +142,11 @@ extern void irc_server_set_nicks (struct t_irc_server *server, const char *nicks
extern void irc_server_set_with_option (struct t_irc_server *server,
int index_option,
struct t_config_option *option);
+extern void irc_server_set_nick (struct t_irc_server *server, const char *nick);
extern void irc_server_init (struct t_irc_server *server);
extern struct t_irc_server *irc_server_alloc (const char *name);
extern int irc_server_alloc_with_url (const char *irc_url);
+extern void irc_server_free_all ();
extern struct t_irc_server *irc_server_new (const char *name, int autoconnect,
int autoreconnect,
int autoreconnect_delay,
@@ -157,15 +160,16 @@ extern struct t_irc_server *irc_server_new (const char *name, int autoconnect,
extern struct t_irc_server *irc_server_duplicate (struct t_irc_server *server,
const char *new_name);
extern int irc_server_rename (struct t_irc_server *server, const char *new_name);
-extern void irc_server_set_nick (struct t_irc_server *server, const char *nick);
+extern void irc_server_send_signal (struct t_irc_server *server,
+ const char *signal, const char *command,
+ const char *full_message);
+extern void irc_server_sendf (struct t_irc_server *server, const char *format, ...);
extern struct t_irc_server *irc_server_search (const char *server_name);
-extern void irc_server_free_all ();
extern int irc_server_connect (struct t_irc_server *server,
int disable_autojoin);
extern void irc_server_auto_connect (int auto_connect, int temp_server);
extern void irc_server_autojoin_channels ();
extern int irc_server_timer_cb (void *data);
-extern void irc_server_sendf (struct t_irc_server *server, const char *format, ...);
extern void irc_server_outqueue_free_all (struct t_irc_server *server);
extern int irc_server_get_channel_count (struct t_irc_server *server);
extern int irc_server_get_pv_count (struct t_irc_server *server);