FreeSWITCH中文网,电话机器人开发网 ,微信订阅号:

FreeSWITCH及VOIP,Openser,电话机器人等产品中文技术资讯、交流、沟通、培训、咨询、服务一体化网络。QQ群:293697898

FreeSWITCH修改头,指定代理添,加请求头,响应头,自定义头等


tags:FreeSWITCH修改头 指定代理添 加请求头 响应头 自定义头等 创建时间:2015-12-23 19:52:48

原文: https://freeswitch.org/confluence/display/FREESWITCH/Sofia+SIP+Stack

Modifying the To: header You can override the To: header by appending ^. Example 1: sofia/foo/user%192.168.1.1^101@$${domain}

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


上海老李,QQ:1354608370,FreeSWITCH QQ群: