7 #ifndef OPTION_DATA_TYPES_H 8 #define OPTION_DATA_TYPES_H 93 static const bool valid =
false;
94 static const int len = 0;
112 static const int len =
sizeof(uint8_t);
215 : psid_len_(psid_len) {
216 if (psid_len_ >
sizeof(uint16_t) * 8) {
236 return (static_cast<unsigned>(psid_len_));
257 explicit PSID(
const uint16_t psid)
291 : prefix_len_(prefix_len) {
296 return (prefix_len_);
305 return (static_cast<unsigned>(prefix_len_));
377 std::vector<uint8_t>& buf);
384 static void writeBinary(
const std::string& hex_str,
385 std::vector<uint8_t>& buf);
394 static std::string
readTuple(
const std::vector<uint8_t>& buf,
404 static void readTuple(
const std::vector<uint8_t>& buf,
412 static void writeTuple(
const std::string& value,
414 std::vector<uint8_t>& buf);
421 std::vector<uint8_t>& buf);
430 static bool readBool(
const std::vector<uint8_t>& buf);
439 static void writeBool(
const bool value, std::vector<uint8_t>& buf);
450 static T
readInt(
const std::vector<uint8_t>& buf) {
453 " by readInteger is unsupported integer type");
458 "failed to read an integer value from a buffer" 459 <<
" - buffer is truncated.");
465 value = *(buf.begin());
481 "invalid size of the data type to be read as integer.");
493 std::vector<uint8_t>& buf) {
499 buf.push_back(static_cast<uint8_t>(value));
502 buf.resize(buf.size() + 2);
506 buf.resize(buf.size() + 4);
527 static std::string
readFqdn(
const std::vector<uint8_t>& buf);
543 static void writeFqdn(
const std::string& fqdn,
544 std::vector<uint8_t>& buf,
545 const bool downcase =
false);
556 static unsigned int getLabelCount(
const std::string& text_name);
580 std::vector<uint8_t>& buf);
609 std::vector<uint8_t>& buf);
616 static std::string
readString(
const std::vector<uint8_t>& buf);
623 std::vector<uint8_t>& buf);
628 std::map<std::string, OptionDataType> data_types_;
632 std::map<OptionDataType, std::string> data_type_names_;
654 OptionDataType getDataTypeImpl(
const std::string& data_type)
const;
660 const std::string& getDataTypeNameImpl(
const OptionDataType data_type)
const;
667 #endif // OPTION_DATA_TYPES_H Encapsulation of option definition parameters and the structure size.
static const bool integer_type
PrefixLen(const uint8_t prefix_len)
Constructor.
const char * encapsulates
Encapsulates PSID length.
uint8_t * writeUint32(uint32_t value, uint8_t *buffer, size_t length)
Write Unsigned 32-Bit Integer to Buffer.
static void writePsid(const PSIDLen &psid_len, const PSID &psid, std::vector< uint8_t > &buf)
Append PSID length/value into a buffer.
static const std::string & getDataTypeName(const OptionDataType data_type)
Return option data type name from the data type enumerator.
static std::string readFqdn(const std::vector< uint8_t > &buf)
Read FQDN from a buffer as a string value.
static T readInt(const std::vector< uint8_t > &buf)
Read integer value from a buffer.
PSIDLen(const uint8_t psid_len)
Constructor.
Utility class for option data types.
static void writeBool(const bool value, std::vector< uint8_t > &buf)
Append boolean value into a buffer.
InvalidDataType(const char *file, size_t line, const char *what)
static void writeFqdn(const std::string &fqdn, std::vector< uint8_t > &buf, const bool downcase=false)
Append FQDN into a buffer.
static int getDataTypeLen(const OptionDataType data_type)
Get data type buffer length.
static void writePrefix(const PrefixLen &prefix_len, const asiolink::IOAddress &prefix, std::vector< uint8_t > &buf)
Append prefix into a buffer.
PSIDLen()
Default constructor.
static bool readBool(const std::vector< uint8_t > &buf)
Read boolean value from a buffer.
std::pair< PrefixLen, asiolink::IOAddress > PrefixTuple
Defines a pair of prefix length / value.
Parameters being used to make up an option definition.
uint16_t asUint16() const
Returns PSID value as a number.
Exception to be thrown when invalid type specified as template parameter.
static PSIDTuple readPsid(const std::vector< uint8_t > &buf)
Read PSID length / value tuple from a buffer.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
const OptionDataType * records
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
uint8_t asUint8() const
Returns prefix length as uint8_t value.
static void writeTuple(const std::string &value, OpaqueDataTuple::LengthFieldType lengthfieldtype, std::vector< uint8_t > &buf)
Append length and string tuple to a buffer.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
static std::string readString(const std::vector< uint8_t > &buf)
Read string value from a buffer.
static OptionDataType getDataType(const std::string &data_type)
Return option data type from its name.
OptionDataType
Data types of DHCP option fields.
uint8_t * writeUint16(uint16_t value, void *buffer, size_t length)
Write Unsigned 16-Bit Integer to Buffer.
uint8_t asUint8() const
Returns PSID length as uint8_t value.
static const OptionDataType type
PSID(const uint16_t psid)
Constructor.
PSID()
Default constructor.
uint32_t readUint32(const uint8_t *buffer, size_t length)
Read Unsigned 32-Bit Integer from Buffer.
LengthFieldType
Size of the length field in the tuple.
static asiolink::IOAddress readAddress(const std::vector< uint8_t > &buf, const short family)
Read IPv4 or IPv6 address from a buffer.
std::pair< PSIDLen, PSID > PSIDTuple
Defines a pair of PSID length / value.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
uint16_t readUint16(const void *buffer, size_t length)
Read Unsigned 16-Bit Integer from Buffer.
A wrapper interface for the ASIO library.
static std::string readTuple(const std::vector< uint8_t > &buf, OpaqueDataTuple::LengthFieldType lengthfieldtype)
Read length and string tuple from a buffer.
static void writeAddress(const asiolink::IOAddress &address, std::vector< uint8_t > &buf)
Append IPv4 or IPv6 address to a buffer.
static PrefixTuple readPrefix(const std::vector< uint8_t > &buf)
Read prefix from a buffer.
Represents a single instance of the opaque data preceded by length.
static void writeBinary(const std::string &hex_str, std::vector< uint8_t > &buf)
Append hex-encoded binary values to a buffer.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
PrefixLen()
Default constructor.
Exception to be thrown when cast to the data type was unsuccessful.
Trait class for data types supported in DHCP option definitions.
static unsigned int getLabelCount(const std::string &text_name)
Return the number of labels in the Name.
The IOAddress class represents an IP addresses (version agnostic)
unsigned int asUnsigned() const
Returns PSID length as unsigned int.
static void writeString(const std::string &value, std::vector< uint8_t > &buf)
Write UTF8-encoded string into a buffer.
const struct OptionDefParams * optionDefParams
Encapsulates prefix length.
static void writeInt(const T value, std::vector< uint8_t > &buf)
Append integer or unsigned integer value to a buffer.
BadDataTypeCast(const char *file, size_t line, const char *what)
unsigned int asUnsigned() const
Returns prefix length as unsigned int.