From: Joshua C. Colp Date: Wed, 16 Apr 2025 09:29:11 +0000 (-0300) Subject: channel: Always provide cause code in ChannelHangupRequest. X-Git-Tag: 21.9.0-rc1~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92d23a8f085f3187b507a4e5e54a285e6c444cdc;p=thirdparty%2Fasterisk.git channel: Always provide cause code in ChannelHangupRequest. When queueing a channel to be hung up a cause code can be specified in one of two ways: 1. ast_queue_hangup_with_cause This function takes in a cause code and queues it as part of the hangup request, which ultimately results in it being set on the channel. 2. ast_channel_hangupcause_set + ast_queue_hangup This combination sets the hangup cause on the channel before queueing the hangup instead of as part of that process. In the #2 case the ChannelHangupRequest event would not contain the cause code. For consistency if a cause code has been set on the channel it will now be added to the event. Resolves: #1197 (cherry picked from commit bcd0e53ef698bd5131ceb8423e0ed4fb0ea41405) --- diff --git a/main/channel.c b/main/channel.c index c70cc0d4a5..47e888de53 100644 --- a/main/channel.c +++ b/main/channel.c @@ -1168,13 +1168,21 @@ int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *fin) /*! \brief Queue a hangup frame for channel */ int ast_queue_hangup(struct ast_channel *chan) { + RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref); struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP }; - int res; + int res, cause; /* Yeah, let's not change a lock-critical value without locking */ ast_channel_lock(chan); ast_channel_softhangup_internal_flag_add(chan, AST_SOFTHANGUP_DEV); - ast_channel_publish_blob(chan, ast_channel_hangup_request_type(), NULL); + + cause = ast_channel_hangupcause(chan); + if (cause) { + blob = ast_json_pack("{s: i}", + "cause", cause); + } + + ast_channel_publish_blob(chan, ast_channel_hangup_request_type(), blob); res = ast_queue_frame(chan, &f); ast_channel_unlock(chan);