mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-17 07:18:15 +00:00
Allow globals in extensions.conf to reference previous variables
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1255 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
47
pbx.c
47
pbx.c
@@ -738,8 +738,9 @@ static void pbx_substitute_variables_temp(struct ast_channel *c,const char *var,
|
|||||||
int offset,offset2;
|
int offset,offset2;
|
||||||
struct ast_var_t *variables;
|
struct ast_var_t *variables;
|
||||||
char *name, *num; /* for callerid name + num variables */
|
char *name, *num; /* for callerid name + num variables */
|
||||||
struct varshead *headp;
|
struct varshead *headp=NULL;
|
||||||
headp=&c->varshead;
|
if (c)
|
||||||
|
headp=&c->varshead;
|
||||||
*ret=NULL;
|
*ret=NULL;
|
||||||
/* Now we have the variable name on cp3 */
|
/* Now we have the variable name on cp3 */
|
||||||
if ((first=strchr(var,':'))) {
|
if ((first=strchr(var,':'))) {
|
||||||
@@ -773,7 +774,7 @@ static void pbx_substitute_variables_temp(struct ast_channel *c,const char *var,
|
|||||||
else
|
else
|
||||||
*ret+=strlen(*ret)+offset;
|
*ret+=strlen(*ret)+offset;
|
||||||
(*ret)[offset2] = '\0';
|
(*ret)[offset2] = '\0';
|
||||||
} else if (!strcmp(var, "CALLERIDNUM")) {
|
} else if (c && !strcmp(var, "CALLERIDNUM")) {
|
||||||
if (c->callerid)
|
if (c->callerid)
|
||||||
strncpy(workspace, c->callerid, workspacelen - 1);
|
strncpy(workspace, c->callerid, workspacelen - 1);
|
||||||
ast_callerid_parse(workspace, &name, &num);
|
ast_callerid_parse(workspace, &name, &num);
|
||||||
@@ -782,7 +783,7 @@ static void pbx_substitute_variables_temp(struct ast_channel *c,const char *var,
|
|||||||
*ret = num;
|
*ret = num;
|
||||||
} else
|
} else
|
||||||
*ret = workspace;
|
*ret = workspace;
|
||||||
} else if (!strcmp(var, "CALLERIDNAME")) {
|
} else if (c && !strcmp(var, "CALLERIDNAME")) {
|
||||||
if (c->callerid)
|
if (c->callerid)
|
||||||
strncpy(workspace, c->callerid, workspacelen - 1);
|
strncpy(workspace, c->callerid, workspacelen - 1);
|
||||||
ast_callerid_parse(workspace, &name, &num);
|
ast_callerid_parse(workspace, &name, &num);
|
||||||
@@ -790,21 +791,21 @@ static void pbx_substitute_variables_temp(struct ast_channel *c,const char *var,
|
|||||||
*ret = name;
|
*ret = name;
|
||||||
else
|
else
|
||||||
*ret = workspace;
|
*ret = workspace;
|
||||||
} else if (!strcmp(var, "CALLERID")) {
|
} else if (c && !strcmp(var, "CALLERID")) {
|
||||||
if (c->callerid) {
|
if (c->callerid) {
|
||||||
strncpy(workspace, c->callerid, workspacelen - 1);
|
strncpy(workspace, c->callerid, workspacelen - 1);
|
||||||
*ret = workspace;
|
*ret = workspace;
|
||||||
} else
|
} else
|
||||||
*ret = NULL;
|
*ret = NULL;
|
||||||
} else if (!strcmp(var, "HINT")) {
|
} else if (c && !strcmp(var, "HINT")) {
|
||||||
if (!ast_get_hint(workspace, workspacelen - 1, c, c->context, c->exten))
|
if (!ast_get_hint(workspace, workspacelen - 1, c, c->context, c->exten))
|
||||||
*ret = NULL;
|
*ret = NULL;
|
||||||
else
|
else
|
||||||
*ret = workspace;
|
*ret = workspace;
|
||||||
} else if (!strcmp(var, "EXTEN")) {
|
} else if (c && !strcmp(var, "EXTEN")) {
|
||||||
strncpy(workspace, c->exten, workspacelen - 1);
|
strncpy(workspace, c->exten, workspacelen - 1);
|
||||||
*ret = workspace;
|
*ret = workspace;
|
||||||
} else if (!strncmp(var, "EXTEN-", strlen("EXTEN-")) &&
|
} else if (c && !strncmp(var, "EXTEN-", strlen("EXTEN-")) &&
|
||||||
/* XXX Remove me eventually */
|
/* XXX Remove me eventually */
|
||||||
(sscanf(var + strlen("EXTEN-"), "%d", &offset) == 1)) {
|
(sscanf(var + strlen("EXTEN-"), "%d", &offset) == 1)) {
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
@@ -814,25 +815,25 @@ static void pbx_substitute_variables_temp(struct ast_channel *c,const char *var,
|
|||||||
strncpy(workspace, c->exten + offset, workspacelen - 1);
|
strncpy(workspace, c->exten + offset, workspacelen - 1);
|
||||||
*ret = workspace;
|
*ret = workspace;
|
||||||
ast_log(LOG_WARNING, "The use of 'EXTEN-foo' has been derprecated in favor of 'EXTEN:foo'\n");
|
ast_log(LOG_WARNING, "The use of 'EXTEN-foo' has been derprecated in favor of 'EXTEN:foo'\n");
|
||||||
} else if (!strcmp(var, "RDNIS")) {
|
} else if (c && !strcmp(var, "RDNIS")) {
|
||||||
if (c->rdnis) {
|
if (c->rdnis) {
|
||||||
strncpy(workspace, c->rdnis, workspacelen - 1);
|
strncpy(workspace, c->rdnis, workspacelen - 1);
|
||||||
*ret = workspace;
|
*ret = workspace;
|
||||||
} else
|
} else
|
||||||
*ret = NULL;
|
*ret = NULL;
|
||||||
} else if (!strcmp(var, "CONTEXT")) {
|
} else if (c && !strcmp(var, "CONTEXT")) {
|
||||||
strncpy(workspace, c->context, workspacelen - 1);
|
strncpy(workspace, c->context, workspacelen - 1);
|
||||||
*ret = workspace;
|
*ret = workspace;
|
||||||
} else if (!strcmp(var, "PRIORITY")) {
|
} else if (c && !strcmp(var, "PRIORITY")) {
|
||||||
snprintf(workspace, workspacelen, "%d", c->priority);
|
snprintf(workspace, workspacelen, "%d", c->priority);
|
||||||
*ret = workspace;
|
*ret = workspace;
|
||||||
} else if (!strcmp(var, "CHANNEL")) {
|
} else if (c && !strcmp(var, "CHANNEL")) {
|
||||||
strncpy(workspace, c->name, workspacelen - 1);
|
strncpy(workspace, c->name, workspacelen - 1);
|
||||||
*ret = workspace;
|
*ret = workspace;
|
||||||
} else if (!strcmp(var, "EPOCH")) {
|
} else if (c && !strcmp(var, "EPOCH")) {
|
||||||
snprintf(workspace, workspacelen -1, "%u",(int)time(NULL));
|
snprintf(workspace, workspacelen -1, "%u",(int)time(NULL));
|
||||||
*ret = workspace;
|
*ret = workspace;
|
||||||
} else if (!strcmp(var, "DATETIME")) {
|
} else if (c && !strcmp(var, "DATETIME")) {
|
||||||
thistime=time(NULL);
|
thistime=time(NULL);
|
||||||
localtime_r(&thistime, &brokentime);
|
localtime_r(&thistime, &brokentime);
|
||||||
snprintf(workspace, workspacelen -1, "%02d%02d%04d-%02d:%02d:%02d",
|
snprintf(workspace, workspacelen -1, "%02d%02d%04d-%02d:%02d:%02d",
|
||||||
@@ -844,18 +845,20 @@ static void pbx_substitute_variables_temp(struct ast_channel *c,const char *var,
|
|||||||
brokentime.tm_sec
|
brokentime.tm_sec
|
||||||
);
|
);
|
||||||
*ret = workspace;
|
*ret = workspace;
|
||||||
} else if (!strcmp(var, "UNIQUEID")) {
|
} else if (c && !strcmp(var, "UNIQUEID")) {
|
||||||
snprintf(workspace, workspacelen -1, "%s", c->uniqueid);
|
snprintf(workspace, workspacelen -1, "%s", c->uniqueid);
|
||||||
} else {
|
} else {
|
||||||
AST_LIST_TRAVERSE(headp,variables,entries) {
|
if (c) {
|
||||||
|
AST_LIST_TRAVERSE(headp,variables,entries) {
|
||||||
#if 0
|
#if 0
|
||||||
ast_log(LOG_WARNING,"Comparing variable '%s' with '%s'\n",var,ast_var_name(variables));
|
ast_log(LOG_WARNING,"Comparing variable '%s' with '%s'\n",var,ast_var_name(variables));
|
||||||
#endif
|
#endif
|
||||||
if (strcasecmp(ast_var_name(variables),var)==0) {
|
if (strcasecmp(ast_var_name(variables),var)==0) {
|
||||||
*ret=ast_var_value(variables);
|
*ret=ast_var_value(variables);
|
||||||
if (*ret) {
|
if (*ret) {
|
||||||
strncpy(workspace, *ret, workspacelen - 1);
|
strncpy(workspace, *ret, workspacelen - 1);
|
||||||
*ret = workspace;
|
*ret = workspace;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1538,6 +1538,7 @@ static int pbx_load_module(void)
|
|||||||
char *cxt, *ext, *pri, *appl, *data, *tc, *cidmatch;
|
char *cxt, *ext, *pri, *appl, *data, *tc, *cidmatch;
|
||||||
struct ast_context *con;
|
struct ast_context *con;
|
||||||
char *start, *end;
|
char *start, *end;
|
||||||
|
char realvalue[256] = "";
|
||||||
|
|
||||||
cfg = ast_load(config);
|
cfg = ast_load(config);
|
||||||
if (cfg) {
|
if (cfg) {
|
||||||
@@ -1548,7 +1549,8 @@ static int pbx_load_module(void)
|
|||||||
"writeprotect"));
|
"writeprotect"));
|
||||||
v = ast_variable_browse(cfg, "globals");
|
v = ast_variable_browse(cfg, "globals");
|
||||||
while(v) {
|
while(v) {
|
||||||
pbx_builtin_setvar_helper(NULL, v->name, v->value);
|
pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
|
||||||
|
pbx_builtin_setvar_helper(NULL, v->name, realvalue);
|
||||||
v = v->next;
|
v = v->next;
|
||||||
}
|
}
|
||||||
cxt = ast_category_browse(cfg, NULL);
|
cxt = ast_category_browse(cfg, NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user