X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2F80221Bundle%2FTLVParser.cc;h=729b1ece583706b2247f715f54a849d628afe42b;hb=57daeae6f2e924ce3f16f9677c3474f531cba9e5;hp=5f35f25a2bcbf056fdc7a0b9b5c915ce026050ee;hpb=bd52d6b1c3b258c030c7302f5e926aeb5b5b0715;p=senf.git diff --git a/senf/Packets/80221Bundle/TLVParser.cc b/senf/Packets/80221Bundle/TLVParser.cc index 5f35f25..729b1ec 100644 --- a/senf/Packets/80221Bundle/TLVParser.cc +++ b/senf/Packets/80221Bundle/TLVParser.cc @@ -29,7 +29,6 @@ // Custom includes #include #include -#include #define prefix_ //-///////////////////////////////////////////////////////////////////////////////////////////////// @@ -42,15 +41,21 @@ SENF_PACKET_TLV_REGISTRY_REGISTER( senf::MIHValidTimeIntervalTLVParser ); //-///////////////////////////////////////////////////////////////////////////////////////////////// // MIHBaseTLVParser -prefix_ void senf::MIHBaseTLVParser::validateTL(boost::uint8_t expectedType, MIHTLVLengthParser::value_type expectedLength) +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()); + throw InvalidMIHPacketException("truncated TLV.") << " Type: " << unsigned(type()); if (type() != expectedType) - throw InvalidMIHPacketException("invalid TLV type") << " Type: " << senf::str(type()); + throw InvalidMIHPacketException("wrong TLV type. expected ") << unsigned(expectedType) << " got " << unsigned(type()); +} + +prefix_ void senf::MIHBaseTLVParser::validateTypeLength(boost::uint8_t expectedType, MIHTLVLengthParser::value_type expectedLength) + const +{ + validateType( expectedType); if (length() != expectedLength) - throw InvalidMIHPacketException("invalid length in TLV.") << " Type: " << senf::str(type()); + throw InvalidMIHPacketException("invalid length in TLV.") << " Type: " << unsigned(type()); } //-///////////////////////////////////////////////////////////////////////////////////////////////// @@ -63,7 +68,6 @@ prefix_ void senf::MIHBaseListTLVParser::maxListSize(MIHTLVLengthParser::value_t maxLength( maxl + senf::bytes(listSize_())); } - //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::MIHFIdTLVParser @@ -185,10 +189,7 @@ prefix_ void senf::MIHFSrcIdTLVParser::dump(std::ostream & 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()); + validateType( typeId); } @@ -206,10 +207,7 @@ prefix_ void senf::MIHFDstIdTLVParser::dump(std::ostream & 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()); + validateType( typeId); } //-///////////////////////////////////////////////////////////////////////////////////////////////// @@ -247,9 +245,9 @@ prefix_ void senf::MIHStatusTLVParser::dump(std::ostream & os) prefix_ void senf::MIHStatusTLVParser::validate() const { - validateTL( typeId, 1); + validateTypeLength( typeId, 1); if (value() >= 4) - throw InvalidMIHPacketException("invalid value in MIHStatusTLV ") << senf::str(value()); + throw InvalidMIHPacketException("invalid value in MIHStatusTLV ") << unsigned( value()); } //-///////////////////////////////////////////////////////////////////////////////////////////////// @@ -278,9 +276,9 @@ prefix_ void senf::MIHRegisterReqCodeTLVParser::dump(std::ostream & os) prefix_ void senf::MIHRegisterReqCodeTLVParser::validate() const { - validateTL( typeId, 1); + validateTypeLength( typeId, 1); if (value() >= 2) - throw InvalidMIHPacketException("invalid value in MIHRegisterReqCodeTLV ") << senf::str(value()); + throw InvalidMIHPacketException("invalid value in MIHRegisterReqCodeTLV ") << unsigned( value()); } //-///////////////////////////////////////////////////////////////////////////////////////////////// @@ -301,7 +299,7 @@ prefix_ void senf::MIHValidTimeIntervalTLVParser::dump(std::ostream & os) prefix_ void senf::MIHValidTimeIntervalTLVParser::validate() const { - validateTL( typeId, 4); + validateTypeLength( typeId, 4); } //-/////////////////////////////////////////////////////////////////////////////////////////////////