From d0389049afac719d9f8123ed8358ee082854d9e7 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Thu, 11 Apr 2013 14:32:06 +0300 Subject: [PATCH] subscriptions: associate dialog with self subscriptions Do this for all self subscriptions not only "wpending". Do not delete the subscription/dialog when receiving an update. --- src/core/sipe-subscriptions.c | 116 +++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 59 deletions(-) diff --git a/src/core/sipe-subscriptions.c b/src/core/sipe-subscriptions.c index 74042d7f..a0ab80bc 100644 --- a/src/core/sipe-subscriptions.c +++ b/src/core/sipe-subscriptions.c @@ -139,6 +139,15 @@ static gboolean sipe_subscription_is_allowed(struct sipe_core_private *sipe_priv (GCompareFunc) g_ascii_strcasecmp) != NULL); } +static struct sip_dialog *sipe_subscribe_dialog(struct sipe_core_private *sipe_private, + const gchar *key) +{ + struct sip_dialog *dialog = g_hash_table_lookup(sipe_private->subscriptions, + key); + SIPE_DEBUG_INFO("sipe_subscribe_dialog: dialog for '%s' is %s", key, dialog ? "not NULL" : "NULL"); + return(dialog); +} + static void sipe_subscription_expiration(struct sipe_core_private *sipe_private, struct sipmsg *msg, const gchar *event); @@ -169,27 +178,32 @@ static gboolean process_subscribe_response(struct sipe_core_private *sipe_privat SIPE_DEBUG_INFO("process_subscribe_response: subscription '%s' to '%s' was terminated", event, with); - /* 200 OK; 481 Call Leg Does Not Exist */ - if ((msg->response == 200) || - (msg->response == 481) || - terminated) + /* 481 Call Leg Does Not Exist */ + if ((msg->response == 481) || terminated) { sipe_subscription_remove(sipe_private, key); /* create/store subscription dialog if not yet */ - if (!terminated && (msg->response == 200)) { - struct sip_subscription *subscription = g_new0(struct sip_subscription, 1); - g_hash_table_insert(sipe_private->subscriptions, - g_strdup(key), - subscription); - - subscription->dialog.callid = g_strdup(sipmsg_find_header(msg, "Call-ID")); - subscription->dialog.cseq = sipmsg_parse_cseq(msg); - subscription->dialog.with = g_strdup(with); - subscription->event = g_strdup(event); - sipe_dialog_parse(&subscription->dialog, msg, TRUE); - - SIPE_DEBUG_INFO("process_subscribe_response: subscription dialog added for: %s", - key); + } else if (msg->response == 200) { + struct sip_dialog *dialog = sipe_subscribe_dialog(sipe_private, key); + + if (!dialog) { + struct sip_subscription *subscription = g_new0(struct sip_subscription, 1); + g_hash_table_insert(sipe_private->subscriptions, + g_strdup(key), + subscription); + + subscription->dialog.callid = g_strdup(sipmsg_find_header(msg, "Call-ID")); + subscription->dialog.cseq = sipmsg_parse_cseq(msg); + subscription->dialog.with = g_strdup(with); + subscription->event = g_strdup(event); + + dialog = &subscription->dialog; + + SIPE_DEBUG_INFO("process_subscribe_response: subscription dialog added for: %s", + key); + } + + sipe_dialog_parse(dialog, msg, TRUE); } g_free(key); @@ -250,10 +264,11 @@ static void sipe_subscribe_self(struct sipe_core_private *sipe_private, const gchar *event, const gchar *accept, const gchar *addheaders, - const gchar *body, - struct sip_dialog *dialog) + const gchar *body) { gchar *self = sip_uri_self(sipe_private); + gchar *key = sipe_subscription_key(event, self); + struct sip_dialog *dialog = sipe_subscribe_dialog(sipe_private, key); sipe_subscribe(sipe_private, self, @@ -263,48 +278,18 @@ static void sipe_subscribe_self(struct sipe_core_private *sipe_private, body, dialog); - g_free(self); -} - -static struct sip_dialog *sipe_subscribe_dialog(struct sipe_core_private *sipe_private, - const gchar *key) -{ - struct sip_dialog *dialog = g_hash_table_lookup(sipe_private->subscriptions, - key); - SIPE_DEBUG_INFO("sipe_subscribe_dialog: dialog for '%s' is %s", key, dialog ? "not NULL" : "NULL"); - return dialog; -} - -static void sipe_subscribe_presence_buddy(struct sipe_core_private *sipe_private, - const gchar *uri, - const gchar *request, - const gchar *body) -{ - gchar *key = sipe_utils_presence_key(uri); - - sip_transport_subscribe(sipe_private, - uri, - request, - body, - sipe_subscribe_dialog(sipe_private, key), - process_subscribe_response); - g_free(key); + g_free(self); } static void sipe_subscribe_presence_wpending(struct sipe_core_private *sipe_private, SIPE_UNUSED_PARAMETER void *unused) { - gchar *key = sipe_subscription_key("presence.wpending", NULL); - sipe_subscribe_self(sipe_private, "presence.wpending", "text/xml+msrtc.wpending", NULL, - NULL, - sipe_subscribe_dialog(sipe_private, key)); - - g_free(key); + NULL); } /** @@ -316,7 +301,6 @@ static void sipe_subscribe_roaming_acl(struct sipe_core_private *sipe_private) "vnd-microsoft-roaming-ACL", "application/vnd-microsoft-roaming-acls+xml", NULL, - NULL, NULL); } @@ -329,7 +313,6 @@ static void sipe_subscribe_roaming_contacts(struct sipe_core_private *sipe_priva "vnd-microsoft-roaming-contacts", "application/vnd-microsoft-roaming-contacts+xml", NULL, - NULL, NULL); } @@ -342,7 +325,6 @@ static void sipe_subscribe_roaming_provisioning(struct sipe_core_private *sipe_p "vnd-microsoft-provisioning", "application/vnd-microsoft-roaming-provisioning+xml", "Expires: 0\r\n", - NULL, NULL); } @@ -363,8 +345,7 @@ static void sipe_subscribe_roaming_provisioning_v2(struct sipe_core_private *sip "" "" "" - "", - NULL); + ""); } /** @@ -385,8 +366,7 @@ static void sipe_subscribe_roaming_self(struct sipe_core_private *sipe_private) "" "" "" - "", - NULL); + ""); } void sipe_subscription_self_events(struct sipe_core_private *sipe_private) @@ -593,7 +573,25 @@ void sipe_subscribe_conference(struct sipe_core_private *sipe_private, NULL); } +/** + * code for presence subscription + */ +static void sipe_subscribe_presence_buddy(struct sipe_core_private *sipe_private, + const gchar *uri, + const gchar *request, + const gchar *body) +{ + gchar *key = sipe_utils_presence_key(uri); + + sip_transport_subscribe(sipe_private, + uri, + request, + body, + sipe_subscribe_dialog(sipe_private, key), + process_subscribe_response); + g_free(key); +} /** * Single Category SUBSCRIBE [MS-PRES] ; To send when the server returns a 200 OK message with state="resubscribe" in response. -- 2.11.4.GIT