summaryrefslogtreecommitdiff
path: root/res/ari/resource_channels.c
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2014-08-18 00:57:01 +0000
committerMatthew Jordan <mjordan@digium.com>2014-08-18 00:57:01 +0000
commitba5d5da60b80b1d639e06d02d7692692281d6063 (patch)
tree4ac71b2c5a6899dbf352eca2942c194b61c0347a /res/ari/resource_channels.c
parent6525f374dbc2198070accbca1a4594d18cc71f9c (diff)
Improve call forwarding reporting, especially with regards to ARI.
This patch addresses a few issues: 1) The order of Dial events have been changed when performing a call forward. The order has now been altered to 1) Dial begins dialing channel A. 2) When A forwards the call to B, we issue the dial end event to channel A, indicating the dial is being canceled due to a forward to B. 3) When the call to channel B occurs, we then issue a new dial begin to channel B. 2) Call forwards are now reported on the calling channel, not the peer channel. 3) AMI DialEnd events have been altered to display the extension the call is being forwarded to when relevant. 4) You can now get the values of channel variables for channels that are not currently in the Stasis application. This brings the retrieval of channel variables more in line with the rest of channel read operations since they may be performed on channels not in Stasis. ASTERISK-24134 #close Reported by Matt Jordan ASTERISK-24138 #close Reported by Matt Jordan Patches: forward-shenanigans.diff uploaded by Matt Jordan (License #6283) Review: https://reviewboard.asterisk.org/r/3899 ........ Merged revisions 420794 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@421310 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/ari/resource_channels.c')
-rw-r--r--res/ari/resource_channels.c39
1 files changed, 33 insertions, 6 deletions
diff --git a/res/ari/resource_channels.c b/res/ari/resource_channels.c
index 23f7fa0f6..0ac53dd73 100644
--- a/res/ari/resource_channels.c
+++ b/res/ari/resource_channels.c
@@ -928,7 +928,8 @@ void ast_ari_channels_get_channel_var(struct ast_variable *headers,
{
RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
- RAII_VAR(char *, value, NULL, ast_free);
+ RAII_VAR(struct ast_str *, value, ast_str_create(32), ast_free);
+ RAII_VAR(struct ast_channel *, channel, NULL, ast_channel_cleanup);
ast_assert(response != NULL);
@@ -939,15 +940,41 @@ void ast_ari_channels_get_channel_var(struct ast_variable *headers,
return;
}
- control = find_control(response, args->channel_id);
- if (control == NULL) {
- /* response filled in by find_control */
+ if (ast_strlen_zero(args->channel_id)) {
+ ast_ari_response_error(
+ response, 400, "Bad Request",
+ "Channel ID is required");
+ return;
+ }
+
+ channel = ast_channel_get_by_name(args->channel_id);
+ if (!channel) {
+ ast_ari_response_error(
+ response, 404, "Channel Not Found",
+ "Provided channel was not found");
return;
}
- value = stasis_app_control_get_channel_var(control, args->variable);
+ /* You may be tempted to lock the channel you're about to read from. You
+ * would be wrong. Some dialplan functions put the channel into
+ * autoservice, which deadlocks if the channel is already locked.
+ * ast_str_retrieve_variable() does its own locking, and the dialplan
+ * functions need to as well. We should be fine without the lock.
+ */
+
+ if (args->variable[strlen(args->variable) - 1] == ')') {
+ if (ast_func_read2(channel, args->variable, &value, 0)) {
+ ast_ari_response_alloc_failed(response);
+ return;
+ }
+ } else {
+ if (!ast_str_retrieve_variable(&value, 0, channel, NULL, args->variable)) {
+ ast_ari_response_alloc_failed(response);
+ return;
+ }
+ }
- if (!(json = ast_json_pack("{s: s}", "value", S_OR(value, "")))) {
+ if (!(json = ast_json_pack("{s: s}", "value", S_OR(ast_str_buffer(value), "")))) {
ast_ari_response_alloc_failed(response);
return;
}