# HG changeset patch
# Node ID a94c40ec9607
# Parent  3c037af432c4
diff --git a/libpurple/account.c b/libpurple/account.c
--- a/libpurple/account.c
+++ b/libpurple/account.c
@@ -2791,13 +2791,10 @@
 		protocol = purple_connection_get_protocol(gc);
 
 	if (protocol) {
-		GList *cur, *groups = NULL;
+		GList *groups;
 
 		/* Make a list of what group each buddy is in */
-		for (cur = buddies; cur != NULL; cur = cur->next) {
-			PurpleBuddy *buddy = cur->data;
-			groups = g_list_append(groups, purple_buddy_get_group(buddy));
-		}
+		groups = g_list_copy_deep(buddies, (GCopyFunc)purple_buddy_get_group, NULL);
 
 		if(PURPLE_IS_PROTOCOL_SERVER(protocol)) {
 			purple_protocol_server_add_buddies(PURPLE_PROTOCOL_SERVER(protocol),
diff --git a/libpurple/media/backend-fs2.c b/libpurple/media/backend-fs2.c
--- a/libpurple/media/backend-fs2.c
+++ b/libpurple/media/backend-fs2.c
@@ -634,20 +634,6 @@
 	return fscandidate;
 }
 
-static GList *
-candidate_list_to_fs(GList *candidates)
-{
-	GList *new_list = NULL;
-
-	for (; candidates; candidates = g_list_next(candidates)) {
-		new_list = g_list_prepend(new_list,
-				candidate_to_fs(candidates->data));
-	}
-
-	new_list = g_list_reverse(new_list);
-	return new_list;
-}
-
 static PurpleMediaCandidate *
 candidate_from_fs(FsCandidate *fscandidate)
 {
@@ -671,20 +657,6 @@
 	return candidate;
 }
 
-static GList *
-candidate_list_from_fs(GList *candidates)
-{
-	GList *new_list = NULL;
-
-	for (; candidates; candidates = g_list_next(candidates)) {
-		new_list = g_list_prepend(new_list,
-			candidate_from_fs(candidates->data));
-	}
-
-	new_list = g_list_reverse(new_list);
-	return new_list;
-}
-
 static FsCodec *
 codec_to_fs(const PurpleMediaCodec *codec)
 {
@@ -746,34 +718,6 @@
 	return new_codec;
 }
 
-static GList *
-codec_list_from_fs(GList *codecs)
-{
-	GList *new_list = NULL;
-
-	for (; codecs; codecs = g_list_next(codecs)) {
-		new_list = g_list_prepend(new_list,
-				codec_from_fs(codecs->data));
-	}
-
-	new_list = g_list_reverse(new_list);
-	return new_list;
-}
-
-static GList *
-codec_list_to_fs(GList *codecs)
-{
-	GList *new_list = NULL;
-
-	for (; codecs; codecs = g_list_next(codecs)) {
-		new_list = g_list_prepend(new_list,
-				codec_to_fs(codecs->data));
-	}
-
-	new_list = g_list_reverse(new_list);
-	return new_list;
-}
-
 static PurpleMediaBackendFs2Session *
 get_session(PurpleMediaBackendFs2 *self, const gchar *sess_id)
 {
@@ -2167,7 +2111,7 @@
 	}
 
 	stream->remote_candidates = g_list_concat(stream->remote_candidates,
-			candidate_list_to_fs(remote_candidates));
+	        g_list_copy_deep(remote_candidates, (GCopyFunc)candidate_to_fs, NULL));
 
 	if (purple_media_is_initiator(priv->media, sess_id, participant) ||
 			purple_media_accepted(
@@ -2274,7 +2218,7 @@
 
 	g_object_get(G_OBJECT(session->session),
 		     "codecs", &fscodecs, NULL);
-	codecs = codec_list_from_fs(fscodecs);
+	codecs = g_list_copy_deep(fscodecs, (GCopyFunc)codec_from_fs, NULL);
 	fs_codec_list_destroy(fscodecs);
 
 	return codecs;
@@ -2292,9 +2236,10 @@
 	stream = get_stream(PURPLE_MEDIA_BACKEND_FS2(self),
 			sess_id, participant);
 
-	if (stream != NULL)
-		candidates = candidate_list_from_fs(
-				stream->local_candidates);
+	if (stream != NULL) {
+		candidates = g_list_copy_deep(stream->local_candidates,
+		                              (GCopyFunc)candidate_from_fs, NULL);
+	}
 	return candidates;
 }
 
@@ -2314,7 +2259,7 @@
 	if (stream == NULL)
 		return FALSE;
 
-	fscodecs = codec_list_to_fs(codecs);
+	fscodecs = g_list_copy_deep(codecs, (GCopyFunc)codec_to_fs, NULL);
 	fs_stream_set_remote_codecs(stream->stream, fscodecs, &err);
 	fs_codec_list_destroy(fscodecs);
 
diff --git a/libpurple/media/candidate.c b/libpurple/media/candidate.c
--- a/libpurple/media/candidate.c
+++ b/libpurple/media/candidate.c
@@ -352,15 +352,7 @@
 GList *
 purple_media_candidate_list_copy(GList *candidates)
 {
-	GList *new_list = NULL;
-
-	for (; candidates; candidates = g_list_next(candidates)) {
-		new_list = g_list_prepend(new_list,
-				purple_media_candidate_copy(candidates->data));
-	}
-
-	new_list = g_list_reverse(new_list);
-	return new_list;
+	return g_list_copy_deep(candidates, (GCopyFunc)purple_media_candidate_copy, NULL);
 }
 
 void
diff --git a/libpurple/media/codec.c b/libpurple/media/codec.c
--- a/libpurple/media/codec.c
+++ b/libpurple/media/codec.c
@@ -343,15 +343,7 @@
 GList *
 purple_media_codec_list_copy(GList *codecs)
 {
-	GList *new_list = NULL;
-
-	for (; codecs; codecs = g_list_next(codecs)) {
-		new_list = g_list_prepend(new_list,
-				purple_media_codec_copy(codecs->data));
-	}
-
-	new_list = g_list_reverse(new_list);
-	return new_list;
+	return g_list_copy_deep(codecs, (GCopyFunc)purple_media_codec_copy, NULL);
 }
 
 void
diff --git a/libpurple/prefs.c b/libpurple/prefs.c
--- a/libpurple/prefs.c
+++ b/libpurple/prefs.c
@@ -739,7 +739,6 @@
 purple_prefs_add_path_list(const char *name, GList *value)
 {
 	struct purple_pref *pref;
-	GList *tmp;
 
 	/* re-use the string list UI OP */
 	PURPLE_PREFS_UI_OP_CALL(add_string_list, name, value);
@@ -749,9 +748,8 @@
 	if(!pref)
 		return;
 
-	for(tmp = value; tmp; tmp = tmp->next)
-		pref->value.stringlist = g_list_append(pref->value.stringlist,
-				g_strdup(tmp->data));
+	pref->value.stringlist = g_list_concat(pref->value.stringlist,
+	        g_list_copy_deep(value, (GCopyFunc)g_strdup, NULL));
 }
 
 static void
@@ -1065,8 +1063,6 @@
 	pref = find_pref(name);
 
 	if(pref) {
-		GList *tmp;
-
 		if(pref->type != PURPLE_PREF_PATH_LIST) {
 			purple_debug_error("prefs",
 					"purple_prefs_set_path_list: %s not a path list pref\n",
@@ -1075,12 +1071,7 @@
 		}
 
 		g_list_free_full(pref->value.stringlist, g_free);
-		pref->value.stringlist = NULL;
-
-		for(tmp = value; tmp; tmp = tmp->next)
-			pref->value.stringlist = g_list_prepend(pref->value.stringlist,
-					g_strdup(tmp->data));
-		pref->value.stringlist = g_list_reverse(pref->value.stringlist);
+		pref->value.stringlist = g_list_copy_deep(value, (GCopyFunc)g_strdup, NULL);
 
 		do_callbacks(name, pref);
 
@@ -1190,7 +1181,6 @@
 purple_prefs_get_string_list(const char *name)
 {
 	struct purple_pref *pref;
-	GList *ret = NULL, *tmp;
 
 	PURPLE_PREFS_UI_OP_CALL_RETURN(get_string_list, name);
 
@@ -1206,11 +1196,7 @@
 		return NULL;
 	}
 
-	for(tmp = pref->value.stringlist; tmp; tmp = tmp->next)
-		ret = g_list_prepend(ret, g_strdup(tmp->data));
-	ret = g_list_reverse(ret);
-
-	return ret;
+	return g_list_copy_deep(pref->value.stringlist, (GCopyFunc)g_strdup, NULL);
 }
 
 const char *
@@ -1239,7 +1225,6 @@
 purple_prefs_get_path_list(const char *name)
 {
 	struct purple_pref *pref;
-	GList *ret = NULL, *tmp;
 
 	PURPLE_PREFS_UI_OP_CALL_RETURN(get_string_list, name);
 
@@ -1255,11 +1240,7 @@
 		return NULL;
 	}
 
-	for(tmp = pref->value.stringlist; tmp; tmp = tmp->next)
-		ret = g_list_prepend(ret, g_strdup(tmp->data));
-	ret = g_list_reverse(ret);
-
-	return ret;
+	return g_list_copy_deep(pref->value.stringlist, (GCopyFunc)g_strdup, NULL);
 }
 
 static void
diff --git a/libpurple/protocols.c b/libpurple/protocols.c
--- a/libpurple/protocols.c
+++ b/libpurple/protocols.c
@@ -340,22 +340,11 @@
 GList *
 purple_protocol_get_statuses(PurpleAccount *account, PurplePresence *presence)
 {
-	GList *statuses = NULL;
-	GList *l;
-	PurpleStatus *status;
-
 	g_return_val_if_fail(account  != NULL, NULL);
 	g_return_val_if_fail(presence != NULL, NULL);
 
-	for (l = purple_account_get_status_types(account); l != NULL; l = l->next)
-	{
-		status = purple_status_new((PurpleStatusType *)l->data, presence);
-		statuses = g_list_prepend(statuses, status);
-	}
-
-	statuses = g_list_reverse(statuses);
-
-	return statuses;
+	return g_list_copy_deep(purple_account_get_status_types(account),
+	                        (GCopyFunc)purple_status_new, presence);
 }
 
 static void
