zone_finder.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #ifndef DATASRC_MEMORY_ZONE_FINDER_H
  15. #define DATASRC_MEMORY_ZONE_FINDER_H 1
  16. #include <datasrc/memory/zone_data.h>
  17. #include <datasrc/memory/treenode_rrset.h>
  18. #include <datasrc/zone.h>
  19. #include <dns/name.h>
  20. #include <dns/rrset.h>
  21. #include <dns/rrtype.h>
  22. #include <string>
  23. namespace isc {
  24. namespace datasrc {
  25. namespace memory {
  26. namespace internal {
  27. // intermediate result context, only used in the zone finder implementation.
  28. class ZoneFinderResultContext;
  29. }
  30. /// A derived zone finder class intended to be used with the memory data
  31. /// source, using ZoneData for its contents.
  32. class InMemoryZoneFinder : boost::noncopyable, public ZoneFinder {
  33. public:
  34. /// \brief Constructor.
  35. ///
  36. /// Since ZoneData does not keep RRClass information, but this
  37. /// information is needed in order to construct actual RRsets,
  38. /// this needs to be passed here (the datasource client should
  39. /// have this information). In the future, this may be replaced
  40. /// by some construction to pull TreeNodeRRsets from a pool, but
  41. /// currently, these are created dynamically with the given RRclass
  42. ///
  43. /// \param zone_data The ZoneData containing the zone.
  44. /// \param rrclass The RR class of the zone
  45. InMemoryZoneFinder(const ZoneData& zone_data,
  46. const isc::dns::RRClass& rrclass) :
  47. zone_data_(zone_data),
  48. rrclass_(rrclass)
  49. {}
  50. /// \brief Find an RRset in the datasource
  51. virtual boost::shared_ptr<ZoneFinder::Context> find(
  52. const isc::dns::Name& name,
  53. const isc::dns::RRType& type,
  54. const FindOptions options = FIND_DEFAULT);
  55. /// \brief Version of find that returns all types at once
  56. ///
  57. /// It acts the same as find, just that when the correct node is found,
  58. /// all the RRsets are filled into the target parameter instead of being
  59. /// returned by the result.
  60. virtual boost::shared_ptr<ZoneFinder::Context> findAll(
  61. const isc::dns::Name& name,
  62. std::vector<isc::dns::ConstRRsetPtr>& target,
  63. const FindOptions options = FIND_DEFAULT);
  64. /// Look for NSEC3 for proving (non)existence of given name.
  65. ///
  66. /// See documentation in \c Zone.
  67. virtual FindNSEC3Result
  68. findNSEC3(const isc::dns::Name& name, bool recursive);
  69. /// \brief Returns the origin of the zone.
  70. virtual isc::dns::Name getOrigin() const;
  71. /// \brief Returns the RR class of the zone.
  72. virtual isc::dns::RRClass getClass() const {
  73. return (rrclass_);
  74. }
  75. private:
  76. /// \brief In-memory version of finder context.
  77. ///
  78. /// The implementation (and any specialized interface) is completely local
  79. /// to the InMemoryZoneFinder class, so it's defined as private
  80. class Context;
  81. /// Actual implementation for both find() and findAll()
  82. internal::ZoneFinderResultContext findInternal(
  83. const isc::dns::Name& name,
  84. const isc::dns::RRType& type,
  85. std::vector<isc::dns::ConstRRsetPtr>* target,
  86. const FindOptions options =
  87. FIND_DEFAULT);
  88. const ZoneData& zone_data_;
  89. const isc::dns::RRClass rrclass_;
  90. };
  91. } // namespace memory
  92. } // namespace datasrc
  93. } // namespace isc
  94. #endif // DATASRC_MEMORY_ZONE_FINDER_H