changeset 3140:aa18e79365b7

[gaim-migrate @ 3155] The king ant ate my picnic committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Fri, 12 Apr 2002 02:40:41 +0000
parents b9cd7332adb7
children bcdbffc2c3e6
files ChangeLog src/protocols/oscar/aim.h src/protocols/oscar/oscar.c src/protocols/oscar/ssi.c
diffstat 4 files changed, 75 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Apr 12 02:32:28 2002 +0000
+++ b/ChangeLog	Fri Apr 12 02:40:41 2002 +0000
@@ -8,9 +8,10 @@
 	* Buddylist looks a little better
 	* Fixed MSN privacy settings
 	* Group deletion fix (Thanks Mark Doliner)
-	* Alias/Group syncronization for Jabber (Thanks JSeymour)
+	* Alias/Group syncronization for Jabber  (Thanks JSeymour)
  	* Fixed broken signal handling in gdm-started GNOME sessions 
  	  (Thanks Jim Seymour, Vann, Robert McQueen)
+	* Oscar group syncronization (Thanks, Mark Doliner)
 	
 version 0.55 (03/29/2002):
 	* Jabber improvements (Thanks Jim Seymour)
--- a/src/protocols/oscar/aim.h	Fri Apr 12 02:32:28 2002 +0000
+++ b/src/protocols/oscar/aim.h	Fri Apr 12 02:40:41 2002 +0000
@@ -1034,6 +1034,7 @@
 faim_export int aim_ssi_addmastergroup(aim_session_t *sess, aim_conn_t *conn);
 faim_export int aim_ssi_addgroups(aim_session_t *sess, aim_conn_t *conn, char **gn, unsigned int num);
 faim_export int aim_ssi_addpord(aim_session_t *sess, aim_conn_t *conn, char **sn, unsigned int num, fu16_t type);
+faim_export int aim_ssi_movebuddy(aim_session_t *sess, aim_conn_t *conn, char *oldgn, char *newgn, char *sn);
 faim_export int aim_ssi_delbuddies(aim_session_t *sess, aim_conn_t *conn, char *gn, char **sn, unsigned int num);
 faim_export int aim_ssi_delmastergroup(aim_session_t *sess, aim_conn_t *conn);
 faim_export int aim_ssi_delgroups(aim_session_t *sess, aim_conn_t *conn, char **gn, unsigned int num);
--- a/src/protocols/oscar/oscar.c	Fri Apr 12 02:32:28 2002 +0000
+++ b/src/protocols/oscar/oscar.c	Fri Apr 12 02:40:41 2002 +0000
@@ -2727,6 +2727,15 @@
 	}
 }
 
+static void oscar_move_buddy(struct gaim_connection *g, char *name, char *old_group, char *new_group) {
+	struct oscar_data *odata = (struct oscar_data *)g->proto_data;
+	if (!odata->icq)
+		if (odata->sess->ssi.received_data) {
+			aim_ssi_movebuddy(odata->sess, odata->conn, old_group, new_group, name);
+			debug_printf("ssi: moved buddy %s from group %s to group %s\n", name, old_group, new_group);
+		}
+}
+
 static void oscar_remove_buddy(struct gaim_connection *g, char *name, char *group) {
 	struct oscar_data *odata = (struct oscar_data *)g->proto_data;
 	if (odata->icq) {
@@ -3611,6 +3620,7 @@
 	ret->change_passwd = oscar_change_passwd;
 	ret->add_buddy = oscar_add_buddy;
 	ret->add_buddies = oscar_add_buddies;
+	ret->group_buddy = oscar_move_buddy;
 	ret->remove_buddy = oscar_remove_buddy;
 	ret->remove_buddies = oscar_remove_buddies;
 	ret->add_permit = oscar_add_permit;
--- a/src/protocols/oscar/ssi.c	Fri Apr 12 02:32:28 2002 +0000
+++ b/src/protocols/oscar/ssi.c	Fri Apr 12 02:40:41 2002 +0000
@@ -8,7 +8,6 @@
  * This is entirely too complicated.
  * You don't know the half of it.
  *
- * XXX - Make sure moving buddies from group to group moves the buddy in the server list also
  * XXX - Test for memory leaks
  * XXX - Better parsing of rights, and use the rights info to limit adds
  *
@@ -610,6 +609,68 @@
 	return 0;
 }
 
+faim_export int aim_ssi_movebuddy(aim_session_t *sess, aim_conn_t *conn, char *oldgn, char *newgn, char *sn)
+{
+	struct aim_ssi_item **groups, *buddy, *cur;
+	fu16_t i;
+
+	if (!sess || !conn || !oldgn || !newgn || !sn)
+		return -EINVAL;
+
+	/* Look up the buddy */
+	if (!(buddy = get_ssi_item(sess->ssi.items, sn, AIM_SSI_TYPE_BUDDY)))
+		return -ENOMEM;
+
+	/* Allocate an array of pointers to the two groups */
+	if (!(groups = (struct aim_ssi_item **)malloc(2*sizeof(struct aim_ssi_item *))))
+		return -ENOMEM;
+
+	/* Look up the old parent group */
+	if (!(groups[0] = get_ssi_item(sess->ssi.items, oldgn, AIM_SSI_TYPE_GROUP))) {
+		free(groups);
+		return -ENOMEM;
+	}
+
+	/* Look up the new parent group */
+	if (!(groups[1] = get_ssi_item(sess->ssi.items, newgn, AIM_SSI_TYPE_GROUP))) {
+		free(groups);
+		return -ENOMEM;
+	}
+
+	/* Send the delete item SNAC */
+	aim_ssi_addmoddel(sess, conn, &buddy, 1, AIM_CB_SSI_DEL);
+
+	/* Put the buddy in the new group */
+	buddy->gid = groups[1]->gid;
+
+	/* Assign a new buddy ID#, because the new group might already have a buddy with this ID# */
+	buddy->bid = 0;
+	do {
+		buddy->bid += 0x0001;
+		for (cur=sess->ssi.items, i=0; ((cur) && (!i)); cur=cur->next)
+			if ((cur->bid == buddy->bid) && (cur->gid == buddy->gid) && (cur->type == AIM_SSI_TYPE_BUDDY) && (cur->name) && aim_sncmp(cur->name, buddy->name))
+				i=1;
+	} while (i);
+
+	/* Rebuild the additional data in the two parent groups */
+	aim_ssi_rebuildgroup(sess, conn, groups[0]);
+	aim_ssi_rebuildgroup(sess, conn, groups[1]);
+
+	/* Send the add item SNAC */
+	aim_ssi_addmoddel(sess, conn, &buddy, 1, AIM_CB_SSI_ADD);
+
+	/* Send the mod item SNAC */
+	aim_ssi_addmoddel(sess, conn, groups, 2, AIM_CB_SSI_MOD);
+
+	/* Free the temporary array */
+	free(groups);
+
+	/* Begin sending SSI SNACs */
+	aim_ssi_dispatch(sess, conn);
+
+	return 0;
+}
+
 faim_export int aim_ssi_delbuddies(aim_session_t *sess, aim_conn_t *conn, char *gn, char **sn, unsigned int num)
 {
 	struct aim_ssi_item *cur, *parentgroup, **delitems;