[Asterisk-cvs] asterisk chanvars.c,1.4,1.5 pbx.c,1.166,1.167
markster at lists.digium.com
markster at lists.digium.com
Sun Oct 31 21:20:48 CST 2004
Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv17737
Modified Files:
chanvars.c pbx.c
Log Message:
Make channel variables inheritable by _ (bug #928)
Index: chanvars.c
===================================================================
RCS file: /usr/cvsroot/asterisk/chanvars.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- chanvars.c 24 Oct 2004 02:53:24 -0000 1.4
+++ chanvars.c 1 Nov 2004 02:23:27 -0000 1.5
@@ -70,6 +70,25 @@
char *ast_var_name(struct ast_var_t *var)
{
+ char *name;
+
+ if (var == NULL)
+ return NULL;
+ if (var->name == NULL)
+ return NULL;
+ /* Return the name without the initial underscores */
+ if ((strlen(var->name) > 0) && (var->name[0] == '_')) {
+ if ((strlen(var->name) > 1) && (var->name[1] == '_'))
+ name = (char*)&(var->name[2]);
+ else
+ name = (char*)&(var->name[1]);
+ } else
+ name = var->name;
+ return name;
+}
+
+char *ast_var_full_name(struct ast_var_t *var)
+{
return (var != NULL ? var->name : NULL);
}
Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.166
retrieving revision 1.167
diff -u -d -r1.166 -r1.167
--- pbx.c 27 Oct 2004 02:26:17 -0000 1.166
+++ pbx.c 1 Nov 2004 02:23:27 -0000 1.167
@@ -56,6 +56,10 @@
#define EXT_DATA_SIZE 8192
#endif
+#define VAR_NORMAL 1
+#define VAR_SOFTTRAN 2
+#define VAR_HARDTRAN 3
+
struct ast_context;
/* ast_exten: An extension */
@@ -375,8 +379,8 @@
{ "SetVar", pbx_builtin_setvar,
"Set variable to value",
- " Setvar(#n=value): Sets channel specific variable n to value"
- },
+ " SetVar(#n=value): Sets variable n to value. If prefixed with _, single\n"
+ "inheritance assumed. If prefixed with __, infinite inheritance is assumed.\n" },
{ "StripMSD", pbx_builtin_stripmsd,
"Strip leading digits",
@@ -4970,29 +4974,30 @@
return NULL;
}
-void pbx_builtin_setvar_helper(struct ast_channel *chan, char *name, char *value)
+void pbx_builtin_setvar_helper(struct ast_channel *chan, char *name, char *value)
{
struct ast_var_t *newvariable;
struct varshead *headp;
+
if (chan)
- headp=&chan->varshead;
+ headp = &chan->varshead;
else
- headp=&globals;
-
- AST_LIST_TRAVERSE (headp,newvariable,entries) {
- if (strcasecmp(ast_var_name(newvariable),name)==0) {
+ headp = &globals;
+
+ AST_LIST_TRAVERSE (headp, newvariable, entries) {
+ if (strcasecmp(ast_var_name(newvariable), name) == 0) {
/* there is already such a variable, delete it */
- AST_LIST_REMOVE(headp,newvariable,ast_var_t,entries);
+ AST_LIST_REMOVE(headp, newvariable, ast_var_t, entries);
ast_var_delete(newvariable);
break;
}
}
-
+
if (value) {
if ((option_verbose > 1) && (headp == &globals))
- ast_verbose(VERBOSE_PREFIX_3 "Setting global variable '%s' to '%s'\n",name, value);
- newvariable=ast_var_assign(name,value);
- AST_LIST_INSERT_HEAD(headp,newvariable,entries);
+ ast_verbose(VERBOSE_PREFIX_3 "Setting global variable '%s' to '%s'\n", name, value);
+ newvariable = ast_var_assign(name, value);
+ AST_LIST_INSERT_HEAD(headp, newvariable, entries);
}
}
@@ -5001,41 +5006,40 @@
char *name;
char *value;
char *stringp=NULL;
-
+
if (!data || ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Ignoring, since there is no variable to set\n");
return 0;
}
-
- stringp=data;
- name=strsep(&stringp,"=");
- value=strsep(&stringp,"\0");
-
- pbx_builtin_setvar_helper(chan,name,value);
-
- return(0);
+
+ stringp = data;
+ name = strsep(&stringp,"=");
+ value = strsep(&stringp,"\0");
+
+ pbx_builtin_setvar_helper(chan, name, value);
+
+ return(0);
}
static int pbx_builtin_setglobalvar(struct ast_channel *chan, void *data)
{
char *name;
char *value;
- char *stringp=NULL;
-
+ char *stringp = NULL;
+
if (!data || ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Ignoring, since there is no variable to set\n");
return 0;
}
-
- stringp=data;
- name=strsep(&stringp,"=");
- value=strsep(&stringp,"\0");
-
- pbx_builtin_setvar_helper(NULL,name,value);
-
- return(0);
-}
+ stringp = data;
+ name = strsep(&stringp, "=");
+ value = strsep(&stringp, "\0");
+
+ pbx_builtin_setvar_helper(NULL, name, value);
+
+ return(0);
+}
static int pbx_builtin_noop(struct ast_channel *chan, void *data)
{
More information about the svn-commits
mailing list