}
}
-Container::SearchResult
-ConfigurableContainer::search(const dns::Name& name, bool want_exact_match,
- bool) const
+Container::FindResult
+ConfigurableContainer::find(const dns::Name& name, bool want_exact_match,
+ bool) const
{
// Nothing found yet.
- // Pointer is used as the SearchResult can't be assigned.
- auto_ptr<SearchResult> candidate(new SearchResult());
+ // Pointer is used as the FindResult can't be assigned.
+ auto_ptr<FindResult> candidate(new FindResult());
BOOST_FOREACH(const DataSourceInfo& info, data_sources_) {
// TODO: Once we have support for the caches, consider them too here
// TODO: In case we have only the datasource and not the finder
// and the need_updater parameter is true, get the zone there.
- return (SearchResult(info.data_src_, result.zone_finder,
+ return (FindResult(info.data_src_, result.zone_finder,
name.getLabelCount(), true));
}
case result::PARTIALMATCH: {
result.zone_finder->getOrigin().getLabelCount());
if (labels > candidate->matched_labels_) {
// This one is strictly better. Replace it.
- candidate.reset(new SearchResult(info.data_src_,
+ candidate.reset(new FindResult(info.data_src_,
result.zone_finder,
labels, false));
}
/// class.
Container() {}
public:
- /// \brief Structure holding the (compound) result of search.
+ /// \brief Structure holding the (compound) result of find.
///
/// As this is read-only structure, we don't bother to create accessors.
/// Instead, all the member variables are defined as const and can be
/// accessed directly.
- struct SearchResult {
+ struct FindResult {
/// \brief Constructor.
///
/// It simply fills in the member variables according to the
/// parameters. See the member descriptions for their meaning.
- SearchResult(DataSourceClient* datasrc,
- const ZoneFinderPtr& finder,
- uint8_t matched_labels, bool exact_match) :
+ FindResult(DataSourceClient* datasrc,
+ const ZoneFinderPtr& finder,
+ uint8_t matched_labels, bool exact_match) :
datasrc_(datasrc),
finder_(finder),
matched_labels_(matched_labels),
///
/// This conscructs a result for negative answer. Both pointers are
/// NULL, matched_labels_ is 0 and exact_match_ is false.
- SearchResult() :
+ FindResult() :
datasrc_(NULL),
matched_labels_(0),
exact_match_(false)
///
/// It is needed for tests and it might be of some use elsewhere
/// too.
- bool operator ==(const SearchResult& other) const {
+ bool operator ==(const FindResult& other) const {
return (datasrc_ == other.datasrc_ &&
finder_ == other.finder_ &&
matched_labels_ == other.matched_labels_ &&
///
/// This is the finder corresponding to the best matching zone.
/// This may be NULL even in case the datasrc_ is something
- /// else, depending on the search options.
+ /// else, depending on the find options.
///
- /// \see search
+ /// \see find
const ZoneFinderPtr finder_;
/// \brief Number of matching labels.
/// this case, the zone finder is needed and the best matching superzone
/// of the searched name is needed. Therefore, the call would look like:
///
- /// SearchResult result(container->search(queried_name));
+ /// FindResult result(container->find(queried_name));
/// if (result.datasrc_) {
/// createTheAnswer(result.finder_);
/// } else {
/// we need an exact match (if we want to manipulate zone data, we must
/// know exactly, which zone we are about to manipulate). Then the call
///
- /// SearchResult result(container->search(zone_name, true, false));
+ /// FindResult result(container->find(zone_name, true, false));
/// if (result.datasrc_) {
/// ZoneUpdaterPtr updater(result.datasrc_->getUpdater(zone_name);
/// ...
/// }
///
- /// \param zone The name of the zone to search.
+ /// \param zone The name of the zone to look for.
/// \param want_exact_match If it is true, it returns only exact matches.
/// If the best possible match is partial, a negative result is
/// returned instead. It is possible the caller could check it and
/// act accordingly if the result would be partial match, but with this
- /// set to true, the search might be actually faster under some
+ /// set to true, the find might be actually faster under some
/// circumstances.
- /// \param want_finder If this is false, the finder_ member of SearchResult
+ /// \param want_finder If this is false, the finder_ member of FindResult
/// might be NULL even if the corresponding data source is found. This
/// is because of performance, in some cases the finder is a side
/// result of the searching algorithm (therefore asking for it again
/// Other things are never the side effect of searching, therefore the
/// caller can get them explicitly (the updater, journal reader and
/// iterator).
- /// \return A SearchResult describing the data source and zone with the
+ /// \return A FindResult describing the data source and zone with the
/// longest match against the zone parameter.
- virtual SearchResult search(const dns::Name& zone,
- bool want_exact_match = false,
- bool want_finder = true) const = 0;
+ virtual FindResult find(const dns::Name& zone,
+ bool want_exact_match = false,
+ bool want_finder = true) const = 0;
};
/// \brief Shared pointer to the container.
/// sense.
void configure(const data::Element& configuration, bool allow_cache);
- /// \brief Implementation of the Container::search.
- virtual SearchResult search(const dns::Name& zone,
- bool want_exact_match = false,
- bool want_finder = true) const;
+ /// \brief Implementation of the Container::find.
+ virtual FindResult find(const dns::Name& zone,
+ bool want_exact_match = false,
+ bool want_finder = true) const;
/// \brief This holds one data source and corresponding information.
///
}
}
// Check the positive result is as we expect it.
- void positiveResult(const Container::SearchResult& result,
+ void positiveResult(const Container::FindResult& result,
const shared_ptr<TestDS>& dsrc,
const Name& name, bool exact,
const char* test)
EXPECT_TRUE(Element::fromJSON(params)->equals(*ds->configuration_));
}
shared_ptr<TestedContainer> container_;
- const Container::SearchResult negativeResult_;
+ const Container::FindResult negativeResult_;
vector<shared_ptr<TestDS> > ds_;
vector<ConfigurableContainer::DataSourceInfo> ds_info_;
const ConstElementPtr config_elem_;
EXPECT_TRUE(container_->dataSources().empty());
}
-// Check the values returned by a search on an empty container. It should be
+// Check the values returned by a find on an empty container. It should be
// a negative answer (nothing found) no matter if we want an exact or inexact
// match.
TEST_F(ContainerTest, emptySearch) {
// Note: we don't have operator<< for the result class, so we cannot use
// EXPECT_EQ. Same for other similar cases.
- EXPECT_TRUE(negativeResult_ == container_->search(Name("example.org"),
- false, false));
- EXPECT_TRUE(negativeResult_ == container_->search(Name("example.org"),
- false, true));
- EXPECT_TRUE(negativeResult_ == container_->search(Name("example.org"), true,
- false));
- EXPECT_TRUE(negativeResult_ == container_->search(Name("example.org"), true,
- true));
+ EXPECT_TRUE(negativeResult_ == container_->find(Name("example.org"),
+ false, false));
+ EXPECT_TRUE(negativeResult_ == container_->find(Name("example.org"),
+ false, true));
+ EXPECT_TRUE(negativeResult_ == container_->find(Name("example.org"), true,
+ false));
+ EXPECT_TRUE(negativeResult_ == container_->find(Name("example.org"), true,
+ true));
}
// Put a single data source inside the container and check it can find an
TEST_F(ContainerTest, singleDSExactMatch) {
container_->dataSources().push_back(ds_info_[0]);
// This zone is not there
- EXPECT_TRUE(negativeResult_ == container_->search(Name("org."), true));
+ EXPECT_TRUE(negativeResult_ == container_->find(Name("org."), true));
// But this one is, so check it.
- positiveResult(container_->search(Name("example.org"), true),
+ positiveResult(container_->find(Name("example.org"), true),
ds_[0], Name("example.org"), true, "Exact match");
// When asking for a sub zone of a zone there, we get nothing
// (we want exact match, this would be partial one)
- EXPECT_TRUE(negativeResult_ == container_->search(Name("sub.example.org."),
- true));
+ EXPECT_TRUE(negativeResult_ == container_->find(Name("sub.example.org."),
+ true));
}
// When asking for a partial match, we get all that the exact one, but more.
TEST_F(ContainerTest, singleDSBestMatch) {
container_->dataSources().push_back(ds_info_[0]);
// This zone is not there
- EXPECT_TRUE(negativeResult_ == container_->search(Name("org.")));
+ EXPECT_TRUE(negativeResult_ == container_->find(Name("org.")));
// But this one is, so check it.
- positiveResult(container_->search(Name("example.org")),
+ positiveResult(container_->find(Name("example.org")),
ds_[0], Name("example.org"), true, "Exact match");
// When asking for a sub zone of a zone there, we get nothing
// (we want exact match, this would be partial one)
- positiveResult(container_->search(Name("sub.example.org.")),
+ positiveResult(container_->find(Name("sub.example.org.")),
ds_[0], Name("example.org"), false, "Subdomain match");
}
SCOPED_TRACE(test_names[i]);
multiConfiguration(i);
// Something that is nowhere there
- EXPECT_TRUE(negativeResult_ == container_->search(Name("org."), true));
+ EXPECT_TRUE(negativeResult_ == container_->find(Name("org."), true));
// This one is there exactly.
- positiveResult(container_->search(Name("example.org"), true),
+ positiveResult(container_->find(Name("example.org"), true),
ds_[0], Name("example.org"), true, "Exact match");
// This one too, but in a different data source.
- positiveResult(container_->search(Name("sub.example.org."), true),
+ positiveResult(container_->find(Name("sub.example.org."), true),
ds_[1], Name("sub.example.org"), true,
"Subdomain match");
// But this one is in neither data source.
EXPECT_TRUE(negativeResult_ ==
- container_->search(Name("sub.example.com."), true));
+ container_->find(Name("sub.example.com."), true));
}
}
SCOPED_TRACE(test_names[i]);
multiConfiguration(i);
// Something that is nowhere there
- EXPECT_TRUE(negativeResult_ == container_->search(Name("org.")));
+ EXPECT_TRUE(negativeResult_ == container_->find(Name("org.")));
// This one is there exactly.
- positiveResult(container_->search(Name("example.org")),
+ positiveResult(container_->find(Name("example.org")),
ds_[0], Name("example.org"), true, "Exact match");
// This one too, but in a different data source.
- positiveResult(container_->search(Name("sub.example.org.")),
+ positiveResult(container_->find(Name("sub.example.org.")),
ds_[1], Name("sub.example.org"), true,
"Subdomain match");
// But this one is in neither data source. But it is a subdomain
// of one of the zones in the first data source.
- positiveResult(container_->search(Name("sub.example.com.")),
+ positiveResult(container_->find(Name("sub.example.com.")),
ds_[0], Name("example.com."), false,
"Subdomain in com");
}