func_channel: dtmf_features setting
[asterisk/asterisk.git] / funcs / func_channel.c
index bd3367d..4d098c3 100644 (file)
@@ -20,7 +20,7 @@
  *
  * \author Kevin P. Fleming <kpfleming@digium.com>
  * \author Ben Winslow
- * 
+ *
  * \ingroup functions
  */
 
@@ -37,12 +37,14 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/module.h"
 #include "asterisk/channel.h"
+#include "asterisk/bridging.h"
 #include "asterisk/pbx.h"
 #include "asterisk/utils.h"
 #include "asterisk/app.h"
 #include "asterisk/indications.h"
 #include "asterisk/stringfields.h"
 #include "asterisk/global_datastores.h"
+#include "asterisk/bridging_basic.h"
 
 /*** DOCUMENTATION
        <function name="CHANNELS" language="en_US">
@@ -77,6 +79,20 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                        <parameter name="item" required="true">
                                <para>Standard items (provided by all channel technologies) are:</para>
                                <enumlist>
+                                       <enum name="amaflags">
+                                               <para>R/W the Automatic Message Accounting (AMA) flags on the channel.
+                                               When read from a channel, the integer value will always be returned.
+                                               When written to a channel, both the string format or integer value
+                                               is accepted.</para>
+                                               <enumlist>
+                                                       <enum name="1"><para><literal>OMIT</literal></para></enum>
+                                                       <enum name="2"><para><literal>BILLING</literal></para></enum>
+                                                       <enum name="3"><para><literal>DOCUMENTATION</literal></para></enum>
+                                               </enumlist>
+                                       </enum>
+                                       <enum name="accountcode">
+                                               <para>R/W the channel's account code.</para>
+                                       </enum>
                                        <enum name="audioreadformat">
                                                <para>R/O format currently being read.</para>
                                        </enum>
@@ -86,11 +102,23 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                        <enum name="audiowriteformat">
                                                <para>R/O format currently being written.</para>
                                        </enum>
+                                       <enum name="dtmf_features">
+                                               <para>R/W The channel's DTMF bridge features.
+                                               May include one or more of 'T' 'K' 'H' 'W' and 'X' in a similar manner to options
+                                               in the <literal>Dial</literal> application. When setting it, the features string
+                                               must be all upper case.</para>
+                                       </enum>
                                        <enum name="callgroup">
-                                               <para>R/W call groups for call pickup.</para>
+                                               <para>R/W numeric call pickup groups that this channel is a member.</para>
                                        </enum>
                                        <enum name="pickupgroup">
-                                               <para>R/W call groups for call pickup.</para>
+                                               <para>R/W numeric call pickup groups this channel can pickup.</para>
+                                       </enum>
+                                       <enum name="namedcallgroup">
+                                               <para>R/W named call pickup groups that this channel is a member.</para>
+                                       </enum>
+                                       <enum name="namedpickupgroup">
+                                               <para>R/W named call pickup groups this channel can pickup.</para>
                                        </enum>
                                        <enum name="channeltype">
                                                <para>R/O technology used for channel.</para>
@@ -98,6 +126,12 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                        <enum name="checkhangup">
                                                <para>R/O Whether the channel is hanging up (1/0)</para>
                                        </enum>
+                                       <enum name="after_bridge_goto">
+                                               <para>R/W the parseable goto string indicating where the channel is
+                                               expected to return to in the PBX after exiting the next bridge it joins
+                                               on the condition that it doesn't hang up. The parseable goto string uses
+                                               the same syntax as the <literal>Goto</literal> application.</para>
+                                       </enum>
                                        <enum name="hangup_handler_pop">
                                                <para>W/O Replace the most recently added hangup handler
                                                with a new hangup handler on the channel if supplied.  The
@@ -233,16 +267,35 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                                <para>     <literal>audio</literal>             Get audio destination</para>
                                                <para>     <literal>video</literal>             Get video destination</para>
                                                <para>     <literal>text</literal>              Get text destination</para>
+                                               <para>   Defaults to <literal>audio</literal> if unspecified.</para>
+                                       </enum>
+                                       <enum name="rtpsource">
+                                               <para>R/O Get source RTP destination information.</para>
+                                               <para>   This option takes one additional argument:</para>
+                                               <para>    Argument 1:</para>
+                                               <para>     <literal>audio</literal>             Get audio destination</para>
+                                               <para>     <literal>video</literal>             Get video destination</para>
+                                               <para>     <literal>text</literal>              Get text destination</para>
+                                               <para>   Defaults to <literal>audio</literal> if unspecified.</para>
                                        </enum>
                                </enumlist>
                                <para><emphasis>chan_iax2</emphasis> provides the following additional options:</para>
                                <enumlist>
+                                       <enum name="osptoken">
+                                               <para>R/O Get the peer's osptoken.</para>
+                                       </enum>
                                        <enum name="peerip">
                                                <para>R/O Get the peer's ip address.</para>
                                        </enum>
                                        <enum name="peername">
                                                <para>R/O Get the peer's username.</para>
                                        </enum>
+                                       <enum name="secure_signaling">
+                                               <para>R/O Get the if the IAX channel is secured.</para>
+                                       </enum>
+                                       <enum name="secure_media">
+                                               <para>R/O Get the if the IAX channel is secured.</para>
+                                       </enum>
                                </enumlist>
                                <para><emphasis>chan_dahdi</emphasis> provides the following additional options:</para>
                                <enumlist>
@@ -300,17 +353,35 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                <para><emphasis>chan_ooh323</emphasis> provides the following additional options:</para>
                                <enumlist>
                                        <enum name="faxdetect">
-                                               <para>Fax Detect [R/W]</para>
+                                               <para>R/W Fax Detect</para>
                                                <para>Returns 0 or 1</para>
                                                <para>Write yes or no</para>
                                        </enum>
                                        <enum name="t38support">
-                                               <para>t38support [R/W]</para>
+                                               <para>R/W t38support</para>
                                                <para>Returns 0 or 1</para>
                                                <para>Write yes or no</para>
                                        </enum>
-                                       <enum name="h323id">
-                                               <para>Returns h323id [R]</para>
+                                       <enum name="h323id_url">
+                                               <para>R/0 Returns caller URL</para>
+                                       </enum>
+                                       <enum name="caller_h323id">
+                                               <para>R/0 Returns caller h323id</para>
+                                       </enum>
+                                       <enum name="caller_dialeddigits">
+                                               <para>R/0 Returns caller dialed digits</para>
+                                       </enum>
+                                       <enum name="caller_email">
+                                               <para>R/0 Returns caller email</para>
+                                       </enum>
+                                       <enum name="callee_email">
+                                               <para>R/0 Returns callee email</para>
+                                       </enum>
+                                       <enum name="callee_dialeddigits">
+                                               <para>R/0 Returns callee dialed digits</para>
+                                       </enum>
+                                       <enum name="caller_url">
+                                               <para>R/0 Returns caller URL</para>
                                        </enum>
                                </enumlist>
                        </parameter>
@@ -346,15 +417,18 @@ static int func_channel_read(struct ast_channel *chan, const char *function,
                             char *data, char *buf, size_t len)
 {
        int ret = 0;
-       char tmp[512];
        struct ast_format_cap *tmpcap;
 
        if (!strcasecmp(data, "audionativeformat")) {
+               char tmp[512];
+
                if ((tmpcap = ast_format_cap_get_type(ast_channel_nativeformats(chan), AST_FORMAT_TYPE_AUDIO))) {
                        ast_copy_string(buf, ast_getformatname_multiple(tmp, sizeof(tmp), tmpcap), len);
                        tmpcap = ast_format_cap_destroy(tmpcap);
                }
        } else if (!strcasecmp(data, "videonativeformat")) {
+               char tmp[512];
+
                if ((tmpcap = ast_format_cap_get_type(ast_channel_nativeformats(chan), AST_FORMAT_TYPE_VIDEO))) {
                        ast_copy_string(buf, ast_getformatname_multiple(tmp, sizeof(tmp), tmpcap), len);
                        tmpcap = ast_format_cap_destroy(tmpcap);
@@ -369,9 +443,13 @@ static int func_channel_read(struct ast_channel *chan, const char *function,
                ast_copy_string(buf, ast_channel_trace_is_enabled(chan) ? "1" : "0", len);
                ast_channel_unlock(chan);
 #endif
-       } else if (!strcasecmp(data, "tonezone") && ast_channel_zone(chan))
+       } else if (!strcasecmp(data, "tonezone") && ast_channel_zone(chan)) {
                locked_copy_string(chan, buf, ast_channel_zone(chan)->country, len);
-       else if (!strcasecmp(data, "language"))
+       } else if (!strcasecmp(data, "dtmf_features")) {
+               if (ast_bridge_features_ds_get_string(chan, buf, len)) {
+                       buf[0] = '\0';
+               }
+       } else if (!strcasecmp(data, "language"))
                locked_copy_string(chan, buf, ast_channel_language(chan), len);
        else if (!strcasecmp(data, "musicclass"))
                locked_copy_string(chan, buf, ast_channel_musicclass(chan), len);
@@ -417,9 +495,10 @@ static int func_channel_read(struct ast_channel *chan, const char *function,
                ast_channel_unlock(chan);
        } else if (!strcasecmp(data, "peer")) {
                struct ast_channel *p;
+
                ast_channel_lock(chan);
                p = ast_bridged_channel(chan);
-               if (p || ast_channel_tech(chan) || ast_channel_cdr(chan)) /* dummy channel? if so, we hid the peer name in the language */
+               if (p || ast_channel_tech(chan)) /* dummy channel? if so, we hid the peer name in the language */
                        ast_copy_string(buf, (p ? ast_channel_name(p) : ""), len);
                else {
                        /* a dummy channel can still pass along bridged peer info via
@@ -437,16 +516,29 @@ static int func_channel_read(struct ast_channel *chan, const char *function,
                locked_copy_string(chan, buf, transfercapability_table[ast_channel_transfercapability(chan) & 0x1f], len);
        } else if (!strcasecmp(data, "callgroup")) {
                char groupbuf[256];
+
                locked_copy_string(chan, buf,  ast_print_group(groupbuf, sizeof(groupbuf), ast_channel_callgroup(chan)), len);
        } else if (!strcasecmp(data, "pickupgroup")) {
                char groupbuf[256];
+
                locked_copy_string(chan, buf,  ast_print_group(groupbuf, sizeof(groupbuf), ast_channel_pickupgroup(chan)), len);
+       } else if (!strcasecmp(data, "namedcallgroup")) {
+               struct ast_str *tmp_str = ast_str_alloca(1024);
+
+               locked_copy_string(chan, buf,  ast_print_namedgroups(&tmp_str, ast_channel_named_callgroups(chan)), len);
+       } else if (!strcasecmp(data, "namedpickupgroup")) {
+               struct ast_str *tmp_str = ast_str_alloca(1024);
+
+               locked_copy_string(chan, buf,  ast_print_namedgroups(&tmp_str, ast_channel_named_pickupgroups(chan)), len);
+       } else if (!strcasecmp(data, "after_bridge_goto")) {
+               ast_after_bridge_goto_read(chan, buf, len);
        } else if (!strcasecmp(data, "amaflags")) {
-               char amabuf[256];
-               snprintf(amabuf,sizeof(amabuf), "%d", ast_channel_amaflags(chan));
-               locked_copy_string(chan, buf, amabuf, len);
+               ast_channel_lock(chan);
+               snprintf(buf, len, "%d", ast_channel_amaflags(chan));
+               ast_channel_unlock(chan);
        } else if (!strncasecmp(data, "secure_bridge_", 14)) {
                struct ast_datastore *ds;
+
                ast_channel_lock(chan);
                if ((ds = ast_channel_datastore_find(chan, &secure_call_info, NULL))) {
                        struct ast_secure_call_store *encrypt = ds->data;
@@ -481,9 +573,15 @@ static int func_channel_write_real(struct ast_channel *chan, const char *functio
                locked_string_field_set(chan, accountcode, value);
        else if (!strcasecmp(data, "userfield"))
                locked_string_field_set(chan, userfield, value);
-       else if (!strcasecmp(data, "amaflags")) {
+       else if (!strcasecmp(data, "after_bridge_goto")) {
+               if (ast_strlen_zero(value)) {
+                       ast_after_bridge_goto_discard(chan);
+               } else {
+                       ast_after_bridge_set_go_on(chan, ast_channel_context(chan), ast_channel_exten(chan), ast_channel_priority(chan), value);
+               }
+       } else if (!strcasecmp(data, "amaflags")) {
                ast_channel_lock(chan);
-               if(isdigit(*value)) {
+               if (isdigit(*value)) {
                        int amaflags;
                        sscanf(value, "%30d", &amaflags);
                        ast_channel_amaflags_set(chan, amaflags);
@@ -503,7 +601,7 @@ static int func_channel_write_real(struct ast_channel *chan, const char *functio
 #ifdef CHANNEL_TRACE
        else if (!strcasecmp(data, "trace")) {
                ast_channel_lock(chan);
-               if (ast_true(value)) 
+               if (ast_true(value))
                        ret = ast_channel_trace_enable(chan);
                else if (ast_false(value))
                        ret = ast_channel_trace_disable(chan);
@@ -518,7 +616,7 @@ static int func_channel_write_real(struct ast_channel *chan, const char *functio
                struct ast_tone_zone *new_zone;
                if (!(new_zone = ast_get_indication_zone(value))) {
                        ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value);
-                       ret = -1;       
+                       ret = -1;
                } else {
                        ast_channel_lock(chan);
                        if (ast_channel_zone(chan)) {
@@ -528,10 +626,30 @@ static int func_channel_write_real(struct ast_channel *chan, const char *functio
                        ast_channel_unlock(chan);
                        new_zone = ast_tone_zone_unref(new_zone);
                }
+       } else if (!strcasecmp(data, "dtmf_features")) {
+               ret = ast_bridge_features_ds_set_string(chan, value);
        } else if (!strcasecmp(data, "callgroup")) {
+               ast_channel_lock(chan);
                ast_channel_callgroup_set(chan, ast_get_group(value));
+               ast_channel_unlock(chan);
        } else if (!strcasecmp(data, "pickupgroup")) {
+               ast_channel_lock(chan);
                ast_channel_pickupgroup_set(chan, ast_get_group(value));
+               ast_channel_unlock(chan);
+       } else if (!strcasecmp(data, "namedcallgroup")) {
+               struct ast_namedgroups *groups = ast_get_namedgroups(value);
+
+               ast_channel_lock(chan);
+               ast_channel_named_callgroups_set(chan, groups);
+               ast_channel_unlock(chan);
+               ast_unref_namedgroups(groups);
+       } else if (!strcasecmp(data, "namedpickupgroup")) {
+               struct ast_namedgroups *groups = ast_get_namedgroups(value);
+
+               ast_channel_lock(chan);
+               ast_channel_named_pickupgroups_set(chan, groups);
+               ast_channel_unlock(chan);
+               ast_unref_namedgroups(groups);
        } else if (!strcasecmp(data, "txgain")) {
                sscanf(value, "%4hhd", &gainset);
                ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0);
@@ -540,12 +658,15 @@ static int func_channel_write_real(struct ast_channel *chan, const char *functio
                ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0);
        } else if (!strcasecmp(data, "transfercapability")) {
                unsigned short i;
+
+               ast_channel_lock(chan);
                for (i = 0; i < 0x20; i++) {
                        if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) {
                                ast_channel_transfercapability_set(chan, i);
                                break;
                        }
                }
+               ast_channel_unlock(chan);
        } else if (!strcasecmp(data, "hangup_handler_pop")) {
                /* Pop one hangup handler before pushing the new handler. */
                ast_pbx_hangup_handler_pop(chan);
@@ -581,13 +702,13 @@ static int func_channel_write_real(struct ast_channel *chan, const char *functio
                } else {
                        store = ds->data;
                }
-               ast_channel_unlock(chan);
 
                if (!strcasecmp(data, "secure_bridge_signaling")) {
                        store->signaling = ast_true(value) ? 1 : 0;
                } else if (!strcasecmp(data, "secure_bridge_media")) {
                        store->media = ast_true(value) ? 1 : 0;
                }
+               ast_channel_unlock(chan);
        } else if (!ast_channel_tech(chan)->func_channel_write
                 || ast_channel_tech(chan)->func_channel_write(chan, function, data, value)) {
                ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n",