[Asterisk-code-review] Added AMI action PJSIPShowAors (asterisk[master])

sungtae kim asteriskteam at digium.com
Fri Dec 29 23:17:23 CST 2017


sungtae kim has uploaded this change for review. ( https://gerrit.asterisk.org/7771


Change subject: Added AMI action PJSIPShowAors
......................................................................

Added AMI action PJSIPShowAors

- #27537
- Added AMI action, PJSIPShowAors.
- It return all of aors info.

Change-Id: If8b990a00909e5b6c0f04a3b8dccd9903dc445eb
---
M res/res_pjsip.c
M res/res_pjsip/location.c
2 files changed, 136 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/71/7771/1

diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index c08e15b..cdcfa6e 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -2267,6 +2267,49 @@
 			</syntax>
 		</managerEventInstance>
 	</managerEvent>
+		<managerEvent language="en_US" name="AorList">
+		<managerEventInstance class="EVENT_FLAG_COMMAND">
+			<synopsis>Provide details about an Address of Record (AoR) section.</synopsis>
+			<syntax>
+				<parameter name="ObjectType">
+					<para>The object's type. This will always be 'aor'.</para>
+				</parameter>
+				<parameter name="ObjectName">
+					<para>The name of this object.</para>
+				</parameter>
+				<parameter name="MinimumExpiration">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='minimum_expiration']/synopsis/node())"/></para>
+				</parameter>
+				<parameter name="MaximumExpiration">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='maximum_expiration']/synopsis/node())"/></para>
+				</parameter>
+				<parameter name="DefaultExpiration">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='default_expiration']/synopsis/node())"/></para>
+				</parameter>
+				<parameter name="QualifyFrequency">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='qualify_frequency']/synopsis/node())"/></para>
+				</parameter>
+				<parameter name="AuthenticateQualify">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='authenticate_qualify']/synopsis/node())"/></para>
+				</parameter>
+				<parameter name="MaxContacts">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='max_contacts']/synopsis/node())"/></para>
+				</parameter>
+				<parameter name="RemoveExisting">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='remove_existing']/synopsis/node())"/></para>
+				</parameter>
+				<parameter name="Mailboxes">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='mailboxes']/synopsis/node())"/></para>
+				</parameter>
+				<parameter name="OutboundProxy">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='outbound_proxy']/synopsis/node())"/></para>
+				</parameter>
+				<parameter name="SupportPath">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='support_path']/synopsis/node())"/></para>
+				</parameter>
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
 	<managerEvent language="en_US" name="ContactStatusDetail">
 		<managerEventInstance class="EVENT_FLAG_COMMAND">
 			<synopsis>Provide details about a contact's status.</synopsis>
@@ -2426,6 +2469,34 @@
 			</managerEvent>
 		</responses>
 	</manager>
+	<manager name="PJSIPShowAors" language="en_US">
+		<synopsis>
+			Lists PJSIP aors.
+		</synopsis>
+		<syntax />
+		<description>
+			<para>
+			Provides a listing of all aors. For each aor an <literal>AorList</literal> event
+			is raised that contains relevant attributes and status information.  Once all
+			aors have been listed an <literal>AorListComplete</literal> event is issued.
+			</para>
+		</description>
+		<responses>
+			<list-elements>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='AorList'])" />
+			</list-elements>
+			<managerEvent language="en_US" name="AorListComplete">
+				<managerEventInstance class="EVENT_FLAG_COMMAND">
+					<synopsis>Provide final information about an aor list.</synopsis>
+					<syntax>
+						<parameter name="EventList"/>
+						<parameter name="ListItems"/>
+					</syntax>
+				</managerEventInstance>
+			</managerEvent>
+		</responses>
+	</manager>
+
  ***/
 
 #define MOD_DATA_CONTACT "contact"
diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c
index 7483a5b..04cfe6c 100644
--- a/res/res_pjsip/location.c
+++ b/res/res_pjsip/location.c
@@ -1179,6 +1179,67 @@
 	return 0;
 }
 
+static struct ao2_container *ast_sip_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;
+	int total_contacts;
+	int num_permanent;
+
+	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"), };
+	RAII_VAR(struct ao2_container *, aors, NULL, ao2_cleanup);
+	int num;
+
+	aors = ast_sip_get_aors();
+	if (!aors) {
+		astman_send_error(s, m, "Could not get aors\n");
+		return 0;
+	}
+
+	if (!(num = ao2_container_count(aors))) {
+		astman_send_error(s, m, "No aors found\n");
+		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);
+
+	return 0;
+}
+
 static struct ast_cli_entry cli_commands[] = {
 	AST_CLI_DEFINE(ast_sip_cli_traverse_objects, "List PJSIP Aors",
 		.command = "pjsip list aors",
@@ -1237,6 +1298,10 @@
 	struct ast_sorcery *sorcery = ast_sip_get_sorcery();
 	int i;
 
+	if (ast_manager_register_xml("PJSIPShowAors", EVENT_FLAG_SYSTEM, ami_show_aors)) {
+		return -1;
+	}
+
 	ast_pjproject_get_buildopt("PJ_MAX_HOSTNAME", "%d", &pj_max_hostname);
 	/* As of pjproject 2.4.5, PJSIP_MAX_URL_SIZE isn't exposed yet but we try anyway. */
 	ast_pjproject_get_buildopt("PJSIP_MAX_URL_SIZE", "%d", &pjsip_max_url_size);

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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: If8b990a00909e5b6c0f04a3b8dccd9903dc445eb
Gerrit-Change-Number: 7771
Gerrit-PatchSet: 1
Gerrit-Owner: sungtae kim <pchero21 at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171229/2af458ec/attachment.html>


More information about the asterisk-code-review mailing list