changeset 31703:54a700cedb38

Fix races between irc_send_raw() and normal prpl-internal sends. Fixes #14263
author Ethan Blanton <elb@pidgin.im>
date Sat, 25 Jun 2011 02:42:08 +0000
parents 47c604efed32
children a99a4f9b7171
files libpurple/protocols/irc/irc.c libpurple/protocols/irc/irc.h
diffstat 2 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/irc/irc.c	Fri Jun 24 16:44:06 2011 +0000
+++ b/libpurple/protocols/irc/irc.c	Sat Jun 25 02:42:08 2011 +0000
@@ -101,7 +101,11 @@
 static int irc_send_raw(PurpleConnection *gc, const char *buf, int len)
 {
 	struct irc_conn *irc = (struct irc_conn*)gc->proto_data;
-	return do_send(irc, buf, len);
+	if (len == -1) {
+		len = strlen(buf);
+	}
+	irc_send_len(irc, buf, len);
+	return len;
 }
 
 static void
@@ -144,16 +148,18 @@
 
 int irc_send(struct irc_conn *irc, const char *buf)
 {
-	int ret, buflen;
+    return irc_send_len(irc, buf, strlen(buf));
+}
+
+int irc_send_len(struct irc_conn *irc, const char *buf, int buflen)
+{
+	int ret;
  	char *tosend= g_strdup(buf);
 
 	purple_signal_emit(_irc_plugin, "irc-sending-text", purple_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, tosend, buflen);
--- a/libpurple/protocols/irc/irc.h	Fri Jun 24 16:44:06 2011 +0000
+++ b/libpurple/protocols/irc/irc.h	Sat Jun 25 02:42:08 2011 +0000
@@ -106,6 +106,7 @@
 typedef int (*IRCCmdCallback) (struct irc_conn *irc, const char *cmd, const char *target, const char **args);
 
 int irc_send(struct irc_conn *irc, const char *buf);
+int irc_send_len(struct irc_conn *irc, const char *buf, int len);
 gboolean irc_blist_timeout(struct irc_conn *irc);
 gboolean irc_who_channel_timeout(struct irc_conn *irc);
 void irc_buddy_query(struct irc_conn *irc);