示例#1
0
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 );
  }
}
示例#2
0
void Message::setString( int direction, const std::string& string,
                         const ValidationRules *validationRules,
                         const DataDictionary* pSessionDataDictionary,
                         const DataDictionary* pApplicationDataDictionary )
throw( Exception )
{
  clear();

  std::string::size_type pos = 0;
  int count = 0;
  std::string msg;

  /*
  static int const headerOrder[] =
  {
    FIELD::BeginString,
    FIELD::BodyLength,
    FIELD::MsgType
  };
  */

  field_type type = header;

  while ( pos < string.size() )
  {
    FieldBase field = extractField( string, pos, pSessionDataDictionary, pApplicationDataDictionary );
    if ( count < 3 &&
         headerOrder[ count++ ] != field.getTag() && 
         !ValidationRules::shouldTolerateOutOfOrderTag(validationRules, OUTGOING_DIRECTION, safeMsgType(), field.getTag() ) 
 )
    {
      //throw InvalidMessage("Header fields out of order.");
      throw TagOutOfOrder( field.getTag() );
    }

    if ( isHeaderField( field, pSessionDataDictionary ) )
    {
      if ( type != header )
      {
        if(m_tag == 0) m_tag = field.getTag();
        m_validStructure = false;
      }

      if ( field.getTag() == FIELD::MsgType )
        msg = field.getString();

      m_header.setField( field, false );

      if ( pSessionDataDictionary )
        setGroup( "_header_", field, string, pos, getHeader(), *pSessionDataDictionary );
    }
    else if ( isTrailerField( field, pSessionDataDictionary ) )
    {
      type = trailer;
      m_trailer.setField( field, false );

      if ( pSessionDataDictionary )
        setGroup( "_trailer_", field, string, pos, getTrailer(), *pSessionDataDictionary );
    }
    else
    {
      if ( type == trailer )
      {
        if(m_tag == 0) m_tag = field.getTag();
        m_validStructure = false;
      }

      type = body;
      setField( field, false );

      if ( pApplicationDataDictionary )
      {
        setGroup( msg, field, string, pos, *this, *pApplicationDataDictionary );
      }
    }
  }

  validate( validationRules );
}