# HG changeset patch # User Sean Egan # Date 1159218519 0 # Node ID bf1f941575beee857a28a66e387cb340f97dcd5d # Parent a426f09455750d4ec562483359160f4291644ed8 [gaim-migrate @ 17350] IRC signals for scripting IRC. Richard, you should use these for irchelper! committer: Tailor Script diff -r a426f0945575 -r bf1f941575be libgaim/protocols/irc/irc.c --- a/libgaim/protocols/irc/irc.c Mon Sep 25 07:31:48 2006 +0000 +++ b/libgaim/protocols/irc/irc.c Mon Sep 25 21:08:39 2006 +0000 @@ -61,7 +61,7 @@ static gboolean irc_nick_equal(const char *nick1, const char *nick2); static void irc_buddy_free(struct irc_buddy *ib); -static GaimPlugin *_irc_plugin = NULL; +GaimPlugin *_irc_plugin = NULL; static const char *status_chars = "@+%&"; @@ -141,18 +141,26 @@ int irc_send(struct irc_conn *irc, const char *buf) { - int ret, buflen = strlen(buf); + int ret, buflen; + char *tosend= g_strdup(buf); + gaim_signal_emit(_irc_plugin, "irc-sending_text", gaim_account_get_connection(irc->account), &tosend); + if (tosend == NULL) + return 0; + + buflen = strlen(tosend); + + /* If we're not buffering writes, try to send immediately */ if (!irc->writeh) - ret = do_send(irc, buf, buflen); + ret = do_send(irc, tosend, buflen); else { ret = -1; errno = EAGAIN; } /* gaim_debug(GAIM_DEBUG_MISC, "irc", "sent%s: %s", - irc->gsc ? " (ssl)" : "", buf); */ + irc->gsc ? " (ssl)" : "", tosend); */ if (ret <= 0 && errno != EAGAIN) { gaim_connection_error(gaim_account_get_connection(irc->account), _("Server has disconnected")); @@ -163,10 +171,10 @@ irc->writeh = gaim_input_add( irc->gsc ? irc->gsc->fd : irc->fd, GAIM_INPUT_WRITE, irc_send_cb, irc); - gaim_circ_buffer_append(irc->outbuf, buf + ret, + gaim_circ_buffer_append(irc->outbuf, tosend + ret, buflen - ret); } - + g_free(tosend); return ret; } @@ -869,6 +877,19 @@ irc_send_raw, /* send_raw */ }; +static gboolean load_plugin (GaimPlugin *plugin) { + + gaim_signal_register(plugin, "irc-sending-text", + gaim_marshal_VOID__POINTER_POINTER, NULL, 2, + gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_CONNECTION), + gaim_value_new_outgoing(GAIM_TYPE_STRING)); + gaim_signal_register(plugin, "irc-receiving-text", + gaim_marshal_VOID__POINTER_POINTER, NULL, 2, + gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_CONNECTION), + gaim_value_new_outgoing(GAIM_TYPE_STRING)); + return TRUE; +} + static GaimPluginInfo info = { @@ -889,7 +910,7 @@ NULL, /**< author */ GAIM_WEBSITE, /**< homepage */ - NULL, /**< load */ + load_plugin, /**< load */ NULL, /**< unload */ NULL, /**< destroy */ diff -r a426f0945575 -r bf1f941575be libgaim/protocols/irc/parse.c --- a/libgaim/protocols/irc/parse.c Mon Sep 25 07:31:48 2006 +0000 +++ b/libgaim/protocols/irc/parse.c Mon Sep 25 21:08:39 2006 +0000 @@ -44,6 +44,8 @@ "orange", "yellow", "green", "teal", "cyan", "light blue", "pink", "grey", "light grey" }; +extern GaimPlugin *_irc_plugin; + /*typedef void (*IRCMsgCallback)(struct irc_conn *irc, char *from, char *name, char **args);*/ static struct _irc_msg { char *name; @@ -534,7 +536,8 @@ guint i; irc->recv_time = time(NULL); - + gaim_signal_emit(_irc_plugin, "irc-receiving-text", gaim_account_get_connection(irc->account), &input); + if (!strncmp(input, "PING ", 5)) { msg = irc_format(irc, "vv", "PONG", input + 5); irc_send(irc, msg);