zone_table.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // Copyright (C) 2010 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. #ifndef __ZONETABLE_H
  15. #define __ZONETABLE_H 1
  16. #include <util/memory_segment.h>
  17. #include <dns/rrset.h>
  18. #include <datasrc/zone.h>
  19. #include <boost/shared_ptr.hpp>
  20. namespace isc {
  21. namespace dns {
  22. class Name;
  23. class RRClass;
  24. }
  25. namespace datasrc {
  26. /// \brief A set of authoritative zones.
  27. ///
  28. /// \c ZoneTable class is primarily intended to be used as a backend for the
  29. /// \c MemoryDataSrc class, but is exposed as a separate class in case some
  30. /// application wants to use it directly (e.g. for a customized data source
  31. /// implementation).
  32. ///
  33. /// For more descriptions about its struct and interfaces, please refer to the
  34. /// corresponding struct and interfaces of \c MemoryDataSrc.
  35. class ZoneTable {
  36. public:
  37. struct FindResult {
  38. FindResult(result::Result param_code, const ZoneFinderPtr param_zone) :
  39. code(param_code), zone(param_zone)
  40. {}
  41. const result::Result code;
  42. const ZoneFinderPtr zone;
  43. };
  44. ///
  45. /// \name Constructors and Destructor.
  46. ///
  47. /// \b Note:
  48. /// The copy constructor and the assignment operator are intentionally
  49. /// defined as private, making this class non copyable.
  50. //@{
  51. private:
  52. ZoneTable(const ZoneTable& source);
  53. ZoneTable& operator=(const ZoneTable& source);
  54. /// Constructor.
  55. ///
  56. /// An object of this class is always expected to be created by the
  57. /// allocator (\c create()), so the constructor is hidden as private.
  58. ///
  59. /// This constructor internally involves resource allocation, and if
  60. /// it fails, a corresponding standard exception will be thrown.
  61. /// It never throws an exception otherwise.
  62. ZoneTable(util::MemorySegment& mem_sgmt);
  63. /// The destructor.
  64. ///
  65. /// An object of this class is always expected to be destroyed explicitly
  66. /// by \c destroy(), so the constructor is hidden as private.
  67. ~ZoneTable();
  68. //@}
  69. public:
  70. /// \brief Allocate and construct \c ZoneTable
  71. ///
  72. /// This static method allocates memory for a new \c ZoneTable object
  73. /// from the given memory segment, constructs the object, and returns
  74. /// a pointer to it.
  75. ///
  76. /// \throw std::bad_alloc Memory allocation fails.
  77. ///
  78. /// \param mem_sgmt A \c MemorySegment from which memory for the new
  79. /// \c ZoneTable is allocated.
  80. static ZoneTable* create(util::MemorySegment& mem_sgmt);
  81. /// \brief Destruct and deallocate \c ZoneTable
  82. ///
  83. /// \throw none
  84. ///
  85. /// \param mem_sgmt The \c MemorySegment that allocated memory for
  86. /// \c ztable.
  87. /// \param ztable A non NULL pointer to a valid \c ZoneTable object
  88. /// that was originally created by the \c create() method (the behavior
  89. /// is undefined if this condition isn't met).
  90. static void destroy(util::MemorySegment& mem_sgmt, ZoneTable* ztable);
  91. /// Add a \c Zone to the \c ZoneTable.
  92. ///
  93. /// \c Zone must not be associated with a NULL pointer; otherwise
  94. /// an exception of class \c InvalidParameter will be thrown.
  95. /// If internal resource allocation fails, a corresponding standard
  96. /// exception will be thrown.
  97. /// This method never throws an exception otherwise.
  98. ///
  99. /// \param zone A \c Zone object to be added.
  100. /// \return \c result::SUCCESS If the zone is successfully
  101. /// added to the zone table.
  102. /// \return \c result::EXIST The zone table already contains
  103. /// zone of the same origin.
  104. result::Result addZone(util::MemorySegment& mem_sgmt, ZoneFinderPtr zone);
  105. /// Remove a \c Zone of the given origin name from the \c ZoneTable.
  106. ///
  107. /// This method never throws an exception.
  108. ///
  109. /// \param origin The origin name of the zone to be removed.
  110. /// \return \c result::SUCCESS If the zone is successfully
  111. /// removed from the zone table.
  112. /// \return \c result::NOTFOUND The zone table does not
  113. /// store the zone that matches \c origin.
  114. result::Result removeZone(const isc::dns::Name& origin);
  115. /// Find a \c Zone that best matches the given name in the \c ZoneTable.
  116. ///
  117. /// It searches the internal storage for a \c Zone that gives the
  118. /// longest match against \c name, and returns the result in the
  119. /// form of a \c FindResult object as follows:
  120. /// - \c code: The result code of the operation.
  121. /// - \c result::SUCCESS: A zone that gives an exact match
  122. /// is found
  123. /// - \c result::PARTIALMATCH: A zone whose origin is a
  124. /// super domain of \c name is found (but there is no exact match)
  125. /// - \c result::NOTFOUND: For all other cases.
  126. /// - \c zone: A "Boost" shared pointer to the found \c Zone object if one
  127. /// is found; otherwise \c NULL.
  128. ///
  129. /// This method never throws an exception.
  130. ///
  131. /// \param name A domain name for which the search is performed.
  132. /// \return A \c FindResult object enclosing the search result (see above).
  133. FindResult findZone(const isc::dns::Name& name) const;
  134. private:
  135. struct ZoneTableImpl;
  136. ZoneTableImpl* impl_;
  137. };
  138. }
  139. }
  140. #endif // __ZONETABLE_H
  141. // Local Variables:
  142. // mode: c++
  143. // End: