//#include "TLVParser.ih"
// Custom includes
-#include <iomanip>
#include <senf/Utils/hexdump.hh>
#include <senf/Utils/Format.hh>
#include <senf/Utils/String.hh>
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_ std::pair<bool, std::string> senf::MIHRegisterReqCodeTLVParser::validate()
+prefix_ void senf::MIHRegisterReqCodeTLVParser::validate()
const
{
- if (length() != 1) return std::make_pair(false, "invalid length in MIHRegisterReqCodeTLV " + senf::str(length()));
- if (value() >= 2) return std::make_pair(false, "invalid value in MIHRegisterReqCodeTLV " + senf::str(value()));
- return std::make_pair(true, "");
+ validateTypeLength( typeId, 1);
+ if (value() >= 2)
+ throw InvalidMIHPacketException("invalid value in MIHRegisterReqCodeTLV ") << senf::str(value());
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
<< ( value()==0 ? " (infinite)" : " seconds") << std::endl;
}
-prefix_ std::pair<bool, std::string> senf::MIHValidTimeIntervalTLVParser::validate()
+prefix_ void senf::MIHValidTimeIntervalTLVParser::validate()
const
{
- if (length() != 4) return std::make_pair(false, "invalid length in MIHValidTimeIntervalTLV " + senf::str(length()));
- return std::make_pair(true, "");
+ validateTypeLength( typeId, 4);
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////