(转)FreeSwitch 拨号规则定义

引自:https://blog.csdn.net/karl_max/article/details/5046811

 

当一个呼叫在ROUTING状态下达到命中拨号规则解析器时,相应的拨号规则就开始解析了。随着解析的进行,在xml文件中的符合条件的或标签中的指令形成一个指令表,安装到这个通道中。

 

你可以将拨号规则文件放到conf/dialplan/default下,这个目录下的拨号规则要比enum拨号规则优先处理。这个目录下的文件执行优先级是按其文件名开头的数字排序(由小到大),最大的那个文件是99999_enum.xml,这个文件捕捉所以的呼叫,所以我们自己定义的文件一定要小于这个文件才可能被先执行。一个以字母开头的文件名会大小999999_enum.xml。

 

可以通过${api func(api arg ${var_name})}的方式调用一个模块的函数。

 

通常一个拨号规则文件会包括三个要素:context, extension, condition和action。这些项目会被依次处理,只到达到action。

 

context

 

context是一个extension的逻辑组,一个context可以包含一个或多个extension。

 

context有一个name参数,any是一个保留的name参数值,它代表任何context。name用来标识一个context。在freeswitch.xml的dialplan section中可以有多个context。

 

extension

 

extension就是一个呼叫的目标。它有一个name,一些condition和action,这些东西会告诉freeswitch应该做什么。

 

语法:

 

<extension name="{exten_name}" [continue="[true|false]"]>

name参数是必须的,它是extension的唯一标识。

 

另外还有一个可选的参数continue,如果它配置为true的话,即使这个extension已经匹配,在执行完它的action后,还会继续执行后序的extension。其默认值为false。

 

{exten_name}可以是任何值。有一种特殊情况,如果exten_name正好与destination_number相等的话,解析器会从这个extension开始解析。但这是意味着就会执行它(执行要看它里面的condition)。如果没有这一特殊情况,解析器会从第一个extension开始解析。

 

如果condition中的field与expression匹配,再执行condition中的action。此时如果expresion中的以()括起来的值话,$1,$2,…,$N会依次得到这些值。在action中的data可以使用这些变量。

 

如果没有匹配成功,则会执行中的指令。此时,因为没有匹配,所以$1,$2等是没有值的。

 

condition中除了field和expression参数外,还可以有一个break参数,这个参数指明什么情况下中断这个extension的条件匹配。也就是说extension在什么情况下在这个condition中止查询,这个condition后面的condition不在执行了。

 

break的值可以是:

 

‘on-true’ :  如果这个匹配成功,则下面的condition不再查询

‘on-false’:  如果这个匹配失败,则…… (这个是默认值) 。也就是说,默认的情况下,只要有一个condition匹配失败了,这个extension也就不再往下执行了,再换它下面的extension。

‘always’  : 总是在此处停止

‘never’    : 永远不在此处停止

示例1:

 

<extension>

  

  <condition field="destination_number" expression="^500$">

     

     <action application="bridge" data="sofia/profilename/500%x.x.x.x"/>

     

     

  condistion>

extension>

示例2,通过网关呼叫用户:

 

<extension name="testing">

   

  <condition field="destination_number" expression="^(100)$">

    

    <action application="bridge" data="sofia/gateway/gw/$1"/>

  condition>

extension>

 

condition

 

condition就是决定当然呼叫是否要在这个extension中处理的一个模式匹配标签。

 

语法:

<condition field="[{field_name}|${variable_name}|${api_func(api_args ${var_name})}]" expression="{expression}" break="[on-true|on-false|always|never]">

   <action application="app name" data="app arg"/>

   <anti-action application="app name" data="app arg"/>

</condition>

 

fileld和expression是必须的,break是可选的。

有一些内部变量可以用:

  • context Why can we use the context as a field? Give us examples of usages please.
  • rdnis Redirected Number, the directory number to which the call was last presented.
  • destination_number Called Number, the number this call is trying to reach (within a given context)
  • dialplan Name of the dialplan module that are used, the name is provided by each dialplan module. Example: XML
  • caller_id_name Name of the caller (provided by the User Agent that has called us).
  • caller_id_number Directory Number of the party who called (caller) -- can be masked (hidden)
  • ani Automatic Number Identification, the number of the calling party (caller) -- cannot be masked
  • aniii The type of device placing the call ANI2
  • uuid Unique identifier of the current call? (looks like a GUID)
  • source Name of the FreeSWITCH module that received the call (e.g. PortAudio)
  • chan_name Name of the current channel (Example: PortAudio/1234). Give us examples when this one can be used.
  • network_addr IP address of the signaling source for a VoIP call.
  • year Calendar year, 0-9999
  • yday Day of year, 1-366
  • mon Month, 1-12 (Jan = 1, etc.)
  • mday Day of month, 1-31
  • week Week of year, 1-53
  • mweek Week of month, 1-6
  • wday Day of week, 1-7 (Sun = 1, Mon = 2, etc.)
  • hour Hour, 0-23
  • minute Minute (of the hour), 0-59
  • minute-of-day Minute of the day, (1-1440) (midnight = 1, 1am = 60, noon = 720, etc.)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值