summaryrefslogtreecommitdiff
path: root/res/res_pjsip
diff options
context:
space:
mode:
authorSungtae Kim <pchero21@gmail.com>2017-12-30 06:14:00 +0100
committerJoshua Colp <jcolp@digium.com>2018-01-02 12:24:38 +0000
commitffbf5be116a3035f0ecf97bd13d87bfd64048fb0 (patch)
tree40657a581294ee38b307eb14e9741ad10857cb10 /res/res_pjsip
parent80e6b2eff54a4ff57e2521164224b1b1c878ae94 (diff)
res_pjsip: Add AMI action 'PJSIPShowAors'
Add an AMI action which provides information on all configured AORs. ASTERISK-27537 Change-Id: If8b990a00909e5b6c0f04a3b8dccd9903dc445eb
Diffstat (limited to 'res/res_pjsip')
-rw-r--r--res/res_pjsip/location.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c
index 7483a5b25..eb9e58870 100644
--- a/res/res_pjsip/location.c
+++ b/res/res_pjsip/location.c
@@ -1179,6 +1179,67 @@ static int cli_aor_print_body(void *obj, void *arg, int flags)
return 0;
}
+static struct ao2_container *cli_get_aors(void)
+{
+ struct ao2_container *aors;
+
+ aors = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "aor",
+ AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
+
+ return aors;
+}
+
+static int format_ami_aorlist_handler(void *obj, void *arg, int flags)
+{
+ struct ast_sip_aor *aor = obj;
+ struct ast_sip_ami *ami = arg;
+ struct ast_str *buf;
+
+ buf = ast_sip_create_ami_event("AorList", ami);
+ if (!buf) {
+ return -1;
+ }
+
+ sip_aor_to_ami(aor, &buf);
+
+ astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
+ ami->count++;
+
+ ast_free(buf);
+
+ return 0;
+}
+
+static int ami_show_aors(struct mansession *s, const struct message *m)
+{
+ struct ast_sip_ami ami = { .s = s, .m = m, .action_id = astman_get_header(m, "ActionID"), };
+ struct ao2_container *aors;
+
+ aors = cli_get_aors();
+ if (!aors) {
+ astman_send_error(s, m, "Could not get AORs\n");
+ return 0;
+ }
+
+ if (!ao2_container_count(aors)) {
+ astman_send_error(s, m, "No AORs found\n");
+ ao2_ref(aors, -1);
+ return 0;
+ }
+
+ astman_send_listack(s, m, "A listing of AORs follows, presented as AorList events",
+ "start");
+
+ ao2_callback(aors, OBJ_NODATA, format_ami_aorlist_handler, &ami);
+
+ astman_send_list_complete_start(s, m, "AorListComplete", ami.count);
+ astman_send_list_complete_end(s);
+
+ ao2_ref(aors, -1);
+
+ return 0;
+}
+
static struct ast_cli_entry cli_commands[] = {
AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "List PJSIP Aors",
.command = "pjsip list aors",
@@ -1317,6 +1378,10 @@ int ast_sip_initialize_sorcery_location(void)
ast_sip_register_cli_formatter(aor_formatter);
ast_cli_register_multiple(cli_commands, ARRAY_LEN(cli_commands));
+ if (ast_manager_register_xml("PJSIPShowAors", EVENT_FLAG_SYSTEM, ami_show_aors)) {
+ return -1;
+ }
+
/*
* Reset StatsD gauges in case we didn't shut down cleanly.
* Note that this must done here, as contacts will create the contact_status
@@ -1335,6 +1400,7 @@ int ast_sip_destroy_sorcery_location(void)
ast_cli_unregister_multiple(cli_commands, ARRAY_LEN(cli_commands));
ast_sip_unregister_cli_formatter(contact_formatter);
ast_sip_unregister_cli_formatter(aor_formatter);
+ ast_manager_unregister("PJSIPShowAors");
internal_sip_unregister_endpoint_formatter(&endpoint_aor_formatter);