📄 transstates.c
字号:
/**************************************************************************************
* setTheParallelTunnelingStateByMessage
*
* putrpose: to determine the parallel tunneling state of the session according to its previous
* state and the faststart and tunneling states of the session.
* This routine handles all outgoing messages (setup for outgoing calls and all
* the rest for incoming calls. The routine modifies the session state variables!
*
* Input: transGlobals - The global data of the module.
* session - the session on which the message is to be sent.
* msgType - The type of the message (setup or other)
* msgBody - the node to the message UU-IE part
* outgoing - RV_TRUE: an outgoing message; RV_FALSE - an incoming message.
*
***************************************************************************************/
void setTheParallelTunnelingStateByMessage(cmTransGlobals *transGlobals,
cmTransSession *session,
int msgType,
int msgBody,
RvBool outgoing)
{
/* for SETUP check if we have both tunneling and faststart and we support
the parallel mode. */
if (msgType == cmQ931setup)
{
if (outgoing)
{
if ((session->faststartState == fsOffered) &&
( (session->tunnelingState == tunnOffered) ||
(session->tunnelingState == tunnPossible) )&&
(session->isParallelTunnelingSupported)
)
session->parallelTunnelingState = parllOffered;
else
session->parallelTunnelingState = parllNo;
}
else
{ /* incoming setup */
int res = -1;
/* check if parallel tunneling was offered */
__pvtGetNodeIdByFieldIds(res, transGlobals->hPvt, msgBody,
{ _q931(h323_message_body)
_q931(setup)
_q931(parallelH245Control)
LAST_TOKEN
});
if ( (session->isParallelTunnelingSupported) && (res >=0) )
session->parallelTunnelingState = parllApproved;
}
}
}
/**************************************************************************************
* needToOpenH245
*
* putrpose: to determine according to the session params whether
* we shall want to open an H.245 (actually doing the connect).
* Input: session - the session on which the message is to be sent.
* forceOpen - we must open (due to a startH245 facility).
*
***************************************************************************************/
RvBool needToOpenH245(cmTransSession *session, RvBool forceOpen)
{
RvBool needToOpen = RV_FALSE;
{
if (forceOpen)
/* we were forced, so we obey */
needToOpen = RV_TRUE;
else
{
/* in case of no forcing, we need to check if we may open an
H.245 connection according to the session's tunneling state
and fast start state */
switch (session->tunnelingState)
{
case tunnNo:
case tunnRejected:
{
if ( (session->faststartState == fsNo) ||
(session->faststartState == fsRejected) )
/* this the normal case (no tunneling, no faststart),
go ahead and ry to open an H.245 connection */
needToOpen = RV_TRUE;
else
{
/* we don't have tunneling but we do have a fast start
on the session so only an explicit user request may
open a real H.245 connection, and even that only
when FS is stable */
if( ((session->openControlWasAsked) || (session->switchToSeparateWasAsked)) &&
(session->faststartState != fsOffered) )
needToOpen = RV_TRUE;
}
break;
}
case tunnApproved:
{
/* we have tunneling,
only user request for a sepearate connection may open */
if (session->switchToSeparateWasAsked)
needToOpen = RV_TRUE;
break;
}
default:
{
/* all other cases mean that we are still not in a stable tunneling state
so we shouldn't open H.245 yet */
needToOpen = RV_FALSE;
break;
}
}
}
}
return needToOpen;
}
/**************************************************************************************
* determineIfToOpenH245
*
* putrpose: This routine checks if it's time to start a H.245 connection either by:
* - listenning if we have an H.245 address and it's time according to the
* H.245 stage to send that address. If so, the address is sent and the
* module starts listenning on that address.
* - trying to connect, if we have the remotes address.
*
* Input: outgoing - RV_TRUE - if an outgoing message, RV_FALSE - if incoming one.
* transGlobals - The global data of the module.
* session - the session on which the message is to be sent.
* messageBodyNode - the UU-IE part of the message to be inspected.
* msgType - The type of the message (setup or other)
* manualRAS - The RAS mode of the application
*
***************************************************************************************/
RvBool determineIfToOpenH245(RvBool outgoing,
cmTransGlobals *transGlobals,
cmTransSession *session,
int messageBodyNode,
int msgType)
{
int res;
RvBool proceed = RV_FALSE;
RvBool forceOpen = RV_FALSE;
RvBool needToOpen;
/* Phase 1: Determine if the stage allows any H.245 operation */
/* according to the message type and the H245 stage parameter
determine whether we can do any operation now */
switch (msgType)
{
case cmQ931setup:
{
if ( (session->h245Stage == cmTransH245Stage_setup) ||
(session->h245Stage == cmTransH245Stage_early) )
proceed = RV_TRUE;
break;
}
case cmQ931callProceeding:
{
if ( (session->h245Stage == cmTransH245Stage_setup) ||
(session->h245Stage == cmTransH245Stage_callProceeding) )
proceed = RV_TRUE;
break;
}
case cmQ931alerting:
{
if ( (session->h245Stage == cmTransH245Stage_setup) ||
(session->h245Stage == cmTransH245Stage_callProceeding) ||
(session->h245Stage == cmTransH245Stage_alerting) )
proceed = RV_TRUE;
break;
}
case cmQ931connect:
{
if ( (session->h245Stage == cmTransH245Stage_setup) ||
(session->h245Stage == cmTransH245Stage_callProceeding) ||
(session->h245Stage == cmTransH245Stage_alerting) ||
(session->h245Stage == cmTransH245Stage_connect) ||
(session->h245Stage == cmTransH245Stage_early) )
proceed = RV_TRUE;
break;
}
}
/* Phase 2: Check for incoming startH245 FACILITY message */
/* first check if we are forced to open H.245 by an incoming
FACILITY with startH245 reason */
if ( (!outgoing) && (msgType == cmQ931facility) )
{
int node;
/* get the reason */
__pvtGetNodeIdByFieldIds(node, transGlobals->hPvt, messageBodyNode,
{ _q931(h323_message_body)
_q931(facility)
_q931(reason)
_q931(startH245)
LAST_TOKEN
});
if (node >= 0)
{
/* if we don't support H.245 we must reply with a FACILITY with noH245 */
if (session->h245Stage == cmTransH245Stage_noH245)
{
int newMessage;
/* we do not support H.245, report it with facility with NoH245 reason */
if (createMessage(transGlobals,
cmQ931facility,
session->CRV,
session->callId,
&newMessage)
)
{
/* set the reason */
int nodeId;
TRANSERR err;
/* set reason */
__pvtBuildByFieldIds(nodeId, transGlobals->hPvt, newMessage,
{ _q931(message)
_q931(facility)
_q931(userUser)
_q931(h323_UserInformation)
_q931(h323_uu_pdu)
_q931(h323_message_body)
_q931(facility)
_q931(reason)
_q931(noH245)
LAST_TOKEN
},
0, NULL);
err = cmTransSendMessage((HSTRANSSESSION)session, newMessage, cmTransQ931Type);
pvtDelete(transGlobals->hPvt, newMessage);
if (err != cmTransOK)
{
RvLogError(&transGlobals->hLog,
(&transGlobals->hLog, "connectH245 failed to send facility (noH245) message"));
return RV_FALSE;
}
}
else
{
RvLogError(&transGlobals->hLog,
(&transGlobals->hLog, "connectH245 failed to create facility (noH245)"));
return RV_FALSE;
}
return RV_TRUE;
}
else
{
proceed = RV_TRUE;
forceOpen = RV_TRUE;
}
}
}
/* Phase 3: Start an H.245 connection if necessary, either as a listener or
as a connector */
/* if we're in the right stage we start the process of dealing with H.245 */
if (proceed)
{
/* check if we need to issue a connect on the H.245 */
needToOpen = needToOpenH245(session, forceOpen);
/* if the H245 host already exists, lock it */
if (session->H245Connection)
if (!emaLock((EMAElement)session->H245Connection))
return RV_FALSE;
/* if it's an outgoing message */
if (outgoing)
{
int addressNode;
/* if we need to open the connection and we do have the remote address
to open to, just do it! */
if (needToOpen)
{
if ( (session->H245Connection) &&
(session->H245Connection->remoteAddress.ip != 0) )
{
connectH245(transGlobals, session, msgType);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -