[Asterisk-code-review] res pjsip: Add AMI action 'PJSIPShowAuths' (asterisk[master])

Joshua Colp asteriskteam at digium.com
Wed Jan 10 06:55:30 CST 2018


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/7808 )

Change subject: res_pjsip: Add AMI action 'PJSIPShowAuths'
......................................................................

res_pjsip: Add AMI action 'PJSIPShowAuths'

Add an AMI action which provides information on all
configured Auths.

ASTERISK-27547

Change-Id: I1a88a75b38a2b1dd9d1de6c0307b20a3f584c817
---
M CHANGES
M res/res_pjsip.c
M res/res_pjsip/config_auth.c
3 files changed, 128 insertions(+), 1 deletion(-)

Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Approved for Submit



diff --git a/CHANGES b/CHANGES
index abf121e..84344aa 100644
--- a/CHANGES
+++ b/CHANGES
@@ -48,6 +48,9 @@
  * A new AMI action, PJSIPShowAors, has been added which displays information
    about all configured PJSIP AORs.
 
+ * A new AMI action, PJSIPShowAuths, has been added which displays information
+   about all configured PJSIP Auths.
+
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 15.1.0 to Asterisk 15.2.0 ------------
 ------------------------------------------------------------------------------
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index c3deb98..65d69c3 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -2267,7 +2267,7 @@
 			</syntax>
 		</managerEventInstance>
 	</managerEvent>
-		<managerEvent language="en_US" name="AorList">
+	<managerEvent language="en_US" name="AorList">
 		<managerEventInstance class="EVENT_FLAG_COMMAND">
 			<synopsis>Provide details about an Address of Record (AoR) section.</synopsis>
 			<syntax>
@@ -2306,6 +2306,37 @@
 				</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="AuthList">
+		<managerEventInstance class="EVENT_FLAG_COMMAND">
+			<synopsis>Provide details about an Address of Record (Auth) section.</synopsis>
+			<syntax>
+				<parameter name="ObjectType">
+					<para>The object's type. This will always be 'auth'.</para>
+				</parameter>
+				<parameter name="ObjectName">
+					<para>The name of this object.</para>
+				</parameter>
+				<parameter name="Username">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='auth']/configOption[@name='username']/synopsis/node())"/></para>
+				</parameter>
+				<parameter name="Md5Cred">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='auth']/configOption[@name='md5_cred']/synopsis/node())"/></para>
+				</parameter>
+				<parameter name="Realm">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='auth']/configOption[@name='realm']/synopsis/node())"/></para>
+				</parameter>
+				<parameter name="AuthType">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='auth']/configOption[@name='auth_type']/synopsis/node())"/></para>
+				</parameter>
+				<parameter name="Password">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='auth']/configOption[@name='password']/synopsis/node())"/></para>
+				</parameter>
+				<parameter name="NonceLifetime">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='auth']/configOption[@name='nonce_lifetime']/synopsis/node())"/></para>
 				</parameter>
 			</syntax>
 		</managerEventInstance>
@@ -2496,6 +2527,32 @@
 			</managerEvent>
 		</responses>
 	</manager>
+	<manager name="PJSIPShowAuths" language="en_US">
+		<synopsis>
+			Lists PJSIP Auths.
+		</synopsis>
+		<syntax />
+		<description>
+			<para>Provides a listing of all Auths. For each Auth an <literal>AuthList</literal> event
+			is raised that contains relevant attributes and status information.  Once all
+			auths have been listed an <literal>AuthListComplete</literal> event is issued.
+			</para>
+		</description>
+		<responses>
+			<list-elements>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='AuthList'])" />
+			</list-elements>
+			<managerEvent language="en_US" name="AuthListComplete">
+				<managerEventInstance class="EVENT_FLAG_COMMAND">
+					<synopsis>Provide final information about an auth list.</synopsis>
+					<syntax>
+						<parameter name="EventList"/>
+						<parameter name="ListItems"/>
+					</syntax>
+				</managerEventInstance>
+			</managerEvent>
+		</responses>
+	</manager>
 
  ***/
 
diff --git a/res/res_pjsip/config_auth.c b/res/res_pjsip/config_auth.c
index 9160e67..4732681 100644
--- a/res/res_pjsip/config_auth.c
+++ b/res/res_pjsip/config_auth.c
@@ -195,6 +195,67 @@
 	.format_ami = format_ami_endpoint_auth
 };
 
+static struct ao2_container *cli_get_auths(void)
+{
+	struct ao2_container *auths;
+
+	auths = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "auth",
+			AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
+
+	return auths;
+}
+
+static int format_ami_authlist_handler(void *obj, void *arg, int flags)
+{
+	struct ast_sip_auth *auth = obj;
+	struct ast_sip_ami *ami = arg;
+	struct ast_str *buf;
+
+	buf = ast_sip_create_ami_event("AuthList", ami);
+	if (!buf) {
+		return CMP_STOP;
+	}
+
+	sip_auth_to_ami(auth, &buf);
+
+	astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
+	ami->count++;
+
+	ast_free(buf);
+
+	return 0;
+}
+
+static int ami_show_auths(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 *auths;
+
+	auths = cli_get_auths();
+	if (!auths) {
+		astman_send_error(s, m, "Could not get Auths\n");
+		return 0;
+	}
+
+	if (!ao2_container_count(auths)) {
+		astman_send_error(s, m, "No Auths found\n");
+		ao2_ref(auths, -1);
+		return 0;
+	}
+
+	astman_send_listack(s, m, "A listing of Auths follows, presented as AuthList events",
+			"start");
+
+	ao2_callback(auths, OBJ_NODATA, format_ami_authlist_handler, &ami);
+
+	astman_send_list_complete_start(s, m, "AuthListComplete", ami.count);
+	astman_send_list_complete_end(s);
+
+	ao2_ref(auths, -1);
+
+	return 0;
+}
+
 static struct ao2_container *cli_get_container(const char *regex)
 {
 	RAII_VAR(struct ao2_container *, container, NULL, ao2_cleanup);
@@ -331,6 +392,10 @@
 	ast_sip_register_cli_formatter(cli_formatter);
 	ast_cli_register_multiple(cli_commands, ARRAY_LEN(cli_commands));
 
+	if (ast_manager_register_xml("PJSIPShowAuths", EVENT_FLAG_SYSTEM, ami_show_auths)) {
+		return -1;
+	}
+
 	return 0;
 }
 
@@ -340,5 +405,7 @@
 	ast_sip_unregister_cli_formatter(cli_formatter);
 	internal_sip_unregister_endpoint_formatter(&endpoint_auth_formatter);
 
+	ast_manager_unregister("PJSIPShowAuths");
+
 	return 0;
 }

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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I1a88a75b38a2b1dd9d1de6c0307b20a3f584c817
Gerrit-Change-Number: 7808
Gerrit-PatchSet: 3
Gerrit-Owner: sungtae kim <pchero21 at gmail.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: sungtae kim <pchero21 at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180110/61f5a32d/attachment.html>


More information about the asterisk-code-review mailing list