Esempio n. 1
0
static int manager_bridge_info(struct mansession *s, const struct message *m)
{
	const char *id = astman_get_header(m, "ActionID");
	const char *bridge_uniqueid = astman_get_header(m, "BridgeUniqueid");
	RAII_VAR(struct ast_str *, id_text, ast_str_create(128), ast_free);
	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
	RAII_VAR(struct ast_str *, bridge_info, NULL, ast_free);
	struct ast_bridge_snapshot *snapshot;
	struct bridge_list_data list_data;

	if (!id_text) {
		astman_send_error(s, m, "Internal error");
		return -1;
	}

	if (ast_strlen_zero(bridge_uniqueid)) {
		astman_send_error(s, m, "BridgeUniqueid must be provided");
		return 0;
	}

	if (!ast_strlen_zero(id)) {
		ast_str_set(&id_text, 0, "ActionID: %s\r\n", id);
	}

	msg = stasis_cache_get(ast_bridge_cache(), ast_bridge_snapshot_type(), bridge_uniqueid);
	if (!msg) {
		astman_send_error(s, m, "Specified BridgeUniqueid not found");
		return 0;
	}

	snapshot = stasis_message_data(msg);
	bridge_info = ast_manager_build_bridge_state_string(snapshot);
	if (!bridge_info) {
		astman_send_error(s, m, "Internal error");
		return -1;
	}

	astman_send_listack(s, m, "Bridge channel listing will follow", "start");

	list_data.id_text = ast_str_buffer(id_text);
	list_data.count = 0;
	ao2_callback_data(snapshot->channels, OBJ_NODATA, send_bridge_info_item_cb, s, &list_data);

	astman_send_list_complete_start(s, m, "BridgeInfoComplete", list_data.count);
	if (!ast_strlen_zero(ast_str_buffer(bridge_info))) {
		astman_append(s, "%s", ast_str_buffer(bridge_info));
	}
	astman_send_list_complete_end(s);

	return 0;
}
Esempio n. 2
0
void ast_ari_bridges_list(struct ast_variable *headers,
	struct ast_ari_bridges_list_args *args,
	struct ast_ari_response *response)
{
	RAII_VAR(struct stasis_cache *, cache, NULL, ao2_cleanup);
	RAII_VAR(struct ao2_container *, snapshots, NULL, ao2_cleanup);
	RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
	struct ao2_iterator i;
	void *obj;

	cache = ast_bridge_cache();
	if (!cache) {
		ast_ari_response_error(
			response, 500, "Internal Server Error",
			"Message bus not initialized");
		return;
	}
	ao2_ref(cache, +1);

	snapshots = stasis_cache_dump(cache, ast_bridge_snapshot_type());
	if (!snapshots) {
		ast_ari_response_alloc_failed(response);
		return;
	}

	json = ast_json_array_create();
	if (!json) {
		ast_ari_response_alloc_failed(response);
		return;
	}

	i = ao2_iterator_init(snapshots, 0);
	while ((obj = ao2_iterator_next(&i))) {
		RAII_VAR(struct stasis_message *, msg, obj, ao2_cleanup);
		struct ast_bridge_snapshot *snapshot = stasis_message_data(msg);
		struct ast_json *json_bridge = ast_bridge_snapshot_to_json(snapshot, stasis_app_get_sanitizer());

		if (!json_bridge || ast_json_array_append(json, json_bridge)) {
			ao2_iterator_destroy(&i);
			ast_ari_response_alloc_failed(response);
			return;
		}
	}
	ao2_iterator_destroy(&i);

	ast_ari_response_ok(response, ast_json_ref(json));
}
Esempio n. 3
0
static int manager_bridges_list(struct mansession *s, const struct message *m)
{
	const char *id = astman_get_header(m, "ActionID");
	const char *type_filter = astman_get_header(m, "BridgeType");
	RAII_VAR(struct ast_str *, id_text, ast_str_create(128), ast_free);
	RAII_VAR(struct ao2_container *, bridges, NULL, ao2_cleanup);
	struct bridge_list_data list_data;

	if (!id_text) {
		astman_send_error(s, m, "Internal error");
		return -1;
	}

	if (!ast_strlen_zero(id)) {
		ast_str_set(&id_text, 0, "ActionID: %s\r\n", id);
	}

	bridges = stasis_cache_dump(ast_bridge_cache(), ast_bridge_snapshot_type());
	if (!bridges) {
		astman_send_error(s, m, "Internal error");
		return -1;
	}

	astman_send_listack(s, m, "Bridge listing will follow", "start");

	if (!ast_strlen_zero(type_filter)) {
		char *type_filter_dup = ast_strdupa(type_filter);

		ao2_callback(bridges, OBJ_MULTIPLE | OBJ_NODATA | OBJ_UNLINK,
			filter_bridge_type_cb, type_filter_dup);
	}

	list_data.id_text = ast_str_buffer(id_text);
	list_data.count = 0;
	ao2_callback_data(bridges, OBJ_NODATA, send_bridge_list_item_cb, s, &list_data);

	astman_send_list_complete_start(s, m, "BridgeListComplete", list_data.count);
	astman_send_list_complete_end(s);

	return 0;
}