[Asterisk-code-review] Bridging: introduce "invisible" bridges. (asterisk[master])
Mark Michelson
asteriskteam at digium.com
Mon May 9 15:04:36 CDT 2016
Mark Michelson has uploaded a new change for review.
https://gerrit.asterisk.org/2789
Change subject: Bridging: introduce "invisible" bridges.
......................................................................
Bridging: introduce "invisible" bridges.
Invisible bridges function the same as normal bridges, but they have the
following restrictions:
* They never show up in CLI, AMI, or ARI queries.
* They cannot be merged with other bridges.
* They cannot be involved in transfers.
* They do not have Stasis messages published about them.
Invisible bridges' main use is for when use of the bridging system is
desired, but the bridge should not be known to users of the Asterisk
system.
Change-Id: I804a209d3181d7c54e3d61a60eb462e7ce0e3670
---
M include/asterisk/bridge_features.h
M main/bridge.c
M main/manager_bridges.c
M main/stasis_bridges.c
M main/stasis_channels.c
5 files changed, 42 insertions(+), 11 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/89/2789/1
diff --git a/include/asterisk/bridge_features.h b/include/asterisk/bridge_features.h
index df01a0d..7fcb85b 100644
--- a/include/asterisk/bridge_features.h
+++ b/include/asterisk/bridge_features.h
@@ -53,6 +53,8 @@
AST_BRIDGE_FLAG_TRANSFER_PROHIBITED = (1 << 8),
/*! Bridge transfers require transfer of entire bridge rather than individual channels */
AST_BRIDGE_FLAG_TRANSFER_BRIDGE_ONLY = (1 << 9),
+ /*! Bridge is invisible to AMI/CLI/ARI/etc. */
+ AST_BRIDGE_FLAG_INVISIBLE = (1 << 10),
};
/*! \brief Flags used for per bridge channel features */
diff --git a/main/bridge.c b/main/bridge.c
index ce6b960..3a87fd0 100644
--- a/main/bridge.c
+++ b/main/bridge.c
@@ -759,11 +759,13 @@
ast_set_flag(&self->feature_flags, flags);
self->allowed_capabilities = capabilities;
- if (bridge_topics_init(self) != 0) {
- ast_log(LOG_WARNING, "Bridge %s: Could not initialize topics\n",
- self->uniqueid);
- ao2_ref(self, -1);
- return NULL;
+ if (!(flags & AST_BRIDGE_FLAG_INVISIBLE)) {
+ if (bridge_topics_init(self) != 0) {
+ ast_log(LOG_WARNING, "Bridge %s: Could not initialize topics\n",
+ self->uniqueid);
+ ao2_ref(self, -1);
+ return NULL;
+ }
}
/* Use our helper function to find the "best" bridge technology. */
@@ -793,9 +795,11 @@
return NULL;
}
- if (!ast_bridge_topic(self)) {
- ao2_ref(self, -1);
- return NULL;
+ if (!(flags & AST_BRIDGE_FLAG_INVISIBLE)) {
+ if (!ast_bridge_topic(self)) {
+ ao2_ref(self, -1);
+ return NULL;
+ }
}
return self;
@@ -2309,6 +2313,11 @@
ast_assert(dst_bridge && src_bridge);
ast_bridge_lock_both(dst_bridge, src_bridge);
+ if (ast_test_flag(&dst_bridge->feature_flags, AST_BRIDGE_FLAG_INVISIBLE) || ast_test_flag(&src_bridge->feature_flags, AST_BRIDGE_FLAG_INVISIBLE)) {
+ ast_bridge_unlock(src_bridge);
+ ast_bridge_unlock(dst_bridge);
+ return -1;
+ }
res = bridge_merge_locked(dst_bridge, src_bridge, merge_best_direction, kick_me, num_kick);
ast_bridge_unlock(src_bridge);
ast_bridge_unlock(dst_bridge);
@@ -4322,7 +4331,7 @@
ast_channel_unlock(chan);
if (bridge
- && ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_MASQUERADE_ONLY)) {
+ && (ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_MASQUERADE_ONLY | AST_BRIDGE_FLAG_INVISIBLE))) {
ao2_ref(bridge, -1);
bridge = NULL;
}
diff --git a/main/manager_bridges.c b/main/manager_bridges.c
index dd3e98b..2069d50 100644
--- a/main/manager_bridges.c
+++ b/main/manager_bridges.c
@@ -572,7 +572,7 @@
}
} else {
bridge = ast_bridge_find_by_id(bridge_uniqueid);
- if (!bridge) {
+ if (!bridge || ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_INVISIBLE)) {
astman_send_error(s, m, "Bridge not found");
return 0;
}
diff --git a/main/stasis_bridges.c b/main/stasis_bridges.c
index d06ee14..234a72e 100644
--- a/main/stasis_bridges.c
+++ b/main/stasis_bridges.c
@@ -276,6 +276,10 @@
ast_assert(bridge != NULL);
+ if (ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_INVISIBLE)) {
+ return;
+ }
+
snapshot = ast_bridge_snapshot_create(bridge);
if (!snapshot) {
return;
@@ -295,6 +299,10 @@
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
ast_assert(obj != NULL);
+
+ if (ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_INVISIBLE)) {
+ return;
+ }
msg = stasis_message_create(ast_bridge_snapshot_type(), obj->bridge);
if (!msg) {
@@ -371,6 +379,8 @@
ast_assert(to != NULL);
ast_assert(from != NULL);
+ ast_assert(ast_test_flag(&to->feature_flags, AST_BRIDGE_FLAG_INVISIBLE) == 0);
+ ast_assert(ast_test_flag(&from->feature_flags, AST_BRIDGE_FLAG_INVISIBLE) == 0);
merge_msg = bridge_merge_message_create(to, from);
if (!merge_msg) {
@@ -447,6 +457,10 @@
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+ if (ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_INVISIBLE)) {
+ return;
+ }
+
if (swap) {
blob = ast_json_pack("{s: s}", "swap", ast_channel_uniqueid(swap));
if (!blob) {
@@ -468,6 +482,10 @@
{
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+ if (ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_INVISIBLE)) {
+ return;
+ }
+
msg = ast_bridge_blob_create(ast_channel_left_bridge_type(), bridge, chan, NULL);
if (!msg) {
return;
diff --git a/main/stasis_channels.c b/main/stasis_channels.c
index eb1f1bc..e56d1b9 100644
--- a/main/stasis_channels.c
+++ b/main/stasis_channels.c
@@ -256,7 +256,9 @@
ast_string_field_set(snapshot, language, ast_channel_language(chan));
if ((bridge = ast_channel_get_bridge(chan))) {
- ast_string_field_set(snapshot, bridgeid, bridge->uniqueid);
+ if (!ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_INVISIBLE)) {
+ ast_string_field_set(snapshot, bridgeid, bridge->uniqueid);
+ }
ao2_cleanup(bridge);
}
--
To view, visit https://gerrit.asterisk.org/2789
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I804a209d3181d7c54e3d61a60eb462e7ce0e3670
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Mark Michelson <mmichelson at digium.com>
More information about the asterisk-code-review
mailing list