configuration.cc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright (C) 2014 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 <dhcpsrv/cfgmgr.h>
  15. #include <dhcpsrv/configuration.h>
  16. #include <sstream>
  17. namespace isc {
  18. namespace dhcp {
  19. Configuration::Configuration()
  20. : sequence_(0) {
  21. }
  22. Configuration::Configuration(uint32_t sequence)
  23. : sequence_(sequence) {
  24. }
  25. std::string
  26. Configuration::getConfigSummary(const uint32_t selection) const {
  27. std::ostringstream s;
  28. size_t subnets_num;
  29. if ((selection & CFGSEL_SUBNET4) == CFGSEL_SUBNET4) {
  30. subnets_num = CfgMgr::instance().getSubnets4()->size();
  31. if (subnets_num > 0) {
  32. s << "added IPv4 subnets: " << subnets_num;
  33. } else {
  34. s << "no IPv4 subnets!";
  35. }
  36. s << "; ";
  37. }
  38. if ((selection & CFGSEL_SUBNET6) == CFGSEL_SUBNET6) {
  39. subnets_num = CfgMgr::instance().getSubnets6()->size();
  40. if (subnets_num > 0) {
  41. s << "added IPv6 subnets: " << subnets_num;
  42. } else {
  43. s << "no IPv6 subnets!";
  44. }
  45. s << "; ";
  46. }
  47. if ((selection & CFGSEL_DDNS) == CFGSEL_DDNS) {
  48. bool ddns_enabled = CfgMgr::instance().ddnsEnabled();
  49. s << "DDNS: " << (ddns_enabled ? "enabled" : "disabled") << "; ";
  50. }
  51. if (s.tellp() == static_cast<std::streampos>(0)) {
  52. s << "no config details available";
  53. }
  54. std::string summary = s.str();
  55. size_t last_separator_pos = summary.find_last_of(";");
  56. if (last_separator_pos == summary.length() - 2) {
  57. summary.erase(last_separator_pos);
  58. }
  59. return (summary);
  60. }
  61. bool
  62. Configuration::sequenceEquals(const Configuration& other) {
  63. return (getSequence() == other.getSequence());
  64. }
  65. }
  66. }