[Asterisk-cvs] asterisk pbx.c,1.171,1.172
markster at lists.digium.com
markster at lists.digium.com
Tue Nov 16 23:48:26 CST 2004
Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv19983
Modified Files:
pbx.c
Log Message:
Add "ImportVar" application
Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.171
retrieving revision 1.172
diff -u -d -r1.171 -r1.172
--- pbx.c 16 Nov 2004 03:13:05 -0000 1.171
+++ pbx.c 17 Nov 2004 04:48:58 -0000 1.172
@@ -182,6 +182,7 @@
static int pbx_builtin_saycharacters(struct ast_channel *, void *);
static int pbx_builtin_sayphonetic(struct ast_channel *, void *);
int pbx_builtin_setvar(struct ast_channel *, void *);
+static int pbx_builtin_importvar(struct ast_channel *, void *);
void pbx_builtin_setvar_helper(struct ast_channel *chan, char *name, char *value);
char *pbx_builtin_getvar_helper(struct ast_channel *chan, char *name);
@@ -388,6 +389,12 @@
" SetVar(#n=value): Sets variable n to value. If prefixed with _, single\n"
"inheritance assumed. If prefixed with __, infinite inheritance is assumed.\n" },
+ { "ImportVar", pbx_builtin_importvar,
+ "Set variable to value",
+ " ImportVar(#n=channel|variable): Sets variable n to variable as evaluated on\n"
+ "the specified channel (instead of current). If prefixed with _, single\n"
+ "inheritance assumed. If prefixed with __, infinite inheritance is assumed.\n" },
+
{ "StripMSD", pbx_builtin_stripmsd,
"Strip leading digits",
" StripMSD(count): Strips the leading 'count' digits from the channel's\n"
@@ -910,16 +917,6 @@
} else if (c && !strcmp(var, "EXTEN")) {
strncpy(workspace, c->exten, workspacelen - 1);
*ret = workspace;
- } else if (c && !strncmp(var, "EXTEN-", strlen("EXTEN-")) &&
- /* XXX Remove me eventually */
- (sscanf(var + strlen("EXTEN-"), "%d", &offset) == 1)) {
- if (offset < 0)
- offset=0;
- if (offset > strlen(c->exten))
- offset = strlen(c->exten);
- strncpy(workspace, c->exten + offset, workspacelen - 1);
- *ret = workspace;
- ast_log(LOG_WARNING, "The use of 'EXTEN-foo' has been deprecated in favor of 'EXTEN:foo'\n");
} else if (c && !strcmp(var, "RDNIS")) {
if (c->cid.cid_rdnis) {
strncpy(workspace, c->cid.cid_rdnis, workspacelen - 1);
@@ -5075,7 +5072,7 @@
return 0;
}
- stringp = data;
+ stringp = ast_strdupa(data);
name = strsep(&stringp,"=");
value = strsep(&stringp,"\0");
@@ -5084,6 +5081,45 @@
return(0);
}
+int pbx_builtin_importvar(struct ast_channel *chan, void *data)
+{
+ char *name;
+ char *value;
+ char *stringp=NULL;
+ char *channel;
+ struct ast_channel *chan2=NULL;
+ char tmp[4096]="";
+ char *s;
+
+ if (!data || ast_strlen_zero(data)) {
+ ast_log(LOG_WARNING, "Ignoring, since there is no variable to set\n");
+ return 0;
+ }
+
+ stringp = ast_strdupa(data);
+ name = strsep(&stringp,"=");
+ channel = strsep(&stringp,"|");
+ value = strsep(&stringp,"\0");
+ if (channel && value && name) {
+ while((chan2 = ast_channel_walk_locked(chan2))) {
+ if (!strcmp(chan2->name, channel))
+ break;
+ ast_mutex_unlock(&chan2->lock);
+ }
+ if (chan2) {
+ s = alloca(strlen(value) + 4);
+ if (s) {
+ sprintf(s, "${%s}", value);
+ pbx_substitute_variables_helper(chan2, s, tmp, sizeof(tmp) - 1);
+ }
+ ast_mutex_unlock(&chan2->lock);
+ }
+ pbx_builtin_setvar_helper(chan, name, tmp);
+ }
+
+ return(0);
+}
+
static int pbx_builtin_setglobalvar(struct ast_channel *chan, void *data)
{
char *name;
More information about the svn-commits
mailing list