Tanin,
Welcome to the FreeSWITCH community! We hope you enjoy your stay. :)
Okay, these are basic but very good questions. If you want a really in depth discussion I recommend getting the FreeSWITCH book and reviewing chapters 5 and 8 which discuss dialplan processing in great detail. However, here is a very brief answer to your question:
There are two basic "phases" to dialplan processing: "hunting" and "executing". During the hunting phase, the dialplan processor parses the dialplan looking for extensions with matching conditions. When a condition matches, any <actions> inside that condition are added to the "task list". (There are various ways to control this hunting behavior, but let's save that for a later discussion.)
Once the hunting phase is done, there is a list of actions that needs to be executed. It's at this point that variables get "expanded". For example this condition yields a value for $1:
<condition field="destination_number" expression="^(10[01][0-9])$">
$1 will contain whatever is matched in the expression. In this case, it will be a four-digit number, like "1000", "1001", etc. (For more information on this topic see
http://wiki.freeswitch.org/wiki/Regex)
See this pastebin where I have separated the hunting from the executing:
It's a call to extension 1009. You first see the dialplan hunting starting at line #3. Notice all the debug lines that begin with "Dialplan:" - these represent the dialplan parser going over each extension's <condition> tags looking for matches. You'll see either PASS or FAIL on a match or no match. (Compare line #76 to line #78.) If there's a match then you'll see any actions being added to the task list. Look starting at line #79 and you'll see all the actions being added for this extension. NOTE: if you look in conf/dialplan/default.xml at the "Local_Extension" dialplan extension you'll see a direct correspondence to the <action> tags there and the actions being added here in the log.
Once the dialplan is done hunting it moves on to the execute phase. (See log entries after line #105.) Notice all the lines beginning with "EXECUTE:" - these represent the actions on the task list actually being executed, one at a time and in the order they were added.
That's it! Well, not exactly, but this will get you started. There are a number of tricks and a few caveats, but you'll get to those in due course. Feel free to join #freeswitch on
irc.freenode.net and chat with us in realtime. Also, we have a conference call every Wednesday. See the main wiki page for more information.
-MC