void Message::validate( const ValidationRules* vrptr ) { /* try { */ if ( !ValidationRules::shouldValidate( vrptr ) ) return; if ( ValidationRules::shouldValidateLength( vrptr ) ) { const BodyLength& aBodyLength = FIELD_GET_REF( m_header, BodyLength ); const int expectedLength = (int)aBodyLength; const int actualLength = bodyLength(); if ( expectedLength != actualLength ) { std::stringstream text; text << "Expected BodyLength=" << expectedLength << ", Received BodyLength=" << actualLength; throw InvalidMessage(text.str()); } } if ( ValidationRules::shouldValidateChecksum( vrptr ) ) { const CheckSum& aCheckSum = FIELD_GET_REF( m_trailer, CheckSum ); const int expectedChecksum = (int)aCheckSum; const int actualChecksum = checkSum(); if ( expectedChecksum != actualChecksum ) { std::stringstream text; text << "Expected CheckSum=" << expectedChecksum << ", Received CheckSum=" << actualChecksum; throw InvalidMessage(text.str()); } } /* } catch ( FieldNotFound& e ) { const std::string fieldName = ( e.field == FIX::FIELD::BodyLength ) ? "BodyLength" : "CheckSum"; throw InvalidMessage( fieldName + std::string(" is missing") ); } catch ( IncorrectDataFormat& e ) { const std::string fieldName = ( e.field == FIX::FIELD::BodyLength ) ? "BodyLength" : "CheckSum"; throw InvalidMessage( fieldName + std::string(" has wrong format: ") + e.detail ); } */ }
void DataDictionary::validate( const Message& message, const DataDictionary* const pSessionDD, const DataDictionary* const pAppDD ) throw( FIX::Exception ) { const Header& header = message.getHeader(); const BeginString& beginString = FIELD_GET_REF( header, BeginString ); const MsgType& msgType = FIELD_GET_REF( header, MsgType ); if ( pSessionDD != 0 && pSessionDD->m_hasVersion ) { if( pSessionDD->getVersion() != beginString ) { throw UnsupportedVersion(); } } int field = 0; if( (pSessionDD !=0 && pSessionDD->m_checkFieldsOutOfOrder) || (pAppDD != 0 && pAppDD->m_checkFieldsOutOfOrder) ) { if ( !message.hasValidStructure(field) ) throw TagOutOfOrder(field); } if ( pAppDD != 0 && pAppDD->m_hasVersion ) { pAppDD->checkMsgType( msgType ); pAppDD->checkHasRequired( message.getHeader(), message, message.getTrailer(), msgType ); } if( pSessionDD != 0 ) { pSessionDD->iterate( message.getHeader(), msgType ); pSessionDD->iterate( message.getTrailer(), msgType ); } if( pAppDD != 0 ) { pAppDD->iterate( message, msgType ); } }