Get rid of ast_bridged_channel() and the bridged_channel field on ast_channels.
authorMark Michelson <mmichelson@digium.com>
Fri, 2 Aug 2013 14:05:07 +0000 (14:05 +0000)
committerMark Michelson <mmichelson@digium.com>
Fri, 2 Aug 2013 14:05:07 +0000 (14:05 +0000)
This commit is smaller than the initial review placed on review board. This is because
a change to allow for channel drivers to access parking functionality externally was
committed and invalidated quite a few of the changes initially made.

(closes issue ASTERISK-22039)
reported by Matt Jordan

Review: https://reviewboard.asterisk.org/r/2717

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396103 65c4cc65-6c06-0410-ace0-fbb531ad65f3

13 files changed:
apps/app_chanspy.c
channels/chan_dahdi.c
channels/chan_iax2.c
channels/chan_mgcp.c
channels/chan_misdn.c
channels/chan_oss.c
channels/chan_sip.c
channels/chan_skinny.c
funcs/func_channel.c
include/asterisk/channel.h
main/channel.c
main/channel_internal_api.c
main/rtp_engine.c

index 4e241b9..0f40e31 100644 (file)
@@ -637,12 +637,14 @@ static int channel_spy(struct ast_channel *chan, struct ast_autochan *spyee_auto
        }
 
        if (ast_test_flag(flags, OPTION_BARGE | OPTION_DTMF_SWITCH_MODES)) {
+               RAII_VAR(struct ast_channel *, bridged, ast_channel_bridge_peer(spyee_autochan->chan), ast_channel_cleanup);
+
                /* And this hook lets us inject audio into the channel that the spied on
                   channel is currently bridged with.
                */
                ast_audiohook_init(&csth.bridge_whisper_audiohook, AST_AUDIOHOOK_TYPE_WHISPER, "Chanspy", 0);
 
-               if ((spyee_bridge_autochan = ast_autochan_setup(ast_bridged_channel(spyee_autochan->chan)))) {
+               if ((spyee_bridge_autochan = ast_autochan_setup(bridged))) {
                        ast_channel_lock(spyee_bridge_autochan->chan);
                        if (start_spying(spyee_bridge_autochan, spyer_name, &csth.bridge_whisper_audiohook)) {
                                ast_log(LOG_WARNING, "Unable to attach barge audiohook on spyee %s. Barge mode disabled!\n", name);
@@ -935,7 +937,7 @@ static int common_exec(struct ast_channel *chan, struct ast_flags *flags,
                                break;
                        }
 
-                       if (ast_test_flag(flags, OPTION_BRIDGED) && !ast_bridged_channel(autochan->chan)) {
+                       if (ast_test_flag(flags, OPTION_BRIDGED) && !ast_channel_is_bridged(autochan->chan)) {
                                continue;
                        }
 
index 15726e1..8ce700c 100644 (file)
@@ -1742,7 +1742,7 @@ static void my_get_and_handle_alarms(void *pvt)
 
 static void *my_get_sigpvt_bridged_channel(struct ast_channel *chan)
 {
-       struct ast_channel *bridged = ast_bridged_channel(chan);
+       RAII_VAR(struct ast_channel *, bridged, ast_channel_bridge_peer(chan), ast_channel_cleanup);
 
        if (bridged && ast_channel_tech(bridged) == &dahdi_tech) {
                struct dahdi_pvt *p = ast_channel_tech_pvt(bridged);
@@ -9737,12 +9737,15 @@ static void *analog_ss_thread(void *data)
                                struct ast_channel *nbridge =
                                        p->subs[SUB_THREEWAY].owner;
                                struct dahdi_pvt *pbridge = NULL;
+                               RAII_VAR(struct ast_channel *, bridged, nbridge ? ast_channel_bridge_peer(nbridge) : NULL, ast_channel_cleanup);
+
                                /* set up the private struct of the bridged one, if any */
-                               if (nbridge && ast_bridged_channel(nbridge))
-                                       pbridge = ast_channel_tech_pvt(ast_bridged_channel(nbridge));
+                               if (nbridge && bridged) {
+                                       pbridge = ast_channel_tech_pvt(bridged);
+                               }
                                if (nbridge && pbridge &&
                                        (ast_channel_tech(nbridge) == &dahdi_tech) &&
-                                       (ast_channel_tech(ast_bridged_channel(nbridge)) == &dahdi_tech) &&
+                                       (ast_channel_tech(bridged) == &dahdi_tech) &&
                                        ISTRUNK(pbridge)) {
                                        int func = DAHDI_FLASH;
                                        /* Clear out the dial buffer */
index 1ae5505..faad641 100644 (file)
@@ -4049,7 +4049,7 @@ static int schedule_delivery(struct iax_frame *fr, int updatehistory, int fromtr
        int ret;
        int needfree = 0;
        struct ast_channel *owner = NULL;
-       struct ast_channel *bridge = NULL;
+       RAII_VAR(struct ast_channel *, bridge, NULL, ast_channel_cleanup);
 
        /*
         * Clear fr->af.data if there is no data in the buffer.  Things
@@ -4096,8 +4096,9 @@ static int schedule_delivery(struct iax_frame *fr, int updatehistory, int fromtr
                iax2_frame_free(fr);
                return -1;
        }
-       if ((owner = iaxs[fr->callno]->owner))
-               bridge = ast_bridged_channel(owner);
+       if ((owner = iaxs[fr->callno]->owner)) {
+               bridge = ast_channel_bridge_peer(owner);
+       }
 
        /* if the user hasn't requested we force the use of the jitterbuffer, and we're bridged to
         * a channel that can accept jitter, then flush and suspend the jb, and send this frame straight through */
index b990646..07d8434 100644 (file)
@@ -922,7 +922,6 @@ static int mgcp_hangup(struct ast_channel *ast)
 {
        struct mgcp_subchannel *sub = ast_channel_tech_pvt(ast);
        struct mgcp_endpoint *p = sub->parent;
-       struct ast_channel *bridged;
 
        ast_debug(1, "mgcp_hangup(%s)\n", ast_channel_name(ast));
        if (!ast_channel_tech_pvt(ast)) {
@@ -969,10 +968,11 @@ static int mgcp_hangup(struct ast_channel *ast)
        }
        sub->cxident[0] = '\0';
        if ((sub == p->sub) && sub->next->owner) {
+               RAII_VAR(struct ast_channel *, bridged, ast_channel_bridge_peer(sub->next->owner), ast_channel_cleanup);
+
                if (p->hookstate == MGCP_OFFHOOK) {
-                       if (sub->next->owner && ast_bridged_channel(sub->next->owner)) {
+                       if (sub->next->owner && bridged) {
                                /* ncs fix! */
-                               bridged = ast_bridged_channel(sub->next->owner);
                                transmit_notify_request_with_callerid(p->sub, (p->ncs ? "L/wt1" : "L/wt"),
                                        S_COR(ast_channel_caller(bridged)->id.number.valid, ast_channel_caller(bridged)->id.number.str, ""),
                                        S_COR(ast_channel_caller(bridged)->id.name.valid, ast_channel_caller(bridged)->id.name.str, ""));
@@ -982,8 +982,7 @@ static int mgcp_hangup(struct ast_channel *ast)
                        p->sub = sub->next;
                        p->sub->cxmode = MGCP_CX_RECVONLY;
                        transmit_modify_request(p->sub);
-                       if (sub->next->owner && ast_bridged_channel(sub->next->owner)) {
-                               bridged = ast_bridged_channel(sub->next->owner);
+                       if (sub->next->owner && bridged) {
                                transmit_notify_request_with_callerid(p->sub, "L/rg",
                                        S_COR(ast_channel_caller(bridged)->id.number.valid, ast_channel_caller(bridged)->id.number.str, ""),
                                        S_COR(ast_channel_caller(bridged)->id.name.valid, ast_channel_caller(bridged)->id.name.str, ""));
index 34a134e..8eaf196 100644 (file)
@@ -104,6 +104,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/format_cap.h"
 #include "asterisk/features_config.h"
 #include "asterisk/bridge.h"
+#include "asterisk/pickup.h"
 
 #include "chan_misdn_config.h"
 #include "isdn_lib.h"
@@ -3442,6 +3443,7 @@ static void misdn_add_number_prefix(int port, enum mISDN_NUMBER_TYPE number_type
 
 static void export_aoc_vars(int originator, struct ast_channel *ast, struct misdn_bchannel *bc)
 {
+       RAII_VAR(struct ast_channel *, chan, NULL, ast_channel_cleanup);
        char buf[128];
 
        if (!bc->AOCD_need_export || !ast) {
@@ -3449,46 +3451,48 @@ static void export_aoc_vars(int originator, struct ast_channel *ast, struct misd
        }
 
        if (originator == ORG_AST) {
-               ast = ast_bridged_channel(ast);
-               if (!ast) {
+               chan = ast_channel_bridge_peer(ast);
+               if (!chan) {
                        return;
                }
+       } else {
+               chan = ast_channel_ref(ast);
        }
 
        switch (bc->AOCDtype) {
        case Fac_AOCDCurrency:
-               pbx_builtin_setvar_helper(ast, "AOCD_Type", "currency");
+               pbx_builtin_setvar_helper(chan, "AOCD_Type", "currency");
                if (bc->AOCD.currency.chargeNotAvailable) {
-                       pbx_builtin_setvar_helper(ast, "AOCD_ChargeAvailable", "no");
+                       pbx_builtin_setvar_helper(chan, "AOCD_ChargeAvailable", "no");
                } else {
-                       pbx_builtin_setvar_helper(ast, "AOCD_ChargeAvailable", "yes");
+                       pbx_builtin_setvar_helper(chan, "AOCD_ChargeAvailable", "yes");
                        if (bc->AOCD.currency.freeOfCharge) {
-                               pbx_builtin_setvar_helper(ast, "AOCD_FreeOfCharge", "yes");
+                               pbx_builtin_setvar_helper(chan, "AOCD_FreeOfCharge", "yes");
                        } else {
-                               pbx_builtin_setvar_helper(ast, "AOCD_FreeOfCharge", "no");
+                               pbx_builtin_setvar_helper(chan, "AOCD_FreeOfCharge", "no");
                                if (snprintf(buf, sizeof(buf), "%d %s", bc->AOCD.currency.currencyAmount * bc->AOCD.currency.multiplier, bc->AOCD.currency.currency) < sizeof(buf)) {
-                                       pbx_builtin_setvar_helper(ast, "AOCD_Amount", buf);
+                                       pbx_builtin_setvar_helper(chan, "AOCD_Amount", buf);
                                        if (bc->AOCD.currency.billingId >= 0 && snprintf(buf, sizeof(buf), "%d", bc->AOCD.currency.billingId) < sizeof(buf)) {
-                                               pbx_builtin_setvar_helper(ast, "AOCD_BillingId", buf);
+                                               pbx_builtin_setvar_helper(chan, "AOCD_BillingId", buf);
                                        }
                                }
                        }
                }
                break;
        case Fac_AOCDChargingUnit:
-               pbx_builtin_setvar_helper(ast, "AOCD_Type", "charging_unit");
+               pbx_builtin_setvar_helper(chan, "AOCD_Type", "charging_unit");
                if (bc->AOCD.chargingUnit.chargeNotAvailable) {
-                       pbx_builtin_setvar_helper(ast, "AOCD_ChargeAvailable", "no");
+                       pbx_builtin_setvar_helper(chan, "AOCD_ChargeAvailable", "no");
                } else {
-                       pbx_builtin_setvar_helper(ast, "AOCD_ChargeAvailable", "yes");
+                       pbx_builtin_setvar_helper(chan, "AOCD_ChargeAvailable", "yes");
                        if (bc->AOCD.chargingUnit.freeOfCharge) {
-                               pbx_builtin_setvar_helper(ast, "AOCD_FreeOfCharge", "yes");
+                               pbx_builtin_setvar_helper(chan, "AOCD_FreeOfCharge", "yes");
                        } else {
-                               pbx_builtin_setvar_helper(ast, "AOCD_FreeOfCharge", "no");
+                               pbx_builtin_setvar_helper(chan, "AOCD_FreeOfCharge", "no");
                                if (snprintf(buf, sizeof(buf), "%d", bc->AOCD.chargingUnit.recordedUnits) < sizeof(buf)) {
-                                       pbx_builtin_setvar_helper(ast, "AOCD_RecordedUnits", buf);
+                                       pbx_builtin_setvar_helper(chan, "AOCD_RecordedUnits", buf);
                                        if (bc->AOCD.chargingUnit.billingId >= 0 && snprintf(buf, sizeof(buf), "%d", bc->AOCD.chargingUnit.billingId) < sizeof(buf)) {
-                                               pbx_builtin_setvar_helper(ast, "AOCD_BillingId", buf);
+                                               pbx_builtin_setvar_helper(chan, "AOCD_BillingId", buf);
                                        }
                                }
                        }
@@ -10943,7 +10947,7 @@ cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data)
        case EVENT_HOLD:
        {
                int hold_allowed;
-               struct ast_channel *bridged;
+               RAII_VAR(struct ast_channel *, bridged, NULL, ast_channel_cleanup);
 
                misdn_cfg_get(bc->port, MISDN_CFG_HOLD_ALLOWED, &hold_allowed, sizeof(hold_allowed));
                if (!hold_allowed) {
@@ -10952,7 +10956,7 @@ cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data)
                        break;
                }
 
-               bridged = ast_bridged_channel(ch->ast);
+               bridged = ast_channel_bridge_peer(ch->ast);
                if (bridged) {
                        chan_misdn_log(2, bc->port, "Bridge Partner is of type: %s\n", ast_channel_tech(bridged)->type);
                        ch->l3id = bc->l3_id;
index 2545138..f8e67e5 100644 (file)
@@ -68,6 +68,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/causes.h"
 #include "asterisk/musiconhold.h"
 #include "asterisk/app.h"
+#include "asterisk/bridge.h"
 
 #include "console_video.h"
 
@@ -1173,7 +1174,7 @@ static char *console_mute(struct ast_cli_entry *e, int cmd, struct ast_cli_args
 static char *console_transfer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
        struct chan_oss_pvt *o = find_desc(oss_active);
-       struct ast_channel *b = NULL;
+       RAII_VAR(struct ast_channel *, b, NULL, ast_channel_cleanup);
        char *tmp, *ext, *ctx;
 
        switch (cmd) {
@@ -1192,24 +1193,19 @@ static char *console_transfer(struct ast_cli_entry *e, int cmd, struct ast_cli_a
                return CLI_SHOWUSAGE;
        if (o == NULL)
                return CLI_FAILURE;
-       if (o->owner == NULL || (b = ast_bridged_channel(o->owner)) == NULL) {
+       if (o->owner == NULL || !ast_channel_is_bridged(o->owner)) {
                ast_cli(a->fd, "There is no call to transfer\n");
                return CLI_SUCCESS;
        }
 
        tmp = ast_ext_ctx(a->argv[2], &ext, &ctx);
-       if (ctx == NULL)                        /* supply default context if needed */
+       if (ctx == NULL) {                      /* supply default context if needed */
                ctx = ast_strdupa(ast_channel_context(o->owner));
-       if (!ast_exists_extension(b, ctx, ext, 1,
-               S_COR(ast_channel_caller(b)->id.number.valid, ast_channel_caller(b)->id.number.str, NULL))) {
-               ast_cli(a->fd, "No such extension exists\n");
-       } else {
-               ast_cli(a->fd, "Whee, transferring %s to %s@%s.\n", ast_channel_name(b), ext, ctx);
-               if (ast_async_goto(b, ctx, ext, 1))
-                       ast_cli(a->fd, "Failed to transfer :(\n");
        }
-       if (tmp)
-               ast_free(tmp);
+       if (ast_bridge_transfer_blind(1, o->owner, ext, ctx, NULL, NULL) != AST_BRIDGE_TRANSFER_SUCCESS) {
+               ast_log(LOG_WARNING, "Unable to transfer call from channel %s\n", ast_channel_name(o->owner));
+       }
+       ast_free(tmp);
        return CLI_SUCCESS;
 }
 
index 1b5f104..736c150 100644 (file)
@@ -7271,7 +7271,7 @@ static int sip_hangup(struct ast_channel *ast)
                        }
 
                        if (!p->pendinginvite) {
-                               struct ast_channel *bridge = ast_bridged_channel(oldowner);
+                               RAII_VAR(struct ast_channel *, bridge, ast_channel_bridge_peer(oldowner), ast_channel_cleanup);
                                char quality_buf[AST_MAX_USER_FIELD], *quality;
 
                                /* We need to get the lock on bridge because ast_rtp_instance_set_stats_vars will attempt
@@ -7282,7 +7282,6 @@ static int sip_hangup(struct ast_channel *ast)
                                        do {
                                                CHANNEL_DEADLOCK_AVOIDANCE(oldowner);
                                        } while (sip_pvt_trylock(p));
-                                       bridge = ast_bridged_channel(oldowner);
                                }
 
                                if (p->rtp) {
@@ -18007,10 +18006,22 @@ static int get_refer_info(struct sip_pvt *transferer, struct sip_request *outgoi
 
        /* Give useful transfer information to the dialplan */
        if (transferer->owner) {
-               struct ast_channel *peer = ast_bridged_channel(transferer->owner);
+               RAII_VAR(struct ast_channel *, peer, ast_channel_bridge_peer(transferer->owner), ast_channel_cleanup);
+
+               /*! pbx_builtin_setvar_helper will attempt to lock the channel. We need
+                * to be sure it's already locked here so we don't deadlock.
+                */
+               while (peer && ast_channel_trylock(peer)) {
+                       sip_pvt_unlock(transferer);
+                       do {
+                               CHANNEL_DEADLOCK_AVOIDANCE(transferer->owner);
+                       } while (sip_pvt_trylock(transferer));
+               }
+
                if (peer) {
                        pbx_builtin_setvar_helper(peer, "SIPREFERRINGCONTEXT", transferer->context);
                        pbx_builtin_setvar_helper(peer, "SIPREFERREDBYHDR", p_referred_by);
+                       ast_channel_unlock(peer);
                }
        }
 
@@ -26354,7 +26365,6 @@ static int handle_request_bye(struct sip_pvt *p, struct sip_request *req)
 {
        struct ast_channel *c=NULL;
        int res;
-       struct ast_channel *bridged_to;
        const char *required;
 
        /* If we have an INCOMING invite that we haven't answered, terminate that transaction */
@@ -26375,7 +26385,7 @@ static int handle_request_bye(struct sip_pvt *p, struct sip_request *req)
        /* Get RTCP quality before end of call */
        if (p->do_history || p->owner) {
                char quality_buf[AST_MAX_USER_FIELD], *quality;
-               struct ast_channel *bridge = p->owner ? ast_bridged_channel(p->owner) : NULL;
+               RAII_VAR(struct ast_channel *, bridge, p->owner ? ast_channel_bridge_peer(p->owner) : NULL, ast_channel_cleanup);
 
                /* We need to get the lock on bridge because ast_rtp_instance_set_stats_vars will attempt
                 * to lock the bridge. This may get hairy...
@@ -26388,7 +26398,6 @@ static int handle_request_bye(struct sip_pvt *p, struct sip_request *req)
                                usleep(1);
                                sip_pvt_lock(p);
                        } while (p->owner && ast_channel_trylock(p->owner));
-                       bridge = p->owner ? ast_bridged_channel(p->owner) : NULL;
                }
 
 
@@ -26452,7 +26461,7 @@ static int handle_request_bye(struct sip_pvt *p, struct sip_request *req)
                if (!res) {
                        c = p->owner;
                        if (c) {
-                               bridged_to = ast_bridged_channel(c);
+                               RAII_VAR(struct ast_channel *, bridged_to, ast_channel_bridge_peer(c), ast_channel_cleanup);
                                if (bridged_to) {
                                        /* Don't actually hangup here... */
                                        ast_queue_unhold(c);
index 1237c78..35da7bf 100644 (file)
@@ -4357,10 +4357,12 @@ static char *_skinny_show_lines(int fd, int *total, struct mansession *s, const
                                l->label);
                        if (verbose) {
                                AST_LIST_TRAVERSE(&l->sub, sub, list) {
+                                       RAII_VAR(struct ast_channel *, bridged, ast_channel_bridge_peer(sub->owner), ao2_cleanup);
+
                                        ast_cli(fd, "  %s> %s to %s\n",
                                                (sub == l->activesub?"Active  ":"Inactive"),
                                                ast_channel_name(sub->owner),
-                                               (ast_bridged_channel(sub->owner)?ast_channel_name(ast_bridged_channel(sub->owner)):"")
+                                               bridged ? ast_channel_name(bridged) : ""
                                        );
                                }
                        }
@@ -7170,6 +7172,8 @@ static int handle_soft_key_event_message(struct skinny_req *req, struct skinnyse
                }
 
                if ((sub && sub->owner) && (ast_channel_state(sub->owner) ==  AST_STATE_UP)) {
+                       RAII_VAR(struct ast_channel *, bridged, NULL, ast_channel_cleanup);
+
                        c = sub->owner;
                        ast_channel_lock(c);
                        bridge_channel = ast_channel_get_bridge_channel(c);
index 3f2ef5c..ccdbb6e 100644 (file)
@@ -495,10 +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;
+               RAII_VAR(struct ast_channel *, p, NULL, ast_channel_cleanup);
 
                ast_channel_lock(chan);
-               p = ast_bridged_channel(chan);
+               p = ast_channel_bridge_peer(chan);
                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 {
index 282230a..cc60deb 100644 (file)
@@ -2330,26 +2330,6 @@ int ast_transfer(struct ast_channel *chan, char *dest);
 void ast_do_masquerade(struct ast_channel *chan);
 
 /*!
- * \brief Find bridged channel
- *
- * \note This function does _not_ return a reference to the bridged channel.
- * The reason for this is mostly historical.  It _should_ return a reference,
- * but it will take a lot of work to make the code base account for that.
- * So, for now, the old rules still apply for how to handle this function.
- * If this function is being used from the channel thread that owns the channel,
- * then a reference is already held, and channel locking is not required to
- * guarantee that the channel will stay around.  If this function is used
- * outside of the associated channel thread, the channel parameter 'chan'
- * MUST be locked before calling this function.  Also, 'chan' must remain locked
- * for the entire time that the result of this function is being used.
- *
- * \param chan Current channel
- *
- * \return A pointer to the bridged channel
-*/
-struct ast_channel *ast_bridged_channel(struct ast_channel *chan);
-
-/*!
  * \brief Inherits channel variable from parent to child channel
  * \param parent Parent channel
  * \param child Child channel
index 9c4a0ba..95d0a5d 100644 (file)
@@ -2606,16 +2606,12 @@ static void free_translation(struct ast_channel *clonechan)
 
 void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force)
 {
-       struct ast_channel *bridge;
+       RAII_VAR(struct ast_channel *, bridge, ast_channel_bridge_peer(chan), ast_channel_cleanup);
 
        ast_channel_lock(chan);
        if (force || ast_strlen_zero(ast_channel_hangupsource(chan))) {
                ast_channel_hangupsource_set(chan, source);
        }
-       bridge = ast_bridged_channel(chan);
-       if (bridge) {
-               ast_channel_ref(bridge);
-       }
        ast_channel_unlock(chan);
 
        if (bridge) {
@@ -2624,7 +2620,6 @@ void ast_set_hangupsource(struct ast_channel *chan, const char *source, int forc
                        ast_channel_hangupsource_set(bridge, source);
                }
                ast_channel_unlock(bridge);
-               ast_channel_unref(bridge);
        }
 }
 
@@ -3942,7 +3937,7 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
                                        ast_debug(1, "Ignoring answer on an inbound call!\n");
                                        ast_frfree(f);
                                        f = &ast_null_frame;
-                               } else if (prestate == AST_STATE_UP && ast_bridged_channel(chan)) {
+                               } else if (prestate == AST_STATE_UP && ast_channel_is_bridged(chan)) {
                                        ast_debug(1, "Dropping duplicate answer!\n");
                                        ast_frfree(f);
                                        f = &ast_null_frame;
@@ -6766,8 +6761,7 @@ void ast_do_masquerade(struct ast_channel *original)
 
        ast_debug(1, "Done Masquerading %s (%d)\n", ast_channel_name(original), ast_channel_state(original));
 
-       if ((bridged = ast_bridged_channel(original))) {
-               ast_channel_ref(bridged);
+       if ((bridged = ast_channel_bridge_peer(original))) {
                ast_channel_unlock(original);
                ast_indicate(bridged, AST_CONTROL_SRCCHANGE);
                ast_channel_unref(bridged);
@@ -6868,12 +6862,6 @@ int ast_setstate(struct ast_channel *chan, enum ast_channel_state state)
        return 0;
 }
 
-/*! BUGBUG ast_bridged_channel() is to be removed. */
-struct ast_channel *ast_bridged_channel(struct ast_channel *chan)
-{
-       return NULL;
-}
-
 /*! \brief Bridge two channels together (early) */
 int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1)
 {
index 35bcb18..6987837 100644 (file)
@@ -67,10 +67,6 @@ struct ast_channel {
        void *music_state;                              /*!< Music State*/
        void *generatordata;                            /*!< Current generator data if there is any */
        struct ast_generator *generator;                /*!< Current active data generator */
-/* BUGBUG bridged_channel must be eliminated from ast_channel */
-       struct ast_channel * bridged_channel;                   /*!< Who are we bridged to, if we're bridged.
-                                                        *   Who is proxying for us, if we are proxied (i.e. chan_agent).
-                                                        *   Do not access directly, use ast_bridged_channel(chan) */
        struct ast_channel *masq;                       /*!< Channel that will masquerade as us */
        struct ast_channel *masqr;                      /*!< Who we are masquerading as */
        const char *blockproc;                          /*!< Procedure causing blocking */
@@ -290,7 +286,6 @@ static void channel_data_add_flags(struct ast_data *tree,
 int ast_channel_data_add_structure(struct ast_data *tree,
        struct ast_channel *chan, int add_bridged)
 {
-       struct ast_channel *bc;
        struct ast_data *data_bridged;
        struct ast_data *data_cdr;
        struct ast_data *data_flags;
@@ -309,7 +304,7 @@ int ast_channel_data_add_structure(struct ast_data *tree,
        ast_data_add_structure(ast_channel, tree, chan);
 
        if (add_bridged) {
-               bc = ast_bridged_channel(chan);
+               RAII_VAR(struct ast_channel *, bc, ast_channel_bridge_peer(chan), ast_channel_cleanup);
                if (bc) {
                        data_bridged = ast_data_add_node(tree, "bridged");
                        if (!data_bridged) {
@@ -1304,15 +1299,6 @@ void ast_channel_internal_bridge_channel_set(struct ast_channel *chan, struct as
        chan->bridge_channel = value;
 }
 
-struct ast_channel *ast_channel_internal_bridged_channel(const struct ast_channel *chan)
-{
-       return chan->bridged_channel;
-}
-void ast_channel_internal_bridged_channel_set(struct ast_channel *chan, struct ast_channel *value)
-{
-       chan->bridged_channel = value;
-}
-
 struct ast_flags *ast_channel_flags(struct ast_channel *chan)
 {
        return &chan->flags;
index 907cb27..1a5333e 100644 (file)
@@ -1298,7 +1298,7 @@ char *ast_rtp_instance_get_quality(struct ast_rtp_instance *instance, enum ast_r
 void ast_rtp_instance_set_stats_vars(struct ast_channel *chan, struct ast_rtp_instance *instance)
 {
        char quality_buf[AST_MAX_USER_FIELD], *quality;
-       struct ast_channel *bridge = ast_bridged_channel(chan);
+       RAII_VAR(struct ast_channel *, bridge, ast_channel_bridge_peer(chan), ast_channel_cleanup);
 
        if ((quality = ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {
                pbx_builtin_setvar_helper(chan, "RTPAUDIOQOS", quality);