pidgin: 9e8a5e8d: Cleanup some duplication and simplify th...

datallah at pidgin.im datallah at pidgin.im
Tue Jun 17 23:21:21 EDT 2008


-----------------------------------------------------------------
Revision: 9e8a5e8d1ce90a9920d2d3f68e0ad2854134b4b5
Ancestor: 5dc14fb64fe3a0d62f23d74764445ca9cf498c81
Author: datallah at pidgin.im
Date: 2008-06-18T03:14:47
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/9e8a5e8d1ce90a9920d2d3f68e0ad2854134b4b5

Modified files:
        libpurple/protocols/jabber/jabber.c

ChangeLog: 

Cleanup some duplication and simplify this.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/jabber.c	cc3fd99cf97449784f8e06a850c9a705e34da3bd
+++ libpurple/protocols/jabber/jabber.c	1e6cb816fea7d89f9135b1a8feb5b737d8dbc5b2
@@ -273,9 +273,42 @@ static void jabber_send_cb(gpointer data
 	purple_circ_buffer_mark_read(js->write_buffer, ret);
 }
 
+static gboolean do_jabber_send_raw(JabberStream *js, const char *data, int len)
+{
+	int ret;
+	gboolean success = TRUE;
+
+	if (len == -1)
+		len = strlen(data);
+
+	if (js->writeh == 0)
+		ret = jabber_do_send(js, data, len);
+	else {
+		ret = -1;
+		errno = EAGAIN;
+	}
+
+	if (ret < 0 && errno != EAGAIN) {
+		purple_connection_error_reason (js->gc,
+			PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
+			_("Write error"));
+		success = FALSE;
+	} else if (ret < len) {
+		if (ret < 0)
+			ret = 0;
+		if (js->writeh == 0)
+			js->writeh = purple_input_add(
+				js->gsc ? js->gsc->fd : js->fd,
+				PURPLE_INPUT_WRITE, jabber_send_cb, js);
+		purple_circ_buffer_append(js->write_buffer,
+			data + ret, len - ret);
+	}
+
+	return success;
+}
+
 void jabber_send_raw(JabberStream *js, const char *data, int len)
 {
-	int ret;
 
 	/* because printing a tab to debug every minute gets old */
 	if(strcmp(data, "\t"))
@@ -284,85 +317,39 @@ void jabber_send_raw(JabberStream *js, c
 
 	/* If we've got a security layer, we need to encode the data,
 	 * splitting it on the maximum buffer length negotiated */
-	
+
 	purple_signal_emit(my_protocol, "jabber-sending-text", js->gc, &data);
 	if (data == NULL)
 		return;
-	
+
 #ifdef HAVE_CYRUS_SASL
 	if (js->sasl_maxbuf>0) {
-		int pos;
+		int pos = 0;
 
 		if (!js->gsc && js->fd<0)
 			return;
-		pos = 0;
+
 		if (len == -1)
 			len = strlen(data);
+
 		while (pos < len) {
 			int towrite;
 			const char *out;
 			unsigned olen;
 
-			if ((len - pos) < js->sasl_maxbuf)
-				towrite = len - pos;
-			else
-				towrite = js->sasl_maxbuf;
+			towrite = MIN((len - pos), js->sasl_maxbuf);
 
 			sasl_encode(js->sasl, &data[pos], towrite, &out, &olen);
 			pos += towrite;
 
-			if (js->writeh == 0)
-				ret = jabber_do_send(js, out, olen);
-			else {
-				ret = -1;
-				errno = EAGAIN;
-			}
-
-			if (ret < 0 && errno != EAGAIN)
-				purple_connection_error_reason (js->gc,
-					PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
-					_("Write error"));
-			else if (ret < olen) {
-				if (ret < 0)
-					ret = 0;
-				if (js->writeh == 0)
-					js->writeh = purple_input_add(
-						js->gsc ? js->gsc->fd : js->fd,
-						PURPLE_INPUT_WRITE,
-						jabber_send_cb, js);
-				purple_circ_buffer_append(js->write_buffer,
-					out + ret, olen - ret);
-			}
+			if (!do_jabber_send_raw(js, out, olen))
+				break;
 		}
 		return;
 	}
 #endif
 
-	if (len == -1)
-		len = strlen(data);
-
-	if (js->writeh == 0)
-		ret = jabber_do_send(js, data, len);
-	else {
-		ret = -1;
-		errno = EAGAIN;
-	}
-
-	if (ret < 0 && errno != EAGAIN)
-		purple_connection_error_reason (js->gc,
-			PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
-			_("Write error"));
-	else if (ret < len) {
-		if (ret < 0)
-			ret = 0;
-		if (js->writeh == 0)
-			js->writeh = purple_input_add(
-				js->gsc ? js->gsc->fd : js->fd,
-				PURPLE_INPUT_WRITE, jabber_send_cb, js);
-		purple_circ_buffer_append(js->write_buffer,
-			data + ret, len - ret);
-	}
-	return;
+	do_jabber_send_raw(js, data, len);
 }
 
 int jabber_prpl_send_raw(PurpleConnection *gc, const char *buf, int len)


More information about the Commits mailing list