[Asterisk-code-review] func_channel: Add CHANNEL_EXISTS function (asterisk[master])

N A asteriskteam at digium.com
Wed Sep 15 13:22:17 CDT 2021


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/16486 )


Change subject: func_channel: Add CHANNEL_EXISTS function
......................................................................

func_channel: Add CHANNEL_EXISTS function

Adds a function to check for the existence of a full channel name.

ASTERISK-29656 #close

Change-Id: Ib464e9eb6e13dc683a846286798fecff4fd943cb
---
A doc/CHANGES-staging/func_channel.txt
M funcs/func_channel.c
2 files changed, 30 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/86/16486/1

diff --git a/doc/CHANGES-staging/func_channel.txt b/doc/CHANGES-staging/func_channel.txt
new file mode 100644
index 0000000..1c5df0f
--- /dev/null
+++ b/doc/CHANGES-staging/func_channel.txt
@@ -0,0 +1,4 @@
+Subject: func_channel
+
+Adds the CHANNEL_EXISTS function to check for the existence
+of a named channel.
diff --git a/funcs/func_channel.c b/funcs/func_channel.c
index d143fdc..0e4c33c 100644
--- a/funcs/func_channel.c
+++ b/funcs/func_channel.c
@@ -20,6 +20,7 @@
  *
  * \author Kevin P. Fleming <kpfleming at digium.com>
  * \author Ben Winslow
+ * \author Naveen Albert <asterisk at phreaknet.org>
  *
  * \ingroup functions
  */
@@ -62,6 +63,18 @@
 			will be space-delimited.</para>
 		</description>
 	</function>
+	<function name="CHANNEL_EXISTS" language="en_US">
+		<synopsis>
+			Checks if the specified channel name exists.
+		</synopsis>
+		<syntax>
+			<parameter name="channel_name" />
+		</syntax>
+		<description>
+			<para>Returns whether or not <replaceable>channel_name</replaceable> is a currently existing channel.
+			<replaceable>channel_name</replaceable> must be a full channel name, not simply a tech/device.</para>
+		</description>
+	</function>
 	<function name="MASTER_CHANNEL" language="en_US">
 		<synopsis>
 			Gets or sets variables on the master channel
@@ -711,6 +724,17 @@
 	.read = func_channels_read,
 };
 
+static int func_chan_exists_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t maxlen)
+{
+	snprintf(buf, maxlen, "%d", (ast_channel_get_by_name(data) ? 1 : 0));
+	return 0;
+}
+
+static struct ast_custom_function chan_exists_function = {
+	.name = "CHANNEL_EXISTS",
+	.read = func_chan_exists_read,
+};
+
 static int func_mchan_read(struct ast_channel *chan, const char *function,
 			     char *data, struct ast_str **buf, ssize_t len)
 {
@@ -761,6 +785,7 @@
 
 	res |= ast_custom_function_unregister(&channel_function);
 	res |= ast_custom_function_unregister(&channels_function);
+	res |= ast_custom_function_unregister(&chan_exists_function);
 	res |= ast_custom_function_unregister(&mchan_function);
 
 	return res;
@@ -772,6 +797,7 @@
 
 	res |= ast_custom_function_register(&channel_function);
 	res |= ast_custom_function_register(&channels_function);
+	res |= ast_custom_function_register(&chan_exists_function);
 	res |= ast_custom_function_register(&mchan_function);
 
 	return res;

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/16486
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Ib464e9eb6e13dc683a846286798fecff4fd943cb
Gerrit-Change-Number: 16486
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210915/e0dc9130/attachment.html>


More information about the asterisk-code-review mailing list