Page 174 - Asterisk™: The Future of Telephony
P. 174

When Asterisk encounters an expression in a dialplan, it replaces the entire expression
               with the resulting value. It is important to note that this takes place after variable sub-
               stitution. To demonstrate, let’s look at the following code: *
                   exten => 321,1,Set(COUNT=3)
                   exten => 321,n,Set(NEWCOUNT=$[${COUNT} + 1])
                   exten => 321,n,SayNumber(${NEWCOUNT})
               In the first priority, we assign the value of 3 to the variable named COUNT.
               In the second priority, only one application—Set()—is involved, but three things ac-
               tually happen:
                 1. Asterisk substitutes ${COUNT} with the number 3 in the expression. The expression
                   effectively becomes this:
                       exten => 321,n,Set(NEWCOUNT=$[3 + 1])
                 2. Asterisk evaluates the expression, adding 1 to 3, and replaces it with its computed
                   value of 4:

                       exten => 321,n,Set(NEWCOUNT=4)
                 3. The value 4 is assigned to the NEWCOUNT variable by the Set() application.
               The third priority simply invokes the SayNumber() application, which speaks the current
               value of the variable ${NEWCOUNT} (set to the value 4 in priority two).
               Try it out in your own dialplan.

               Operators

               When you create an Asterisk dialplan, you’re really writing code in a specialized script-
               ing language. This means that the Asterisk dialplan—like any programming language
               —recognizes symbols called operators that allow you to manipulate variables. Let’s
               look at the types of operators that are available in Asterisk:
               Boolean operators
                   These operators evaluate the “truth” of a statement. In computing terms, that es-
                   sentially refers to whether the statement is something or nothing (nonzero or zero,
                   true or false, on or off, and so on). The Boolean operators are:

                   expr1 | expr2
                       This operator (called the “or” operator, or “pipe”) returns the evaluation of
                       expr1 if it is true (neither an empty string nor zero). Otherwise, it returns the
                       evaluation of expr2.






               * Remember that when you reference a variable you can call it by its name, but when you refer to a variable’s
                 value, you have to use the dollar sign and brackets around the variable name.

               146 | Chapter 6: More Dialplan Concepts
   169   170   171   172   173   174   175   176   177   178   179