summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2018-01-10 06:55:10 -0600
committerGerrit Code Review <gerrit2@gerrit.digium.api>2018-01-10 06:55:10 -0600
commit7f2d6f51ed2b73c05fc5d0b5ff06120af3e2f430 (patch)
tree6cca9d58c3c6f312c3505fb4e2b87bc06ffe8279
parenta1eb5b06a8c5b426f237698a5dca93210cc28716 (diff)
parenta8a2f39f048c06773eb3e97703d8b8bdcd3e91bd (diff)
Merge "res_pjsip_endpoint_identifier_ip.c: Allow multiple IdentifyDetail AMI events." into 13
-rw-r--r--res/res_pjsip_endpoint_identifier_ip.c57
1 files changed, 32 insertions, 25 deletions
diff --git a/res/res_pjsip_endpoint_identifier_ip.c b/res/res_pjsip_endpoint_identifier_ip.c
index 5324af7b9..14f4cfd1a 100644
--- a/res/res_pjsip_endpoint_identifier_ip.c
+++ b/res/res_pjsip_endpoint_identifier_ip.c
@@ -484,47 +484,54 @@ static int sip_identify_to_ami(const struct ip_identify_match *identify,
return ast_sip_sorcery_object_to_ami(identify, buf);
}
-static int find_identify_by_endpoint(void *obj, void *arg, int flags)
+static int send_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;
+ /* 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;
+ struct ast_variable fields = {
+ .name = "endpoint",
+ .value = ast_sorcery_object_get_id(endpoint),
+ };
identifies = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "identify",
- AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
+ AST_RETRIEVE_FLAG_MULTIPLE, &fields);
if (!identifies) {
return -1;
}
- identify = ao2_callback(identifies, 0, find_identify_by_endpoint,
- (void *) ast_sorcery_object_get_id(endpoint));
- if (!identify) {
- return 1;
- }
-
- 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++;
+ /* Build and send any found identify object's AMI IdentifyDetail event. */
+ ao2_callback_data(identifies, OBJ_MULTIPLE | OBJ_NODATA,
+ send_identify_ami_event,
+ (void *) ast_sorcery_object_get_id(endpoint),
+ ami);
+ ao2_ref(identifies, -1);
return 0;
}