From e459b8dadf42a3a015b312dfa9aadf507b4c85d9 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 --- main/channel_internal_api.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'main/channel_internal_api.c') diff --git a/main/channel_internal_api.c b/main/channel_internal_api.c index d94b267e6..3c156d4fa 100644 --- a/main/channel_internal_api.c +++ b/main/channel_internal_api.c @@ -1661,3 +1661,25 @@ int ast_channel_internal_setup_topics(struct ast_channel *chan) return 0; } + +AST_THREADSTORAGE(channel_errno); + +void ast_channel_internal_errno_set(enum ast_channel_error error) +{ + enum ast_channel_error *error_code = ast_threadstorage_get(&channel_errno, sizeof(*error_code)); + if (!error_code) { + return; + } + + *error_code = error; +} + +enum ast_channel_error ast_channel_internal_errno(void) +{ + enum ast_channel_error *error_code = ast_threadstorage_get(&channel_errno, sizeof(*error_code)); + if (!error_code) { + return AST_CHANNEL_ERROR_UNKNOWN; + } + + return *error_code; +} -- cgit v1.2.3