From 6d39b51315cc836aa7d47ec0edef7c65cdb2d0a9 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Fri, 9 Aug 2013 22:13:22 +0300 Subject: [PATCH] buddy: add interface to iterate over buddies This removes the last externel reference to sipe_private->buddies. --- src/core/sipe-buddy.c | 7 +++++++ src/core/sipe-buddy.h | 11 +++++++++++ src/core/sipe-ocs2005.c | 8 ++++---- src/core/sipe-ocs2007.c | 6 +++--- src/core/sipe-subscriptions.c | 18 +++++++++--------- 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/core/sipe-buddy.c b/src/core/sipe-buddy.c index c0dfe994..49477801 100644 --- a/src/core/sipe-buddy.c +++ b/src/core/sipe-buddy.c @@ -95,6 +95,13 @@ struct sipe_buddy *sipe_buddy_find_by_uri(struct sipe_core_private *sipe_private return(g_hash_table_lookup(sipe_private->buddies, uri)); } +void sipe_buddy_foreach(struct sipe_core_private *sipe_private, + GHFunc callback, + gpointer callback_data) +{ + g_hash_table_foreach(sipe_private->buddies, callback, callback_data); +} + static void buddy_free(struct sipe_buddy *buddy) { #ifndef _WIN32 diff --git a/src/core/sipe-buddy.h b/src/core/sipe-buddy.h index 2e6470b1..1c2a8606 100644 --- a/src/core/sipe-buddy.h +++ b/src/core/sipe-buddy.h @@ -86,6 +86,17 @@ struct sipe_buddy *sipe_buddy_find_by_uri(struct sipe_core_private *sipe_private const gchar *uri); /** + * Iterate buddy list + * + * @param sipe_private SIPE core data + * @param callback function to call on each buddy + * @param callback_data user data for the callback + */ +void sipe_buddy_foreach(struct sipe_core_private *sipe_private, + GHFunc callback, + gpointer callback_data); + +/** * Cancels buddy subscriptions and then deletes the buddy * * @param sipe_private SIPE core data diff --git a/src/core/sipe-ocs2005.c b/src/core/sipe-ocs2005.c index 062df07c..b94162e7 100644 --- a/src/core/sipe-ocs2005.c +++ b/src/core/sipe-ocs2005.c @@ -3,7 +3,7 @@ * * pidgin-sipe * - * Copyright (C) 2011 SIPE Project + * Copyright (C) 2011-2013 SIPE Project * * * This program is free software; you can redistribute it and/or modify @@ -501,9 +501,9 @@ static void update_calendar_status(struct sipe_core_private *sipe_private, SIPE_UNUSED_PARAMETER void *unused) { SIPE_DEBUG_INFO_NOFORMAT("update_calendar_status() started."); - g_hash_table_foreach(sipe_private->buddies, - (GHFunc)update_calendar_status_cb, - sipe_private); + sipe_buddy_foreach(sipe_private, + (GHFunc) update_calendar_status_cb, + sipe_private); /* repeat scheduling */ sipe_ocs2005_schedule_status_update(sipe_private, diff --git a/src/core/sipe-ocs2007.c b/src/core/sipe-ocs2007.c index d626b385..74a66e35 100644 --- a/src/core/sipe-ocs2007.c +++ b/src/core/sipe-ocs2007.c @@ -2011,9 +2011,9 @@ static void sipe_refresh_blocked_status_cb(char *buddy_name, static void sipe_refresh_blocked_status(struct sipe_core_private *sipe_private) { - g_hash_table_foreach(sipe_private->buddies, - (GHFunc) sipe_refresh_blocked_status_cb, - sipe_private); + sipe_buddy_foreach(sipe_private, + (GHFunc) sipe_refresh_blocked_status_cb, + sipe_private); } /** diff --git a/src/core/sipe-subscriptions.c b/src/core/sipe-subscriptions.c index 3ed0a42e..72ad1c0f 100644 --- a/src/core/sipe-subscriptions.c +++ b/src/core/sipe-subscriptions.c @@ -772,21 +772,21 @@ void sipe_subscribe_presence_initial(struct sipe_core_private *sipe_private) gchar *to = sip_uri_self(sipe_private); gchar *resources_uri = g_strdup(""); if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007)) { - g_hash_table_foreach(sipe_private->buddies, - (GHFunc) sipe_subscribe_resource_uri_with_context, - &resources_uri); + sipe_buddy_foreach(sipe_private, + (GHFunc) sipe_subscribe_resource_uri_with_context, + &resources_uri); } else { - g_hash_table_foreach(sipe_private->buddies, - (GHFunc) sipe_subscribe_resource_uri, - &resources_uri); + sipe_buddy_foreach(sipe_private, + (GHFunc) sipe_subscribe_resource_uri, + &resources_uri); } sipe_subscribe_presence_batched_to(sipe_private, resources_uri, to); g_free(to); } else { - g_hash_table_foreach(sipe_private->buddies, - (GHFunc) schedule_buddy_resubscription_cb, - sipe_private); + sipe_buddy_foreach(sipe_private, + (GHFunc) schedule_buddy_resubscription_cb, + sipe_private); } SIPE_CORE_PRIVATE_FLAG_SET(SUBSCRIBED_BUDDIES); -- 2.11.4.GIT