[Asterisk-code-review] func_channel: Adds TECH_EXISTS function. (asterisk[master])

N A asteriskteam at digium.com
Sat Feb 19 13:24:01 CST 2022


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


Change subject: func_channel: Adds TECH_EXISTS function.
......................................................................

func_channel: Adds TECH_EXISTS function.

Adds a TECH_EXISTS function which can be used to check
if a particular channel technology is available for use
on the system.

ASTERISK-29926 #close

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



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/63/18063/1

diff --git a/doc/CHANGES-staging/func_channel_tech.txt b/doc/CHANGES-staging/func_channel_tech.txt
new file mode 100644
index 0000000..7673581
--- /dev/null
+++ b/doc/CHANGES-staging/func_channel_tech.txt
@@ -0,0 +1,5 @@
+Subject: func_channel
+
+A TECH_EXISTS function now allows users to check
+whether a particular channel technology is available
+for use.
diff --git a/funcs/func_channel.c b/funcs/func_channel.c
index c6e5ec1..dc49f87 100644
--- a/funcs/func_channel.c
+++ b/funcs/func_channel.c
@@ -63,6 +63,19 @@
 			will be space-delimited.</para>
 		</description>
 	</function>
+	<function name="TECH_EXISTS" language="en_US">
+		<synopsis>
+			Checks if the specified channel technology exists and is usable.
+		</synopsis>
+		<syntax>
+			<parameter name="tech" required="true">
+				<para>The name of the channel technology (e.g. DAHDI, PJSIP, IAX2, etc.).</para>
+			</parameter>
+		</syntax>
+		<description>
+			<para>Returns 1 if the channel technology <replaceable>tech</replaceable> exists, 0 if not.</para>
+		</description>
+	</function>
 	<function name="CHANNEL_EXISTS" language="en_US">
 		<synopsis>
 			Checks if the specified channel exists.
@@ -760,6 +773,21 @@
 	.read = func_channels_read,
 };
 
+static int func_tech_exists_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t maxlen)
+{
+	if (ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "%s: Channel tech required\n", function);
+		return -1;
+	}
+	snprintf(buf, maxlen, "%d", (ast_get_channel_tech(data) ? 1 : 0));
+	return 0;
+}
+
+static struct ast_custom_function tech_exists_function = {
+	.name = "TECH_EXISTS",
+	.read = func_tech_exists_read,
+};
+
 static int func_chan_exists_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t maxlen)
 {
 	struct ast_channel *chan_found = NULL;
@@ -833,6 +861,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(&tech_exists_function);
 	res |= ast_custom_function_unregister(&mchan_function);
 
 	return res;
@@ -845,6 +874,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(&tech_exists_function);
 	res |= ast_custom_function_register(&mchan_function);
 
 	return res;

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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Idf110464ed69a757b3e0c9d0e8d95d4d24559b46
Gerrit-Change-Number: 18063
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/20220219/5abed0f9/attachment.html>


More information about the asterisk-code-review mailing list