7#ifndef RADIUS_CLIENT_ATTRIBUTE_H
8#define RADIUS_CLIENT_ATTRIBUTE_H
20#include <boost/multi_index/hashed_index.hpp>
21#include <boost/multi_index/member.hpp>
22#include <boost/multi_index/sequenced_index.hpp>
23#include <boost/multi_index_container.hpp>
24#include <boost/noncopyable.hpp>
25#include <boost/shared_ptr.hpp>
31static constexpr size_t MAX_STRING_LEN = 253;
34static constexpr size_t MAX_VSA_DATA_LEN = MAX_STRING_LEN - 4;
37using isc::data::TypeError;
92 const std::string& value);
103 const std::vector<uint8_t>& value);
116 const std::string& value);
125 const std::vector<uint8_t>& value);
173 const uint32_t vendor,
174 const std::string& value);
184 const uint32_t vendor,
185 const std::vector<uint8_t>& value);
200 virtual std::string
toText(
size_t indent = 0)
const = 0;
205 virtual std::vector<uint8_t>
toBytes()
const = 0;
215 virtual std::string
toString()
const;
221 virtual std::vector<uint8_t>
toBinary()
const;
227 virtual uint32_t
toInt()
const;
263 virtual std::vector<uint8_t>
toVsaData()
const;
282 const std::string& value);
293 const std::vector<uint8_t>& value);
310 isc_throw(BadValue,
"value is empty");
312 if (value.size() > MAX_STRING_LEN) {
313 isc_throw(BadValue,
"value is too large " << value.size()
314 <<
" > " << MAX_STRING_LEN);
322 AttrString(
const uint8_t type,
const std::vector<uint8_t>& value);
337 const std::vector<uint8_t>& bytes);
354 return (value_.size());
361 virtual std::string
toText(
size_t indent = 0)
const override;
366 virtual std::vector<uint8_t>
toBytes()
const override;
378 virtual std::vector<uint8_t>
toBinary()
const override;
398 AttrInt(
const uint8_t type,
const int32_t value)
399 :
Attribute(type), value_(static_cast<uint32_t>(value)) {
406 AttrInt(
const uint8_t type,
const uint32_t value)
423 const std::vector<uint8_t>& bytes);
448 virtual std::string
toText(
size_t indent = 0)
const override;
453 virtual std::vector<uint8_t>
toBytes()
const override;
458 virtual uint32_t
toInt()
const override {
469 const uint32_t value_;
483 isc_throw(BadValue,
"not v4 address " << value);
500 const std::vector<uint8_t>& bytes);
524 virtual std::string
toText(
size_t indent = 0)
const override;
529 virtual std::vector<uint8_t>
toBytes()
const override;
559 isc_throw(BadValue,
"not v6 address " << value);
576 const std::vector<uint8_t>& bytes);
601 virtual std::string
toText(
size_t indent = 0)
const override;
606 virtual std::vector<uint8_t>
toBytes()
const override;
636 :
Attribute(type), len_(len), value_(value) {
638 isc_throw(BadValue,
"not v6 address " << value);
642 <<
static_cast<unsigned>(len));
659 const std::vector<uint8_t>& bytes);
684 virtual std::string
toText(
size_t indent = 0)
const override;
689 virtual std::vector<uint8_t>
toBytes()
const override;
727 AttrVsa(
const uint8_t type,
const uint32_t vendor,
728 const std::string& value)
729 :
Attribute(type), vendor_(vendor), value_(value) {
731 isc_throw(BadValue,
"value is empty");
733 if (value.size() > MAX_VSA_DATA_LEN) {
734 isc_throw(BadValue,
"value is too large " << value.size()
735 <<
" > " << MAX_VSA_DATA_LEN);
744 AttrVsa(
const uint8_t type,
const uint32_t vendor,
745 const std::vector<uint8_t>& value);
761 const std::vector<uint8_t>& bytes);
779 return (4 + value_.size());
786 virtual std::string
toText(
size_t indent = 0)
const override;
791 virtual std::vector<uint8_t>
toBytes()
const override;
803 virtual std::vector<uint8_t>
toVsaData()
const override;
825 typedef boost::multi_index_container<
829 boost::multi_index::indexed_by<
831 boost::multi_index::sequenced<>,
833 boost::multi_index::hashed_non_unique<
834 boost::multi_index::member<
876 bool del(
const uint8_t type);
892 size_t count(
const uint8_t type)
const;
906 std::string
toText(
size_t indent = 0)
const;
922 AttributeContainer::iterator
begin() {
929 AttributeContainer::const_iterator
begin()
const {
936 AttributeContainer::const_iterator
cbegin()
const {
943 AttributeContainer::iterator
end() {
950 AttributeContainer::const_iterator
end()
const {
955 AttributeContainer::const_iterator
cend()
const {
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
The IOAddress class represents an IP addresses (version agnostic).
bool isV6() const
Convenience function to check for an IPv6 address.
bool isV4() const
Convenience function to check for an IPv4 address.
virtual uint32_t toInt() const override
To integer.
static AttributePtr fromText(const uint8_t type, const std::string &repr)
From text.
virtual std::vector< uint8_t > toBytes() const override
To bytes.
virtual size_t getValueLen() const override
Value length.
virtual data::ElementPtr toElement() const override
Unparse attribute.
AttrInt(const uint8_t type, const uint32_t value)
Constructor (unsigned).
friend class Attribute
Make Attribute a friend class.
virtual std::string toText(size_t indent=0) const override
Returns text representation of the attribute.
AttrInt(const uint8_t type, const int32_t value)
Constructor (signed).
static AttributePtr fromBytes(const uint8_t type, const std::vector< uint8_t > &bytes)
From bytes.
virtual AttrValueType getValueType() const override
Get value type.
AttrIpAddr(const uint8_t type, const asiolink::IOAddress &value)
Constructor.
virtual data::ElementPtr toElement() const override
Unparse attribute.
virtual std::vector< uint8_t > toBytes() const override
To bytes.
static AttributePtr fromText(const uint8_t type, const std::string &repr)
From text.
virtual asiolink::IOAddress toIpAddr() const override
To IPv4 address.
static AttributePtr fromBytes(const uint8_t type, const std::vector< uint8_t > &bytes)
From bytes.
virtual size_t getValueLen() const override
Value length.
friend class Attribute
Make Attribute a friend class.
virtual AttrValueType getValueType() const override
Get value type.
virtual std::string toText(size_t indent=0) const override
Returns text representation of the attribute.
virtual std::string toText(size_t indent=0) const override
Returns text representation of the attribute.
virtual asiolink::IOAddress toIpv6Addr() const override
To IPv6 address.
static AttributePtr fromBytes(const uint8_t type, const std::vector< uint8_t > &bytes)
From bytes.
virtual std::vector< uint8_t > toBytes() const override
To bytes.
virtual AttrValueType getValueType() const override
Get value type.
virtual size_t getValueLen() const override
Value length.
static AttributePtr fromText(const uint8_t type, const std::string &repr)
From text.
AttrIpv6Addr(const uint8_t type, const asiolink::IOAddress &value)
Constructor.
friend class Attribute
Make Attribute a friend class.
virtual data::ElementPtr toElement() const override
Unparse attribute.
virtual asiolink::IOAddress toIpv6Prefix() const override
To IPv6 prefix.
AttrIpv6Prefix(const uint8_t type, const uint8_t len, const asiolink::IOAddress &value)
Constructor.
virtual std::vector< uint8_t > toBytes() const override
To bytes.
virtual data::ElementPtr toElement() const override
Unparse attribute.
virtual size_t getValueLen() const override
Value length.
virtual uint8_t toIpv6PrefixLen() const override
To IPv6 prefix length.
friend class Attribute
Make Attribute a friend class.
virtual AttrValueType getValueType() const override
Get value type.
static AttributePtr fromText(const uint8_t type, const std::string &repr)
From text.
static AttributePtr fromBytes(const uint8_t type, const std::vector< uint8_t > &bytes)
From bytes.
virtual std::string toText(size_t indent=0) const override
Returns text representation of the attribute.
static AttributePtr fromBytes(const uint8_t type, const std::vector< uint8_t > &bytes)
From bytes.
static AttributePtr fromText(const uint8_t type, const std::string &repr)
From text.
virtual std::vector< uint8_t > toBytes() const override
To bytes.
virtual data::ElementPtr toElement() const override
Unparse attribute.
virtual std::string toText(size_t indent=0) const override
Returns text representation of the attribute.
AttrString(const uint8_t type, const std::string &value)
Constructor.
virtual std::vector< uint8_t > toBinary() const override
To binary.
virtual size_t getValueLen() const override
Value length.
friend class Attribute
Make Attribute a friend class.
virtual std::string toString() const override
To string.
virtual AttrValueType getValueType() const override
Get value type.
virtual data::ElementPtr toElement() const override
Unparse attribute.
virtual std::string toText(size_t indent=0) const override
Returns text representation of the attribute.
virtual uint32_t toVendorId() const override
To vendor id.
static AttributePtr fromBytes(const uint8_t type, const std::vector< uint8_t > &bytes)
From bytes.
virtual AttrValueType getValueType() const override
Get value type.
friend class Attribute
Make Attribute a friend class.
static AttributePtr fromText(const uint8_t type, const std::string &repr)
From text.
virtual std::vector< uint8_t > toVsaData() const override
To vsa data.
AttrVsa(const uint8_t type, const uint32_t vendor, const std::string &value)
Constructor.
virtual size_t getValueLen() const override
Value length.
virtual std::vector< uint8_t > toBytes() const override
To bytes.
RADIUS attribute base class.
static AttributePtr fromBytes(const std::vector< uint8_t > &bytes)
Generic factories.
virtual std::string toString() const
Specific get methods.
virtual size_t getValueLen() const =0
Generic get methods.
static AttributePtr fromInt(const uint8_t type, const uint32_t value)
From integer with type.
static AttributePtr fromIpAddr(const uint8_t type, const asiolink::IOAddress &value)
From IPv4 address with type.
virtual uint32_t toInt() const
To integer.
Attribute(const uint8_t type)
Constructor.
virtual uint32_t toVendorId() const
To vendor id.
static AttributePtr fromString(const uint8_t type, const std::string &value)
From type specific factories.
virtual std::vector< uint8_t > toBytes() const =0
To bytes (wire format).
uint8_t getType() const
Get type.
virtual ~Attribute()=default
Virtual destructor.
virtual asiolink::IOAddress toIpAddr() const
To IPv4 address.
virtual asiolink::IOAddress toIpv6Addr() const
To IPv6 address.
static AttributePtr fromBinary(const uint8_t type, const std::vector< uint8_t > &value)
From binary with type.
static AttributePtr fromText(const AttrDefPtr &def, const std::string &value)
From definition generic factories.
virtual uint8_t toIpv6PrefixLen() const
To IPv6 prefix length.
static AttributePtr fromIpv6Prefix(const uint8_t type, const uint8_t len, const asiolink::IOAddress &value)
From IPv6 prefix with type.
virtual std::string toText(size_t indent=0) const =0
Returns text representation of the attribute.
static AttributePtr fromIpv6Addr(const uint8_t type, const asiolink::IOAddress &value)
From IPv6 address with type.
virtual asiolink::IOAddress toIpv6Prefix() const
To IPv6 prefix.
virtual AttrValueType getValueType() const =0
Get value type.
virtual std::vector< uint8_t > toBinary() const
To binary.
static AttributePtr fromVsa(const uint8_t type, const uint32_t vendor, const std::string &value)
From Vendor ID and string data with type.
virtual std::vector< uint8_t > toVsaData() const
To vsa data.
Collection of attributes.
boost::multi_index_container< ConstAttributePtr, boost::multi_index::indexed_by< boost::multi_index::sequenced<>, boost::multi_index::hashed_non_unique< boost::multi_index::member< Attribute, const uint8_t, &Attribute::type_ > > > > AttributeContainer
Type of the container.
AttributeContainer container_
The container.
size_t size() const
Returns the number of elements.
AttributeContainer::const_iterator begin() const
Get the iterator to the beginning.
std::string toText(size_t indent=0) const
Returns text representation of the collection.
bool empty() const
Indicates the object is empty.
void append(const Attributes &other)
Append another collection.
size_t count(const uint8_t type) const
Counts instance of the attribute in the collection.
virtual ~Attributes()
Destructor.
AttributeContainer::const_iterator cend() const
Get the const iterator to the past-the-end.
ConstAttributePtr get(const uint8_t type) const
Get instance of the attribute in the collection.
data::ElementPtr toElement() const override
Unparse collection.
void add(const ConstAttributePtr &attr, bool back=true)
Adds instance of the attribute to the collection.
AttributeContainer::const_iterator cbegin() const
Get the const iterator to the beginning.
void clear()
Clear the collection.
AttributeContainer::iterator begin()
Get the iterator to the beginning.
bool del(const uint8_t type)
Deletes an attribute from the collection.
static Attributes fromElement(const data::ConstElementPtr &attr_list)
Parse collection.
AttributeContainer::iterator end()
Get the iterator to the past-the-end.
AttributeContainer::const_iterator end() const
Get the iterator to the past-the-end.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< Attributes > AttributesPtr
Shared pointers to attribute collection.
boost::shared_ptr< const Attribute > ConstAttributePtr
boost::shared_ptr< AttrDef > AttrDefPtr
Shared pointers to Attribute definition.
AttrValueType
Attribute value types.
boost::shared_ptr< Attribute > AttributePtr
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.