comparison libpurple/protocols/irc/irc.c @ 32159: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 1a248102e437
children accce7b79737 3f47428bd4de
comparison
equal deleted inserted replaced
32158:47c604efed32 32159:54a700cedb38
99 } 99 }
100 100
101 static int irc_send_raw(PurpleConnection *gc, const char *buf, int len) 101 static int irc_send_raw(PurpleConnection *gc, const char *buf, int len)
102 { 102 {
103 struct irc_conn *irc = (struct irc_conn*)gc->proto_data; 103 struct irc_conn *irc = (struct irc_conn*)gc->proto_data;
104 return do_send(irc, buf, len); 104 if (len == -1) {
105 len = strlen(buf);
106 }
107 irc_send_len(irc, buf, len);
108 return len;
105 } 109 }
106 110
107 static void 111 static void
108 irc_send_cb(gpointer data, gint source, PurpleInputCondition cond) 112 irc_send_cb(gpointer data, gint source, PurpleInputCondition cond)
109 { 113 {
142 #endif 146 #endif
143 } 147 }
144 148
145 int irc_send(struct irc_conn *irc, const char *buf) 149 int irc_send(struct irc_conn *irc, const char *buf)
146 { 150 {
147 int ret, buflen; 151 return irc_send_len(irc, buf, strlen(buf));
152 }
153
154 int irc_send_len(struct irc_conn *irc, const char *buf, int buflen)
155 {
156 int ret;
148 char *tosend= g_strdup(buf); 157 char *tosend= g_strdup(buf);
149 158
150 purple_signal_emit(_irc_plugin, "irc-sending-text", purple_account_get_connection(irc->account), &tosend); 159 purple_signal_emit(_irc_plugin, "irc-sending-text", purple_account_get_connection(irc->account), &tosend);
151 if (tosend == NULL) 160 if (tosend == NULL)
152 return 0; 161 return 0;
153
154 buflen = strlen(tosend);
155
156 162
157 /* If we're not buffering writes, try to send immediately */ 163 /* If we're not buffering writes, try to send immediately */
158 if (!irc->writeh) 164 if (!irc->writeh)
159 ret = do_send(irc, tosend, buflen); 165 ret = do_send(irc, tosend, buflen);
160 else { 166 else {