1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright (C) 2013-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef OPTION_STRING_H
#define OPTION_STRING_H

#include <dhcp/option.h>
#include <util/buffer.h>

#include <boost/shared_ptr.hpp><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <string><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace isc {
namespace dhcp {

/// @brief 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.
class OptionString : public Option {
public:

    /// @brief 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.
    ///
    /// @param u universe (V4 or V6).
    /// @param type option code.
    /// @param value a string value to be carried by the option.
    ///
    /// @throw isc::OutOfRange if provided string is empty.
    OptionString(const Option::Universe u, const uint16_t type,
                 const std::string& value);

    /// @brief 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.
    ///
    /// @param u universe (V4 or V6).
    /// @param type option code.
    /// @param begin iterator pointing to the first byte of the buffer chunk.
    /// @param end iterator pointing to the last byte of the buffer chunk.
    ///
    /// @throw isc::OutOfRange if provided buffer is truncated.
    OptionString(const Option::Universe u, const uint16_t type,
                 OptionBufferConstIter begin, OptionBufferConstIter end);

    /// @brief Copies this option and returns a pointer to the copy.
    OptionPtr clone() const;<--- Derived function 'OptionString::clone'

    /// @brief Returns length of the whole option, including header.
    ///
    /// @return length of the whole option.
    virtual uint16_t len() const;<--- Function in derived class

    /// @brief Returns the string value held by the option.
    ///
    /// @return string value held by the option.
    std::string getValue() const;

    /// @brief Sets the string value to be held by the option.
    ///
    /// Trailing NULLs will be trimmed.
    ///
    /// @param value string value to be set.
    ///
    /// @throw isc::OutOfRange if a string value to be set is empty.
    void setValue(const std::string& value);

    /// @brief 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.
    ///
    /// @param [out] buf output buffer where the option will be stored.
    /// @param check if set to false, allows options larger than 255 for v4
    virtual void pack(isc::util::OutputBuffer& buf, bool check = true) const;<--- Function in derived class

    /// @brief 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.
    ///
    /// @param begin the iterator pointing to the option payload.
    /// @param end the iterator pointing to the end of the option payload.
    ///
    /// @throw isc::OutOfRange if provided buffer is truncated.
    virtual void unpack(OptionBufferConstIter begin, OptionBufferConstIter end);<--- unpack is a virtual function

    /// @brief Returns option information in the textual format.
    ///
    /// @param indent Number of space characters to be inserted before
    /// the text.
    ///
    /// @return Option information in the textual format.
    virtual std::string toText(int indent = 0) const;<--- Function in derived class

    /// @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() const;<--- Function in derived class
};

/// Pointer to the OptionString object.
typedef boost::shared_ptr<OptionString> OptionStringPtr;

} // namespace isc::dhcp
} // namespace isc

#endif // OPTION_STRING_H