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
// Copyright (C) 2018-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 ISC_ADAPTOR_OPTION_H
#define ISC_ADAPTOR_OPTION_H 1

#include <dhcp/option_data_types.h>
#include <yang/adaptor.h>

#include <unordered_map><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace isc {
namespace yang {

/// @brief Map for DHCP option definitions handling code and
/// an index built from space and name.
///
/// The map is used to store space+name to code mappings so for
/// an option data without a code entry the code entry can be supplied.
using OptionCodes = std::unordered_map<std::string, uint16_t>;

/// @brief JSON adaptor for option data or definition setting defaults.
///
/// Both option data and option definition lists are keyed by the code
/// and space pair so both must be available in setOptionXXX methods.
/// For space there is an implicit default so setSpace must be called
/// to add this default to option entries without space.
/// Note remaining adaptors assume this was done first.
///
/// checkCode and checkType can be used to check if code or type is present
/// (type is mandatory in option definitions).
///
/// A missing code can be found in standard definitions (loaded by initCodes)
/// or in configuration option definitions (at global and client classes
/// scopes). setCode uses the space+name to code map to set missing codes
/// and raises an error when it can't.
class AdaptorOption {
public:
    /// @brief Destructor.
    virtual ~AdaptorOption() = default;

    /// @brief Set space.
    ///
    /// @param option The option.
    /// @param space The default space name.
    static void setSpace(isc::data::ElementPtr option,
                         const std::string& space);

    /// @brief Checks if type is specified in option definition.
    ///
    /// @param option The option.
    /// @throw MissingKey if the type is not present.
    static void checkType(isc::data::ConstElementPtr option);

    /// @brief Check if code is specified in option defintion.
    ///
    /// @param option The option.
    /// @throw MissingKey if the code is not present.
    static void checkCode(isc::data::ConstElementPtr option);

    /// @brief Collect definition.
    ///
    /// This method looks at an option definition and adds the
    /// space+name to code mapping into the OptionCodes codes store
    /// aka definitions.
    ///
    /// @param option The option definition.
    /// @param codes The reference to option definitions.
    static void collect(isc::data::ConstElementPtr option, OptionCodes& codes);

    /// @brief Set code from name and definitions.
    ///
    /// @param option The option data.
    /// @param codes Option definitions.
    static void setCode(isc::data::ElementPtr option,
                        const OptionCodes& codes);

    /// @brief Initialize code map.
    ///
    /// @param codes The reference to option definitions.
    /// @param space The space name.
    static void initCodes(OptionCodes& codes, const std::string& space);

protected:
    /// @brief Initialize code map from option definition parameters.
    ///
    /// @param codes The reference to option definitions.
    /// @param space The space name.
    /// @param params Array of option definition parameters
    /// @param params_size The size of the array.
    static void initCodesInternal(OptionCodes& codes, const std::string& space,
                                  const isc::dhcp::OptionDefParams* params,
                                  size_t params_size);
};  // AdaptorOption

}  // namespace yang
}  // namespace isc

#endif  // ISC_ADAPTOR_OPTION_H