天天看点

freeswitch dialplan 笔记

我建了一个 Freeswitch 内核研究 交流群, 45211986, 欢迎加入, 另外,提供基于SIP的通信服务器及客户端解决方案,

承接 sip/ims 视频客户端开发,支持接入sip软交换,ims核心网,支持 语音,视频,即时通信功能,视频格式支持 h263,h264,mpeg4 软编软解,提供硬件编解码接口对接,提供服务器,有兴趣请联系我。

Freeswitch包含xml 格式dialplan,asterisk likedialplan以及外部语言接口的dialplan,

Dialplan放在conf/dialplan目录,由三个主要文件组成:

default.xml—The primary FreeSWITCHDialplan configuration

public.xml—Handles calls coming in toFreeSWITCH from another location

features.xml—A special context for handlingspecific dialing features

default/—Files in this directory getincluded in the default context

public/—Filesin this directory get included in the public context

Xml格式dialplan从高到低分group ,Context,extenstion,级别.Group是Context的集合,

每个Context一个或者多个extenstion的组合,是一个逻辑上的概念,extension  实际上也是一个逻辑上的概念,他并不是传统pbx上分机的概念,一个extension 代表一个小的,根据被叫号码指定的一个功能集合,一个extension被其name唯一标示,freeswitch默认配置包含三个Context, 名字分别为default,public和features,default为主dialplan,注册到freeswitch的分机会被路由到此context,大部分都在这里实现,public是从外部(未注册)或者那些未认证的客户端呼叫到freeswitch时采用的Context,features context是一些呼叫特性的实现,每个extension是根据条件执行的一系列application,一般是根据被叫号码指定的一系列规则,这些application 构成了可编程pbx的基础,context, extension,application(action)关系如下:

每个进入freeswitch的呼叫都在freeswitch里预先定义了其 context,DialPlan,及extenstion,这些规则指定了如何路由这个呼叫,系统默认xml dialplan的context为default.

/usr/local/freeswitch/conf/dialplan/default.xml

为freeswitch内部分机(验证)的默认dialplan,Context name 为default,里面包含许多例子,

此文件同时包括/usr/local/freeswitch/conf/dialplan/default/*.xml目录下的所有文件,

所以如果想在default context下添加自己的dialplan,令写一个xml放在 default目录即可。

另外,如果想添加自己的context,可以在/usr/local/freeswitch/conf/dialplan/ 添加一个xml文件,

与default.xml类似,/usr/local/freeswitch/conf/dialplan/public.xml为非注册到freeswitch的终端呼入的dialplan,Context 名为 public,/usr/local/freeswitch/conf/dialplan/public/目录可以添加context为public的extension.

在xml配置文件里包含其他目录下文件的方法为用宏X-PRE-PROCESS,如下例子包含default目录下的所有xml文件到此xml文件。

<X-PRE-PROCESS cmd="include"data="default/*.xml"/>

Freeswitch默认提供了大量测试demo,根据被叫号码对应不同功能,列表如下:

Extension: Function:
1000—1019 Local Extensions
** + Extension Number Intercept a ringing phone (that is, "call pickup")
2000 Sample call group: Sales
2001 Sample call group: Support
2002 Sample call group: Billing
3000-3399 Sample conference rooms
4000 or *98 Retrieve voicemail
5000 Demo IVR
5900 FIFO queue park
5901 FIFO queue retrieve
6000 Valet park retrieval, manual
6001-6099 Valet park/retrieval, automatic
9178 Example fax receive
9179 Example fax transmit
9180 Ring test, far end generates ring tone
9181 Ring test, send U.K. ring tone
9182 Ring test, send music as ring tone
9183 Answer, then send U.K. ring tone
9184 Answer, then send music as ring tone
9191 ClueCon registration
9192 Information dump
9195 Delayed echo test
9196 Echo test
9197 Milliwatt tone (test signal quality)
9198 Tetris
9664 Music on hold

这些功能的实现默认都在default.xml中。

Xml dialplan大量使用兼容perl的正则表达式,大多用在${destination_number}的比较上,

常用的如

^789  --------------------------匹配与789开头的

789$ ---------------------------匹配以789结尾的

 \d-------------------------------匹配 0-9任意数字

^\d$----------------------------以任意数字开头的

^\d{3}$ ---------------------匹配以三个数字开头的

^(\d{5})$--------------------匹配以五个数字开头的,并把变量保存到$1中

^(9\d{10}|123)$ 匹配以123开头或者以9,加上10个数字开头

 等等。

另外,freeswitch提供控制台命令regex,可以测试指定字符串是否与某个模式匹配,