diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-03-13 21:40:43 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-03-13 21:40:43 +0000 |
commit | 9acd41d1bcca37513692cef6456f1bff53098980 (patch) | |
tree | 104d02463b6f0b711b7802bc61a346ea6985044f | |
parent | d0afc7be659112525da26c2aabe6d937abccb9e4 (diff) |
Merged revisions 108583 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r108583 | russell | 2008-03-13 16:38:16 -0500 (Thu, 13 Mar 2008) | 11 lines
Fix another issue that was causing crashes in chanspy. This introduces a new
datastore callback, called chan_fixup(). The concept is exactly like the
fixup callback that is used in the channel technology interface. This callback
gets called when the owning channel changes due to a masquerade. Before this
was introduced, if a masquerade happened on a channel being spyed on, the
channel pointer in the datastore became invalid.
(closes issue #12187)
(reported by, and lots of testing from atis)
(props to file for the help with ideas)
........
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@108584 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r-- | apps/app_chanspy.c | 10 | ||||
-rw-r--r-- | include/asterisk/channel.h | 15 | ||||
-rw-r--r-- | main/channel.c | 8 |
3 files changed, 32 insertions, 1 deletions
diff --git a/apps/app_chanspy.c b/apps/app_chanspy.c index d7047d047..32d5e7c0b 100644 --- a/apps/app_chanspy.c +++ b/apps/app_chanspy.c @@ -427,9 +427,19 @@ static void chanspy_ds_destroy(void *data) ast_mutex_unlock(&chanspy_ds->lock); } +static void chanspy_ds_chan_fixup(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan) +{ + struct chanspy_ds *chanspy_ds = data; + + ast_mutex_lock(&chanspy_ds->lock); + chanspy_ds->chan = new_chan; + ast_mutex_unlock(&chanspy_ds->lock); +} + static const struct ast_datastore_info chanspy_ds_info = { .type = "chanspy", .destroy = chanspy_ds_destroy, + .chan_fixup = chanspy_ds_chan_fixup, }; static struct chanspy_ds *chanspy_ds_free(struct chanspy_ds *chanspy_ds) diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h index e5fd5ba81..ddba96f89 100644 --- a/include/asterisk/channel.h +++ b/include/asterisk/channel.h @@ -191,6 +191,21 @@ struct ast_datastore_info { const char *type; /*!< Type of data store */ void *(*duplicate)(void *data); /*!< Duplicate item data (used for inheritance) */ void (*destroy)(void *data); /*!< Destroy function */ + /*! + * \brief Fix up channel references + * + * \arg data The datastore data + * \arg old_chan The old channel owning the datastore + * \arg new_chan The new channel owning the datastore + * + * This is exactly like the fixup callback of the channel technology interface. + * It allows a datastore to fix any pointers it saved to the owning channel + * in case that the owning channel has changed. Generally, this would happen + * when the datastore is set to be inherited, and a masquerade occurs. + * + * \return nothing. + */ + void (*chan_fixup)(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan); }; /*! \brief Structure for a channel data store */ diff --git a/main/channel.c b/main/channel.c index 93f6f58f3..aeb4845cc 100644 --- a/main/channel.c +++ b/main/channel.c @@ -3878,8 +3878,14 @@ int ast_do_masquerade(struct ast_channel *original) ast_app_group_update(clone, original); /* Move data stores over */ - if (AST_LIST_FIRST(&clone->datastores)) + if (AST_LIST_FIRST(&clone->datastores)) { + struct ast_datastore *ds; AST_LIST_APPEND_LIST(&original->datastores, &clone->datastores, entry); + AST_LIST_TRAVERSE(&original->datastores, ds, entry) { + if (ds->info->chan_fixup) + ds->info->chan_fixup(ds->data, clone, original); + } + } clone_variables(original, clone); /* Presense of ADSI capable CPE follows clone */ |