📄 ua_appprobe.cpp
字号:
{
if (G_trace >= 1) std::cerr << "== Entering buildReqInDialog" << std::endl;
SIP_MessageContainer* L_Rsp = new SIP_MessageContainer;
print_message_info(P_Message_rsp, "Sending");
L_Rsp->setPayload(P_Message_rsp);
// set the call with 1 for the User and the Provider value set by the stack
L_Rsp->setCallId
(FF_Identifier(1,
P_initialRequest.getCallId().
getProviderIdentifier()));
// set the dialogId with 1 for the User and the Provider value set by
// the stack
L_Rsp->setDialogId(FF_Identifier(1,P_initialRequest.getDialogId().
getProviderIdentifier()));
// set the TransactionId with 1 for the User and the Provider value
// set by the stack
L_Rsp->setTransactionId(FF_Identifier
(1,-1));
// Set also the subscription IF if available
L_Rsp->setSubscriptionId(FF_Identifier
(1,P_initialRequest.getSubscriptionId().
getProviderIdentifier()));
if (G_trace >= 1) {
fprintf(stderr,
"== Building request with provider IDs:\n"
"== Call-ID = %d,\n"
"== Dialog-ID = %d,\n"
"== Trans-ID = %d,\n"
"== Sub-ID = %d.\n",
L_Rsp->getCallId().getProviderIdentifier(),
L_Rsp->getDialogId().getProviderIdentifier(),
L_Rsp->getTransactionId().getProviderIdentifier(),
L_Rsp->getSubscriptionId().getProviderIdentifier());
}
if (G_trace >= 2) std::cerr << "== Returning from buildRsp" << std::endl;
return L_Rsp;
}
SIP_Event* UA_AppProbe::createMessage () throw ()
{
if (G_trace >= 1) std::cerr << "== Entering createMessage" << std::endl;
return new(std::nothrow) SIP_MessageContainer;
}
void UA_AppProbe::destroyMessage (SIP_Event& P_message) throw ()
{
if (G_trace >= 1) std::cerr << "== Entering destroyMessage" << std::endl;
delete &P_message;
}
SIP_Probe& UA_AppProbe::getProbe () throw (std::exception)
{
if (SIP_AppProbe::getProbe())
return *SIP_AppProbe::getProbe();
else
throw std::runtime_error("From UA_AppProbe::getProbe, Probe not set yet");
}
void UA_AppProbe::initOrReinitSession(std::string & P_calledUri,
SIP_Service * P_service,
UA_Session * P_session_for_reinvite)
throw ()
{
sip_msg_method_t L_method = SIP_MSG_INVITE;
sip_msg_header_t * L_from = 0;
sip_msg_header_t * L_to = 0;
sip_msg_header_t * L_contact = 0;
sip_msg_header_t * L_eventhdr = 0;
sip_msg_header_t * L_expires = 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_status_t L_sip_rc;
sip_msg_error_t L_error;
sip_msg_body_t * L_sdp_body = 0;
sdp_announcement_t * L_sdp = 0;
UA_Session * L_session = 0;
if (G_trace >= 1)
std::cerr <<"== myAppProbeClient::sendNewCall"<<std::endl;
std::string L_transport;
std::string L_extensionMethodName;
char* L_extensionMethodNameRef = 0;
if (getTransport() == SIP_TRANSPORT_TCP)
L_transport = "tcp";
else
L_transport = "udp";
if(!P_session_for_reinvite) {
L_session = dynamic_cast<UA_Session*>
(getProbe().createSession(*P_service));
if (L_session == 0)
{
std::cerr <<"== myAppProbeClient::sendNewCall new "
<<"session can't be created"
<<std::endl;
return;
}
if (G_trace >= 1)
std::cerr <<"== myAppProbeClient::sendNewCall new session created"
<<std::endl;
L_request_uri = sip_msg_parse_uri((char *)P_calledUri.c_str(), &L_error);
if(!L_request_uri)
{
std::cerr<<"== Syntax error near token \'"
<<L_error.unexpected_token<<"\' in request URI\n" <<std::endl;
return ;
}
L_session->setService(*P_service);
} else {
if (G_trace >= 1)
std::cerr
<< "== myAppProbeClient::sendNewCall re-using previous "
<< "session for re-invite"
<< std::endl;
L_session = P_session_for_reinvite;
L_request_uri = sip_msg_new_empty_uri();
}
SIP_MessageContainer* L_event = 0;
if (!G_subscribe || (G_subscribe && !G_new_call))
{
L_sdp = sdp_new_announcement(0,
(char *)"media",
(char *)getSipUserInfo().c_str(),
P_session_for_reinvite ? // The body must be different
(char *)"12341234" : // in a re-invite to make the
(char *)"43214312", // difference with a session-timer
(char *)"2",
(char *)"IN",
(char *)"IP4",
(char *)"127.0.0.2",
NULL);
if(!L_sdp)
{
std::cerr <<"== Unable to build SDP announcement\n"<<std::endl;
return;
}
L_sdp_body = sip_msg_new_sdp_body(L_sdp,SIP_FALSE, NULL);
}
L_calling_uri = sip_msg_new_sip_url((char *)getSipUserInfo().c_str(),
(char *)getHostname().c_str(),
getPort(),
(char *)L_transport.c_str(),
NULL,
SIP_MSG_NONE,
NULL,
-1,
NULL,
SIP_FALSE,
NULL,
NULL);
if(!L_calling_uri)
{
std::cerr <<"== Unable to build the calling uri"<<std::endl;
return ;
}
L_headerVector = sip_msg_new_header_vector (&L_error);
if (!L_headerVector)
{
std::cerr <<"== Unable to build the header vector"<<std::endl;
return ;
}
if(!P_session_for_reinvite) {
if (sip_msg_insert_header (L_headerVector,
sip_msg_new_from_header(L_calling_uri,
NULL,
NULL,
NULL,
NULL),
-1) != SIP_NORMAL){
std::cerr << "== Unable to insert the from header"<<std::endl;
return ;
}
if (sip_msg_insert_header (L_headerVector,
sip_msg_new_to_header(L_request_uri,
NULL,
NULL,
NULL,
NULL),
-1) != SIP_NORMAL){
std::cerr << "== Unable to insert the to header"<<std::endl;
return ;
}
#if 0
if (sip_msg_insert_header (L_headerVector,
sip_msg_new_contact_header(L_calling_uri,
NULL,
NULL,
NULL,
NULL),
-1) != SIP_NORMAL){
std::cerr << "== Unable to insert the contact header"<<std::endl;
return ;
}
#endif
}
char to_string[255];
sip_msg_print_header(sip_msg_new_to_header(L_request_uri,
"zy",
NULL,
NULL,
NULL),
to_string, 255, SIP_FALSE, NULL);
std::cerr << "to_string["<<to_string<< "]" <<std::endl;
char from_string[255];
sip_msg_print_header(sip_msg_new_from_header(L_calling_uri,
"hello",
NULL,
NULL,
NULL),
from_string, 255, SIP_FALSE, NULL);
std::cerr << "from_string["<<from_string<< "]" <<std::endl;
if (G_subscribe && G_new_call)
{
static int L_id = 0;
char L_idstr[10];
L_id++;
sprintf(L_idstr, "%d", L_id);
L_eventhdr = sip_msg_new_event_header((char *)"TESTEVENT",
L_idstr,
NULL,
NULL);
if(!L_eventhdr)
{
std::cerr <<"== Unable to build the event: header\n"<<std::endl;
return ;
}
L_sip_rc = sip_msg_insert_header (L_headerVector,L_eventhdr,-1);
if (L_sip_rc != SIP_NORMAL)
{
std::cerr << "== Unable to insert header to "
<<L_error.unexpected_token<<std::endl;
return ;
}
L_expires = sip_msg_new_expires_header(G_expires,
NULL,
NULL);
if(!L_expires)
{
std::cerr <<"== Unable to build the expires: header\n"<<std::endl;
return ;
}
L_sip_rc = sip_msg_insert_header (L_headerVector,L_expires,-1);
if (L_sip_rc != SIP_NORMAL)
{
std::cerr << "== Unable to insert header to "
<<L_error.unexpected_token<<std::endl;
return ;
}
L_method = SIP_MSG_SUBSCRIBE;
}
if (G_refer && G_new_call)
{
if (G_trace >= 1)
std::cerr <<"== myAppProbeClient::sendNewCall with refer"<<std::endl;
std::string L_referToString;
L_referToString.append("Refer-To:");
L_referToString.append(G_referTo);
sip_msg_header_t * L_referTo =
sip_msg_new_raw_header((char*)L_referToString.c_str(),0,&L_error);
if (L_referTo == 0)
{
std::cerr << "== Unable to create Refer-To raw header "
<<L_error.unexpected_token<< " with string "
<< L_referToString <<std::endl;
return ;
}
L_sip_rc = sip_msg_insert_header (L_headerVector,L_referTo,-1);
if (L_sip_rc != SIP_NORMAL)
{
std::cerr << "== Unable to insert header Refer-To "
<<L_error.unexpected_token<<std::endl;
return ;
}
if (sip_msg_insert_header (L_headerVector,
sip_msg_new_contact_header(L_calling_uri,
NULL,
-1,
-1,
NULL,
NULL),
-1) != SIP_NORMAL){
std::cerr << "== Unable to insert the contact header"<<std::endl;
return ;
}
L_method = SIP_MSG_EXTENSION;
L_extensionMethodName = "REFER";
L_extensionMethodNameRef = (char*)L_extensionMethodName.c_str();
}
l_sipRequest = sip_msg_new_request
(L_method,
L_request_uri,
NULL,
L_headerVector,
L_sdp_body,
L_extensionMethodNameRef,
0,
&L_error );
char r_url[255];
sip_msg_print_uri(L_request_uri,r_url,255,NULL);
std::cerr << "r_url["<<r_url<< "]" <<std::endl;
if (!l_sipRequest)
{
std::cerr <<"== 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);
if (P_session_for_reinvite) {
L_event->setCallId
(FF_Identifier(1,L_session->getProviderCallId()));
L_event->setDialogId
(FF_Identifier(1,L_session->getProviderDialogId()));
} else {
L_event->setCallId(FF_Identifier(1,SIP_SRVC_NEW_CALL));
L_event->setDialogId(FF_Identifier(1,SIP_SRVC_NEW_DIALOG));
}
L_event->setTransactionId(FF_Identifier
(1,SIP_SRVC_NEW_TRANSACTION));
if (G_subscribe && G_new_call)
{
L_event->setSubscriptionId(FF_Identifier(1,-1));
}
print_message_info(l_sipRequest, "Sending");
getProbe().send(L_session->getService(),*L_session,*L_event);
L_session->setState(UA_Session::CALL_CALLING);
return;
}
void UA_AppProbe::statelessRequest
(
std::string & P_calledUri,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -