Ejemplo n.º 1
0
static int add_channel_to_bridge(
	struct stasis_app_control *control,
	struct ast_channel *chan, void *obj)
{
	struct ast_bridge *bridge = obj;
	int res;

	res = control_add_channel_to_bridge(control,
		chan, bridge);
	return res;
}
Ejemplo n.º 2
0
static int app_control_dial(struct stasis_app_control *control,
	struct ast_channel *chan, void *data)
{
	RAII_VAR(struct ast_dial *, dial, ast_dial_create(), ast_dial_destroy);
	struct stasis_app_control_dial_data *dial_data = data;
	enum ast_dial_result res;
	char *tech, *resource;
	struct ast_channel *new_chan;
	RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);

	tech = dial_data->endpoint;
	if (!(resource = strchr(tech, '/'))) {
		return -1;
	}
	*resource++ = '\0';

	if (!dial) {
		ast_log(LOG_ERROR, "Failed to create dialing structure.\n");
		return -1;
	}

	if (ast_dial_append(dial, tech, resource, NULL) < 0) {
		ast_log(LOG_ERROR, "Failed to add %s/%s to dialing structure.\n", tech, resource);
		return -1;
	}

	ast_dial_set_global_timeout(dial, dial_data->timeout);

	res = ast_dial_run(dial, NULL, 0);
	if (res != AST_DIAL_RESULT_ANSWERED || !(new_chan = ast_dial_answered_steal(dial))) {
		return -1;
	}

	if (!(bridge = ast_bridge_basic_new())) {
		ast_log(LOG_ERROR, "Failed to create basic bridge.\n");
		return -1;
	}

	if (ast_bridge_impart(bridge, new_chan, NULL, NULL,
		AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
		ast_hangup(new_chan);
	} else {
		control_add_channel_to_bridge(control, chan, bridge);
	}

	return 0;
}