config_parser.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (C) 2012-2013 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. /// @brief Configure DHCPv4 server (@c Dhcpv4Srv) with a set of configuration values.
  26. ///
  27. /// This function parses configuration information stored in @c config_set
  28. /// and configures the @c server by applying the configuration to it.
  29. /// It provides the strong exception guarantee as long as the underlying
  30. /// derived class implementations of @c DhcpConfigParser meet the assumption,
  31. /// that is, it ensures that either configuration is fully applied or the
  32. /// state of the server is intact.
  33. ///
  34. /// If a syntax or semantics level error happens during the configuration
  35. /// (such as malformed configuration or invalid configuration parameter),
  36. /// this function returns appropriate error code.
  37. ///
  38. /// This function is called every time a new configuration is received. The extra
  39. /// parameter is a reference to DHCPv4 server component. It is currently not used
  40. /// and CfgMgr::instance() is accessed instead.
  41. ///
  42. /// This method does not throw. It catches all exceptions and returns them as
  43. /// reconfiguration statuses. It may return the following response codes:
  44. /// 0 - configuration successful
  45. /// 1 - malformed configuration (parsing failed)
  46. /// 2 - commit failed (parsing was successful, but failed to store the
  47. /// values in to server's configuration)
  48. ///
  49. /// @param config_set a new configuration (JSON) for DHCPv4 server
  50. /// @return answer that contains result of reconfiguration
  51. isc::data::ConstElementPtr
  52. configureDhcp4Server(Dhcpv4Srv&,
  53. isc::data::ConstElementPtr config_set);
  54. /// @brief Returns the global uint32_t values storage.
  55. ///
  56. /// This function must be only used by unit tests that need
  57. /// to access uint32_t global storage to verify that the
  58. /// Uint32Parser works as expected.
  59. ///
  60. /// @return a reference to a global uint32 values storage.
  61. const std::map<std::string, uint32_t>& getUint32Defaults();
  62. }; // end of isc::dhcp namespace
  63. }; // end of isc namespace
  64. #endif // DHCP4_CONFIG_PARSER_H