[Asterisk-Users] Re: Bison, Flex, Conditional Expression
Steve Murphy
murf at e-tools.com
Sun Jun 5 23:26:46 MST 2005
To any that may be interested in the implementation of the conditional expression
in the expression parser (ast_expr2*) in asterisk, I've filed the patch at:
http://bugs.digium.com/view.php?id=4459
Right now, a comment has been added noting that the IF func provides this capability,
and asks if both would really be necessary. It's a good question. I haven't been
following the addition of this new set of capabilities in asterisk, but see that
"show functions" returns:
DB DB(<family>/<key>) Read or Write from/to the Asterisk database
ENV ENV(<envname>) Gets or sets the environment variable specified
IF IF(<expr>?<true>:<false>) Conditional: Returns the data following '?' if true else the data following ':'
EXISTS EXISTS(<data>) Existence Test: Returns 1 if exists, 0 otherwise
ISNULL ISNULL(<data>) NULL Test: Returns 1 if NULL or 0 otherwise
CDR CDR(<name>[|options]) Gets or sets a CDR variable
STRFTIME STRFTIME([<epoch>][,[timezone][,for Returns the current date/time in a specified format.
LEN LEN(<string>) Returns the length of the argument given
REGEX REGEX("<regular expression>" <data> Regular Expression: Returns 1 if data matches regular expression.
FIELDQTY FIELDQTY(<varname>,<delim>) Count the fields, with an arbitrary delimiter
GROUP_LIST GROUP_LIST() Gets a list of the groups set on a channel.
GROUP GROUP([category]) Gets or sets the channel group.
GROUP_MATCH_COUNT GROUP_MATCH_COUNT(groupmatch[@categ Counts the number of channels in the groups matching the specified pattern
GROUP_COUNT GROUP_COUNT([groupname][@category]) Counts the number of channels in the specified group
CHECK_MD5 CHECK_MD5(<digest>,<data>) Checks an MD5 digest
MD5 MD5(<data>) Computes an MD5 digest
IAXPEER IAXPEER(<peername>[:item]) Gets IAX peer information
SIP_HEADER SIP_HEADER(<name>) Gets or sets the specified SIP header
How are these functions used? The last sentence of the README.variables file says:
Certain functional variables may be accessed with $(foo <args>). A list
of these functional variables may be found by typing "show functions"
at the Asterisk CLI.
So, I guess you could say:
SetVAR(var=$(IF a=b?true:false))
or do I have to say:
SetVAR(var=$(IF $[a=b]?true:false))
or
SetVAR(var=$(IF $[a=b]?$[possibly_more_complicated_true_expr]:$[possibly_more_complicated_false_expr]))
[ between the two sets above, the second "feels" more realistic than the first, as the actual
evaluation of a=b most likely will have be done by the expression parser... if not, the expression
parser will no longer be necessary]
vs:
SetVAR(var=$[a=b ? true :: false])
As I said, I haven't been following the Function additions at all (yet), and haven't
actually tried to fit any of them in my extensions.conf (yet).
Someone who's more involved with this might show some examples of how functions are
used, and maybe we can see then which method might be best, if any, and whether it might be
better to toss one, or keep them both...
Can anyone help cast some more light on how Functions like IF would be used in extensions.conf?
Was I right about the usage above?
murf
More information about the asterisk-users
mailing list