From eff97808fb95e4f9de13c90990f8ef5435352f31 Mon Sep 17 00:00:00 2001 From: Mark Michelson Date: Mon, 17 Oct 2016 14:18:57 -0500 Subject: ARI: Detect duplicate channel IDs ARI and AMI allow for an explicit channel ID to be specified when originating channels. Unfortunately, there is nothing in place to prevent someone from using the same ID for multiple channels. Further complicating things, adding ID validation to channel allocation makes it impossible for ARI to discern why channel allocation failed, resulting in a vague error code being returned. The fix for this is to institute a new method for channel errors to be discerned. The method mirrors errno, in that when an error occurs, the caller can consult the channel errno value to determine what the error was. This initial iteration of the feature only introduces "unknown" and "channel ID exists" errors. However, it's possible to add more errors as needed. ARI uses this feature to determine why channel allocation failed and can return a 409 error during origination to show that a channel with the given ID already exists. ASTERISK-26421 Change-Id: Ibba7ae68842dab6df0c2e9c45559208bc89d3d06 --- res/ari/resource_channels.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'res/ari') diff --git a/res/ari/resource_channels.c b/res/ari/resource_channels.c index 6baac7a4e..04db70451 100644 --- a/res/ari/resource_channels.c +++ b/res/ari/resource_channels.c @@ -1109,7 +1109,12 @@ static void ari_channels_handle_originate_with_id(const char *args_endpoint, } if (ast_dial_prerun(dial, other, format_cap)) { - ast_ari_response_alloc_failed(response); + if (ast_channel_errno() == AST_CHANNEL_ERROR_ID_EXISTS) { + ast_ari_response_error(response, 409, "Conflict", + "Channel with given unique ID already exists"); + } else { + ast_ari_response_alloc_failed(response); + } ast_dial_destroy(dial); ast_free(origination); ast_channel_cleanup(other); -- cgit v1.2.3