diff options
-rwxr-xr-x | Makefile | 2 | ||||
-rwxr-xr-x | channel.c | 2 | ||||
-rwxr-xr-x | chanvars.c | 2 | ||||
-rwxr-xr-x | configs/extensions.conf.sample | 7 | ||||
-rwxr-xr-x | include/asterisk/channel.h | 1 | ||||
-rwxr-xr-x | include/asterisk/chanvars.h | 2 | ||||
-rwxr-xr-x | include/asterisk/pbx.h | 1 | ||||
-rwxr-xr-x | pbx.c | 27 | ||||
-rwxr-xr-x | pbx/Makefile | 2 | ||||
-rwxr-xr-x | pbx/pbx_config.c | 7 | ||||
-rwxr-xr-x | pbx/pbx_dundi.c | 53 |
11 files changed, 68 insertions, 38 deletions
@@ -162,9 +162,11 @@ CFLAGS+=$(shell if [ -f /usr/local/include/zaptel.h ]; then echo "-DZAPTEL_OPTIM LIBEDIT=editline/libedit.a ASTERISKVERSION=$(shell if [ -f .version ]; then cat .version; else if [ -d CVS ]; then if [ -f CVS/Tag ] ; then echo "CVS-`sed 's/^T//g' CVS/Tag`-`date +"%D-%T"`"; else echo "CVS-HEAD-`date +"%D-%T"`"; fi; fi; fi) +ASTERISKVERSIONNUM=$(shell if [ -d CVS ]; then echo 999999 ; else if [ -f .version ] ; then awk -F. '{printf "%02d%02d%02d", $$1, $$2, $$3}' .version ; else echo 000000 ; fi ; fi) HTTPDIR=$(shell if [ -d /var/www ]; then echo "/var/www"; else echo "/home/httpd"; fi) RPMVERSION=$(shell if [ -f .version ]; then sed 's/[-\/:]/_/g' .version; else echo "unknown" ; fi) CFLAGS+=-DASTERISK_VERSION=\"$(ASTERISKVERSION)\" +CFLAGS+=-DASTERISK_VERSION_NUM=\"$(ASTERISKVERSIONNUM)\" CFLAGS+=-DINSTALL_PREFIX=\"$(INSTALL_PREFIX)\" CFLAGS+=-DASTETCDIR=\"$(ASTETCDIR)\" CFLAGS+=-DASTLIBDIR=\"$(ASTLIBDIR)\" @@ -340,8 +340,6 @@ struct ast_channel *ast_channel_alloc(int needqueue) headp=&tmp->varshead; ast_mutex_init(&tmp->lock); AST_LIST_HEAD_INIT(headp); - tmp->vars=ast_var_assign("tempvar","tempval"); - AST_LIST_INSERT_HEAD(headp,tmp->vars,entries); strncpy(tmp->context, "default", sizeof(tmp->context)-1); strncpy(tmp->language, defaultlanguage, sizeof(tmp->language)-1); strncpy(tmp->exten, "s", sizeof(tmp->exten)-1); diff --git a/chanvars.c b/chanvars.c index 4c67ca8db..bc13b223a 100755 --- a/chanvars.c +++ b/chanvars.c @@ -17,7 +17,7 @@ #include <asterisk/chanvars.h> #include <asterisk/logger.h> -struct ast_var_t *ast_var_assign(char *name, char *value) +struct ast_var_t *ast_var_assign(const char *name, const char *value) { int i; struct ast_var_t *var; diff --git a/configs/extensions.conf.sample b/configs/extensions.conf.sample index 32e43e09c..7ff155af7 100755 --- a/configs/extensions.conf.sample +++ b/configs/extensions.conf.sample @@ -247,6 +247,13 @@ include => iaxprovider ; Asterisk PBX ; ; switch => IAX2/user:password@bigserver/local +; +; An "lswitch" is like a switch but is literal, in that +; variable substitution is not performed at load time +; but is passed to the switch directly (presumably to +; be substituted in the switch routine itself) +; +; lswitch => Loopback/12${EXTEN}@othercontext [macro-stdexten]; ; diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h index a964ea93a..f56f5bba0 100755 --- a/include/asterisk/channel.h +++ b/include/asterisk/channel.h @@ -228,7 +228,6 @@ struct ast_channel { int hangupcause; /* A linked list for variables */ - struct ast_var_t *vars; AST_LIST_HEAD(varshead,ast_var_t) varshead; unsigned int callgroup; diff --git a/include/asterisk/chanvars.h b/include/asterisk/chanvars.h index d37c159ee..a871707a3 100755 --- a/include/asterisk/chanvars.h +++ b/include/asterisk/chanvars.h @@ -22,7 +22,7 @@ struct ast_var_t { AST_LIST_ENTRY(ast_var_t) entries; }; -struct ast_var_t *ast_var_assign(char *name,char *value); +struct ast_var_t *ast_var_assign(const char *name, const char *value); void ast_var_delete(struct ast_var_t *var); char *ast_var_name(struct ast_var_t *var); char *ast_var_value(struct ast_var_t *var); diff --git a/include/asterisk/pbx.h b/include/asterisk/pbx.h index 96e3de71c..ffd20a6bd 100755 --- a/include/asterisk/pbx.h +++ b/include/asterisk/pbx.h @@ -548,6 +548,7 @@ extern void pbx_builtin_setvar_helper(struct ast_channel *chan, char *name, char extern void pbx_builtin_clear_globals(void); extern int pbx_builtin_setvar(struct ast_channel *chan, void *data); extern void pbx_substitute_variables_helper(struct ast_channel *c,const char *cp1,char *cp2,int count); +extern void pbx_substitute_variables_varshead(struct varshead *headp, const char *cp1, char *cp2, int count); int ast_extension_patmatch(const char *pattern, const char *data); @@ -828,7 +828,7 @@ static struct ast_exten *pbx_find_extension(struct ast_channel *chan, struct ast return NULL; } -static void pbx_substitute_variables_temp(struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen) +static void pbx_substitute_variables_temp(struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp) { char *first,*second; char tmpvar[80] = ""; @@ -836,7 +836,6 @@ static void pbx_substitute_variables_temp(struct ast_channel *c, const char *var struct tm brokentime; int offset,offset2; struct ast_var_t *variables; - struct varshead *headp=NULL; if (c) headp=&c->varshead; @@ -861,7 +860,7 @@ static void pbx_substitute_variables_temp(struct ast_channel *c, const char *var if (!first) first = tmpvar + strlen(tmpvar); *first='\0'; - pbx_substitute_variables_temp(c,tmpvar,ret,workspace,workspacelen - 1); + pbx_substitute_variables_temp(c,tmpvar,ret,workspace,workspacelen - 1, headp); if (!(*ret)) return; offset=atoi(first+1); if ((second=strchr(first+1,':'))) { @@ -1009,7 +1008,7 @@ static void pbx_substitute_variables_temp(struct ast_channel *c, const char *var strncpy(workspace, c->language, workspacelen - 1); *ret = workspace; } else { - if (c) { + if (headp) { AST_LIST_TRAVERSE(headp,variables,entries) { #if 0 ast_log(LOG_WARNING,"Comparing variable '%s' with '%s'\n",var,ast_var_name(variables)); @@ -1056,7 +1055,7 @@ static void pbx_substitute_variables_temp(struct ast_channel *c, const char *var } } -void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count) +static void pbx_substitute_variables_helper_full(struct ast_channel *c, const char *cp1, char *cp2, int count, struct varshead *headp) { char *cp4; const char *tmp, *whereweare; @@ -1147,7 +1146,7 @@ void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, cha /* Retrieve variable value */ workspace[0] = '\0'; - pbx_substitute_variables_temp(c,vars,&cp4, workspace, sizeof(workspace)); + pbx_substitute_variables_temp(c,vars,&cp4, workspace, sizeof(workspace), headp); if (cp4) { length = strlen(cp4); if (length > count) @@ -1222,6 +1221,16 @@ void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, cha } } +void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count) +{ + pbx_substitute_variables_helper_full(c, cp1, cp2, count, NULL); +} + +void pbx_substitute_variables_varshead(struct varshead *headp, const char *cp1, char *cp2, int count) +{ + pbx_substitute_variables_helper_full(NULL, cp1, cp2, count, headp); +} + static void pbx_substitute_variables(char *passdata, int datalen, struct ast_channel *c, struct ast_exten *e) { memset(passdata, 0, datalen); @@ -1806,6 +1815,11 @@ int ast_spawn_extension(struct ast_channel *c, const char *context, const char * return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, HELPER_SPAWN); } +int ast_exec_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid) +{ + return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, HELPER_EXEC); +} + int ast_pbx_run(struct ast_channel *c) { int firstpass = 1; @@ -5335,3 +5349,4 @@ int ast_context_verify_includes(struct ast_context *con) } return res; } + diff --git a/pbx/Makefile b/pbx/Makefile index 8fb70b645..3bb8d33cf 100755 --- a/pbx/Makefile +++ b/pbx/Makefile @@ -13,7 +13,7 @@ -PBX_LIBS=pbx_config.so pbx_spool.so pbx_dundi.so +PBX_LIBS=pbx_config.so pbx_spool.so pbx_dundi.so pbx_loopback.so # Add GTK console if appropriate #PBX_LIBS+=$(shell gtk-config --cflags >/dev/null 2>/dev/null && echo "pbx_gtkconsole.so") diff --git a/pbx/pbx_config.c b/pbx/pbx_config.c index 7e0d6d9cd..63c66016c 100755 --- a/pbx/pbx_config.c +++ b/pbx/pbx_config.c @@ -1754,10 +1754,13 @@ static int pbx_load_module(void) pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1); if (ast_context_add_ignorepat2(con, realvalue, registrar)) ast_log(LOG_WARNING, "Unable to include ignorepat '%s' in context '%s'\n", v->value, cxt); - } else if (!strcasecmp(v->name, "switch")) { + } else if (!strcasecmp(v->name, "switch") || !strcasecmp(v->name, "lswitch")) { char *stringp=NULL; memset(realvalue, 0, sizeof(realvalue)); - pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1); + if (!strcasecmp(v->name, "switch")) + pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1); + else + strncpy(realvalue, v->value, sizeof(realvalue) - 1); tc = realvalue; stringp=tc; appl = strsep(&stringp, "/"); diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c index 7dc346764..89e18dfa0 100755 --- a/pbx/pbx_dundi.c +++ b/pbx/pbx_dundi.c @@ -480,7 +480,6 @@ static int dundi_lookup_local(struct dundi_result *dr, struct dundi_mapping *map { int flags; int x; - struct ast_channel *chan=NULL; if (!ast_strlen_zero(map->lcontext)) { flags = 0; if (ast_exists_extension(NULL, map->lcontext, called_number, 1, NULL)) @@ -501,27 +500,35 @@ static int dundi_lookup_local(struct dundi_result *dr, struct dundi_mapping *map flags &= ~(DUNDI_FLAG_MATCHMORE|DUNDI_FLAG_CANMATCH); } if (flags) { - /* Clearly we can't say 'don't ask' anymore... */ - chan = ast_channel_alloc(0); - if (chan) { - flags |= map->options & 0xffff; - dr[anscnt].flags = flags; - dr[anscnt].techint = map->tech; - dr[anscnt].weight = map->weight; - dr[anscnt].expiration = DUNDI_DEFAULT_CACHE_TIME; - strncpy(dr[anscnt].tech, tech2str(map->tech), sizeof(dr[anscnt].tech)); - dr[anscnt].eid = *us_eid; - dundi_eid_to_str(dr[anscnt].eid_str, sizeof(dr[anscnt].eid_str), &dr[anscnt].eid); - if (flags & DUNDI_FLAG_EXISTS) { - pbx_builtin_setvar_helper(chan, "NUMBER", called_number); - pbx_builtin_setvar_helper(chan, "EID", dr[anscnt].eid_str); - pbx_builtin_setvar_helper(chan, "SECRET", cursecret); - pbx_builtin_setvar_helper(chan, "IPADDR", ipaddr); - pbx_substitute_variables_helper(chan, map->dest, dr[anscnt].dest, sizeof(dr[anscnt].dest)); - } else - dr[anscnt].dest[0] = '\0'; - anscnt++; - } + struct varshead headp; + struct ast_var_t *newvariable; + flags |= map->options & 0xffff; + dr[anscnt].flags = flags; + dr[anscnt].techint = map->tech; + dr[anscnt].weight = map->weight; + dr[anscnt].expiration = DUNDI_DEFAULT_CACHE_TIME; + strncpy(dr[anscnt].tech, tech2str(map->tech), sizeof(dr[anscnt].tech)); + dr[anscnt].eid = *us_eid; + dundi_eid_to_str(dr[anscnt].eid_str, sizeof(dr[anscnt].eid_str), &dr[anscnt].eid); + if (flags & DUNDI_FLAG_EXISTS) { + AST_LIST_HEAD_INIT(&headp); + newvariable = ast_var_assign("NUMBER", called_number); + AST_LIST_INSERT_HEAD(&headp, newvariable, entries); + newvariable = ast_var_assign("EID", dr[anscnt].eid_str); + AST_LIST_INSERT_HEAD(&headp, newvariable, entries); + newvariable = ast_var_assign("SECRET", cursecret); + AST_LIST_INSERT_HEAD(&headp, newvariable, entries); + newvariable = ast_var_assign("IPADDR", ipaddr); + AST_LIST_INSERT_HEAD(&headp, newvariable, entries); + pbx_substitute_variables_varshead(&headp, map->dest, dr[anscnt].dest, sizeof(dr[anscnt].dest)); + while (!AST_LIST_EMPTY(&headp)) { /* List Deletion. */ + newvariable = AST_LIST_FIRST(&headp); + AST_LIST_REMOVE_HEAD(&headp, entries); + ast_var_delete(newvariable); + } + } else + dr[anscnt].dest[0] = '\0'; + anscnt++; } else { /* No answers... Find the fewest number of digits from the number for which we have no answer. */ @@ -541,8 +548,6 @@ static int dundi_lookup_local(struct dundi_result *dr, struct dundi_mapping *map } } } - if (chan) - ast_hangup(chan); return anscnt; } |