[asterisk-bugs] [Asterisk 0010613]: Unable to use variables containing times

noreply at bugs.digium.com noreply at bugs.digium.com
Fri Aug 31 13:07:02 CDT 2007


A NOTE has been added to this issue. 
====================================================================== 
http://bugs.digium.com/view.php?id=10613 
====================================================================== 
Reported By:                Karl Anderson
Assigned To:                Corydon76
====================================================================== 
Project:                    Asterisk
Issue ID:                   10613
Category:                   Functions/func_logic
Reproducibility:            always
Severity:                   tweak
Priority:                   normal
Status:                     assigned
Asterisk Version:            1.4.10.1  
SVN Branch (only for SVN checkouts, not tarball releases): N/A  
SVN Revision (number only!):  
Disclaimer on File?:        N/A 
Request Review:              
====================================================================== 
Date Submitted:             08-30-2007 18:38 CDT
Last Modified:              08-31-2007 13:07 CDT
====================================================================== 
Summary:                    Unable to use variables containing times
Description: 
Due to the syntax of the function IF I am unable to use it (or any other)
logic functions to make decisions on variables holding times.  Example:

Set(REDIRECT_TIME=${ODBC_PREF(${MACRO_CONTEXT}|${MACRO_EXTEN}|REDIRECT_TIME)})
Set(REDIRECT_TIME=${IF($["REDIRECT_TIME" !=
""]?${REDIRECT_TIME}:"*|*|*|*")})
GotoIfTime(${REDIRECT_TIME}}?INSIDE_RANGE)

1. A odbc connection is used to query a MySQL table for this
context/extensions REDIRECT_TIME.
2. If there was no return from the MySQL then use wildcards (works)
otherwise use the time found (broken)
3. Goto based on the time

In this example if the MySQL holds a time then func if incorrectly uses
the first ':' (8:00-17:00|mon-fri) effectively making the if statement:
            ^


IF REDIRECT_TIME ? 8 : 00-17:00|mon-fri

Which fails.  After looking into the source code I (albeit not a
programmer) recommend either not striping quotes first (if present) or
using a regex to find the last occurance of ':' 
====================================================================== 

---------------------------------------------------------------------- 
 Karl Anderson - 08-31-07 13:07  
---------------------------------------------------------------------- 
Applied the above patch but still had the same problem.  I created a test
using the above code (but corrected the variable in second line) which
produced the erroneous output:

    -- Executing [s at macro-CEP:9] Set("Local/CEP at 099-99fc,2",
"REDIRECT_TIME=8:00-21:00|mon-fri") in new stack
    -- Executing [s at macro-CEP:10] Set("Local/CEP at 099-99fc,2",
"REDIRECT_TIME=8") in new stack

As you can see the func if incorrectly sets REDIRECT_TIME to '8' because
that is the first occurance of the true/false delimiter ':' even though it
is both within quotes and valid.

Note the above was preformed with the uploaded 20070831_bug10613.diff
applied but as it did not correct the problem I have since reverted.

I wish I new C better but if you where to implement the changes I am
suggesting in perl it would look like this (notice this too is untested and
written on the fly):

if ($data =~ m/(.*)\?"(.*)":"(.*)"/) {
	$expr = $1;
	$iftrue = $2;
	$iffalse = $3;
} else {
	$data =~ s/"//g;
	@expr_split = split(/?/, $data);
	$expr = @expr_split[0];
	@return_split = split(/:/, @expr_split[1]);
	$iftrue = @return_split[0];
	$iffalse = @return_split[1];
}

Basicly if there are '"' around the 'iftrue' and 'iffalse' in the func if
call then treat it as a group otherwise preform as normal. 

Issue History 
Date Modified   Username       Field                    Change               
====================================================================== 
08-31-07 13:07  Karl Anderson  Note Added: 0069788                          
======================================================================




More information about the asterisk-bugs mailing list