Beispiel #1
0
/*!
 * \internal
 * \brief Peek at channel before it is pushed into bridge
 * \since 13.2.0
 *
 * \param self Bridge to operate upon.
 * \param bridge_channel Bridge channel to push.
 * \param swap Bridge channel to swap places with if not NULL.
 *
 * \note On entry, self is already locked.
 *
 * \retval 0 on success.
 * \retval -1 on failure.  The channel should not be pushed.
 */
static int bridge_stasis_push_peek(struct ast_bridge *self, struct ast_bridge_channel *bridge_channel, struct ast_bridge_channel *swap)
{
    struct stasis_app_control *swap_control;
    struct ast_channel_snapshot *to_be_replaced;

    if (!swap) {
        goto done;
    }

    swap_control = stasis_app_control_find_by_channel(swap->chan);
    if (!swap_control) {
        ast_log(LOG_ERROR,"Failed to find stasis app control for swapped channel %s\n", ast_channel_name(swap->chan));
        return -1;
    }
    to_be_replaced = ast_channel_snapshot_get_latest(ast_channel_uniqueid(swap->chan));

    ast_debug(3, "Copying stasis app name %s from %s to %s\n", app_name(control_app(swap_control)),
              ast_channel_name(swap->chan), ast_channel_name(bridge_channel->chan));

    ast_channel_lock(bridge_channel->chan);

    /* copy the app name from the swap channel */
    app_set_replace_channel_app(bridge_channel->chan, app_name(control_app(swap_control)));

    /* set the replace channel snapshot */
    app_set_replace_channel_snapshot(bridge_channel->chan, to_be_replaced);

    ast_channel_unlock(bridge_channel->chan);

    ao2_ref(swap_control, -1);
    ao2_cleanup(to_be_replaced);

done:
    return ast_bridge_base_v_table.push_peek(self, bridge_channel, swap);
}
Beispiel #2
0
/*!
 * \brief Dial timeout
 *
 * This is a bridge interval hook callback. The interval hook triggering
 * means that the dial timeout has been reached. If the channel has not
 * been answered by the time this callback is called, then the channel
 * is hung up
 *
 * \param bridge_channel Bridge channel on which interval hook has been called
 * \param ignore Ignored
 * \return -1 (i.e. remove the interval hook)
 */
static int bridge_timeout(struct ast_bridge_channel *bridge_channel, void *ignore)
{
	struct ast_datastore *datastore;
	RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);

	control = stasis_app_control_find_by_channel(bridge_channel->chan);

	ast_channel_lock(bridge_channel->chan);
	if (ast_channel_state(bridge_channel->chan) != AST_STATE_UP) {
		/* Don't bother removing the datastore because it will happen when the channel is hung up */
		ast_channel_unlock(bridge_channel->chan);
		stasis_app_send_command_async(control, hangup_channel, NULL, NULL);
		return -1;
	}

	datastore = ast_channel_datastore_find(bridge_channel->chan, &timeout_datastore, NULL);
	if (!datastore) {
		ast_channel_unlock(bridge_channel->chan);
		return -1;
	}
	ast_channel_datastore_remove(bridge_channel->chan, datastore);
	ast_channel_unlock(bridge_channel->chan);
	ast_datastore_free(datastore);

	return -1;
}
Beispiel #3
0
/*!
 * \internal
 * \brief Push this channel into the Stasis bridge.
 * \since 12.5.0
 *
 * \param self Bridge to operate upon.
 * \param bridge_channel Bridge channel to push.
 * \param swap Bridge channel to swap places with if not NULL.
 *
 * \note On entry, self is already locked.
 *
 * \retval 0 on success.
 * \retval -1 on failure.  The channel did not get pushed.
 */
static int bridge_stasis_push(struct ast_bridge *self, struct ast_bridge_channel *bridge_channel, struct ast_bridge_channel *swap)
{
    struct stasis_app_control *control = stasis_app_control_find_by_channel(bridge_channel->chan);

    if (!control && !stasis_app_channel_is_internal(bridge_channel->chan)) {
        /* channel not in Stasis(), get it there */
        ast_debug(1, "Bridge %s: pushing non-stasis %p(%s) setup to come back in under stasis\n",
                  self->uniqueid, bridge_channel, ast_channel_name(bridge_channel->chan));

        /* Attach after-bridge callback and pass ownership of swap_app to it */
        if (ast_bridge_set_after_callback(bridge_channel->chan,
                                          bridge_stasis_run_cb, NULL, NULL)) {
            ast_log(LOG_ERROR,
                    "Failed to set after bridge callback for bridge %s non-stasis push of %s\n",
                    self->uniqueid, ast_channel_name(bridge_channel->chan));
            return -1;
        }

        bridge_stasis_queue_join_action(self, bridge_channel, swap);

        /* Return -1 so the push fails and the after-bridge callback gets called
         * This keeps the bridging framework from putting the channel into the bridge
         * until the Stasis thread gets started, and then the channel is put into the bridge.
         */
        return -1;
    }

    /*
     * If going into a holding bridge, default the role to participant, if
     * it has no compatible role currently
     */
    if ((self->technology->capabilities & AST_BRIDGE_CAPABILITY_HOLDING)
            && !ast_channel_has_role(bridge_channel->chan, "announcer")
            && !ast_channel_has_role(bridge_channel->chan, "holding_participant")) {
        if (ast_channel_add_bridge_role(bridge_channel->chan, "holding_participant")) {
            ast_log(LOG_ERROR, "Failed to set holding participant on %s\n", ast_channel_name(bridge_channel->chan));
            return -1;
        }

        if (ast_channel_set_bridge_role_option(bridge_channel->chan, "holding_participant", "idle_mode", "none")) {
            ast_log(LOG_ERROR, "Failed to set holding participant mode on %s\n", ast_channel_name(bridge_channel->chan));
            return -1;
        }
    }

    ao2_cleanup(control);
    if (self->allowed_capabilities & STASIS_BRIDGE_MIXING_CAPABILITIES) {
        ast_bridge_channel_update_linkedids(bridge_channel, swap);
        if (ast_test_flag(&self->feature_flags, AST_BRIDGE_FLAG_SMART)) {
            ast_bridge_channel_update_accountcodes(bridge_channel, swap);
        }
    }

    return ast_bridge_base_v_table.push(self, bridge_channel, swap);
}
Beispiel #4
0
static int bridge_stasis_moving(struct ast_bridge_channel *bridge_channel, void *hook_pvt,
                                struct ast_bridge *src, struct ast_bridge *dst)
{
    if (src->v_table == &bridge_stasis_v_table &&
            dst->v_table != &bridge_stasis_v_table) {
        RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
        struct ast_channel *chan;

        chan = bridge_channel->chan;
        ast_assert(chan != NULL);

        control = stasis_app_control_find_by_channel(chan);
        if (!control) {
            return -1;
        }

        stasis_app_channel_set_stasis_end_published(chan);
        app_send_end_msg(control_app(control), chan);
    }

    return -1;
}
Beispiel #5
0
/*!
 * \brief Performs common setup for a bridge playback operation
 * with both new controls and when existing controls are  found.
 *
 * \param args_media media string split from arguments
 * \param args_lang language string split from arguments
 * \param args_offset_ms milliseconds offset split from arguments
 * \param args_playback_id string to use for playback split from
 *        arguments (null valid)
 * \param response ARI response being built
 * \param bridge Bridge the playback is being peformed on
 * \param found_channel The channel that was found controlling playback
 *
 * \retval PLAY_FOUND_SUCCESS The operation was successful
 * \retval PLAY_FOUND_FAILURE The operation failed (terminal failure)
 * \retval PLAY_FOUND_CHANNEL_UNAVAILABLE The operation failed because
 * the channel requested to playback with is breaking down.
 */
static enum play_found_result ari_bridges_play_found(const char *args_media,
	const char *args_lang,
	int args_offset_ms,
	int args_skipms,
	const char *args_playback_id,
	struct ast_ari_response *response,
	struct ast_bridge *bridge,
	struct ast_channel *found_channel)
{
	RAII_VAR(struct ast_channel *, play_channel, found_channel, ao2_cleanup);
	RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
	RAII_VAR(char *, playback_url, NULL, ast_free);
	RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);

	control = stasis_app_control_find_by_channel(play_channel);
	if (!control) {
		ast_ari_response_error(
			response, 500, "Internal Error", "Failed to get control snapshot");
		return PLAY_FOUND_FAILURE;
	}

	ao2_lock(control);
	if (stasis_app_control_is_done(control)) {
		/* We failed to queue the action. Bailout and return that we aren't terminal. */
		ao2_unlock(control);
		return PLAY_FOUND_CHANNEL_UNAVAILABLE;
	}

	if (ari_bridges_play_helper(args_media, args_lang, args_offset_ms,
			args_skipms, args_playback_id, response, bridge, control,
			&json, &playback_url)) {
		ao2_unlock(control);
		return PLAY_FOUND_FAILURE;
	}
	ao2_unlock(control);

	ast_ari_response_created(response, playback_url, ast_json_ref(json));
	return PLAY_FOUND_SUCCESS;
}