container.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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_CONTAINER_H
  15. #define DATASRC_CONTAINER_H
  16. #include <dns/name.h>
  17. #include <boost/shared_ptr.hpp>
  18. #include <boost/noncopyable.hpp>
  19. namespace isc {
  20. namespace datasrc {
  21. class ZoneFinder;
  22. typedef boost::shared_ptr<ZoneFinder> ZoneFinderPtr;
  23. class DataSourceClient;
  24. typedef boost::shared_ptr<DataSourceClient> DataSourceClientPtr;
  25. /// \brief The container of data sources.
  26. ///
  27. /// The purpose of this class is to hold several data sources and search
  28. /// through them to find one containing a zone best matching a request.
  29. ///
  30. /// This is an abstract base class. It is not expected we would use multiple
  31. /// implementation inside the servers (but it is not forbidden either), we
  32. /// have it to allow easy testing. It is possible to create a mock-up class
  33. /// instead of creating a full-blown configuration. The real implementation
  34. /// is the ConfigurableContainer.
  35. class Container : public boost::noncopyable {
  36. protected:
  37. /// \brief Constructur.
  38. ///
  39. /// It is protected to prevent accidental creation of the abstract base
  40. /// class.
  41. Container() {}
  42. public:
  43. /// \brief Structure holding the (compound) result of search.
  44. ///
  45. /// As this is read-only structure, we don't bother to create accessors.
  46. /// Instead, all the member variables are defined as const and can be
  47. /// accessed directly.
  48. struct SearchResult {
  49. /// \brief Constructor.
  50. ///
  51. /// It simply fills in the member variables according to the
  52. /// parameters. See the member descriptions for their meaning.
  53. SearchResult(const DataSourceClientPtr& datasrc,
  54. const ZoneFinderPtr& finder,
  55. uint8_t matched_labels, bool exact_match) :
  56. datasrc_(datasrc),
  57. finder_(finder),
  58. matched_labels_(matched_labels),
  59. exact_match(exact_match)
  60. { }
  61. /// \brief Negative answer constructor.
  62. ///
  63. /// This conscructs a result for negative answer. Both pointers are
  64. /// NULL, matched_labels_ is 0 and exact_match_ is false.
  65. SearchResult() :
  66. matched_labels_(0),
  67. exact_match_(false)
  68. { }
  69. /// \brief The found data source.
  70. ///
  71. /// The data source containing the best matching zone. If no such
  72. /// data source exists, this is NULL pointer.
  73. const DataSourceClientPtr datasrc_;
  74. /// \brief The finder for the requested zone.
  75. ///
  76. /// This is the finder corresponding to the best matching zone.
  77. /// This may be NULL even in case the datasrc_ is something
  78. /// else, depending on the search options.
  79. ///
  80. /// \see search
  81. const ZoneFinderPtr finder_;
  82. /// \brief Number of matching labels.
  83. ///
  84. /// The number of labels the result have in common with the queried
  85. /// name of zone.
  86. const uint8_t matched_labels_;
  87. /// \brief If the result is an exact match.
  88. const bool exact_match_;
  89. };
  90. /// \brief Search for a zone thourgh the data sources.
  91. ///
  92. /// This searches the contained data sources for a one that best matches
  93. /// the zone name.
  94. ///
  95. /// \param zone The name of the zone to search.
  96. /// \param want_exact_match If it is true, it returns only exact matches.
  97. /// If the best possible match is partial, a negative result is
  98. /// returned instead. It is possible the caller could check it and
  99. /// act accordingly if the result would be partial match, but with this
  100. /// set to true, the search might be actually faster under some
  101. /// circumstances.
  102. /// \param want_finder If this is false, the finder_ member of SearchResult
  103. /// might be NULL even if the corresponding data source is found. This
  104. /// is because of performance, in some cases the finder is a side
  105. /// result of the searching algorithm (therefore asking for it again
  106. /// would be a waste), but under other circumstances it is not, so
  107. /// providing it when it is not needed would also be wasteful.
  108. ///
  109. /// Other things are never the side effect of searching, therefore the
  110. /// caller can get them explicitly (the updater, journal reader and
  111. /// iterator).
  112. /// \return A SearchResult describing the data source and zone with the
  113. /// longest match against the zone parameter.
  114. virtual SearchResult search(const dns::Name& zone,
  115. bool want_exact_match = false,
  116. bool want_finder = true) const = 0;
  117. };
  118. class ConfigurableContainer : public Container {
  119. };
  120. } // namespace datasrc
  121. } // namespace isc
  122. #endif // DATASRC_CONTAINER_H