📄 iannerw.c
字号:
/* incorrect payload size! payload corrupted! */
send_nack6(pNode, seqn, nCurPayload, RV_TRUE);
fError = RV_TRUE;
break;
}
/* notify application!*/
if (pNode->pAnnexE->events.AnnexEEvRestart != NULL)
{
cmTransportAddress SrcAddr;
SrcAddr.distribution = cmDistributionUnicast;
SrcAddr.type = cmTransportTypeIP;
SrcAddr.ip = pNode->RemoteHost.nIP;
SrcAddr.port = pNode->RemoteHost.nPort;
pNode->pAnnexE->events.AnnexEEvRestart(
AsHANNEXE(pNode->pAnnexE),
pNode->pAnnexE->hAppAnnexE,
&SrcAddr
);
}
else
{
RvLogInfo(&pNode->pAnnexE->log,
(&pNode->pAnnexE->log, "Restart command arrived - no CB to treat it was given"));
}
pPayload = MoveToNextPayload(pPayload, nSz);
break;
default:
{
int transType = pTrPayload[IAnnexET00Header_TRANSPORT_TYPE];
/* reserved for future use.... (not supported by this version of AnnexE)*/
send_nack3(pNode, seqn, transType, RV_TRUE);
/* break the processing of the rest payloads in the PDU as there
is no guarantee to find the exact size of the payload.*/
fError = RV_TRUE;
}
break;
}
};
break;
case AEPT_OIDTypedMessage: {
/***************************************************************/
/* T == 01 * OBJECT IDENTIFIER typed messages */
/***************************************************************/
int iLength;
/* check size of payload! */
if ((int)sizeof_OIDHeader(pPayload) >= nBytesAvail)
{
/* incorrect payload size! payload corrupted! */
send_nack6(pNode, seqn, nCurPayload, RV_TRUE);
fError = RV_TRUE;
break;
}
nSz = sizeof_OID(pPayload);
nBytesAvail -= nSz;
if (nBytesAvail < 0)
{
/* incorrect payload size! payload corrupted! */
send_nack6(pNode, seqn, nCurPayload, RV_TRUE);
fError = RV_TRUE;
break;
}
/* that type of messages is not supported in the current implementation of
the Annex E => return corresponding NAck (REASON_5: "Object-ID payload
not supported)! As it is possible to find the exact size of the payload
the PDU parsing is not broken, but the current payload is skipped!*/
iLength = AsOIDHeader(pPayload)[IAnnexET01Header_OID_LENGTH];
send_nack5(pNode,
seqn,
iLength,
&AsOIDHeader(pPayload)[IAnnexET01Header_OID],
RV_FALSE);
pPayload = MoveToNextPayload(pPayload, sizeof_OID(pPayload));
};
break;
case AEPT_StaticMessage: {
/***************************************************************/
/* T == 10 * Static-payload typed messages */
/***************************************************************/
/* typecast to the Annex E Static-typed message payload */
IAnnexET10Payload* pStPayload = (IAnnexET10Payload*)pPayload;
RvBool fSessionField = pStPayload[IAnnexET10Payload_Header+IAnnexET10Header_PFLAGS] & AEP_MASK_S;
RvBool fAddressField = pStPayload[IAnnexET10Payload_Header+IAnnexET10Header_PFLAGS] & AEP_MASK_A;
RvUint16 nSessionID;
RvUint32 nAddress = 0;
RvUint8* pData;
RvUint16 nDataSize;
int staticType;
int iMsgSize;
/* check size of payload! */
nSz = sizeof_Static(pPayload);
nBytesAvail -= nSz;
if (nBytesAvail < 0)
{
/* incorrect payload size! payload corrupted! */
send_nack6(pNode, seqn, nCurPayload, RV_TRUE);
fError = RV_TRUE;
break;
}
if (pStPayload[IAnnexET10Payload_Header+IAnnexET10Header_STATIC_TYPE] != 0)
{
/* this implementation of the Annex E supports only H.225 messages,
all the rest are unknown currently.*/
staticType = pStPayload[IAnnexET10Payload_Header+IAnnexET10Header_STATIC_TYPE];
send_nack4(pNode, seqn, staticType, RV_FALSE);
/* skip payload*/
pPayload = MoveToNextPayload(pPayload, sizeof_Static(pStPayload));
break;
}
if (fSessionField)
{
if (fAddressField)
{
nSessionID = ntoh16(&AsStaticSA(pStPayload)[IAnnexET10PayloadSA_SESSION]);
nAddress = ntoh32(&AsStaticSA(pStPayload)[IAnnexET10PayloadSA_SESSION]);
pData = &AsStaticSA(pStPayload)[IAnnexET10PayloadSA_DATA];
nDataSize = ntoh16(&AsStaticSA(pStPayload)[IAnnexET10PayloadSA_DATA_LENGTH]);
}
else
{
nSessionID = ntoh16(&AsStaticS(pStPayload)[IAnnexET10PayloadS_SESSION]);
pData = &AsStaticS(pStPayload)[IAnnexET10PayloadS_DATA];
nDataSize = ntoh16(&AsStaticS(pStPayload)[IAnnexET10PayloadS_DATA_LENGTH]);
}
/* Turn the last bit of the session Id for incoming msgs */
nSessionID ^= 0x8000U;
}
else
{
/* this h.225 message has no session fields defined. From AnnexE API those
messages are only session oriented => we suppose the payload is
broken while transferring.*/
send_nack6(pNode, seqn, nCurPayload, RV_FALSE);
/* Do not break the processing of the PDU as that mistake may be in
result of a bug in the remote Annex E module implementation. It is
possible to follow valid payloads in the PDU!
skip payload*/
pPayload = MoveToNextPayload(pPayload, sizeof_Static(pStPayload));
break;
}
/* everything is alright and we may notify the user for the received payload*/
if (pNode->pAnnexE->events.AnnexEEvNewMessage != NULL)
{
pNode->fDontSend = RV_TRUE; /* block sends until all the treatment is done by the user */
pNode->nRef++; /* protect the node*/
iMsgSize = nDataSize;
pNode->pAnnexE->events.AnnexEEvNewMessage(
AsHANNEXE(pNode->pAnnexE),
pNode->pAnnexE->hAppAnnexE,
pNode->RemoteHost.nIP,
pNode->RemoteHost.nPort,
pData,
iMsgSize
);
if (pNode->nRef == 1)
{
/* node is closed by the application ?!?!*/
del_node(pNode);
}
else
{
pNode->nRef--; /* unprotect the nodee*/
pNode->fDontSend = RV_FALSE; /* allow sends again */
/* send any messages that the user has sent during the callback */
if (pNode->pCurrentPDU)
send_current_pdu(pNode);
}
}
/* static-payload processing is done! now skip to the next one!*/
pPayload = MoveToNextPayload(pPayload, nSz);
};
break;
case AEPT_ReservedForFutureUse: {
/***************************************************************/
/* T == 11 * Reserved for future use */
/***************************************************************/
/* this is not a valid Annex E Transport message!*/
send_nack6(pNode, seqn, nCurPayload, RV_TRUE);
/* break the processing of the rest payloads in the PDU as there is no
guarantee to find the exact size of the payload.*/
fError = RV_TRUE;
};
break;
}
if (fError)
{
/* during the parsing of the current payload in the PDU there
was a serious error! => break further processing!*/
break;
}
nCurPayload++;
}
if ((!fError) && (AEHGet_A(pPDU->PDU) != 0) && (AEHGet_H(pPDU->PDU) == 0) && (pNode->pCurrentPDU != NULL)) {
/* send current pdu forced*/
send_current_pdu(pNode);
}
}
RvBool check_pdu(tNode* pNode, IN tpPDU pPDU)
{
IAnnexEPayloadHeader* pPayload;
int nBytesAvail = pPDU->nSize;
int nSz, i, cnt;
/* get first payload!*/
if (AEHGet_L(pPDU->PDU) != 0)
{
pPayload = (IAnnexEPayloadHeader*)(&pPDU->PDU[4 + 4]);
nBytesAvail -= 4 + 4;
}
else
{
pPayload = (IAnnexEPayloadHeader*)(&pPDU->PDU[4]);
nBytesAvail -= 4;
}
if (nBytesAvail <= 0)
return RV_FALSE;
while ((void*)pPayload < (void*)(&pPDU->PDU[pPDU->nSize]))
{
switch (AEPGet_T(*pPayload))
{
case AEPT_TransportMessage: {
IAnnexET00Header* pTrPayload = (IAnnexET00Header*)(pPayload);
/* check 'Source/Dest' and 'Session' flags in payload header*/
if ((AEPGet_A(*pPayload) != 0) || (AEPGet_S(*pPayload) != 0))
{
/* this is not a valid Annex E Transport message!*/
return RV_FALSE;
}
switch (pTrPayload[IAnnexET00Header_TRANSPORT_TYPE])
{
case AEPT00_IAmAlive:
nSz = sizeof_IAmAlive(pTrPayload);
nBytesAvail -= nSz;
if (nBytesAvail < 0)
return RV_FALSE;
pPayload = MoveToNextPayload(pPayload, nSz);
break;
case AEPT00_Ack:
nSz = sizeof_Ack(pTrPayload);
nBytesAvail -= nSz;
if (nBytesAvail < 0)
return RV_FALSE;
pPayload = MoveToNextPayload(pPayload, nSz);
break;
case AEPT00_NAck:
{
IAnnexENAckReason* pReason = AsNAckReason(GetNAckReasonPtr(pTrPayload));
nSz = sizeof_IAnnexET00NAckHeader;
nBytesAvail -= nSz;
if (nBytesAvail < 0)
return RV_FALSE;
cnt = countof_NAckReasons(pTrPayload);
for (i = 0; i < cnt; i++)
{
/* goto next reason*/
nSz = sizeof_NAckReason(pReason);
nBytesAvail -= nSz;
if (nBytesAvail < 0)
return RV_FALSE;
pReason = MoveToNextReason(pReason, nSz);
}
pPayload = (IAnnexEPayloadHeader*)pReason;
}
break;
case AEPT00_Restart:
nSz = sizeof_IAnnexET00Restart;
nBytesAvail -= nSz;
if (nBytesAvail < 0)
return RV_FALSE;
pPayload = MoveToNextPayload(pPayload, nSz);
break;
default:
return RV_FALSE;
}
};
break;
case AEPT_OIDTypedMessage:
{
if ((int)sizeof_OIDHeader(pPayload) >= nBytesAvail)
return RV_FALSE;
nSz = sizeof_OID(pPayload);
nBytesAvail -= nSz;
if (nBytesAvail < 0)
return RV_FALSE;
pPayload = MoveToNextPayload(pPayload, nSz);
};
break;
case AEPT_StaticMessage:
{
nSz = sizeof_Static(pPayload);
nBytesAvail -= nSz;
if (nBytesAvail < 0)
return RV_FALSE;
pPayload = MoveToNextPayload(pPayload, nSz);
};
break;
case AEPT_ReservedForFutureUse:
{
return RV_FALSE;
};
break;
}
}
#if defined(RV_ANNEXE_DEBUG)
if (nBytesAvail != 0)
{
RvLogExcep(&pNode->pAnnexE->log, (&pNode->pAnnexE->log,
"check_pdu: nBytesAvail=%d", nBytesAvail));
}
#endif
return RV_TRUE;
}
#ifdef __cplusplus
}
#endif /* __cplusplus*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -