summaryrefslogtreecommitdiff
path: root/res/ari/resource_channels.c
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2014-07-07 02:15:00 +0000
committerMatthew Jordan <mjordan@digium.com>2014-07-07 02:15:00 +0000
commitd4b436d0ea766d51d7743a874df441d40fdcd226 (patch)
tree955ebd4c8cf179d6dcdcdbfa6a32ac654f3600a9 /res/ari/resource_channels.c
parentedcaa54019a14cdfd2d5e8453b15a52819cecb36 (diff)
ARI/res_stasis: Subscribe to both Local channel halves when originating to app
This patch fixes two bugs: 1. When originating a channel into a Stasis application, we already create a subscription for the channel that is going into our Stasis app. Unfortunately, when you create a Local channel and pass it off to a Stasis app, you really aren't creating just one channel: you're creating two. This patch snags the second half of the Local channel pair (assuming it is a Local channel pair, but luckily core_local is kind about such assumptions) and subscribes to it as well. 2. Subscriptions are a bit sticky right now. If a subscription is made, the 'interest' count gets bumped on the Stasis subscription - but unless something explicitly unsubscribes the channel, said subscription sticks around. This is not much of a problem is a user is creating the subscription - if they made it, they must want it. However, when we are creating implicit subscriptions, we need to make sure something clears them out. This patch takes a pessimistic approach: it watches the cache updates coming from Stasis and, if we notice that the cache just cleared out an object, we delete our subscription object. This keeps our ao2 container of Stasis forwards in an application from growing out of hand; it also is a bit more forgiving for end users who may not realize they were supposed to unsubscribe from that channel that just hung up. Review: https://reviewboard.asterisk.org/r/3710/ #ASTERISK-23939 #close ........ Merged revisions 418089 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@418090 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/ari/resource_channels.c')
-rw-r--r--res/ari/resource_channels.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/res/ari/resource_channels.c b/res/ari/resource_channels.c
index 6cc00ce41..393609298 100644
--- a/res/ari/resource_channels.c
+++ b/res/ari/resource_channels.c
@@ -42,6 +42,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/stasis_app_snoop.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/causes.h"
+#include "asterisk/core_local.h"
#include "resource_channels.h"
#include <limits.h>
@@ -775,6 +776,7 @@ static void ari_channels_handle_originate_with_id(const char *args_endpoint,
struct ast_format tmp_fmt;
char *stuff;
struct ast_channel *chan;
+ struct ast_channel *local_peer;
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
struct ast_assigned_ids assignedids = {
.uniqueid = args_channel_id,
@@ -859,20 +861,24 @@ static void ari_channels_handle_originate_with_id(const char *args_endpoint,
return;
}
- snapshot = ast_channel_snapshot_get_latest(ast_channel_uniqueid(chan));
- ast_channel_unlock(chan);
+ /* See if this is a Local channel and if so, get the peer */
+ local_peer = ast_local_get_peer(chan);
if (!ast_strlen_zero(args_app)) {
- /* channel: + channel ID + null terminator */
- char uri[9 + strlen(ast_channel_uniqueid(chan))];
- const char *uris[1] = { uri, };
-
- sprintf(uri, "channel:%s", ast_channel_uniqueid(chan));
- stasis_app_subscribe(args_app, uris, 1, NULL);
+ stasis_app_subscribe_channel(args_app, chan);
+ if (local_peer) {
+ stasis_app_subscribe_channel(args_app, local_peer);
+ }
}
+ snapshot = ast_channel_snapshot_get_latest(ast_channel_uniqueid(chan));
+ ast_channel_unlock(chan);
+
ast_ari_response_ok(response, ast_channel_snapshot_to_json(snapshot, NULL));
ast_channel_unref(chan);
+ if (local_peer) {
+ ast_channel_unref(local_peer);
+ }
}
void ast_ari_channels_originate_with_id(struct ast_variable *headers,