📄 transnet.c
字号:
if (!winHaTransHost)
emaSetApplicationHandle((EMAElement)winningHost, (void *)looseHaTransHost);
RvMutexUnlock(&transGlobals->lockSessionsList);
}
/* clear the loosing host from the session */
if (session->Q931Connection == loosingHost)
session->Q931Connection = NULL;
if (session->annexEConnection == loosingHost)
session->annexEConnection = NULL;
return answer;
}
/**************************************************************************************
* transReportConnect
*
* Purpose: To invoke the callbacks for the connected host and all its associated sessions
*
* Input: host - The host which got connected.
* session - The session on which to report the host connection (NULL for all).
* isConnected - RV_TRUE: A connect happened, RV_FALSE: an accept happened.
*
**************************************************************************************/
void transReportConnect(cmTransHost *host, cmTransSession *session, RvBool isConnected)
{
cmTransSession *nextSession;
HATRANSSESSION haTransSession;
/* retrieve the transport module global area */
cmTransGlobals *transGlobals = (cmTransGlobals *)emaGetUserData((EMAElement)host);
/* report the connection of the host only if its a TPKT connection */
if ( ((!session) || (session->annexEConnection != host)) &&
(transGlobals->hostEventHandlers.cmEvTransHostConnected) )
{
HATRANSHOST haTransHost = (HATRANSHOST)emaGetApplicationHandle((EMAElement)host);
int NumOfLocks;
RvLogInfo(&transGlobals->hLog,
(&transGlobals->hLog, "cmEvTransHostConnected(hsHost = %d(%p), haHost=%p, type=%d)",
emaGetIndex((EMAElement)host), host, haTransHost,host->type));
NumOfLocks = emaPrepareForCallback((EMAElement)host);
(transGlobals->hostEventHandlers.cmEvTransHostConnected)(
(HSTRANSHOST) host,
haTransHost,
host->type,
isConnected);
emaReturnFromCallback((EMAElement)host, NumOfLocks);
}
/* if reporting was asked for just one session (in case of dummy connect for
multiplexed hosts just report on that session */
if ( (session) && (!emaWasDeleted((EMAElement)host)) )
{
if (transGlobals->sessionEventHandlers.cmEvTransSessionNewConnection)
{
/* report just for the given session (if one is given) */
if ( (!session->reportedQ931Connect) )
{
int sessNumOfLocks, hostNumOfLocks;
haTransSession = (HATRANSSESSION)emaGetApplicationHandle((EMAElement)session);
RvLogInfo(&transGlobals->hLog,
(&transGlobals->hLog, "cmEvTransSessionNewConnection(hsSession = %d(%p), haSession=%p, type=%d)",
emaGetIndex((EMAElement)session), session, haTransSession, host->type));
sessNumOfLocks = emaPrepareForCallback((EMAElement)session);
hostNumOfLocks = emaPrepareForCallback((EMAElement)host);
transGlobals->sessionEventHandlers.cmEvTransSessionNewConnection(
(HSTRANSSESSION)session, haTransSession, host->type);
emaReturnFromCallback((EMAElement)session, sessNumOfLocks);
emaReturnFromCallback((EMAElement)host, hostNumOfLocks);
session->reportedQ931Connect = RV_TRUE;
}
}
}
else
/* go over the sessions that are connected to that host and report the connect */
if (!emaWasDeleted((EMAElement)host))
{
int sessNumOfLocks, hostNumOfLocks;
switch (host->type)
{
case cmTransQ931Conn:
/* for Q.931 hosts, go over all the sessions connected to them and report them */
for (nextSession = host->firstSession; nextSession != NULL; nextSession = nextSession->nextSession)
{
if (emaLock((EMAElement)nextSession))
{
/* report the connection */
haTransSession = (HATRANSSESSION)emaGetApplicationHandle((EMAElement)nextSession);
/* for the Q.931 type connections (TPKT or annex E) report them always */
if (!emaWasDeleted((EMAElement)nextSession))
if (transGlobals->sessionEventHandlers.cmEvTransSessionNewConnection)
{
/* report just for the session */
if ( (!nextSession->reportedQ931Connect) )
{
RvLogInfo(&transGlobals->hLog,
(&transGlobals->hLog, "cmEvTransSessionNewConnection(hsSession = %d(%p), haSession=%p, type=%d)",
emaGetIndex((EMAElement)nextSession), nextSession, haTransSession, host->type));
hostNumOfLocks = emaPrepareForCallback((EMAElement)host);
sessNumOfLocks = emaPrepareForCallback((EMAElement)nextSession);
transGlobals->sessionEventHandlers.cmEvTransSessionNewConnection(
(HSTRANSSESSION)nextSession, haTransSession, host->type);
emaReturnFromCallback((EMAElement)nextSession, sessNumOfLocks);
emaReturnFromCallback((EMAElement)host, hostNumOfLocks);
if (nextSession)
{
if (host->type == cmTransQ931Conn)
nextSession->reportedQ931Connect = RV_TRUE;
else
nextSession->reportedH245Connect = RV_TRUE;
}
}
}
/* unlock and release the current session */
emaUnlock((EMAElement)nextSession);
}
}
break;
case cmTransH245Conn:
/* for H.245, check if there is a session attached to it, and if so
report the connection on that session */
nextSession = host->firstSession;
if (nextSession)
{
haTransSession = (HATRANSSESSION)emaGetApplicationHandle((EMAElement)nextSession);
/* close the tunneling on the session */
nextSession->tunnelingState = tunnNo;
/* Determine whether to report on H.245 connection */
if (!nextSession->reportedH245Connect)
{
/* mark that we already reported on an H.245 connection for this session */
nextSession->reportedH245Connect = RV_TRUE;
if (transGlobals->sessionEventHandlers.cmEvTransSessionNewConnection)
{
RvLogInfo(&transGlobals->hLog,
(&transGlobals->hLog, "cmEvTransSessionNewConnection(hsSession = %d(%p), haSession=%p, type=cmTransH245Conn)",
emaGetIndex((EMAElement)nextSession), nextSession, haTransSession));
hostNumOfLocks = emaPrepareForCallback((EMAElement)host);
sessNumOfLocks = emaPrepareForCallback((EMAElement)nextSession);
transGlobals->sessionEventHandlers.cmEvTransSessionNewConnection(
(HSTRANSSESSION)nextSession, haTransSession, cmTransH245Conn);
emaReturnFromCallback((EMAElement)nextSession, sessNumOfLocks);
emaReturnFromCallback((EMAElement)host, hostNumOfLocks);
if (nextSession)
nextSession->reportedH245Connect = RV_TRUE;
}
}
}
break;
}
}
/* mark the host as connecte dso it will be reported when closed */
if (!emaWasDeleted((EMAElement)host))
host->reported = RV_TRUE;
}
/**************************************************************************************
* solveH245Conflict
*
* Purpose: To decide which one of two coliding H.245 connections will survive.
*
* Input: host - The h.245 host which has a listen and connecting processes.
*
**************************************************************************************/
void solveH245Conflict(cmTransHost *host)
{
cmTransGlobals *transGlobals = (cmTransGlobals *)emaGetUserData((EMAElement)host);
if (!transGlobals)
return;
/* if we are having a connecting request and a accepting request, determine
which one should be closed */
if (host->state == hostListenningConnecting)
{
int cmpRes;
RvLogInfo(&transGlobals->hLog,
(&transGlobals->hLog, "solveH245Conflict on host=%d(%p) local:(ip=%x;port=%d) remote:(ip=%x;port=%d)",
emaGetIndex((EMAElement)host), host, host->localAddress.ip, host->localAddress.port,
host->remoteAddress.ip, host->remoteAddress.port));
/* compare the listenning address (local) to the connecting address (remote) */
cmpRes = memcmp((void *)&host->remoteAddress.ip,
(void *)&host->localAddress.ip,
sizeof(host->localAddress.ip));
/* if the remote address is bigger or if both address are the same but the remote
port is bigger, then close the connecting host and keep the accepting one,
else do the opposite */
if ( (cmpRes > 0) ||
(
(cmpRes == 0) &&
(host->remoteAddress.port > host->localAddress.port)
)
)
{
/* close the connecting host */
if (host->hTpkt)
{
tpktClose(host->hTpkt);
host->hTpkt = NULL;
}
RvLogInfo(&transGlobals->hLog,
(&transGlobals->hLog, "solveH245Conflict closed outgoing colliding connection"));
/* the host now is just listenning */
host->state = hostListenning;
}
else
{
/* close the accepting socket and don't touch the connecting one */
if (host->h245Listen)
{
tpktClose(host->h245Listen);
host->h245Listen = NULL;
}
RvLogInfo(&transGlobals->hLog,
(&transGlobals->hLog, "solveH245Conflict closed incoming colliding connection"));
}
}
}
/**************************************************************************************
* transQ931AcceptHandler
*
* Purpose: The callback routine for the socket that listens for incoming Q.931 requests
*
* Input: standard input of TPKT callback
*
**************************************************************************************/
void transQ931AcceptHandler(HTPKT tpkt,RvSelectEvents event,int length,int error,void*context)
{
/* retrieve the transport module global area */
cmTransGlobals *transGlobals = (cmTransGlobals *)context;
if (length);
if (!transGlobals)
{
RvLogError(&transGlobals->hLog, (&transGlobals->hLog,
"transQ931AcceptHandler got no context on event %d", event));
return;
}
if (error)
{
RvLogError(&transGlobals->hLog, (&transGlobals->hLog,
"transQ931AcceptHandler got error on event %d", event));
return;
}
/* we don't treat the pre-accept event for Q.931 */
if (event == 0)
return;
/* treat the accept event of a Q.931 TPKT connection */
if (event == RvSelectAccept)
{
TRANSERR res;
cmTransHost *host;
/* create a new connected host element for the new connection */
res = createHostByType( transGlobals,
NULL,
(HSTRANSHOST *)&host,
cmTransQ931Conn,
tpkt,
cmTransNoAnnexE);
if (res != cmTransOK)
{
tpktClose(tpkt);
RvLogError(&transGlobals->hLog, (&transGlobals->hLog,
"transQ931AcceptHandler rejected connection (host wasnt created) res=%d", res));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -