changeset 20467:86da6ab1f612

Correctly process an additional <Service> with type Profile and name 'Messenger Roaming Identity' sent with the contact list using a recently registered WLM account, that was causing the initial ADL command to be sent malformed, and our presence status not being forwarded to our buddies
author Carlos Silva <typ0@pidgin.im>
date Sat, 14 Jul 2007 00:04:48 +0000
parents a8599711efb7
children b888c2f15c79
files libpurple/protocols/msn/contact.c libpurple/protocols/msn/notification.c libpurple/protocols/msn/userlist.c libpurple/xmlnode.h
diffstat 4 files changed, 149 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/contact.c	Mon Jul 09 17:59:36 2007 +0000
+++ b/libpurple/protocols/msn/contact.c	Sat Jul 14 00:04:48 2007 +0000
@@ -90,6 +90,9 @@
 static int
 msn_get_memberrole(char * role)
 {
+	
+	purple_debug_info("::","msn_get_memberrole()\n");
+
 	if(!strcmp(role,"Allow")){
 		return MSN_LIST_AL_OP;
 	}else if(!strcmp(role,"Block")){
@@ -124,25 +127,31 @@
 msn_parse_contact_list(MsnContact * contact)
 {
 	MsnSession * session;
-	int list_op =0;
-	char * passport;
-	xmlnode * node,*body,*response,*result,*services;
-	xmlnode *service,*memberships;
+	int list_op = 0;
+	char * passport, *debugdata, *typedata;
+	xmlnode *node, *body, *response, *result, *services;
+	xmlnode *service, *memberships, *info, *handle, *handletype;
 	xmlnode *LastChangeNode;
-	xmlnode *membershipnode,*members,*member,*passportNode;
+	xmlnode *membershipnode, *members, *member, *passportNode;
 	char *LastChangeStr;
 
+	purple_debug_info("::","msn_parse_contact_list()\n");
+
 	session = contact->session;
-	purple_debug_misc("MSNCL","parse contact list:{%s}\nsize:%d\n",contact->soapconn->body,contact->soapconn->body_len);
-	node = 	xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len);
+	node = xmlnode_from_str(contact->soapconn->body, contact->soapconn->body_len);
+
+	debugdata = xmlnode_to_formatted_str(node, NULL);
+	purple_debug_info("MSNCL","Received contact list, parsing:\n%s",debugdata);
+	g_free(debugdata);
 
 	if(node == NULL){
-		purple_debug_misc("MSNCL","parse contact from str err!\n");
+		purple_debug_error("MSNCL","Unable to parse SOAP data!\n");
 		return;
 	}
-	purple_debug_misc("MSNCL","node{%p},name:%s,child:%s,last:%s\n",node,node->name,node->child->name,node->lastchild->name);
+
+	purple_debug_info("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");
-	purple_debug_misc("MSNCL","body{%p},name:%s\n",body,body->name);
+	purple_debug_info("MSNCL","Body @ %p:  Name: '%s'\n",body,body->name);
 	response = xmlnode_get_child(body,"FindMembershipResponse");
 
 	if (response == NULL) {
@@ -154,77 +163,115 @@
 		msn_get_contact_list(contact, NULL);
 		return;
 	}
+	purple_debug_info("MSNCL","Response @ %p: Name: '%s'\n",response,response->name);
 
-	purple_debug_misc("MSNCL","response{%p},name:%s\n",response,response->name);
-	result =xmlnode_get_child(response,"FindMembershipResult");
+	result = xmlnode_get_child(response,"FindMembershipResult");
 	if(result == NULL){
-		purple_debug_misc("MSNCL","receive No Update!\n");
-		return;
-	}
-	purple_debug_misc("MSNCL","result{%p},name:%s\n",result,result->name);
-	services =xmlnode_get_child(result,"Services");
-	purple_debug_misc("MSNCL","services{%p},name:%s\n",services,services->name);
-	service =xmlnode_get_child(services,"Service");
-	purple_debug_misc("MSNCL","service{%p},name:%s\n",service,service->name);
-	
-	/*Last Change Node*/
-	LastChangeNode = xmlnode_get_child(service,"LastChange");
-	LastChangeStr = xmlnode_get_data(LastChangeNode);
-	purple_debug_misc("MSNCL","LastChangeNode0 %s\n",LastChangeStr);	
-	purple_account_set_string(session->account, "CLLastChange",LastChangeStr);
-	purple_debug_misc("MSNCL","LastChangeNode %s\n",LastChangeStr);
-	
-	memberships =xmlnode_get_child(service,"Memberships");
-	if (memberships == NULL) {
-		xmlnode_free(node);
+		purple_debug_warning("MSNCL","receive No Update!\n");
 		return;
 	}
-	purple_debug_misc("MSNCL","memberships{%p},name:%s\n",memberships,memberships->name);
-	for(membershipnode = xmlnode_get_child(memberships, "Membership"); membershipnode;
-					membershipnode = xmlnode_get_next_twin(membershipnode)){
-		xmlnode *roleNode;
-		char *role;
-		roleNode = xmlnode_get_child(membershipnode,"MemberRole");
-		role=xmlnode_get_data(roleNode);
-		list_op = msn_get_memberrole(role);
-		purple_debug_misc("MSNCL","MemberRole role:%s,list_op:%d\n",role,list_op);
-		g_free(role);
-		members = xmlnode_get_child(membershipnode,"Members");
-		for(member = xmlnode_get_child(members, "Member"); member;
-				member = xmlnode_get_next_twin(member)){
-			MsnUser *user;
-			xmlnode * typeNode;
-			char * type;
+	purple_debug_info("MSNCL","Result @ %p: Name: '%s'\n",result,result->name);
+
+	services = xmlnode_get_child(result,"Services");
+	purple_debug_info("MSNCL","Services @ %p\n",services);
+	
+	for( service = xmlnode_get_child(services, "Service"); service;
+	                                service = xmlnode_get_next_twin(service)) {
+		purple_debug_info("MSNCL","Service @ %p\n",service);
+	
+		if ( (info = xmlnode_get_child(service,"Info")) == NULL ) {
+			purple_debug_error("MSNCL","Error getting 'Info' child node\n");
+			continue;
+		}
+		if ( (handle = xmlnode_get_child(info,"Handle")) == NULL ) {
+			purple_debug_error("MSNCL","Error getting 'Handle' child node\n");
+			continue;
+		}
+		if ( (handletype = xmlnode_get_child(handle,"Type")) == NULL ) {
+			purple_debug_error("MSNCL","Error getting 'Type' child node\n");
+			continue;
+		}
+
+		if ( (typedata = xmlnode_get_data(handletype)) == NULL) {
+			purple_debug_error("MSNCL","Error retrieving data from 'Type' child node\n");
+			continue;
+		}
+
+		purple_debug_info("MSNCL","processing '%s' Service\n",typedata);
+
+		if ( !g_strcasecmp(typedata, "Profile") ) {
+			/* Process Windows Live 'Messenger Roaming Identity' */
+			g_free(typedata);
+			continue;
+		}
+
+		if ( !g_strcasecmp(typedata, "Messenger") ) {
 
-			purple_debug_misc("MSNCL","type:%s\n",xmlnode_get_attrib(member,"type"));
-			if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"PassportMember")){
-				passportNode = xmlnode_get_child(member,"PassportName");
-				passport = xmlnode_get_data(passportNode);
-				typeNode = xmlnode_get_child(member,"Type");
-				type = xmlnode_get_data(typeNode);
-				purple_debug_misc("MSNCL","Passport name:%s,type:%s\n",passport,type);
-				g_free(type);
-
-				user = msn_userlist_find_add_user(session->userlist,passport,NULL);
-				msn_got_lst_user(session, user, list_op, NULL);
-				g_free(passport);
+			/*Last Change Node*/
+			LastChangeNode = xmlnode_get_child(service, "LastChange");
+			LastChangeStr = xmlnode_get_data(LastChangeNode);
+			purple_debug_info("MSNCL","LastChangeNode: '%s'\n",LastChangeStr);	
+			purple_account_set_string(session->account, "CLLastChange",LastChangeStr);
+	
+			memberships = xmlnode_get_child(service,"Memberships");
+			if (memberships == NULL) {
+				purple_debug_warning("MSNCL","Memberships = NULL, cleaning up and returning.\n");
+				g_free(typedata);
+				xmlnode_free(node);
+				return;
 			}
-			if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"PhoneMember")){
-			}
-			if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"EmailMember")){
-				xmlnode *emailNode;
+			purple_debug_info("MSNCL","Memberships @ %p: Name: '%s'\n",memberships,memberships->name);
+			for(membershipnode = xmlnode_get_child(memberships, "Membership"); membershipnode;
+							membershipnode = xmlnode_get_next_twin(membershipnode)){
+				xmlnode *roleNode;
+				char *role;
+
+				roleNode = xmlnode_get_child(membershipnode,"MemberRole");
+				role = xmlnode_get_data(roleNode);
+				list_op = msn_get_memberrole(role);
+				purple_debug_info("MSNCL","MemberRole role: %s, list_op: %d\n",role,list_op);
+				
+				g_free(role);
+				
+				members = xmlnode_get_child(membershipnode,"Members");
+				for(member = xmlnode_get_child(members, "Member"); member;
+						member = xmlnode_get_next_twin(member)){
+					MsnUser *user;
+					xmlnode * typeNode;
+					char * type;
 
-				emailNode = xmlnode_get_child(member,"Email");
-				passport = xmlnode_get_data(emailNode);
-				purple_debug_info("MSNCL","Email Member :name:%s,list_op:%d\n",passport,list_op);
-				user = msn_userlist_find_add_user(session->userlist,passport,NULL);
-				msn_got_lst_user(session,user,list_op,NULL);
-				g_free(passport);
+					purple_debug_info("MSNCL","Member type: %s\n",xmlnode_get_attrib(member,"type"));
+					if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"PassportMember")){
+						passportNode = xmlnode_get_child(member,"PassportName");
+						passport = xmlnode_get_data(passportNode);
+						typeNode = xmlnode_get_child(member,"Type");
+						type = xmlnode_get_data(typeNode);
+						purple_debug_info("MSNCL","Passport name: '%s', Type: %s\n",passport,type);
+						g_free(type);
+
+						user = msn_userlist_find_add_user(session->userlist,passport,NULL);
+						msn_got_lst_user(session, user, list_op, NULL);
+						g_free(passport);
+					}
+					if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"PhoneMember")){
+					}
+					if(!g_strcasecmp(xmlnode_get_attrib(member,"type"),"EmailMember")){
+						xmlnode *emailNode;
+
+						emailNode = xmlnode_get_child(member,"Email");
+						passport = xmlnode_get_data(emailNode);
+						purple_debug_info("MSNCL","Email Member: Name: '%s', list_op: %d\n",passport,list_op);
+						user = msn_userlist_find_add_user(session->userlist,passport,NULL);
+						msn_got_lst_user(session,user,list_op,NULL);
+						g_free(passport);
+					}
+				}
 			}
+			g_free(typedata);	/* Free 'Type' node data after processing 'Messenger' Service */
 		}
 	}
 
-	xmlnode_free(node);
+	xmlnode_free(node);	/* Free the whole XML tree */
 }
 
 static void
@@ -236,13 +283,15 @@
 	const char *abLastChange;
 	const char *dynamicItemLastChange;
 
+	purple_debug_info("::","msn_get_contact_list_cb()\n");
+
 	contact = soapconn->parent;
 	g_return_if_fail(contact != NULL);
 	session = soapconn->session;
 	g_return_if_fail(session != NULL);
 
 #ifdef  MSN_CONTACT_SOAP_DEBUG
-	purple_debug_misc("msn", "soap contact server Reply: {%s}\n", soapconn->read_buf);
+	purple_debug_info("msn", "soap contact server Reply: {%s}\n", soapconn->read_buf);
 #endif
 	msn_parse_contact_list(contact);
 	/*free the read buffer*/
@@ -278,7 +327,9 @@
 	MsnSoapReq *soap_request;
 	char *body = NULL;
 	char * update_str;
-	
+
+	purple_debug_info("::","msn_get_contact_list()\n");
+
 	purple_debug_info("MaYuan","Getting Contact List...\n");
 	if(update_time != NULL){
 		purple_debug_info("MSNCL","last update time:{%s}\n",update_time);
@@ -303,6 +354,8 @@
 	MsnSession *session = contact->session;
 	xmlnode *group;
 
+	purple_debug_info("::","msn_parse_addressbook_groups()\n");
+
 	for(group = xmlnode_get_child(node, "Group"); group;
 					group = xmlnode_get_next_twin(group)){
 		xmlnode *groupId, *groupInfo, *groupname;
@@ -321,7 +374,7 @@
 			continue;
 		}
 
-		purple_debug_misc("MsnAB","group_id:%s name:%s\n",group_id,group_name);
+		purple_debug_info("MsnAB","group_id: %s, name: %s\n",group_id,group_name);
 		if ((purple_find_group(group_name)) == NULL){
 			PurpleGroup *g = purple_group_new(group_name);
 			purple_blist_add_group(g, NULL);
--- a/libpurple/protocols/msn/notification.c	Mon Jul 09 17:59:36 2007 +0000
+++ b/libpurple/protocols/msn/notification.c	Sat Jul 14 00:04:48 2007 +0000
@@ -592,7 +592,8 @@
 	char *email,*domain;
 	char *list_op_str,*type_str;
 
-	purple_debug_info("MaYuan","passport:%s type: %d\n",passport, type);
+	purple_debug_info("::","msn_add_contact_xml()\n");
+	purple_debug_info("MaYuan","Passport: %s, type: %d\n",passport, type);
 	tokens = g_strsplit(passport, "@", 2);
 	email = tokens[0];
 	domain = tokens[1];
@@ -601,7 +602,7 @@
 	for(d_node = xmlnode_get_child(mlNode,"d"); d_node; d_node = xmlnode_get_next_twin(d_node))
 	{
 		const char * attr = NULL;
-		purple_debug_info("MaYuan","d_node:%s\n",d_node->name);
+		purple_debug_info("MaYuan","d_node: %s\n",d_node->name);
 		attr = xmlnode_get_attrib(d_node,"n");
 		if(attr == NULL){
 			continue;
@@ -624,7 +625,7 @@
 	xmlnode_set_attrib(c_node,"n",email);
 
 	list_op_str = g_strdup_printf("%d",list_op);
-	purple_debug_info("MaYuan","list_op:%d\n",list_op);
+	purple_debug_info("MaYuan","list_op: %d\n",list_op);
 	xmlnode_set_attrib(c_node,"l",list_op_str);
 	g_free(list_op_str);
 
@@ -650,8 +651,8 @@
 msn_notification_post_adl(MsnCmdProc *cmdproc, const char *payload, int payload_len)
 {
 	MsnTransaction *trans;
-
-	purple_debug_info("MaYuan","Send ADL{%s}\n",payload);
+	purple_debug_info("::","msn_notification_post_adl()\n");
+	purple_debug_info("MaYuan","Sending ADL with payload: %s\n",payload);
 	trans = msn_transaction_new(cmdproc, "ADL","%d",strlen(payload));
 	msn_transaction_set_payload(trans, payload, strlen(payload));
 	msn_cmdproc_send_trans(cmdproc, trans);
@@ -669,6 +670,7 @@
 	int adl_count = 0;
 	const char *display_name;
 
+	purple_debug_info("::","msn_notification_dump_contact()\n");
 	adl_node = xmlnode_new("ml");
 	adl_node->child = NULL;
 	xmlnode_set_attrib(adl_node, "l", "1");
@@ -750,7 +752,7 @@
 
 	if (!initial)
         {
-                purple_debug_info("::","Initial ADL received\n");
+                purple_debug_info("typ0","Initial ADL received\n");
                 msn_session_finish_login(cmdproc->session);
         }
 }
@@ -892,6 +894,8 @@
 	gint group_id;
 	const char *group_name;
 
+	purple_debug_info("::","adg_cmd()\n");
+	
 	session = cmdproc->session;
 
 	group_id = atoi(cmd->params[3]);
@@ -1551,7 +1555,7 @@
 static void
 ubx_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
 {
-	purple_debug_info("MaYuan","UBX... \n");
+	purple_debug_info("typ0","UBX received.\n");
 	if(cmd->payload_len == 0){
 		return;
 	}
@@ -1561,7 +1565,7 @@
 static void
 uux_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
 {
-	purple_debug_info("MaYuan","UUX... \n");
+	purple_debug_info("typ0","UUX received.\n");
 }
 
 /**************************************************************************
@@ -1575,7 +1579,7 @@
 	const char *value;
 	const char *clLastChange;
 
-	purple_debug_info("MaYuan","profile_msg... \n");
+	purple_debug_info("::","profile_msg()\n");
 	session = cmdproc->session;
 
 	if (strcmp(msg->remote_user, "Hotmail"))
@@ -1760,6 +1764,7 @@
 static void
 delete_oim_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
 {
+	purple_debug_info("::","delete_oim_msg()\n");
 }
 
 static void
@@ -1871,7 +1876,7 @@
 	xmlnode *adl_node;
 	char *payload;
 	int payload_len;
-
+	purple_debug_info("::","msn_notification_add_buddy()\n");
 	cmdproc = notification->servconn->cmdproc;
 
 	adl_node = xmlnode_new("ml");
@@ -1902,6 +1907,7 @@
 	char *payload;
 	int payload_len;
 
+	purple_debug_info("::","msn_notification_rem_buddy()\n");
 	cmdproc = notification->servconn->cmdproc;
 
 	rml_node = xmlnode_new("ml");
@@ -1912,7 +1918,7 @@
 	payload = xmlnode_to_str(rml_node,&payload_len);
 	xmlnode_free(rml_node);
 
-	purple_debug_info("MaYuan","RML{%s}\n",payload);
+	purple_debug_info("MaYuan","Send RML with payload {%s}\n",payload);
 	trans = msn_transaction_new(cmdproc, "RML","%d",strlen(payload));
 	msn_transaction_set_payload(trans, payload, strlen(payload));
 	msn_cmdproc_send_trans(cmdproc, trans);
--- a/libpurple/protocols/msn/userlist.c	Mon Jul 09 17:59:36 2007 +0000
+++ b/libpurple/protocols/msn/userlist.c	Sat Jul 14 00:04:48 2007 +0000
@@ -196,6 +196,7 @@
 	return -1;
 }
 
+/* this function msn_got_add_user isn't called anywhere */
 void
 msn_got_add_user(MsnSession *session, MsnUser *user,
 				 MsnListId list_id, const char * group_id)
@@ -349,6 +350,8 @@
 	const char *passport;
 	const char *store;
 
+	purple_debug_info("::","msn_got_lst_user()\n");
+
 	account = session->account;
 	gc = purple_account_get_connection(account);
 
@@ -745,6 +748,8 @@
 	GSList *l;
 	MsnUser * user;
 
+	purple_debug_info("::","msn_userlist_load()\n");
+
 	g_return_if_fail(gc != NULL);
 
 	for (gnode = purple_get_blist()->root; gnode; gnode = gnode->next)
--- a/libpurple/xmlnode.h	Mon Jul 09 17:59:36 2007 +0000
+++ b/libpurple/xmlnode.h	Sat Jul 14 00:04:48 2007 +0000
@@ -128,7 +128,7 @@
  *
  * @param node The node to get data from.
  *
- * @return The data from the node.  This data is in raw escaped format.
+ * @return The data from the node or NULL. This data is in raw escaped format.
  *         You must g_free this string when finished using it.
  */
 char *xmlnode_get_data(xmlnode *node);