20
20
*
21
21
* \author Kevin P. Fleming <kpfleming@digium.com>
22
22
* \author Ben Winslow
23
+ * \author Naveen Albert <asterisk@phreaknet.org>
23
24
*
24
25
* \ingroup functions
25
26
*/
62
63
will be space-delimited.</para>
63
64
</description>
64
65
</function>
66
+ <function name="CHANNEL_EXISTS" language="en_US">
67
+ <synopsis>
68
+ Checks if the specified channel exists.
69
+ </synopsis>
70
+ <syntax>
71
+ <parameter name="name_or_uid" required="true">
72
+ <para>The name or unique ID of the channel to check.</para>
73
+ </parameter>
74
+ </syntax>
75
+ <description>
76
+ <para>Returns 1 if the channel <replaceable>name_or_uid</replaceable> exists, 0 if not.</para>
77
+ </description>
78
+ </function>
65
79
<function name="MASTER_CHANNEL" language="en_US">
66
80
<synopsis>
67
81
Gets or sets variables on the master channel
@@ -711,6 +725,28 @@ static struct ast_custom_function channels_function = {
711
725
.read = func_channels_read ,
712
726
};
713
727
728
+ static int func_chan_exists_read (struct ast_channel * chan , const char * function , char * data , char * buf , size_t maxlen )
729
+ {
730
+ struct ast_channel * chan_found = NULL ;
731
+
732
+ if (ast_strlen_zero (data )) {
733
+ ast_log (LOG_WARNING , "%s: Channel name or unique ID required\n" , function );
734
+ return -1 ;
735
+ }
736
+
737
+ chan_found = ast_channel_get_by_name (data );
738
+ snprintf (buf , maxlen , "%d" , (chan_found ? 1 : 0 ));
739
+ if (chan_found ) {
740
+ ast_channel_unref (chan_found );
741
+ }
742
+ return 0 ;
743
+ }
744
+
745
+ static struct ast_custom_function chan_exists_function = {
746
+ .name = "CHANNEL_EXISTS" ,
747
+ .read = func_chan_exists_read ,
748
+ };
749
+
714
750
static int func_mchan_read (struct ast_channel * chan , const char * function ,
715
751
char * data , struct ast_str * * buf , ssize_t len )
716
752
{
@@ -761,6 +797,7 @@ static int unload_module(void)
761
797
762
798
res |= ast_custom_function_unregister (& channel_function );
763
799
res |= ast_custom_function_unregister (& channels_function );
800
+ res |= ast_custom_function_unregister (& chan_exists_function );
764
801
res |= ast_custom_function_unregister (& mchan_function );
765
802
766
803
return res ;
@@ -772,6 +809,7 @@ static int load_module(void)
772
809
773
810
res |= ast_custom_function_register (& channel_function );
774
811
res |= ast_custom_function_register (& channels_function );
812
+ res |= ast_custom_function_register (& chan_exists_function );
775
813
res |= ast_custom_function_register (& mchan_function );
776
814
777
815
return res ;
0 commit comments