diff options
author | Marcin Siodelski <marcin@isc.org> | 2016-06-24 10:31:55 +0200 |
---|---|---|
committer | Marcin Siodelski <marcin@isc.org> | 2016-07-08 07:50:19 +0200 |
commit | ee88ec857c21b9de5a2a45d3ca05d37c6696cf78 (patch) | |
tree | 4b624f577226399f74285cdd1f27909ca89f3e10 /src/lib/dhcp | |
parent | [master] Finished merge of trac4523 (vendor options in Renew and Rebind) (diff) | |
download | kea-ee88ec857c21b9de5a2a45d3ca05d37c6696cf78.tar.xz kea-ee88ec857c21b9de5a2a45d3ca05d37c6696cf78.zip |
[4497] Fix constness of methods in Option classes.
Diffstat (limited to 'src/lib/dhcp')
30 files changed, 129 insertions, 130 deletions
diff --git a/src/lib/dhcp/option.cc b/src/lib/dhcp/option.cc index b3f8786980..d91c4a411c 100644 --- a/src/lib/dhcp/option.cc +++ b/src/lib/dhcp/option.cc @@ -54,7 +54,7 @@ Option::Option(Universe u, uint16_t type, OptionBufferConstIter first, } void -Option::check() { +Option::check() const { if ( (universe_ != V4) && (universe_ != V6) ) { isc_throw(BadValue, "Invalid universe type specified. " << "Only V4 and V6 are allowed."); @@ -77,7 +77,7 @@ Option::check() { // both types and data size. } -void Option::pack(isc::util::OutputBuffer& buf) { +void Option::pack(isc::util::OutputBuffer& buf) const { // Write a header. packHeader(buf); // Write data. @@ -89,7 +89,7 @@ void Option::pack(isc::util::OutputBuffer& buf) { } void -Option::packHeader(isc::util::OutputBuffer& buf) { +Option::packHeader(isc::util::OutputBuffer& buf) const { if (universe_ == V4) { if (len() > 255) { isc_throw(OutOfRange, "DHCPv4 Option " << type_ << " is too big. " @@ -109,7 +109,7 @@ Option::packHeader(isc::util::OutputBuffer& buf) { } void -Option::packOptions(isc::util::OutputBuffer& buf) { +Option::packOptions(isc::util::OutputBuffer& buf) const { switch (universe_) { case V4: LibDHCP::packOptions4(buf, options_); @@ -141,7 +141,7 @@ Option::unpackOptions(const OptionBuffer& buf) { } } -uint16_t Option::len() { +uint16_t Option::len() const { // Returns length of the complete option (data length + DHCPv4/DHCPv6 // option header) @@ -149,7 +149,7 @@ uint16_t Option::len() { size_t length = getHeaderLen() + data_.size(); // ... and sum of lengths of all suboptions - for (OptionCollection::iterator it = options_.begin(); + for (OptionCollection::const_iterator it = options_.begin(); it != options_.end(); ++it) { length += (*it).second->len(); @@ -162,7 +162,7 @@ uint16_t Option::len() { } bool -Option::valid() { +Option::valid() const { if (universe_ != V4 && universe_ != V6) { return (false); @@ -171,7 +171,7 @@ Option::valid() { return (true); } -OptionPtr Option::getOption(uint16_t opt_type) { +OptionPtr Option::getOption(uint16_t opt_type) const { isc::dhcp::OptionCollection::const_iterator x = options_.find(opt_type); if ( x != options_.end() ) { @@ -190,7 +190,7 @@ bool Option::delOption(uint16_t opt_type) { } -std::string Option::toText(int indent) { +std::string Option::toText(int indent) const { std::stringstream output; output << headerToText(indent) << ": "; @@ -209,13 +209,13 @@ std::string Option::toText(int indent) { } std::string -Option::toString() { +Option::toString() const { /// @todo: Implement actual conversion in derived classes. return (toText(0)); } std::vector<uint8_t> -Option::toBinary(const bool include_header) { +Option::toBinary(const bool include_header) const { OutputBuffer buf(len()); try { // If the option is too long, exception will be thrown. We allow @@ -236,7 +236,7 @@ Option::toBinary(const bool include_header) { } std::string -Option::toHexString(const bool include_header) { +Option::toHexString(const bool include_header) const { // Prepare binary version of the option. std::vector<uint8_t> option_vec = toBinary(include_header); @@ -250,7 +250,7 @@ Option::toHexString(const bool include_header) { } std::string -Option::headerToText(const int indent, const std::string& type_name) { +Option::headerToText(const int indent, const std::string& type_name) const { std::stringstream output; for (int i = 0; i < indent; i++) output << " "; @@ -284,7 +284,7 @@ Option::suboptionsToText(const int indent) const { } uint16_t -Option::getHeaderLen() { +Option::getHeaderLen() const { switch (universe_) { case V4: return OPTION4_HDR_LEN; // header length for v4 @@ -305,7 +305,7 @@ void Option::addOption(OptionPtr opt) { options_.insert(make_pair(opt->getType(), opt)); } -uint8_t Option::getUint8() { +uint8_t Option::getUint8() const { if (data_.size() < sizeof(uint8_t) ) { isc_throw(OutOfRange, "Attempt to read uint8 from option " << type_ << " that has size " << data_.size()); @@ -313,12 +313,12 @@ uint8_t Option::getUint8() { return (data_[0]); } -uint16_t Option::getUint16() { +uint16_t Option::getUint16() const { // readUint16() checks and throws OutOfRange if data_ is too small. return (readUint16(&data_[0], data_.size())); } -uint32_t Option::getUint32() { +uint32_t Option::getUint32() const { // readUint32() checks and throws OutOfRange if data_ is too small. return (readUint32(&data_[0], data_.size())); } diff --git a/src/lib/dhcp/option.h b/src/lib/dhcp/option.h index 61eade0d64..181f28924a 100644 --- a/src/lib/dhcp/option.h +++ b/src/lib/dhcp/option.h @@ -158,7 +158,7 @@ public: /// @param buf pointer to a buffer /// /// @throw BadValue Universe of the option is neither V4 nor V6. - virtual void pack(isc::util::OutputBuffer& buf); + virtual void pack(isc::util::OutputBuffer& buf) const; /// @brief Parses received buffer. /// @@ -172,7 +172,7 @@ public: /// @param indent number of spaces before printing text /// /// @return string with text representation. - virtual std::string toText(int indent = 0); + virtual std::string toText(int indent = 0) const; /// @brief Returns string representation of the value /// @@ -180,7 +180,7 @@ public: /// refers to a specific option. /// /// @return string that represents the value of the option. - virtual std::string toString(); + virtual std::string toString() const; /// @brief Returns binary representation of the option. /// @@ -189,7 +189,7 @@ public: /// header fields. /// /// @return Vector holding binary representation of the option. - virtual std::vector<uint8_t> toBinary(const bool include_header = false); + virtual std::vector<uint8_t> toBinary(const bool include_header = false) const; /// @brief Returns string containing hexadecimal representation of option. /// @@ -198,7 +198,7 @@ public: /// header fields. /// /// @return String containing hexadecimal representation of the option. - virtual std::string toHexString(const bool include_header = false); + virtual std::string toHexString(const bool include_header = false) const; /// Returns option type (0-255 for DHCPv4, 0-65535 for DHCPv6) /// @@ -209,17 +209,17 @@ public: /// option header) /// /// @return length of the option - virtual uint16_t len(); + virtual uint16_t len() const; /// @brief Returns length of header (2 for v4, 4 for v6) /// /// @return length of option header - virtual uint16_t getHeaderLen(); + virtual uint16_t getHeaderLen() const; /// returns if option is valid (e.g. option may be truncated) /// /// @return true, if option is valid - virtual bool valid(); + virtual bool valid() const; /// Returns pointer to actual data. /// @@ -246,7 +246,7 @@ public: /// @param type type of requested suboption /// /// @return shared_ptr to requested suoption - OptionPtr getOption(uint16_t type); + OptionPtr getOption(uint16_t type) const; /// @brief Returns all encapsulated options. /// @@ -269,21 +269,21 @@ public: /// @throw isc::OutOfRange Thrown if the option has a length of 0. /// /// @return value of the first byte - uint8_t getUint8(); + uint8_t getUint8() const; /// @brief Returns content of first word. /// /// @throw isc::OutOfRange Thrown if the option has a length less than 2. /// /// @return uint16_t value stored on first two bytes - uint16_t getUint16(); + uint16_t getUint16() const; /// @brief Returns content of first double word. /// /// @throw isc::OutOfRange Thrown if the option has a length less than 4. /// /// @return uint32_t value stored on first four bytes - uint32_t getUint32(); + uint32_t getUint32() const; /// @brief Sets content of this option to singe uint8 value. /// @@ -378,7 +378,7 @@ protected: /// directly by other classes. /// /// @param [out] buf output buffer. - void packHeader(isc::util::OutputBuffer& buf); + void packHeader(isc::util::OutputBuffer& buf) const; /// @brief Store sub options in a buffer. /// @@ -393,7 +393,7 @@ protected: /// exceptions thrown by pack methods invoked on objects /// representing sub options. We should consider whether to aggregate /// those into one exception which can be documented here. - void packOptions(isc::util::OutputBuffer& buf); + void packOptions(isc::util::OutputBuffer& buf) const; /// @brief Builds a collection of sub options from the buffer. /// @@ -420,7 +420,7 @@ protected: /// /// @return Option header in the textual format. std::string headerToText(const int indent = 0, - const std::string& type_name = ""); + const std::string& type_name = "") const; /// @brief Returns collection of suboptions in the textual format. /// @@ -441,7 +441,7 @@ protected: /// It is used in constructors. In there are any problems detected /// (like specifying type > 255 for DHCPv4 option), it will throw /// BadValue or OutOfRange exceptions. - void check(); + void check() const; /// option universe (V4 or V6) Universe universe_; diff --git a/src/lib/dhcp/option4_addrlst.cc b/src/lib/dhcp/option4_addrlst.cc index 8e24c5e0ca..981fe8dc75 100644 --- a/src/lib/dhcp/option4_addrlst.cc +++ b/src/lib/dhcp/option4_addrlst.cc @@ -56,7 +56,7 @@ Option4AddrLst::Option4AddrLst(uint8_t type, const IOAddress& addr) } void -Option4AddrLst::pack(isc::util::OutputBuffer& buf) { +Option4AddrLst::pack(isc::util::OutputBuffer& buf) const { if (addrs_.size() * V4ADDRESS_LEN > 255) { isc_throw(OutOfRange, "DHCPv4 Option4AddrLst " << type_ << " is too big." @@ -106,13 +106,13 @@ void Option4AddrLst::addAddress(const isc::asiolink::IOAddress& addr) { addrs_.push_back(addr); } -uint16_t Option4AddrLst::len() { +uint16_t Option4AddrLst::len() const { // Returns length of the complete option (option header + data length) return (getHeaderLen() + addrs_.size() * V4ADDRESS_LEN); } -std::string Option4AddrLst::toText(int indent) { +std::string Option4AddrLst::toText(int indent) const { std::stringstream output; output << headerToText(indent) << ":"; diff --git a/src/lib/dhcp/option4_addrlst.h b/src/lib/dhcp/option4_addrlst.h index 2a4f41cd79..02777569f2 100644 --- a/src/lib/dhcp/option4_addrlst.h +++ b/src/lib/dhcp/option4_addrlst.h @@ -85,20 +85,20 @@ public: /// Method will throw if option storing fails for some reason. /// /// @param buf output buffer (option will be stored there) - virtual void pack(isc::util::OutputBuffer& buf); + virtual void pack(isc::util::OutputBuffer& buf) const; /// Returns string representation of the option. /// /// @param indent number of spaces before printing text /// /// @return string with text representation. - virtual std::string toText(int indent = 0); + virtual std::string toText(int indent = 0) const; /// Returns length of the complete option (data length + DHCPv4/DHCPv6 /// option header) /// /// @return length of the option - virtual uint16_t len(); + virtual uint16_t len() const; /// @brief Returns vector with addresses. /// diff --git a/src/lib/dhcp/option4_client_fqdn.cc b/src/lib/dhcp/option4_client_fqdn.cc index 3fda78635e..5dd571bceb 100644 --- a/src/lib/dhcp/option4_client_fqdn.cc +++ b/src/lib/dhcp/option4_client_fqdn.cc @@ -463,7 +463,7 @@ Option4ClientFqdn::getDomainNameType() const { } void -Option4ClientFqdn::pack(isc::util::OutputBuffer& buf) { +Option4ClientFqdn::pack(isc::util::OutputBuffer& buf) const { // Header = option code and length. packHeader(buf); // Flags field. @@ -487,7 +487,7 @@ Option4ClientFqdn::unpack(OptionBufferConstIter first, } std::string -Option4ClientFqdn::toText(int indent) { +Option4ClientFqdn::toText(int indent) const { std::ostringstream stream; std::string in(indent, ' '); // base indentation stream << in << "type=" << type_ << " (CLIENT_FQDN), " @@ -504,7 +504,7 @@ Option4ClientFqdn::toText(int indent) { } uint16_t -Option4ClientFqdn::len() { +Option4ClientFqdn::len() const { uint16_t domain_name_length = 0; // Try to calculate the length of the domain name only if there is // any domain name specified. diff --git a/src/lib/dhcp/option4_client_fqdn.h b/src/lib/dhcp/option4_client_fqdn.h index f59bc4ecd1..c23bb8ecc7 100644 --- a/src/lib/dhcp/option4_client_fqdn.h +++ b/src/lib/dhcp/option4_client_fqdn.h @@ -299,7 +299,7 @@ public: /// @brief Writes option in the wire format into a buffer. /// /// @param [out] buf output buffer where option data will be stored. - virtual void pack(isc::util::OutputBuffer& buf); + virtual void pack(isc::util::OutputBuffer& buf) const; /// @brief Parses option from the received buffer. /// @@ -322,13 +322,13 @@ public: /// @param indent number of spaces before printed text. /// /// @return string with text representation. - virtual std::string toText(int indent = 0); + virtual std::string toText(int indent = 0) const; /// @brief Returns length of the complete option (data length + /// DHCPv4 option header). /// /// @return length of the option. - virtual uint16_t len(); + virtual uint16_t len() const; /// /// @name Well known Rcode declarations for DHCPv4 Client FQDN %Option diff --git a/src/lib/dhcp/option6_addrlst.cc b/src/lib/dhcp/option6_addrlst.cc index 5547187eae..f71537c254 100644 --- a/src/lib/dhcp/option6_addrlst.cc +++ b/src/lib/dhcp/option6_addrlst.cc @@ -56,7 +56,7 @@ Option6AddrLst::setAddresses(const AddressContainer& addrs) { addrs_ = addrs; } -void Option6AddrLst::pack(isc::util::OutputBuffer& buf) { +void Option6AddrLst::pack(isc::util::OutputBuffer& buf) const { buf.writeUint16(type_); @@ -89,7 +89,7 @@ void Option6AddrLst::unpack(OptionBufferConstIter begin, } } -std::string Option6AddrLst::toText(int indent) { +std::string Option6AddrLst::toText(int indent) const { stringstream output; output << headerToText(indent) << ":"; @@ -100,7 +100,7 @@ std::string Option6AddrLst::toText(int indent) { return (output.str()); } -uint16_t Option6AddrLst::len() { +uint16_t Option6AddrLst::len() const { return (OPTION6_HDR_LEN + addrs_.size() * V6ADDRESS_LEN); } diff --git a/src/lib/dhcp/option6_addrlst.h b/src/lib/dhcp/option6_addrlst.h index da6475d3eb..0b22a1b4f8 100644 --- a/src/lib/dhcp/option6_addrlst.h +++ b/src/lib/dhcp/option6_addrlst.h @@ -48,7 +48,7 @@ public: /// @brief Assembles on-wire form of this option /// /// @param buf pointer to packet buffer - void pack(isc::util::OutputBuffer& buf); + void pack(isc::util::OutputBuffer& buf) const; /// @brief Parses received data /// @@ -57,7 +57,7 @@ public: virtual void unpack(OptionBufferConstIter begin, OptionBufferConstIter end); - virtual std::string toText(int indent = 0); + virtual std::string toText(int indent = 0) const; /// @brief Sets a single address. /// @@ -80,7 +80,7 @@ public: AddressContainer getAddresses() const { return addrs_; }; // returns data length (data length + DHCPv4/DHCPv6 option header) - virtual uint16_t len(); + virtual uint16_t len() const; protected: AddressContainer addrs_; diff --git a/src/lib/dhcp/option6_client_fqdn.cc b/src/lib/dhcp/option6_client_fqdn.cc index cad4282254..020f8efe24 100644 --- a/src/lib/dhcp/option6_client_fqdn.cc +++ b/src/lib/dhcp/option6_client_fqdn.cc @@ -395,7 +395,7 @@ Option6ClientFqdn::getDomainNameType() const { } void -Option6ClientFqdn::pack(isc::util::OutputBuffer& buf) { +Option6ClientFqdn::pack(isc::util::OutputBuffer& buf) const { // Header = option code and length. packHeader(buf); // Flags field. @@ -416,7 +416,7 @@ Option6ClientFqdn::unpack(OptionBufferConstIter first, } std::string -Option6ClientFqdn::toText(int indent) { +Option6ClientFqdn::toText(int indent) const { std::ostringstream stream; std::string in(indent, ' '); // base indentation stream << in << "type=" << type_ << "(CLIENT_FQDN)" << ", " @@ -432,7 +432,7 @@ Option6ClientFqdn::toText(int indent) { } uint16_t -Option6ClientFqdn::len() { +Option6ClientFqdn::len() const { uint16_t domain_name_length = 0; if (impl_->domain_name_) { // If domain name is partial, the NULL terminating character diff --git a/src/lib/dhcp/option6_client_fqdn.h b/src/lib/dhcp/option6_client_fqdn.h index fae7b312f0..3f7d5f6c9c 100644 --- a/src/lib/dhcp/option6_client_fqdn.h +++ b/src/lib/dhcp/option6_client_fqdn.h @@ -217,7 +217,7 @@ public: /// @brief Writes option in the wire format into a buffer. /// /// @param [out] buf output buffer where option data will be stored. - virtual void pack(isc::util::OutputBuffer& buf); + virtual void pack(isc::util::OutputBuffer& buf) const; /// @brief Parses option from the received buffer. /// @@ -240,13 +240,13 @@ public: /// @param indent number of spaces before printed text. /// /// @return string with text representation. - virtual std::string toText(int indent = 0); + virtual std::string toText(int indent = 0) const; /// @brief Returns length of the complete option (data length + /// DHCPv6 option header). /// /// @return length of the option. - virtual uint16_t len(); + virtual uint16_t len() const; private: diff --git a/src/lib/dhcp/option6_ia.cc b/src/lib/dhcp/option6_ia.cc index ccb4d82425..bfcce7e244 100644 --- a/src/lib/dhcp/option6_ia.cc +++ b/src/lib/dhcp/option6_ia.cc @@ -48,7 +48,7 @@ Option6IA::Option6IA(uint16_t type, OptionBufferConstIter begin, unpack(begin, end); } -void Option6IA::pack(isc::util::OutputBuffer& buf) { +void Option6IA::pack(isc::util::OutputBuffer& buf) const { buf.writeUint16(type_); buf.writeUint16(len() - OPTION6_HDR_LEN); buf.writeUint32(iaid_); @@ -76,7 +76,7 @@ void Option6IA::unpack(OptionBufferConstIter begin, unpackOptions(OptionBuffer(begin, end)); } -std::string Option6IA::toText(int indent) { +std::string Option6IA::toText(int indent) const { stringstream output; switch(getType()) { @@ -96,13 +96,13 @@ std::string Option6IA::toText(int indent) { return (output.str()); } -uint16_t Option6IA::len() { +uint16_t Option6IA::len() const { uint16_t length = OPTION6_HDR_LEN /*header (4)*/ + OPTION6_IA_LEN /* option content (12) */; // length of all suboptions - for (OptionCollection::iterator it = options_.begin(); + for (OptionCollection::const_iterator it = options_.begin(); it != options_.end(); ++it) { length += (*it).second->len(); diff --git a/src/lib/dhcp/option6_ia.h b/src/lib/dhcp/option6_ia.h index bd49c36fdb..315b6ff3ef 100644 --- a/src/lib/dhcp/option6_ia.h +++ b/src/lib/dhcp/option6_ia.h @@ -43,7 +43,7 @@ public: /// byte after stored option. /// /// @param buf buffer (option will be stored here) - void pack(isc::util::OutputBuffer& buf); + void pack(isc::util::OutputBuffer& buf) const; /// @brief Parses received buffer /// @@ -59,8 +59,7 @@ public: /// @param indent number of leading space characters /// /// @return string with text represenation - virtual std::string - toText(int indent = 0); + virtual std::string toText(int indent = 0) const; /// Sets T1 timer. /// @@ -98,7 +97,7 @@ public: /// Returns length of this option, including option header and suboptions /// /// @return length of this option - virtual uint16_t len(); + virtual uint16_t len() const; protected: diff --git a/src/lib/dhcp/option6_iaaddr.cc b/src/lib/dhcp/option6_iaaddr.cc index c360889535..4f6812130d 100644 --- a/src/lib/dhcp/option6_iaaddr.cc +++ b/src/lib/dhcp/option6_iaaddr.cc @@ -42,7 +42,7 @@ Option6IAAddr::Option6IAAddr(uint32_t type, OptionBuffer::const_iterator begin, unpack(begin, end); } -void Option6IAAddr::pack(isc::util::OutputBuffer& buf) { +void Option6IAAddr::pack(isc::util::OutputBuffer& buf) const { buf.writeUint16(type_); @@ -81,7 +81,7 @@ void Option6IAAddr::unpack(OptionBuffer::const_iterator begin, unpackOptions(OptionBuffer(begin, end)); } -std::string Option6IAAddr::toText(int indent) { +std::string Option6IAAddr::toText(int indent) const { std::stringstream output; output << headerToText(indent, "IAADDR") << ": " << "address=" << addr_ @@ -92,14 +92,14 @@ std::string Option6IAAddr::toText(int indent) { return (output.str()); } -uint16_t Option6IAAddr::len() { +uint16_t Option6IAAddr::len() const { uint16_t length = OPTION6_HDR_LEN + OPTION6_IAADDR_LEN; // length of all suboptions // TODO implement: // protected: unsigned short Option::lenHelper(int header_size); - for (OptionCollection::iterator it = options_.begin(); + for (OptionCollection::const_iterator it = options_.begin(); it != options_.end(); ++it) { length += (*it).second->len(); diff --git a/src/lib/dhcp/option6_iaaddr.h b/src/lib/dhcp/option6_iaaddr.h index 83996581b3..1425a4ce1f 100644 --- a/src/lib/dhcp/option6_iaaddr.h +++ b/src/lib/dhcp/option6_iaaddr.h @@ -52,7 +52,7 @@ public: /// byte after stored option. /// /// @param buf pointer to a buffer - void pack(isc::util::OutputBuffer& buf); + void pack(isc::util::OutputBuffer& buf) const; /// @brief Parses received buffer. /// @@ -67,7 +67,7 @@ public: /// /// @return string with text representation. virtual std::string - toText(int indent = 0); + toText(int indent = 0) const; /// sets address in this option. @@ -106,7 +106,7 @@ public: getValid() const { return valid_; } /// returns data length (data length + DHCPv4/DHCPv6 option header) - virtual uint16_t len(); + virtual uint16_t len() const; protected: /// contains an IPv6 address diff --git a/src/lib/dhcp/option6_iaprefix.cc b/src/lib/dhcp/option6_iaprefix.cc index b61bd88dcb..5b96247169 100644 --- a/src/lib/dhcp/option6_iaprefix.cc +++ b/src/lib/dhcp/option6_iaprefix.cc @@ -44,7 +44,7 @@ Option6IAPrefix::Option6IAPrefix(uint32_t type, OptionBuffer::const_iterator beg unpack(begin, end); } -void Option6IAPrefix::pack(isc::util::OutputBuffer& buf) { +void Option6IAPrefix::pack(isc::util::OutputBuffer& buf) const { if (!addr_.isV6()) { isc_throw(isc::BadValue, addr_ << " is not an IPv6 address"); } @@ -90,7 +90,7 @@ void Option6IAPrefix::unpack(OptionBuffer::const_iterator begin, unpackOptions(OptionBuffer(begin, end)); } -std::string Option6IAPrefix::toText(int indent) { +std::string Option6IAPrefix::toText(int indent) const { std::stringstream output; output << headerToText(indent, "IAPREFIX") << ": " << "prefix=" << addr_ << "/" << static_cast<int>(prefix_len_) @@ -101,7 +101,7 @@ std::string Option6IAPrefix::toText(int indent) { return (output.str()); } -uint16_t Option6IAPrefix::len() { +uint16_t Option6IAPrefix::len() const { uint16_t length = OPTION6_HDR_LEN + OPTION6_IAPREFIX_LEN; @@ -117,7 +117,7 @@ void Option6IAPrefix::mask(OptionBuffer::const_iterator begin, OptionBuffer::const_iterator end, const uint8_t len, - OptionBuffer& output_address) { + OptionBuffer& output_address) const { output_address.resize(16, 0); if (len >= 128) { std::copy(begin, end, output_address.begin()); diff --git a/src/lib/dhcp/option6_iaprefix.h b/src/lib/dhcp/option6_iaprefix.h index d15786b03e..e6c588d5e9 100644 --- a/src/lib/dhcp/option6_iaprefix.h +++ b/src/lib/dhcp/option6_iaprefix.h @@ -82,7 +82,7 @@ public: /// @throw BadValue if the address is not IPv6 /// /// @param buf pointer to a buffer - void pack(isc::util::OutputBuffer& buf); + void pack(isc::util::OutputBuffer& buf) const; /// @brief Parses received buffer. /// @@ -103,7 +103,7 @@ public: /// @param indent number of spaces before printing text /// /// @return string with text representation. - virtual std::string toText(int indent = 0); + virtual std::string toText(int indent = 0) const; /// sets address in this option. /// @@ -115,7 +115,7 @@ public: uint8_t getLength() const { return prefix_len_; } /// returns data length (data length + DHCPv4/DHCPv6 option header) - virtual uint16_t len(); + virtual uint16_t len() const; private: @@ -130,7 +130,7 @@ private: void mask(OptionBuffer::const_iterator begin, OptionBuffer::const_iterator end, const uint8_t len, - OptionBuffer& output_address); + OptionBuffer& output_address) const; uint8_t prefix_len_; }; diff --git a/src/lib/dhcp/option6_status_code.cc b/src/lib/dhcp/option6_status_code.cc index 5277843ff2..e46315839f 100644 --- a/src/lib/dhcp/option6_status_code.cc +++ b/src/lib/dhcp/option6_status_code.cc @@ -41,7 +41,7 @@ Option6StatusCode::Option6StatusCode(OptionBufferConstIter begin, } void -Option6StatusCode::pack(isc::util::OutputBuffer& buf) { +Option6StatusCode::pack(isc::util::OutputBuffer& buf) const { // Pack option header. packHeader(buf); // Write numeric status code. @@ -69,12 +69,12 @@ Option6StatusCode::unpack(OptionBufferConstIter begin, OptionBufferConstIter end } uint16_t -Option6StatusCode::len() { +Option6StatusCode::len() const { return (getHeaderLen() + sizeof(uint16_t) + status_message_.size()); } std::string -Option6StatusCode::toText(int indent) { +Option6StatusCode::toText(int indent) const { std::ostringstream output; output << headerToText(indent) << ": " << dataToText(); diff --git a/src/lib/dhcp/option6_status_code.h b/src/lib/dhcp/option6_status_code.h index 028cf2609f..c022c59e43 100644 --- a/src/lib/dhcp/option6_status_code.h +++ b/src/lib/dhcp/option6_status_code.h @@ -43,7 +43,7 @@ public: /// byte after stored option. /// /// @param [out] buf Pointer to the output buffer. - virtual void pack(isc::util::OutputBuffer& buf); + virtual void pack(isc::util::OutputBuffer& buf) const; /// @brief Parses received buffer. /// @@ -54,12 +54,12 @@ public: /// @brief Returns total length of the option. /// /// The returned length is a sum of the option header and data fields. - virtual uint16_t len(); + virtual uint16_t len() const; /// @brief Returns textual representation of the option. /// /// @param indent Number of spaces before printing text. - virtual std::string toText(int indent = 0); + virtual std::string toText(int indent = 0) const; /// @brief Returns textual representation of the option data. /// diff --git a/src/lib/dhcp/option_custom.cc b/src/lib/dhcp/option_custom.cc index 79d0aca57e..1d99da7449 100644 --- a/src/lib/dhcp/option_custom.cc +++ b/src/lib/dhcp/option_custom.cc @@ -357,7 +357,7 @@ OptionCustom::dataFieldToText(const OptionDataType data_type, } void -OptionCustom::pack(isc::util::OutputBuffer& buf) { +OptionCustom::pack(isc::util::OutputBuffer& buf) const { // Pack DHCP header (V4 or V6). packHeader(buf); @@ -494,7 +494,7 @@ OptionCustom::unpack(OptionBufferConstIter begin, } uint16_t -OptionCustom::len() { +OptionCustom::len() const { // The length of the option is a sum of option header ... size_t length = getHeaderLen(); @@ -505,7 +505,7 @@ OptionCustom::len() { } // ... and lengths of all suboptions - for (OptionCollection::iterator it = options_.begin(); + for (OptionCollection::const_iterator it = options_.begin(); it != options_.end(); ++it) { length += (*it).second->len(); @@ -523,7 +523,7 @@ void OptionCustom::initialize(const OptionBufferConstIter first, createBuffers(getData()); } -std::string OptionCustom::toText(int indent) { +std::string OptionCustom::toText(int indent) const { std::stringstream output; output << headerToText(indent) << ":"; diff --git a/src/lib/dhcp/option_custom.h b/src/lib/dhcp/option_custom.h index d3e0147afc..e766ebef18 100644 --- a/src/lib/dhcp/option_custom.h +++ b/src/lib/dhcp/option_custom.h @@ -243,7 +243,7 @@ public: /// @brief Writes DHCP option in a wire format to a buffer. /// /// @param buf output buffer (option will be stored there). - virtual void pack(isc::util::OutputBuffer& buf); + virtual void pack(isc::util::OutputBuffer& buf) const; /// @brief Parses received buffer. /// @@ -257,13 +257,13 @@ public: /// @param indent number of spaces before printed text. /// /// @return string with text representation. - virtual std::string toText(int indent = 0); + virtual std::string toText(int indent = 0) const; /// @brief Returns length of the complete option (data length + /// DHCPv4/DHCPv6 option header) /// /// @return length of the option - virtual uint16_t len(); + virtual uint16_t len() const; /// @brief Sets content of this option from buffer. /// diff --git a/src/lib/dhcp/option_int.h b/src/lib/dhcp/option_int.h index 868ee3ca58..2aa81ecbc8 100644 --- a/src/lib/dhcp/option_int.h +++ b/src/lib/dhcp/option_int.h @@ -98,7 +98,7 @@ public: /// @throw isc::dhcp::InvalidDataType if size of a data field type is not /// equal to 1, 2 or 4 bytes. The data type is not checked in this function /// because it is checked in a constructor. - void pack(isc::util::OutputBuffer& buf) { + void pack(isc::util::OutputBuffer& buf) const { // Pack option header. packHeader(buf); // Depending on the data type length we use different utility functions @@ -184,13 +184,13 @@ public: /// Returns length of this option, including option header and suboptions /// /// @return length of this option - virtual uint16_t len() { + virtual uint16_t len() const { // Calculate the length of the header. uint16_t length = (getUniverse() == Option::V4) ? OPTION4_HDR_LEN : OPTION6_HDR_LEN; // The data length is equal to size of T. length += sizeof(T);; // length of all suboptions - for (OptionCollection::iterator it = options_.begin(); + for (OptionCollection::const_iterator it = options_.begin(); it != options_.end(); ++it) { length += (*it).second->len(); @@ -204,7 +204,7 @@ public: /// The returned value also includes the suboptions if present. /// /// @param indent Number of spaces to be inserted before the text. - virtual std::string toText(int indent = 0) { + virtual std::string toText(int indent = 0) const { std::stringstream output; output << headerToText(indent) << ": "; diff --git a/src/lib/dhcp/option_int_array.h b/src/lib/dhcp/option_int_array.h index 6ed029db95..d8a533ab7f 100644 --- a/src/lib/dhcp/option_int_array.h +++ b/src/lib/dhcp/option_int_array.h @@ -131,7 +131,7 @@ public: /// @throw isc::dhcp::InvalidDataType if size of a data fields type is not /// equal to 1, 2 or 4 bytes. The data type is not checked in this function /// because it is checked in a constructor. - void pack(isc::util::OutputBuffer& buf) { + void pack(isc::util::OutputBuffer& buf) const { // Pack option header. packHeader(buf); // Pack option data. @@ -229,11 +229,11 @@ public: /// Returns length of this option, including option header and suboptions /// /// @return length of this option - virtual uint16_t len() { + virtual uint16_t len() const { uint16_t length = (getUniverse() == Option::V4) ? OPTION4_HDR_LEN : OPTION6_HDR_LEN; length += values_.size() * sizeof(T); // length of all suboptions - for (OptionCollection::iterator it = options_.begin(); + for (OptionCollection::const_iterator it = options_.begin(); it != options_.end(); ++it) { length += (*it).second->len(); @@ -247,7 +247,7 @@ public: /// the text. /// /// @return textual representation of the option. - virtual std::string toText(int indent = 0) { + virtual std::string toText(int indent = 0) const { std::stringstream output; output << headerToText(indent) << ":"; diff --git a/src/lib/dhcp/option_opaque_data_tuples.cc b/src/lib/dhcp/option_opaque_data_tuples.cc index 1358b6c2d3..28a4a5982a 100644 --- a/src/lib/dhcp/option_opaque_data_tuples.cc +++ b/src/lib/dhcp/option_opaque_data_tuples.cc @@ -26,7 +26,7 @@ OptionOpaqueDataTuples::OptionOpaqueDataTuples(Option::Universe u, } void -OptionOpaqueDataTuples::pack(isc::util::OutputBuffer& buf) { +OptionOpaqueDataTuples::pack(isc::util::OutputBuffer& buf) const { packHeader(buf); for (TuplesCollection::const_iterator it = tuples_.begin(); @@ -107,7 +107,7 @@ OptionOpaqueDataTuples::hasTuple(const std::string& tuple_str) const { } uint16_t -OptionOpaqueDataTuples::len() { +OptionOpaqueDataTuples::len() const { // The option starts with the header. uint16_t length = getHeaderLen(); // Now iterate over existing tuples and add their size. @@ -120,7 +120,7 @@ OptionOpaqueDataTuples::len() { } std::string -OptionOpaqueDataTuples::toText(int indent) { +OptionOpaqueDataTuples::toText(int indent) const { std::ostringstream s; // Apply indentation diff --git a/src/lib/dhcp/option_opaque_data_tuples.h b/src/lib/dhcp/option_opaque_data_tuples.h index e6016dccbc..18b977c5e5 100644 --- a/src/lib/dhcp/option_opaque_data_tuples.h +++ b/src/lib/dhcp/option_opaque_data_tuples.h @@ -65,7 +65,7 @@ public: /// @brief Renders option into the buffer in the wire format. /// /// @param [out] buf Buffer to which the option is rendered. - virtual void pack(isc::util::OutputBuffer& buf); + virtual void pack(isc::util::OutputBuffer& buf) const; /// @brief Parses buffer holding an option. /// @@ -123,13 +123,13 @@ public: bool hasTuple(const std::string& tuple_str) const; /// @brief Returns the full length of the option, including option header. - virtual uint16_t len(); + virtual uint16_t len() const; /// @brief Returns text representation of the option. /// /// @param indent Number of space characters before text. /// @return Text representation of the option. - virtual std::string toText(int indent = 0); + virtual std::string toText(int indent = 0) const; private: diff --git a/src/lib/dhcp/option_string.cc b/src/lib/dhcp/option_string.cc index c875143217..4e8e6b3a3d 100644 --- a/src/lib/dhcp/option_string.cc +++ b/src/lib/dhcp/option_string.cc @@ -48,12 +48,12 @@ OptionString::setValue(const std::string& value) { uint16_t -OptionString::len() { +OptionString::len() const { return (getHeaderLen() + getData().size()); } void -OptionString::pack(isc::util::OutputBuffer& buf) { +OptionString::pack(isc::util::OutputBuffer& buf) const { // Pack option header. packHeader(buf); // Pack data. @@ -76,7 +76,7 @@ OptionString::unpack(OptionBufferConstIter begin, } std::string -OptionString::toText(int indent) { +OptionString::toText(int indent) const { std::ostringstream output; output << headerToText(indent) << ": " << "\"" << getValue() << "\" (string)"; @@ -85,7 +85,7 @@ OptionString::toText(int indent) { } std::string -OptionString::toString() { +OptionString::toString() const { return (getValue()); } diff --git a/src/lib/dhcp/option_string.h b/src/lib/dhcp/option_string.h index 147251d4fa..d3a8f83b0d 100644 --- a/src/lib/dhcp/option_string.h +++ b/src/lib/dhcp/option_string.h @@ -59,7 +59,7 @@ public: /// @brief Returns length of the whole option, including header. /// /// @return length of the whole option. - virtual uint16_t len(); + virtual uint16_t len() const; /// @brief Returns the string value held by the option. /// @@ -80,7 +80,7 @@ public: /// is moved to the end of stored data. /// /// @param [out] buf output buffer where the option will be stored. - virtual void pack(isc::util::OutputBuffer& buf); + virtual void pack(isc::util::OutputBuffer& buf) const; /// @brief Decodes option data from the provided buffer. /// @@ -101,13 +101,13 @@ public: /// the text. /// /// @return Option information in the textual format. - virtual std::string toText(int indent = 0); + virtual std::string toText(int indent = 0) const; /// @brief Returns actual value of the option in string format. /// /// This method is used in client classification. /// @return Content of the option. - virtual std::string toString(); + virtual std::string toString() const; }; /// Pointer to the OptionString object. diff --git a/src/lib/dhcp/option_vendor.cc b/src/lib/dhcp/option_vendor.cc index 210abac8b0..dd85a2793c 100644 --- a/src/lib/dhcp/option_vendor.cc +++ b/src/lib/dhcp/option_vendor.cc @@ -24,7 +24,7 @@ OptionVendor::OptionVendor(Option::Universe u, OptionBufferConstIter begin, } -void OptionVendor::pack(isc::util::OutputBuffer& buf) { +void OptionVendor::pack(isc::util::OutputBuffer& buf) const { packHeader(buf); // Store vendor-id @@ -59,7 +59,7 @@ void OptionVendor::unpack(OptionBufferConstIter begin, } } -uint16_t OptionVendor::len() { +uint16_t OptionVendor::len() const { uint16_t length = getHeaderLen(); length += sizeof(uint32_t); // Vendor-id field @@ -70,7 +70,7 @@ uint16_t OptionVendor::len() { } // length of all suboptions - for (OptionCollection::iterator it = options_.begin(); + for (OptionCollection::const_iterator it = options_.begin(); it != options_.end(); ++it) { length += (*it).second->len(); @@ -79,7 +79,7 @@ uint16_t OptionVendor::len() { } uint8_t -OptionVendor::dataLen() { +OptionVendor::dataLen() const { // Calculate and store data-len as follows: // data-len = total option length - header length // - enterprise id field length - data-len field size @@ -87,7 +87,7 @@ OptionVendor::dataLen() { } std::string -OptionVendor::toText(int indent) { +OptionVendor::toText(int indent) const { std::stringstream output; output << headerToText(indent) << ": " << getVendorId() << " (uint32)"; diff --git a/src/lib/dhcp/option_vendor.h b/src/lib/dhcp/option_vendor.h index 47fb194022..a0b5b1734e 100644 --- a/src/lib/dhcp/option_vendor.h +++ b/src/lib/dhcp/option_vendor.h @@ -54,7 +54,7 @@ public: /// unused byte after stored option. /// /// @param [out] buf buffer (option will be stored here) - virtual void pack(isc::util::OutputBuffer& buf); + virtual void pack(isc::util::OutputBuffer& buf) const; /// @brief Parses received buffer /// @@ -82,14 +82,14 @@ public: /// Returns length of this option, including option header and suboptions /// /// @return length of this option - virtual uint16_t len(); + virtual uint16_t len() const; /// @brief Returns the option in the textual format. /// /// @param indent Number of spaces to be inserted before the text. /// /// @return Vendor option in the textual format. - virtual std::string toText(int indent = 0); + virtual std::string toText(int indent = 0) const; private: @@ -101,7 +101,7 @@ private: /// this value. /// /// @return Returns calculated data-len value. - uint8_t dataLen(); + uint8_t dataLen() const; uint32_t vendor_id_; ///< Enterprise-id }; diff --git a/src/lib/dhcp/option_vendor_class.cc b/src/lib/dhcp/option_vendor_class.cc index b3db4641f0..7ecf5d1e4f 100644 --- a/src/lib/dhcp/option_vendor_class.cc +++ b/src/lib/dhcp/option_vendor_class.cc @@ -28,7 +28,7 @@ OptionVendorClass::OptionVendorClass(Option::Universe u, } void -OptionVendorClass::pack(isc::util::OutputBuffer& buf) { +OptionVendorClass::pack(isc::util::OutputBuffer& buf) const { packHeader(buf); buf.writeUint32(getVendorId()); @@ -138,7 +138,7 @@ OptionVendorClass::hasTuple(const std::string& tuple_str) const { uint16_t -OptionVendorClass::len() { +OptionVendorClass::len() const { // The option starts with the header and enterprise id. uint16_t length = getHeaderLen() + sizeof(uint32_t); // Now iterate over existing tuples and add their size. @@ -157,7 +157,7 @@ OptionVendorClass::len() { } std::string -OptionVendorClass::toText(int indent) { +OptionVendorClass::toText(int indent) const { std::ostringstream s; // Apply indentation diff --git a/src/lib/dhcp/option_vendor_class.h b/src/lib/dhcp/option_vendor_class.h index 33b76d9606..2018c838fd 100644 --- a/src/lib/dhcp/option_vendor_class.h +++ b/src/lib/dhcp/option_vendor_class.h @@ -72,7 +72,7 @@ public: /// @brief Renders option into the buffer in the wire format. /// /// @param [out] buf Buffer to which the option is rendered. - virtual void pack(isc::util::OutputBuffer& buf); + virtual void pack(isc::util::OutputBuffer& buf) const; /// @brief Parses buffer holding an option. /// @@ -135,13 +135,13 @@ public: bool hasTuple(const std::string& tuple_str) const; /// @brief Returns the full length of the option, including option header. - virtual uint16_t len(); + virtual uint16_t len() const; /// @brief Returns text representation of the option. /// /// @param indent Number of space characters before text. /// @return Text representation of the option. - virtual std::string toText(int indent = 0); + virtual std::string toText(int indent = 0) const; private: |