[Asterisk-code-review] res pjsip pubsub.c: Fix AMI event list counts. (asterisk[13])

Richard Mudgett asteriskteam at digium.com
Fri Jan 20 12:39:13 CST 2017


Richard Mudgett has uploaded a new change for review. ( https://gerrit.asterisk.org/4742 )

Change subject: res_pjsip_pubsub.c: Fix AMI event list counts.
......................................................................

res_pjsip_pubsub.c: Fix AMI event list counts.

Fix the AMI PJSIPShowSubscriptionsInbound, PJSIPShowSubscriptionsOutbound,
and PJSIPShowResourceLists actions event counts.  The reported counts may
not necessarily be accurate depending on what happens.

The subscriptions count would be wrong if Asterisk ever has outbound
subscriptions.

The resource list count could be wrong if a list were added or removed
during the AMI action being processed.

Change-Id: I4344301827523fa174960a42c413fd19abe4aed5
---
M res/res_pjsip_pubsub.c
1 file changed, 16 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/42/4742/1

diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c
index f6b6efc..87b1658 100644
--- a/res/res_pjsip_pubsub.c
+++ b/res/res_pjsip_pubsub.c
@@ -3646,6 +3646,8 @@
 	sip_subscription_to_ami(sub_tree, &buf);
 	astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
 	ast_free(buf);
+
+	++ami->count;
 	return 0;
 }
 
@@ -3664,14 +3666,13 @@
 static int ami_show_subscriptions_inbound(struct mansession *s, const struct message *m)
 {
 	struct ast_sip_ami ami = { .s = s, .m = m, .action_id = astman_get_header(m, "ActionID"), };
-	int num;
 
-	astman_send_listack(s, m, "Following are Events for "
-			    "each inbound Subscription", "start");
+	astman_send_listack(s, m, "Following are Events for each inbound Subscription",
+		"start");
 
-	num = for_each_subscription(ami_subscription_detail_inbound, &ami);
+	for_each_subscription(ami_subscription_detail_inbound, &ami);
 
-	astman_send_list_complete_start(s, m, "InboundSubscriptionDetailComplete", num);
+	astman_send_list_complete_start(s, m, "InboundSubscriptionDetailComplete", ami.count);
 	astman_send_list_complete_end(s);
 	return 0;
 }
@@ -3679,14 +3680,13 @@
 static int ami_show_subscriptions_outbound(struct mansession *s, const struct message *m)
 {
 	struct ast_sip_ami ami = { .s = s, .m = m, .action_id = astman_get_header(m, "ActionID"), };
-	int num;
 
-	astman_send_listack(s, m, "Following are Events for "
-			    "each outbound Subscription", "start");
+	astman_send_listack(s, m, "Following are Events for each outbound Subscription",
+		"start");
 
-	num = for_each_subscription(ami_subscription_detail_outbound, &ami);
+	for_each_subscription(ami_subscription_detail_outbound, &ami);
 
-	astman_send_list_complete_start(s, m, "OutboundSubscriptionDetailComplete", num);
+	astman_send_list_complete_start(s, m, "OutboundSubscriptionDetailComplete", ami.count);
 	astman_send_list_complete_end(s);
 	return 0;
 }
@@ -3707,31 +3707,31 @@
 		return CMP_STOP;
 	}
 	astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
-
 	ast_free(buf);
+
+	++ami->count;
 	return 0;
 }
 
 static int ami_show_resource_lists(struct mansession *s, const struct message *m)
 {
 	struct ast_sip_ami ami = { .s = s, .m = m, .action_id = astman_get_header(m, "ActionID"), };
-	int num;
 	struct ao2_container *lists;
 
 	lists = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "resource_list",
 			AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
 
-	if (!lists || !(num = ao2_container_count(lists))) {
+	if (!lists || !ao2_container_count(lists)) {
 		astman_send_error(s, m, "No resource lists found\n");
 		return 0;
 	}
 
-	astman_send_listack(s, m, "A listing of resource lists follows, "
-			    "presented as ResourceListDetail events", "start");
+	astman_send_listack(s, m, "A listing of resource lists follows, presented as ResourceListDetail events",
+		"start");
 
 	ao2_callback(lists, OBJ_NODATA, format_ami_resource_lists, &ami);
 
-	astman_send_list_complete_start(s, m, "ResourceListDetailComplete", num);
+	astman_send_list_complete_start(s, m, "ResourceListDetailComplete", ami.count);
 	astman_send_list_complete_end(s);
 	return 0;
 }

-- 
To view, visit https://gerrit.asterisk.org/4742
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4344301827523fa174960a42c413fd19abe4aed5
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>



More information about the asterisk-code-review mailing list