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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// 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 PROCESS_CONFIG_CTL_INFO_H
#define PROCESS_CONFIG_CTL_INFO_H

#include <cc/cfg_to_element.h>
#include <database/database_connection.h>
#include <util/optional.h>

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

namespace isc {
namespace process {

/// @brief Provides configuration information used during a server's
/// configuration process.
///
class ConfigDbInfo : public isc::data::CfgToElement {
public:
    /// @brief Constructor
    ConfigDbInfo() {};

    /// @brief Set the access string.
    ///
    /// Sets the db's access string to the given value and then parses it
    /// into name-value pairs and storing them internally as a
    /// DatabaseConnection::ParameterMap.  It discards the existing content
    /// of the map first.  It does not validate the parameter names of values,
    /// ensuring the validity of the string content is placed upon the caller.
    ///
    /// @param access_str string of name=value pairs separated by spaces.
    /// @param test_mode flag used in unittests only to skip parsing the access
    /// string and storing the parameters.
    void setAccessString(const std::string& access_str, bool test_mode = false);

    /// @brief Retrieves the database access string.
    ///
    /// @return database access string.
    std::string getAccessString() const {
        return (access_str_);
    }

    /// @brief Retrieves the database access string with password redacted.
    ///
    /// @return database access string with password redacted.
    std::string redactedAccessString() const {
        return (db::DatabaseConnection::redactedAccessString(access_params_));
    }

    /// @brief Retrieve the map of parameter values.
    ///
    /// @return Constant reference to the database's parameter map.
    const db::DatabaseConnection::ParameterMap& getParameters() const {
        return (access_params_);
    }

    /// @brief Fetch the value of a given parameter.
    ///
    /// @param name name of the parameter value to fetch.
    /// @param[out] value string which will contain the value of the
    /// parameter (if found).
    ///
    /// @return Boolean true if the parameter named is found in the map,
    /// false otherwise.
    bool getParameterValue(const std::string& name,
                           std::string& value) const;

    /// @brief Unparse a configuration object.
    ///
    /// @return a pointer to unparsed configuration.
    virtual isc::data::ElementPtr toElement() const;<--- Function in derived class

    /// @brief Compares two objects for equality.
    ///
    /// @param other An object to be compared with this object.
    ///
    /// @return true if objects are equal, false otherwise.
    bool equals(const ConfigDbInfo& other) const;

    /// @brief Compares two objects for equality.
    ///
    /// @param other An object to be compared with this object.
    ///
    /// @return true if objects are equal, false otherwise.
    bool operator==(const ConfigDbInfo& other) const {
        return (equals(other));
    }

    /// @brief Compares two objects for inequality.
    ///
    /// @param other An object to be compared with this object.
    ///
    /// @return true if objects are not equal, false otherwise.
    bool operator!=(const ConfigDbInfo& other) const {
        return (!equals(other));
    }

private:
    /// @brief Access string of parameters used to access this database.
    std::string access_str_;

    /// @brief Map of the access parameters and their values.
    db::DatabaseConnection::ParameterMap access_params_;
};

typedef std::vector<ConfigDbInfo> ConfigDbInfoList;

/// @brief Embodies configuration information used during a server's
/// configuration process.
///
/// This is class conveys the configuration control information
/// described by the following JSON text:
///
/// @code
/// "config-control" :
/// {
///     "config-databases":
///     [
///     {
///         # first config db
///         # common database access parameters
///         "type": <"mysql"|"postgresql">,
///         "name": <"db name">,
///         "host": <"db host name">,
///             :
///     },
///     {
///         # next config db
///     }
///     ]
///
/// }
/// @endcode
///
class ConfigControlInfo : public isc::data::CfgToElement {
public:

    /// @brief Constructor.
    ConfigControlInfo()
        : config_fetch_wait_time_(30, true) {};

    /// @brief Copy Constructor.
    ConfigControlInfo(const ConfigControlInfo& other);

    /// @brief Sets new value of the config-fetch-wait-time.
    ///
    /// @param config_fetch_wait_time New value of the parameter which
    /// specifies a time period in seconds between the attempts to
    /// fetch the server configuration updates. The value of 0 disables
    /// the periodic attempts to fetch the updates.
    void setConfigFetchWaitTime(const util::Optional<uint16_t>& config_fetch_wait_time) {
        config_fetch_wait_time_ = config_fetch_wait_time;
    }

    /// @brief Returns configured config-fetch-wait-time value.
    ///
    /// This value specifies the time period in seconds between the
    /// attempts to fetch the server configuration updates via the
    /// configuration backends. The value of 0 means that the
    /// mechanism to periodically fetch the configuration updates
    /// is disabled.
    ///
    /// @return Time period between the subsequent attempts to
    /// fetch server configuration updates in seconds.
    const util::Optional<uint16_t>& getConfigFetchWaitTime() const {
        return (config_fetch_wait_time_);
    }

    /// @brief Sets configuration database access string.
    ///
    /// @param access_str database access string.
    ///
    /// @throw BadValue if an entry exists that matches the parameters
    /// in the given access string, or if the access string is invalid.
    void addConfigDatabase(const std::string& access_str);

    /// @brief Retrieves the list of databases.
    ///
    /// The entries in the list are stored in the order they were
    /// added to it (FIFO).
    ///
    /// @return a reference to a const list of databases.
    const ConfigDbInfoList& getConfigDatabases() const {
        return (db_infos_);
    }

    /// @brief Retrieves the database with the given access parameter value.
    ///
    /// @return A reference to the matching database or the not-found value
    /// available via @c EMPTY_DB().
    const ConfigDbInfo& findConfigDb(const std::string& param_name,
                                     const std::string& param_value);

    /// @brief Empties the contents of the class, including the database list.
    void clear();

    /// @brief Merges specified configuration into this configuration.
    ///
    /// If the other configuration is non-empty it completely replaces
    /// this configuration.
    ///
    /// @param other the other configuration to be merged into this
    /// configuration.
    void merge(const ConfigControlInfo& other);

    /// @brief Unparse a configuration object.
    ///
    /// @return a pointer to unparsed configuration.
    virtual isc::data::ElementPtr toElement() const;<--- Function in derived class

    /// @brief Fetches the not-found value returned by database list searches.
    ///
    /// @return a reference to the empty ConfigDBInfo.
    static const ConfigDbInfo& EMPTY_DB();

    /// @brief Compares two objects for equality.
    ///
    /// @param other An object to be compared with this object.
    ///
    /// @return true if objects are equal, false otherwise.
    bool equals(const ConfigControlInfo& other) const;

private:

    /// @brief Configured value of the config-fetch-wait-time.
    util::Optional<uint16_t> config_fetch_wait_time_;

    /// @brief List of configuration databases.
    ConfigDbInfoList db_infos_;
};

/// @brief Defines a pointer to a ConfigControlInfo.
typedef boost::shared_ptr<ConfigControlInfo> ConfigControlInfoPtr;

/// @brief Defines a pointer to a const ConfigControlInfo.
typedef boost::shared_ptr<const ConfigControlInfo> ConstConfigControlInfoPtr;

} // namespace process
} // end namespace isc

#endif // PROCESS_CONFIG_CTL_INFO_H