diff --git a/include/asterisk/dial.h b/include/asterisk/dial.h index 9a247807022bcfc9a86082e20121edcdde9d8ac2..fe4b63e93b53b66d599e2958af99b9a5f956d009 100644 --- a/include/asterisk/dial.h +++ b/include/asterisk/dial.h @@ -82,6 +82,12 @@ enum ast_dial_result ast_dial_run(struct ast_dial *dial, struct ast_channel *cha */ struct ast_channel *ast_dial_answered(struct ast_dial *dial); +/*! \brief Steal the channel that answered + * \note Returns the Asterisk channel that answered and removes it from the dialing structure + * \param dial Dialing structure + */ +struct ast_channel *ast_dial_answered_steal(struct ast_dial *dial); + /*! \brief Return state of dial * \note Returns the state of the dial attempt * \param dial Dialing structure diff --git a/main/dial.c b/main/dial.c index 7b6ce871ea874a4cc66cef18c0ac867b05d801de..83e6fbd7168f47e4d43898a5bb3232a38dbb56c9 100644 --- a/main/dial.c +++ b/main/dial.c @@ -721,6 +721,25 @@ struct ast_channel *ast_dial_answered(struct ast_dial *dial) return ((dial->state == AST_DIAL_RESULT_ANSWERED) ? AST_LIST_FIRST(&dial->channels)->owner : NULL); } +/*! \brief Steal the channel that answered + * \note Returns the Asterisk channel that answered and removes it from the dialing structure + * \param dial Dialing structure + */ +struct ast_channel *ast_dial_answered_steal(struct ast_dial *dial) +{ + struct ast_channel *chan = NULL; + + if (!dial) + return NULL; + + if (dial->state == AST_DIAL_RESULT_ANSWERED) { + chan = AST_LIST_FIRST(&dial->channels)->owner; + AST_LIST_FIRST(&dial->channels)->owner = NULL; + } + + return chan; +} + /*! \brief Return state of dial * \note Returns the state of the dial attempt * \param dial Dialing structure