<p>Friendly Automation <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/11287">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Kevin Harwell: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res/ari/resource_channels.c: Added hangup reason code for channels<br><br>Currently, DELETE /ari/channels/<channelID> supports only few hangup reasons.<br>It's good enough for simple use, but when it needs to set the detail reason,<br>it comes challenges.<br>Added reason_code query parameter for that.<br><br>ASTERISK-28385<br><br>Change-Id: I1cf1d991ffd759d0591b347445a55f416ddc3ff2<br>---<br>M res/ari/resource_channels.c<br>M res/ari/resource_channels.h<br>M res/res_ari_channels.c<br>M rest-api/api-docs/channels.json<br>4 files changed, 78 insertions(+), 33 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/ari/resource_channels.c b/res/ari/resource_channels.c</span><br><span>index c195eef..1164ab1 100644</span><br><span>--- a/res/ari/resource_channels.c</span><br><span>+++ b/res/ari/resource_channels.c</span><br><span>@@ -49,6 +49,40 @@</span><br><span> #include <limits.h></span><br><span> </span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief Return the corresponded hangup code of the given reason */</span><br><span style="color: hsl(120, 100%, 40%);">+static int convert_reason_to_hangup_code(const char* reason)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!strcmp(reason, "normal")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_CAUSE_NORMAL;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcmp(reason, "busy")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_CAUSE_BUSY;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcmp(reason, "congestion")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_CAUSE_CONGESTION;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcmp(reason, "no_answer")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_CAUSE_NOANSWER;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcmp(reason, "timeout")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_CAUSE_NO_USER_RESPONSE;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcmp(reason, "rejected")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_CAUSE_CALL_REJECTED;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcmp(reason, "unallocated")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_CAUSE_UNALLOCATED;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcmp(reason, "normal_unspecified")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_CAUSE_NORMAL_UNSPECIFIED;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcmp(reason, "number_incomplete")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_CAUSE_INVALID_NUMBER_FORMAT;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcmp(reason, "codec_mismatch")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcmp(reason, "interworking")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_CAUSE_INTERWORKING;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcmp(reason, "failure")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_CAUSE_FAILURE;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if(!strcmp(reason, "answered_elsewhere")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_CAUSE_ANSWERED_ELSEWHERE;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*!</span><br><span> * \brief Ensure channel is in a state that allows operation to be performed.</span><br><span> *</span><br><span>@@ -885,39 +919,34 @@</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_strlen_zero(args->reason) || !strcmp(args->reason, "normal")) {</span><br><span style="color: hsl(0, 100%, 40%);">- cause = AST_CAUSE_NORMAL;</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (!strcmp(args->reason, "busy")) {</span><br><span style="color: hsl(0, 100%, 40%);">- cause = AST_CAUSE_BUSY;</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (!strcmp(args->reason, "congestion")) {</span><br><span style="color: hsl(0, 100%, 40%);">- cause = AST_CAUSE_CONGESTION;</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (!strcmp(args->reason, "no_answer")) {</span><br><span style="color: hsl(0, 100%, 40%);">- cause = AST_CAUSE_NOANSWER;</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (!strcmp(args->reason, "timeout")) {</span><br><span style="color: hsl(0, 100%, 40%);">- cause = AST_CAUSE_NO_USER_RESPONSE;</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (!strcmp(args->reason, "rejected")) {</span><br><span style="color: hsl(0, 100%, 40%);">- cause = AST_CAUSE_CALL_REJECTED;</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (!strcmp(args->reason, "unallocated")) {</span><br><span style="color: hsl(0, 100%, 40%);">- cause = AST_CAUSE_UNALLOCATED;</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (!strcmp(args->reason, "normal_unspecified")) {</span><br><span style="color: hsl(0, 100%, 40%);">- cause = AST_CAUSE_NORMAL_UNSPECIFIED;</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (!strcmp(args->reason, "number_incomplete")) {</span><br><span style="color: hsl(0, 100%, 40%);">- cause = AST_CAUSE_INVALID_NUMBER_FORMAT;</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (!strcmp(args->reason, "codec_mismatch")) {</span><br><span style="color: hsl(0, 100%, 40%);">- cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (!strcmp(args->reason, "interworking")) {</span><br><span style="color: hsl(0, 100%, 40%);">- cause = AST_CAUSE_INTERWORKING;</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (!strcmp(args->reason, "failure")) {</span><br><span style="color: hsl(0, 100%, 40%);">- cause = AST_CAUSE_FAILURE;</span><br><span style="color: hsl(0, 100%, 40%);">- } else if(!strcmp(args->reason, "answered_elsewhere")) {</span><br><span style="color: hsl(0, 100%, 40%);">- cause = AST_CAUSE_ANSWERED_ELSEWHERE;</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_ari_response_error(</span><br><span style="color: hsl(0, 100%, 40%);">- response, 400, "Invalid Reason",</span><br><span style="color: hsl(0, 100%, 40%);">- "Invalid reason for hangup provided");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(args->reason) && !ast_strlen_zero(args->reason_code)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_ari_response_error(response, 400, "Bad Request",</span><br><span style="color: hsl(120, 100%, 40%);">+ "The reason and reason_code can't both be specified");</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(args->reason_code)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* reason_code allows any hangup code */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (sscanf(args->reason_code, "%30d", &cause) != 1) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_ari_response_error(</span><br><span style="color: hsl(120, 100%, 40%);">+ response, 400, "Invalid Reason Code",</span><br><span style="color: hsl(120, 100%, 40%);">+ "Invalid reason for hangup reason code provided");</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!ast_strlen_zero(args->reason)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* reason allows only listed hangup reason */</span><br><span style="color: hsl(120, 100%, 40%);">+ cause = convert_reason_to_hangup_code(args->reason);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (cause == -1) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_ari_response_error(</span><br><span style="color: hsl(120, 100%, 40%);">+ response, 400, "Invalid Reason",</span><br><span style="color: hsl(120, 100%, 40%);">+ "Invalid reason for hangup reason provided");</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* not specified. set default hangup */</span><br><span style="color: hsl(120, 100%, 40%);">+ cause = AST_CAUSE_NORMAL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ast_channel_hangupcause_set(chan, cause);</span><br><span> ast_softhangup(chan, AST_SOFTHANGUP_EXPLICIT);</span><br><span> </span><br><span>diff --git a/res/ari/resource_channels.h b/res/ari/resource_channels.h</span><br><span>index 401c8a5..8aefb40 100644</span><br><span>--- a/res/ari/resource_channels.h</span><br><span>+++ b/res/ari/resource_channels.h</span><br><span>@@ -207,7 +207,9 @@</span><br><span> struct ast_ari_channels_hangup_args {</span><br><span> /*! Channel's id */</span><br><span> const char *channel_id;</span><br><span style="color: hsl(0, 100%, 40%);">- /*! Reason for hanging up the channel */</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! The reason code for hanging up the channel for detail use. Mutually exclusive with 'reason'. See detail hangup codes at here. https://wiki.asterisk.org/wiki/display/AST/Hangup+Cause+Mappings */</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *reason_code;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! Reason for hanging up the channel for simple use. Mutually exclusive with 'reason_code'. */</span><br><span> const char *reason;</span><br><span> };</span><br><span> /*!</span><br><span>diff --git a/res/res_ari_channels.c b/res/res_ari_channels.c</span><br><span>index 73d1e4b..825d4c2 100644</span><br><span>--- a/res/res_ari_channels.c</span><br><span>+++ b/res/res_ari_channels.c</span><br><span>@@ -598,6 +598,10 @@</span><br><span> {</span><br><span> struct ast_json *field;</span><br><span> /* Parse query parameters out of it */</span><br><span style="color: hsl(120, 100%, 40%);">+ field = ast_json_object_get(body, "reason_code");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (field) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args->reason_code = ast_json_string_get(field);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> field = ast_json_object_get(body, "reason");</span><br><span> if (field) {</span><br><span> args->reason = ast_json_string_get(field);</span><br><span>@@ -625,6 +629,9 @@</span><br><span> #endif /* AST_DEVMODE */</span><br><span> </span><br><span> for (i = get_params; i; i = i->next) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcmp(i->name, "reason_code") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ args.reason_code = (i->value);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else</span><br><span> if (strcmp(i->name, "reason") == 0) {</span><br><span> args.reason = (i->value);</span><br><span> } else</span><br><span>diff --git a/rest-api/api-docs/channels.json b/rest-api/api-docs/channels.json</span><br><span>index 4ea5f56..7741269 100644</span><br><span>--- a/rest-api/api-docs/channels.json</span><br><span>+++ b/rest-api/api-docs/channels.json</span><br><span>@@ -407,13 +407,20 @@</span><br><span> "dataType": "string"</span><br><span> },</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ "name": "reason_code",</span><br><span style="color: hsl(120, 100%, 40%);">+ "description": "The reason code for hanging up the channel for detail use. Mutually exclusive with 'reason'. See detail hangup codes at here. https://wiki.asterisk.org/wiki/display/AST/Hangup+Cause+Mappings",</span><br><span style="color: hsl(120, 100%, 40%);">+ "paramType": "query",</span><br><span style="color: hsl(120, 100%, 40%);">+ "required": false,</span><br><span style="color: hsl(120, 100%, 40%);">+ "allowMultiple": false,</span><br><span style="color: hsl(120, 100%, 40%);">+ "dataType": "string"</span><br><span style="color: hsl(120, 100%, 40%);">+ },</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span> "name": "reason",</span><br><span style="color: hsl(0, 100%, 40%);">- "description": "Reason for hanging up the channel",</span><br><span style="color: hsl(120, 100%, 40%);">+ "description": "Reason for hanging up the channel for simple use. Mutually exclusive with 'reason_code'.",</span><br><span> "paramType": "query",</span><br><span> "required": false,</span><br><span> "allowMultiple": false,</span><br><span> "dataType": "string",</span><br><span style="color: hsl(0, 100%, 40%);">- "defalutValue": "normal",</span><br><span> "allowableValues": {</span><br><span> "valueType": "LIST",</span><br><span> "values": [</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/11287">change 11287</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/11287"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I1cf1d991ffd759d0591b347445a55f416ddc3ff2 </div>
<div style="display:none"> Gerrit-Change-Number: 11287 </div>
<div style="display:none"> Gerrit-PatchSet: 5 </div>
<div style="display:none"> Gerrit-Owner: sungtae kim <pchero21@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: sungtae kim <pchero21@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>