zone_finder.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_finder.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 Search for an RRset of given RR type at the zone origin
  56. /// specialized for in-memory data source.
  57. ///
  58. /// This specialized version exploits internal data structure to find
  59. /// RRsets at the zone origin and (if \c use_minttl is true) extract
  60. /// the SOA Minimum TTL much more efficiently.
  61. virtual boost::shared_ptr<Context> findAtOrigin(
  62. const isc::dns::RRType& type, bool use_minttl,
  63. FindOptions options);
  64. /// \brief Version of find that returns all types at once
  65. ///
  66. /// It acts the same as find, just that when the correct node is found,
  67. /// all the RRsets are filled into the target parameter instead of being
  68. /// returned by the result.
  69. virtual boost::shared_ptr<ZoneFinder::Context> findAll(
  70. const isc::dns::Name& name,
  71. std::vector<isc::dns::ConstRRsetPtr>& target,
  72. const FindOptions options = FIND_DEFAULT);
  73. /// Look for NSEC3 for proving (non)existence of given name.
  74. ///
  75. /// See documentation in \c Zone.
  76. virtual FindNSEC3Result
  77. findNSEC3(const isc::dns::Name& name, bool recursive);
  78. /// \brief Returns the origin of the zone.
  79. virtual isc::dns::Name getOrigin() const;
  80. /// \brief Returns the RR class of the zone.
  81. virtual isc::dns::RRClass getClass() const {
  82. return (rrclass_);
  83. }
  84. private:
  85. /// \brief In-memory version of finder context.
  86. ///
  87. /// The implementation (and any specialized interface) is completely local
  88. /// to the InMemoryZoneFinder class, so it's defined as private
  89. class Context;
  90. /// Actual implementation for both find() and findAll()
  91. internal::ZoneFinderResultContext findInternal(
  92. const isc::dns::Name& name,
  93. const isc::dns::RRType& type,
  94. std::vector<isc::dns::ConstRRsetPtr>* target,
  95. const FindOptions options =
  96. FIND_DEFAULT);
  97. const ZoneData& zone_data_;
  98. const isc::dns::RRClass rrclass_;
  99. };
  100. } // namespace memory
  101. } // namespace datasrc
  102. } // namespace isc
  103. #endif // DATASRC_MEMORY_ZONE_FINDER_H
  104. // Local Variables:
  105. // mode: c++
  106. // End: