//#include "TLVParser.ih"
// Custom includes
-#include <iomanip>
#include <senf/Utils/hexdump.hh>
#include <senf/Utils/Format.hh>
+#include <senf/Utils/String.hh>
#define prefix_
//-/////////////////////////////////////////////////////////////////////////////////////////////////
SENF_PACKET_TLV_REGISTRY_REGISTER( senf::MIHValidTimeIntervalTLVParser );
//-/////////////////////////////////////////////////////////////////////////////////////////////////
+// MIHBaseTLVParser
+
+prefix_ void senf::MIHBaseTLVParser::validateType(boost::uint8_t expectedType)
+ const
+{
+ if (! check( 1 + senf::bytes(length_()) + length()) )
+ throw InvalidMIHPacketException("truncated TLV.") << " Type: " << senf::str(type());
+ if (type() != expectedType)
+ throw InvalidMIHPacketException("invalid TLV type: ") << senf::str(type());
+}
+
+prefix_ void senf::MIHBaseTLVParser::validateTypeLength(boost::uint8_t expectedType, MIHTLVLengthParser::value_type expectedLength)
+ const
+{
+ validateType( expectedLength);
+ if (length() != expectedLength)
+ throw InvalidMIHPacketException("invalid length in TLV.") << " Type: " << senf::str(type());
+}
+
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
// senf::MIHBaseListTLVParser
prefix_ void senf::MIHBaseListTLVParser::maxListSize(MIHTLVLengthParser::value_type maxl)
MIHFIdTLVParser::dump(os);
}
+prefix_ void senf::MIHFSrcIdTLVParser::validate()
+ const
+{
+ if (! check( 1 + senf::bytes(length_()) + length()) )
+ throw InvalidMIHPacketException("truncated TLV.") << " Type: " << senf::str(type());
+ if (type() != typeId)
+ throw InvalidMIHPacketException("invalid TLV type: ") << senf::str(type());
+}
+
+
//-/////////////////////////////////////////////////////////////////////////////////////////////////
// senf::MIHFDstIdTLVParser
MIHFIdTLVParser::dump(os);
}
+prefix_ void senf::MIHFDstIdTLVParser::validate()
+ const
+{
+ if (! check( 1 + senf::bytes(length_()) + length()) )
+ throw InvalidMIHPacketException("truncated TLV.") << " Type: " << senf::str(type());
+ if (type() != typeId)
+ throw InvalidMIHPacketException("invalid TLV type: ") << senf::str(type());
+}
+
//-/////////////////////////////////////////////////////////////////////////////////////////////////
// senf::MIHStatusTLVParser
os << " (???; invalid value!)" << std::endl;
}
+prefix_ void senf::MIHStatusTLVParser::validate()
+ const
+{
+ validateTypeLength( typeId, 1);
+ if (value() >= 4)
+ throw InvalidMIHPacketException("invalid value in MIHStatusTLV ") << senf::str(value());
+}
+
//-/////////////////////////////////////////////////////////////////////////////////////////////////
// senf::MIHRegisterReqCodeTLVParser
os << " (???; invalid value!)" << std::endl;
}
+prefix_ void senf::MIHRegisterReqCodeTLVParser::validate()
+ const
+{
+ validateTypeLength( typeId, 1);
+ if (value() >= 2)
+ throw InvalidMIHPacketException("invalid value in MIHRegisterReqCodeTLV ") << senf::str(value());
+}
+
//-/////////////////////////////////////////////////////////////////////////////////////////////////
// senf::MIHValidTimeIntervalTLVParser
<< ( value()==0 ? " (infinite)" : " seconds") << std::endl;
}
+prefix_ void senf::MIHValidTimeIntervalTLVParser::validate()
+ const
+{
+ validateTypeLength( typeId, 4);
+}
+
//-/////////////////////////////////////////////////////////////////////////////////////////////////
// senf::MIHTLVLengthParser