dbaccess_parser.cc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <dhcp6/dbaccess_parser.h>
  15. #include <boost/foreach.hpp>
  16. #include <map>
  17. #include <string>
  18. #include <utility>
  19. using namespace std;
  20. using namespace isc::data;
  21. namespace isc {
  22. namespace dhcp {
  23. /// @brief an auxiliary type used for storing an element name and its parser
  24. typedef map<string, ConstElementPtr> ConfigPairMap;
  25. typedef pair<string, ConstElementPtr> ConfigPair;
  26. // Parse the configuration and check that the various keywords are consistent.
  27. void
  28. DbAccessParser::build(isc::data::ConstElementPtr config_value) {
  29. const ConfigPairMap& config_map = config_value->mapValue();
  30. // Check if the "type" keyword exists and thrown an exception if not.
  31. ConfigPairMap::const_iterator type_ptr = config_map.find("type");
  32. if (type_ptr == config_map.end()) {
  33. isc_throw(TypeKeywordMissing, "lease database access parameters must "
  34. "include the keyword 'type' to determine type of database "
  35. "to be accessed");
  36. }
  37. // Check if the 'type; keyword known and throw an exception if not.
  38. string dbtype = type_ptr->second->stringValue();
  39. if ((dbtype != "memfile") && (dbtype != "mysql")) {
  40. isc_throw(BadValue, "unknown backend database type: " << dbtype);
  41. }
  42. /// @todo Log a warning if the type is memfile and there are other keywords.
  43. /// This will be done when the module is moved to libdhcpsrv
  44. // All OK, build up the access string
  45. dbaccess_ = "";
  46. BOOST_FOREACH(ConfigPair param, config_value->mapValue()) {
  47. if (! dbaccess_.empty()) {
  48. dbaccess_ += std::string(" ");
  49. }
  50. dbaccess_ += (param.first + std::string("=") +
  51. param.second->stringValue());
  52. }
  53. }
  54. // Commit the changes - reopen the database with the new parameters
  55. void
  56. DbAccessParser::commit() {
  57. }
  58. }; // namespace dhcp
  59. }; // namespace isc