mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-11 12:28:27 +00:00
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
This commit is contained in:
@@ -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);
|
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;
|
struct ip_identify_match *identify = obj;
|
||||||
const char *endpoint_name = arg;
|
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,
|
static int format_ami_endpoint_identify(const struct ast_sip_endpoint *endpoint,
|
||||||
struct ast_sip_ami *ami)
|
struct ast_sip_ami *ami)
|
||||||
{
|
{
|
||||||
RAII_VAR(struct ao2_container *, identifies, NULL, ao2_cleanup);
|
struct ao2_container *identifies;
|
||||||
RAII_VAR(struct ip_identify_match *, identify, NULL, ao2_cleanup);
|
struct ast_variable fields = {
|
||||||
RAII_VAR(struct ast_str *, buf, NULL, ast_free);
|
.name = "endpoint",
|
||||||
|
.value = ast_sorcery_object_get_id(endpoint),
|
||||||
|
};
|
||||||
|
|
||||||
identifies = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "identify",
|
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) {
|
if (!identifies) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
identify = ao2_callback(identifies, 0, find_identify_by_endpoint,
|
/* Build and send any found identify object's AMI IdentifyDetail event. */
|
||||||
(void *) ast_sorcery_object_get_id(endpoint));
|
ao2_callback_data(identifies, OBJ_MULTIPLE | OBJ_NODATA,
|
||||||
if (!identify) {
|
send_identify_ami_event,
|
||||||
return 1;
|
(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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user