[svn-commits] mmichelson: branch mmichelson/rls-notify r418151 - /team/mmichelson/rls-notif...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Jul 7 15:32:50 CDT 2014


Author: mmichelson
Date: Mon Jul  7 15:32:48 2014
New Revision: 418151

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=418151
Log:
Change how subscription state is communicated.

Now subscription state is stored on each ast_sip_subscription.
This way, if individual subscriptions get terminated, the state
can be properly communicated in an RLMI body. When the subscription
is terminated by the subscriber, all subscriptions in the tree
are marked as terminated.


Modified:
    team/mmichelson/rls-notify/res/res_pjsip_pubsub.c

Modified: team/mmichelson/rls-notify/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/rls-notify/res/res_pjsip_pubsub.c?view=diff&rev=418151&r1=418150&r2=418151
==============================================================================
--- team/mmichelson/rls-notify/res/res_pjsip_pubsub.c (original)
+++ team/mmichelson/rls-notify/res/res_pjsip_pubsub.c Mon Jul  7 15:32:48 2014
@@ -436,6 +436,8 @@
 	struct ast_str *body_text;
 	/*! Indicator that the body text has changed since the last notification */
 	int body_changed;
+	/*! The current state of the subscription */
+	pjsip_evsub_state subscription_state;
 	/*! Name of resource being subscribed to */
 	char resource[0];
 };
@@ -1017,15 +1019,18 @@
 		ao2_ref(sub, -1);
 		return NULL;
 	}
+
 	sub->serializer = ast_sip_create_serializer();
 	if (!sub->serializer) {
 		ao2_ref(sub, -1);
 		return NULL;
 	}
+
 	sub->role = role;
 	sub->type = type;
 	sub->endpoint = ao2_bump(endpoint);
 	sub->handler = handler;
+	sub->subscription_state = PJSIP_EVSUB_STATE_ACTIVE;
 
 	return sub;
 }
@@ -1492,10 +1497,9 @@
 	return generate_list_body(root, body_text);
 }
 
-static int send_notify(struct ast_sip_subscription *sub, int terminate)
+static int send_notify(struct ast_sip_subscription *sub)
 {
 	pjsip_evsub *evsub = sip_subscription_get_evsub(sub);
-	pjsip_evsub_state state;
 	pjsip_tx_data *tdata;
 	struct ast_sip_body body = {
 		.type = ast_sip_subscription_get_body_type(sub),
@@ -1509,14 +1513,7 @@
 		return -1;
 	}
 
-	if (terminate) {
-		state = PJSIP_EVSUB_STATE_TERMINATED;
-	} else {
-		state = pjsip_evsub_get_state(evsub) <= PJSIP_EVSUB_STATE_ACTIVE ?
-			PJSIP_EVSUB_STATE_ACTIVE : PJSIP_EVSUB_STATE_TERMINATED;
-	}
-
-	if (pjsip_evsub_notify(evsub, state, NULL, NULL, &tdata) != PJ_SUCCESS) {
+	if (pjsip_evsub_notify(evsub, sub->subscription_state, NULL, NULL, &tdata) != PJ_SUCCESS) {
 		ast_free(body_text);
 		return -1;
 	}
@@ -1560,7 +1557,7 @@
 		return 0;
 	}
 
-	return send_notify(sub, 0);
+	return send_notify(sub);
 }
 
 static int sched_cb(const void *data)
@@ -1596,6 +1593,9 @@
 	}
 
 	sub->body_changed = 1;
+	if (terminate) {
+		sub->subscription_state = PJSIP_EVSUB_STATE_TERMINATED;
+	}
 
 	while (sub->type == SIP_SUBSCRIPTION_VIRTUAL) {
 		sub = sub->reality.virtual.parent;
@@ -1604,7 +1604,7 @@
 	if (sub->reality.real.notification_batch_interval) {
 		return schedule_notification(sub);
 	} else {
-		return send_notify(sub, terminate);
+		return send_notify(sub);
 	}
 }
 
@@ -2045,7 +2045,7 @@
 		if (generate_initial_notify(sub)) {
 			pjsip_evsub_terminate(sip_subscription_get_evsub(sub), PJ_TRUE);
 		}
-		send_notify(sub, 0);
+		send_notify(sub);
 	}
 
 	resource_tree_destroy(&tree);
@@ -2519,7 +2519,7 @@
 		reason = AST_SIP_SUBSCRIPTION_NOTIFY_REASON_RENEWED;
 	}
 
-	if (send_notify(sub, 0)) {
+	if (send_notify(sub)) {
 		*p_st_code = 500;
 	}
 
@@ -2567,11 +2567,23 @@
 	ast_sip_push_task(sub->serializer, serialized_pubsub_on_client_refresh, sub);
 }
 
+static void set_state_terminated(struct ast_sip_subscription *sub)
+{
+	struct ast_sip_subscription *iter;
+
+	sub->subscription_state = PJSIP_EVSUB_STATE_TERMINATED;
+	AST_LIST_TRAVERSE(&sub->children, iter, next) {
+		set_state_terminated(iter);
+	}
+}
+
 static int serialized_pubsub_on_server_timeout(void *userdata)
 {
 	struct ast_sip_subscription *sub = userdata;
 
-	send_notify(sub, 1);
+	set_state_terminated(sub);
+	send_notify(sub);
+
 	ao2_cleanup(sub);
 	return 0;
 }




More information about the svn-commits mailing list