lease_parser.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright (C) 2017 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. #ifndef LEASE_PARSER_H
  7. #define LEASE_PARSER_H
  8. #include <cc/data.h>
  9. #include <cc/simple_parser.h>
  10. #include <dhcpsrv/lease.h>
  11. #include <dhcpsrv/srv_config.h>
  12. namespace isc {
  13. namespace lease_cmds {
  14. /// @brief Base class for Lease4 and Lease6 parsers
  15. class LeaseParser : public isc::data::SimpleParser {
  16. protected:
  17. /// @brief Returns an address from JSON structure
  18. ///
  19. /// @param scope a map the element will be searched at
  20. /// @param name key name to be searched for
  21. /// @return IOAddress representation
  22. isc::asiolink::IOAddress getIOAddress(const isc::data::ConstElementPtr& scope,
  23. const std::string& name);
  24. };
  25. /// @brief Parser for Lease4 structure
  26. ///
  27. /// It expects the data in the following format:
  28. /// {
  29. /// "ip-address": "192.0.2.1",
  30. /// "hw-address": "00:01:02:03:04:05",
  31. /// "client-id": "this-is-a-client",
  32. /// "valid-lft": 3600,
  33. /// "cltt": 12345678,
  34. /// "expire": 1499282530,
  35. /// "subnet-id": 1,
  36. /// "fdqn-fwd": true,
  37. /// "fqdn-rev": true,
  38. /// "hostname": "myhost.example.org",
  39. /// "state": 0
  40. /// }
  41. class Lease4Parser : public LeaseParser {
  42. public:
  43. /// @brief Parses Element tree and tries to convert to Lease4
  44. ///
  45. /// See @ref Lease6Parser class description for expected format.
  46. ///
  47. /// @param cfg Currently running config (used for sanity checks and defaults)
  48. /// @param lease_info structure to be parsed
  49. /// @return A pointer to Lease4
  50. /// @throw BadValue if any of the parameters is invalid
  51. /// @throw DhcpConfigError if mandatory parameter is missing
  52. virtual isc::dhcp::Lease4Ptr parse(isc::dhcp::ConstSrvConfigPtr& cfg,
  53. const isc::data::ConstElementPtr& lease_info);
  54. /// @brief virtual dtor (does nothing)
  55. virtual ~Lease4Parser() {}
  56. };
  57. /// @brief Parser for Lease6 structure
  58. ///
  59. /// {
  60. /// "address": "2001:db8::1",
  61. /// "duid": "00:01:02:03:04:05",
  62. /// "type": "IA_NA",
  63. /// "cltt": 12345678,
  64. /// "preferred-lft": 3600,
  65. /// "valid-lft": 3600,
  66. /// "expire": 1499282530,
  67. /// "subnet-id": 1,
  68. /// "fdqn-fwd": true,
  69. /// "fqdn-rev": true,
  70. /// "hostname": "myhost.example.org",
  71. /// "state": 0
  72. /// }
  73. /// It expects the input data to use the following format:
  74. class Lease6Parser : public LeaseParser {
  75. public:
  76. /// @brief Parses Element tree and tries to convert to Lease4
  77. ///
  78. /// See @ref Lease6Parser class description for expected format.
  79. ///
  80. /// @param cfg Currently running config (used for sanity checks and defaults)
  81. /// @param lease_info structure to be parsed
  82. /// @return A pointer to Lease4
  83. /// @throw BadValue if any of the parameters is invalid
  84. /// @throw DhcpConfigError if mandatory parameter is missing
  85. virtual isc::dhcp::Lease6Ptr parse(isc::dhcp::ConstSrvConfigPtr& cfg,
  86. const isc::data::ConstElementPtr& lease_info);
  87. /// @brief virtual dtor (does nothing)
  88. virtual ~Lease6Parser() {}
  89. };
  90. }; // end of isc::dhcp namespace
  91. }; // end of isc namespace
  92. #endif