cfg_db_access.cc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/host_mgr.h>
  10. #include <dhcpsrv/lease_mgr_factory.h>
  11. #include <sstream>
  12. namespace isc {
  13. namespace dhcp {
  14. CfgDbAccess::CfgDbAccess()
  15. : appended_parameters_(), lease_db_access_("type=memfile"),
  16. host_db_access_() {
  17. }
  18. std::string
  19. CfgDbAccess::getLeaseDbAccessString() const {
  20. return (getAccessString(lease_db_access_));
  21. }
  22. std::string
  23. CfgDbAccess::getHostDbAccessString() const {
  24. return (getAccessString(host_db_access_));
  25. }
  26. void
  27. CfgDbAccess::createManagers() const {
  28. // Recreate lease manager.
  29. LeaseMgrFactory::destroy();
  30. LeaseMgrFactory::create(getLeaseDbAccessString());
  31. // Recreate host data source.
  32. HostDataSourceFactory::destroy();
  33. if (!host_db_access_.empty()) {
  34. HostMgr::create(getHostDbAccessString());
  35. }
  36. }
  37. std::string
  38. CfgDbAccess::getAccessString(const std::string& access_string) const {
  39. std::ostringstream s;
  40. s << access_string;
  41. // Only append additional parameters if any parameters are specified
  42. // in a configuration. For host database, no parameters mean that
  43. // database access is disabled and thus we don't want to append any
  44. // parameters.
  45. if ((s.tellp() != std::streampos(0)) && (!appended_parameters_.empty())) {
  46. s << " " << appended_parameters_;
  47. }
  48. return (s.str());
  49. }
  50. } // end of isc::dhcp namespace
  51. } // end of isc namespace