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

noreply at bugs.digium.com noreply at bugs.digium.com
Fri Aug 31 13:35:44 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:35 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 ':' 
====================================================================== 

---------------------------------------------------------------------- 
 Corydon76 - 08-31-07 13:35  
---------------------------------------------------------------------- 
Like I said, you need escaping:

exten => 124,1,Set(mytime=8:30-17:00)
exten => 124,n,Set(mybtime=${IF(${mytime}?${mytime}:)})
exten => 124,n,Set(mybtime=${IF(${mytime}?"${mytime}":foo)})
exten => 124,n,Set(mybtime=${IF(${mytime}?\"${mytime}\":foo)})
exten => 124,n,Set(mybtime=${IF(${mytime}?\\\"${mytime}\\\":foo)})

This last one is probably what you're going to have to use to get it to
work correctly in 1.4.  The second one (with quotes, but no backslashes) is
what you can use in trunk, because we made some changes for sanity sake.

However, you still have yet another problem, which is that you CANNOT set
the '|' character in a variable in 1.4.  Period.  Impossible.  It just does
not support it and it is the reason why we have made the above changes for
trunk.

What you'll probably have to do to get around this restriction is to use
the ${SET()} dialplan function, as it does not have this limitation. 

Issue History 
Date Modified   Username       Field                    Change               
====================================================================== 
08-31-07 13:35  Corydon76      Note Added: 0069797                          
======================================================================




More information about the asterisk-bugs mailing list