From 0aac38c0acb7ce274c77ef1c00265718729e83ac Mon Sep 17 00:00:00 2001 From: "Joshua C. Colp" <jcolp@sangoma.com> Date: Thu, 23 Sep 2021 11:13:17 -0300 Subject: [PATCH] ari: Ignore invisible bridges when listing bridges. When listing bridges we go through the ones present in ARI, get their snapshot, turn it into JSON, and add it to the payload we ultimately return. An invisible "dial bridge" exists within ARI that would also try to be added to this payload if the channel "create" and "dial" routes were used. This would ultimately fail due to invisible bridges having no snapshot resulting in the listing of bridges failing. This change makes it so that the listing of bridges ignores invisible ones. ASTERISK-29668 Change-Id: I14fa4b589b4657d1c2a5226b0f527f45a0cd370a --- res/ari/resource_bridges.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/res/ari/resource_bridges.c b/res/ari/resource_bridges.c index e4e70641a9..d03e86f561 100644 --- a/res/ari/resource_bridges.c +++ b/res/ari/resource_bridges.c @@ -905,12 +905,23 @@ void ast_ari_bridges_list(struct ast_variable *headers, i = ao2_iterator_init(bridges, 0); while ((bridge = ao2_iterator_next(&i))) { - struct ast_bridge_snapshot *snapshot = ast_bridge_get_snapshot(bridge); - /* ast_bridge_snapshot_to_json will return NULL if snapshot is NULL */ - struct ast_json *json_bridge = ast_bridge_snapshot_to_json(snapshot, stasis_app_get_sanitizer()); + struct ast_bridge_snapshot *snapshot; + struct ast_json *json_bridge = NULL; + + /* Invisible bridges don't get shown externally and have no snapshot */ + if (ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_INVISIBLE)) { + ao2_ref(bridge, -1); + continue; + } + + snapshot = ast_bridge_get_snapshot(bridge); + if (snapshot) { + json_bridge = ast_bridge_snapshot_to_json(snapshot, stasis_app_get_sanitizer()); + ao2_ref(snapshot, -1); + } ao2_ref(bridge, -1); - ao2_cleanup(snapshot); + if (!json_bridge || ast_json_array_append(json, json_bridge)) { ao2_iterator_destroy(&i); ast_ari_response_alloc_failed(response); -- GitLab