Kea  2.1.2-git
isc::dhcp::OptionString Class Reference

Class which represents an option carrying a single string value. More...

#include <option_string.h>

+ Inheritance diagram for isc::dhcp::OptionString:

Public Member Functions

 OptionString (const Option::Universe u, const uint16_t type, const std::string &value)
 Constructor, used to create options to be sent. More...
 
 OptionString (const Option::Universe u, const uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end)
 Constructor, used for receiving options. More...
 
OptionPtr clone () const
 Copies this option and returns a pointer to the copy. More...
 
std::string getValue () const
 Returns the string value held by the option. More...
 
virtual uint16_t len () const
 Returns length of the whole option, including header. More...
 
virtual void pack (isc::util::OutputBuffer &buf) const
 Creates on-wire format of the option. More...
 
void setValue (const std::string &value)
 Sets the string value to be held by the option. More...
 
virtual std::string toString () const
 Returns actual value of the option in string format. More...
 
virtual std::string toText (int indent=0) const
 Returns option information in the textual format. More...
 
virtual void unpack (OptionBufferConstIter begin, OptionBufferConstIter end)
 Decodes option data from the provided buffer. More...
 
- Public Member Functions inherited from isc::dhcp::Option
 Option (Universe u, uint16_t type)
 ctor, used for options constructed, usually during transmission More...
 
 Option (Universe u, uint16_t type, const OptionBuffer &data)
 Constructor, used for received options. More...
 
 Option (Universe u, uint16_t type, OptionBufferConstIter first, OptionBufferConstIter last)
 Constructor, used for received options. More...
 
 Option (const Option &source)
 Copy constructor. More...
 
virtual ~Option ()
 just to force that every option has virtual dtor More...
 
void addOption (OptionPtr opt)
 Adds a sub-option. More...
 
bool delOption (uint16_t type)
 Attempts to delete first suboption of requested type. More...
 
bool equals (const OptionPtr &other) const
 Checks if options are equal. More...
 
virtual bool equals (const Option &other) const
 Checks if two options are equal. More...
 
virtual const OptionBuffergetData () const
 Returns pointer to actual data. More...
 
std::string getEncapsulatedSpace () const
 Returns the name of the option space encapsulated by this option. More...
 
virtual uint16_t getHeaderLen () const
 Returns length of header (2 for v4, 4 for v6) More...
 
OptionPtr getOption (uint16_t type) const
 Returns shared_ptr to suboption of specific type. More...
 
const OptionCollectiongetOptions () const
 Returns all encapsulated options. More...
 
void getOptionsCopy (OptionCollection &options_copy) const
 Performs deep copy of suboptions. More...
 
uint16_t getType () const
 Returns option type (0-255 for DHCPv4, 0-65535 for DHCPv6) More...
 
uint16_t getUint16 () const
 Returns content of first word. More...
 
uint32_t getUint32 () const
 Returns content of first double word. More...
 
uint8_t getUint8 () const
 Returns content of first byte. More...
 
Universe getUniverse () const
 returns option universe (V4 or V6) More...
 
Optionoperator= (const Option &rhs)
 Assignment operator. More...
 
template<typename InputIterator >
void setData (InputIterator first, InputIterator last)
 Sets content of this option from buffer. More...
 
void setEncapsulatedSpace (const std::string &encapsulated_space)
 Sets the name of the option space encapsulated by this option. More...
 
void setUint16 (uint16_t value)
 Sets content of this option to a single uint16 value. More...
 
void setUint32 (uint32_t value)
 Sets content of this option to a single uint32 value. More...
 
void setUint8 (uint8_t value)
 Sets content of this option to a single uint8 value. More...
 
virtual std::vector< uint8_t > toBinary (const bool include_header=false) const
 Returns binary representation of the option. More...
 
virtual std::string toHexString (const bool include_header=false) const
 Returns string containing hexadecimal representation of option. More...
 
virtual bool valid () const
 returns if option is valid (e.g. More...
 

Additional Inherited Members

- Public Types inherited from isc::dhcp::Option
typedef OptionPtr Factory(Option::Universe u, uint16_t type, const OptionBuffer &buf)
 a factory function prototype More...
 
enum  Universe { V4, V6 }
 defines option universe DHCPv4 or DHCPv6 More...
 
- Static Public Member Functions inherited from isc::dhcp::Option
static OptionPtr create (Universe u, uint16_t type)
 Factory function creating an instance of the Option. More...
 
static OptionPtr create (Universe u, uint16_t type, const OptionBuffer &data)
 Factory function creating an instance of the Option. More...
 
static OptionPtr factory (Option::Universe u, uint16_t type, const OptionBuffer &buf)
 Factory function to create instance of option. More...
 
static OptionPtr factory (Option::Universe u, uint16_t type)
 Factory function to create instance of option. More...
 
- Static Public Attributes inherited from isc::dhcp::Option
static bool lenient_parsing_
 Governs whether options should be parsed less strictly. More...
 
static const size_t OPTION4_HDR_LEN = 2
 length of the usual DHCPv4 option header (there are exceptions) More...
 
static const size_t OPTION6_HDR_LEN = 4
 length of any DHCPv6 option header More...
 
- Protected Member Functions inherited from isc::dhcp::Option
void check () const
 A protected method used for option correctness. More...
 
template<typename OptionType >
OptionPtr cloneInternal () const
 Copies this option and returns a pointer to the copy. More...
 
std::string headerToText (const int indent=0, const std::string &type_name="") const
 Returns option header in the textual format. More...
 
void packHeader (isc::util::OutputBuffer &buf) const
 Store option's header in a buffer. More...
 
void packOptions (isc::util::OutputBuffer &buf) const
 Store sub options in a buffer. More...
 
std::string suboptionsToText (const int indent=0) const
 Returns collection of suboptions in the textual format. More...
 
void unpackOptions (const OptionBuffer &buf)
 Builds a collection of sub options from the buffer. More...
 
- Protected Attributes inherited from isc::dhcp::Option
OptionBuffer data_
 contains content of this data More...
 
std::string encapsulated_space_
 Name of the option space being encapsulated by this option. More...
 
OptionCollection options_
 collection for storing suboptions More...
 
uint16_t type_
 option type (0-255 for DHCPv4, 0-65535 for DHCPv6) More...
 
Universe universe_
 option universe (V4 or V6) More...
 

Detailed Description

Class which represents an option carrying a single string value.

This class represents an option carrying a single string value. Currently this class imposes that the minimal length of the carried string is 1. Per RFC 2132, Sec 2 trailing NULLs are trimmed during either construction or unpacking.

Todo:
In the future this class may be extended with some more string content checks and encoding methods if required.

Definition at line 28 of file option_string.h.

Constructor & Destructor Documentation

◆ OptionString() [1/2]

isc::dhcp::OptionString::OptionString ( const Option::Universe  u,
const uint16_t  type,
const std::string &  value 
)

Constructor, used to create options to be sent.

This constructor creates an instance of option which carries a string value specified as constructor's parameter. This constructor is most often used to create an instance of an option which will be sent in the outgoing packet. Trailing NULLs will be trimmed.

Parameters
uuniverse (V4 or V6).
typeoption code.
valuea string value to be carried by the option.
Exceptions
isc::OutOfRangeif provided string is empty.

Definition at line 16 of file option_string.cc.

References setValue().

+ Here is the call graph for this function:

◆ OptionString() [2/2]

isc::dhcp::OptionString::OptionString ( const Option::Universe  u,
const uint16_t  type,
OptionBufferConstIter  begin,
OptionBufferConstIter  end 
)

Constructor, used for receiving options.

This constructor creates an instance of the option from the provided chunk of buffer. This buffer may hold the data received on the wire. Trailing NULLs will be trimmed.

Parameters
uuniverse (V4 or V6).
typeoption code.
beginiterator pointing to the first byte of the buffer chunk.
enditerator pointing to the last byte of the buffer chunk.
Exceptions
isc::OutOfRangeif provided buffer is truncated.

Definition at line 24 of file option_string.cc.

References unpack().

+ Here is the call graph for this function:

Member Function Documentation

◆ clone()

OptionPtr isc::dhcp::OptionString::clone ( ) const
virtual

Copies this option and returns a pointer to the copy.

Reimplemented from isc::dhcp::Option.

Definition at line 34 of file option_string.cc.

◆ getValue()

std::string isc::dhcp::OptionString::getValue ( ) const

Returns the string value held by the option.

Returns
string value held by the option.

Definition at line 39 of file option_string.cc.

References isc::dhcp::Option::getData().

Referenced by isc::dhcp::Dhcpv4Srv::processClientName(), toString(), and toText().

+ Here is the call graph for this function:

◆ len()

uint16_t isc::dhcp::OptionString::len ( ) const
virtual

Returns length of the whole option, including header.

Returns
length of the whole option.

Reimplemented from isc::dhcp::Option.

Definition at line 69 of file option_string.cc.

References isc::dhcp::Option::getData(), and isc::dhcp::Option::getHeaderLen().

+ Here is the call graph for this function:

◆ pack()

void isc::dhcp::OptionString::pack ( isc::util::OutputBuffer buf) const
virtual

Creates on-wire format of the option.

This function creates on-wire format of the option and appends it to the data existing in the provided buffer. The internal buffer's pointer is moved to the end of stored data.

Parameters
[out]bufoutput buffer where the option will be stored.

Reimplemented from isc::dhcp::Option.

Definition at line 74 of file option_string.cc.

References isc::dhcp::Option::getData(), isc::dhcp::Option::packHeader(), and isc::util::OutputBuffer::writeData().

+ Here is the call graph for this function:

◆ setValue()

void isc::dhcp::OptionString::setValue ( const std::string &  value)

Sets the string value to be held by the option.

Trailing NULLs will be trimmed.

Parameters
valuestring value to be set.
Exceptions
isc::OutOfRangeif a string value to be set is empty.

Definition at line 45 of file option_string.cc.

References isc::dhcp::Option::getType(), isc_throw, isc::util::str::seekTrimmed(), and isc::dhcp::Option::setData().

Referenced by OptionString().

+ Here is the call graph for this function:

◆ toString()

std::string isc::dhcp::OptionString::toString ( ) const
virtual

Returns actual value of the option in string format.

This method is used in client classification.

Returns
Content of the option.

Reimplemented from isc::dhcp::Option.

Definition at line 110 of file option_string.cc.

References getValue().

+ Here is the call graph for this function:

◆ toText()

std::string isc::dhcp::OptionString::toText ( int  indent = 0) const
virtual

Returns option information in the textual format.

Parameters
indentNumber of space characters to be inserted before the text.
Returns
Option information in the textual format.

Reimplemented from isc::dhcp::Option.

Definition at line 101 of file option_string.cc.

References getValue(), and isc::dhcp::Option::headerToText().

+ Here is the call graph for this function:

◆ unpack()

void isc::dhcp::OptionString::unpack ( OptionBufferConstIter  begin,
OptionBufferConstIter  end 
)
virtual

Decodes option data from the provided buffer.

This function decodes option data from the provided buffer. Note that it does not decode the option code and length, so the iterators must point to the beginning and end of the option payload respectively. The size of the decoded payload must be at least 1 byte. Trailing NULLs will be trimmed.

Parameters
beginthe iterator pointing to the option payload.
endthe iterator pointing to the end of the option payload.
Exceptions
isc::OutOfRangeif provided buffer is truncated.

Reimplemented from isc::dhcp::Option.

Definition at line 86 of file option_string.cc.

References isc::dhcp::Option::getType(), isc_throw, isc::util::str::seekTrimmed(), and isc::dhcp::Option::setData().

Referenced by OptionString().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: