Commit 59b545e9 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[1065] Support for subdomain match

Only in the interface and test implementation for now. The SQLite
version just ignores the parameter for now, will be done soon in this
branch.
parent 7e89c625
......@@ -84,8 +84,14 @@ public:
*
* \param zone_id The zone to search in, as returned by getZone()
* \param name The name of the records to find
* \param subdomains If set to true, match subdomains of name instead
* of name itself. It is used to find empty domains and match
* wildcards.
* \todo Should we return the name as well? If we search for subdomains
* it might be useful (and needed in case of wildcard).
*/
virtual void searchForRecords(int zone_id, const std::string& name) = 0;
virtual void searchForRecords(int zone_id, const std::string& name,
bool subdomains = false) = 0;
/**
* \brief Retrieves the next record from the search started with searchForRecords()
......
......@@ -323,7 +323,7 @@ SQLite3Database::getZone(const isc::dns::Name& name) const {
}
void
SQLite3Database::searchForRecords(int zone_id, const std::string& name) {
SQLite3Database::searchForRecords(int zone_id, const std::string& name, bool) {
resetSearch();
if (sqlite3_bind_int(dbparameters_->q_any_, 1, zone_id) != SQLITE_OK) {
isc_throw(DataSourceError,
......
......@@ -100,8 +100,10 @@ public:
*
* \param zone_id The zone to seach in, as returned by getZone()
* \param name The name to find records for
* \param subdomains Match subdomains instead of the name.
*/
virtual void searchForRecords(int zone_id, const std::string& name);
virtual void searchForRecords(int zone_id, const std::string& name,
bool subdomains = false);
/**
* \brief Retrieve the next record from the search started with
......
......@@ -54,7 +54,9 @@ public:
}
}
virtual void searchForRecords(int zone_id, const std::string& name) {
virtual void searchForRecords(int zone_id, const std::string& name,
bool subdomains)
{
search_running_ = true;
// 'hardcoded' name to trigger exceptions (for testing
......@@ -69,14 +71,29 @@ public:
}
searched_name_ = name;
// we're not aiming for efficiency in this test, simply
// copy the relevant vector from records
cur_record = 0;
if (zone_id == 42) {
if (records.count(name) > 0) {
cur_name = records.find(name)->second;
} else {
if (subdomains) {
cur_name.clear();
// Just walk everything and check if it is a subdomain.
// If it is, just copy all data from there.
for (Domains::iterator i(records.begin()); i != records.end();
++ i) {
Name local(i->first);
if (local.compare(isc::dns::Name(name)).getRelation() ==
isc::dns::NameComparisonResult::SUBDOMAIN) {
cur_name.insert(cur_name.end(), i->second.begin(),
i->second.end());
}
}
} else {
if (records.count(name) > 0) {
// we're not aiming for efficiency in this test, simply
// copy the relevant vector from records
cur_name = records.find(name)->second;
} else {
cur_name.clear();
}
}
} else {
cur_name.clear();
......@@ -119,7 +136,9 @@ public:
return (database_name_);
}
private:
std::map<std::string, std::vector< std::vector<std::string> > > records;
typedef std::map<std::string, std::vector< std::vector<std::string> > >
Domains;
Domains records;
// used as internal index for getNextRecord()
size_t cur_record;
// used as temporary storage after searchForRecord() and during
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment