cfg_option_def.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // Copyright (C) 2014-2015 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 CFG_OPTION_DEF_H
  7. #define CFG_OPTION_DEF_H
  8. #include <dhcp/option_definition.h>
  9. #include <dhcp/option_space_container.h>
  10. #include <string>
  11. namespace isc {
  12. namespace dhcp {
  13. /// @brief Represents option definitions used by the DHCP server.
  14. ///
  15. /// This class provides methods to add and retrieve option definitions
  16. /// specified by the administrator for the DHCP server. Option definitions
  17. /// specify formats of the options. This class doesn't hold information
  18. /// about the data being carried by the options.
  19. ///
  20. /// Option definitions are grouped by option spaces. The option space is
  21. /// identified by the unique name which is specified as a string. The
  22. /// following names: "dhcp4" and "dhcp6" are reserved, though. They are
  23. /// names of option spaces used for standard top-level DHCPv4 and DHCPv6
  24. /// options respectively.
  25. class CfgOptionDef {
  26. public:
  27. /// @brief Copies this configuration to a new configuration.
  28. ///
  29. /// This method copies the option definitions stores in the configuration
  30. /// to an object passed as parameter. There are no shared objects or
  31. /// pointers between the original object and a copy.
  32. ///
  33. /// @param [out] new_config An object to which the configuration will be
  34. /// copied.
  35. void copyTo(CfgOptionDef& new_config) const;
  36. /// @name Methods and operators used for comparing objects.
  37. ///
  38. //@{
  39. /// @brief Check if configuration is equal to other configuration.
  40. ///
  41. /// @param other An object holding configuration to compare to.
  42. ///
  43. /// @return true if configurations are equal, false otherwise.
  44. bool equals(const CfgOptionDef& other) const;
  45. /// @brief Equality operator.
  46. ///
  47. /// @param other An object holding configuration to compare to.
  48. ///
  49. /// @return true if configurations are equal, false otherwise.
  50. bool operator==(const CfgOptionDef& other) const {
  51. return (equals(other));
  52. }
  53. /// @brief Inequality operator.
  54. ///
  55. /// @param other An object holding configuration to compare to.
  56. ///
  57. /// @return true if configurations are unequal, false otherwise.
  58. bool operator!=(const CfgOptionDef& other) const {
  59. return (!equals(other));
  60. }
  61. //@}
  62. /// @brief Add new option definition.
  63. ///
  64. /// @param def option definition to be added.
  65. /// @param option_space name of the option space to add definition to.
  66. ///
  67. /// @throw isc::dhcp::DuplicateOptionDefinition when the particular
  68. /// option definition already exists.
  69. /// @throw isc::dhcp::MalformedOptionDefinition when the pointer to
  70. /// an option definition is NULL.
  71. /// @throw isc::BadValue when the option space name is empty or
  72. /// when trying to override the standard option (in dhcp4 or dhcp6
  73. /// option space).
  74. void add(const OptionDefinitionPtr& def, const std::string& option_space);
  75. /// @brief Return option definitions for particular option space.
  76. ///
  77. /// @param option_space option space.
  78. ///
  79. /// @return Pointer to the collection of option definitions for
  80. /// the particular option space. The option collection is empty
  81. /// if no option exists for the option space specified.
  82. OptionDefContainerPtr getAll(const std::string& option_space) const;
  83. /// @brief Return option definition for a particular option space and code.
  84. ///
  85. /// @param option_space option space.
  86. /// @param option_code option code.
  87. ///
  88. /// @return An option definition or NULL pointer if option definition
  89. /// has not been found.
  90. OptionDefinitionPtr get(const std::string& option_space,
  91. const uint16_t option_code) const;
  92. /// @brief Return option definition for the particular option space and name.
  93. ///
  94. /// @param option_space pption space.
  95. /// @param option_name option name.
  96. ///
  97. /// @return An option definition or NULL pointer if option definition
  98. /// has not been found.
  99. OptionDefinitionPtr get(const std::string& option_space,
  100. const std::string& option_name) const;
  101. /// @brief Returns reference to container holding option definitions.
  102. const OptionDefSpaceContainer& getContainer() const {
  103. return (option_definitions_);
  104. }
  105. private:
  106. /// @brief A collection of option definitions.
  107. ///
  108. /// The option definitions stored in this container can be accessed
  109. /// using the option space name they belong to.
  110. OptionDefSpaceContainer option_definitions_;
  111. };
  112. /// @name Pointers to the @c CfgOptionDef objects.
  113. //@{
  114. /// @brief Non-const pointer.
  115. typedef boost::shared_ptr<CfgOptionDef> CfgOptionDefPtr;
  116. /// @brief Const pointer.
  117. typedef boost::shared_ptr<const CfgOptionDef> ConstCfgOptionDefPtr;
  118. //@}
  119. }
  120. }
  121. #endif // CFG_OPTION_DEF_H