im.pidgin.pidgin: aa714a29059f790cb003a8fe1bec9c8873d09e33

datallah at pidgin.im datallah at pidgin.im
Mon Nov 12 18:21:27 EST 2007


-----------------------------------------------------------------
Revision: aa714a29059f790cb003a8fe1bec9c8873d09e33
Ancestor: b5e5dd9f65bbbc5b686cf039a4c0c08ef94cb79a
Author: datallah at pidgin.im
Date: 2007-11-12T05:09:17
Branch: im.pidgin.pidgin

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

ChangeLog: 

Leak fix, cleanup and code reuse.

-------------- next part --------------
============================================================
--- libpurple/protocols/bonjour/bonjour_ft.c	1cedfa71db2df860a4fd6374b456ac19ba2100b1
+++ libpurple/protocols/bonjour/bonjour_ft.c	ab132b61fb95894fea7fd8d5f5a6bcebb34e81ce
@@ -303,13 +303,13 @@ bonjour_free_xfer(PurpleXfer *xfer)
 		purple_debug_info("Bonjour", "bonjour-free-xfer-null.\n");
 		return;
 	}
-	purple_debug_info("Bonjour", "bonjour-free-xfer-%x.\n", (int)xfer);
+	purple_debug_info("Bonjour", "bonjour-free-xfer-%p.\n", xfer);
 	xf = (XepXfer*)xfer->data;
 	if(xf != NULL){
 		bd = (BonjourData*)xf->data;
 		if(bd != NULL){
 			bd->xfer_lists = g_list_remove(bd->xfer_lists, xfer);
-			purple_debug_info("Bonjour", "B free xfer from lists(0x%x).\n", (int)bd->xfer_lists);
+			purple_debug_info("Bonjour", "B free xfer from lists(%p).\n", bd->xfer_lists);
 		}
 		if (xf->proxy_connection != NULL)
 			purple_proxy_connect_cancel(xf->proxy_connection);
@@ -318,10 +318,11 @@ bonjour_free_xfer(PurpleXfer *xfer)
 		g_free(xf->jid);
 		g_free(xf->proxy_host);
 		g_free(xf->buddy_ip);
+		g_free(xf->sid);
 		g_free(xf);
 		xfer->data = NULL;
 	}
-	purple_debug_info("Bonjour", "Need close socket=0x%x.\n", xfer->fd);
+	purple_debug_info("Bonjour", "Need close socket=%d.\n", xfer->fd);
 }
 
 PurpleXfer *
@@ -347,7 +348,7 @@ bonjour_new_xfer(PurpleConnection *gc, c
 			return NULL;
 		}
 		xep_xfer->data = bd;
-		purple_debug_info("Bonjour", "Bonjour-new-xfer bd=0x%x data=0x%x.\n",(int)bd, (int)xep_xfer->data);
+		purple_debug_info("Bonjour", "Bonjour-new-xfer bd=%p data=%p.\n", bd, xep_xfer->data);
 		xep_xfer->mode = XEP_BYTESTREAMS | XEP_IBB;
 		xfer->data = xep_xfer;
 		xep_xfer->sid = NULL;
@@ -461,7 +462,7 @@ xep_si_parse(PurpleConnection *pc, xmlno
 				purple_xfer_cancel_remote(xfer);
 			}
 		} else {
-			purple_debug_info("Bonjour", "si offer Message type - Unknown-%d.\n",type);
+			purple_debug_info("Bonjour", "si offer Message type - Unknown-%d.\n", type);
 		}
 	}
 }
@@ -504,7 +505,7 @@ xep_bytestreams_parse(PurpleConnection *
 							xf->proxy_host = g_strdup(host);
 							xf->proxy_port = portnum;
 							purple_debug_info("Bonjour", "bytestream offer parse"
-							                  "jid=%s host=%s port=0x%x.\n",jid, host, portnum);
+							                  "jid=%s host=%s port=%d.\n", jid, host, portnum);
 							bonjour_bytestreams_connect(xfer);
 						}
 					} else {
@@ -516,7 +517,7 @@ xep_bytestreams_parse(PurpleConnection *
 			}
 
 		} else {
-			purple_debug_info("Bonjour", "bytestream offer Message type - Unknown-%d.\n",type);
+			purple_debug_info("Bonjour", "bytestream offer Message type - Unknown-%d.\n", type);
 		}
 	}
 }
@@ -631,7 +632,7 @@ bonjour_sock5_request_cb(gpointer data, 
 		} else if(acceptfd == -1) {
 
 		} else {
-			purple_debug_info("Bonjour", "Conjour-sock5-request-cb. state= %d, accept=%d\n", xf->sock5_req_state,acceptfd);
+			purple_debug_info("Bonjour", "Conjour-sock5-request-cb. state= %d, accept=%d\n", xf->sock5_req_state, acceptfd);
 			purple_input_remove(xfer->watcher);
 			close(source);
 			xfer->watcher = purple_input_add(acceptfd, PURPLE_INPUT_READ,
============================================================
--- libpurple/protocols/bonjour/jabber.c	42a1f2a98905f8dbf1398e0e96e91d8d108e8e93
+++ libpurple/protocols/bonjour/jabber.c	e5ae3b581340d9231c23ca4391cd68cf59b84dd4
@@ -711,23 +711,21 @@ _connected_to_buddy(gpointer data, gint 
 	}
 }
 
-int
-bonjour_jabber_send_message(BonjourJabber *data, const gchar *to, const gchar *body)
+static PurpleBuddy *
+_find_or_start_conversation(BonjourJabber *data, const gchar *to)
 {
-	xmlnode *message_node, *node, *node2;
-	gchar *message;
-	PurpleBuddy *pb;
-	BonjourBuddy *bb;
-	int ret;
+	PurpleBuddy *pb = NULL;
+	BonjourBuddy *bb = NULL;
 
+	g_return_val_if_fail(data != NULL, NULL);
+	g_return_val_if_fail(to != NULL, NULL);
+
 	pb = purple_find_buddy(data->account, to);
-	if (pb == NULL) {
-		purple_debug_info("bonjour", "Can't send a message to an offline buddy (%s).\n", to);
+	if (pb == NULL || pb->proto_data == NULL)
 		/* You can not send a message to an offline buddy */
-		return -10000;
-	}
+		return NULL;
 
-	bb = pb->proto_data;
+	bb = (BonjourBuddy *) pb->proto_data;
 
 	/* Check if there is a previously open conversation */
 	if (bb->conversation == NULL)
@@ -735,6 +733,8 @@ bonjour_jabber_send_message(BonjourJabbe
 		PurpleProxyConnectData *connect_data;
 		PurpleProxyInfo *proxy_info;
 
+		purple_debug_info("Bonjour", "Starting conversation with %s\n", to);
+
 		/* Make sure that the account always has a proxy of "none".
 		 * This is kind of dirty, but proxy_connect_none() isn't exposed. */
 		proxy_info = purple_account_get_proxy_info(data->account);
@@ -744,13 +744,12 @@ bonjour_jabber_send_message(BonjourJabbe
 		}
 		purple_proxy_info_set_type(proxy_info, PURPLE_PROXY_NONE);
 
-		connect_data =
-			purple_proxy_connect(data->account->gc, data->account, bb->ip,
-					     bb->port_p2pj, _connected_to_buddy, pb);
+		connect_data = purple_proxy_connect(data->account->gc, data->account,
+						    bb->ip, bb->port_p2pj, _connected_to_buddy, pb);
 
 		if (connect_data == NULL) {
 			purple_debug_error("bonjour", "Unable to connect to buddy (%s).\n", to);
-			return -10001;
+			return NULL;
 		}
 
 		bb->conversation = bonjour_jabber_conv_new();
@@ -759,7 +758,27 @@ bonjour_jabber_send_message(BonjourJabbe
 		 * that neeeds to wait until we're actually connected. */
 		bb->conversation->tx_handler = 0;
 	}
+	return pb;
+}
 
+int
+bonjour_jabber_send_message(BonjourJabber *data, const gchar *to, const gchar *body)
+{
+	xmlnode *message_node, *node, *node2;
+	gchar *message;
+	PurpleBuddy *pb;
+	BonjourBuddy *bb;
+	int ret;
+
+	pb = _find_or_start_conversation(data, to);
+	if (pb == NULL) {
+		purple_debug_info("bonjour", "Can't send a message to an offline buddy (%s).\n", to);
+		/* You can not send a message to an offline buddy */
+		return -10000;
+	}
+
+	bb = pb->proto_data;
+
 	message_node = xmlnode_new("message");
 	xmlnode_set_attrib(message_node, "to", bb->name);
 	xmlnode_set_attrib(message_node, "from", purple_account_get_username(data->account));
@@ -853,58 +872,7 @@ bonjour_jabber_stop(BonjourJabber *data)
 		g_slist_free(buddies);
 	}
 }
-static PurpleBuddy *
-_start_conversation(BonjourJabber *data, const gchar *to)
-{
-	PurpleBuddy *pb = NULL;
-	BonjourBuddy *bb = NULL;
 
-	if(data == NULL || to == NULL)
-		return NULL;
-
-	purple_debug_info("Bonjour", "start-conversation with  %s - \n", to);
-
-	pb = purple_find_buddy(data->account, to);
-	if (pb == NULL)
-		/* You can not send a message to an offline buddy */
-		return NULL;
-
-	bb = (BonjourBuddy *) pb->proto_data;
-	if(bb == NULL)
-		return NULL;
-
-	/* Check if there is a previously open conversation */
-	if (bb->conversation == NULL)
-	{
-		PurpleProxyConnectData *connect_data;
-		PurpleProxyInfo *proxy_info;
-
-		/* Make sure that the account always has a proxy of "none".
-		 * This is kind of dirty, but proxy_connect_none() isn't exposed. */
-		proxy_info = purple_account_get_proxy_info(data->account);
-		if (proxy_info == NULL) {
-			proxy_info = purple_proxy_info_new();
-			purple_account_set_proxy_info(data->account, proxy_info);
-		}
-		purple_proxy_info_set_type(proxy_info, PURPLE_PROXY_NONE);
-
-		connect_data = purple_proxy_connect(data->account->gc, data->account,
-						    bb->ip, bb->port_p2pj, _connected_to_buddy, pb);
-
-		if (connect_data == NULL) {
-			purple_debug_error("bonjour", "Unable to connect to buddy (%s).\n", to);
-			return NULL;
-		}
-
-		bb->conversation = bonjour_jabber_conv_new();
-		bb->conversation->connect_data = connect_data;
-		/* We don't want _send_data() to register the tx_handler;
-		 * that neeeds to wait until we're actually connected. */
-		bb->conversation->tx_handler = 0;
-	}
-	return pb;
-}
-
 XepIq *
 xep_iq_new(void *data, XepIqType type, const gchar *to, const gchar *id)
 {
@@ -998,22 +966,21 @@ xep_iq_send(XepIq *iq)
 int
 xep_iq_send(XepIq *iq)
 {
-	char *msg = NULL;
-	gint msg_len = 0;
 	int ret = -1;
 	PurpleBuddy *pb = NULL;
-	/* Convert xml node into stream */
-	msg = xmlnode_to_str(iq->node, &msg_len);
-	xmlnode_free(iq->node);
+
 	/* start the talk, reuse the message socket  */
-	pb = _start_conversation ((BonjourJabber*)iq->data, iq->to);
+	pb = _find_or_start_conversation ((BonjourJabber*)iq->data, iq->to);
 	/* Send the message */
-	if (pb != NULL)
+	if (pb != NULL) {
+		/* Convert xml node into stream */
+		gchar *msg = xmlnode_to_str(iq->node, NULL);
 		ret = _send_data(pb, msg);
-	g_free(msg);
-	if (ret == -1)
-		return -1;
-	return 0;
+		g_free(msg);
+	}
+	xmlnode_free(iq->node);
+
+	return (ret >= 0) ? 0 : -1;
 }
 
 /* This returns a ';' delimited string containing all non-localhost IPs */


More information about the Commits mailing list