13#include <boost/lexical_cast.hpp> 
   36    size_t equal = trimed.find(
'=');
 
   37    if (equal == string::npos) {
 
   41    string name = 
str::trim(trimed.substr(0, equal));
 
   45    string value = 
str::trim(trimed.substr(equal + 1));
 
 
   65    switch (
static_cast<uint8_t
>(def->value_type_)) {
 
   69        if (!isdigit(value[0])) {
 
   73                return (
fromInt(def->type_, ic_def->value_));
 
   86                  << 
static_cast<unsigned>(def->value_type_));
 
 
   93    if (bytes.size() < 2) {
 
   96    uint8_t type = bytes[0];
 
   97    uint8_t len = bytes[1];
 
   99    if (len != bytes.size()) {
 
  101                  << 
" != " << 
static_cast<unsigned>(len));
 
  103    vector<uint8_t> value;
 
  104    value.resize(len - 2);
 
  105    if (value.size() > 0) {
 
  106        memmove(&value[0], &bytes[2], value.size());
 
 
  123    switch (
static_cast<uint8_t
>(def->value_type_)) {
 
  137                  << 
static_cast<unsigned>(def->value_type_));
 
 
  223        isc_throw(BadValue, 
"value is empty");
 
  225    if (value.size() > MAX_STRING_LEN) {
 
  226        isc_throw(BadValue, 
"value is too large " << value.size()
 
  227                  << 
" > " << MAX_STRING_LEN);
 
  229    value_.resize(value.size());
 
  230    memmove(&value_[0], &value[0], value_.size());
 
 
  238    if (repr.size() > MAX_STRING_LEN) {
 
  240                  << 
" > " << MAX_STRING_LEN);
 
 
  250    if (bytes.size() > MAX_STRING_LEN) {
 
  252                  << 
" > " << MAX_STRING_LEN);
 
 
  259    ostringstream output;
 
  260    for (
size_t i = 0; i < indent; i++) {
 
  264    return (output.str());
 
 
  269    vector<uint8_t> output;
 
  273    memmove(&output[2], &value_[0], output.size() - 2);
 
 
  279    vector<uint8_t> binary;
 
  281    if (binary.size() > 0) {
 
  282        memmove(&binary[0], &value_[0], binary.size());
 
 
  298        vector<uint8_t> binary;
 
  299        binary.resize(value_.size());
 
  300        if (binary.size() > 0) {
 
  301            memmove(&binary[0], value_.c_str(), binary.size());
 
 
  315        int64_t val = boost::lexical_cast<int64_t>(repr);
 
  316        if ((val < numeric_limits<int32_t>::min()) ||
 
  317            (val > numeric_limits<uint32_t>::max())) {
 
 
  332    if (bytes.size() != 4) {
 
  334        msg << 
"bad value length " << bytes.size() << 
" != 4";
 
  341    int32_t val = (
static_cast<int32_t
>(bytes[0])) << 24;
 
  342    val |= (
static_cast<int32_t
>(bytes[1])) << 16;
 
  343    val |= (
static_cast<int32_t
>(bytes[2])) << 8;
 
  344    val |= 
static_cast<int32_t
>(bytes[3]);
 
 
  350    ostringstream output;
 
  351    for (
size_t i = 0; i < indent; i++) {
 
  357        output << ic_def->name_;
 
  361    return (output.str());
 
 
  366    vector<uint8_t> output;
 
  370    output[2] = 
static_cast<uint8_t
>((value_ & 0xff000000U) >> 24);
 
  371    output[3] = 
static_cast<uint8_t
>((value_ & 0xff0000U) >> 16);
 
  372    output[4] = 
static_cast<uint8_t
>((value_ & 0xff00U) >> 8);
 
  373    output[5] = 
static_cast<uint8_t
>(value_ & 0xffU);
 
 
  407    if (bytes.size() != 4) {
 
  409        msg << 
"bad value length " << bytes.size() << 
" != 4";
 
 
  422    ostringstream output;
 
  423    for (
size_t i = 0; i < indent; i++) {
 
  428    return (output.str());
 
 
  433    vector<uint8_t> output;
 
  437    vector<uint8_t> binary = value_.toBytes();
 
  438    memmove(&output[2], &binary[0], output.size() - 2);
 
 
  451    val << value_.toText();
 
 
  472    if (bytes.size() != 16) {
 
  474        msg << 
"bad value length " << bytes.size() << 
" != 16";
 
 
  487    ostringstream output;
 
  488    for (
size_t i = 0; i < indent; i++) {
 
  493    return (output.str());
 
 
  498    vector<uint8_t> output;
 
  502    vector<uint8_t> binary = value_.toBytes();
 
  503    memmove(&output[2], &binary[0], output.size() - 2);
 
 
  516    val << value_.toText();
 
 
  524        auto pos = repr.find(
'/');
 
  525        if ((pos == string::npos) ||
 
  526            (pos == repr.size() - 1) ||
 
  531        int len = boost::lexical_cast<int>(repr.substr(pos + 1));
 
  532        if ((len < numeric_limits<uint8_t>::min()) ||
 
  533            (len > numeric_limits<uint8_t>::max())) {
 
  537                                                static_cast<uint8_t
>(len),
 
 
  552    if (bytes.size() < 2) {
 
  553        msg << 
"bad value length " << bytes.size() << 
" < 2";
 
  554    } 
else if (bytes.size() > 18) {
 
  555        msg << 
"bad value length " << bytes.size() << 
" > 18";
 
  556    } 
else if (bytes[1] > 128) {
 
  557        msg << 
"bad prefix length " << 
static_cast<unsigned>(bytes[1]) << 
" > 128";
 
  559    string const msg_str(msg.str());
 
  560    if (!msg_str.empty()) {
 
  562            .arg(
static_cast<unsigned>(type))
 
  567    uint8_t len = bytes[1];
 
  568    vector<uint8_t> prefix(16);
 
  569    if (bytes.size() > 2) {
 
  570        memmove(&prefix[0], &bytes[2], bytes.size() - 2);
 
 
  578    ostringstream output;
 
  579    for (
size_t i = 0; i < indent; i++) {
 
  583           << value_.toText() << 
"/" << 
static_cast<unsigned>(len_);
 
  584    return (output.str());
 
 
  589    vector<uint8_t> output;
 
  596    vector<uint8_t> binary = value_.toBytes();
 
  597    memmove(&output[4], &binary[0], output.size() - 4);
 
 
  610    val << value_.toText() << 
"/" << 
static_cast<unsigned>(len_);
 
 
  620    static_cast<void>(
container_.push_back(attr));
 
 
  626    auto it = idx.find(type);
 
  627    if (it != idx.end()) {
 
 
  636    for (
auto const& it : other) {
 
 
  644    return (idx.count(type));
 
 
  650    auto it = idx.find(type);
 
  651    if (it != idx.end()) {
 
 
  660    ostringstream output;
 
  662    for (
auto const& it : *
this) {
 
  668        output << it->toText(indent);
 
  670    return (output.str());
 
 
  676    for (
auto const& it : *
this) {
 
  677        output->add(it->toElement());
 
 
  688    for (
auto const& entry : attr_list->listValue()) {
 
  703                (!raw->stringValue().empty())) {
 
  705                    vector<uint8_t> binary;
 
  717            (!
data->stringValue().empty())) {
 
 
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown when an object can not be found.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
The IOAddress class represents an IP addresses (version agnostic)
static IOAddress fromBytes(short family, const uint8_t *data)
Creates an address from over wire data.
A standard Data module exception that is thrown if a function is called for an Element that has a wro...
static AttrDefs & instance()
Returns a single instance.
AttrDefPtr getByName(const std::string &name) const
Get attribute definition by name.
std::string getName(const uint8_t type) const
Get attribute name.
AttrDefPtr getByType(const uint8_t type) const
Get attribute definition by type.
IntCstDefPtr getByValue(const uint8_t type, const uint32_t value) const
Get integer constant definition by attribute type and value.
RADIUS attribute holding integers.
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.
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.
RADIUS attribute holding IPv4 addresses.
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.
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.
RADIUS attribute holding IPv6 addresses.
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.
virtual std::vector< uint8_t > toBytes() const override
To bytes.
static AttributePtr fromText(const uint8_t type, const std::string &repr)
From text.
AttrIpv6Addr(const uint8_t type, const asiolink::IOAddress &value)
Constructor.
virtual data::ElementPtr toElement() const override
Unparse attribute.
RADIUS attribute holding IPv6 prefixes.
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.
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.
RADIUS attribute derived classes: do not use them directly outside unit tests, instead use 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.
static AttributePtr fromBytes(const std::vector< uint8_t > &bytes)
From bytes (wire format).
virtual std::string toString() const
Specific 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.
static AttributePtr fromString(const uint8_t type, const std::string &value)
From type specific factories.
uint8_t getType() const
Get type.
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 std::string &repr)
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.
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.
Collection of attributes.
void add(const ConstAttributePtr &attr)
Adds instance of the attribute to the collection.
AttributeContainer container_
The container.
std::string toText(size_t indent=0) const
Returns text representation of the collection.
void append(const Attributes &other)
Append another collection.
size_t count(const uint8_t type) const
Counts instance of the attribute in the collection.
ConstAttributePtr get(const uint8_t type) const
Get instance of the attribute in the collection.
data::ElementPtr toElement() const override
Unparse collection.
bool del(const uint8_t type)
Deletes an attribute from the collection.
static Attributes fromElement(const data::ConstElementPtr &attr_list)
Parse collection.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< IntCstDef > IntCstDefPtr
Shared pointers to Integer constant definition.
const isc::log::MessageID RADIUS_IPV6PREFIX_ATTRIBUTE_FROM_BYTES_FAILED
boost::shared_ptr< const Attribute > ConstAttributePtr
const isc::log::MessageID RADIUS_IPADDR_ATTRIBUTE_FROM_BYTES_FAILED
const isc::log::MessageID RADIUS_IPV6PREFIX_ATTRIBUTE_FROM_TEXT_FAILED
boost::shared_ptr< AttrDef > AttrDefPtr
Shared pointers to Attribute definition.
string attrValueTypeToText(const AttrValueType value)
AttrValueType value -> name function.
boost::shared_ptr< Attribute > AttributePtr
const isc::log::MessageID RADIUS_IPV6ADDR_ATTRIBUTE_FROM_TEXT_FAILED
isc::log::Logger radius_logger("radius-hooks")
Radius Logger.
const isc::log::MessageID RADIUS_INTEGER_ATTRIBUTE_FROM_TEXT_FAILED
const isc::log::MessageID RADIUS_INTEGER_ATTRIBUTE_FROM_BYTES_FAILED
const isc::log::MessageID RADIUS_IPADDR_ATTRIBUTE_FROM_TEXT_FAILED
const isc::log::MessageID RADIUS_IPV6ADDR_ATTRIBUTE_FROM_BYTES_FAILED
void decodeHex(const string &encoded_str, vector< uint8_t > &output)
Decode a base16 encoded string into binary data.
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 format.
bool isPrintable(const string &content)
Check if a string is printable.
string trim(const string &input)
Trim leading and trailing spaces.
Defines the logger used by the top-level component of kea-lfc.