changeset 20479:6a8463be5b23

Improve MSN_SOAP_DEBUG and workaround a Win32 bug which would case Pidgin to consume insane amounts of memory when printing a large string to the Debug Window.
author Carlos Silva <typ0@pidgin.im>
date Wed, 08 Aug 2007 23:01:44 +0000
parents c1c4468207fa
children 7d3e53e3f623
files libpurple/protocols/msn/contact.c libpurple/protocols/msn/nexus.c libpurple/protocols/msn/soap.c
diffstat 3 files changed, 70 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/contact.c	Tue Aug 07 22:07:26 2007 +0000
+++ b/libpurple/protocols/msn/contact.c	Wed Aug 08 23:01:44 2007 +0000
@@ -181,7 +181,7 @@
 {
 	MsnSession * session;
 	int list_op = 0;
-	char * passport, *debugdata, *typedata;
+	char * passport, *typedata;
 	xmlnode *fault, *faultstringnode, *faultdetail, *errorcode;
 	xmlnode *node, *body, *response, *result, *services;
 	xmlnode *service, *memberships, *info, *handle, *handletype;
@@ -189,8 +189,6 @@
 	xmlnode *membershipnode, *members, *member, *passportNode;
 	char *LastChangeStr;
 
-	purple_debug_info("::","msn_parse_contact_list()\n");
-
 	session = contact->session;
 	node = xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len);
 
@@ -199,14 +197,9 @@
 		return;
 	}
 
-#ifdef MSN_SOAP_DEBUG
-	debugdata = xmlnode_to_formatted_str(node, NULL);
-	purple_debug_info("MSNCL","Received contact list, parsing:\n%s", debugdata);
-	g_free(debugdata);
-#endif
+	purple_debug_misc("MSNCL","Parsing contact list with size %d\n", contact->soapconn->body_len);
 
-
-	purple_debug_info("MSNCL","Root node @ %p: Name: '%s', child: '%s', lastchild: '%s'\n",node,node->name,node->child->name,node->lastchild->name);
+	purple_debug_misc("MSNCL","Root node @ %p: Name: '%s', child: '%s', lastchild: '%s'\n",node,node->name,node->child->name,node->lastchild->name);
 	body = xmlnode_get_child(node,"Body");
 
 	if (body == NULL) {
@@ -221,7 +214,7 @@
 	        purple_debug_info("MSNCL","Fault received from SOAP server!\n");
 
 		if ( (faultstringnode = xmlnode_get_child(fault, "faultstring")) != NULL ) {
-			gchar * faultstring = xmlnode_get_data(faultstring);
+			gchar * faultstring = xmlnode_get_data(faultstringnode);
 			purple_debug_info("MSNCL","Faultstring: %s\n", faultstring);
 			g_free(faultstring);
 		}
@@ -392,16 +385,13 @@
 	const char *abLastChange;
 	const char *dynamicItemLastChange;
 
-	purple_debug_info("::","msn_get_contact_list_cb()\n");
+	purple_debug_misc("MSNCL","Got the contact list!\n");
 
 	contact = soapconn->parent;
 	g_return_if_fail(contact != NULL);
 	session = soapconn->session;
 	g_return_if_fail(session != NULL);
 
-#ifdef  MSN_SOAP_DEBUG
-	purple_debug_info("MSNCL", "SOAP server reply: \n%s\n", soapconn->read_buf);
-#endif
 	msn_parse_contact_list(contact);
 	/*free the read buffer*/
 	msn_soap_free_read_buf(soapconn);
@@ -425,7 +415,7 @@
 {
 	MsnSoapConn * soapconn = data;	
 
-	purple_debug_info("MSNP14","finish contact written\n");
+	purple_debug_misc("MSNCL","Sent SOAP request for the contact list.\n");
 	soapconn->read_cb = msn_get_contact_list_cb;
 //	msn_soap_read_cb(data,source,cond);
 }
@@ -438,11 +428,9 @@
 	char *body = NULL;
 	char * update_str;
 
-	purple_debug_info("::","msn_get_contact_list()\n");
-
-	purple_debug_info("MSNP14","Getting Contact List.\n");
+	purple_debug_misc("MSNCL","Getting Contact List.\n");
 	if ( update_time != NULL ) {
-		purple_debug_info("MSNCL","last update time:{%s}\n",update_time);
+		purple_debug_info("MSNCL","Last update time: %s\n",update_time);
 		update_str = g_strdup_printf(MSN_GET_CONTACT_UPDATE_XML,update_time);
 	} else {
 		update_str = g_strdup("");
@@ -465,7 +453,7 @@
 	MsnSession *session = contact->session;
 	xmlnode *group;
 
-	purple_debug_info("::","msn_parse_addressbook_groups()\n");
+	purple_debug_info("MsnAb","msn_parse_addressbook_groups()\n");
 
 	for(group = xmlnode_get_child(node, "Group"); group;
 					group = xmlnode_get_next_twin(group)){
@@ -624,7 +612,6 @@
 	xmlnode	*contacts;
 	xmlnode *abNode;
 	xmlnode *fault, *faultstringnode, *faultdetail, *errorcode;
-	gchar *printabledata;
 
 	session = contact->session;
 
@@ -632,13 +619,11 @@
 
 	node = xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len);
 	if ( node == NULL ) {
-		purple_debug_error("MSN AddressBook","Error parsing received Address Book with size %d:\n \"%s\"\n", contact->soapconn->body_len, contact->soapconn->body);
+		purple_debug_error("MSN AddressBook","Error parsing Address Book with size %d\n", contact->soapconn->body_len);
 		return FALSE;
 	}
 
-	printabledata = xmlnode_to_formatted_str(node, NULL);
-	purple_debug_misc("MSN AddressBook","Received Address Book with size %d:\n %s\n", contact->soapconn->body_len, (char *) printabledata);
-	g_free(printabledata);
+	purple_debug_misc("MSN AddressBook", "Parsing Address Book with size %d\n", contact->soapconn->body_len);
 
 	purple_debug_misc("MSN AddressBook","node{%p},name:%s,child:%s,last:%s\n",node,node->name,node->child->name,node->lastchild->name);
 	
@@ -649,7 +634,7 @@
 		purple_debug_info("MSN AddressBook","Fault received from SOAP server!\n");
 		
 		if ( (faultstringnode = xmlnode_get_child(fault, "faultstring")) != NULL ) {
-			gchar *faultstring = xmlnode_get_data(faultstring);
+			gchar *faultstring = xmlnode_get_data(faultstringnode);
 			purple_debug_info("MSN AddressBook","Faultstring: %s\n", faultstring);
 			g_free(faultstring);
 		}
@@ -754,7 +739,8 @@
 	session = soapconn->session;
 	g_return_if_fail(session != NULL);
 
-//	purple_debug_misc("msn", "soap contact server Reply: {%s}\n", soapconn->read_buf);
+	purple_debug_misc("MSN AddressBook", "Got the Address Book!\n");
+
 	if ( msn_parse_addressbook(contact) ) {
 		msn_soap_free_read_buf(soapconn);
 
@@ -781,7 +767,7 @@
 {
 	MsnSoapConn * soapconn = data;	
 
-	purple_debug_info("MSNP14","finish contact written\n");
+	purple_debug_misc("MSN AddressBook","Sent SOAP request for the Address Book.\n");
 	soapconn->read_cb = msn_get_address_cb;
 }
 
@@ -793,7 +779,7 @@
 	char *body = NULL;
 	char *ab_update_str,*update_str;
 
-	purple_debug_info("::","msn_get_address_book()\n");
+	purple_debug_misc("MSN AddressBook","Getting Address Book\n");
 
 	/*build SOAP and POST it*/
 	if ( LastChanged != NULL ) {
@@ -846,7 +832,7 @@
 	char *contact_xml = NULL;
 	char *soap_action;
 
-	purple_debug_info("::","msn_add_contact()\n");
+	purple_debug_info("MSNCL","msn_add_contact()\n");
 	contact_xml = g_strdup_printf(MSN_CONTACT_XML,passport);
 	if ( groupId == NULL ) {
 		body = g_strdup_printf(MSN_ADD_CONTACT_TEMPLATE,contact_xml);
--- a/libpurple/protocols/msn/nexus.c	Tue Aug 07 22:07:26 2007 +0000
+++ b/libpurple/protocols/msn/nexus.c	Wed Aug 08 23:01:44 2007 +0000
@@ -25,6 +25,7 @@
 #include "soap.h"
 #include "nexus.h"
 #include "notification.h"
+
 #undef NEXUS_LOGIN_TWN
 
 /*Local Function Prototype*/
@@ -158,10 +159,8 @@
 	session = nexus->session;
 	g_return_if_fail(session != NULL);
 
-	purple_debug_misc("msn", "TWN Server Reply: {%s}\n", soapconn->read_buf);
-
 	/*reply OK, we should process the SOAP body*/
-	purple_debug_info("MSNP14","Windows Live ID Reply OK!\n");
+	purple_debug_info("MSN Nexus","TWN Server Windows Live ID Reply OK!\n");
 
 	//TODO: we should parse it using XML
 #ifdef NEXUS_LOGIN_TWN
@@ -205,7 +204,7 @@
 	cert_str = g_strdup_printf("t=%s&p=%s",msn_twn_t,msn_twn_p);
 	msn_got_login_params(session, cert_str);
 
-	purple_debug_info("MSNP14","close nexus connection! \n");
+	purple_debug_info("MSN Nexus","Close nexus connection!\n");
 	g_free(cert_str);
 	g_free(login_params);
 	msn_nexus_destroy(nexus);
@@ -242,7 +241,7 @@
 	char *rst1_str,*rst2_str,*rst3_str;
 #endif
 
-	purple_debug_info("MSNP14","starting Windows Live ID authentication\n");
+	purple_debug_info("MSN Nexus","Starting Windows Live ID authentication\n");
 
 	soapconn = data;
 	g_return_if_fail(soapconn != NULL);
@@ -277,7 +276,7 @@
 	 * for when windows g_strdup_printf() implementation get NULL point,It crashed!
 	 */
 	if(!(lc && id && tw && ru && ct && kpp && kv && ver && tpf)){
-		purple_debug_error("MSNP14","WLM Authenticate Key Error!\n");
+		purple_debug_error("MSN Nexus","WLM Authenticate Key Error!\n");
 		msn_session_set_error(session, MSN_ERROR_AUTH, _("Windows Live ID authentication Failed"));
 		g_free(username);
 		g_free(password);
@@ -335,8 +334,10 @@
 					soapconn->login_path,soapconn->login_host,(int)strlen(tail));
 
 	request_str = g_strdup_printf("%s%s", head,tail);
-	purple_debug_misc("msn", "TWN Sending:\n%s\n", request_str);
 
+#ifdef MSN_SOAP_DEBUG	
+	purple_debug_misc("MSN Nexus", "TWN Sending:\n%s\n", request_str);
+#endif
 	g_free(head);
 	g_free(tail);
 	g_free(username);
@@ -467,7 +468,7 @@
 msn_nexus_connect(MsnNexus *nexus)
 {
 	/*  Authenticate via Windows Live ID. */
-	purple_debug_info("MSNP14","msn_nexus_connect...\n");
+	purple_debug_info("MSN Nexus","msn_nexus_connect()\n");
 	msn_soap_init(nexus->soapconn,MSN_TWN_SERVER,1,nexus_login_connect_cb,nexus_login_error_cb);
 	msn_soap_connect(nexus->soapconn);
 }
--- a/libpurple/protocols/msn/soap.c	Tue Aug 07 22:07:26 2007 +0000
+++ b/libpurple/protocols/msn/soap.c	Wed Aug 08 23:01:44 2007 +0000
@@ -66,7 +66,7 @@
 	MsnSoapConn * soapconn;
 	MsnSession *session;
 
-	purple_debug_info("MSN SOAP","SOAP server connection established!\n");
+	purple_debug_misc("MSN SOAP","SOAP server connection established!\n");
 
 	soapconn = data;
 	g_return_if_fail(soapconn != NULL);
@@ -93,7 +93,7 @@
 	MsnSoapConn * soapconn = data;
 
 	g_return_if_fail(data != NULL);
-	purple_debug_info("MSN SOAP","Soap connection error!\n");
+	purple_debug_warning("MSN SOAP","Soap connection error!\n");
 	msn_soap_set_process_step(soapconn, MSN_SOAP_UNCONNECTED);
 
 	/*error callback*/
@@ -108,7 +108,7 @@
 				PurpleSslInputFunction	connect_cb,
 				PurpleSslErrorFunction	error_cb)
 {
-	purple_debug_info("MSN SOAP","msn_soap_init()\n");
+	purple_debug_misc("MSN SOAP","Initializing SOAP connection\n");
 	soapconn->login_host = g_strdup(host);
 	soapconn->ssl_conn = ssl;
 	soapconn->connect_cb = connect_cb;
@@ -218,18 +218,14 @@
 		len = read(soapconn->fd, temp_buf, requested_len);
 	}
 
+	
 	if ( len <= 0 ) {
 		switch (errno) {
 
 			case 0:
 			case EBADF: /* we are sometimes getting this in Windows */
-			case EAGAIN:
-#ifdef MSN_SOAP_DEBUG
-				purple_debug_info("MSN SOAP",
-					"msn_soap_read(): %s, returning len = %d.\n",
-					strerror(errno), len);
-#endif
-				     return len;
+			case EAGAIN: return len;
+
 			default : purple_debug_error("MSN SOAP", "Read error!"
 						"read len: %d, error = %s\n",
 						len, strerror(errno));
@@ -243,9 +239,6 @@
 		}
 	}
 	else {
-#ifdef MSN_SOAP_DEBUG
-		purple_debug_info("MSN SOAP", "Allocating space for more %d bytes from incoming data. Total space now (according to soapconn->read_len = %d\n", len, soapconn->read_len);
-#endif
 		soapconn->read_buf = g_realloc(soapconn->read_buf,
 						soapconn->read_len + len + 1);
 		if ( soapconn->read_buf != NULL ) {
@@ -260,38 +253,11 @@
 			
 	}
 
-#ifdef MSN_SOAP_DEBUG
-	purple_debug_info("MSN SOAP","Read SOAP bytes: %d\n", len);
-
-	if (len > -1) {
-		gchar * soapbody = NULL;
-		xmlnode * node = NULL;
-		soapbody = g_strstr_len(soapconn->read_buf, soapconn->read_len, "\r\n\r\n");
-		if (soapbody != NULL)
-			node = xmlnode_from_str(soapbody+4, -1);
-	
-	        if (node != NULL) {
-        	        gchar *pretty = xmlnode_to_formatted_str(node, NULL);
-			gchar *http_headers, *delimiter;
+#if defined(MSN_SOAP_DEBUG)
+	if (len > 0)
+		purple_debug_info("MSN SOAP","Read %d bytes from SOAP server:\n%s\n", len, soapconn->read_buf + soapconn->read_len - len);
+#endif
 
-			delimiter = g_strstr_len(soapconn->read_buf, soapconn->read_len,"\r\n\r\n");
-			if (delimiter  != NULL) {
-
-				http_headers = g_strndup(soapconn->read_buf, delimiter + 4 - soapconn->read_buf);
-                		purple_debug_info("MSN SOAP","Nexus server read data:\n%s%s\n", http_headers, pretty);
-				g_free(http_headers);
-			}
-			else
-				purple_debug_info("MSN SOAP","Nexus server read data:\n%s\n", soapconn->read_buf);
-		
-        	        g_free(pretty);
-                	xmlnode_free(node);
-        	}
-        	else
-                	purple_debug_info("MSN SOAP","Received data from Nexus server:\n%s\n", soapconn->read_buf);
-		
-	}
-#endif
 	return len;
 }
 
@@ -304,15 +270,18 @@
 	int len;
 	char * body_start,*body_len;
 	char *length_start,*length_end;
-
 #ifdef MSN_SOAP_DEBUG
+#if !defined(_WIN32)
+	gchar * formattedxml = NULL;
+	gchar * http_headers = NULL;
+	xmlnode * node = NULL;
+#endif
 	purple_debug_misc("MSN SOAP", "msn_soap_read_cb()\n");
 #endif
 	session = soapconn->session;
 	g_return_if_fail(session != NULL);
 
 	
-
 	/*read the request header*/
 	len = msn_soap_read(soapconn);
 	
@@ -468,13 +437,30 @@
 			soapconn->body_len	= atoi(body_len);
 			g_free(body_len);
 #ifdef MSN_SOAP_DEBUG
-			purple_debug_misc("MSN SOAP","SOAP Read length: %d, Body len: %d\n", soapconn->read_len, soapconn->body_len);
+			purple_debug_misc("MSN SOAP","SOAP bytes read so far: %d, Content-Length: %d\n", soapconn->read_len, soapconn->body_len);
 #endif
 			soapconn->need_to_read = (body_start - soapconn->read_buf + soapconn->body_len) - soapconn->read_len;
 			if ( soapconn->need_to_read > 0 ) {
 				return;
 			}
 
+#if defined(MSN_SOAP_DEBUG) && !defined(_WIN32)
+
+			node = xmlnode_from_str(soapconn->body, soapconn->body_len);
+	
+			if (node != NULL) {
+				formattedxml = xmlnode_to_formatted_str(node, NULL);
+				http_headers = g_strndup(soapconn->read_buf, soapconn->body - soapconn->read_buf);
+				
+				purple_debug_info("MSN SOAP","Data with XML payload received from the SOAP server:\n%s%s\n", http_headers, formattedxml);
+				g_free(http_headers);
+				g_free(formattedxml);
+				xmlnode_free(node);
+			}
+			else
+				purple_debug_info("MSN SOAP","Data received from the SOAP server:\n%s\n", soapconn->read_buf);
+#endif
+
 			/*remove the read handler*/
 			purple_input_remove(soapconn->input_handler);
 			soapconn->input_handler = -1;
@@ -658,12 +644,12 @@
 	if (!msn_soap_connected(soapconn) && (soapconn->step == MSN_SOAP_UNCONNECTED)
 					&&(!g_queue_is_empty(soapconn->soap_queue))) {
 		/*not connected?and we have something to process connect it first*/
-		purple_debug_info("MSN SOAP","No connection to SOAP server. Connecting...\n");
+		purple_debug_misc("MSN SOAP","No connection to SOAP server. Connecting...\n");
 		msn_soap_init_func(soapconn);
 		msn_soap_connect(soapconn);
 		return;
 	}
-	purple_debug_info("MSN SOAP","Connected to SOAP server!\n");
+	purple_debug_misc("MSN SOAP","Connected to SOAP server!\n");
 
 	/*if connected, what we only needed to do is to queue the request, 
 	 * when SOAP request in the queue processed done, will do this command.
@@ -683,12 +669,13 @@
 {
 	char * soap_head = NULL;
 	char * request_str = NULL;
-
 #ifdef MSN_SOAP_DEBUG
+#if !defined(_WIN32)
 	xmlnode * node;
+#endif
+	purple_debug_misc("MSN SOAP","msn_soap_post_request()\n");
+#endif
 
-	purple_debug_info("MSN SOAP","msn_soap_post_request()...\n");
-#endif
 	msn_soap_set_process_step(soapconn,MSN_SOAP_PROCESSING);
 	soap_head = g_strdup_printf(
 					"POST %s HTTP/1.1\r\n"
@@ -709,16 +696,16 @@
 					);
 	request_str = g_strdup_printf("%s%s", soap_head, request->body);
 
-#ifdef MSN_SOAP_DEBUG
+#if defined(MSN_SOAP_DEBUG) && !defined(_WIN32)
 	node = xmlnode_from_str(request->body, -1);
 	if (node != NULL) {
-		char *pretty = xmlnode_to_formatted_str(node, NULL);
-		purple_debug_info("MSN SOAP","Posting request to SOAP server:\n%s%s\n",soap_head, pretty);
-		g_free(pretty);
+		char *formattedstr = xmlnode_to_formatted_str(node, NULL);
+		purple_debug_info("MSN SOAP","Posting request to SOAP server:\n%s%s\n",soap_head, formattedstr);
+		g_free(formattedstr);
 		xmlnode_free(node);
 	}
 	else
-		purple_debug_info("MSN SOAP","Failed to parse SOAP request:\n%s\n", request_str);
+		purple_debug_info("MSN SOAP","Failed to parse SOAP request being sent:\n%s\n", request_str);
 #endif
 	
 	g_free(soap_head);