changeset 20501:f6dff814d95f

cleans up ownership of soap callback data, this soap stuff is perfect weight-loss pill, because it makes you want to throw up
author Ka-Hing Cheung <khc@hxbc.us>
date Sun, 09 Sep 2007 01:42:46 +0000
parents 403ff626b803
children b5a2938b4549
files libpurple/protocols/msn/contact.c libpurple/protocols/msn/oim.c libpurple/protocols/msn/soap.c libpurple/protocols/msn/soap.h
diffstat 4 files changed, 71 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/contact.c	Sun Sep 09 00:50:14 2007 +0000
+++ b/libpurple/protocols/msn/contact.c	Sun Sep 09 01:42:46 2007 +0000
@@ -77,7 +77,8 @@
 void
 msn_callback_state_free(MsnCallbackState *state)
 {
-	g_return_if_fail(state != NULL);
+	if (state == NULL)
+		return;
 	
 	if (state->who != NULL)
 		g_free(state->who);
@@ -248,6 +249,9 @@
 	MsnSoapConn *soapconn = data;
 	MsnContact *contact;
 
+	if (soapconn->body == NULL)
+		return;
+
 	contact = soapconn->parent;
 	g_return_if_fail(contact != NULL);
 
@@ -533,6 +537,9 @@
 	const char *dynamicItemLastChange;
 	gchar *partner_scenario;
 
+	if (soapconn->body == NULL)
+		return;
+
 	purple_debug_misc("MSNCL","Got the contact list!\n");
 
 	contact = soapconn->parent;
@@ -902,6 +909,9 @@
 	MsnContact *contact;
 	MsnSession *session;
 
+	if (soapconn->body == NULL)
+		return;
+
 	contact = soapconn->parent;
 	g_return_if_fail(contact != NULL);
 	session = soapconn->session;
@@ -990,11 +1000,16 @@
 	g_return_if_fail(soapconn->data_cb != NULL);
 	g_return_if_fail(soapconn->session != NULL);
 	g_return_if_fail(soapconn->session->userlist != NULL);
+
+	state = (MsnCallbackState *) soapconn->data_cb;
+
+	if (soapconn->body == NULL) {
+		msn_callback_state_free(state);
+		return;
+	}
 	
 	userlist = soapconn->session->userlist;
 	
-	state = (MsnCallbackState *) soapconn->data_cb;
-	
 	purple_debug_info("MSNCL","Contact added successfully\n");
 
 	// the code this block is replacing didn't send ADL for yahoo contacts,
@@ -1078,14 +1093,19 @@
 	MsnCallbackState *state; 
 	MsnUserList *userlist;
 
-        g_return_if_fail(soapconn->data_cb != NULL);
-        g_return_if_fail(soapconn->session != NULL);
-        g_return_if_fail(soapconn->session->userlist != NULL);
+	g_return_if_fail(soapconn->data_cb != NULL);
+	g_return_if_fail(soapconn->session != NULL);
+	g_return_if_fail(soapconn->session->userlist != NULL);
 
-        userlist = soapconn->session->userlist;
+	userlist = soapconn->session->userlist;
 
 	state = (MsnCallbackState *) soapconn->data_cb;
 
+	if (soapconn->body == NULL) {
+		msn_callback_state_free(state);
+		return;
+	}
+	
 	if (msn_userlist_add_buddy_to_group(userlist, state->who, state->new_group_name) == TRUE) {
 		purple_debug_info("MSNCL", "Contact %s added to group %s successfully!\n", state->who, state->new_group_name);
 	} else {
@@ -1204,6 +1224,9 @@
 {
 	MsnSoapConn * soapconn = data;
 
+	if (soapconn->body == NULL)
+		return;
+
 	// we should probably delete it from the userlist aswell
 	purple_debug_info("MSNCL","Delete contact successful\n");
 	msn_soap_free_read_buf(soapconn);
@@ -1253,6 +1276,11 @@
 {
 	MsnSoapConn * soapconn = data;
 	MsnCallbackState *state = (MsnCallbackState *) soapconn->data_cb;
+
+	if (soapconn->body == NULL) {
+		msn_callback_state_free(state);
+		return;
+	}
 	
 	if (msn_userlist_rem_buddy_from_group(soapconn->session->userlist, state->who, state->old_group_name)) {
 		purple_debug_info("MSN CL", "Contact %s deleted successfully from group %s\n", state->who, state->old_group_name);
@@ -1341,6 +1369,11 @@
 static void
 msn_update_contact_read_cb(gpointer data, gint source, PurpleInputCondition cond)
 {
+	MsnSoapConn *soapconn = data;
+
+	if (soapconn->body == NULL)
+		return;
+
 	purple_debug_info("MSN CL","Contact updated successfully\n");
 }
 
@@ -1394,6 +1427,11 @@
 
 	state = (MsnCallbackState *) soapconn->data_cb;
 
+	if (soapconn->body == NULL) {
+		msn_callback_state_free(state);
+		return;
+	}
+	
 	purple_debug_info("MSN CL", "Contact %s deleted successfully from %s list on server!\n", state->who, MsnMemberRole[state->list_id]);
 
 	if (state->list_id == MSN_LIST_PL) {
@@ -1493,6 +1531,11 @@
 
 	state = (MsnCallbackState *) soapconn->data_cb;
 	
+	if (soapconn->body == NULL) {
+		msn_callback_state_free(state);
+		return;
+	}
+	
 	purple_debug_info("MSN CL", "Contact %s added successfully to %s list on server!\n", state->who, MsnMemberRole[state->list_id]);
 
 	if (state->list_id == MSN_LIST_RL && (state->action & MSN_DENIED_BUDDY) ) {
@@ -1621,9 +1664,15 @@
 	g_return_if_fail(soapconn->session != NULL);
 	g_return_if_fail(soapconn->session->userlist != NULL);
 	g_return_if_fail(soapconn->session->contact != NULL);
+
+	state = (MsnCallbackState *) soapconn->data_cb;
 	
-	if (soapconn->data_cb != NULL) {
-		state = (MsnCallbackState *) soapconn->data_cb;
+	if (soapconn->body == NULL) {
+		msn_callback_state_free(state);
+		return;
+	}
+	
+	if (state) {
 		userlist = soapconn->session->userlist;
 		
 		if (state->action & MSN_RENAME_GROUP) {
--- a/libpurple/protocols/msn/oim.c	Sun Sep 09 00:50:14 2007 +0000
+++ b/libpurple/protocols/msn/oim.c	Sun Sep 09 01:42:46 2007 +0000
@@ -239,6 +239,9 @@
 	MsnSession *session = soapconn->session;
 	MsnOim * oim;
 
+	if (soapconn->body == NULL)
+		return;
+
 	g_return_if_fail(session != NULL);
 	oim = soapconn->session->oim;
 	g_return_if_fail(oim != NULL);
@@ -338,6 +341,8 @@
 {
 	MsnSoapConn * soapconn = data;
 
+	if (soapconn->body == NULL)
+		return;
 	purple_debug_info("MSNP14","OIM delete read buffer:{%s}\n",soapconn->body);
 
 	msn_soap_free_read_buf(soapconn);
@@ -571,6 +576,9 @@
 	MsnSoapConn * soapconn = data;
 	MsnOim * oim = soapconn->session->oim;
 
+	if (soapconn->body == NULL)
+		return;
+
 	purple_debug_info("MSNP14","OIM get read buffer:{%s}\n",soapconn->body);
 
 	/*we need to process the read message!*/
--- a/libpurple/protocols/msn/soap.c	Sun Sep 09 00:50:14 2007 +0000
+++ b/libpurple/protocols/msn/soap.c	Sun Sep 09 01:42:46 2007 +0000
@@ -150,7 +150,12 @@
 
 	g_return_if_fail(soapconn != NULL);
 
+	soapconn->body = NULL;
+
 	while ((request = g_queue_pop_head(soapconn->soap_queue)) != NULL){
+		if (soapconn->read_cb) {
+			soapconn->read_cb(soapconn, -1, 0);
+		}
 		msn_soap_request_free(request);
 	}
 }
@@ -510,14 +515,6 @@
 	soapconn->written_len = 0;
 }
 
-void
-msn_soap_free_data_cb(MsnSoapConn *soapconn)
-{
-	if (soapconn->data_cb) {
-		g_free(soapconn->data_cb);
-	}
-}
-
 /*Soap write process func*/
 static void
 msn_soap_write_cb(gpointer data, gint source, PurpleInputCondition cond)
@@ -625,7 +622,6 @@
 	g_free(request->login_path);
 	g_free(request->soap_action);
 	g_free(request->body);
-	g_free(request->data_cb);
 	request->read_cb	= NULL;
 	request->written_cb	= NULL;
 
--- a/libpurple/protocols/msn/soap.h	Sun Sep 09 00:50:14 2007 +0000
+++ b/libpurple/protocols/msn/soap.h	Sun Sep 09 01:42:46 2007 +0000
@@ -140,7 +140,6 @@
 void msn_soap_write(MsnSoapConn * soapconn, char *write_buf, PurpleInputFunction written_cb);
 void msn_soap_post(MsnSoapConn *soapconn,MsnSoapReq *request,MsnSoapConnectInitFunction msn_soap_init_func);
 
-void msn_soap_free_data_cb(MsnSoapConn *soapconn);
 void msn_soap_free_read_buf(MsnSoapConn *soapconn);
 void msn_soap_free_write_buf(MsnSoapConn *soapconn);
 void msn_soap_connect_cb(gpointer data, PurpleSslConnection *gsc, PurpleInputCondition cond);