Setup environment variables for the benefit of child processes and disallow changing...
[asterisk/asterisk.git] / funcs / func_channel.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2006, Digium, Inc.
5  *
6  * See http://www.asterisk.org for more information about
7  * the Asterisk project. Please do not directly contact
8  * any of the maintainers of this project for assistance;
9  * the project provides a web site, mailing lists and IRC
10  * channels for your use.
11  *
12  * This program is free software, distributed under the terms of
13  * the GNU General Public License Version 2. See the LICENSE file
14  * at the top of the source tree.
15  */
16
17 /*! \file
18  *
19  * \brief Channel info dialplan functions
20  *
21  * \author Kevin P. Fleming <kpfleming@digium.com>
22  * \author Ben Winslow
23  * 
24  * \ingroup functions
25  */
26
27 #include "asterisk.h"
28
29 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
30
31 #include <regex.h>
32 #include <ctype.h>
33
34 #include "asterisk/module.h"
35 #include "asterisk/channel.h"
36 #include "asterisk/pbx.h"
37 #include "asterisk/utils.h"
38 #include "asterisk/app.h"
39 #include "asterisk/indications.h"
40 #include "asterisk/stringfields.h"
41
42 /*** DOCUMENTATION
43         <function name="CHANNELS" language="en_US">
44                 <synopsis>
45                         Gets the list of channels, optionally filtering by a regular expression.
46                 </synopsis>
47                 <syntax>
48                         <parameter name="regular_expression" />
49                 </syntax>
50                 <description>
51                         <para>Gets the list of channels, optionally filtering by a <replaceable>regular_expression</replaceable>. If
52                         no argument is provided, all known channels are returned. The
53                         <replaceable>regular_expression</replaceable> must correspond to
54                         the POSIX.2 specification, as shown in <emphasis>regex(7)</emphasis>. The list returned
55                         will be space-delimited.</para>
56                 </description>
57         </function>
58         <function name="MASTER_CHANNEL" language="en_US">
59                 <synopsis>
60                         Gets or sets variables on the master channel
61                 </synopsis>
62                 <description>
63                         <para>Allows access to the channel which created the current channel, if any.  If the channel is already
64                         a master channel, then accesses local channel variables.</para>
65                 </description>
66         </function>
67         <function name="CHANNEL" language="en_US">
68                 <synopsis>
69                         Gets/sets various pieces of information about the channel.
70                 </synopsis>
71                 <syntax>
72                         <parameter name="item" required="true">
73                                 <para>Standard items (provided by all channel technologies) are:</para>
74                                 <enumlist>
75                                         <enum name="audioreadformat">
76                                                 <para>R/O format currently being read.</para>
77                                         </enum>
78                                         <enum name="audionativeformat">
79                                                 <para>R/O format used natively for audio.</para>
80                                         </enum>
81                                         <enum name="audiowriteformat">
82                                                 <para>R/O format currently being written.</para>
83                                         </enum>
84                                         <enum name="callgroup">
85                                                 <para>R/W call groups for call pickup.</para>
86                                         </enum>
87                                         <enum name="channeltype">
88                                                 <para>R/O technology used for channel.</para>
89                                         </enum>
90                                         <enum name="language">
91                                                 <para>R/W language for sounds played.</para>
92                                         </enum>
93                                         <enum name="musicclass">
94                                                 <para>R/W class (from musiconhold.conf) for hold music.</para>
95                                         </enum>
96                                         <enum name="name">
97                                                 <para>The name of the channel</para>
98                                         </enum>
99                                         <enum name="parkinglot">
100                                                 <para>R/W parkinglot for parking.</para>
101                                         </enum>
102                                         <enum name="rxgain">
103                                                 <para>R/W set rxgain level on channel drivers that support it.</para>
104                                         </enum>
105                                         <enum name="state">
106                                                 <para>R/O state for channel</para>
107                                         </enum>
108                                         <enum name="tonezone">
109                                                 <para>R/W zone for indications played</para>
110                                         </enum>
111                                         <enum name="transfercapability">
112                                                 <para>R/W ISDN Transfer Capability, one of:</para>
113                                                 <enumlist>
114                                                         <enum name="SPEECH" />
115                                                         <enum name="DIGITAL" />
116                                                         <enum name="RESTRICTED_DIGITAL" />
117                                                         <enum name="3K1AUDIO" />
118                                                         <enum name="DIGITAL_W_TONES" />
119                                                         <enum name="VIDEO" />
120                                                 </enumlist>
121                                         </enum>
122                                         <enum name="txgain">
123                                                 <para>R/W set txgain level on channel drivers that support it.</para>
124                                         </enum>
125                                         <enum name="videonativeformat">
126                                                 <para>R/O format used natively for video</para>
127                                         </enum>
128                                         <enum name="trace">
129                                                 <para>R/W whether or not context tracing is enabled, only available
130                                                 <emphasis>if CHANNEL_TRACE is defined</emphasis>.</para>
131                                         </enum>
132                                 </enumlist>
133                                 <para><emphasis>chan_sip</emphasis> provides the following additional options:</para>
134                                 <enumlist>
135                                         <enum name="peerip">
136                                                 <para>R/O Get the IP address of the peer.</para>
137                                         </enum>
138                                         <enum name="recvip">
139                                                 <para>R/O Get the source IP address of the peer.</para>
140                                         </enum>
141                                         <enum name="from">
142                                                 <para>R/O Get the URI from the From: header.</para>
143                                         </enum>
144                                         <enum name="uri">
145                                                 <para>R/O Get the URI from the Contact: header.</para>
146                                         </enum>
147                                         <enum name="useragent">
148                                                 <para>R/O Get the useragent.</para>
149                                         </enum>
150                                         <enum name="peername">
151                                                 <para>R/O Get the name of the peer.</para>
152                                         </enum>
153                                         <enum name="t38passthrough">
154                                                 <para>R/O <literal>1</literal> if T38 is offered or enabled in this channel,
155                                                 otherwise <literal>0</literal></para>
156                                         </enum>
157                                         <enum name="rtpqos">
158                                                 <para>R/O Get QOS information about the RTP stream</para>
159                                                 <para>    This option takes two additional arguments:</para>
160                                                 <para>    Argument 1:</para>
161                                                 <para>     <literal>audio</literal>             Get data about the audio stream</para>
162                                                 <para>     <literal>video</literal>             Get data about the video stream</para>
163                                                 <para>     <literal>text</literal>              Get data about the text stream</para>
164                                                 <para>    Argument 2:</para>
165                                                 <para>     <literal>local_ssrc</literal>        Local SSRC (stream ID)</para>
166                                                 <para>     <literal>local_lostpackets</literal> Local lost packets</para>
167                                                 <para>     <literal>local_jitter</literal>      Local calculated jitter</para>
168                                                 <para>     <literal>local_maxjitter</literal>   Local calculated jitter (maximum)</para>
169                                                 <para>     <literal>local_minjitter</literal>   Local calculated jitter (minimum)</para>
170                                                 <para>     <literal>local_normdevjitter</literal>Local calculated jitter (normal deviation)</para>
171                                                 <para>     <literal>local_stdevjitter</literal> Local calculated jitter (standard deviation)</para>
172                                                 <para>     <literal>local_count</literal>       Number of received packets</para>
173                                                 <para>     <literal>remote_ssrc</literal>       Remote SSRC (stream ID)</para>
174                                                 <para>     <literal>remote_lostpackets</literal>Remote lost packets</para>
175                                                 <para>     <literal>remote_jitter</literal>     Remote reported jitter</para>
176                                                 <para>     <literal>remote_maxjitter</literal>  Remote calculated jitter (maximum)</para>
177                                                 <para>     <literal>remote_minjitter</literal>  Remote calculated jitter (minimum)</para>
178                                                 <para>     <literal>remote_normdevjitter</literal>Remote calculated jitter (normal deviation)</para>
179                                                 <para>     <literal>remote_stdevjitter</literal>Remote calculated jitter (standard deviation)</para>
180                                                 <para>     <literal>remote_count</literal>      Number of transmitted packets</para>
181                                                 <para>     <literal>remote_ssrc</literal>       Remote SSRC (stream ID)</para>
182                                                 <para>     <literal>remote_lostpackets</literal>Remote lost packets</para>
183                                                 <para>     <literal>remote_jitter</literal>     Remote reported jitter</para>
184                                                 <para>     <literal>remote_maxjitter</literal>  Remote calculated jitter (maximum)</para>
185                                                 <para>     <literal>remote_minjitter</literal>  Remote calculated jitter (minimum)</para>
186                                                 <para>     <literal>remote_normdevjitter</literal>Remote calculated jitter (normal deviation)</para>
187                                                 <para>     <literal>remote_stdevjitter</literal>Remote calculated jitter (standard deviation)</para>
188                                                 <para>     <literal>remote_count</literal>      Number of transmitted packets</para>
189                                                 <para>     <literal>rtt</literal>               Round trip time</para>
190                                                 <para>     <literal>maxrtt</literal>            Round trip time (maximum)</para>
191                                                 <para>     <literal>minrtt</literal>            Round trip time (minimum)</para>
192                                                 <para>     <literal>normdevrtt</literal>        Round trip time (normal deviation)</para>
193                                                 <para>     <literal>stdevrtt</literal>          Round trip time (standard deviation)</para>
194                                                 <para>     <literal>all</literal>               All statistics (in a form suited to logging,
195                                                 but not for parsing)</para>
196                                         </enum>
197                                         <enum name="rtpdest">
198                                                 <para>R/O Get remote RTP destination information.</para>
199                                                 <para>   This option takes one additional argument:</para>
200                                                 <para>    Argument 1:</para>
201                                                 <para>     <literal>audio</literal>             Get audio destination</para>
202                                                 <para>     <literal>video</literal>             Get video destination</para>
203                                                 <para>     <literal>text</literal>              Get text destination</para>
204                                         </enum>
205                                 </enumlist>
206                                 <para><emphasis>chan_iax2</emphasis> provides the following additional options:</para>
207                                 <enumlist>
208                                         <enum name="peerip">
209                                                 <para>R/O Get the peer's ip address.</para>
210                                         </enum>
211                                         <enum name="peername">
212                                                 <para>R/O Get the peer's username.</para>
213                                         </enum>
214                                 </enumlist>
215                                 <para><emphasis>chan_dahdi</emphasis> provides the following additional options:</para>
216                                 <enumlist>
217                                         <enum name="reversecharge">
218                                                 <para>R/O Reverse Charging Indication, one of:</para>
219                                                 <enumlist>
220                                                         <enum name="-1 - None" />
221                                                         <enum name="1 - Reverse Charging Requested" />
222                                                 </enumlist>
223                                         </enum>
224                                 </enumlist>
225                         </parameter>
226                 </syntax>
227                 <description>
228                         <para>Gets/sets various pieces of information about the channel, additional <replaceable>item</replaceable> may
229                         be available from the channel driver; see its documentation for details. Any <replaceable>item</replaceable>
230                         requested that is not available on the current channel will return an empty string.</para>
231                 </description>
232         </function>
233  ***/
234
235 #define locked_copy_string(chan, dest, source, len) \
236         do { \
237                 ast_channel_lock(chan); \
238                 ast_copy_string(dest, source, len); \
239                 ast_channel_unlock(chan); \
240         } while (0)
241 #define locked_string_field_set(chan, field, source) \
242         do { \
243                 ast_channel_lock(chan); \
244                 ast_string_field_set(chan, field, source); \
245                 ast_channel_unlock(chan); \
246         } while (0)
247
248 static const char * const transfercapability_table[0x20] = {
249         "SPEECH", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
250         "DIGITAL", "RESTRICTED_DIGITAL", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
251         "3K1AUDIO", "DIGITAL_W_TONES", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
252         "VIDEO", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", };
253
254 static int func_channel_read(struct ast_channel *chan, const char *function,
255                              char *data, char *buf, size_t len)
256 {
257         int ret = 0;
258
259         if (!strcasecmp(data, "audionativeformat"))
260                 /* use the _multiple version when chan->nativeformats holds multiple formats */
261                 /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_AUDIO_MASK); */
262                 ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_AUDIO_MASK), len);
263         else if (!strcasecmp(data, "videonativeformat"))
264                 /* use the _multiple version when chan->nativeformats holds multiple formats */
265                 /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_VIDEO_MASK); */
266                 ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_VIDEO_MASK), len);
267         else if (!strcasecmp(data, "audioreadformat"))
268                 ast_copy_string(buf, ast_getformatname(chan->readformat), len);
269         else if (!strcasecmp(data, "audiowriteformat"))
270                 ast_copy_string(buf, ast_getformatname(chan->writeformat), len);
271 #ifdef CHANNEL_TRACE
272         else if (!strcasecmp(data, "trace")) {
273                 ast_channel_lock(chan);
274                 ast_copy_string(buf, ast_channel_trace_is_enabled(chan) ? "1" : "0", len);
275                 ast_channel_unlock(chan);
276         }
277 #endif
278         else if (!strcasecmp(data, "tonezone") && chan->zone)
279                 locked_copy_string(chan, buf, chan->zone->country, len);
280         else if (!strcasecmp(data, "language"))
281                 locked_copy_string(chan, buf, chan->language, len);
282         else if (!strcasecmp(data, "musicclass"))
283                 locked_copy_string(chan, buf, chan->musicclass, len);
284         else if (!strcasecmp(data, "name")) {
285                 locked_copy_string(chan, buf, chan->name, len);
286         } else if (!strcasecmp(data, "parkinglot"))
287                 locked_copy_string(chan, buf, chan->parkinglot, len);
288         else if (!strcasecmp(data, "state"))
289                 locked_copy_string(chan, buf, ast_state2str(chan->_state), len);
290         else if (!strcasecmp(data, "channeltype"))
291                 locked_copy_string(chan, buf, chan->tech->type, len);
292         else if (!strcasecmp(data, "accountcode"))
293                 locked_copy_string(chan, buf, chan->accountcode, len);
294         else if (!strcasecmp(data, "peeraccount"))
295                 locked_copy_string(chan, buf, chan->peeraccount, len);
296         else if (!strcasecmp(data, "hangupsource"))
297                 locked_copy_string(chan, buf, chan->hangupsource, len);
298         else if (!strcasecmp(data, "appname") && chan->appl)
299                 locked_copy_string(chan, buf, chan->appl, len);
300         else if (!strcasecmp(data, "appdata") && chan->data)
301                 locked_copy_string(chan, buf, chan->data, len);
302         else if (!strcasecmp(data, "exten") && chan->data)
303                 locked_copy_string(chan, buf, chan->exten, len);
304         else if (!strcasecmp(data, "context") && chan->data)
305                 locked_copy_string(chan, buf, chan->context, len);
306         else if (!strcasecmp(data, "userfield") && chan->data)
307                 locked_copy_string(chan, buf, chan->userfield, len);
308         else if (!strcasecmp(data, "channame") && chan->data)
309                 locked_copy_string(chan, buf, chan->name, len);
310         else if (!strcasecmp(data, "linkedid")) {
311                 ast_channel_lock(chan);
312                 if (ast_strlen_zero(chan->linkedid)) {
313                         /* fall back on the channel's uniqueid if linkedid is unset */
314                         ast_copy_string(buf, chan->uniqueid, len);
315                 }
316                 else {
317                         ast_copy_string(buf, chan->linkedid, len);
318                 }
319                 ast_channel_unlock(chan);
320         } else if (!strcasecmp(data, "peer")) {
321                 struct ast_channel *p;
322                 ast_channel_lock(chan);
323                 p = ast_bridged_channel(chan);
324                 if (p || chan->tech || chan->cdr) /* dummy channel? if so, we hid the peer name in the language */
325                         ast_copy_string(buf, (p ? p->name : ""), len);
326                 else {
327                         /* a dummy channel can still pass along bridged peer info via
328                            the BRIDGEPEER variable */
329                         const char *pname = pbx_builtin_getvar_helper(chan, "BRIDGEPEER");
330                         if (!ast_strlen_zero(pname))
331                                 ast_copy_string(buf, pname, len); /* a horrible kludge, but... how else? */
332                         else
333                                 buf[0] = 0;
334                 }
335                 ast_channel_unlock(chan);
336         } else if (!strcasecmp(data, "uniqueid")) {
337                 locked_copy_string(chan, buf, chan->uniqueid, len);
338         } else if (!strcasecmp(data, "transfercapability"))
339                 locked_copy_string(chan, buf, transfercapability_table[chan->transfercapability & 0x1f], len);
340         else if (!strcasecmp(data, "callgroup")) {
341                 char groupbuf[256];
342                 locked_copy_string(chan, buf,  ast_print_group(groupbuf, sizeof(groupbuf), chan->callgroup), len);
343         } else if (!strcasecmp(data, "amaflags")) {
344                 char amabuf[256];
345                 snprintf(amabuf,sizeof(amabuf), "%d", chan->amaflags);
346                 locked_copy_string(chan, buf, amabuf, len);
347         } else if (!chan->tech || !chan->tech->func_channel_read || chan->tech->func_channel_read(chan, function, data, buf, len)) {
348                 ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data);
349                 ret = -1;
350         }
351
352         return ret;
353 }
354
355 static int func_channel_write(struct ast_channel *chan, const char *function,
356                               char *data, const char *value)
357 {
358         int ret = 0;
359         signed char gainset;
360
361         if (!strcasecmp(data, "language"))
362                 locked_string_field_set(chan, language, value);
363         else if (!strcasecmp(data, "parkinglot"))
364                 locked_string_field_set(chan, parkinglot, value);
365         else if (!strcasecmp(data, "musicclass"))
366                 locked_string_field_set(chan, musicclass, value);
367         else if (!strcasecmp(data, "accountcode"))
368                 locked_string_field_set(chan, accountcode, value);
369         else if (!strcasecmp(data, "userfield"))
370                 locked_string_field_set(chan, userfield, value);
371         else if (!strcasecmp(data, "amaflags")) {
372                 ast_channel_lock(chan);
373                 if(isdigit(*value)) {
374                         sscanf(value, "%30d", &chan->amaflags);
375                 } else if (!strcasecmp(value,"OMIT")){
376                         chan->amaflags = 1;
377                 } else if (!strcasecmp(value,"BILLING")){
378                         chan->amaflags = 2;
379                 } else if (!strcasecmp(value,"DOCUMENTATION")){
380                         chan->amaflags = 3;
381                 }
382                 ast_channel_unlock(chan);
383         } else if (!strcasecmp(data, "peeraccount"))
384                 locked_string_field_set(chan, peeraccount, value);
385         else if (!strcasecmp(data, "hangupsource"))
386                 /* XXX - should we be forcing this here? */
387                 ast_set_hangupsource(chan, value, 0);
388 #ifdef CHANNEL_TRACE
389         else if (!strcasecmp(data, "trace")) {
390                 ast_channel_lock(chan);
391                 if (ast_true(value)) 
392                         ret = ast_channel_trace_enable(chan);
393                 else if (ast_false(value))
394                         ret = ast_channel_trace_disable(chan);
395                 else {
396                         ret = -1;
397                         ast_log(LOG_WARNING, "Invalid value for CHANNEL(trace).");
398                 }
399                 ast_channel_unlock(chan);
400         }
401 #endif
402         else if (!strcasecmp(data, "tonezone")) {
403                 struct ast_tone_zone *new_zone;
404                 if (!(new_zone = ast_get_indication_zone(value))) {
405                         ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value);
406                         ret = -1;       
407                 } else {
408                         ast_channel_lock(chan);
409                         if (chan->zone) {
410                                 chan->zone = ast_tone_zone_unref(chan->zone);
411                         }
412                         chan->zone = ast_tone_zone_ref(new_zone);
413                         ast_channel_unlock(chan);
414                         new_zone = ast_tone_zone_unref(new_zone);
415                 }
416         } else if (!strcasecmp(data, "callgroup"))
417                 chan->callgroup = ast_get_group(value);
418         else if (!strcasecmp(data, "txgain")) {
419                 sscanf(value, "%4hhd", &gainset);
420                 ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0);
421         } else if (!strcasecmp(data, "rxgain")) {
422                 sscanf(value, "%4hhd", &gainset);
423                 ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0);
424         } else if (!strcasecmp(data, "transfercapability")) {
425                 unsigned short i;
426                 for (i = 0; i < 0x20; i++) {
427                         if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) {
428                                 chan->transfercapability = i;
429                                 break;
430                         }
431                 }
432         } else if (!chan->tech->func_channel_write
433                  || chan->tech->func_channel_write(chan, function, data, value)) {
434                 ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n",
435                                 data);
436                 ret = -1;
437         }
438
439         return ret;
440 }
441
442 static struct ast_custom_function channel_function = {
443         .name = "CHANNEL",
444         .read = func_channel_read,
445         .write = func_channel_write,
446 };
447
448 static int func_channels_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t maxlen)
449 {
450         struct ast_channel *c = NULL;
451         regex_t re;
452         int res;
453         size_t buflen = 0;
454         struct ast_channel_iterator *iter;
455
456         buf[0] = '\0';
457
458         if (!ast_strlen_zero(data)) {
459                 if ((res = regcomp(&re, data, REG_EXTENDED | REG_ICASE | REG_NOSUB))) {
460                         regerror(res, &re, buf, maxlen);
461                         ast_log(LOG_WARNING, "Error compiling regular expression for %s(%s): %s\n", function, data, buf);
462                         return -1;
463                 }
464         }
465
466         if (!(iter = ast_channel_iterator_all_new())) {
467                 if (!ast_strlen_zero(data)) {
468                         regfree(&re);
469                 }
470                 return -1;
471         }
472
473         while ((c = ast_channel_iterator_next(iter))) {
474                 ast_channel_lock(c);
475                 if (ast_strlen_zero(data) || regexec(&re, c->name, 0, NULL, 0) == 0) {
476                         size_t namelen = strlen(c->name);
477                         if (buflen + namelen + (ast_strlen_zero(buf) ? 0 : 1) + 1 < maxlen) {
478                                 if (!ast_strlen_zero(buf)) {
479                                         strcat(buf, " ");
480                                         buflen++;
481                                 }
482                                 strcat(buf, c->name);
483                                 buflen += namelen;
484                         } else {
485                                 ast_log(LOG_WARNING, "Number of channels exceeds the available buffer space.  Output will be truncated!\n");
486                         }
487                 }
488                 ast_channel_unlock(c);
489                 c = ast_channel_unref(c);
490         }
491
492         ast_channel_iterator_destroy(iter);
493
494         if (!ast_strlen_zero(data)) {
495                 regfree(&re);
496         }
497
498         return 0;
499 }
500
501 static struct ast_custom_function channels_function = {
502         .name = "CHANNELS",
503         .read = func_channels_read,
504 };
505
506 static int func_mchan_read(struct ast_channel *chan, const char *function,
507                              char *data, struct ast_str **buf, ssize_t len)
508 {
509         struct ast_channel *mchan = ast_channel_get_by_name(chan->linkedid);
510         char *template = alloca(4 + strlen(data));
511         sprintf(template, "${%s}", data); /* SAFE */
512         ast_str_substitute_variables(buf, len, mchan ? mchan : chan, template);
513         if (mchan) {
514                 ast_channel_unref(mchan);
515         }
516         return 0;
517 }
518
519 static int func_mchan_write(struct ast_channel *chan, const char *function,
520                               char *data, const char *value)
521 {
522         struct ast_channel *mchan = ast_channel_get_by_name(chan->linkedid);
523         pbx_builtin_setvar_helper(mchan ? mchan : chan, data, value);
524         if (mchan) {
525                 ast_channel_unref(mchan);
526         }
527         return 0;
528 }
529
530 static struct ast_custom_function mchan_function = {
531         .name = "MASTER_CHANNEL",
532         .read2 = func_mchan_read,
533         .write = func_mchan_write,
534 };
535
536 static int unload_module(void)
537 {
538         int res = 0;
539
540         res |= ast_custom_function_unregister(&channel_function);
541         res |= ast_custom_function_unregister(&channels_function);
542         res |= ast_custom_function_unregister(&mchan_function);
543
544         return res;
545 }
546
547 static int load_module(void)
548 {
549         int res = 0;
550
551         res |= ast_custom_function_register(&channel_function);
552         res |= ast_custom_function_register(&channels_function);
553         res |= ast_custom_function_register(&mchan_function);
554
555         return res;
556 }
557
558 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Channel information dialplan functions");