📄 ua_appprobe.cpp
字号:
SIP_Service * P_service,
sip_msg_method_t P_method,
char * P_extension_method,
char * P_CallID
) throw ()
{
sip_msg_header_t * L_CSeq = 0;
sip_msg_header_t * L_CallID = 0;
sip_msg_header_t * L_from = 0;
sip_msg_header_t * L_to = 0;
sip_msg_uri_t * L_request_uri = 0;
sip_msg_uri_t * L_calling_uri = 0;
sip_msg_message_t * l_sipRequest = 0;
sip_msg_header_vector_t * L_headerVector = 0;
sip_msg_body_t * L_sdp_body = 0;
sdp_announcement_t * L_sdp = 0;
sip_status_t L_sip_rc;
sip_msg_error_t L_error;
unsigned int L_cseq_num = 3221225472u ; /* (3/2) * 2^31 */
sip_bool_t L_bool = SIP_FALSE;
SIP_MessageContainer * L_event = 0;
if (G_trace >= 1) {
std::cerr <<"== myAppProbeClient::statelessRequest"<<std::endl;
}
UA_Session* L_session = dynamic_cast<UA_Session*>
(getProbe().createSession(*P_service));
if (L_session == 0) {
std::cerr <<"== myAppProbeClient::statelessRequest "
<<"new session can't be created"
<<std::endl;
return;
}
if (G_trace >= 1) {
std::cerr <<"== myAppProbeClient::statelessRequest new session created"
<<std::endl;
}
if (G_trace >= 1) {
std::cerr << "Building URI from : "
<< getSipUserInfo()
<< "@"
<< getHostname()
<< ":"
<< getPort()
<<std::endl;
}
L_calling_uri =
sip_msg_new_sip_url((char *)getSipUserInfo().c_str(), /* (char*) */
(char *)getHostname().c_str(),/* (char*) */
getPort(), /* int */
(char *)((getTransport() == SIP_TRANSPORT_TCP) ? "tcp" : "udp"),
NULL, /* (char *) */
SIP_MSG_NONE,
NULL,
-1,
NULL,
L_bool,
NULL,
NULL);
if(!L_calling_uri)
{
std::cerr <<"== myAppProbeClient::statelessRequest "
<<"== Unable to build the calling uri"<<std::endl;
return ;
}
L_from = sip_msg_new_from_header(L_calling_uri, NULL, NULL, NULL, NULL);
if(!L_from)
{
std::cerr <<"== myAppProbeClient::statelessRequest "
<<"== Unable to build the From: header\n"<<std::endl;
return ;
}
L_CSeq = sip_msg_new_cseq_header(L_cseq_num,
P_method,
P_extension_method,
NULL, NULL);
if(!L_CSeq)
{
std::cerr <<"== myAppProbeClient::statelessRequest "
<<"== Unable to build the CSeq: header\n"<<std::endl;
return ;
}
L_CallID = sip_msg_new_call_id_header(P_CallID,
NULL, NULL, NULL);
if(!L_CallID)
{
std::cerr <<"== myAppProbeClient::statelessRequest "
<<"== Unable to build the CallID: header\n"<<std::endl;
return ;
}
L_request_uri = sip_msg_parse_uri((char *)P_calledUri.c_str(), &L_error);
if(!L_request_uri)
{
std::cerr<< "== myAppProbeClient::statelessRequest "
<< "== Syntax error near token \'"
<< L_error.unexpected_token
<< "\' in request URI\n"
<< std::endl;
return ;
}
L_session->setReqUri(L_request_uri);
L_to = sip_msg_new_to_header(L_request_uri, NULL,
(char *)"stateless", NULL, NULL);
if(!L_to)
{
std::cerr <<"== myAppProbeClient::statelessRequest "
<<"== Unable to build the To: header\n"<<std::endl;
return ;
}
L_headerVector = sip_msg_new_header_vector (&L_error);
if (!L_headerVector)
{
std::cerr <<"== myAppProbeClient::statelessRequest "
<<"== Unable to build the header vector"<<std::endl;
return ;
}
L_sip_rc = sip_msg_insert_header (L_headerVector,L_from,-1);
if (L_sip_rc != SIP_NORMAL)
{
std::cerr <<"== myAppProbeClient::statelessRequest "
<< "== Unable to insert header from"<<std::endl;
return ;
}
L_sip_rc = sip_msg_insert_header (L_headerVector,L_to,-1);
if (L_sip_rc != SIP_NORMAL)
{
std::cerr <<"== myAppProbeClient::statelessRequest "
<< "== Unable to insert header to "
<<L_error.unexpected_token<<std::endl;
return ;
}
L_sip_rc = sip_msg_insert_header (L_headerVector,L_CallID,-1);
if (L_sip_rc != SIP_NORMAL)
{
std::cerr <<"== myAppProbeClient::statelessRequest "
<< "== Unable to insert the CallID: header"
<< L_error.unexpected_token<<std::endl;
return ;
}
L_sip_rc = sip_msg_insert_header (L_headerVector,L_CSeq,-1);
if (L_sip_rc != SIP_NORMAL)
{
std::cerr <<"== myAppProbeClient::statelessRequest "
<< "== Unable to insert the CSeq: header"
<< L_error.unexpected_token<<std::endl;
return ;
}
if(P_method == SIP_MSG_INVITE) { /* Stateless RE-INVITE */
L_sdp = sdp_new_announcement(0,
(char *)"media",
(char *)getSipUserInfo().c_str(),
(char *)"12341234",
(char *)"2",
(char *)"IN",
(char *)"IP4",
(char *)"127.0.0.2",
NULL);
if(!L_sdp)
{
std::cerr <<"== myAppProbeClient::statelessRequest "
<<"== Unable to build SDP announcement\n"<<std::endl;
return;
}
L_sdp_body = sip_msg_new_sdp_body(L_sdp,SIP_FALSE, NULL);
}
l_sipRequest = sip_msg_new_request
(P_method,
L_request_uri,
NULL,
L_headerVector,
L_sdp_body,
0,
0,
&L_error );
if (!l_sipRequest)
{
std::cerr <<"== myAppProbeClient::statelessRequest "
<<"== Unable to build new Request "
<<L_error.unexpected_token<<std::endl;
return ;
}
L_session->setReqUri(L_request_uri);
L_event = new SIP_MessageContainer;
L_event->setPayload(l_sipRequest);
L_event->setCallId(FF_Identifier
(SIP_SRVC_NO_CALL,SIP_SRVC_NO_CALL));
L_event->setDialogId(FF_Identifier
(SIP_SRVC_NO_DIALOG,SIP_SRVC_NO_DIALOG));
L_event->setTransactionId(FF_Identifier
(1,SIP_SRVC_NEW_TRANSACTION));
L_session->setService(*P_service);
print_message_info(l_sipRequest, "Sending");
getProbe().send(*P_service,*L_session,*L_event);
if(P_method == SIP_MSG_INVITE) { // RE-invite
L_session->setState(UA_Session::CALL_CALLING);
} else { // Bye
L_session->setState(UA_Session::CALL_RELEASING);
}
return;
}
void UA_AppProbe::closeSession(UA_Session& P_session)
{
sip_msg_error_t L_error;
sip_msg_message_t* L_Message_rsp = 0;
if (G_trace >= 1) std::cerr << "== Entering closeSession" << std::endl;
switch (G_closeMode)
{
case 0:
{
SIP_MessageContainer* L_message = new SIP_MessageContainer;
L_message->setCallId
(FF_Identifier(1,P_session.getProviderCallId()));
L_message->setDialogId
(FF_Identifier(1,P_session.getProviderDialogId()));
L_message->setTransactionId
(FF_Identifier(1,-1));
if (G_subscribe)
{
L_message->setSubscriptionId
(FF_Identifier(1,P_session.getProviderSubscriptionId()));
}
if (G_subscribe && G_new_call)
{
std::cout << "Closing subscrition with currentSubscritionMustBeClosed"<<std::endl;
L_message->currentSubscriptionMustBeClosed();
}
else
{
if (!G_silent) {
printf("Closing dialog with : message_ptr -> "
"currentDialogMustBeClosed()\n");
}
L_message->currentDialogMustBeClosed();
}
L_message->setPayload(0);
getProbe().send(P_session.getService(),P_session,*L_message);
}
break;
case 1:
{
if (!G_silent) {
printf("Closing session with getProbe().destroySession().\n");
}
getProbe().destroySession(P_session,SIP_CAUSE_NORMAL);
}
break;
case 2:
{
SIP_MessageContainer* L_message;
if (G_trace >= 1)
std::cerr << "== send BYE "<<std::endl;
if (G_subscribe)
{
sip_msg_header_t * L_expires = 0;
sip_msg_header_vector_t * L_hdr_vector = 0;
L_expires = sip_msg_new_expires_header(0, NULL, NULL);
if (!L_expires)
{
std::cerr <<"== Unable to build new expires header "<<L_error.status
<<std::endl;
getProbe().destroySession(P_session,SIP_CAUSE_NORMAL);
return ;
}
L_hdr_vector = sip_msg_new_header_vector(NULL);
if (!L_hdr_vector)
{
std::cerr <<"== Unable to build header vector "<<L_error.status
<<std::endl;
getProbe().destroySession(P_session,SIP_CAUSE_NORMAL);
return ;
}
sip_status_t L_sip_rc;
L_sip_rc = sip_msg_insert_header (L_hdr_vector,L_expires,-1);
if (L_sip_rc != SIP_NORMAL)
{
std::cerr << "== Unable to insert header" <<std::endl;
return ;
}
L_Message_rsp = sip_msg_new_request
(SIP_MSG_SUBSCRIBE,
sip_msg_new_empty_uri(),
NULL,
L_hdr_vector,
0,
0,
0,
&L_error);
L_message = new SIP_MessageContainer;
L_message->setCallId
(FF_Identifier(1,P_session.getProviderCallId()));
L_message->setDialogId
(FF_Identifier(1,P_session.getProviderDialogId()));
L_message->setTransactionId
(FF_Identifier(1,-1));
L_message->setSubscriptionId
(FF_Identifier(1,P_session.getProviderSubscriptionId()));
if (G_trace >= 1)
std::cerr << "== send UNSUBSCRIBE "<<std::endl;
L_message->setPayload(L_Message_rsp);
if (!G_silent) {
printf("Terminating the subscription with expire = 0.\n");
}
getProbe().send(P_session.getService(),P_session,*L_message);
}
if (!G_subscribe || (G_subscribe && !G_new_call))
{
L_Message_rsp = sip_msg_new_request
(SIP_MSG_BYE,
sip_msg_new_empty_uri(),
NULL,
0,
0,
0,
0,
&L_error);
if (!L_Message_rsp)
{
std::cerr <<"== Unable to build new Request "<<L_er
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -