From 73876d41da2e9520ab48bc334f7c1f86792c2f43 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Mon, 8 Apr 2013 23:21:41 +0300 Subject: [PATCH] subscriptions: DRY removal for allowed event check Factor out the common g_slist_find_custom() call to one new sipe-subscription function. --- src/core/sip-transport.c | 18 ++++++------------ src/core/sipe-subscriptions.c | 14 ++++++++++++-- src/core/sipe-subscriptions.h | 10 ++++++++++ 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/core/sip-transport.c b/src/core/sip-transport.c index 69775cd0..0f15b121 100644 --- a/src/core/sip-transport.c +++ b/src/core/sip-transport.c @@ -1074,8 +1074,7 @@ static gboolean process_register_response(struct sipe_core_private *sipe_private /* subscriptions, done only once */ if (!transport->subscribed) { - if (g_slist_find_custom(sipe_private->allowed_events, "vnd-microsoft-roaming-contacts", - (GCompareFunc)g_ascii_strcasecmp)) { + if (sipe_subscription_is_allowed(sipe_private, "vnd-microsoft-roaming-contacts")) { sipe_subscribe_roaming_contacts(sipe_private); } @@ -1087,12 +1086,10 @@ static gboolean process_register_response(struct sipe_core_private *sipe_private */ if (SIPE_CORE_PRIVATE_FLAG_IS(OCS2007)) { - if (g_slist_find_custom(sipe_private->allowed_events, "vnd-microsoft-roaming-self", - (GCompareFunc)g_ascii_strcasecmp)) { + if (sipe_subscription_is_allowed(sipe_private, "vnd-microsoft-roaming-self")) { sipe_subscribe_roaming_self(sipe_private); } - if (g_slist_find_custom(sipe_private->allowed_events, "vnd-microsoft-provisioning-v2", - (GCompareFunc)g_ascii_strcasecmp)) { + if (sipe_subscription_is_allowed(sipe_private, "vnd-microsoft-provisioning-v2")) { sipe_subscribe_roaming_provisioning_v2(sipe_private); } } @@ -1101,16 +1098,13 @@ static gboolean process_register_response(struct sipe_core_private *sipe_private { //sipe_options_request(sip, sipe_private->public.sip_domain); - if (g_slist_find_custom(sipe_private->allowed_events, "vnd-microsoft-roaming-ACL", - (GCompareFunc)g_ascii_strcasecmp)) { + if (sipe_subscription_is_allowed(sipe_private, "vnd-microsoft-roaming-ACL")) { sipe_subscribe_roaming_acl(sipe_private); } - if (g_slist_find_custom(sipe_private->allowed_events, "vnd-microsoft-provisioning", - (GCompareFunc)g_ascii_strcasecmp)) { + if (sipe_subscription_is_allowed(sipe_private, "vnd-microsoft-provisioning")) { sipe_subscribe_roaming_provisioning(sipe_private); } - if (g_slist_find_custom(sipe_private->allowed_events, "presence.wpending", - (GCompareFunc)g_ascii_strcasecmp)) { + if (sipe_subscription_is_allowed(sipe_private, "presence.wpending")) { sipe_subscribe_presence_wpending(sipe_private, NULL); } diff --git a/src/core/sipe-subscriptions.c b/src/core/sipe-subscriptions.c index e3091513..dccca1e1 100644 --- a/src/core/sipe-subscriptions.c +++ b/src/core/sipe-subscriptions.c @@ -140,6 +140,14 @@ void sipe_subscription_terminate(struct sipe_core_private *sipe_private, g_free(key); } +gboolean sipe_subscription_is_allowed(struct sipe_core_private *sipe_private, + const gchar *event) +{ + return(g_slist_find_custom(sipe_private->allowed_events, + event, + (GCompareFunc) g_ascii_strcasecmp) != NULL); +} + static void sipe_presence_timeout_mime_cb(gpointer user_data, SIPE_UNUSED_PARAMETER const GSList *fields, const gchar *body, @@ -236,7 +244,8 @@ static void sipe_subscription_expiration(struct sipe_core_private *sipe_private, if (timeout > 240) timeout -= 120; if (sipe_strcase_equal(event, "presence.wpending") && - g_slist_find_custom(sipe_private->allowed_events, "presence.wpending", (GCompareFunc)g_ascii_strcasecmp)) { + sipe_subscription_is_allowed(sipe_private, + "presence.wpending")) { gchar *action_name = g_strdup_printf("<%s>", "presence.wpending"); sipe_schedule_seconds(sipe_private, action_name, @@ -247,7 +256,8 @@ static void sipe_subscription_expiration(struct sipe_core_private *sipe_private, g_free(action_name); } else if (sipe_strcase_equal(event, "presence") && - g_slist_find_custom(sipe_private->allowed_events, "presence", (GCompareFunc)g_ascii_strcasecmp)) { + sipe_subscription_is_allowed(sipe_private, + "presence")) { gchar *who = parse_from(sipmsg_find_header(msg, "To")); gchar *action_name = sipe_utils_presence_key(who); diff --git a/src/core/sipe-subscriptions.h b/src/core/sipe-subscriptions.h index 5e8773a6..c27c1395 100644 --- a/src/core/sipe-subscriptions.h +++ b/src/core/sipe-subscriptions.h @@ -32,6 +32,16 @@ void sipe_subscriptions_unsubscribe(struct sipe_core_private *sipe_private); void sipe_subscriptions_destroy(struct sipe_core_private *sipe_private); /** + * Does the server allow a subscription to a certain event? + * + * @param sipe_private SIPE core private data + * @param event subscription event (must not be @c NULL) + */ +gboolean sipe_subscription_is_allowed(struct sipe_core_private *sipe_private, + const gchar *event); + + +/** * Terminate subscription * * @param sipe_private SIPE core private data -- 2.11.4.GIT