freeswitch查看所有通道变量
概述
freeswitch 是一款好用的开源软交换平台。
实际应用中,我们经常需要对fs中的通道变量操作,包括设置和获取,set & get。
但是,fs中有众多的内部定义通道变量,也有外部传入的自定义通道变量,如何最快找到我们需要的通道变量,就需要一点小的技巧。
环境
centos:CentOS release 7.0 (Final)或以上版本
freeswitch:v1.8.7
GCC:4.8.5
info接口
freeswitch的mod_dptools模块提供了一个app接口“info”。
<action application="info"/>
该接口需要在"call_debug=true"的情况下使用。
测试
设置拨号计划:
<condition field="destination_number" expression="^(\d+)$">
<action application="set" data="call_debug=true"/>
<action application="info"/>
</condition>
发起呼叫,呼叫进入fs后,日志打印如下:
2022-09-19 16:49:27.649708 [DEBUG] switch_core_state_machine.c:328 sofia/external/1001@10.55.55.138 Standard EXECUTE
EXECUTE sofia/external/1001@10.55.55.138 set(call_debug=true)
2022-09-19 16:49:27.649708 [DEBUG] mod_dptools.c:1548 SET sofia/external/1001@10.55.55.138 [call_debug]=[true]
EXECUTE sofia/external/1001@10.55.55.138 info()
2022-09-19 16:49:27.649708 [INFO] mod_dptools.c:1761 CHANNEL_DATA:
Channel-State: [CS_EXECUTE]
Channel-Call-State: [RINGING]
Channel-State-Number: [4]
Channel-Name: [sofia/external/1001@10.55.55.138]
Unique-ID: [f80fc7b2-37f7-11ed-9d90-cd61d01aad6a]
Call-Direction: [inbound]
Presence-Call-Direction: [inbound]
Channel-HIT-Dialplan: [true]
Channel-Call-UUID: [f80fc7b2-37f7-11ed-9d90-cd61d01aad6a]
Answer-State: [ringing]
Caller-Direction: [inbound]
Caller-Logical-Direction: [inbound]
Caller-Username: [1001]
Caller-Dialplan: [XML]
Caller-Caller-ID-Name: [Extension 1001]
Caller-Caller-ID-Number: [1001]
Caller-Orig-Caller-ID-Name: [Extension 1001]
Caller-Orig-Caller-ID-Number: [1001]
Caller-Network-Addr: [10.55.55.138]
Caller-ANI: [1001]
Caller-Destination-Number: [1002]
Caller-Unique-ID: [f80fc7b2-37f7-11ed-9d90-cd61d01aad6a]
Caller-Source: [mod_sofia]
Caller-Context: [public]
Caller-Channel-Name: [sofia/external/1001@10.55.55.138]
Caller-Profile-Index: [1]
Caller-Profile-Created-Time: [1663577367649708]
Caller-Channel-Created-Time: [1663577367649708]
Caller-Channel-Answered-Time: [0]
Caller-Channel-Progress-Time: [0]
Caller-Channel-Progress-Media-Time: [0]
Caller-Channel-Hangup-Time: [0]
Caller-Channel-Transfer-Time: [0]
Caller-Channel-Resurrect-Time: [0]
Caller-Channel-Bridged-Time: [0]
Caller-Channel-Last-Hold: [0]
Caller-Channel-Hold-Accum: [0]
Caller-Screen-Bit: [true]
Caller-Privacy-Hide-Name: [false]
Caller-Privacy-Hide-Number: [false]
variable_direction: [inbound]
variable_uuid: [f80fc7b2-37f7-11ed-9d90-cd61d01aad6a]
variable_session_id: [1]
variable_sip_from_user: [1001]
variable_sip_from_uri: [1001@10.55.55.138]
variable_sip_from_host: [10.55.55.138]
variable_video_media_flow: [sendrecv]
variable_audio_media_flow: [sendrecv]
variable_channel_name: [sofia/external/1001@10.55.55.138]
variable_sip_call_id: [cf6b81f0-b29a-123b-3d84-000c29a63969]
variable_ep_codec_string: [CORE_PCM_MODULE.PCMA@8000h@20i@64000b]
variable_sip_local_network_addr: [10.55.55.137]
variable_sip_network_ip: [10.55.55.138]
variable_sip_network_port: [5080]
variable_sip_invite_stamp: [1663577367649708]
variable_sip_received_ip: [10.55.55.138]
variable_sip_received_port: [5080]
variable_sip_via_protocol: [udp]
variable_sip_from_user_stripped: [1001]
variable_sip_from_tag: [1gjS3t5F2D0gS]
variable_sofia_profile_name: [external]
variable_recovery_profile_name: [external]
variable_sip_Remote-Party-ID: ["Extension 1001" <sip:1001@10.55.55.138>;party=calling;screen=yes;privacy=off]
variable_sip_cid_type: [rpid]
variable_sip_full_via: [SIP/2.0/UDP 10.55.55.138:5080;rport=5080;branch=z9hG4bKF6gF1SKQK6rtF]
variable_sip_from_display: [Extension 1001]
variable_sip_full_from: ["Extension 1001" <sip:1001@10.55.55.138>;tag=1gjS3t5F2D0gS]
variable_sip_full_to: [<sip:1002@10.55.55.137:5080>]
variable_sip_allow: [INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY]
variable_sip_req_user: [1002]
variable_sip_req_port: [5080]
variable_sip_req_uri: [1002@10.55.55.137:5080]
variable_sip_req_host: [10.55.55.137]
variable_sip_to_user: [1002]
variable_sip_to_port: [5080]
variable_sip_to_uri: [1002@10.55.55.137:5080]
variable_sip_to_host: [10.55.55.137]
variable_sip_contact_user: [mod_sofia]
variable_sip_contact_port: [5080]
variable_sip_contact_uri: [mod_sofia@10.55.55.138:5080]
variable_sip_contact_host: [10.55.55.138]
variable_rtp_use_codec_string: [OPUS,G722,PCMU,PCMA,VP8]
variable_sip_user_agent: [FreeSWITCH-mod_sofia/1.6.19+git~20220408T073647Z~f81cb238da~64bit]
variable_sip_via_host: [10.55.55.138]
variable_sip_via_port: [5080]
variable_sip_via_rport: [5080]
variable_max_forwards: [69]
variable_sip_h_X-userName: [userName]
variable_sip_h_X-userNumber: [07551001]
variable_switch_r_sdp: [v=0
o=FreeSWITCH 1663546705 1663546706 IN IP4 10.55.55.138
s=FreeSWITCH
c=IN IP4 10.55.55.138
t=0 0
m=audio 30662 RTP/AVP 8 18 101
a=rtpmap:8 PCMA/8000
a=rtpmap:18 G729/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
]
variable_endpoint_disposition: [DELAYED NEGOTIATION]
variable_DP_MATCH: [ARRAY::1002|:1002]
variable_call_uuid: [f80fc7b2-37f7-11ed-9d90-cd61d01aad6a]
variable_call_debug: [true]
variable_current_application: [info]
总结
从测试结果中,我们可以更轻松的获取自己想要的通道变量的名称和值。
要注意的一点是,info打印的变量名称和channel中的变量名称是有区别的,如果希望在C/C++代码中获取对应的通道变量,需要使用channel中的变量名。
info和channel的通道变量名称对应关系,参考fs官方文档“https://freeswitch.org/confluence/display/FREESWITCH/Channel+Variables”。
空空如常
求真得真