From e089779908a08f29b16e8b70c080fd2338b92d3b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= <a@rodrigoramirez.com>
Date: Tue, 3 Mar 2020 14:42:16 +0000
Subject: [PATCH] res_rtp_asterisk: Add 'rtp show settings' cli command

This change introduce a CLI command for the RTP to display the general
configuration.

In the first step add the follow fields of the configurations:
  - rtpstart
  - rtpend
  - dtmftimeout
  - rtpchecksum
  - strictrtp
  - learning_min_sequential
  - icesupport

Change-Id: Ibe5450898e2c3e1ed68c10993aa1ac6bf09b821f
---
 .../res_rtp_asterisk_show_settings_cli.txt    |  7 ++++
 res/res_rtp_asterisk.c                        | 37 +++++++++++++++++++
 2 files changed, 44 insertions(+)
 create mode 100644 doc/CHANGES-staging/res_rtp_asterisk_show_settings_cli.txt

diff --git a/doc/CHANGES-staging/res_rtp_asterisk_show_settings_cli.txt b/doc/CHANGES-staging/res_rtp_asterisk_show_settings_cli.txt
new file mode 100644
index 0000000000..4f636bbe42
--- /dev/null
+++ b/doc/CHANGES-staging/res_rtp_asterisk_show_settings_cli.txt
@@ -0,0 +1,7 @@
+Subject: res_rtp_asterisk
+
+This change include a new cli command 'rtp show settings'
+
+The command display by general settings of rtp configuration. For this
+point is added the fields: rtpstart, rtpend, dtmftimeout, rtpchecksum,
+strictrtp, learning_min_sequential and icesupport.
diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index 969fc2d628..b49b2e30e1 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -8652,6 +8652,42 @@ static char *handle_cli_rtp_set_debug(struct ast_cli_entry *e, int cmd, struct a
 	return CLI_SHOWUSAGE;   /* default, failure */
 }
 
+
+static char *handle_cli_rtp_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "rtp show settings";
+		e->usage =
+			"Usage: rtp show settings\n"
+			"       Display RTP configuration settings\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	if (a->argc != 3) {
+		return CLI_SHOWUSAGE;
+	}
+
+	ast_cli(a->fd, "\n\nGeneral Settings:\n");
+	ast_cli(a->fd, "----------------\n");
+	ast_cli(a->fd, "  Port start:      %d\n", rtpstart);
+	ast_cli(a->fd, "  Port end:        %d\n", rtpend);
+	ast_cli(a->fd, "  Checksums:       %s\n", AST_CLI_YESNO(nochecksums == 0));
+	ast_cli(a->fd, "  DTMF Timeout:    %d\n", dtmftimeout);
+	ast_cli(a->fd, "  Strict RTP:      %s\n", AST_CLI_YESNO(strictrtp));
+
+	if (strictrtp) {
+		ast_cli(a->fd, "  Probation:       %d frames\n", learning_min_sequential);
+	}
+
+	ast_cli(a->fd, "  ICE support:     %s\n", AST_CLI_YESNO(icesupport));
+
+	return CLI_SUCCESS;
+}
+
+
 static char *handle_cli_rtcp_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	switch (cmd) {
@@ -8714,6 +8750,7 @@ static char *handle_cli_rtcp_set_stats(struct ast_cli_entry *e, int cmd, struct
 
 static struct ast_cli_entry cli_rtp[] = {
 	AST_CLI_DEFINE(handle_cli_rtp_set_debug,  "Enable/Disable RTP debugging"),
+	AST_CLI_DEFINE(handle_cli_rtp_settings,   "Display RTP settings"),
 	AST_CLI_DEFINE(handle_cli_rtcp_set_debug, "Enable/Disable RTCP debugging"),
 	AST_CLI_DEFINE(handle_cli_rtcp_set_stats, "Enable/Disable RTCP stats"),
 };
-- 
GitLab