📄 h323parser.cpp
字号:
std::string str = strm.str(); AttachPropertyInstanceEx( hFrame, RasPropertyInfo.hProperty, BytesLeft, pFrame, (DWORD) str.size()+1, (void*) str.c_str(), 0, 0, 0); H323_MESSAGES::RasMessage msg; ASN1::PERDecoder decoder((char*)pFrame, (char*)pFrame+BytesLeft, env); PERAttacher attacher(decoder, hFrame, RasPropertyInfo.hProperty, "RasMessage ",1); msg.accept(attacher); return NULL;}//============================================================================// Function: TPKT_Register// // Description: Create our property database and handoff sets.//// Modification History//// Huang-Ming Huang 08/11/2000 Created//============================================================================void BHAPI TPKT_Register( HPROTOCOL hTPKT){ // tell the kernel to make reserve some space for our property table CreatePropertyDatabase( hTPKT, 1); // add our properties to the kernel's database AddProperty( hTPKT, &TpktPropertyInfo);}//============================================================================// Function: TPKT_RecognizeFrame// // Description: Determine whether we exist in the frame at the spot // indicated. We also indicate who (if anyone) follows us// and how much of the frame we claim.//// Modification History//// Huang-Ming Huang 08/11/2000 Created//============================================================================LPBYTE BHAPI TPKT_RecognizeFrame( HFRAME hFrame, LPBYTE pMacFrame, LPBYTE pFrame, DWORD MacType, DWORD BytesLeft, HPROTOCOL hPrevProtocol, DWORD nPrevProtOffset, LPDWORD pProtocolStatus, LPHPROTOCOL phNextProtocol, LPDWORD InstData) { *pProtocolStatus = PROTOCOL_STATUS_NOT_RECOGNIZED; if (BytesLeft >=4 && pFrame[0] == 0x03 && pFrame[1] == 0x00 && !(pFrame[2] == 0 && pFrame[3] == 0)) { pFrame += 4; int len = ( pFrame[2] << 8 | pFrame[3]); if (BytesLeft < 8 && BytesLeft != len) *pProtocolStatus = PROTOCOL_STATUS_CLAIMED; else *pProtocolStatus = PROTOCOL_STATUS_RECOGNIZED; } return pFrame;}//============================================================================// Function: TPKT_AttachProperties// // Description: Indicate where in the frame each of our properties live.//// Modification History//// Huang-Ming Huang 08/11/2000 Created//============================================================================LPBYTE BHAPI TPKT_AttachProperties( HFRAME hFrame, LPBYTE pMacFrame, LPBYTE pFrame, DWORD MacType, DWORD BytesLeft, HPROTOCOL hPrevProtocol, DWORD nPrevProtOffset, DWORD InstData) { // apply the header overlay in order to decode the protocol int len = pFrame[2] << 8 | pFrame[3]; char buf[80]; sprintf(buf, "TPKT Header (Packet Length = %d)", len); AttachPropertyInstanceEx(hFrame, TpktPropertyInfo.hProperty, 4, pFrame, strlen(buf)+1, buf, 0, 0, 0); AttachPropertyInstanceEx(hFrame, TpktPropertyInfo.hProperty, 1, pFrame, 28, "TPKT Identifier Byte = 0x03", 0 , 1, 0); AttachPropertyInstanceEx(hFrame, TpktPropertyInfo.hProperty, 1, pFrame+1, 21, "Reserved Byte = 0x00", 0 , 1, 0); sprintf(buf, "Packet Length = %d", len); AttachPropertyInstanceEx(hFrame, TpktPropertyInfo.hProperty, 2, pFrame+2, strlen(buf)+1, buf, 0, 1, 0); return pFrame+4;}//============================================================================// Function: H245_Register// // Description: Create our property database and handoff sets.//// Modification History//// Huang-Ming Huang 08/11/2000 Created//============================================================================void BHAPI H245_Register( HPROTOCOL hH245){ // tell the kernel to make reserve some space for our property table CreatePropertyDatabase( hH245, 1); // add our properties to the kernel's database AddProperty( hH245, &H245PropertyInfo);}//============================================================================// Function: H245_RecognizeFrame// // Description: Determine whether we exist in the frame at the spot // indicated. We also indicate who (if anyone) follows us// and how much of the frame we claim.//// Modification History//// Huang-Ming Huang 08/11/2000 Created//============================================================================LPBYTE BHAPI H245_RecognizeFrame( HFRAME hFrame, LPBYTE pMacFrame, LPBYTE pFrame, DWORD MacType, DWORD BytesLeft, HPROTOCOL hPrevProtocol, DWORD nPrevProtOffset, LPDWORD pProtocolStatus, LPHPROTOCOL phNextProtocol, LPDWORD InstData) { *pProtocolStatus = PROTOCOL_STATUS_NOT_RECOGNIZED; ASN1::PERDecoder decoder((char*)pFrame, (char*)pFrame+BytesLeft, env, true); MULTIMEDIA_SYSTEM_CONTROL::MultimediaSystemControlMessage msg; try { if (msg.accept(decoder)) { unsigned char* nextPos = (unsigned char*)decoder.getNextPosition(); if ( nextPos - pFrame < BytesLeft) { if (*nextPos != '\x03' || *(nextPos+1) != '\x00') return pFrame; } else if (pFrame[0] == '\x03' && pFrame[1] == '\x00' && pFrame[4] == '\x08' && pFrame[5] == '\x02') { unsigned len = pFrame[2] << 8 | pFrame[3]; if (len <= BytesLeft) { unsigned char* q931Frame = pFrame+4; unsigned char* nextFrame; if ((nextFrame = Q931_RecognizeFrame(hFrame, pMacFrame, q931Frame, MacType, BytesLeft-4, hPrevProtocol, nPrevProtOffset, pProtocolStatus, phNextProtocol, InstData)) != q931Frame) { *pProtocolStatus = PROTOCOL_STATUS_NOT_RECOGNIZED; if (nextFrame <= (pFrame+ BytesLeft-4)) { if (nextFrame[0] == '\x03' && nextFrame[1] == '\x00') return pFrame; } else if (nextFrame == pFrame+ BytesLeft) return pFrame; } } } pFrame = nextPos; *pProtocolStatus = PROTOCOL_STATUS_NEXT_PROTOCOL; *phNextProtocol = hTPKT; } } catch (...) { } return pFrame;}//============================================================================// Function: H245_AttachProperties// // Description: Indicate where in the frame each of our properties live.//// Modification History//// Huang-Ming Huang 08/11/2000 Created//============================================================================LPBYTE BHAPI H245_AttachProperties( HFRAME hFrame, LPBYTE pMacFrame, LPBYTE pFrame, DWORD MacType, DWORD BytesLeft, HPROTOCOL hPrevProtocol, DWORD nPrevProtOffset, DWORD InstData) { // Decode the first byte to determine the type of the message ASN1::PERDecoder decoder((char*)pFrame, (char*)pFrame+BytesLeft, env); ASN1::PERDecoder::memento_type memento = decoder.get_memento(); MULTIMEDIA_SYSTEM_CONTROL::MultimediaSystemControlMessage msg; msg.accept(decoder); if (msg.currentSelection() >= 0) { ASN1::CHOICE& choice = *static_cast<ASN1::CHOICE*>(msg.getSelection()); // Attach the summery std::ostringstream strm; strm << "H.245 " << choice.getSelectionName() << " (Length = " << decoder.getPosition()-(char*)pFrame << ")"; std::string str = strm.str(); AttachPropertyInstanceEx( hFrame, H245PropertyInfo.hProperty, decoder.getPosition()-(char*)pFrame, pFrame, (DWORD) str.size()+1, (void*) str.c_str(), 0, 0, 0) ; decoder.rollback(memento); // Attach the property of the whole message strm.str(""); strm << "MultimediaSystemControlMessage ::= "; PERAttacher attacher(decoder, hFrame, H245PropertyInfo.hProperty, strm.str(), 1); msg.accept(attacher); } else { // Attach the summery std::ostringstream strm; strm << "H.245 unknown extension (Length = " << decoder.getPosition()-(char*)pFrame << ")"; std::string str = strm.str(); AttachPropertyInstanceEx( hFrame, H245PropertyInfo.hProperty, decoder.getPosition()-(char*)pFrame, pFrame, (DWORD) str.size()+1, (void*) str.c_str(), 0, 0, 0) ; } return (unsigned char*)decoder.getPosition();}//============================================================================// Function: Q931_Register// // Description: Create our property database and handoff sets.//// Modification History//// Huang-Ming Huang 08/11/2000 Created//============================================================================void BHAPI Q931_Register( HPROTOCOL hQ931){ // tell the kernel to make reserve some space for our property table CreatePropertyDatabase( hQ931, 1); // add our properties to the kernel's database AddProperty( hQ931, &Q931PropertyInfo);}//============================================================================// Function: Q931_RecognizeFrame// // Description: Determine whether we exist in the frame at the spot // indicated. We also indicate who (if anyone) follows us// and how much of the frame we claim.//// Modification History//// Huang-Ming Huang 08/11/2000 Created//============================================================================LPBYTE BHAPI Q931_RecognizeFrame( HFRAME hFrame, LPBYTE pMacFrame, LPBYTE pFrame, DWORD MacType, DWORD BytesLeft, HPROTOCOL hPrevProtocol, DWORD nPrevProtOffset, LPDWORD pProtocolStatus, LPHPROTOCOL phNextProtocol, LPDWORD InstData) { *pProtocolStatus = PROTOCOL_STATUS_NOT_RECOGNIZED; Q931Decoder decoder(pFrame, BytesLeft, env); Q931PDU msg; try { if (msg.accept(decoder)) { int sz = decoder.getPosition(); if ( sz < BytesLeft) { if (*(pFrame+sz) != '\x03' || *(pFrame+sz+1) != '\x00') return pFrame; } *pProtocolStatus = PROTOCOL_STATUS_NEXT_PROTOCOL; pFrame += sz; *phNextProtocol = hTPKT; } } catch (...) { } return pFrame;}//============================================================================// Function: Q931_AttachProperties// // Description: Indicate where in the frame each of our properties live.//// Modification History//// Huang-Ming Huang 08/11/2000 Created//============================================================================LPBYTE BHAPI Q931_AttachProperties( HFRAME hFrame, LPBYTE pMacFrame, LPBYTE pFrame, DWORD MacType, DWORD BytesLeft, HPROTOCOL hPrevProtocol, DWORD nPrevProtOffset, DWORD InstData) { // Decode the first byte to determine the type of the message Q931Decoder decoder(pFrame, BytesLeft,env); Q931PDU pdu; pdu.accept(decoder); pdu.attachProperties(hFrame, Q931PropertyInfo.hProperty); return pFrame+BytesLeft;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -