diff libpurple/protocols/msn/notification.c @ 20414:76e736b59aa4

fixes #971, we can only ADL 150 contacts at a time or the notification server will kill us
author Ka-Hing Cheung <khc@hxbc.us>
date Mon, 14 May 2007 00:40:29 +0000
parents 522ade544156
children 0f6747c5dcc2
line wrap: on
line diff
--- a/libpurple/protocols/msn/notification.c	Sat May 12 19:35:18 2007 +0000
+++ b/libpurple/protocols/msn/notification.c	Mon May 14 00:40:29 2007 +0000
@@ -39,7 +39,7 @@
  ****************************************************************************/
 
 static void msn_notification_fqy_yahoo(MsnSession *session, const char *passport);
-static void msn_notification_post_adl(MsnCmdProc *cmdproc, char *payload, int payload_len);
+static void msn_notification_post_adl(MsnCmdProc *cmdproc, const char *payload, int payload_len);
 static void msn_add_contact_xml(xmlnode *mlNode, const char *passport, int list_op, int type);
 
 /**************************************************************************
@@ -631,7 +631,7 @@
 }
 
 static void
-msn_notification_post_adl(MsnCmdProc *cmdproc, char *payload, int payload_len)
+msn_notification_post_adl(MsnCmdProc *cmdproc, const char *payload, int payload_len)
 {
 	MsnTransaction *trans;
 
@@ -645,29 +645,42 @@
 void
 msn_notification_dump_contact(MsnSession *session)
 {
-	MsnUserList *userlist;
 	MsnUser *user;
 	GList *l;
 	xmlnode *adl_node;
 	char *payload;
 	int payload_len;
+	int adl_count = 0;
 	const char *display_name;
 
-	userlist = session->userlist;
 	adl_node = xmlnode_new("ml");
 	adl_node->child = NULL;
 	xmlnode_set_attrib(adl_node, "l", "1");
-
+	
 	/*get the userlist*/
-	for (l = userlist->users; l != NULL; l = l->next){
+	for (l = session->userlist->users; l != NULL; l = l->next){
 		user = l->data;
-		msn_add_contact_xml(adl_node,user->passport,user->list_op&MSN_LIST_OP_MASK,user->type);
+		msn_add_contact_xml(adl_node, user->passport,
+			user->list_op & MSN_LIST_OP_MASK, user->type);
+
+		/* each ADL command may contain up to 150 contacts */
+		if (++adl_count % 150 == 0 || l->next == NULL) {
+			payload = xmlnode_to_str(adl_node,&payload_len);
+
+			msn_notification_post_adl(session->notification->cmdproc,
+				payload, payload_len);
+
+			g_free(payload);
+			xmlnode_free(adl_node);
+
+			if (l->next) {
+				adl_node = xmlnode_new("ml");
+				adl_node->child = NULL;
+				xmlnode_set_attrib(adl_node, "l", "1");
+			}
+		}
 	}
 
-	payload = xmlnode_to_str(adl_node,&payload_len);
-	xmlnode_free(adl_node);
-
-	msn_notification_post_adl(session->notification->cmdproc,payload,payload_len);
 
 	display_name = purple_connection_get_display_name(session->account->gc);
 	if (display_name && strcmp(display_name,