Add "Loopback" switch
authorMark Spencer <markster@digium.com>
Sun, 24 Oct 2004 02:53:24 +0000 (02:53 +0000)
committerMark Spencer <markster@digium.com>
Sun, 24 Oct 2004 02:53:24 +0000 (02:53 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4070 65c4cc65-6c06-0410-ace0-fbb531ad65f3

Makefile
channel.c
chanvars.c
configs/extensions.conf.sample
include/asterisk/channel.h
include/asterisk/chanvars.h
include/asterisk/pbx.h
pbx.c
pbx/Makefile
pbx/pbx_config.c
pbx/pbx_dundi.c

index bd58503..a549844 100755 (executable)
--- a/Makefile
+++ b/Makefile
@@ -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)\"
index 8d70ee2..b9607a0 100755 (executable)
--- a/channel.c
+++ b/channel.c
@@ -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);
index 4c67ca8..bc13b22 100755 (executable)
@@ -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;
index 32e43e0..7ff155a 100755 (executable)
@@ -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];
 ;
index a964ea9..f56f5bb 100755 (executable)
@@ -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;
index d37c159..a871707 100755 (executable)
@@ -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);
index 96e3de7..ffd20a6 100755 (executable)
@@ -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);
 
diff --git a/pbx.c b/pbx.c
index 4426eec..e40746d 100755 (executable)
--- a/pbx.c
+++ b/pbx.c
@@ -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;
 }
+
index 8fb70b6..3bb8d33 100755 (executable)
@@ -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")
index 7e0d6d9..63c6601 100755 (executable)
@@ -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, "/");
index 7dc3467..89e18df 100755 (executable)
@@ -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;
 }