[asterisk-commits] mmichelson: branch mmichelson/subscription_abstraction r416646 - in /team/mmi...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jun 18 13:56:38 CDT 2014
Author: mmichelson
Date: Wed Jun 18 13:56:33 2014
New Revision: 416646
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=416646
Log:
Implement proper notifier-side termination logic.
Modified:
team/mmichelson/subscription_abstraction/include/asterisk/res_pjsip_pubsub.h
team/mmichelson/subscription_abstraction/res/res_pjsip_exten_state.c
team/mmichelson/subscription_abstraction/res/res_pjsip_mwi.c
team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c
Modified: team/mmichelson/subscription_abstraction/include/asterisk/res_pjsip_pubsub.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/subscription_abstraction/include/asterisk/res_pjsip_pubsub.h?view=diff&rev=416646&r1=416645&r2=416646
==============================================================================
--- team/mmichelson/subscription_abstraction/include/asterisk/res_pjsip_pubsub.h (original)
+++ team/mmichelson/subscription_abstraction/include/asterisk/res_pjsip_pubsub.h Wed Jun 18 13:56:33 2014
@@ -333,19 +333,17 @@
*
* \param sub The subscription on which a state change is occurring.
* \param notify_data Event package-specific data used to create the NOTIFY body.
+ * \param terminate True if this NOTIFY is intended to terminate the subscription.
* \retval 0 Success
* \retval non-zero Failure
*/
-int ast_sip_subscription_notify(struct ast_sip_subscription *sub, void *notify_data);
+int ast_sip_subscription_notify(struct ast_sip_subscription *sub, void *notify_data, int terminate);
/*! Retrieve the local URI for this subscription */
void ast_sip_subscription_get_local_uri(struct ast_sip_subscription *sub, char *buf, size_t size);
/*! Retrive the remote URI for this subscription */
void ast_sip_subscription_get_remote_uri(struct ast_sip_subscription *sub, char *buf, size_t size);
-
-/*! Terminate an active SIP subscription. */
-void ast_sip_subscription_terminate(struct ast_sip_subscription *sub);
const char *ast_sip_subscription_get_resource_name(struct ast_sip_subscription *sub);
Modified: team/mmichelson/subscription_abstraction/res/res_pjsip_exten_state.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/subscription_abstraction/res/res_pjsip_exten_state.c?view=diff&rev=416646&r1=416645&r2=416646
==============================================================================
--- team/mmichelson/subscription_abstraction/res/res_pjsip_exten_state.c (original)
+++ team/mmichelson/subscription_abstraction/res/res_pjsip_exten_state.c Wed Jun 18 13:56:33 2014
@@ -178,13 +178,14 @@
"exten_state", 1024, 1024);
exten_state_data.device_state_info = info;
- ast_sip_subscription_notify(exten_state_sub->sip_sub, &exten_state_data);
+ 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;
+ int terminate;
};
static void notify_task_data_destructor(void *obj)
@@ -199,7 +200,7 @@
}
static struct notify_task_data *alloc_notify_task_data(char *exten, struct exten_state_subscription *exten_state_sub,
- struct ast_state_cb_info *info)
+ struct ast_state_cb_info *info, int terminate)
{
struct notify_task_data *task_data =
ao2_alloc(sizeof(*task_data), notify_task_data_destructor);
@@ -209,6 +210,7 @@
return NULL;
}
+ task_data->terminate = terminate;
task_data->exten_state_sub = exten_state_sub;
task_data->exten_state_sub->last_exten_state = info->exten_state;
task_data->exten_state_sub->last_presence_state = info->presence_state;
@@ -248,7 +250,8 @@
task_data->exten_state_data.pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(),
"exten_state", 1024, 1024);
- ast_sip_subscription_notify(task_data->exten_state_sub->sip_sub, &task_data->exten_state_data);
+ ast_sip_subscription_notify(task_data->exten_state_sub->sip_sub, &task_data->exten_state_data,
+ task_data->terminate);
pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(),
task_data->exten_state_data.pool);
@@ -267,7 +270,7 @@
struct notify_task_data *task_data;
struct exten_state_subscription *exten_state_sub = data;
- if (!(task_data = alloc_notify_task_data(exten, exten_state_sub, info))) {
+ if (!(task_data = alloc_notify_task_data(exten, exten_state_sub, info, 0))) {
return -1;
}
@@ -284,7 +287,35 @@
static void state_changed_destroy(int id, void *data)
{
struct exten_state_subscription *exten_state_sub = data;
- ao2_cleanup(exten_state_sub);
+ struct ast_state_cb_info info = { 0, };
+ struct notify_task_data *task_data;
+ char *subtype;
+ char *message;
+
+ info.exten_state = ast_extension_state_extended(NULL, exten_state_sub->context,
+ exten_state_sub->exten, &info.device_state_info);
+ info.presence_state = ast_hint_presence_state(NULL, exten_state_sub->context,
+ exten_state_sub->exten, &subtype, &message);
+ info.presence_subtype = subtype;
+ info.presence_message = message;
+
+ task_data = alloc_notify_task_data(exten_state_sub->exten, exten_state_sub, &info, 1);
+ if (!task_data) {
+ goto cleanup;
+ }
+
+ if (ast_sip_push_task(ast_sip_subscription_get_serializer(task_data->exten_state_sub->sip_sub),
+ notify_task, task_data)) {
+ goto cleanup;
+ }
+
+ return;
+
+cleanup:
+ ao2_cleanup(task_data);
+ ao2_cleanup(info.device_state_info);
+ ast_free(subtype);
+ ast_free(message);
}
static struct ast_datastore_info ds_info = { };
Modified: team/mmichelson/subscription_abstraction/res/res_pjsip_mwi.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/subscription_abstraction/res/res_pjsip_mwi.c?view=diff&rev=416646&r1=416645&r2=416646
==============================================================================
--- team/mmichelson/subscription_abstraction/res/res_pjsip_mwi.c (original)
+++ team/mmichelson/subscription_abstraction/res/res_pjsip_mwi.c Wed Jun 18 13:56:33 2014
@@ -436,7 +436,7 @@
ao2_callback(sub->stasis_subs, OBJ_NODATA, get_message_count, &counter);
if (sub->is_solicited) {
- ast_sip_subscription_notify(sub->sip_sub, &counter);
+ ast_sip_subscription_notify(sub->sip_sub, &counter, 0);
return;
}
Modified: team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c?view=diff&rev=416646&r1=416645&r2=416646
==============================================================================
--- team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c (original)
+++ team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c Wed Jun 18 13:56:33 2014
@@ -943,7 +943,8 @@
return res;
}
-int ast_sip_subscription_notify(struct ast_sip_subscription *sub, void *notify_data)
+int ast_sip_subscription_notify(struct ast_sip_subscription *sub, void *notify_data,
+ int terminate)
{
struct ast_sip_body body = {
.type = ast_sip_subscription_get_body_type(sub),
@@ -952,7 +953,7 @@
struct ast_str *body_text = ast_str_create(64);
pjsip_evsub *evsub = sip_subscription_get_evsub(sub);
pjsip_tx_data *tdata;
- pjsip_evsub_state state = pjsip_evsub_get_state(evsub);
+ pjsip_evsub_state state;
if (!body_text) {
return -1;
@@ -965,7 +966,12 @@
body.body_text = ast_str_buffer(body_text);
- state = state <= PJSIP_EVSUB_STATE_ACTIVE ? PJSIP_EVSUB_STATE_ACTIVE : PJSIP_EVSUB_STATE_TERMINATED;
+ 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;
+ }
ast_log_backtrace();
More information about the asterisk-commits
mailing list