1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
- //
- // Permission to use, copy, modify, and/or distribute this software for any
- // purpose with or without fee is hereby granted, provided that the above
- // copyright notice and this permission notice appear in all copies.
- //
- // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- #include <dhcp6/dbaccess_parser.h>
- #include <boost/foreach.hpp>
- #include <map>
- #include <string>
- #include <utility>
- using namespace std;
- using namespace isc::data;
- namespace isc {
- namespace dhcp {
- /// @brief an auxiliary type used for storing an element name and its parser
- typedef map<string, ConstElementPtr> ConfigPairMap;
- typedef pair<string, ConstElementPtr> ConfigPair;
- // Parse the configuration and check that the various keywords are consistent.
- void
- DbAccessParser::build(isc::data::ConstElementPtr config_value) {
- const ConfigPairMap& config_map = config_value->mapValue();
- // Check if the "type" keyword exists and thrown an exception if not.
- ConfigPairMap::const_iterator type_ptr = config_map.find("type");
- if (type_ptr == config_map.end()) {
- isc_throw(TypeKeywordMissing, "lease database access parameters must "
- "include the keyword 'type' to determine type of database "
- "to be accessed");
- }
- // Check if the 'type; keyword known and throw an exception if not.
- string dbtype = type_ptr->second->stringValue();
- if ((dbtype != "memfile") && (dbtype != "mysql")) {
- isc_throw(BadValue, "unknown backend database type: " << dbtype);
- }
- /// @todo Log a warning if the type is memfile and there are other keywords.
- /// This will be done when the module is moved to libdhcpsrv
- // All OK, build up the access string
- dbaccess_ = "";
- BOOST_FOREACH(ConfigPair param, config_value->mapValue()) {
- if (! dbaccess_.empty()) {
- dbaccess_ += std::string(" ");
- }
- dbaccess_ += (param.first + std::string("=") +
- param.second->stringValue());
- }
- }
- // Commit the changes - reopen the database with the new parameters
- void
- DbAccessParser::commit() {
- }
- }; // namespace dhcp
- }; // namespace isc
|