# define PTRMAP_GET_CONTENTS(v) (*(v).second)
#endif
-prefix_ std::pair<bool, std::string> senf::MIHMessageRegistry::validate(key_t messageId, senf::Packet message)
+prefix_ void senf::MIHMessageRegistry::validate(key_t messageId, senf::Packet message)
{
Map::const_iterator i (map_.find( messageId));
if (i != map_.end())
- return PTRMAP_GET_CONTENTS(*i).validate( message);
- return std::make_pair(true, "");
+ PTRMAP_GET_CONTENTS(*i).validate( message);
}
#undef PTRMAP_GET_CONTENTS
struct MIHMessageRegistry_EntryBase {
virtual ~MIHMessageRegistry_EntryBase() {}
- virtual std::pair<bool, std::string> validate(senf::Packet message) const = 0;
+ virtual void validate(senf::Packet message) const = 0;
};
template <class MIHPacket,
- bool use_validate_member = has_static_validate_member<typename MIHPacket::type, std::pair<bool, std::string>(MIHPacket)>::value>
+ bool use_validate_member = has_static_validate_member<typename MIHPacket::type, void(MIHPacket)>::value>
struct MIHMessageRegistryEntry : MIHMessageRegistry_EntryBase
{
- virtual std::pair<bool, std::string> validate(senf::Packet message) const {
- return std::make_pair(true, "");
- }
+ virtual void validate(senf::Packet message) const {}
};
template <class MIHPacket>
struct MIHMessageRegistryEntry<MIHPacket, true> : MIHMessageRegistry_EntryBase
{
- virtual std::pair<bool, std::string> validate(senf::Packet message) const {
- return MIHPacket::type::validate(message.as<MIHPacket>());
+ virtual void validate(senf::Packet message) const {
+ MIHPacket::type::validate(message.as<MIHPacket>());
}
};
}
template <typename MIHPacket>
void registerMessageType();
- std::pair<bool, std::string> validate(key_t messageId, senf::Packet message);
+ void validate(key_t messageId, senf::Packet message);
private:
typedef boost::ptr_map<key_t, detail::MIHMessageRegistry_EntryBase > Map;
static const boost::uint16_t MESSAGE_ID;
- static std::pair<bool, std::string> validate(packet message) {
+ static void validate(packet message) {
return message->registerRequestCodeTLV().validate();
}
};
mihPacket->src_mihfId().value( "senf@berlios.de");
mihPacket->dst_mihfId().value( "test");
- BOOST_CHECK(! MIHPacketType::validate( mihPacket).first);
+ BOOST_CHECK_THROW( MIHPacketType::validate( mihPacket), InvalidMIHPacketException);
mihPacket.finalizeThis();
- BOOST_CHECK( MIHPacketType::validate( mihPacket).first);
+ BOOST_CHECK_NO_THROW( MIHPacketType::validate( mihPacket));
{
test::TestMessagePacket testMessage (test::TestMessagePacket::createAfter(mihPacket));
mihPacket.finalizeAll();
- BOOST_CHECK( MIHPacketType::validate( mihPacket).first);
+ BOOST_CHECK_NO_THROW( MIHPacketType::validate( mihPacket));
}
{
test::ValidatedTestMessagePacket testMessage (test::ValidatedTestMessagePacket::createAfter(mihPacket));
mihPacket.finalizeAll();
testMessage->registerRequestCodeTLV().value() << 3;
- BOOST_CHECK(! MIHPacketType::validate( mihPacket).first);
+ BOOST_CHECK_THROW( MIHPacketType::validate( mihPacket), InvalidMIHPacketException);
testMessage->registerRequestCodeTLV().value() << 1;
- BOOST_CHECK( MIHPacketType::validate( mihPacket).first);
+ BOOST_CHECK_NO_THROW( MIHPacketType::validate( mihPacket));
}
}
return e ? e->factory() : MIHGenericPayloadPacket::factory();
}
-prefix_ std::pair<bool, std::string> senf::MIHPacketType::validate(packet p)
+prefix_ void senf::MIHPacketType::validate(packet p)
{
try {
if (p.data().size() < initSize())
- return std::make_pair(false, "truncated MIH message");
+ throw InvalidMIHPacketException("truncated MIH message");
if (p->version() != 1)
- return std::make_pair(false, "invalid MIH version: " + senf::str(p->version()) );
+ throw InvalidMIHPacketException("invalid MIH version: ") << senf::str(p->version());
if (p->payloadLength() != p.size()-8)
- return std::make_pair(false, "wrong MIH length: " + senf::str(p->payloadLength()) );
+ throw InvalidMIHPacketException("wrong MIH length: ") << senf::str(p->payloadLength());
if (p.next(senf::nothrow))
- return MIHMessageRegistry::instance().validate( p->messageId(), p.next());
+ MIHMessageRegistry::instance().validate( p->messageId(), p.next());
} catch (senf::TruncatedPacketException e) {
- return std::make_pair(false, "truncated MIH message");
+ throw InvalidMIHPacketException("truncated MIH message");
}
- return std::make_pair(true, "");
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
static void dump(packet p, std::ostream &os);
static void finalize(packet p);
static factory_t nextPacketType(packet p);
-
- static std::pair<bool, std::string> validate(packet p);
+ static void validate(packet p);
};
/** \brief MIH packet typedef
//-/////////////////////////////////////////////////////////////////////////////////////////////////
// MIHBaseTLVParser
-prefix_ std::pair<bool, std::string> senf::MIHBaseTLVParser::validateTL(boost::uint8_t expectedType, MIHTLVLengthParser::value_type expectedLength)
+prefix_ void senf::MIHBaseTLVParser::validateTL(boost::uint8_t expectedType, MIHTLVLengthParser::value_type expectedLength)
const
{
if (! check( 1 + senf::bytes(length_()) + length()) )
- return std::make_pair(false, "truncated TLV. Type: " + senf::str(type()));
+ throw InvalidMIHPacketException("truncated TLV.") << " Type: " << senf::str(type());
if (type() != expectedType)
- return std::make_pair(false, "invalid TLV type: " + senf::str(type()));
+ throw InvalidMIHPacketException("invalid TLV type") << " Type: " << senf::str(type());
if (length() != expectedLength)
- return std::make_pair(false, "invalid length in TLV. Type: " + senf::str(type()));
- return std::make_pair(true, "");
+ throw InvalidMIHPacketException("invalid length in TLV.") << " Type: " << senf::str(type());
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
MIHFIdTLVParser::dump(os);
}
-prefix_ std::pair<bool, std::string> senf::MIHFSrcIdTLVParser::validate()
+prefix_ void senf::MIHFSrcIdTLVParser::validate()
const
{
if (! check( 1 + senf::bytes(length_()) + length()) )
- return std::make_pair(false, "truncated TLV. Type: " + senf::str(type()));
+ throw InvalidMIHPacketException("truncated TLV.") << " Type: " << senf::str(type());
if (type() != typeId)
- return std::make_pair(false, "invalid TLV type: " + senf::str(type()));
- return std::make_pair(true, "");
+ throw InvalidMIHPacketException("invalid TLV type: ") << senf::str(type());
}
MIHFIdTLVParser::dump(os);
}
-prefix_ std::pair<bool, std::string> senf::MIHFDstIdTLVParser::validate()
+prefix_ void senf::MIHFDstIdTLVParser::validate()
const
{
if (! check( 1 + senf::bytes(length_()) + length()) )
- return std::make_pair(false, "truncated TLV. Type: " + senf::str(type()));
+ throw InvalidMIHPacketException("truncated TLV.") << " Type: " << senf::str(type());
if (type() != typeId)
- return std::make_pair(false, "invalid TLV type: " + senf::str(type()));
- return std::make_pair(true, "");
+ throw InvalidMIHPacketException("invalid TLV type: ") << senf::str(type());
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
os << " (???; invalid value!)" << std::endl;
}
-prefix_ std::pair<bool, std::string> senf::MIHStatusTLVParser::validate()
+prefix_ void senf::MIHStatusTLVParser::validate()
const
{
- if (! validateTL( typeId, 1).first)
- return validateTL( typeId, 1);
+ validateTL( typeId, 1);
if (value() >= 4)
- return std::make_pair(false, "invalid value in MIHStatusTLV " + senf::str(value()));
- return std::make_pair(true, "");
+ throw InvalidMIHPacketException("invalid value in MIHStatusTLV ") << senf::str(value());
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
os << " (???; invalid value!)" << std::endl;
}
-prefix_ std::pair<bool, std::string> senf::MIHRegisterReqCodeTLVParser::validate()
+prefix_ void senf::MIHRegisterReqCodeTLVParser::validate()
const
{
- if (! validateTL( typeId, 1).first)
- return validateTL( typeId, 1);
+ validateTL( typeId, 1);
if (value() >= 2)
- return std::make_pair(false, "invalid value in MIHRegisterReqCodeTLV " + senf::str(value()));
- return std::make_pair(true, "");
+ 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 (! validateTL( typeId, 4).first) return validateTL( typeId, 4);
- return std::make_pair(true, "");
+ validateTL( typeId, 4);
}
//-/////////////////////////////////////////////////////////////////////////////////////////////////
: senf::Exception("MIHTLVLengthException") {}
};
+ struct InvalidMIHPacketException : public senf::Exception {
+ InvalidMIHPacketException(std::string const & description)
+ : senf::Exception("Invalid MIH message: ") { append(description); }
+ };
+
class MIHTLVLengthParser
: public detail::packet::IntParserOps<MIHTLVLengthParser, boost::uint32_t>,
*/
void maxLength(MIHTLVLengthParser::value_type maxl) const;
- std::pair<bool, std::string> validateTL(boost::uint8_t type, MIHTLVLengthParser::value_type length) const;
+ void validateTL(boost::uint8_t type, MIHTLVLengthParser::value_type length) const;
};
}
static type_t::value_type const typeId = 1;
void dump(std::ostream & os) const;
- std::pair<bool, std::string> validate() const;
+ void validate() const;
};
/** \brief Parser for 802.21 destination MIHF_ID TLV
}
static type_t::value_type const typeId = 2;
void dump(std::ostream & os) const;
- std::pair<bool, std::string> validate() const;
+ void validate() const;
};
/** \brief Parser for 802.21 Status TLV
}
static type_t::value_type const typeId = 3;
void dump(std::ostream & os) const; ///< dump string representation to given stream
- std::pair<bool, std::string> validate() const;
+ void validate() const;
enum StatusCode {
Success, UnspecifiedFailure, Rejected, AuthorizationFailure, NetworkError };
}
static type_t::value_type const typeId = 11;
void dump(std::ostream & os) const; ///< dump string representation to given stream
- std::pair<bool, std::string> validate() const;
+ void validate() const;
enum RequestCode { Registration, ReRegistration };
};
}
static type_t::value_type const typeId = 12;
void dump(std::ostream & os) const; ///< dump string representation to given stream
- std::pair<bool, std::string> validate() const;
+ void validate() const;
};
}