freeswitch dialplan 筆記 |
發(fā)布時間: 2012/9/15 21:07:05 |
????我建了一個 Freeswitch 內核研究 交流群, 45211986, 歡迎加入, 另外,提供基于SIP的通信服務器及客戶端解決方案。 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 實際上也是一個邏輯上的概念,他并不是傳統(tǒng)pbx上分機的概念,一個extension 代表一個小的,根據(jù)被叫號碼指定的一個功能集合,一個extension被其name唯一標示,freeswitch默認配置包含三個Context, 名字分別為default,public和features,default為主dialplan,注冊到freeswitch的分機會被路由到此context,大部分都在這里實現(xiàn),public是從外部(未注冊)或者那些未認證的客戶端呼叫到freeswitch時采用的Context,features context是一些呼叫特性的實現(xiàn),每個extension是根據(jù)條件執(zhí)行的一系列application,一般是根據(jù)被叫號碼指定的一系列規(guī)則,這些application 構成了可編程pbx的基礎,context, extension,application(action)關系如下:
每個進入freeswitch的呼叫都在freeswitch里預先定義了其 context,DialPlan,及extenstion,這些規(guī)則指定了如何路由這個呼叫,系統(tǒng)默認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,根據(jù)被叫號碼對應不同功能,列表如下:
這些功能的實現(xiàn)默認都在default.xml中。 Xml dialplan大量使用兼容perl的正則表達式,大多用在${destination_number}的比較上, 常用的如 ^789 --------------------------匹配與789開頭的 789$ ---------------------------匹配以789結尾的 \d-------------------------------匹配 0-9任意數(shù)字 ^\d$----------------------------以任意數(shù)字開頭的 ^\d{3}$ ---------------------匹配以三個數(shù)字開頭的 ^(\d{5})$--------------------匹配以五個數(shù)字開頭的,并把變量保存到$1中 ^(9\d{10}|123)$ 匹配以123開頭或者以9,加上10個數(shù)字開頭 等等。 另外,freeswitch提供控制臺命令regex,可以測試指定字符串是否與某個模式匹配, 格式為regex 字符串|模式,如: freeswitch@internal> regex1234|^\d{4} 返回true. 億恩-天使(QQ:530997) 電話 037160135991 服務器租用,托管歡迎咨詢。 本文出自:億恩科技【prubsntakaful.com】 |