container.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #include "container.h"
  15. #include "client.h"
  16. #include <memory>
  17. #include <boost/foreach.hpp>
  18. using namespace isc::data;
  19. using namespace std;
  20. namespace isc {
  21. namespace datasrc {
  22. ConfigurableContainer::ConfigurableContainer(const ConstElementPtr&, bool,
  23. const ConstContainerPtr&)
  24. {
  25. // TODO: Implement
  26. }
  27. Container::SearchResult
  28. ConfigurableContainer::search(const dns::Name& name, bool want_exact_match,
  29. bool ) const
  30. {
  31. // Nothing found yet.
  32. // Pointer is used as the SearchResult can't be assigned.
  33. auto_ptr<SearchResult> candidate(new SearchResult());
  34. BOOST_FOREACH(const DataSourceInfo& info, data_sources_) {
  35. // TODO: Once we have support for the caches, consider them too here
  36. // somehow. This would probably get replaced by a function, that
  37. // checks if there's a cache available, if it is, checks the loaded
  38. // zones and zones expected to be in the real data source. If it is
  39. // the cached one, provide the cached one. If it is in the external
  40. // data source, use the datasource and don't provide the finder yet.
  41. DataSourceClient::FindResult result(info.data_src_->findZone(name));
  42. switch (result.code) {
  43. case result::SUCCESS: {
  44. // If we found an exact match, we have no hope to getting
  45. // a better one. Stop right here.
  46. // TODO: In case we have only the datasource and not the finder
  47. // and the need_updater parameter is true, get the zone there.
  48. return (SearchResult(info.data_src_, result.zone_finder,
  49. name.getLabelCount(), true));
  50. }
  51. case result::PARTIALMATCH: {
  52. if (!want_exact_match) {
  53. // In case we have a partial match, check if it is better
  54. // than what we have. If so, replace it.
  55. uint8_t labels(
  56. result.zone_finder->getOrigin().getLabelCount());
  57. if (labels > candidate->matched_labels_) {
  58. // This one is strictly better. Replace it.
  59. candidate.reset(new SearchResult(info.data_src_,
  60. result.zone_finder,
  61. labels, false));
  62. }
  63. }
  64. break;
  65. }
  66. default: {
  67. // Nothing found, nothing to do.
  68. ;
  69. }
  70. }
  71. }
  72. // TODO: In case we have only the datasource and not the finder
  73. // and the need_updater parameter is true, get the zone there.
  74. // Return the partial match we have. In case we didn't want a partial
  75. // match, this surely contains the original empty result.
  76. return (*candidate);
  77. }
  78. }
  79. }