Implement setvar functionality in chan_skinny
authorJason Parker <jparker@digium.com>
Mon, 6 Aug 2007 16:08:11 +0000 (16:08 +0000)
committerJason Parker <jparker@digium.com>
Mon, 6 Aug 2007 16:08:11 +0000 (16:08 +0000)
Closes issue #10379, patch by mvanbaak.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@78179 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_skinny.c
configs/skinny.conf.sample

index a05730d..48c1578 100644 (file)
@@ -1020,6 +1020,7 @@ struct skinny_line {
        struct skinny_subchannel *sub;
        struct skinny_line *next;
        struct skinny_device *parent;
+       struct ast_variable *chanvars;          /*!< Channel variables to set for inbound call */
 };
 
 struct skinny_speeddial {
@@ -1316,6 +1317,24 @@ static struct skinny_line *find_line_by_name(const char *dest)
        return tmpl;
 }
 
+/*!
+ * implement the setvar config line
+ */
+static struct ast_variable *add_var(const char *buf, struct ast_variable *list)
+{
+       struct ast_variable *tmpvar = NULL;
+       char *varname = ast_strdupa(buf), *varval = NULL;
+
+       if ((varval = strchr(varname,'='))) {
+               *varval++ = '\0';
+               if ((tmpvar = ast_variable_new(varname, varval))) {
+                       tmpvar->next = list;
+                       list = tmpvar;
+               }
+       }
+       return list;
+}
+
 /* It's quicker/easier to find the subchannel when we know the instance number too */
 static struct skinny_subchannel *find_subchannel_by_instance_reference(struct skinny_device *d, int instance, int reference)
 {
@@ -2279,6 +2298,7 @@ static struct skinny_device *build_device(const char *cat, struct ast_variable *
        struct skinny_speeddial *sd;
        struct skinny_addon *a;
        char device_vmexten[AST_MAX_EXTENSION];
+       struct ast_variable *chanvars = NULL;
        int lineInstance = 1;
        int speeddialInstance = 1;
        int y = 0;
@@ -2362,6 +2382,8 @@ static struct skinny_device *build_device(const char *cat, struct ast_variable *
                                mwiblink = ast_true(v->value);
                        } else if (!strcasecmp(v->name, "linelabel")) {
                                ast_copy_string(linelabel, v->value, sizeof(linelabel));
+                       } else if (!strcasecmp(v->name, "setvar")) {
+                               chanvars = add_var(v->value, chanvars);
                        } else if (!strcasecmp(v->name, "speeddial")) {
                                if (!(sd = ast_calloc(1, sizeof(*sd)))) {
                                        return NULL;
@@ -2422,6 +2444,7 @@ static struct skinny_device *build_device(const char *cat, struct ast_variable *
                                                ast_verb(3, "Setting mailbox '%s' on %s@%s\n", mailbox, d->name, l->name);
                                        if (!ast_strlen_zero(device_vmexten))
                                                ast_copy_string(l->vmexten, device_vmexten, sizeof(vmexten));
+                                       l->chanvars = chanvars;
                                        l->msgstate = -1;
                                        l->capability = d->capability;
                                        l->prefs = d->prefs;
@@ -3009,6 +3032,7 @@ static struct ast_channel *skinny_new(struct skinny_line *l, int state)
        struct ast_channel *tmp;
        struct skinny_subchannel *sub;
        struct skinny_device *d = l->parent;
+       struct ast_variable *v = NULL;
        int fmt;
 
        tmp = ast_channel_alloc(1, state, l->cid_num, l->cid_name, l->accountcode, l->exten, l->context, l->amaflags, "Skinny/%s@%s-%d", l->name, d->name, callnums);
@@ -3079,6 +3103,10 @@ static struct ast_channel *skinny_new(struct skinny_line *l, int state)
                if (sub->rtp)
                        ast_jb_configure(tmp, &global_jbconf);
 
+               /* Set channel variables for this call from configuration */
+               for (v = l->chanvars ; v ; v = v->next)
+                       pbx_builtin_setvar_helper(tmp, v->name, v->value);
+
                if (state != AST_STATE_DOWN) {
                        if (ast_pbx_start(tmp)) {
                                ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
index bc4c515..c698d8f 100644 (file)
@@ -72,6 +72,7 @@ keepalive=120
 ;permit=192.168.0/24   ; Optional, used for authentication
 ;nat=yes
 ;callerid="George W. Bush" <202-456-1414>
+;setvar=CUSTID=5678    ; Channel variable to be set for all calls from this device
 ;mailbox=500
 ;callwaiting=yes
 ;transfer=yes