config_parser.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <exceptions/exceptions.h>
  15. #include <cc/data.h>
  16. #include <stdint.h>
  17. #include <string>
  18. #ifndef DHCP4_CONFIG_PARSER_H
  19. #define DHCP4_CONFIG_PARSER_H
  20. /// @todo: This header file and its .cc counterpart are very similar between
  21. /// DHCPv4 and DHCPv6. They should be merged. A ticket #2355.
  22. namespace isc {
  23. namespace dhcp {
  24. class Dhcpv4Srv;
  25. /// An exception that is thrown if an error occurs while configuring an
  26. /// @c Dhcpv4Srv object.
  27. class Dhcp4ConfigError : public isc::Exception {
  28. public:
  29. /// @brief constructor
  30. ///
  31. /// @param file name of the file, where exception occurred
  32. /// @param line line of the file, where exception occurred
  33. /// @param what text description of the issue that caused exception
  34. Dhcp4ConfigError(const char* file, size_t line, const char* what)
  35. : isc::Exception(file, line, what) {}
  36. };
  37. /// @brief Configure DHCPv4 server (@c Dhcpv4Srv) with a set of configuration values.
  38. ///
  39. /// This function parses configuration information stored in @c config_set
  40. /// and configures the @c server by applying the configuration to it.
  41. /// It provides the strong exception guarantee as long as the underlying
  42. /// derived class implementations of @c DhcpConfigParser meet the assumption,
  43. /// that is, it ensures that either configuration is fully applied or the
  44. /// state of the server is intact.
  45. ///
  46. /// If a syntax or semantics level error happens during the configuration
  47. /// (such as malformed configuration or invalid configuration parameter),
  48. /// this function returns appropriate error code.
  49. ///
  50. /// This function is called every time a new configuration is received. The extra
  51. /// parameter is a reference to DHCPv4 server component. It is currently not used
  52. /// and CfgMgr::instance() is accessed instead.
  53. ///
  54. /// This method does not throw. It catches all exceptions and returns them as
  55. /// reconfiguration statuses. It may return the following response codes:
  56. /// 0 - configuration successful
  57. /// 1 - malformed configuration (parsing failed)
  58. /// 2 - commit failed (parsing was successful, but failed to store the
  59. /// values in to server's configuration)
  60. ///
  61. /// @param config_set a new configuration (JSON) for DHCPv4 server
  62. /// @return answer that contains result of reconfiguration
  63. isc::data::ConstElementPtr
  64. configureDhcp4Server(Dhcpv4Srv&,
  65. isc::data::ConstElementPtr config_set);
  66. /// @brief Returns the global uint32_t values storage.
  67. ///
  68. /// This function must be only used by unit tests that need
  69. /// to access uint32_t global storage to verify that the
  70. /// Uint32Parser works as expected.
  71. ///
  72. /// @return a reference to a global uint32 values storage.
  73. const std::map<std::string, uint32_t>& getUint32Defaults();
  74. }; // end of isc::dhcp namespace
  75. }; // end of isc namespace
  76. #endif // DHCP4_CONFIG_PARSER_H