diff src/protocols/msn/msn.c @ 4349:0c68d402f59f

[gaim-migrate @ 4614] XML Blist Gaim stores all the buddy lists in one big happy file now. You can order the buddies however you want, and they'll stay ordered that way. We can also store some per-buddy information now, which will be cool. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sun, 19 Jan 2003 22:16:52 +0000
parents cc2f780c0505
children 5fb47ec9bfe4
line wrap: on
line diff
--- a/src/protocols/msn/msn.c	Sun Jan 19 22:03:57 2003 +0000
+++ b/src/protocols/msn/msn.c	Sun Jan 19 22:16:52 2003 +0000
@@ -488,7 +488,7 @@
 			struct conversation *cnv;
 			struct buddy *b;
 
-			if ((b = find_buddy(gc, user)) != NULL)
+			if ((b = find_buddy(gc->user, user)) != NULL)
 				username = get_buddy_alias(b);
 			else
 				username = user;
@@ -1083,7 +1083,7 @@
 			signoff(map->gc);
 			return;
 		}
-		map->gc->permit = g_slist_append(map->gc->permit, map->user);
+		gaim_privacy_permit_add(map->gc->user, map->user);
 		build_allow_list(); /* er. right. we'll need to have a thing for this in CUI too */
 		show_got_added(map->gc, NULL, map->user, map->friend, NULL);
 	}
@@ -1105,7 +1105,7 @@
 			signoff(map->gc);
 			return;
 		}
-		map->gc->deny = g_slist_append(map->gc->deny, map->user);
+		gaim_privacy_deny_add(map->gc->user, map->user);
 		build_block_list();
 	}
 
@@ -1122,7 +1122,7 @@
 	if (!g_strncasecmp(buf, "ADD", 3)) {
 		char *list, *user, *friend, *tmp = buf;
 		struct msn_add_permit *ap;
-		GSList *perm = gc->permit;
+		GSList *perm = gc->user->permit;
 		char msg[MSN_BUF_LEN];
 
 		GET_NEXT(tmp);
@@ -1167,14 +1167,14 @@
 			 * from users who are not in BL will be delivered
 			 *
 			 * In other words, deny some */
-			gc->permdeny = DENY_SOME;
+			gc->user->permdeny = DENY_SOME;
 		} else {
 			/* If the current
 			 * setting is BL, only messages from people who are in the AL will be
 			 * delivered.
-			 * 
+			 *
 			 * In other words, permit some */
-			gc->permdeny = PERMIT_SOME;
+			gc->user->permdeny = PERMIT_SOME;
 		}
 	} else if (!g_strncasecmp(buf, "BPR", 3)) {
 	} else if (!g_strncasecmp(buf, "CHG", 3)) {
@@ -1247,8 +1247,8 @@
 	} else if (!g_strncasecmp(buf, "LST", 3)) {
 		char *which, *who, *friend, *tmp = buf;
 		struct msn_add_permit *ap; /* for any as yet undealt with buddies who've added you to their buddy list when you were off-line.  How dare they! */
-		GSList *perm = gc->permit; /* current permit list */
-		GSList *denyl = gc->deny;
+		GSList *perm = gc->user->permit; /* current permit list */
+		GSList *denyl = gc->user->deny;
 		char msg[MSN_BUF_LEN];
 		int new = 1;
 		int pos, tot;
@@ -1274,15 +1274,14 @@
 			b->friend = g_strdup(friend);
 			md->fl = g_slist_append(md->fl, b);
 		} else if (!g_strcasecmp(which, "AL") && pos) {
-			char *dupl;
-			if ((dupl = (char *)g_slist_find_custom(gc->deny, who, 
-							(GCompareFunc)strcmp))) {
+			if (g_slist_find_custom(gc->user->deny, who,
+							(GCompareFunc)strcmp)) {
 				debug_printf("moving from deny to permit: %s", who);
-				gc->deny = g_slist_remove(gc->deny, dupl);
+				gaim_privacy_deny_remove(gc->user, who);
 			}
-			gc->permit = g_slist_append(gc->permit, g_strdup(who));
+			gaim_privacy_permit_add(gc->user, who);
 		} else if (!g_strcasecmp(which, "BL") && pos) {
-			gc->deny = g_slist_append(gc->deny, g_strdup(who));
+			gaim_privacy_deny_remove(gc->user, who);
 		} else if (!g_strcasecmp(which, "RL")) {
 		    if (pos) {
 			while(perm) {
@@ -1320,25 +1319,15 @@
 			account_online(gc);
 			serv_finish_login(gc);
 
-			md->permit = g_slist_copy(gc->permit);
-			md->deny = g_slist_copy(gc->deny);
-
-			if (bud_list_cache_exists(gc))
-				do_import(gc, NULL);
-			else {
-				g_snprintf(sendbuf, sizeof(sendbuf), "BLP %u AL\r\n", ++md->trId);
-				if (msn_write(md->fd, sendbuf, strlen(sendbuf)) < 0) {
-					hide_login_progress(gc, _("Unable to write"));
-					signoff(gc);
-					return 0;
-				}
-			}
+			md->permit = g_slist_copy(gc->user->permit);
+			md->deny = g_slist_copy(gc->user->deny);
+
 			while (md->fl) {
 				struct msn_buddy *mb = md->fl->data;
-				struct buddy *b = find_buddy(gc, mb->user);
+				struct buddy *b = find_buddy(gc->user, mb->user);
 				md->fl = g_slist_remove(md->fl, mb);
 				if(!b)
-					b = add_buddy(gc, _("Buddies"), mb->user, NULL);
+					b = add_buddy(gc->user, _("Buddies"), mb->user, NULL);
 				serv_got_alias(gc, mb->user, mb->friend);
 				g_free(mb->user);
 				g_free(mb->friend);
@@ -2458,7 +2447,7 @@
 {
 	GList *m = NULL;
 	struct proto_buddy_menu *pbm;
-	struct buddy *b = find_buddy(gc, who);
+	struct buddy *b = find_buddy(gc->user, who);
 	static char buf[MSN_BUF_LEN];
 
 	pbm = g_new0(struct proto_buddy_menu, 1);
@@ -2604,7 +2593,7 @@
 	char buf[MSN_BUF_LEN];
 	GSList *s, *t = NULL;
 
-	if (gc->permdeny == PERMIT_ALL || gc->permdeny == DENY_SOME)
+	if (gc->user->permdeny == PERMIT_ALL || gc->user->permdeny == DENY_SOME)
 		g_snprintf(buf, sizeof(buf), "BLP %u AL\r\n", ++md->trId);
 	else
 		g_snprintf(buf, sizeof(buf), "BLP %u BL\r\n", ++md->trId);
@@ -2618,11 +2607,11 @@
 	/* this is safe because we'll always come here after we've gotten the list off the server,
 	 * and data is never removed. So if the lengths are equal we don't know about anyone locally
 	 * and so there's no sense in going through them all. */
-	if (g_slist_length(gc->permit) == g_slist_length(md->permit)) {
+	if (g_slist_length(gc->user->permit) == g_slist_length(md->permit)) {
 		g_slist_free(md->permit);
 		md->permit = NULL;
 	}
-	if (g_slist_length(gc->deny) == g_slist_length(md->deny)) {
+	if (g_slist_length(gc->user->deny) == g_slist_length(md->deny)) {
 		g_slist_free(md->deny);
 		md->deny = NULL;
 	}
@@ -2630,16 +2619,15 @@
 		return;
 
 	if (md->permit) {
-		s = g_slist_nth(gc->permit, g_slist_length(md->permit));
+		s = g_slist_nth(gc->user->permit, g_slist_length(md->permit));
 		while (s) {
 			char *who = s->data;
-			char *dupl;
 			s = s->next;
 			if (!strchr(who, '@')) {
 				t = g_slist_append(t, who);
 				continue;
 			}
-			if ((dupl = (char *)g_slist_find(md->deny, who))) {
+			if (g_slist_find(md->deny, who)) {
 				t = g_slist_append(t, who);
 				continue;
 			}
@@ -2651,9 +2639,7 @@
 			}
 		}
 		while (t) {
-			char *who = t->data;
-			gc->permit = g_slist_remove(gc->permit, who);
-			g_free(who);
+			gaim_privacy_permit_remove(gc->user, t->data);
 			t = t->next;
 		}
 		if (t)
@@ -2664,16 +2650,15 @@
 	}
 	
 	if (md->deny) {
-		s = g_slist_nth(gc->deny, g_slist_length(md->deny));
+		s = g_slist_nth(gc->user->deny, g_slist_length(md->deny));
 		while (s) {
 			char *who = s->data;
-			char *dupl;
 			s = s->next;
 			if (!strchr(who, '@')) {
 				t = g_slist_append(t, who);
 				continue;
 			}
-			if ((dupl = (char *)g_slist_find(md->deny, who))) {
+			if (g_slist_find(md->deny, who)) {
 				t = g_slist_append(t, who);
 				continue;
 			}
@@ -2685,9 +2670,7 @@
 			}
 		}
 		while (t) {
-			char *who = t->data;
-			gc->deny = g_slist_remove(gc->deny, who);
-			g_free(who);
+			gaim_privacy_deny_remove(gc->user, t->data);
 			t = t->next;
 		}
 		if (t)
@@ -2697,11 +2680,10 @@
 	}
 }
 
-static void msn_add_permit(struct gaim_connection *gc, char *who)
+static void msn_add_permit(struct gaim_connection *gc, const char *who)
 {
 	struct msn_data *md = gc->proto_data;
 	char buf[MSN_BUF_LEN];
-	char *dupl;
 
 	if (!strchr(who, '@')) {
 		g_snprintf(buf, sizeof(buf), 
@@ -2709,15 +2691,13 @@
 			     "Perhaps you meant %s@hotmail.com.  No changes were made to your "
 			     "allow list."), who);
 		do_error_dialog(_("Invalid MSN screenname"), buf, GAIM_ERROR);
-		gc->permit = g_slist_remove(gc->permit, who);
-		g_free(who);
+		gaim_privacy_permit_remove(gc->user, who);
 		return;
 	}
 
-	if ((dupl = (char *)g_slist_find_custom(gc->deny, who, 
-					(GCompareFunc)strcmp))) {
+	if (g_slist_find_custom(gc->user->deny, who, (GCompareFunc)strcmp)) {
 		debug_printf("MSN: Moving %s from BL to AL\n", who);
-		gc->deny = g_slist_remove(gc->deny, dupl);
+		gaim_privacy_deny_remove(gc->user, who);
 		g_snprintf(buf, sizeof(buf), "REM %u BL %s\r\n", ++md->trId, who);
 			if (msn_write(md->fd, buf, strlen(buf)) < 0) {
 				hide_login_progress(gc, _("Write error"));
@@ -2733,7 +2713,7 @@
 	}
 }
 
-static void msn_rem_permit(struct gaim_connection *gc, char *who)
+static void msn_rem_permit(struct gaim_connection *gc, const char *who)
 {
 	struct msn_data *md = gc->proto_data;
 	char buf[MSN_BUF_LEN];
@@ -2744,8 +2724,8 @@
 		signoff(gc);
 		return;
 	}
-	
-	g_slist_append(gc->deny, who);
+
+	gaim_privacy_deny_add(gc->user, who);
 	g_snprintf(buf, sizeof(buf), "ADD %u BL %s %s\r\n", ++md->trId, who, who);
 	if (msn_write(md->fd, buf, strlen(buf)) < 0) {
 		hide_login_progress(gc, _("Write error"));
@@ -2754,27 +2734,24 @@
 	}
 }
 
-static void msn_add_deny(struct gaim_connection *gc, char *who)
+static void msn_add_deny(struct gaim_connection *gc, const char *who)
 {
 	struct msn_data *md = gc->proto_data;
 	char buf[MSN_BUF_LEN];
-	char *dupl;
-	
+
 	if (!strchr(who, '@')) {
 		g_snprintf(buf, sizeof(buf), 
 			   _("An MSN screenname must be in the form \"user@server.com\".  "
 			     "Perhaps you meant %s@hotmail.com.  No changes were made to your "
 			     "block list."), who);
 		do_error_dialog(_("Invalid MSN screenname"), buf, GAIM_ERROR);
-		gc->deny = g_slist_remove(gc->deny, who);
-		g_free(who);
+		gaim_privacy_deny_remove(gc->user, who);
 		return;
 	}
 
-	if ((dupl = (char *)g_slist_find_custom(gc->permit, who, 
-					(GCompareFunc)strcmp))) {
+	if (g_slist_find_custom(gc->user->permit, who, (GCompareFunc)strcmp)) {
 		debug_printf("MSN: Moving %s from AL to BL\n", who);
-		gc->permit = g_slist_remove(gc->permit, dupl);
+		gaim_privacy_permit_remove(gc->user, who);
 		g_snprintf(buf, sizeof(buf), "REM %u AL %s\r\n", ++md->trId, who);
 		if (msn_write(md->fd, buf, strlen(buf)) < 0) {
 			hide_login_progress(gc, _("Write error"));
@@ -2782,7 +2759,7 @@
 			return;
 		}
 	}
-		
+
 
 	g_snprintf(buf, sizeof(buf), "ADD %u BL %s %s\r\n", ++md->trId, who, who);
 	if (msn_write(md->fd, buf, strlen(buf)) < 0) {
@@ -2792,7 +2769,7 @@
 	}
 }
 
-static void msn_rem_deny(struct gaim_connection *gc, char *who)
+static void msn_rem_deny(struct gaim_connection *gc, const char *who)
 {
 	struct msn_data *md = gc->proto_data;
 	char buf[MSN_BUF_LEN];
@@ -2803,8 +2780,8 @@
 		signoff(gc);
 		return;
 	}
-	
-	g_slist_append(gc->permit, who);
+
+	gaim_privacy_permit_add(gc->user, who);
 	g_snprintf(buf, sizeof(buf), "ADD %u AL %s %s\r\n", ++md->trId, who, who);
 	if (msn_write(md->fd, buf, strlen(buf)) < 0) {
 		hide_login_progress(gc, _("Write error"));