]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Some dialplan functions, such as CUT(), expect to operate on variables on a
authorRussell Bryant <russell@russellbryant.com>
Mon, 23 Apr 2007 18:17:00 +0000 (18:17 +0000)
committerRussell Bryant <russell@russellbryant.com>
Mon, 23 Apr 2007 18:17:00 +0000 (18:17 +0000)
channel.  So, this little hack lets them work in places where a channel doesn't
exist, such as within DUNDi configuration.
(issue #9465, reported and patched by Corydon76, testing by blitzrage)

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

main/pbx.c

index 257728df454ad5c5f162789b90094f6badb76faa..1f6ccbd46c3b16d3cb8c3619252b6a674365660d 100644 (file)
@@ -1642,7 +1642,21 @@ static void pbx_substitute_variables_helper_full(struct ast_channel *c, struct v
                        parse_variable_name(vars, &offset, &offset2, &isfunction);
                        if (isfunction) {
                                /* Evaluate function */
-                               cp4 = ast_func_read(c, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace;
+                               if (c)
+                                       cp4 = ast_func_read(c, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace;
+                               else {
+                                       struct varshead old;
+                                       struct ast_channel *c = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Bogus/%p", vars);
+                                       if (c) {
+                                               memcpy(&old, &c->varshead, sizeof(old));
+                                               memcpy(&c->varshead, headp, sizeof(c->varshead));
+                                               cp4 = ast_func_read(c, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace;
+                                               /* Don't deallocate the varshead that was passed in */
+                                               memcpy(&c->varshead, &old, sizeof(c->varshead));
+                                               ast_channel_free(c);
+                                       } else
+                                               ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution.  Function results may be blank.\n");
+                               }
 
                                if (option_debug)
                                        ast_log(LOG_DEBUG, "Function result is '%s'\n", cp4 ? cp4 : "(null)");