diff libgaim/protocols/msn/userlist.c @ 20390:d634f88e25d8

msn.tgz from SF Patch #1621854 from Ka-Hing Cheung "This tarball brings soc-2006-msnp13 up to head. In addition to that it also fixes a crash with sending offline messages. I wasn't able to generate a diff against that branch, svn seems to insist on diff'ing against HEAD after I run the merge command. After running `svn merge -r 16309:HEAD https://gaim.svn.sourceforge.net/svnroot/gaim/trunk` on the soc-2006-msnp13 you can replace the msn directory with the attached tarball. The fix for offline messaging is on msn.c:901: if (!session->oim) session->oim = msn_oim_new(session)" committer: Richard Laager <rlaager@wiktel.com>
author Ka-Hing Cheung <khc@hxbc.us>
date Sun, 15 Apr 2007 02:18:17 +0000
parents e354528c4163
children 9ba7dee775e1 9755b2f7bb0f
line wrap: on
line diff
--- a/libgaim/protocols/msn/userlist.c	Sun Apr 15 02:10:37 2007 +0000
+++ b/libgaim/protocols/msn/userlist.c	Sun Apr 15 02:18:17 2007 +0000
@@ -40,23 +40,10 @@
 static void
 msn_accept_add_cb(MsnPermitAdd *pa)
 {
-	if (g_list_find(gaim_connections_get_all(), pa->gc) != NULL)
-	{
-		MsnSession *session = pa->gc->proto_data;
-		MsnUserList *userlist = session->userlist;
-		GaimBuddy *buddy;
-
-		msn_userlist_add_buddy(userlist, pa->who, MSN_LIST_AL, NULL);
+	MsnSession *session = pa->gc->proto_data;
+	MsnUserList *userlist = session->userlist;
 
-		buddy = gaim_find_buddy(pa->gc->account, pa->who);
-
-		if (buddy != NULL)
-			gaim_account_notify_added(pa->gc->account, pa->who,
-				NULL, pa->friendly, NULL);
-		else
-			gaim_account_request_add(pa->gc->account, pa->who,
-				NULL, pa->friendly, NULL);
-	}
+	msn_userlist_add_buddy(userlist, pa->who, MSN_LIST_AL, NULL);
 
 	g_free(pa->who);
 	g_free(pa->friendly);
@@ -83,35 +70,16 @@
 got_new_entry(GaimConnection *gc, const char *passport, const char *friendly)
 {
 	MsnPermitAdd *pa;
-	char *msg;
 
 	pa = g_new0(MsnPermitAdd, 1);
 	pa->who = g_strdup(passport);
 	pa->friendly = g_strdup(friendly);
 	pa->gc = gc;
+	
+	gaim_account_request_authorization(gaim_connection_get_account(gc), passport, NULL, friendly, NULL,
+					   gaim_find_buddy(gaim_connection_get_account(gc), passport) != NULL,
+					   G_CALLBACK(msn_accept_add_cb), G_CALLBACK(msn_cancel_add_cb), pa);
 
-	if (friendly != NULL)
-	{
-		msg = g_strdup_printf(
-				   _("The user %s (%s) wants to add %s to his or her "
-					 "buddy list."),
-				   passport, friendly,
-				   gaim_account_get_username(gc->account));
-	}
-	else
-	{
-		msg = g_strdup_printf(
-				   _("The user %s wants to add %s to his or "
-					 "her buddy list."),
-				   passport, gaim_account_get_username(gc->account));
-	}
-
-	gaim_request_action(gc, NULL, msg, NULL,
-						GAIM_DEFAULT_ACTION_NONE, pa, 2,
-						_("Authorize"), G_CALLBACK(msn_accept_add_cb),
-						_("Deny"), G_CALLBACK(msn_cancel_add_cb));
-
-	g_free(msg);
 }
 
 /**************************************************************************
@@ -188,7 +156,6 @@
 {
 	MsnSession *session;
 	MsnCmdProc *cmdproc;
-	MsnTransaction *trans;
 	MsnMoveBuddy *data;
 
 	session = userlist->session;
@@ -206,9 +173,6 @@
 	/*add new group via SOAP action*/
 	msn_add_group(session, new_group_name);
 
-	msn_transaction_set_data(trans, data);
-
-	msn_cmdproc_send_trans(cmdproc, trans);
 }
 
 /**************************************************************************
@@ -255,22 +219,14 @@
 		if (group_id != NULL)
 		{
 			msn_user_add_group_id(user, group_id);
-		}
-		else
-		{
+		}else{
 			/* session->sync->fl_users_count++; */
 		}
-	}
-	else if (list_id == MSN_LIST_AL)
-	{
+	}else if (list_id == MSN_LIST_AL){
 		gaim_privacy_permit_add(account, passport, TRUE);
-	}
-	else if (list_id == MSN_LIST_BL)
-	{
+	}else if (list_id == MSN_LIST_BL){
 		gaim_privacy_deny_add(account, passport, TRUE);
-	}
-	else if (list_id == MSN_LIST_RL)
-	{
+	}else if (list_id == MSN_LIST_RL){
 		GaimConnection *gc;
 		GaimConversation *convo;
 
@@ -294,8 +250,7 @@
  			g_free(msg);
  		}
  
-		if (!(user->list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP)))
-		{
+		if (!(user->list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP))){
 			/*
 			 * TODO: The friendly name was NULL for me when I
 			 *       looked at this.  Maybe we should use the store
@@ -320,29 +275,19 @@
 
 	passport = msn_user_get_passport(user);
 
-	if (list_id == MSN_LIST_FL)
-	{
+	if (list_id == MSN_LIST_FL){
 		/* TODO: When is the user totally removed? */
-		if (group_id != NULL)
-		{
+		if (group_id != NULL){
 			msn_user_remove_group_id(user, group_id);
 			return;
-		}
-		else
-		{
+		}else{
 			/* session->sync->fl_users_count--; */
 		}
-	}
-	else if (list_id == MSN_LIST_AL)
-	{
+	}else if (list_id == MSN_LIST_AL){
 		gaim_privacy_permit_remove(account, passport, TRUE);
-	}
-	else if (list_id == MSN_LIST_BL)
-	{
+	}else if (list_id == MSN_LIST_BL){
 		gaim_privacy_deny_remove(account, passport, TRUE);
-	}
-	else if (list_id == MSN_LIST_RL)
-	{
+	}else if (list_id == MSN_LIST_RL){
 		GaimConversation *convo;
 
 		gaim_debug_info("msn",
@@ -367,11 +312,9 @@
 	user->list_op &= ~(1 << list_id);
 	/* gaim_user_remove_list_id (user, list_id); */
 
-	if (user->list_op == 0)
-	{
+	if (user->list_op == 0){
 		gaim_debug_info("msn", "Buddy '%s' shall be deleted?.\n",
 						passport);
-
 	}
 }
 
@@ -390,8 +333,7 @@
 	passport = msn_user_get_passport(user);
 	store = msn_user_get_store_name(user);
 
-	if (list_op & MSN_LIST_FL_OP)
-	{
+	if (list_op & MSN_LIST_FL_OP){
 		GSList *c;
 		for (c = group_ids; c != NULL; c = g_slist_next(c))	{
 			char *group_id;
@@ -404,22 +346,19 @@
 		serv_got_alias(gc, passport, store);
 	}
 
-	if (list_op & MSN_LIST_AL_OP)
-	{
+	if (list_op & MSN_LIST_AL_OP){
 		/* These are users who are allowed to see our status. */
 		gaim_privacy_deny_remove(account, passport, TRUE);
 		gaim_privacy_permit_add(account, passport, TRUE);
 	}
 
-	if (list_op & MSN_LIST_BL_OP)
-	{
+	if (list_op & MSN_LIST_BL_OP){
 		/* These are users who are not allowed to see our status. */
 		gaim_privacy_permit_remove(account, passport, TRUE);
 		gaim_privacy_deny_add(account, passport, TRUE);
 	}
 
-	if (list_op & MSN_LIST_RL_OP)
-	{
+	if (list_op & MSN_LIST_RL_OP){
 		/* These are users who have us on their buddy list. */
 		/*
 		 * TODO: What is store name set to when this happens?
@@ -428,8 +367,7 @@
 		 *       should use the friendly name, instead? --KingAnt
 		 */
 
-		if (!(list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP)))
-		{
+		if (!(list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP))){
 //			got_new_entry(gc, passport, store);
 		}
 	}
@@ -465,19 +403,15 @@
 	GList *l;
 
 	/*destroy userlist*/
-	for (l = userlist->users; l != NULL; l = l->next)
-	{
+	for (l = userlist->users; l != NULL; l = l->next){
 		msn_user_destroy(l->data);
 	}
-
 	g_list_free(userlist->users);
 
 	/*destroy group list*/
-	for (l = userlist->groups; l != NULL; l = l->next)
-	{
+	for (l = userlist->groups; l != NULL; l = l->next){
 		msn_group_destroy(l->data);
 	}
-
 	g_list_free(userlist->groups);
 
 	g_queue_free(userlist->buddy_icon_requests);
@@ -488,6 +422,20 @@
 	g_free(userlist);
 }
 
+MsnUser *
+msn_userlist_find_add_user(MsnUserList *userlist,const char *passport,const char *userName)
+{
+	MsnUser *user;
+
+	user = msn_userlist_find_user(userlist, passport);
+	if (user == NULL){
+		user = msn_user_new(userlist, passport, userName);
+		msn_userlist_add_user(userlist, user);
+	}
+	msn_user_set_store_name(user, userName);
+	return user;
+}
+
 void
 msn_userlist_add_user(MsnUserList *userlist, MsnUser *user)
 {
@@ -507,14 +455,15 @@
 
 	g_return_val_if_fail(passport != NULL, NULL);
 
-	for (l = userlist->users; l != NULL; l = l->next)
-	{
+	for (l = userlist->users; l != NULL; l = l->next){
 		MsnUser *user = (MsnUser *)l->data;
-
+//		gaim_debug_info("MsnUserList","user passport:%s,passport:%s\n",user->passport,passport);
 		g_return_val_if_fail(user->passport != NULL, NULL);
 
-		if (!strcmp(passport, user->passport))
+		if (!g_strcasecmp(passport, user->passport)){
+//			gaim_debug_info("MsnUserList","return:%p\n",user);
 			return user;
+		}
 	}
 
 	return NULL;
@@ -540,11 +489,10 @@
 	g_return_val_if_fail(userlist != NULL, NULL);
 	g_return_val_if_fail(id       != NULL, NULL);
 
-	for (l = userlist->groups; l != NULL; l = l->next)
-	{
+	for (l = userlist->groups; l != NULL; l = l->next){
 		MsnGroup *group = l->data;
 
-		if (!g_strcasecmp(group->id, id))
+		if (!g_strcasecmp(group->id,id))
 			return group;
 	}
 
@@ -559,8 +507,7 @@
 	g_return_val_if_fail(userlist != NULL, NULL);
 	g_return_val_if_fail(name     != NULL, NULL);
 
-	for (l = userlist->groups; l != NULL; l = l->next)
-	{
+	for (l = userlist->groups; l != NULL; l = l->next){
 		MsnGroup *group = l->data;
 
 		if ((group->name != NULL) && !g_strcasecmp(name, group->name))
@@ -577,11 +524,9 @@
 
 	group = msn_userlist_find_group_with_name(userlist, group_name);
 
-	if (group != NULL)
+	if (group != NULL){
 		return msn_group_get_id(group);
-	}
-	else
-	{
+	}else{
 		return NULL;
 	}
 }
@@ -593,10 +538,11 @@
 
 	group = msn_userlist_find_group_with_id(userlist, group_id);
 
-	if (group != NULL)
+	if (group != NULL){
 		return msn_group_get_name(group);
-	else
+	}else{
 		return NULL;
+	}
 }
 
 void
@@ -634,7 +580,6 @@
 	const char *list;
 
 	user = msn_userlist_find_user(userlist, who);
-	group_id = -1;
 
 	g_return_if_fail(user != NULL);
 
@@ -654,8 +599,7 @@
 	}
 
 	/* First we're going to check if not there. */
-	if (!(user_is_there(user, list_id, group_id)))
-	{
+	if (!(user_is_there(user, list_id, group_id))){
 		list = lists[list_id];
 		gaim_debug_error("msn", "User '%s' is not there: %s\n",
 						 who, list);
@@ -682,13 +626,11 @@
 	gaim_debug_info("MaYuan", "userlist add buddy,name:{%s},group:{%s}\n",who ,group_name);
 	group_id = NULL;
 
-	if (!gaim_email_is_valid(who))
-	{
+	if (!gaim_email_is_valid(who)){
 		/* only notify the user about problems adding to the friends list
 		 * maybe we should do something else for other lists, but it probably
 		 * won't cause too many problems if we just ignore it */
-		if (list_id == MSN_LIST_FL)
-		{
+		if (list_id == MSN_LIST_FL)	{
 			char *str = g_strdup_printf(_("Unable to add \"%s\"."), who);
 			gaim_notify_error(NULL, NULL, str,
 							  _("The screen name specified is invalid."));
@@ -698,12 +640,10 @@
 		return;
 	}
 
-	if (group_name != NULL)
-	{
+	if (group_name != NULL){
 		group_id = msn_userlist_find_group_id(userlist, group_name);
 
-		if (group_id < 0)
-		{
+		if (group_id == NULL){
 			/* Whoa, we must add that group first. */
 			msn_request_add_group(userlist, who, NULL, group_name);
 			return;
@@ -713,8 +653,7 @@
 	user = msn_userlist_find_user(userlist, who);
 
 	/* First we're going to check if it's already there. */
-	if (user_is_there(user, list_id, group_id))
-	{
+	if (user_is_there(user, list_id, group_id)){
 		list = lists[list_id];
 		gaim_debug_error("msn", "User '%s' is already there: %s\n", who, list);
 		return;
@@ -727,8 +666,10 @@
 
 	gaim_debug_info("MaYuan", "add user:{%s} to group id {%s}\n",store_name ,group_id);
 	msn_add_contact(userlist->session->contact,who,group_id);
+#if 1
 	msn_notification_add_buddy(userlist->session->notification, list, who,
 							   store_name, group_id);
+#endif
 }
 
 void
@@ -739,8 +680,7 @@
 
 	new_group_id = msn_userlist_find_group_id(userlist, new_group_name);
 
-	if (new_group_id == NULL)
-	{
+	if (new_group_id == NULL){
 		msn_request_add_group(userlist, who, old_group_name, new_group_name);
 		return;
 	}
@@ -748,3 +688,47 @@
 	msn_userlist_add_buddy(userlist, who, MSN_LIST_FL, new_group_name);
 	msn_userlist_rem_buddy(userlist, who, MSN_LIST_FL, old_group_name);
 }
+
+/*load userlist from the Blist file cache*/
+void
+msn_userlist_load(MsnSession *session)
+{
+	GaimBlistNode *gnode, *cnode, *bnode;
+	GaimConnection *gc = gaim_account_get_connection(session->account);
+	GSList *l;
+	MsnUser * user;
+
+	g_return_if_fail(gc != NULL);
+
+	for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next){
+		if(!GAIM_BLIST_NODE_IS_GROUP(gnode))
+			continue;
+		for(cnode = gnode->child; cnode; cnode = cnode->next) {
+			if(!GAIM_BLIST_NODE_IS_CONTACT(cnode))
+				continue;
+			for(bnode = cnode->child; bnode; bnode = bnode->next) {
+				GaimBuddy *b;
+				if(!GAIM_BLIST_NODE_IS_BUDDY(bnode))
+					continue;
+				b = (GaimBuddy *)bnode;
+				if(b->account == gc->account){
+					user = msn_userlist_find_add_user(session->userlist,
+						b->name,NULL);
+					msn_user_set_op(user,MSN_LIST_FL_OP);
+				}
+			}
+		}
+	}
+	for (l = session->account->permit; l != NULL; l = l->next) {
+		user = msn_userlist_find_add_user(session->userlist,
+						(char *)l->data,NULL);
+		msn_user_set_op(user,MSN_LIST_AL_OP);
+	}
+	for (l = session->account->deny; l != NULL; l = l->next) {
+		user = msn_userlist_find_add_user(session->userlist,
+						(char *)l->data,NULL);
+		msn_user_set_op(user,MSN_LIST_BL_OP);
+	}
+	
+}
+