diff libpurple/protocols/msn/notification.c @ 20439:bee467c81570

A bunch of MSNP14 stuff: Don't store the group id on the group blist node. Fix & tidy up payload length detection for commands (errors can have payloads too) Avoid a crash when connecting to a new account with no contact list Tidy up addressbook parsing slightly Fix crashes when buddy list sync issues are detected Fix initial email notifications, Fixes #1293 Plug a few memory leaks Detect OIM authentication failures correctly NOTE: I have disabled dynamic address book retrieval, instead we now receive the whole address book. This is because the blist sync stuff is still very wonky.
author Stu Tomlinson <stu@nosnilmot.com>
date Sun, 27 May 2007 17:00:06 +0000
parents 703fc3437ab5
children 5ecaa00090d7
line wrap: on
line diff
--- a/libpurple/protocols/msn/notification.c	Sun May 27 11:23:09 2007 +0000
+++ b/libpurple/protocols/msn/notification.c	Sun May 27 17:00:06 2007 +0000
@@ -599,7 +599,8 @@
 	domain = tokens[1];
 
 	/*find a domain Node*/
-	for(d_node = xmlnode_get_child(mlNode,"d"); d_node; d_node = xmlnode_get_next_twin(d_node)){
+	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);
 		attr = xmlnode_get_attrib(d_node,"n");
@@ -610,7 +611,8 @@
 			break;
 		}
 	}
-	if(d_node == NULL){
+	if(d_node == NULL)
+	{
 		/*domain not found, create a new domain Node*/
 		purple_debug_info("MaYuan","get No d_node\n");
 		d_node = xmlnode_new("d");
@@ -623,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_str);
+	purple_debug_info("MaYuan","list_op:%d\n",list_op);
 	xmlnode_set_attrib(c_node,"l",list_op_str);
 	g_free(list_op_str);
 #if 0
@@ -643,7 +645,7 @@
 #endif
 	xmlnode_insert_child(d_node, c_node);
 
-	g_free(tokens);
+	g_strfreev(tokens);
 }
 
 static void
@@ -743,6 +745,24 @@
 }
 
 static void
+adl_error(MsnCmdProc *cmdproc, MsnTransaction *trans, int error)
+{
+	MsnSession *session;
+	PurpleAccount *account;
+	PurpleConnection *gc;
+	char *reason = NULL;
+
+	session = cmdproc->session;
+	account = session->account;
+	gc = purple_account_get_connection(account);
+
+	purple_debug_error("msn","ADL error\n");
+	reason = g_strdup_printf(_("Unknown error (%d)"), error);
+	purple_notify_error(gc, NULL, _("Unable to add user"), reason);
+	g_free(reason);
+}
+
+static void
 fqy_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload,
 			 size_t len)
 {
@@ -1582,12 +1602,17 @@
 		session->passport_info.sl = atol(value);
 
 	/*starting retrieve the contact list*/
+#ifdef MSN_PARTIAL_ADDRESSBOOK
 	msn_userlist_load(session);
-	
+#endif
 	session->contact = msn_contact_new(session);
 	clLastChange = purple_account_get_string(session->account, "CLLastChange", NULL);
 	msn_get_contact_list(session->contact, clLastChange);
-//	msn_contact_connect(session->contact);
+#if 0
+	/* always get the full list? */
+	msn_get_contact_list(session->contact, NULL);
+	msn_contact_connect(session->contact);
+#endif
 }
 
 static void
@@ -1648,58 +1673,72 @@
 initial_mdata_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
 {
 	MsnSession *session;
-	char **elems, **cur, **tokens;
-
-//	purple_debug_info("MaYuan","mdata...{%s} \n",msg->body);
+	PurpleConnection *gc;
+	GHashTable *table;
+	const char *mdata, *unread;
 
-//	/*time debug*/
-	{
-	const char *timestr;
-	time_t t;
-	struct tm *tm;
-	char datestr[]="2006-07-15T07:21:26+0700";
-	GDate *date;
-	time(&t);
-	tm = gmtime(&t);
-	timestr = purple_utf8_strftime("%a, %d %b %Y %T %Z", tm);
-//	strftime(datestr,strlen(datestr),"%a",tm);
-	date = g_date_new();
-	g_date_set_parse(date,datestr);
-	purple_debug_info("MaYuan","date is NULL?date valid%d\n",g_date_valid(date));
-	g_date_free(date);
-	purple_debug_info("MaYuan","utf8 time:{%s}\n",timestr);
-	}
+	session = cmdproc->session;
+	gc = session->account->gc;
+
+	if (strcmp(msg->remote_user, "Hotmail"))
+		/* This isn't an official message. */
+		return;
 
 	/*new a oim session*/
-	session = cmdproc->session;
 	session->oim = msn_oim_new(session);
 //	msn_oim_connect(session->oim);
 
-	/*parse offline message data*/
-	elems = g_strsplit(msg->body, "\r\n", 0);
-	for (cur = elems; *cur != NULL; cur++){
-		const char *key, *value;
+	table = msn_message_get_hashtable_from_body(msg);
 
-//		purple_debug_info("MaYuan","cur:{%s}\n",*cur);
-		tokens = g_strsplit(*cur, ": ", 2);
+	mdata = g_hash_table_lookup(table, "Mail-Data");
+
+	if (mdata != NULL)
+		msn_parse_oim_msg(session->oim, mdata);
 
-		key = tokens[0];
-		value = tokens[1];
+	if (g_hash_table_lookup(table, "Inbox-URL") == NULL)
+	{
+		g_hash_table_destroy(table);
+		return;
+	}
 
-		/*if not MIME content ,then return*/
-		if ((key != NULL) && (!strcmp(key, "Mail-Data")) ){
-//			purple_debug_info("MaYuan","data:{%s}\n",value);
-			msn_parse_oim_msg(session->oim,value);
-			g_strfreev(tokens);
-			break;
-		}
+	if (session->passport_info.file == NULL)
+	{
+		MsnTransaction *trans;
+		trans = msn_transaction_new(cmdproc, "URL", "%s", "INBOX");
+		msn_transaction_queue_cmd(trans, msg->cmd);
 
-		g_strfreev(tokens);
+		msn_cmdproc_send_trans(cmdproc, trans);
+
+		g_hash_table_destroy(table);
+		return;
 	}
 
-	g_strfreev(elems);
-/* test code for add group*/
-//	msn_add_group(session,"hello");
+	if (!purple_account_get_check_mail(session->account))
+	{
+		g_hash_table_destroy(table);
+		return;
+	}
+
+	unread = g_hash_table_lookup(table, "Inbox-Unread");
+
+	if (unread != NULL)
+	{
+		int count = atoi(unread);
+
+		if (count > 0)
+		{
+			const char *passport;
+			const char *url;
+
+			passport = msn_user_get_passport(session->user);
+			url = session->passport_info.file;
+
+			purple_notify_emails(gc, atoi(unread), FALSE, NULL, NULL,
+							   &passport, &url, NULL, NULL);
+		}
+	}
+
+	g_hash_table_destroy(table);
 }
 
 /*offline Message Notification*/
@@ -1923,6 +1962,7 @@
 	msn_table_add_cmd(cbs_table, "fallback", "XFR", xfr_cmd);
 
 	msn_table_add_error(cbs_table, "ADD", add_error);
+	msn_table_add_error(cbs_table, "ADL", adl_error);
 	msn_table_add_error(cbs_table, "REG", reg_error);
 	msn_table_add_error(cbs_table, "RMG", rmg_error);
 	/* msn_table_add_error(cbs_table, "REA", rea_error); */