[asterisk-commits] mmichelson: branch mmichelson/rls-notify r417787 - /team/mmichelson/rls-notif...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 2 18:14:13 CDT 2014


Author: mmichelson
Date: Wed Jul  2 18:14:10 2014
New Revision: 417787

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=417787
Log:
Adjust the notifiers to comply with the new API.

Also fixed some warnings in res_pjsip_pubsub.c


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

Modified: team/mmichelson/rls-notify/res/res_pjsip_exten_state.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/rls-notify/res/res_pjsip_exten_state.c?view=diff&rev=417787&r1=417786&r2=417787
==============================================================================
--- team/mmichelson/rls-notify/res/res_pjsip_exten_state.c (original)
+++ team/mmichelson/rls-notify/res/res_pjsip_exten_state.c Wed Jul  2 18:14:10 2014
@@ -69,15 +69,16 @@
 
 static void subscription_shutdown(struct ast_sip_subscription *sub);
 static int new_subscribe(struct ast_sip_endpoint *endpoint, const char *resource);
-static int notify_required(struct ast_sip_subscription *sub,
-		enum ast_sip_subscription_notify_reason reason);
+static int subscription_established(struct ast_sip_subscription *sub);
+static void *get_notify_data(struct ast_sip_subscription *sub);
 static void to_ami(struct ast_sip_subscription *sub,
 		   struct ast_str **buf);
 
 struct ast_sip_notifier presence_notifier = {
 	.default_accept = DEFAULT_PRESENCE_BODY,
 	.new_subscribe = new_subscribe,
-	.notify_required = notify_required,
+	.subscription_established = subscription_established,
+	.get_notify_data = get_notify_data,
 };
 
 struct ast_sip_subscription_handler presence_handler = {
@@ -144,44 +145,6 @@
 	return exten_state_sub;
 }
 
-/*!
- * \internal
- * \brief Get device state information and send notification to the subscriber.
- */
-static void send_notify(struct exten_state_subscription *exten_state_sub)
-{
-	RAII_VAR(struct ao2_container*, info, NULL, ao2_cleanup);
-	char *subtype = NULL, *message = NULL;
-	struct ast_sip_exten_state_data exten_state_data = {
-		.exten = exten_state_sub->exten,
-		.presence_state = ast_hint_presence_state(NULL, exten_state_sub->context,
-							  exten_state_sub->exten, &subtype, &message),
-		.presence_subtype = subtype,
-		.presence_message = message,
-		.user_agent = exten_state_sub->user_agent
-	};
-
-	ast_sip_subscription_get_local_uri(exten_state_sub->sip_sub,
-			exten_state_data.local, sizeof(exten_state_data.local));
-	ast_sip_subscription_get_remote_uri(exten_state_sub->sip_sub,
-			exten_state_data.remote, sizeof(exten_state_data.remote));
-
-	if ((exten_state_data.exten_state = ast_extension_state_extended(
-		     NULL, exten_state_sub->context, exten_state_sub->exten, &info)) < 0) {
-
-		ast_log(LOG_WARNING, "Unable to get device hint/info for extension %s\n",
-			exten_state_sub->exten);
-		return;
-	}
-
-	exten_state_data.pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(),
-			"exten_state", 1024, 1024);
-
-	exten_state_data.device_state_info = info;
-	ast_sip_subscription_notify(exten_state_sub->sip_sub, &exten_state_data, 0);
-	pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), exten_state_data.pool);
-}
-
 struct notify_task_data {
 	struct ast_sip_exten_state_data exten_state_data;
 	struct exten_state_subscription *exten_state_sub;
@@ -354,7 +317,7 @@
 	return 200;
 }
 
-static int initial_subscribe(struct ast_sip_subscription *sip_sub)
+static int subscription_established(struct ast_sip_subscription *sip_sub)
 {
 	struct ast_sip_endpoint *endpoint = ast_sip_subscription_get_endpoint(sip_sub);
 	const char *resource = ast_sip_subscription_get_resource_name(sip_sub);
@@ -391,33 +354,69 @@
 		return -1;
 	}
 
-	send_notify(exten_state_sub);
 	ao2_cleanup(exten_state_sub);
 	return 0;
 }
 
-static int notify_required(struct ast_sip_subscription *sub,
-		enum ast_sip_subscription_notify_reason reason)
+static void exten_state_data_destructor(void *obj)
+{
+	struct ast_sip_exten_state_data *exten_state_data = obj;
+
+	ao2_cleanup(exten_state_data->device_state_info);
+	ast_free(exten_state_data->presence_subtype);
+	ast_free(exten_state_data->presence_message);
+	if (exten_state_data->pool) {
+		pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), exten_state_data->pool);
+	}
+}
+
+static struct ast_sip_exten_state_data *alloc_exten_state_data(struct ast_sip_subscription *sip_sub,
+		struct exten_state_subscription *exten_state_sub)
+{
+	struct ast_sip_exten_state_data *exten_state_data;
+	struct ao2_container *info;
+	char *subtype = NULL;
+	char *message = NULL;
+
+	exten_state_data = ao2_alloc(sizeof(*exten_state_data), exten_state_data_destructor);
+	if (!exten_state_data) {
+		return NULL;
+	}
+
+	exten_state_data->exten = exten_state_sub->exten;
+	exten_state_data->presence_state = ast_hint_presence_state(NULL, exten_state_sub->context,
+			exten_state_sub->exten, &subtype, &message);
+	exten_state_data->presence_subtype = subtype;
+	exten_state_data->presence_message = message;
+	exten_state_data->user_agent = exten_state_sub->user_agent;
+	ast_sip_subscription_get_local_uri(sip_sub, exten_state_data->local,
+			sizeof(exten_state_data->local));
+	ast_sip_subscription_get_remote_uri(sip_sub, exten_state_data->remote,
+			sizeof(exten_state_data->remote));
+
+	if ((exten_state_data->exten_state = ast_extension_state_extended(
+		     NULL, exten_state_sub->context, exten_state_sub->exten, &info)) < 0) {
+		ao2_cleanup(exten_state_data);
+		return NULL;
+	}
+
+	exten_state_data->pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(),
+			"exten_state", 1024, 1024);
+
+	exten_state_data->device_state_info = info;
+	return exten_state_data;
+}
+
+static void *get_notify_data(struct ast_sip_subscription *sub)
 {
 	struct exten_state_subscription *exten_state_sub;
 
-	switch (reason) {
-	case AST_SIP_SUBSCRIPTION_NOTIFY_REASON_STARTED:
-		return initial_subscribe(sub);
-	case AST_SIP_SUBSCRIPTION_NOTIFY_REASON_RENEWED:
-	case AST_SIP_SUBSCRIPTION_NOTIFY_REASON_TERMINATED:
-	case AST_SIP_SUBSCRIPTION_NOTIFY_REASON_OTHER:
-		exten_state_sub = get_exten_state_sub(sub);
-
-		if (!exten_state_sub) {
-			return -1;
-		}
-
-		send_notify(exten_state_sub);
-		break;
-	}
-
-	return 0;
+	exten_state_sub = get_exten_state_sub(sub);
+	if (!exten_state_sub) {
+		return NULL;
+	}
+
+	return alloc_exten_state_data(sub, exten_state_sub);
 }
 
 static void to_ami(struct ast_sip_subscription *sub,

Modified: team/mmichelson/rls-notify/res/res_pjsip_mwi.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/rls-notify/res/res_pjsip_mwi.c?view=diff&rev=417787&r1=417786&r2=417787
==============================================================================
--- team/mmichelson/rls-notify/res/res_pjsip_mwi.c (original)
+++ team/mmichelson/rls-notify/res/res_pjsip_mwi.c Wed Jul  2 18:14:10 2014
@@ -52,13 +52,14 @@
 static void mwi_to_ami(struct ast_sip_subscription *sub, struct ast_str **buf);
 static int mwi_new_subscribe(struct ast_sip_endpoint *endpoint,
 		const char *resource);
-static int mwi_notify_required(struct ast_sip_subscription *sip_sub,
-		enum ast_sip_subscription_notify_reason reason);
+static int mwi_subscription_established(struct ast_sip_subscription *sub);
+static void *mwi_get_notify_data(struct ast_sip_subscription *sub);
 
 static struct ast_sip_notifier mwi_notifier = {
 	.default_accept = MWI_TYPE"/"MWI_SUBTYPE,
 	.new_subscribe = mwi_new_subscribe,
-	.notify_required = mwi_notify_required,
+	.subscription_established = mwi_subscription_established,
+	.get_notify_data = mwi_get_notify_data,
 };
 
 static struct ast_sip_subscription_handler mwi_handler = {
@@ -676,7 +677,7 @@
 	return 200;
 }
 
-static int mwi_initial_subscription(struct ast_sip_subscription *sip_sub)
+static int mwi_subscription_established(struct ast_sip_subscription *sip_sub)
 {
 	const char *resource = ast_sip_subscription_get_resource_name(sip_sub);
 	struct mwi_subscription *sub;
@@ -694,39 +695,33 @@
 		return -1;
 	}
 
-	send_mwi_notify(sub);
-
 	ao2_cleanup(sub);
 	ao2_cleanup(endpoint);
 	return 0;
-}
-
-static int mwi_notify_required(struct ast_sip_subscription *sip_sub,
-		enum ast_sip_subscription_notify_reason reason)
-{
+
+}
+
+static void *mwi_get_notify_data(struct ast_sip_subscription *sub)
+{
+	struct ast_sip_message_accumulator *counter;
 	struct mwi_subscription *mwi_sub;
 	struct ast_datastore *mwi_datastore;
 
-	switch (reason) {
-	case AST_SIP_SUBSCRIPTION_NOTIFY_REASON_STARTED:
-		return mwi_initial_subscription(sip_sub);
-	case AST_SIP_SUBSCRIPTION_NOTIFY_REASON_RENEWED:
-	case AST_SIP_SUBSCRIPTION_NOTIFY_REASON_TERMINATED:
-	case AST_SIP_SUBSCRIPTION_NOTIFY_REASON_OTHER:
-		mwi_datastore = ast_sip_subscription_get_datastore(sip_sub, "MWI datastore");
-
-		if (!mwi_datastore) {
-			return -1;
-		}
-
-		mwi_sub = mwi_datastore->data;
-
-		send_mwi_notify(mwi_sub);
+	mwi_datastore = ast_sip_subscription_get_datastore(sub, "MWI datastore");
+	if (!mwi_datastore) {
+		return NULL;
+	}
+	mwi_sub = mwi_datastore->data;
+
+	counter = ao2_alloc(sizeof(*counter), NULL);
+	if (!counter) {
 		ao2_cleanup(mwi_datastore);
-		break;
-	}
-
-	return 0;
+		return NULL;
+	}
+
+	ao2_callback(mwi_sub->stasis_subs, OBJ_NODATA, get_message_count, counter);
+	ao2_cleanup(mwi_datastore);
+	return counter;
 }
 
 static void mwi_subscription_mailboxes_str(struct ao2_container *stasis_subs,

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=417787&r1=417786&r2=417787
==============================================================================
--- team/mmichelson/rls-notify/res/res_pjsip_pubsub.c (original)
+++ team/mmichelson/rls-notify/res/res_pjsip_pubsub.c Wed Jul  2 18:14:10 2014
@@ -1467,6 +1467,8 @@
 		pjsip_tx_data_dec_ref(tdata);
 		return -1;
 	}
+	
+	return 0;
 }
 
 static int generate_list_body(struct ast_sip_subscription *sub)
@@ -1822,7 +1824,6 @@
 
 static int generate_initial_notify(struct ast_sip_subscription *sub)
 {
-	int i;
 	struct ast_sip_subscription *child;
 	void *notify_data;
 	int res;




More information about the asterisk-commits mailing list