📄 transport.c
字号:
IN int size)
{
cmTransGlobals *transGlobals = (cmTransGlobals *)hAppTrans;
/* lock the entire module before intalling the handlers */
RvMutexLock(&transGlobals->lockSessionsList);
memcpy((void *)&(transGlobals->hostEventHandlers),
(void *)transHostEvents,
size);
RvMutexUnlock(&transGlobals->lockSessionsList);
return cmTransOK;
}
/**************************************************************************************
* cmTransGetHostEventHandler
*
* Purpose: Gets the event handlers' pointers for host related callbacks
*
* Input: hAppTrans - A handle to the entire transport module
* size - The size of the given structure.
*
* Output: transHostEvents - A structure with the pointers to the callbacks
*
**************************************************************************************/
TRANSERR cmTransGetHostEventHandler( IN HAPPTRANS hAppTrans,
OUT TRANSHOSTEVENTS *transHostEvents,
IN int size)
{
cmTransGlobals *transGlobals = (cmTransGlobals *)hAppTrans;
/* lock the entire module before getting the handlers */
RvMutexLock(&transGlobals->lockSessionsList);
memcpy( (void *)transHostEvents,
(void *)&(transGlobals->hostEventHandlers),
size);
RvMutexUnlock(&transGlobals->lockSessionsList);
return cmTransOK;
}
/**************************************************************************************
* setQ931Host
*
* Purpose: chooses a Q.931 host (existing or new) and sets its local address.
*
* Input: hsTransSession - the handle to the session.
* localAddress - the local address to connect from.
* remoteAddress - The remote address to connect to.
* createNewHost - RV_TRUE: create new host even if multiplexed
* RV_FALSE: for multiplex use existing host, if exists.
*
* Output: None.
*
* Returned Value: cmTransErr - In case that an error occured.
* cmTransNotMultiplexed - The given host is not multiplexed.
* cmTransOK - In case that the connection is already opened.
*
**************************************************************************************/
TRANSERR setQ931Host( IN cmTransSession *session,
INOUT cmTransportAddress *localAddress,
IN cmTransportAddress *remoteAddress,
IN cmTransHost *oldHost,
IN RvBool createNewHost)
{
RvBool hostIsLocked = RV_FALSE;
cmTransHost *host = NULL;
TRANSERR res = cmTransOK;
cmTransGlobals *transGlobals = (cmTransGlobals *)emaGetUserData((EMAElement)session);
/* If allowed, look for a suitable host in the host's hash */
if ( (!createNewHost) && (session->isMultiplexed) )
host = findHostInHash(transGlobals,
remoteAddress,
session->isMultiplexed,
RV_FALSE);
/* if host was not found and we have an old host, use it */
if ( (!host) && (oldHost) )
{
/* use the existing host (created when the local address was given) */
host = oldHost;
/* lock the host */
if(emaLock((EMAElement) host))
hostIsLocked = RV_TRUE;
else
return cmTransErr;
/* Ignore the previous session, it is the same as this one */
host->firstSession = NULL;
/* set the given remote address into the hash, if none was determined yet */
if (host->remoteAddress.ip == 0)
setRemoteAddress(host, remoteAddress);
}
else
/* We have a new host, get rid of the old one which was created
just for the local address (what a waste, next time use diffSrcAddressInSetupAndARQ
in the configuration */
if (oldHost)
closeHostInternal((HSTRANSHOST)oldHost, RV_TRUE);
/* Still no host? create a new host */
if (!host)
{
res = createHostByType(transGlobals,
(HSTRANSSESSION)session,
(HSTRANSHOST *)&host,
cmTransQ931Conn,
NULL,
cmTransNoAnnexE);
if (res != cmTransOK)
{
RvLogError(&transGlobals->hLog,
(&transGlobals->hLog, "allocateQ931Host failed on allocating host element"));
return cmTransErr;
}
/* update the given address to the host */
host->remoteAddress.type = (cmTransportType)-1;
host->remoteAddress.ip = 0;
host->localAddress.type = (cmTransportType)-1;
host->localAddress.ip = 0;
/* Write the remote address, if exists, to the hash */
if (remoteAddress)
{
if (setRemoteAddress(host, remoteAddress) == cmTransErr)
{
RvLogError(&transGlobals->hLog,
(&transGlobals->hLog, "allocateQ931Host failed on updating hosts hash table"));
return cmTransErr;
}
}
/* Update the local address, if exists */
if (localAddress)
host->localAddress = *localAddress;
else
{
host->localAddress.ip = 0;
host->localAddress.port = 0;
}
}
/* lock the host */
if (!hostIsLocked)
{
/* lock the host */
if(emaLock((EMAElement) host))
hostIsLocked = RV_TRUE;
else
return cmTransErr;
}
session->Q931Connection = host;
/* add the session to the host */
RvMutexLock(&transGlobals->lockSessionsList);
if (session != host->firstSession)
{
session->nextSession = host->firstSession;
if (session->nextSession)
session->nextSession->prevSession = session;
host->firstSession = session;
}
else
printf("transport(1):insert same seesion as firstSession:%x\n", session);
RvMutexUnlock(&transGlobals->lockSessionsList);
/* allocate a new tpkt element for the connection */
if (host->state == hostIdle)
{
getGoodAddress(transGlobals,
host->hTpkt,
NULL,
cmTransQ931Conn,
&host->localAddress);
host->hTpkt = tpktOpen(transGlobals->tpktCntrl,
&host->localAddress,
RvH323ConnectionQ931,
tpktClient,
transQ931Handler,
(void *)host);
if (host->hTpkt != NULL)
host->state = hostConnecting;
else
res = cmTransErr;
}
/* update selected local address on the host */
if (host->hTpkt)
{
getGoodAddress(transGlobals,
session->Q931Connection->hTpkt,
NULL,
cmTransQ931Conn,
&host->localAddress);
if (localAddress)
*localAddress = host->localAddress;
}
/* Unlock the host */
emaUnlock((EMAElement) host);
return res;
}
/**************************************************************************************
* setAddressForH245Host
*
* Purpose: allocates a new H.245 host and start listenning on it.
*
* Input: hsTransSession - the handle to the session.
* localAddress - the local address to listen on.ng host, if exists.
*
* Output: None.
*
* Returned Value: cmTransErr - In case that an error occured.
* cmTransOK - All OK
*
**************************************************************************************/
TRANSERR setAddressForH245Host( IN cmTransSession *session,
IN cmTransportAddress *localAddress)
{
TRANSERR res;
cmTransHost *host = NULL;
cmTransGlobals *transGlobals = (cmTransGlobals *)emaGetUserData((EMAElement)session);
res = createHostByType(transGlobals,
(HSTRANSSESSION)session,
(HSTRANSHOST *)&host,
cmTransH245Conn,
NULL,
cmTransNoAnnexE);
if (res != cmTransOK)
{
RvLogError(&transGlobals->hLog,
(&transGlobals->hLog, "setAddressForH245Host failed on allocating host element"));
return cmTransErr;
}
else
{
TRANSERR reply = cmTransOK;
/* start listenning */
if (transGlobals->hostEventHandlers.cmEvTransHostListen)
{
HATRANSHOST haTransHost =
(HATRANSHOST)emaGetApplicationHandle(((EMAElement)host));
RvLogInfo(&transGlobals->hLog,
(&transGlobals->hLog,
"cmEvTransHostListen(hsHost = %d(%p), haHost=%p, type=cmTransH245Conn, address = (ip:%x,port:%d))",
emaGetIndex((EMAElement)host), host, haTransHost, localAddress->ip, localAddress->port));
/* see if we need to get a good IP address */
if (localAddress->ip == 0)
{
cmTransportAddress ta;
memset(&ta, 0, sizeof(cmTransportAddress));
if (session->Q931Connection != NULL)
{
getGoodAddress(transGlobals,
0,
session->Q931Connection,
cmTransH245Conn,
&ta);
}
if (session->annexEConnection != NULL)
{
getGoodAddress(transGlobals,
0,
session->annexEConnection,
cmTransH245Conn,
&ta);
}
localAddress->ip = ta.ip;
}
/* no need to lock or to prepare for callback - the element is brand new */
emaMark((EMAElement)host);
reply = transGlobals->hostEventHandlers.cmEvTransHostListen(
(HSTRANSHOST)host,
haTransHost,
cmTransH245Conn,
localAddress);
emaRelease((EMAElement)host);
host->reported = RV_TRUE;
}
if (reply == cmTransOK)
host->h245Listen =
tpktOpen(transGlobals->tpktCntrl,
localAddress,
RvH323ConnectionH245,
tpktServer,
transH245AcceptHandler,
(void *)host);
else
host->h245Listen = NULL;
/* get the allocated local address */
getGoodAddress(transGlobals,
host->h245Listen,
NULL,
cmTransH245Conn,
localAddress);
if (transGlobals->hostEventHandlers.cmEvTransHostListening)
{
int numOfLocks;
HATRANSHOST haTransHost =
(HATRANSHOST)emaGetApplicationHandle(((EMAElement)host));
RvLogInfo(&transGlobals->hLog,
(&transGlobals->hLog,
"cmEvTransHostListening(hsHost = %d(%p), haHost=%p, type=cmTransH245Conn, address = (ip:%x,port:%d) error = %d)",
emaGetIndex((EMAElement)host), host, haTransHost, localAddress->ip, localAddress->port, (host->h245Listen == NULL)));
emaLock((EMAElement)host);
numOfLocks = emaPrepareForCallback((EMAElement)host);
transGlobals->hostEventHandlers.cmEvTransHostListening(
(HSTRANSHOST)host,
haTransHost,
cmTransH245Conn,
localAddress,
(host->h245Listen == NULL));
emaReturnFromCallback((EMAElement)host, numOfLocks);
emaUnlock((EMAElement)host);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -