[Asterisk-code-review] res pjsip endpoint identifier ip.c: Allow multiple IdentifyD... (asterisk[master])

Richard Mudgett asteriskteam at digium.com
Fri Jan 5 18:14:23 CST 2018


Richard Mudgett has uploaded this change for review. ( https://gerrit.asterisk.org/7849


Change subject: res_pjsip_endpoint_identifier_ip.c: Allow multiple IdentifyDetail AMI events.
......................................................................

res_pjsip_endpoint_identifier_ip.c: Allow multiple IdentifyDetail AMI events.

The AMI PJSIPShowEndpoint action could only list one IdentifyDetail AMI
event per endpoint.  However, there is no reason that multiple
type=identify sections cannot identify the same endpoint.

* Reworked format_ami_endpoint_identify() to generate as many
IdentifyDetail AMI events as there are matching identifiers.

Change-Id: Ie146792aef72d78e05416ab5b27bc552a30399db
---
M res/res_pjsip_endpoint_identifier_ip.c
1 file changed, 32 insertions(+), 24 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/49/7849/1

diff --git a/res/res_pjsip_endpoint_identifier_ip.c b/res/res_pjsip_endpoint_identifier_ip.c
index 8b92cef..8495777 100644
--- a/res/res_pjsip_endpoint_identifier_ip.c
+++ b/res/res_pjsip_endpoint_identifier_ip.c
@@ -457,20 +457,41 @@
 	return ast_sip_sorcery_object_to_ami(identify, buf);
 }
 
-static int find_identify_by_endpoint(void *obj, void *arg, int flags)
+static int send_matching_identify_ami_event(void *obj, void *arg, void *data, int flags)
 {
 	struct ip_identify_match *identify = obj;
 	const char *endpoint_name = arg;
+	struct ast_sip_ami *ami = data;
+	struct ast_str *buf;
 
-	return strcmp(identify->endpoint_name, endpoint_name) ? 0 : CMP_MATCH;
+	if (strcmp(identify->endpoint_name, endpoint_name)) {
+		/* The identify object doesn't match the desired endpoint. */
+		return 0;
+	}
+
+	/* Build AMI event */
+	buf = ast_sip_create_ami_event("IdentifyDetail", ami);
+	if (!buf) {
+		return CMP_STOP;
+	}
+	if (sip_identify_to_ami(identify, &buf)) {
+		ast_free(buf);
+		return CMP_STOP;
+	}
+	ast_str_append(&buf, 0, "EndpointName: %s\r\n", endpoint_name);
+
+	/* Send AMI event */
+	astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
+	++ami->count;
+
+	ast_free(buf);
+	return 0;
 }
 
 static int format_ami_endpoint_identify(const struct ast_sip_endpoint *endpoint,
 					struct ast_sip_ami *ami)
 {
-	RAII_VAR(struct ao2_container *, identifies, NULL, ao2_cleanup);
-	RAII_VAR(struct ip_identify_match *, identify, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_str *, buf, NULL, ast_free);
+	struct ao2_container *identifies;
 
 	identifies = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "identify",
 		AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
@@ -478,26 +499,13 @@
 		return -1;
 	}
 
-	identify = ao2_callback(identifies, 0, find_identify_by_endpoint,
-		(void *) ast_sorcery_object_get_id(endpoint));
-	if (!identify) {
-		return 1;
-	}
+	/* Build and send any matching identify object AMI events. */
+	ao2_callback_data(identifies, OBJ_MULTIPLE | OBJ_NODATA,
+		send_matching_identify_ami_event,
+		(void *) ast_sorcery_object_get_id(endpoint),
+		ami);
 
-	if (!(buf = ast_sip_create_ami_event("IdentifyDetail", ami))) {
-		return -1;
-	}
-
-	if (sip_identify_to_ami(identify, &buf)) {
-		return -1;
-	}
-
-	ast_str_append(&buf, 0, "EndpointName: %s\r\n",
-		ast_sorcery_object_get_id(endpoint));
-
-	astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
-	ami->count++;
-
+	ao2_ref(identifies, -1);
 	return 0;
 }
 

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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie146792aef72d78e05416ab5b27bc552a30399db
Gerrit-Change-Number: 7849
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180105/c97dc6e8/attachment-0001.html>


More information about the asterisk-code-review mailing list