在FreeSWITCH中,要将SIP中的INFO参照INVITE发送,可以通过以下步骤实现:
1. 在FreeSWITCH中创建一个SIP会话,即建立一个SIP通道。
2. 在SIP通道中发送一个INVITE请求。
3. 在SIP通道中等待对方的响应,如果对方接受了INVITE请求,则会发送一个200 OK响应。如果对方拒绝了INVITE请求,则会发送一个4xx或5xx的响应。
4. 在SIP通道中发送一个INFO请求,该请求需要参照之前发送的INVITE请求,即要使用相同的Call-ID、From、To等头部信息,并在INFO请求的Content-Type头部中指定应用程序类型和版本号。
5. 在SIP通道中等待对方对INFO请求的响应,如果对方接受了INFO请求,则会发送一个200 OK响应。如果对方拒绝了INFO请求,则会发送一个4xx或5xx的响应。
在FreeSWITCH中,可以使用mod_sofia模块来实现SIP通道的创建和INVITE请求的发送。可以使用SIP API来发送INFO请求,具体实现步骤如下:
1. 创建一个SIP会话:
```
session = sofia_glue_session_create(switch_core_session_get_pool(session), "sofia/external/username@sip.provider.com", NULL, NULL, NULL);
```
2. 发送一个INVITE请求:
```
switch_channel_set_variable(session->channel, "sip_auto_answer", "true");
switch_channel_set_variable(session->channel, "sip_force_contact", "sip:username@sip.provider.com");
switch_channel_set_variable(session->channel, "sip_force_expires", "1800");
switch_channel_set_variable(session->channel, "sip_callee_id_number", "1000");
switch_channel_set_variable(session->channel, "sip_callee_id_name", "Alice");
switch_channel_set_variable(session->channel, "sip_caller_id_number", "2000");
switch_channel_set_variable(session->channel, "sip_caller_id_name", "Bob");
switch_channel_set_variable(session->channel, "sip_auth_username", "username");
switch_channel_set_variable(session->channel, "sip_auth_password", "password");
switch_channel_set_variable(session->channel, "sip_profile", "external");
switch_channel_set_variable(session->channel, "sip_invite_stamp", switch_channel_get_var(session->channel, "last_sent_cseq"));
switch_channel_set_variable(session->channel, "sip_call_id", switch_channel_get_variable(session->channel, "sip_call_id"));
switch_channel_set_variable(session->channel, "sip_full_from", switch_channel_get_variable(session->channel, "sip_full_from"));
switch_channel_set_variable(session->channel, "sip_full_to", switch_channel_get_variable(session->channel, "sip_full_to"));
switch_channel_set_variable(session->channel, "sip_req_uri", "sip:1000@sip.provider.com");
switch_channel_set_variable(session->channel, "sip_req_user", "1000");
switch_channel_set_variable(session->channel, "sip_req_host", "sip.provider.com");
switch_channel_set_variable(session->channel, "sip_req_port", "5060");
switch_channel_set_variable(session->channel, "sip_req_method", "INVITE");
switch_channel_set_variable(session->channel, "sip_req_user_agent", "FreeSWITCH");
switch_channel_set_variable(session->channel, "sip_req_contact", "<sip:[email protected]:5080;transport=udp>");
switch_channel_set_variable(session->channel, "sip_req_accept", "application/sdp");
switch_channel_set_variable(session->channel, "sip_req_content_type", "application/sdp");
switch_channel_set_variable(session->channel, "sip_req_content_length", "0");
switch_channel_set_variable(session->channel, "sip_req_via_protocol", "udp");
switch_channel_set_variable(session->channel, "sip_req_via_port", "5060");
switch_channel_set_variable(session->channel, "sip_req_via_host", "127.0.0.1");
switch_channel_set_variable(session->channel, "sip_req_via_branch", "z9hG4bK-1234-5678");
switch_channel_set_variable(session->channel, "sip_req_via_rport", "5060");
switch_channel_set_variable(session->channel, "sip_req_via_received", "127.0.0.1");
switch_channel_set_variable(session->channel, "sip_req_via_protocol_id", "1");
switch_channel_set_variable(session->channel, "sip_req_via_secure", "false");
switch_channel_set_variable(session->channel, "sip_req_via_transport", "udp");
switch_channel_set_variable(session->channel, "sip_req_user_info", "<sip:[email protected]>");
switch_channel_set_variable(session->channel, "sip_req_uri_user", "1000");
switch_channel_set_variable(session->channel, "sip_req_uri_host", "sip.provider.com");
switch_core_session_receive_message(session, "mod_sofia", "sip", "INVITE");
```
3. 等待对方的响应:
```
while (switch_channel_up(session->channel) && !switch_channel_test_flag(session->channel, CF_BRIDGE)) {
switch_yield(1000000);
}
```
4. 发送一个INFO请求:
```
switch_channel_set_variable(session->channel, "sip_req_method", "INFO");
switch_channel_set_variable(session->channel, "sip_req_content_type", "application/vnd.3gpp.sms");
switch_channel_set_variable(session->channel, "sip_req_content_length", "10");
switch_channel_set_variable(session->channel, "sip_req_accept", "application/sdp");
switch_channel_set_variable(session->channel, "sip_req_contact", "<sip:[email protected]:5080;transport=udp>");
switch_channel_set_variable(session->channel, "sip_req_uri", "sip:1000@sip.provider.com");
switch_channel_set_variable(session->channel, "sip_req_user", "1000");
switch_channel_set_variable(session->channel, "sip_req_host", "sip.provider.com");
switch_channel_set_variable(session->channel, "sip_req_port", "5060");
switch_channel_set_variable(session->channel, "sip_req_user_info", "<sip:[email protected]>");
switch_core_session_receive_message(session, "mod_sofia", "sip", "INFO");
```
5. 等待对方对INFO请求的响应:
```
while (switch_channel_up(session->channel) && !switch_channel_test_flag(session->channel, CF_BRIDGE)) {
switch_yield(1000000);
}
```
通过以上步骤,就可以在FreeSWITCH中将SIP中的INFO参照INVITE发送。需要注意的是,在发送INFO请求时,需要参照之前发送的INVITE请求,并且在Content-Type头部中指定应用程序类型和版本号。