dbaccess_parser.h 3.36 KB
Newer Older
1
// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
2
//
3 4 5
// 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/.
6 7 8 9 10

#ifndef DBACCESS_PARSER_H
#define DBACCESS_PARSER_H

#include <cc/data.h>
11 12
#include <cc/simple_parser.h>
#include <dhcpsrv/cfg_db_access.h>
13
#include <exceptions/exceptions.h>
14 15 16 17 18 19 20 21 22 23 24 25 26

#include <string>

namespace isc {
namespace dhcp {

/// @brief Parse Lease Database Parameters
///
/// This class is the parser for the lease database configuration.  This is a
/// map under the top-level "lease-database" element, and comprises a map of
/// strings.
///
/// Only the "type" sub-element is mandatory: the remaining sub-elements 
27
/// depend on the database chosen.
28
class DbAccessParser: public isc::data::SimpleParser {
29
public:
30 31 32 33 34 35 36

    /// @brief Specifies the database type
    typedef enum {
        LEASE_DB = 1,
        HOSTS_DB = 2
    } DBType;

37 38 39 40 41
    /// @brief Keyword and associated value
    typedef std::pair<std::string, std::string> StringPair;

    /// @brief Keyword/value collection of database access parameters
    typedef std::map<std::string, std::string> StringPairMap;
42

43
    /// @brief Constructor
44
    ///
45
    /// @param db_type Specifies database type (lease or hosts)
46
    DbAccessParser(DBType db_type);
47 48 49 50 51

    /// The destructor.
    virtual ~DbAccessParser()
    {}

52
    /// @brief Parse configuration value.
53 54 55 56
    ///
    /// Parses the set of strings forming the database access specification and
    /// checks that all are OK.  In particular it checks:
    ///
57 58
    /// - "type" is "memfile", "mysql" or "postgresql"
    /// - "lfc-interval" is a number from the range of 0 to 4294967295.
59
    /// - "connect-timeout" is a number from the range of 0 to 4294967295.
60
    /// - "port" is a number from the range of 0 to 65535.
61 62 63 64
    ///
    /// Once all has been validated, constructs the database access string
    /// expected by the lease manager.
    ///
65 66
    /// @param cfg_db The configuration where the access string will be set
    /// @param database_config The configuration value for the "*-database"
67
    ///        identifier.
68
    ///
69 70 71
    /// @throw isc::dhcp::DhcpConfigError The 'type' keyword contains an
    ///        unknown database type or is missing from the list of
    ///        database access keywords.
72 73
    void parse(isc::dhcp::CfgDbAccessPtr& cfg_db,
               isc::data::ConstElementPtr database_config);
74

75

76
protected:
77
    /// @brief Get database access parameters
78 79
    ///
    /// Used in testing to check that the configuration information has been
80
    /// parsed correctly.
81
    ///
82 83 84
    /// @return Reference to the internal map of keyword/value pairs
    ///         representing database access information.  This is valid only
    ///         for so long as the the parser remains in existence.
85 86
    const StringPairMap& getDbAccessParameters() const {
        return (values_);
87 88
    }

89

90
    /// @brief Construct database access string
91 92 93 94 95 96
    ///
    /// Constructs the database access string from the stored parameters.
    ///
    /// @return Database access string
    std::string getDbAccessString() const;

97
private:
98

99
    std::map<std::string, std::string> values_; ///< Stored parameter values
100

101
    DBType type_; ///< Database type (leases or hosts)
102 103 104 105 106 107 108
};

};  // namespace dhcp
};  // namespace isc


#endif // DBACCESS_PARSER_H