Commit 1921e129 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[1174] use std::string instead of Name for getZone()

parent 872bd575
......@@ -49,7 +49,7 @@ DatabaseClient::DatabaseClient(boost::shared_ptr<DatabaseAccessor>
DataSourceClient::FindResult
DatabaseClient::findZone(const Name& name) const {
std::pair<bool, int> zone(database_->getZone(name));
std::pair<bool, int> zone(database_->getZone(name.toText()));
// Try exact first
if (zone.first) {
return (FindResult(result::SUCCESS,
......@@ -60,7 +60,7 @@ DatabaseClient::findZone(const Name& name) const {
// Start from 1, as 0 is covered above
for (size_t i(1); i < name.getLabelCount(); ++i) {
isc::dns::Name superdomain(name.split(i));
zone = database_->getZone(superdomain);
zone = database_->getZone(superdomain.toText());
if (zone.first) {
return (FindResult(result::PARTIALMATCH,
ZoneFinderPtr(new Finder(database_,
......@@ -472,7 +472,7 @@ private:
ZoneIteratorPtr
DatabaseClient::getIterator(const isc::dns::Name& name) const {
// Get the zone
std::pair<bool, int> zone(database_->getZone(name));
std::pair<bool, int> zone(database_->getZone(name.toText()));
if (!zone.first) {
// No such zone, can't continue
isc_throw(DataSourceError, "Zone " + name.toText() +
......
......@@ -88,7 +88,8 @@ public:
* It is not specified if and what implementation of this method may throw,
* so code should expect anything.
*
* \param name The name of the zone's apex to be looked up.
* \param name The (fully qualified) domain name of the zone's apex to be
* looked up.
* \return The first part of the result indicates if a matching zone
* was found. In case it was, the second part is internal zone ID.
* This one will be passed to methods finding data in the zone.
......@@ -96,7 +97,7 @@ public:
* be returned - the ID is only passed back to the database as
* an opaque handle.
*/
virtual std::pair<bool, int> getZone(const isc::dns::Name& name) const = 0;
virtual std::pair<bool, int> getZone(const std::string& name) const = 0;
/**
* \brief This holds the internal context of ZoneIterator for databases
......
......@@ -288,14 +288,14 @@ SQLite3Database::close(void) {
}
std::pair<bool, int>
SQLite3Database::getZone(const isc::dns::Name& name) const {
SQLite3Database::getZone(const std::string& name) const {
int rc;
// Take the statement (simple SELECT id FROM zones WHERE...)
// and prepare it (bind the parameters to it)
sqlite3_reset(dbparameters_->q_zone_);
rc = sqlite3_bind_text(dbparameters_->q_zone_, 1, name.toText().c_str(),
-1, SQLITE_TRANSIENT);
rc = sqlite3_bind_text(dbparameters_->q_zone_, 1, name.c_str(),
-1, SQLITE_STATIC);
if (rc != SQLITE_OK) {
isc_throw(SQLite3Error, "Could not bind " << name <<
" to SQL statement (zone)");
......
......@@ -87,11 +87,11 @@ public:
*
* \exception SQLite3Error if something about the database is broken.
*
* \param name The name of zone to look up
* \param name The (fully qualified) domain name of zone to look up
* \return The pair contains if the lookup was successful in the first
* element and the zone id in the second if it was.
*/
virtual std::pair<bool, int> getZone(const isc::dns::Name& name) const;
virtual std::pair<bool, int> getZone(const std::string& name) const;
/** \brief Look up all resource records for a name
*
......
......@@ -44,14 +44,14 @@ public:
NopAccessor() : database_name_("mock_database")
{ }
virtual std::pair<bool, int> getZone(const Name& name) const {
if (name == Name("example.org")) {
virtual std::pair<bool, int> getZone(const std::string& name) const {
if (name == "example.org.") {
return (std::pair<bool, int>(true, 42));
} else if (name == Name("null.example.org")) {
} else if (name == "null.example.org.") {
return (std::pair<bool, int>(true, 13));
} else if (name == Name("empty.example.org")) {
} else if (name == "empty.example.org.") {
return (std::pair<bool, int>(true, 0));
} else if (name == Name("bad.example.org")) {
} else if (name == "bad.example.org.") {
return (std::pair<bool, int>(true, -1));
} else {
return (std::pair<bool, int>(false, 0));
......
......@@ -83,25 +83,25 @@ public:
// This zone exists in the data, so it should be found
TEST_F(SQLite3Access, getZone) {
std::pair<bool, int> result(db->getZone(Name("example.com")));
std::pair<bool, int> result(db->getZone("example.com."));
EXPECT_TRUE(result.first);
EXPECT_EQ(1, result.second);
}
// But it should find only the zone, nothing below it
TEST_F(SQLite3Access, subZone) {
EXPECT_FALSE(db->getZone(Name("sub.example.com")).first);
EXPECT_FALSE(db->getZone("sub.example.com.").first);
}
// This zone is not there at all
TEST_F(SQLite3Access, noZone) {
EXPECT_FALSE(db->getZone(Name("example.org")).first);
EXPECT_FALSE(db->getZone("example.org.").first);
}
// This zone is there, but in different class
TEST_F(SQLite3Access, noClass) {
initAccessor(SQLITE_DBFILE_EXAMPLE, RRClass::CH());
EXPECT_FALSE(db->getZone(Name("example.com")).first);
EXPECT_FALSE(db->getZone("example.com.").first);
}
// This tests the iterator context
......@@ -109,7 +109,7 @@ TEST_F(SQLite3Access, iterator) {
// Our test zone is conveniently small, but not empty
initAccessor(SQLITE_DBFILE_EXAMPLE_ORG, RRClass::IN());
const std::pair<bool, int> zone_info(db->getZone(Name("example.org")));
const std::pair<bool, int> zone_info(db->getZone("example.org."));
ASSERT_TRUE(zone_info.first);
// Get the iterator context
......@@ -223,7 +223,7 @@ checkRecordRow(const std::string columns[],
}
TEST_F(SQLite3Access, getRecords) {
const std::pair<bool, int> zone_info(db->getZone(Name("example.com")));
const std::pair<bool, int> zone_info(db->getZone("example.com."));
ASSERT_TRUE(zone_info.first);
const int zone_id = zone_info.second;
......
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