All pastes #941680 Raw Edit

Mine

public text v1 · immutable
·published 2008-03-13 21:32 UTC
rendered paste body
Index: apps/app_chanspy.c
===================================================================
--- apps/app_chanspy.c  (revision 108534)
+++ apps/app_chanspy.c  (working copy)
@@ -390,9 +390,19 @@
        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)
Index: include/asterisk/channel.h
===================================================================
--- include/asterisk/channel.h  (revision 108534)
+++ include/asterisk/channel.h  (working copy)
@@ -154,6 +154,21 @@
        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 */
Index: main/channel.c
===================================================================
--- main/channel.c      (revision 108534)
+++ main/channel.c      (working copy)
@@ -3494,8 +3494,14 @@
 
        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 */