Freeswitch自定义SIP头域

添加自定义SIP头

自定义头域必须使用X-前缀

diaplan中

<action application="set" data="sip_h_X-My-Heder=123456"/>

lua脚本中

local my_header = "123456"
...
session:execute("set", "sip_h_X-My-Header=" .. my_header)
session:execute("export","sip_h_X-My-Header=" .. my_header)

实际效果

在sip消息后续的传递过程中,抓取sip信令可以看到在sip消息的头域里面添加了如下的一行:

X-My-Header: 123456

添加有对应信道变量的sip头

  1. 修改方式和添加自定义sip头基本一致;
  2. 可以通过将sip_h_添加到任何通道变量前面来向出站sip添加任意标头;
  3. 自定义sip头需要以X-为前缀,添加有对应信道变量的sip头不需要。

此段描述引用自Freeswitch官网,没有经过测试
Adding Request Header部分

获取自定义sip头

获取sip头和获取信道变量相似

diaplan中

<action application="log" data="My Header: ${sip_h_X-My-Header}"/>

lua脚本中

local my_header = session:getVariable("sip_h_X-My-Header")
freeswitch.consoleLog("info", "My Header: " .. my_header)

获取非自定义sip头

暂时没有找到可以直接获取非自定义的sip头的方法,只能通过相关的信道变量来获取sip头的信息。

猜你喜欢

转载自blog.csdn.net/z_junyu/article/details/84571493