<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16535">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">func_channel: Add CHANNEL_EXISTS function.<br><br>Adds a function to check for the existence of a channel by<br>name or by UNIQUEID.<br><br>ASTERISK-29656 #close<br><br>Change-Id: Ib464e9eb6e13dc683a846286798fecff4fd943cb<br>---<br>A doc/CHANGES-staging/func_channel.txt<br>M funcs/func_channel.c<br>2 files changed, 42 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/func_channel.txt b/doc/CHANGES-staging/func_channel.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..7f92c3e</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/func_channel.txt</span><br><span>@@ -0,0 +1,4 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: func_channel</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Adds the CHANNEL_EXISTS function to check for the existence</span><br><span style="color: hsl(120, 100%, 40%);">+of a channel by name or unique ID.</span><br><span>diff --git a/funcs/func_channel.c b/funcs/func_channel.c</span><br><span>index d143fdc..312806d 100644</span><br><span>--- a/funcs/func_channel.c</span><br><span>+++ b/funcs/func_channel.c</span><br><span>@@ -20,6 +20,7 @@</span><br><span> *</span><br><span> * \author Kevin P. Fleming <kpfleming@digium.com></span><br><span> * \author Ben Winslow</span><br><span style="color: hsl(120, 100%, 40%);">+ * \author Naveen Albert <asterisk@phreaknet.org></span><br><span> *</span><br><span> * \ingroup functions</span><br><span> */</span><br><span>@@ -62,6 +63,19 @@</span><br><span> will be space-delimited.</para></span><br><span> </description></span><br><span> </function></span><br><span style="color: hsl(120, 100%, 40%);">+ <function name="CHANNEL_EXISTS" language="en_US"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ Checks if the specified channel exists.</span><br><span style="color: hsl(120, 100%, 40%);">+ </synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ <syntax></span><br><span style="color: hsl(120, 100%, 40%);">+ <parameter name="name_or_uid" required="true"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>The name or unique ID of the channel to check.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </parameter></span><br><span style="color: hsl(120, 100%, 40%);">+ </syntax></span><br><span style="color: hsl(120, 100%, 40%);">+ <description></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>Returns 1 if the channel <replaceable>name_or_uid</replaceable> exists, 0 if not.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </description></span><br><span style="color: hsl(120, 100%, 40%);">+ </function></span><br><span> <function name="MASTER_CHANNEL" language="en_US"></span><br><span> <synopsis></span><br><span> Gets or sets variables on the master channel</span><br><span>@@ -711,6 +725,28 @@</span><br><span> .read = func_channels_read,</span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static int func_chan_exists_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t maxlen)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_channel *chan_found = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(data)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "%s: Channel name or unique ID required\n", function);</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ chan_found = ast_channel_get_by_name(data);</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(buf, maxlen, "%d", (chan_found ? 1 : 0));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (chan_found) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unref(chan_found);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_custom_function chan_exists_function = {</span><br><span style="color: hsl(120, 100%, 40%);">+ .name = "CHANNEL_EXISTS",</span><br><span style="color: hsl(120, 100%, 40%);">+ .read = func_chan_exists_read,</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int func_mchan_read(struct ast_channel *chan, const char *function,</span><br><span> char *data, struct ast_str **buf, ssize_t len)</span><br><span> {</span><br><span>@@ -761,6 +797,7 @@</span><br><span> </span><br><span> res |= ast_custom_function_unregister(&channel_function);</span><br><span> res |= ast_custom_function_unregister(&channels_function);</span><br><span style="color: hsl(120, 100%, 40%);">+ res |= ast_custom_function_unregister(&chan_exists_function);</span><br><span> res |= ast_custom_function_unregister(&mchan_function);</span><br><span> </span><br><span> return res;</span><br><span>@@ -772,6 +809,7 @@</span><br><span> </span><br><span> res |= ast_custom_function_register(&channel_function);</span><br><span> res |= ast_custom_function_register(&channels_function);</span><br><span style="color: hsl(120, 100%, 40%);">+ res |= ast_custom_function_register(&chan_exists_function);</span><br><span> res |= ast_custom_function_register(&mchan_function);</span><br><span> </span><br><span> return res;</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16535">change 16535</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/16535"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 19 </div>
<div style="display:none"> Gerrit-Change-Id: Ib464e9eb6e13dc683a846286798fecff4fd943cb </div>
<div style="display:none"> Gerrit-Change-Number: 16535 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>