freeswitch 自定义头字段

本文详细介绍如何使用FreeSWITCH进行SIP高级配置,包括指定SIP代理、添加请求和响应头、设置自定义头、过滤联系人及执行SIP摘要授权等。通过这些配置,可以增强SIP会话的灵活性和安全性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Specifying SIP Proxy With fs_path
You can route a call through a specific SIP proxy by using the "fs_path" directive. Example:
sofia/foo/user@that.domain;fs_path=sip:proxy.this.domain
Channel Variables

Adding Request Headers
You can add arbitrary headers to outbound SIP calls by prefixing the string 'sip_h_' to any channel variable, for example:
<action application="set" data="sip_h_X-Answer=42"></action>
<action application="bridge" data="sofia/mydomain.com/1000@example.com"></action>
Note that for BYE requests, you will need to use the prefix 'sip_bye_h_' on the channel variable.
Informational Tip
While not required, you should prefix your headers with "X-" to avoid issues with interoperability with other SIP stacks.
All inbound SIP calls will install any X- headers into local variables.
This means you can easily bridge any X- header from one FreeSWITCH instance to another.
To access the header above on a 2nd box, use the channel variable ${sip_h_X-Answer}
It is important to note that the syntax ${sip_h_customer-header} can't be used to retrieve any custom header not starting with X-.
It is because Sofia only reads and puts into variables custom headers starting with X-.


Adding Response Headers
There are three types of response header prefixes that can be set:
Response header
sip_rh_
Provisional response header
sip_ph_
Bye response header
sip_bye_h_
Each prefix will exclusively add headers for their given types of requests - there is no "global" response header prefix that will add a header to all response messages.
For example:
<action application="set" data="sip_rh_X-Reason=Destination Number Not in Footprint"></action>
<action application="set" data="sip_bye_h_X-Accounting=Some Accounting Data"></action>

Adding Custom Headers
For instance, you may need P-Charge-Info to append to your INVITE header, you may do as follows:
<action application="set"><![CDATA[sip_h_P-Charge-Info=<sip:${caller_id_number}@${domain_name}>;npi=0;noa=3]]></action>
Then, you would see it in SIP message:
INVITE sip:19099099099@1.2.3.4 SIP/2.0
Via: SIP/2.0/UDP 5.6.7.8:5080;rport;branch=z9hG4bKyg61X9v3gUD4g
Max-Forwards: 69
From: "DJB" <sip:2132132132@5.6.7.8>;tag=XQKQ322vQF5gK
To: <sip:19099099099@1.2.3.4>
Call-ID: b6c776f6-47ed-1230-0085-000f1f659e58
CSeq: 30776798 INVITE
Contact: <sip:mod_sofia@5.6.7.8:5080>
User-Agent: FreeSWITCH-mod_sofia/1.2.0-rc2+git~20120713T162602Z~0afd7318bd+unclean~20120713T184029Z
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, UPDATE, INFO, REGISTER, REFER, NOTIFY
Supported: timer, precondition, path, replaces
Allow-Events: talk, hold, conference, refer
Content-Type: application/sdp
Content-Disposition: session
Content-Length: 229
P-Charge-Info: <sip:2132132132@5.6.7.8>;npi=0;noa=3
X-FS-Support: update_display,send_info.
Remote-Party-ID: "DJB" <sip:2132132132@5.6.7.8>;party=calling;screen=yes;privacy=off
Strip SIP Headers
Strip SIP Headers

Additional Channel variables
Additional variables may also be set to influence the way calls are handled by sofia.
For example, contacts can be filtered by setting the 'sip_exclude_contact' variable. Example:
<anti-action application="set" data="sip_exclude_contact=${network_addr}"></anti>
Or you can perform SIP Digest authorization on outgoing calls by setting sip_auth_username and sip_auth_password variables to avoid using Gateways to authenticate. Example:
<action application="bridge" data="[sip_auth_username=secretusername,sip_auth_password=secretpassword]sofia/external/00123456789@sip.example.com"></action>
Changing the SIP Contact user FreeSWITCH normally uses mod_sofia@ip:port for the internal SIP contact. To change this to foo@ip:port, there is a variable, sip_contact_user:
{sip_contact_user=foo}sofia/my_profile/1234@192.168.0.1;transport=tcp

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值