Hangup handlers - Dialplan subroutines that run when the channel hangs up.
[asterisk/asterisk.git] / funcs / func_channel.c
index e82c39a..699f3b6 100644 (file)
  * \ingroup functions
  */
 
+/*** MODULEINFO
+       <support_level>core</support_level>
+ ***/
+
 #include "asterisk.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
@@ -38,6 +42,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/app.h"
 #include "asterisk/indications.h"
 #include "asterisk/stringfields.h"
+#include "asterisk/global_datastores.h"
 
 /*** DOCUMENTATION
        <function name="CHANNELS" language="en_US">
@@ -84,9 +89,38 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                        <enum name="callgroup">
                                                <para>R/W call groups for call pickup.</para>
                                        </enum>
+                                       <enum name="pickupgroup">
+                                               <para>R/W call groups for call pickup.</para>
+                                       </enum>
                                        <enum name="channeltype">
                                                <para>R/O technology used for channel.</para>
                                        </enum>
+                                       <enum name="checkhangup">
+                                               <para>R/O Whether the channel is hanging up (1/0)</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
+                                               assigned string is passed to the Gosub application when
+                                               the channel is hung up.  Any optionally omitted context
+                                               and exten are supplied by the channel pushing the handler
+                                               before it is pushed.</para>
+                                       </enum>
+                                       <enum name="hangup_handler_push">
+                                               <para>W/O Push a hangup handler onto the channel hangup
+                                               handler stack.  The assigned string is passed to the
+                                               Gosub application when the channel is hung up.  Any
+                                               optionally omitted context and exten are supplied by the
+                                               channel pushing the handler before it is pushed.</para>
+                                       </enum>
+                                       <enum name="hangup_handler_wipe">
+                                               <para>W/O Wipe the entire hangup handler stack and replace
+                                               with a new hangup handler on the channel if supplied.  The
+                                               assigned string is passed to the Gosub application when
+                                               the channel is hung up.  Any optionally omitted context
+                                               and exten are supplied by the channel pushing the handler
+                                               before it is pushed.</para>
+                                       </enum>
                                        <enum name="language">
                                                <para>R/W language for sounds played.</para>
                                        </enum>
@@ -102,6 +136,12 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                        <enum name="rxgain">
                                                <para>R/W set rxgain level on channel drivers that support it.</para>
                                        </enum>
+                                       <enum name="secure_bridge_signaling">
+                                               <para>Whether or not channels bridged to this channel require secure signaling</para>
+                                       </enum>
+                                       <enum name="secure_bridge_media">
+                                               <para>Whether or not channels bridged to this channel require secure media</para>
+                                       </enum>
                                        <enum name="state">
                                                <para>R/O state for channel</para>
                                        </enum>
@@ -178,14 +218,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                                <para>     <literal>remote_normdevjitter</literal>Remote calculated jitter (normal deviation)</para>
                                                <para>     <literal>remote_stdevjitter</literal>Remote calculated jitter (standard deviation)</para>
                                                <para>     <literal>remote_count</literal>      Number of transmitted packets</para>
-                                               <para>     <literal>remote_ssrc</literal>       Remote SSRC (stream ID)</para>
-                                               <para>     <literal>remote_lostpackets</literal>Remote lost packets</para>
-                                               <para>     <literal>remote_jitter</literal>     Remote reported jitter</para>
-                                               <para>     <literal>remote_maxjitter</literal>  Remote calculated jitter (maximum)</para>
-                                               <para>     <literal>remote_minjitter</literal>  Remote calculated jitter (minimum)</para>
-                                               <para>     <literal>remote_normdevjitter</literal>Remote calculated jitter (normal deviation)</para>
-                                               <para>     <literal>remote_stdevjitter</literal>Remote calculated jitter (standard deviation)</para>
-                                               <para>     <literal>remote_count</literal>      Number of transmitted packets</para>
                                                <para>     <literal>rtt</literal>               Round trip time</para>
                                                <para>     <literal>maxrtt</literal>            Round trip time (maximum)</para>
                                                <para>     <literal>minrtt</literal>            Round trip time (minimum)</para>
@@ -200,13 +232,11 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                                <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>
                                        </enum>
                                </enumlist>
                                <para><emphasis>chan_iax2</emphasis> provides the following additional options:</para>
                                <enumlist>
-                                       <enum name="osptoken">
-                                               <para>R/W Get or set the OSP token information for a call.</para>
-                                       </enum>
                                        <enum name="peerip">
                                                <para>R/O Get the peer's ip address.</para>
                                        </enum>
@@ -216,13 +246,72 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                </enumlist>
                                <para><emphasis>chan_dahdi</emphasis> provides the following additional options:</para>
                                <enumlist>
+                                       <enum name="dahdi_channel">
+                                               <para>R/O DAHDI channel related to this channel.</para>
+                                       </enum>
+                                       <enum name="dahdi_span">
+                                               <para>R/O DAHDI span related to this channel.</para>
+                                       </enum>
+                                       <enum name="dahdi_type">
+                                               <para>R/O DAHDI channel type, one of:</para>
+                                               <enumlist>
+                                                       <enum name="analog" />
+                                                       <enum name="mfc/r2" />
+                                                       <enum name="pri" />
+                                                       <enum name="pseudo" />
+                                                       <enum name="ss7" />
+                                               </enumlist>
+                                       </enum>
+                                       <enum name="keypad_digits">
+                                               <para>R/O PRI Keypad digits that came in with the SETUP message.</para>
+                                       </enum>
                                        <enum name="reversecharge">
-                                               <para>R/O Reverse Charging Indication, one of:</para>
+                                               <para>R/O PRI Reverse Charging Indication, one of:</para>
                                                <enumlist>
-                                                       <enum name="-1 - None" />
-                                                       <enum name="1 - Reverse Charging Requested" />
+                                                       <enum name="-1"> <para>None</para></enum>
+                                                       <enum name=" 1"> <para>Reverse Charging Requested</para></enum>
                                                </enumlist>
                                        </enum>
+                                       <enum name="no_media_path">
+                                               <para>R/O PRI Nonzero if the channel has no B channel.
+                                               The channel is either on hold or a call waiting call.</para>
+                                       </enum>
+                                       <enum name="buffers">
+                                               <para>W/O Change the channel's buffer policy (for the current call only)</para>
+                                               <para>This option takes two arguments:</para>
+                                               <para>  Number of buffers,</para>
+                                               <para>  Buffer policy being one of:</para>
+                                               <para>      <literal>full</literal></para>
+                                               <para>      <literal>immediate</literal></para>
+                                               <para>      <literal>half</literal></para>
+                                       </enum>
+                                       <enum name="echocan_mode">
+                                               <para>W/O Change the configuration of the active echo
+                                               canceller on the channel (if any), for the current call
+                                               only.</para>
+                                               <para>Possible values are:</para>
+                                               <para>  <literal>on</literal>   Normal mode (the echo canceller is actually reinitalized)</para>
+                                               <para>  <literal>off</literal>  Disabled</para>
+                                               <para>  <literal>fax</literal>  FAX/data mode (NLP disabled if possible, otherwise
+                                                       completely disabled)</para>
+                                               <para>  <literal>voice</literal>        Voice mode (returns from FAX mode, reverting the changes that were made)</para>
+                                       </enum>
+                               </enumlist>
+                               <para><emphasis>chan_ooh323</emphasis> provides the following additional options:</para>
+                               <enumlist>
+                                       <enum name="faxdetect">
+                                               <para>Fax Detect [R/W]</para>
+                                               <para>Returns 0 or 1</para>
+                                               <para>Write yes or no</para>
+                                       </enum>
+                                       <enum name="t38support">
+                                               <para>t38support [R/W]</para>
+                                               <para>Returns 0 or 1</para>
+                                               <para>Write yes or no</para>
+                                       </enum>
+                                       <enum name="h323id">
+                                               <para>Returns h323id [R]</para>
+                                       </enum>
                                </enumlist>
                        </parameter>
                </syntax>
@@ -243,7 +332,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #define locked_string_field_set(chan, field, source) \
        do { \
                ast_channel_lock(chan); \
-               ast_string_field_set(chan, field, source); \
+               ast_channel_##field##_set(chan, source); \
                ast_channel_unlock(chan); \
        } while (0)
 
@@ -257,74 +346,81 @@ 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"))
-               /* use the _multiple version when chan->nativeformats holds multiple formats */
-               /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_AUDIO_MASK); */
-               ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_AUDIO_MASK), len);
-       else if (!strcasecmp(data, "videonativeformat"))
-               /* use the _multiple version when chan->nativeformats holds multiple formats */
-               /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_VIDEO_MASK); */
-               ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_VIDEO_MASK), len);
-       else if (!strcasecmp(data, "audioreadformat"))
-               ast_copy_string(buf, ast_getformatname(chan->readformat), len);
-       else if (!strcasecmp(data, "audiowriteformat"))
-               ast_copy_string(buf, ast_getformatname(chan->writeformat), len);
+       if (!strcasecmp(data, "audionativeformat")) {
+               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")) {
+               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);
+               }
+       } else if (!strcasecmp(data, "audioreadformat")) {
+               ast_copy_string(buf, ast_getformatname(ast_channel_readformat(chan)), len);
+       } else if (!strcasecmp(data, "audiowriteformat")) {
+               ast_copy_string(buf, ast_getformatname(ast_channel_writeformat(chan)), len);
 #ifdef CHANNEL_TRACE
-       else if (!strcasecmp(data, "trace")) {
+       } else if (!strcasecmp(data, "trace")) {
                ast_channel_lock(chan);
                ast_copy_string(buf, ast_channel_trace_is_enabled(chan) ? "1" : "0", len);
                ast_channel_unlock(chan);
-       }
 #endif
-       else if (!strcasecmp(data, "tonezone") && chan->zone)
-               locked_copy_string(chan, buf, chan->zone->country, len);
+       } 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"))
-               locked_copy_string(chan, buf, chan->language, len);
+               locked_copy_string(chan, buf, ast_channel_language(chan), len);
        else if (!strcasecmp(data, "musicclass"))
-               locked_copy_string(chan, buf, chan->musicclass, len);
+               locked_copy_string(chan, buf, ast_channel_musicclass(chan), len);
        else if (!strcasecmp(data, "name")) {
-               locked_copy_string(chan, buf, chan->name, len);
+               locked_copy_string(chan, buf, ast_channel_name(chan), len);
        } else if (!strcasecmp(data, "parkinglot"))
-               locked_copy_string(chan, buf, chan->parkinglot, len);
+               locked_copy_string(chan, buf, ast_channel_parkinglot(chan), len);
        else if (!strcasecmp(data, "state"))
-               locked_copy_string(chan, buf, ast_state2str(chan->_state), len);
+               locked_copy_string(chan, buf, ast_state2str(ast_channel_state(chan)), len);
        else if (!strcasecmp(data, "channeltype"))
-               locked_copy_string(chan, buf, chan->tech->type, len);
+               locked_copy_string(chan, buf, ast_channel_tech(chan)->type, len);
        else if (!strcasecmp(data, "accountcode"))
-               locked_copy_string(chan, buf, chan->accountcode, len);
-       else if (!strcasecmp(data, "peeraccount"))
-               locked_copy_string(chan, buf, chan->peeraccount, len);
+               locked_copy_string(chan, buf, ast_channel_accountcode(chan), len);
+       else if (!strcasecmp(data, "checkhangup")) {
+               ast_channel_lock(chan);
+               ast_copy_string(buf, ast_check_hangup(chan) ? "1" : "0", len);
+               ast_channel_unlock(chan);
+       } else if (!strcasecmp(data, "peeraccount"))
+               locked_copy_string(chan, buf, ast_channel_peeraccount(chan), len);
        else if (!strcasecmp(data, "hangupsource"))
-               locked_copy_string(chan, buf, chan->hangupsource, len);
-       else if (!strcasecmp(data, "appname") && chan->appl)
-               locked_copy_string(chan, buf, chan->appl, len);
-       else if (!strcasecmp(data, "appdata") && chan->data)
-               locked_copy_string(chan, buf, chan->data, len);
-       else if (!strcasecmp(data, "exten") && chan->data)
-               locked_copy_string(chan, buf, chan->exten, len);
-       else if (!strcasecmp(data, "context") && chan->data)
-               locked_copy_string(chan, buf, chan->context, len);
-       else if (!strcasecmp(data, "userfield") && chan->data)
-               locked_copy_string(chan, buf, chan->userfield, len);
-       else if (!strcasecmp(data, "channame") && chan->data)
-               locked_copy_string(chan, buf, chan->name, len);
+               locked_copy_string(chan, buf, ast_channel_hangupsource(chan), len);
+       else if (!strcasecmp(data, "appname") && ast_channel_appl(chan))
+               locked_copy_string(chan, buf, ast_channel_appl(chan), len);
+       else if (!strcasecmp(data, "appdata") && ast_channel_data(chan))
+               locked_copy_string(chan, buf, ast_channel_data(chan), len);
+       else if (!strcasecmp(data, "exten") && ast_channel_data(chan))
+               locked_copy_string(chan, buf, ast_channel_exten(chan), len);
+       else if (!strcasecmp(data, "context") && ast_channel_data(chan))
+               locked_copy_string(chan, buf, ast_channel_context(chan), len);
+       else if (!strcasecmp(data, "userfield") && ast_channel_data(chan))
+               locked_copy_string(chan, buf, ast_channel_userfield(chan), len);
+       else if (!strcasecmp(data, "channame") && ast_channel_data(chan))
+               locked_copy_string(chan, buf, ast_channel_name(chan), len);
        else if (!strcasecmp(data, "linkedid")) {
                ast_channel_lock(chan);
-               if (ast_strlen_zero(chan->linkedid)) {
+               if (ast_strlen_zero(ast_channel_linkedid(chan))) {
                        /* fall back on the channel's uniqueid if linkedid is unset */
-                       ast_copy_string(buf, chan->uniqueid, len);
+                       ast_copy_string(buf, ast_channel_uniqueid(chan), len);
                }
                else {
-                       ast_copy_string(buf, chan->linkedid, len);
+                       ast_copy_string(buf, ast_channel_linkedid(chan), len);
                }
                ast_channel_unlock(chan);
        } else if (!strcasecmp(data, "peer")) {
                struct ast_channel *p;
                ast_channel_lock(chan);
                p = ast_bridged_channel(chan);
-               if (p || chan->tech || chan->cdr) /* dummy channel? if so, we hid the peer name in the language */
-                       ast_copy_string(buf, (p ? p->name : ""), len);
+               if (p || ast_channel_tech(chan) || ast_channel_cdr(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
                            the BRIDGEPEER variable */
@@ -336,17 +432,32 @@ static int func_channel_read(struct ast_channel *chan, const char *function,
                }
                ast_channel_unlock(chan);
        } else if (!strcasecmp(data, "uniqueid")) {
-               locked_copy_string(chan, buf, chan->uniqueid, len);
-       } else if (!strcasecmp(data, "transfercapability"))
-               locked_copy_string(chan, buf, transfercapability_table[chan->transfercapability & 0x1f], len);
-       else if (!strcasecmp(data, "callgroup")) {
+               locked_copy_string(chan, buf, ast_channel_uniqueid(chan), len);
+       } else if (!strcasecmp(data, "transfercapability")) {
+               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), chan->callgroup), len);
+               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, "amaflags")) {
                char amabuf[256];
-               snprintf(amabuf,sizeof(amabuf), "%d", chan->amaflags);
+               snprintf(amabuf,sizeof(amabuf), "%d", ast_channel_amaflags(chan));
                locked_copy_string(chan, buf, amabuf, len);
-       } else if (!chan->tech || !chan->tech->func_channel_read || chan->tech->func_channel_read(chan, function, data, buf, len)) {
+       } 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;
+                       if (!strcasecmp(data, "secure_bridge_signaling")) {
+                               snprintf(buf, len, "%s", encrypt->signaling ? "1" : "");
+                       } else if (!strcasecmp(data, "secure_bridge_media")) {
+                               snprintf(buf, len, "%s", encrypt->media ? "1" : "");
+                       }
+               }
+               ast_channel_unlock(chan);
+       } else if (!ast_channel_tech(chan) || !ast_channel_tech(chan)->func_channel_read || ast_channel_tech(chan)->func_channel_read(chan, function, data, buf, len)) {
                ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data);
                ret = -1;
        }
@@ -354,7 +465,7 @@ static int func_channel_read(struct ast_channel *chan, const char *function,
        return ret;
 }
 
-static int func_channel_write(struct ast_channel *chan, const char *function,
+static int func_channel_write_real(struct ast_channel *chan, const char *function,
                              char *data, const char *value)
 {
        int ret = 0;
@@ -373,13 +484,15 @@ static int func_channel_write(struct ast_channel *chan, const char *function,
        else if (!strcasecmp(data, "amaflags")) {
                ast_channel_lock(chan);
                if(isdigit(*value)) {
-                       sscanf(value, "%30d", &chan->amaflags);
+                       int amaflags;
+                       sscanf(value, "%30d", &amaflags);
+                       ast_channel_amaflags_set(chan, amaflags);
                } else if (!strcasecmp(value,"OMIT")){
-                       chan->amaflags = 1;
+                       ast_channel_amaflags_set(chan, 1);
                } else if (!strcasecmp(value,"BILLING")){
-                       chan->amaflags = 2;
+                       ast_channel_amaflags_set(chan, 2);
                } else if (!strcasecmp(value,"DOCUMENTATION")){
-                       chan->amaflags = 3;
+                       ast_channel_amaflags_set(chan, 3);
                }
                ast_channel_unlock(chan);
        } else if (!strcasecmp(data, "peeraccount"))
@@ -396,7 +509,7 @@ static int func_channel_write(struct ast_channel *chan, const char *function,
                        ret = ast_channel_trace_disable(chan);
                else {
                        ret = -1;
-                       ast_log(LOG_WARNING, "Invalid value for CHANNEL(trace).");
+                       ast_log(LOG_WARNING, "Invalid value for CHANNEL(trace).\n");
                }
                ast_channel_unlock(chan);
        }
@@ -408,16 +521,18 @@ static int func_channel_write(struct ast_channel *chan, const char *function,
                        ret = -1;       
                } else {
                        ast_channel_lock(chan);
-                       if (chan->zone) {
-                               chan->zone = ast_tone_zone_unref(chan->zone);
+                       if (ast_channel_zone(chan)) {
+                               ast_channel_zone_set(chan, ast_tone_zone_unref(ast_channel_zone(chan)));
                        }
-                       chan->zone = ast_tone_zone_ref(new_zone);
+                       ast_channel_zone_set(chan, ast_tone_zone_ref(new_zone));
                        ast_channel_unlock(chan);
                        new_zone = ast_tone_zone_unref(new_zone);
                }
-       } else if (!strcasecmp(data, "callgroup"))
-               chan->callgroup = ast_get_group(value);
-       else if (!strcasecmp(data, "txgain")) {
+       } else if (!strcasecmp(data, "callgroup")) {
+               ast_channel_callgroup_set(chan, ast_get_group(value));
+       } else if (!strcasecmp(data, "pickupgroup")) {
+               ast_channel_pickupgroup_set(chan, ast_get_group(value));
+       } else if (!strcasecmp(data, "txgain")) {
                sscanf(value, "%4hhd", &gainset);
                ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0);
        } else if (!strcasecmp(data, "rxgain")) {
@@ -427,12 +542,54 @@ static int func_channel_write(struct ast_channel *chan, const char *function,
                unsigned short i;
                for (i = 0; i < 0x20; i++) {
                        if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) {
-                               chan->transfercapability = i;
+                               ast_channel_transfercapability_set(chan, i);
                                break;
                        }
                }
-       } else if (!chan->tech->func_channel_write
-                || chan->tech->func_channel_write(chan, function, data, value)) {
+       } else if (!strcasecmp(data, "hangup_handler_pop")) {
+               /* Pop one hangup handler before pushing the new handler. */
+               ast_pbx_hangup_handler_pop(chan);
+               ast_pbx_hangup_handler_push(chan, value);
+       } else if (!strcasecmp(data, "hangup_handler_push")) {
+               ast_pbx_hangup_handler_push(chan, value);
+       } else if (!strcasecmp(data, "hangup_handler_wipe")) {
+               /* Pop all hangup handlers before pushing the new handler. */
+               while (ast_pbx_hangup_handler_pop(chan)) {
+               }
+               ast_pbx_hangup_handler_push(chan, value);
+       } else if (!strncasecmp(data, "secure_bridge_", 14)) {
+               struct ast_datastore *ds;
+               struct ast_secure_call_store *store;
+
+               if (!chan || !value) {
+                       return -1;
+               }
+
+               ast_channel_lock(chan);
+               if (!(ds = ast_channel_datastore_find(chan, &secure_call_info, NULL))) {
+                       if (!(ds = ast_datastore_alloc(&secure_call_info, NULL))) {
+                               ast_channel_unlock(chan);
+                               return -1;
+                       }
+                       if (!(store = ast_calloc(1, sizeof(*store)))) {
+                               ast_channel_unlock(chan);
+                               ast_free(ds);
+                               return -1;
+                       }
+                       ds->data = store;
+                       ast_channel_datastore_add(chan, ds);
+               } 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;
+               }
+       } 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",
                                data);
                ret = -1;
@@ -441,6 +598,24 @@ static int func_channel_write(struct ast_channel *chan, const char *function,
        return ret;
 }
 
+static int func_channel_write(struct ast_channel *chan, const char *function, char *data, const char *value)
+{
+       int res;
+       ast_chan_write_info_t write_info = {
+               .version = AST_CHAN_WRITE_INFO_T_VERSION,
+               .write_fn = func_channel_write_real,
+               .chan = chan,
+               .function = function,
+               .data = data,
+               .value = value,
+       };
+
+       res = func_channel_write_real(chan, function, data, value);
+       ast_channel_setoption(chan, AST_OPTION_CHANNEL_WRITE, &write_info, sizeof(write_info), 0);
+
+       return res;
+}
+
 static struct ast_custom_function channel_function = {
        .name = "CHANNEL",
        .read = func_channel_read,
@@ -465,7 +640,7 @@ static int func_channels_read(struct ast_channel *chan, const char *function, ch
                }
        }
 
-       if (!(iter = ast_channel_iterator_all_new(0))) {
+       if (!(iter = ast_channel_iterator_all_new())) {
                if (!ast_strlen_zero(data)) {
                        regfree(&re);
                }
@@ -474,14 +649,14 @@ static int func_channels_read(struct ast_channel *chan, const char *function, ch
 
        while ((c = ast_channel_iterator_next(iter))) {
                ast_channel_lock(c);
-               if (ast_strlen_zero(data) || regexec(&re, c->name, 0, NULL, 0) == 0) {
-                       size_t namelen = strlen(c->name);
+               if (ast_strlen_zero(data) || regexec(&re, ast_channel_name(c), 0, NULL, 0) == 0) {
+                       size_t namelen = strlen(ast_channel_name(c));
                        if (buflen + namelen + (ast_strlen_zero(buf) ? 0 : 1) + 1 < maxlen) {
                                if (!ast_strlen_zero(buf)) {
                                        strcat(buf, " ");
                                        buflen++;
                                }
-                               strcat(buf, c->name);
+                               strcat(buf, ast_channel_name(c));
                                buflen += namelen;
                        } else {
                                ast_log(LOG_WARNING, "Number of channels exceeds the available buffer space.  Output will be truncated!\n");
@@ -508,7 +683,7 @@ static struct ast_custom_function channels_function = {
 static int func_mchan_read(struct ast_channel *chan, const char *function,
                             char *data, struct ast_str **buf, ssize_t len)
 {
-       struct ast_channel *mchan = ast_channel_get_by_name(chan->linkedid);
+       struct ast_channel *mchan = ast_channel_get_by_name(ast_channel_linkedid(chan));
        char *template = alloca(4 + strlen(data));
        sprintf(template, "${%s}", data); /* SAFE */
        ast_str_substitute_variables(buf, len, mchan ? mchan : chan, template);
@@ -521,7 +696,7 @@ static int func_mchan_read(struct ast_channel *chan, const char *function,
 static int func_mchan_write(struct ast_channel *chan, const char *function,
                              char *data, const char *value)
 {
-       struct ast_channel *mchan = ast_channel_get_by_name(chan->linkedid);
+       struct ast_channel *mchan = ast_channel_get_by_name(ast_channel_linkedid(chan));
        pbx_builtin_setvar_helper(mchan ? mchan : chan, data, value);
        if (mchan) {
                ast_channel_unref(mchan);