soc.2010.msn-tlc: 96ca69fa: Add support to ref/unref SlpMessageParts..

masca at cpw.pidgin.im masca at cpw.pidgin.im
Wed Jul 7 21:41:28 EDT 2010


----------------------------------------------------------------------
Revision: 96ca69fa93f6afbfdad3cfde404932d9855178c4
Parent:   d69cf67a92dca1d570bd214aac76805af1d1d703
Author:   masca at cpw.pidgin.im
Date:     07/06/10 15:00:21
Branch:   im.pidgin.soc.2010.msn-tlc
URL: http://d.pidgin.im/viewmtn/revision/info/96ca69fa93f6afbfdad3cfde404932d9855178c4

Changelog: 

Add support to ref/unref SlpMessageParts.

Changes against parent d69cf67a92dca1d570bd214aac76805af1d1d703

  patched  libpurple/protocols/msn/directconn.c
  patched  libpurple/protocols/msn/msg.c
  patched  libpurple/protocols/msn/slpmsg_part.c
  patched  libpurple/protocols/msn/slpmsg_part.h

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/msg.c	722c049914d84a9dcb77ce499aaee2c958fd2d4d
+++ libpurple/protocols/msn/msg.c	d993f4a1d6823a9be723978d587aee2cc207512b
@@ -72,7 +72,7 @@ msn_message_destroy(MsnMessage *msg)
 
 	g_hash_table_destroy(msg->header_table);
 	g_list_free(msg->header_list);
-	msn_slpmsgpart_destroy(msg->part);
+	msn_slpmsgpart_unref(msg->part);
 
 	g_free(msg);
 }
============================================================
--- libpurple/protocols/msn/directconn.c	02ce8a59fae9e3d5fbf701d2fc0f1b146f941d20
+++ libpurple/protocols/msn/directconn.c	c66ada2cacd78bcf63481c72cc5366cc1877402c
@@ -116,7 +116,7 @@ msn_dc_destroy_packet(MsnDirectConnPacke
 		msn_message_unref(p->msg);
 #endif
 	if (p->part)
-		msn_slpmsgpart_destroy(p->part);
+		msn_slpmsgpart_unref(p->part);
 
 	g_free(p);
 }
============================================================
--- libpurple/protocols/msn/slpmsg_part.c	4c14c86850074788c9886bb250f667c9e8f976e9
+++ libpurple/protocols/msn/slpmsg_part.c	323df8b2607a93ea42ce5d72fd56214969798b9b
@@ -17,7 +17,7 @@ MsnSlpMessagePart *msn_slpmsgpart_new(Ms
 	part->ack_cb = msn_slpmsgpart_ack;
 	part->nak_cb = msn_slpmsgpart_nak;
 
-	return part;
+	return msn_slpmsgpart_ref(part);
 }
 
 MsnSlpMessagePart *msn_slpmsgpart_new_from_data(const char *data, size_t data_len)
@@ -61,6 +61,12 @@ void msn_slpmsgpart_destroy(MsnSlpMessag
 	if (!part)
 		return;
 
+	if (part->ref_count > 0) {
+		msn_slpmsgpart_unref(part);
+		
+		return;
+	}
+
 	g_free(part->header);
 	g_free(part->footer);
 
@@ -68,6 +74,30 @@ void msn_slpmsgpart_destroy(MsnSlpMessag
 
 }
 
+MsnSlpMessagePart *msn_slpmsgpart_ref(MsnSlpMessagePart *part)
+{
+	g_return_val_if_fail(part != NULL, NULL);
+	part->ref_count ++;
+
+	return part;
+}
+
+MsnSlpMessagePart *msn_slpmsgpart_unref(MsnSlpMessagePart *part)
+{
+	g_return_val_if_fail(part != NULL, NULL);
+	g_return_val_if_fail(part->ref_count > 0, NULL);
+
+	part->ref_count--;
+
+	if (part->ref_count == 0) {
+		msn_slpmsgpart_destroy(part);
+
+		 return NULL;
+	}
+
+	return part;
+}
+
 void msn_slpmsgpart_set_bin_data(MsnSlpMessagePart *part, const void *data, size_t len)
 {
 	g_return_if_fail(part != NULL);
============================================================
--- libpurple/protocols/msn/slpmsg_part.h	75548a15e0c2bb5856cfe056d1ec437004827d03
+++ libpurple/protocols/msn/slpmsg_part.h	ef969f38130c46b8089b669352806a053ec3e8b1
@@ -8,6 +8,8 @@ struct _MsnSlpMessagePart
 
 struct _MsnSlpMessagePart
 {
+	int ref_count;
+
 	MsnP2PHeader *header;
 	MsnP2PFooter *footer;
 
@@ -25,6 +27,10 @@ void msn_slpmsgpart_destroy(MsnSlpMessag
 
 void msn_slpmsgpart_destroy(MsnSlpMessagePart *part);
 
+MsnSlpMessagePart *msn_slpmsgpart_ref(MsnSlpMessagePart *part);
+
+MsnSlpMessagePart *msn_slpmsgpart_unref(MsnSlpMessagePart *part);
+
 void msn_slpmsgpart_set_bin_data(MsnSlpMessagePart *part, const void *data, size_t len);
 
 char *msn_slpmsgpart_serialize(MsnSlpMessagePart *part, size_t *ret_size);


More information about the Commits mailing list