summaryrefslogtreecommitdiff
path: root/main/channel.c
diff options
context:
space:
mode:
authorKinsey Moore <kmoore@digium.com>2014-06-26 12:43:47 +0000
committerKinsey Moore <kmoore@digium.com>2014-06-26 12:43:47 +0000
commite977b7936b02bcd33a35bf7c4e5b51f496f727e5 (patch)
tree02c6fd7d4127021f3e20f783e350da4d78123bbd /main/channel.c
parent22e62ac6f640f6442968e5ab9146d3a7fe496f95 (diff)
Bridging: Allow channels to define bridging hooks
This patch allows the current owner of a channel to define various feature hooks to be made available once the channel has entered a bridge. This includes any hooks that are setup on the ast_bridge_features struct such as DTMF hooks, bridge event hooks (join, leave, etc.), and interval hooks. Review: https://reviewboard.asterisk.org/r/3649/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@417361 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/channel.c')
-rw-r--r--main/channel.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/main/channel.c b/main/channel.c
index 04c396a71..7d9f04837 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -10453,3 +10453,71 @@ void ast_channel_end_dtmf(struct ast_channel *chan, char digit, struct timeval s
ast_log(LOG_DTMF, "DTMF end '%c' simulated on %s due to %s, duration %ld ms\n",
digit, ast_channel_name(chan), why, duration);
}
+
+static void features_destroy(void *obj)
+{
+ ast_bridge_features_destroy(obj);
+}
+
+static const struct ast_datastore_info bridge_features_info = {
+ .type = "bridge-features",
+ .destroy = features_destroy,
+};
+
+struct ast_bridge_features *ast_channel_feature_hooks_get(struct ast_channel *chan)
+{
+ struct ast_datastore *datastore;
+
+ datastore = ast_channel_datastore_find(chan, &bridge_features_info, NULL);
+ if (!datastore) {
+ return NULL;
+ }
+ return datastore->data;
+}
+
+static int channel_feature_hooks_set_full(struct ast_channel *chan, struct ast_bridge_features *features, int replace)
+{
+ struct ast_datastore *datastore;
+ struct ast_bridge_features *ds_features;
+
+ datastore = ast_channel_datastore_find(chan, &bridge_features_info, NULL);
+ if (datastore) {
+ ds_features = datastore->data;
+ if (replace) {
+ ast_bridge_features_cleanup(ds_features);
+ ast_bridge_features_init(ds_features);
+ }
+ if (features) {
+ ast_bridge_features_merge(ds_features, features);
+ }
+ return 0;
+ }
+
+ datastore = ast_datastore_alloc(&bridge_features_info, NULL);
+ if (!datastore) {
+ return -1;
+ }
+
+ ds_features = ast_bridge_features_new();
+ if (!ds_features) {
+ ast_datastore_free(datastore);
+ return -1;
+ }
+
+ if (features) {
+ ast_bridge_features_merge(ds_features, features);
+ }
+ datastore->data = ds_features;
+ ast_channel_datastore_add(chan, datastore);
+ return 0;
+}
+
+int ast_channel_feature_hooks_append(struct ast_channel *chan, struct ast_bridge_features *features)
+{
+ return channel_feature_hooks_set_full(chan, features, 0);
+}
+
+int ast_channel_feature_hooks_replace(struct ast_channel *chan, struct ast_bridge_features *features)
+{
+ return channel_feature_hooks_set_full(chan, features, 1);
+}