📄 sipua.c
字号:
sleep(3);
printf("Sending BYE request...\n");
/* send BYE request *//*依靠呼叫状态,SIPcallhandling级处理用户请求也不尽相同*/
/*为什么这里就一定肯定为发送BYE呢*/
sip_call_release(instance,
call,
dialog,
&new_trans,
NULL,
NULL,
SIP_CALL_RELEASE_GRACEFUL,/*从SIP角度看,正常释放。释放呼叫事件回调被调用*/
user_info);/*释放特定呼叫,此例程较复杂,可查看自己的读书笔记*/
printf("The call is terminated.\n");
sip_exit = SIP_TRUE;
}// end 3
return SIP_NORMAL;
}
/*
* FACILITY:
*
* sip_call_on_release
*
* ABSTRACT:
*
* The SIP call release reception callback
*
* FORMAL PARAMETERS:
*
* instance : The SIP call handling instance
* call : The call identifier
* dialog : The dialog identifier
* transaction : The transaction identifier
* request_uri : The request URI in the message
* request : Additional headers in the INVITE
* body : The received body
* user_info : The user info
*
* RETURN VALUE:
*
* SIP_NORMAL : successful completion
*
*/
sip_status_t sip_call_on_release
(
sip_call_inst_t instance,
sip_call_t call,
sip_dialog_t dialog,
sip_trans_t transaction,
sip_msg_uri_t * request_uri,
sip_msg_header_vector_t * request,
sip_msg_body_t * body,
sip_user_info_t * user_info
)
{
sip_call_reply(instance,
call,
dialog,
transaction,
SIP_CALL_NO_SUBSCRIPTION,/*subscriptionID,在这里为0*/
200,
NULL,
NULL,
NULL,
SIP_FALSE,
NULL);/*对入请求,发送一个回复*/
/*此例程允许用户回复入OPTIONS, EXTENSION, INFO,或 re-
INVITE请求。*/
printf("The current call has been released\n");
sip_exit = SIP_TRUE;
return SIP_NORMAL;
}
/*
* FACILITY:
*
* sip_call_on_cancel
*
* ABSTRACT:
*
* The SIP call cancel reception callback
*
* FORMAL PARAMETERS:
*
* instance : The SIP call handling instance
* call : The call identifier
* dialog : The dialog identifier
* transaction : The transaction identifier
* request_uri : The request URI in the message
* request : Additional headers in the INVITE
* body : The received body
* user_info : The user info
*
* RETURN VALUE:
*
* SIP_NORMAL : successful completion
*
*/
sip_status_t sip_call_on_cancel
(
sip_call_inst_t instance,
sip_call_t call,
sip_dialog_t dialog,
sip_trans_t trans,
sip_msg_uri_t * request_uri,
sip_msg_header_vector_t * request,
sip_msg_body_t * body,
sip_user_info_t * user_info
)
{
printf("The current call has been canceled\n");
return SIP_NORMAL;
}
/*
* FACILITY:
*
* sip_call_on_get_media
*
* ABSTRACT:
*
* The SIP get_media reception callback
*
* FORMAL PARAMETERS:
*
* instance : The SIP call instance
* call : The call identifier
* dialog : The dialog identifier
* transaction : The transaction identifier
* status_code : The status code (1xx) received in the response
* reason_phrase : The character string in the received status line
* response : Additional headers in the response
* body : The received body
* user_info : The user info
*
* RETURN VALUE:
*
* SIP_NORMAL : successful completion
*
*/
sip_status_t sip_call_on_get_media
(
sip_call_inst_t instance,
sip_call_t call,
sip_dialog_t dialog,
sip_trans_t transaction,
sip_uint32_t status_code,
char * reason_phrase,
sip_msg_header_vector_t * response,
sip_msg_body_t * body,
sip_user_info_t * user_info
)
{
sip_trans_t new_trans;
printf("Get media received\n");
/* send ACK request */
sip_call_connect(instance,
call,
dialog,
transaction,
NULL,
body,
NULL);/*在接收了最终的成功响应后,发送ACK请求*/
printf("The call has been accepted (in get_media).\n");
if(!no_bye) {// 1
printf("Waiting 3 seconds before releasing the call...\n");
sleep(3);
printf("Sending BYE request...\n");
/* send BYE request */
sip_call_release(instance,
call,
dialog,
&new_trans,
NULL,
NULL,
SIP_CALL_RELEASE_GRACEFUL,/*从SIP角度看,正常释放。释放呼叫事件回调被调用*/
user_info);/*释放特定的呼叫,此实例比较复杂,参考读书笔记*/
/*依靠呼叫状态,SIPcallhandling级处理用户请求不同,怎么知道此是发送BYE请求*/
printf("The call is terminated.\n");
sip_exit = SIP_TRUE;
}//end 1
return SIP_NORMAL;
}
/*
* FACILITY:
*
* sip_call_on_request
*
* ABSTRACT:
*
* Any request that cannot be mapped on defined callback
*
* FORMAL PARAMETERS:
*
* instance : The SIP call instance
* call : The call identifier
* dialog : The dialog identifier
* transaction : The transaction identifier
* subscription : The subscription identifier
* method : The method type
* method_name : The method name
* request_uri : The request URI in the message
* from : The from header
* to : The to header
* request : Additional headers in the INVITE
* body : The received body
* user_info : The user info
*
* RETURN VALUE:
*
* SIP_NORMAL : successful completion
*
*/
sip_status_t sip_call_on_request
(
sip_call_inst_t instance,
sip_call_t call,
sip_dialog_t dialog,
sip_trans_t transaction,
sip_subs_t subscription,
sip_msg_method_t method,
char * method_name,
sip_msg_uri_t * request_uri,
sip_msg_header_t * from,
sip_msg_header_t * to,
sip_msg_header_vector_t * request,
sip_msg_body_t * body,
sip_user_info_t * user_info
)
{
printf("Unknown request received\n");
return SIP_NORMAL;
}
/*
* FACILITY:
*
* sip_call_on_reply
*
* ABSTRACT:
*
* Any response that cannot be mapped on defined callback
*
* FORMAL PARAMETERS:
*
* instance : The SIP call instance
* call : The call identifier
* dialog : The dialog identifier
* transaction : The transaction identifier
* subscription : The subscription identifier
* method : The method type
* method_name : The method name
* status_code : The status code (1xx) received in the response
* reason_phrase : The character string in the received status line
* response : Additional headers in the response
* body : The received body
* user_info : The user info
*
* RETURN VALUE:
*
* SIP_NORMAL : successful completion
*
*/
sip_status_t sip_call_on_reply
(
sip_call_inst_t instance,
sip_call_t call,
sip_dialog_t dialog,
sip_trans_t transaction,
sip_subs_t subscription,
sip_msg_method_t method,
char * method_name,
sip_uint32_t status_code,
char * reason_phrase,
sip_msg_header_vector_t * response,
sip_msg_body_t * body,
sip_user_info_t * user_info
)
{
printf("Response received: '%d", status_code);
if(reason_phrase) {
printf(" %s", reason_phrase);
}
printf("'\n");
return SIP_NORMAL;
}
/*
* FACILITY:
*
* The SIP call subscription reception callback
*
* FORMAL PARAMETERS:
*
* instance : The SIP call instance
* call : The call identifier
* dialog : The dialog identifier
* transaction : The transaction identifier
* subscription : The subscription identifier
* request_uri : The request URI to forward the INVITE
* from : The from header
* to : The to header
* contact : The contact header
* event : The event header for subscription
* expires : The event expiration header
* request : Additional headers in the INVITE
* body : The INVITE body
* user_info : The user info
*
* RETURN VALUE:
*
* SIP_NORMAL : successful completion
*
*/
sip_status_t sip_call_on_evt_subscribe
(
sip_call_inst_t instance,
sip_call_t call,
sip_dialog_t dialog,
sip_trans_t transaction,
sip_subs_t subscription,
sip_msg_uri_t * request_uri,
sip_msg_header_t * from,
sip_msg_header_t * to,
sip_msg_header_t * contact,
sip_msg_header_t * event,
sip_msg_header_t * expires,
sip_msg_header_vector_t * request,
sip_msg_body_t * body,
sip_user_info_t * user_info
)
{
sip_status_t sip_status;
int index;
sip_msg_header_t * contact_response;
sip_msg_header_t * expires_response;
sip_msg_header_t * subscription_state;
char from_string[255];
if(sip_msg_print_header(from, from_string, 255, SIP_FALSE, NULL) > 0) {/*此例程编码一个完整的SIP头结构为包含等价SIP头的字符串。呼叫者必须提供空的内存缓冲,和此缓冲的可用字节数*/
printf("Subscription for event '%s' received %s\n",
event -> structured_header -> content.event.event_type,
from_string);
}
contact_response = sip_msg_new_contact_header
(request_uri, NULL, -1, -1, NULL, NULL);/*此例程用给定的参数建造一个新的SIPContact头,或更改一个存在的Contact头的参数*/
if(!contact_response) {
printf("Unable to build the Contact: header\n");
exit(1);
}
expires_response = sip_msg_new_expires_header(10, NULL, NULL);/*例程用给定的参数建造了新的SIPExpires头,或更改存在的头中的参数*/
if(!expires_response) {
printf("Unable to build the Expires: header\n");
exit(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -