[asterisk-commits] tilghman: trunk r57691 - in /trunk:
include/asterisk/channel.h main/channel.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Sat Mar 3 07:40:19 MST 2007
Author: tilghman
Date: Sat Mar 3 08:40:18 2007
New Revision: 57691
URL: http://svn.digium.com/view/asterisk?view=rev&rev=57691
Log:
Expand datastores to add the notion of inheritance. This will be needed for
the conversion of IAX2 variables from the current custom method to ast_storage.
Modified:
trunk/include/asterisk/channel.h
trunk/main/channel.c
Modified: trunk/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/channel.h?view=diff&rev=57691&r1=57690&r2=57691
==============================================================================
--- trunk/include/asterisk/channel.h (original)
+++ trunk/include/asterisk/channel.h Sat Mar 3 08:40:18 2007
@@ -153,7 +153,9 @@
#include "asterisk/linkedlists.h"
#include "asterisk/stringfields.h"
#include "asterisk/compiler.h"
-
+#include <limits.h>
+
+#define DATASTORE_INHERIT_FOREVER INT_MAX
#define AST_MAX_FDS 10
/*
@@ -185,6 +187,7 @@
/*! \brief Structure for a data store type */
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 */
};
@@ -193,6 +196,7 @@
char *uid; /*!< Unique data store identifier */
void *data; /*!< Contained data */
const struct ast_datastore_info *info; /*!< Data store type information */
+ unsigned int inheritance; /*!< Number of levels this item will continue to be inherited */
AST_LIST_ENTRY(ast_datastore) entry; /*!< Used for easy linking */
};
@@ -608,6 +612,9 @@
/*! \brief Free a channel datastore structure */
int ast_channel_datastore_free(struct ast_datastore *datastore);
+/*! \brief Inherit datastores from a parent to a child. */
+int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to);
+
/*! \brief Add a datastore to a channel */
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore);
Modified: trunk/main/channel.c
URL: http://svn.digium.com/view/asterisk/trunk/main/channel.c?view=diff&rev=57691&r1=57690&r2=57691
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Sat Mar 3 08:40:18 2007
@@ -1145,7 +1145,7 @@
/* Free allocated UID memory */
if (datastore->uid != NULL) {
- free(datastore->uid);
+ ast_free(datastore->uid);
datastore->uid = NULL;
}
@@ -1153,6 +1153,23 @@
free(datastore);
return res;
+}
+
+int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to)
+{
+ struct ast_datastore *datastore = NULL, *datastore2;
+
+ AST_LIST_TRAVERSE(&from->datastores, datastore, entry) {
+ if (datastore->inheritance > 0) {
+ datastore2 = ast_channel_datastore_alloc(datastore->info, datastore->uid);
+ if (datastore2) {
+ datastore2->data = datastore->info->duplicate(datastore->data);
+ datastore2->inheritance = datastore->inheritance == DATASTORE_INHERIT_FOREVER ? DATASTORE_INHERIT_FOREVER : datastore->inheritance - 1;
+ AST_LIST_INSERT_TAIL(&to->datastores, datastore2, entry);
+ }
+ }
+ }
+ return 0;
}
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
@@ -2817,8 +2834,10 @@
/* XXX why is this necessary, for the parent_channel perhaps ? */
if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name))
ast_set_callerid(chan, oh->cid_num, oh->cid_name, oh->cid_num);
- if (oh->parent_channel)
+ if (oh->parent_channel) {
ast_channel_inherit_variables(oh->parent_channel, chan);
+ ast_channel_datastore_inherit(oh->parent_channel, chan);
+ }
if (oh->account)
ast_cdr_setaccount(chan, oh->account);
}
More information about the asterisk-commits
mailing list