diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h index 46039ac85fa92993d67148c0112532dc609e2a35..c1b99db7d4b03216df9cb503db02d17639713237 100644 --- a/include/asterisk/channel.h +++ b/include/asterisk/channel.h @@ -633,6 +633,9 @@ struct ast_channel_tech { int (* cc_callback)(struct ast_channel *inbound, const char *dest, ast_cc_callback_fn callback); }; +/*! Kill the channel channel driver technology descriptor. */ +extern const struct ast_channel_tech ast_kill_tech; + struct ast_epoll_data; /*! diff --git a/main/channel.c b/main/channel.c index c97268c5056d17ed48e61c243e7d0608d6a06564..103627bc3a6e4320cc865ebbd2161235cba6d791 100644 --- a/main/channel.c +++ b/main/channel.c @@ -612,6 +612,55 @@ static struct ast_cli_entry cli_channel[] = { AST_CLI_DEFINE(handle_cli_core_show_channeltype, "Give more details on that channel type") }; +static struct ast_frame *kill_read(struct ast_channel *chan) +{ + /* Hangup channel. */ + return NULL; +} + +static struct ast_frame *kill_exception(struct ast_channel *chan) +{ + /* Hangup channel. */ + return NULL; +} + +static int kill_write(struct ast_channel *chan, struct ast_frame *frame) +{ + /* Hangup channel. */ + return -1; +} + +static int kill_fixup(struct ast_channel *oldchan, struct ast_channel *newchan) +{ + /* No problem fixing up the channel. */ + return 0; +} + +static int kill_hangup(struct ast_channel *chan) +{ + chan->tech_pvt = NULL; + return 0; +} + +/*! + * \brief Kill the channel channel driver technology descriptor. + * + * \details + * The purpose of this channel technology is to encourage the + * channel to hangup as quickly as possible. + * + * \note Used by DTMF atxfer and zombie channels. + */ +const struct ast_channel_tech ast_kill_tech = { + .type = "Kill", + .description = "Kill channel (should not see this)", + .read = kill_read, + .exception = kill_exception, + .write = kill_write, + .fixup = kill_fixup, + .hangup = kill_hangup, +}; + #ifdef CHANNEL_TRACE /*! \brief Destructor for the channel trace datastore */ static void ast_chan_trace_destroy_cb(void *data) @@ -6613,6 +6662,12 @@ int ast_do_masquerade(struct ast_channel *original) goto done; } + /* + * We just hung up the physical side of the channel. Set the + * new zombie to use the kill channel driver for safety. + */ + clonechan->tech = &ast_kill_tech; + /* Mangle the name of the clone channel */ snprintf(zombn, sizeof(zombn), "%s<ZOMBIE>", orig); /* quick, hide the brains! */ __ast_change_name_nolink(clonechan, zombn); diff --git a/main/features.c b/main/features.c index 1bb86fc3018fe8aeb9114d513e406a014e98536e..e8e9164d3148bc8b93ce5bc88e49b590ecbc7631 100644 --- a/main/features.c +++ b/main/features.c @@ -477,59 +477,16 @@ struct ast_dial_features { int is_caller; }; -#if defined(ATXFER_NULL_TECH) -static struct ast_frame *null_read(struct ast_channel *chan) -{ - /* Hangup channel. */ - return NULL; -} - -static struct ast_frame *null_exception(struct ast_channel *chan) -{ - /* Hangup channel. */ - return NULL; -} - -static int null_write(struct ast_channel *chan, struct ast_frame *frame) -{ - /* Hangup channel. */ - return -1; -} - -static int null_fixup(struct ast_channel *oldchan, struct ast_channel *newchan) -{ - /* No problem fixing up the channel. */ - return 0; -} - -static int null_hangup(struct ast_channel *chan) -{ - chan->tech_pvt = NULL; - return 0; -} - -static const struct ast_channel_tech null_tech = { - .type = "NULL", - .description = "NULL channel driver for atxfer", - .capabilities = -1, - .read = null_read, - .exception = null_exception, - .write = null_write, - .fixup = null_fixup, - .hangup = null_hangup, -}; -#endif /* defined(ATXFER_NULL_TECH) */ - #if defined(ATXFER_NULL_TECH) /*! * \internal - * \brief Set the channel technology to the NULL technology. + * \brief Set the channel technology to the kill technology. * * \param chan Channel to change technology. * * \return Nothing */ -static void set_null_chan_tech(struct ast_channel *chan) +static void set_kill_chan_tech(struct ast_channel *chan) { int idx; @@ -546,8 +503,8 @@ static void set_null_chan_tech(struct ast_channel *chan) chan->tech_pvt = NULL; } - /* Install the NULL technology and wake up anyone waiting on it. */ - chan->tech = &null_tech; + /* Install the kill technology and wake up anyone waiting on it. */ + chan->tech = &ast_kill_tech; for (idx = 0; idx < AST_MAX_FDS; ++idx) { switch (idx) { case AST_ALERT_FD: @@ -3146,7 +3103,7 @@ static struct ast_channel *feature_request_and_dial(struct ast_channel *caller, * Get rid of caller's physical technology so it is free for * other calls. */ - set_null_chan_tech(caller); + set_kill_chan_tech(caller); #endif /* defined(ATXFER_NULL_TECH) */ } else { /* caller is not hungup so monitor it. */ diff --git a/main/format_cap.c b/main/format_cap.c index 3ef0e74d344001a147d870c89b386b4a57a0adb3..63dc0491dffbfba4e8d0c80fa845a6c52157cbb0 100644 --- a/main/format_cap.c +++ b/main/format_cap.c @@ -307,8 +307,11 @@ int ast_format_cap_iscompatible(const struct ast_format_cap *cap, const struct a { struct ast_format *f; struct ast_format_cap *tmp_cap = (struct ast_format_cap *) cap; - f = ao2_find(tmp_cap->formats, (struct ast_format *) format, OBJ_POINTER | tmp_cap->nolock); + if (!tmp_cap) { + return 0; + } + f = ao2_find(tmp_cap->formats, (struct ast_format *) format, OBJ_POINTER | tmp_cap->nolock); if (f) { ao2_ref(f, -1); return 1;