cfg_db_access.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #include <config.h>
  7. #include <dhcpsrv/cfg_db_access.h>
  8. #include <dhcpsrv/host_data_source_factory.h>
  9. #include <dhcpsrv/lease_mgr_factory.h>
  10. #include <sstream>
  11. namespace isc {
  12. namespace dhcp {
  13. CfgDbAccess::CfgDbAccess()
  14. : appended_parameters_(), lease_db_access_("type=memfile"),
  15. host_db_access_() {
  16. }
  17. std::string
  18. CfgDbAccess::getLeaseDbAccessString() const {
  19. return (getAccessString(lease_db_access_));
  20. }
  21. std::string
  22. CfgDbAccess::getHostDbAccessString() const {
  23. return (getAccessString(host_db_access_));
  24. }
  25. void
  26. CfgDbAccess::createManagers() const {
  27. // Recreate lease manager.
  28. LeaseMgrFactory::destroy();
  29. LeaseMgrFactory::create(getLeaseDbAccessString());
  30. // Recreate host data source.
  31. HostDataSourceFactory::destroy();
  32. if (!host_db_access_.empty()) {
  33. HostDataSourceFactory::create(getHostDbAccessString());
  34. }
  35. }
  36. std::string
  37. CfgDbAccess::getAccessString(const std::string& access_string) const {
  38. std::ostringstream s;
  39. s << access_string;
  40. // Only append additional parameters if any parameters are specified
  41. // in a configuration. For host database, no parameters mean that
  42. // database access is disabled and thus we don't want to append any
  43. // parameters.
  44. if ((s.tellp() != std::streampos(0)) && (!appended_parameters_.empty())) {
  45. s << " " << appended_parameters_;
  46. }
  47. return (s.str());
  48. }
  49. } // end of isc::dhcp namespace
  50. } // end of isc namespace