BIND 10 trac1062, updated. d719b47c4131e2120305cee60395c0a88f5aca25 [1062] needed to make a few const ZoneFinder args nonconst
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Aug 11 16:45:53 UTC 2011
The branch, trac1062 has been updated
via d719b47c4131e2120305cee60395c0a88f5aca25 (commit)
via ac15a86eb62832cc22533bc33b802ea297666ad5 (commit)
via b19a36e30d0d3829c68f2e0300ea1487da242af8 (commit)
via 12b3473393fb7a471fc7d928476b0ba66da145e9 (commit)
from cfd1d9e142fa2fd8b21f74de0e4a0109e0a04439 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit d719b47c4131e2120305cee60395c0a88f5aca25
Author: Jelte Jansen <jelte at isc.org>
Date: Thu Aug 11 18:02:27 2011 +0200
[1062] needed to make a few const ZoneFinder args nonconst
commit ac15a86eb62832cc22533bc33b802ea297666ad5
Author: Jelte Jansen <jelte at isc.org>
Date: Thu Aug 11 17:31:06 2011 +0200
[1062] rest of the review comments
commit b19a36e30d0d3829c68f2e0300ea1487da242af8
Author: Jelte Jansen <jelte at isc.org>
Date: Thu Aug 11 13:09:12 2011 +0200
[1062] added getDBName to DatabaseConnection
and add database name to logging output
commit 12b3473393fb7a471fc7d928476b0ba66da145e9
Author: Jelte Jansen <jelte at isc.org>
Date: Thu Aug 11 11:39:28 2011 +0200
[1062] unconst find()
-----------------------------------------------------------------------
Summary of changes:
src/bin/auth/query.cc | 8 +-
src/bin/auth/query.h | 8 +-
src/bin/auth/tests/query_unittest.cc | 4 +-
src/lib/datasrc/database.cc | 28 ++-
src/lib/datasrc/database.h | 19 ++-
src/lib/datasrc/datasrc_messages.mes | 13 +-
src/lib/datasrc/memory_datasrc.cc | 2 +-
src/lib/datasrc/memory_datasrc.h | 2 +-
src/lib/datasrc/sqlite3_connection.cc | 80 +++++----
src/lib/datasrc/sqlite3_connection.h | 3 +
src/lib/datasrc/tests/database_unittest.cc | 208 +++++++++++++++++---
.../datasrc/tests/sqlite3_connection_unittest.cc | 15 ++-
src/lib/datasrc/zone.h | 2 +-
src/lib/util/filename.h | 5 +
src/lib/util/tests/filename_unittest.cc | 15 ++
15 files changed, 313 insertions(+), 99 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/auth/query.cc b/src/bin/auth/query.cc
index 05bcd89..3fe03c8 100644
--- a/src/bin/auth/query.cc
+++ b/src/bin/auth/query.cc
@@ -31,7 +31,7 @@ namespace isc {
namespace auth {
void
-Query::getAdditional(const ZoneFinder& zone, const RRset& rrset) const {
+Query::getAdditional(ZoneFinder& zone, const RRset& rrset) const {
RdataIteratorPtr rdata_iterator(rrset.getRdataIterator());
for (; !rdata_iterator->isLast(); rdata_iterator->next()) {
const Rdata& rdata(rdata_iterator->getCurrent());
@@ -47,7 +47,7 @@ Query::getAdditional(const ZoneFinder& zone, const RRset& rrset) const {
}
void
-Query::findAddrs(const ZoneFinder& zone, const Name& qname,
+Query::findAddrs(ZoneFinder& zone, const Name& qname,
const ZoneFinder::FindOptions options) const
{
// Out of zone name
@@ -86,7 +86,7 @@ Query::findAddrs(const ZoneFinder& zone, const Name& qname,
}
void
-Query::putSOA(const ZoneFinder& zone) const {
+Query::putSOA(ZoneFinder& zone) const {
ZoneFinder::FindResult soa_result(zone.find(zone.getOrigin(),
RRType::SOA()));
if (soa_result.code != ZoneFinder::SUCCESS) {
@@ -104,7 +104,7 @@ Query::putSOA(const ZoneFinder& zone) const {
}
void
-Query::getAuthAdditional(const ZoneFinder& zone) const {
+Query::getAuthAdditional(ZoneFinder& zone) const {
// Fill in authority and addtional sections.
ZoneFinder::FindResult ns_result = zone.find(zone.getOrigin(),
RRType::NS());
diff --git a/src/bin/auth/query.h b/src/bin/auth/query.h
index fa023fe..13523e8 100644
--- a/src/bin/auth/query.h
+++ b/src/bin/auth/query.h
@@ -69,7 +69,7 @@ private:
/// Adds a SOA of the zone into the authority zone of response_.
/// Can throw NoSOA.
///
- void putSOA(const isc::datasrc::ZoneFinder& zone) const;
+ void putSOA(isc::datasrc::ZoneFinder& zone) const;
/// \brief Look up additional data (i.e., address records for the names
/// included in NS or MX records).
@@ -85,7 +85,7 @@ private:
/// query is to be found.
/// \param rrset The RRset (i.e., NS or MX rrset) which require additional
/// processing.
- void getAdditional(const isc::datasrc::ZoneFinder& zone,
+ void getAdditional(isc::datasrc::ZoneFinder& zone,
const isc::dns::RRset& rrset) const;
/// \brief Find address records for a specified name.
@@ -104,7 +104,7 @@ private:
/// be found.
/// \param qname The name in rrset RDATA.
/// \param options The search options.
- void findAddrs(const isc::datasrc::ZoneFinder& zone,
+ void findAddrs(isc::datasrc::ZoneFinder& zone,
const isc::dns::Name& qname,
const isc::datasrc::ZoneFinder::FindOptions options
= isc::datasrc::ZoneFinder::FIND_DEFAULT) const;
@@ -127,7 +127,7 @@ private:
///
/// \param zone The \c ZoneFinder through which the NS and additional data
/// for the query are to be found.
- void getAuthAdditional(const isc::datasrc::ZoneFinder& zone) const;
+ void getAuthAdditional(isc::datasrc::ZoneFinder& zone) const;
public:
/// Constructor from query parameters.
diff --git a/src/bin/auth/tests/query_unittest.cc b/src/bin/auth/tests/query_unittest.cc
index 9ef8c13..68f0a1d 100644
--- a/src/bin/auth/tests/query_unittest.cc
+++ b/src/bin/auth/tests/query_unittest.cc
@@ -127,7 +127,7 @@ public:
virtual FindResult find(const isc::dns::Name& name,
const isc::dns::RRType& type,
RRsetList* target = NULL,
- const FindOptions options = FIND_DEFAULT) const;
+ const FindOptions options = FIND_DEFAULT);
// If false is passed, it makes the zone broken as if it didn't have the
// SOA.
@@ -165,7 +165,7 @@ private:
ZoneFinder::FindResult
MockZoneFinder::find(const Name& name, const RRType& type,
- RRsetList* target, const FindOptions options) const
+ RRsetList* target, const FindOptions options)
{
// Emulating a broken zone: mandatory apex RRs are missing if specifically
// configured so (which are rare cases).
diff --git a/src/lib/datasrc/database.cc b/src/lib/datasrc/database.cc
index abd979c..7bbf285 100644
--- a/src/lib/datasrc/database.cc
+++ b/src/lib/datasrc/database.cc
@@ -93,11 +93,15 @@ void addOrCreate(isc::dns::RRsetPtr& rrset,
if (!rrset) {
rrset.reset(new isc::dns::RRset(name, cls, type, ttl));
} else {
- if (ttl < rrset->getTTL()) {
- rrset->setTTL(ttl);
- }
// This is a check to make sure find() is not messing things up
assert(type == rrset->getType());
+ if (ttl != rrset->getTTL()) {
+ if (ttl < rrset->getTTL()) {
+ rrset->setTTL(ttl);
+ }
+ logger.info(DATASRC_DATABASE_FIND_TTL_MISMATCH)
+ .arg(name).arg(cls).arg(type).arg(rrset->getTTL());
+ }
}
try {
rrset->addRdata(isc::dns::rdata::createRdata(type, cls, rdata_str));
@@ -156,7 +160,7 @@ ZoneFinder::FindResult
DatabaseClient::Finder::find(const isc::dns::Name& name,
const isc::dns::RRType& type,
isc::dns::RRsetList*,
- const FindOptions) const
+ const FindOptions)
{
// This variable is used to determine the difference between
// NXDOMAIN and NXRRSET
@@ -164,14 +168,15 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
isc::dns::RRsetPtr result_rrset;
ZoneFinder::Result result_status = SUCCESS;
RRsigStore sig_store;
- logger.debug(DBG_TRACE_DETAILED, DATASRC_DATABASE_FIND_RECORDS).arg(name).arg(type);
+ logger.debug(DBG_TRACE_DETAILED, DATASRC_DATABASE_FIND_RECORDS)
+ .arg(connection_->getDBName()).arg(name).arg(type);
try {
connection_->searchForRecords(zone_id_, name.toText());
- std::string columns[DatabaseConnection::RecordColumnCount];
+ std::string columns[DatabaseConnection::RECORDCOLUMNCOUNT];
while (connection_->getNextRecord(columns,
- DatabaseConnection::RecordColumnCount)) {
+ DatabaseConnection::RECORDCOLUMNCOUNT)) {
if (!records_found) {
records_found = true;
}
@@ -233,17 +238,20 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
}
}
} catch (const DataSourceError& dse) {
- logger.error(DATASRC_DATABASE_FIND_ERROR).arg(dse.what());
+ logger.error(DATASRC_DATABASE_FIND_ERROR)
+ .arg(connection_->getDBName()).arg(dse.what());
// call cleanup and rethrow
connection_->resetSearch();
throw;
} catch (const isc::Exception& isce) {
- logger.error(DATASRC_DATABASE_FIND_UNCAUGHT_ISC_ERROR).arg(isce.what());
+ logger.error(DATASRC_DATABASE_FIND_UNCAUGHT_ISC_ERROR)
+ .arg(connection_->getDBName()).arg(isce.what());
// cleanup, change it to a DataSourceError and rethrow
connection_->resetSearch();
isc_throw(DataSourceError, isce.what());
} catch (const std::exception& ex) {
- logger.error(DATASRC_DATABASE_FIND_UNCAUGHT_ERROR).arg(ex.what());
+ logger.error(DATASRC_DATABASE_FIND_UNCAUGHT_ERROR)
+ .arg(connection_->getDBName()).arg(ex.what());
connection_->resetSearch();
throw;
}
diff --git a/src/lib/datasrc/database.h b/src/lib/datasrc/database.h
index 4ad3f49..4a28b7c 100644
--- a/src/lib/datasrc/database.h
+++ b/src/lib/datasrc/database.h
@@ -93,7 +93,7 @@ public:
* In the case of a database error, a DatasourceError is thrown.
*
* The columns passed is an array of std::strings consisting of
- * DatabaseConnection::RecordColumnCount elements, the elements of which
+ * DatabaseConnection::RECORDCOLUMNCOUNT elements, the elements of which
* are defined in DatabaseConnection::RecordColumns, in their basic
* string representation.
*
@@ -146,7 +146,18 @@ public:
};
/// The number of fields the columns array passed to getNextRecord should have
- static const size_t RecordColumnCount = 4;
+ static const size_t RECORDCOLUMNCOUNT = 4;
+
+ /**
+ * \brief Returns a string identifying this dabase backend
+ *
+ * Any implementation is free to choose the exact string content,
+ * but it is advisable to make it a name that is distinguishable
+ * from the others.
+ *
+ * \return the name of the dabase
+ */
+ virtual const std::string& getDBName() const = 0;
};
/**
@@ -236,8 +247,7 @@ public:
virtual FindResult find(const isc::dns::Name& name,
const isc::dns::RRType& type,
isc::dns::RRsetList* target = NULL,
- const FindOptions options = FIND_DEFAULT)
- const;
+ const FindOptions options = FIND_DEFAULT);
/**
* \brief The zone ID
@@ -274,6 +284,7 @@ public:
* returned, though.
*/
virtual FindResult findZone(const isc::dns::Name& name) const;
+
private:
/// \brief Our connection.
const boost::shared_ptr<DatabaseConnection> connection_;
diff --git a/src/lib/datasrc/datasrc_messages.mes b/src/lib/datasrc/datasrc_messages.mes
index af704d9..5a63b0d 100644
--- a/src/lib/datasrc/datasrc_messages.mes
+++ b/src/lib/datasrc/datasrc_messages.mes
@@ -63,23 +63,28 @@ The maximum allowed number of items of the hotspot cache is set to the given
number. If there are too many, some of them will be dropped. The size of 0
means no limit.
-% DATASRC_DATABASE_FIND_ERROR error retrieving data from database datasource: %1
+% DATASRC_DATABASE_FIND_ERROR error retrieving data from datasource %1: %2
The was an internal error while reading data from a datasource. This can either
mean the specific data source implementation is not behaving correctly, or the
data it provides is invalid. The current search is aborted.
The error message contains specific information about the error.
-% DATASRC_DATABASE_FIND_RECORDS looking for record %1/%2
+% DATASRC_DATABASE_FIND_RECORDS looking in datasource %1 for record %2/%3
Debug information. The database data source is looking up records with the given
name and type in the database.
-% DATASRC_DATABASE_FIND_UNCAUGHT_ERROR uncaught general error retrieving data from database datasource: %1
+% DATASRC_DATABASE_FIND_TTL_MISMATCH TTL values differ for elements of %1/%2/%3, setting to %4
+The datasource backend provided resource records for the given RRset with
+different TTL values. The TTL of the RRSET is set to the lowest value, which
+is printed in the log message.
+
+% DATASRC_DATABASE_FIND_UNCAUGHT_ERROR uncaught general error retrieving data from datasource %1: %2
There was an uncaught general exception while reading data from a datasource.
This most likely points to a logic error in the code, and can be considered a
bug. The current search is aborted. Specific information about the exception is
printed in this error message.
-% DATASRC_DATABASE_FIND_UNCAUGHT_ISC_ERROR uncaught error retrieving data from database datasource: %1
+% DATASRC_DATABASE_FIND_UNCAUGHT_ISC_ERROR uncaught error retrieving data from datasource %1: %2
There was an uncaught ISC exception while reading data from a datasource. This
most likely points to a logic error in the code, and can be considered a bug.
The current search is aborted. Specific information about the exception is
diff --git a/src/lib/datasrc/memory_datasrc.cc b/src/lib/datasrc/memory_datasrc.cc
index 26223da..d06cd9b 100644
--- a/src/lib/datasrc/memory_datasrc.cc
+++ b/src/lib/datasrc/memory_datasrc.cc
@@ -618,7 +618,7 @@ InMemoryZoneFinder::getClass() const {
ZoneFinder::FindResult
InMemoryZoneFinder::find(const Name& name, const RRType& type,
- RRsetList* target, const FindOptions options) const
+ RRsetList* target, const FindOptions options)
{
return (impl_->find(name, type, target, options));
}
diff --git a/src/lib/datasrc/memory_datasrc.h b/src/lib/datasrc/memory_datasrc.h
index 9707797..0234a91 100644
--- a/src/lib/datasrc/memory_datasrc.h
+++ b/src/lib/datasrc/memory_datasrc.h
@@ -73,7 +73,7 @@ public:
virtual FindResult find(const isc::dns::Name& name,
const isc::dns::RRType& type,
isc::dns::RRsetList* target = NULL,
- const FindOptions options = FIND_DEFAULT) const;
+ const FindOptions options = FIND_DEFAULT);
/// \brief Inserts an rrset into the zone.
///
diff --git a/src/lib/datasrc/sqlite3_connection.cc b/src/lib/datasrc/sqlite3_connection.cc
index acba0e6..4fd4800 100644
--- a/src/lib/datasrc/sqlite3_connection.cc
+++ b/src/lib/datasrc/sqlite3_connection.cc
@@ -17,6 +17,7 @@
#include <datasrc/sqlite3_connection.h>
#include <datasrc/logger.h>
#include <datasrc/data_source.h>
+#include <util/filename.h>
namespace isc {
namespace datasrc {
@@ -48,7 +49,9 @@ struct SQLite3Parameters {
SQLite3Connection::SQLite3Connection(const std::string& filename,
const isc::dns::RRClass& rrclass) :
dbparameters_(new SQLite3Parameters),
- class_(rrclass.toText())
+ class_(rrclass.toText()),
+ database_name_("sqlite3_" +
+ isc::util::Filename(filename).nameAndExtension())
{
LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_SQLITE_NEWCONN);
@@ -322,21 +325,17 @@ SQLite3Connection::getZone(const isc::dns::Name& name) const {
void
SQLite3Connection::searchForRecords(int zone_id, const std::string& name) {
resetSearch();
- int result;
- result = sqlite3_bind_int(dbparameters_->q_any_, 1, zone_id);
- if (result != SQLITE_OK) {
+ if (sqlite3_bind_int(dbparameters_->q_any_, 1, zone_id) != SQLITE_OK) {
isc_throw(DataSourceError,
"Error in sqlite3_bind_int() for zone_id " <<
- zone_id << ", sqlite3 result code: " << result);
+ zone_id << ": " << sqlite3_errmsg(dbparameters_->db_));
}
-
// use transient since name is a ref and may disappear
- result = sqlite3_bind_text(dbparameters_->q_any_, 2, name.c_str(), -1,
- SQLITE_TRANSIENT);
- if (result != SQLITE_OK) {
+ if (sqlite3_bind_text(dbparameters_->q_any_, 2, name.c_str(), -1,
+ SQLITE_TRANSIENT) != SQLITE_OK) {
isc_throw(DataSourceError,
"Error in sqlite3_bind_text() for name " <<
- name << ", sqlite3 result code: " << result);
+ name << ": " << sqlite3_errmsg(dbparameters_->db_));
}
}
@@ -346,10 +345,23 @@ namespace {
// might not be directly convertable
// In case sqlite3_column_text() returns NULL, we just make it an
// empty string.
+// The sqlite3parameters value is only used to check the error code if
+// ucp == NULL
const char*
-convertToPlainChar(const unsigned char* ucp) {
+convertToPlainChar(const unsigned char* ucp,
+ SQLite3Parameters* dbparameters) {
if (ucp == NULL) {
- return ("");
+ // The field can really be NULL, in which case we return an
+ // empty string, or sqlite may have run out of memory, in
+ // which case we raise an error
+ if (dbparameters &&
+ sqlite3_errcode(dbparameters->db_) == SQLITE_NOMEM) {
+ isc_throw(DataSourceError,
+ "Sqlite3 backend encountered a memory allocation "
+ "error in sqlite3_column_text()");
+ } else {
+ return ("");
+ }
}
const void* p = ucp;
return (static_cast<const char*>(p));
@@ -358,35 +370,35 @@ convertToPlainChar(const unsigned char* ucp) {
bool
SQLite3Connection::getNextRecord(std::string columns[], size_t column_count) {
- try {
- sqlite3_stmt* current_stmt = dbparameters_->q_any_;
- const int rc = sqlite3_step(current_stmt);
+ if (column_count != RECORDCOLUMNCOUNT) {
+ isc_throw(DataSourceError,
+ "Datasource backend caller did not pass a column array "
+ "of size " << RECORDCOLUMNCOUNT <<
+ " to getNextRecord()");
+ }
- if (column_count != RecordColumnCount) {
- isc_throw(DataSourceError,
- "Datasource backend caller did not pass a column array "
- "of size " << RecordColumnCount <<
- " to getNextRecord()");
- }
+ sqlite3_stmt* current_stmt = dbparameters_->q_any_;
+ const int rc = sqlite3_step(current_stmt);
- if (rc == SQLITE_ROW) {
- for (int column = 0; column < column_count; ++column) {
+ if (rc == SQLITE_ROW) {
+ for (int column = 0; column < column_count; ++column) {
+ try {
columns[column] = convertToPlainChar(sqlite3_column_text(
- current_stmt, column));
+ current_stmt, column),
+ dbparameters_);
+ } catch (const std::bad_alloc&) {
+ isc_throw(DataSourceError,
+ "bad_alloc in Sqlite3Connection::getNextRecord");
}
- return (true);
- } else if (rc == SQLITE_DONE) {
- // reached the end of matching rows
- resetSearch();
- return (false);
}
+ return (true);
+ } else if (rc == SQLITE_DONE) {
+ // reached the end of matching rows
resetSearch();
- isc_throw(DataSourceError,
- "Unexpected failure in sqlite3_step (sqlite result code " << rc << ")");
- } catch (const std::bad_alloc&) {
- isc_throw(DataSourceError,
- "bad_alloc in Sqlite3Connection::getNextRecord");
+ return (false);
}
+ isc_throw(DataSourceError, "Unexpected failure in sqlite3_step: " <<
+ sqlite3_errmsg(dbparameters_->db_));
// Compilers might not realize isc_throw always throws
return (false);
}
diff --git a/src/lib/datasrc/sqlite3_connection.h b/src/lib/datasrc/sqlite3_connection.h
index d41b814..8c38b8a 100644
--- a/src/lib/datasrc/sqlite3_connection.h
+++ b/src/lib/datasrc/sqlite3_connection.h
@@ -135,6 +135,8 @@ public:
*/
virtual void resetSearch();
+ virtual const std::string& getDBName() const { return database_name_; }
+
private:
/// \brief Private database data
SQLite3Parameters* dbparameters_;
@@ -144,6 +146,7 @@ private:
void open(const std::string& filename);
/// \brief Closes the database
void close();
+ const std::string database_name_;
};
}
diff --git a/src/lib/datasrc/tests/database_unittest.cc b/src/lib/datasrc/tests/database_unittest.cc
index 8cfbb08..609ab6a 100644
--- a/src/lib/datasrc/tests/database_unittest.cc
+++ b/src/lib/datasrc/tests/database_unittest.cc
@@ -16,12 +16,15 @@
#include <dns/name.h>
#include <dns/rrttl.h>
+#include <dns/rrset.h>
#include <exceptions/exceptions.h>
#include <datasrc/database.h>
#include <datasrc/zone.h>
#include <datasrc/data_source.h>
+#include <testutils/dnsmessage_test.h>
+
#include <map>
using namespace isc::datasrc;
@@ -37,7 +40,11 @@ namespace {
*/
class MockConnection : public DatabaseConnection {
public:
- MockConnection() : search_running_(false) { fillData(); }
+ MockConnection() : search_running_(false),
+ database_name_("mock_database")
+ {
+ fillData();
+ }
virtual std::pair<bool, int> getZone(const Name& name) const {
if (name == Name("example.org")) {
@@ -85,7 +92,7 @@ public:
throw std::exception();
}
- if (column_count != DatabaseConnection::RecordColumnCount) {
+ if (column_count != DatabaseConnection::RECORDCOLUMNCOUNT) {
isc_throw(DataSourceError, "Wrong column count in getNextRecord");
}
if (cur_record < cur_name.size()) {
@@ -108,6 +115,9 @@ public:
return (search_running_);
}
+ virtual const std::string& getDBName() const {
+ return database_name_;
+ }
private:
std::map<std::string, std::vector< std::vector<std::string> > > records;
// used as internal index for getNextRecord()
@@ -125,6 +135,8 @@ private:
// hardcode some exceptions into getNextRecord
std::string searched_name_;
+ const std::string database_name_;
+
// Adds one record to the current name in the database
// The actual data will not be added to 'records' until
// addCurName() is called
@@ -271,6 +283,8 @@ public:
// Will be deleted by client_, just keep the current value for comparison.
MockConnection* current_connection_;
shared_ptr<DatabaseClient> client_;
+ const std::string database_name_;
+
/**
* Check the zone finder is a valid one and references the zone ID and
* connection available here.
@@ -317,18 +331,31 @@ doFindTest(shared_ptr<DatabaseClient::Finder> finder,
const isc::dns::RRType& expected_type,
const isc::dns::RRTTL expected_ttl,
ZoneFinder::Result expected_result,
- unsigned int expected_rdata_count,
- unsigned int expected_signature_count)
+ const std::vector<std::string>& expected_rdatas,
+ const std::vector<std::string>& expected_sig_rdatas)
{
ZoneFinder::FindResult result =
finder->find(name, type, NULL, ZoneFinder::FIND_DEFAULT);
ASSERT_EQ(expected_result, result.code) << name << " " << type;
- if (expected_rdata_count > 0) {
- EXPECT_EQ(expected_rdata_count, result.rrset->getRdataCount());
+ if (expected_rdatas.size() > 0) {
+ EXPECT_EQ(expected_rdatas.size(), result.rrset->getRdataCount());
EXPECT_EQ(expected_ttl, result.rrset->getTTL());
EXPECT_EQ(expected_type, result.rrset->getType());
- if (expected_signature_count > 0) {
- EXPECT_EQ(expected_signature_count,
+
+ isc::dns::RRsetPtr expected_rrset(
+ new isc::dns::RRset(name, finder->getClass(),
+ expected_type, expected_ttl));
+ for (unsigned int i = 0; i < expected_rdatas.size(); ++i) {
+ expected_rrset->addRdata(
+ isc::dns::rdata::createRdata(expected_type,
+ finder->getClass(),
+ expected_rdatas[i]));
+ }
+ isc::testutils::rrsetCheck(expected_rrset, result.rrset);
+
+ if (expected_sig_rdatas.size() > 0) {
+ // TODO same for sigrrset
+ EXPECT_EQ(expected_sig_rdatas.size(),
result.rrset->getRRsig()->getRdataCount());
} else {
EXPECT_EQ(isc::dns::RRsetPtr(), result.rrset->getRRsig());
@@ -346,110 +373,224 @@ TEST_F(DatabaseClientTest, find) {
dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder));
EXPECT_EQ(42, finder->zone_id());
EXPECT_FALSE(current_connection_->searchRunning());
+ std::vector<std::string> expected_rdatas;
+ std::vector<std::string> expected_sig_rdatas;
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
+ expected_rdatas.push_back("192.0.2.1");
doFindTest(finder, isc::dns::Name("www.example.org."),
isc::dns::RRType::A(), isc::dns::RRType::A(),
isc::dns::RRTTL(3600),
- ZoneFinder::SUCCESS, 1, 0);
+ ZoneFinder::SUCCESS,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
+ expected_rdatas.push_back("192.0.2.1");
+ expected_rdatas.push_back("192.0.2.2");
doFindTest(finder, isc::dns::Name("www2.example.org."),
isc::dns::RRType::A(), isc::dns::RRType::A(),
isc::dns::RRTTL(3600),
- ZoneFinder::SUCCESS, 2, 0);
+ ZoneFinder::SUCCESS,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
+ expected_rdatas.push_back("2001:db8::1");
+ expected_rdatas.push_back("2001:db8::2");
doFindTest(finder, isc::dns::Name("www.example.org."),
isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
isc::dns::RRTTL(3600),
- ZoneFinder::SUCCESS, 2, 0);
+ ZoneFinder::SUCCESS,
+ expected_rdatas, expected_sig_rdatas);
+ EXPECT_FALSE(current_connection_->searchRunning());
+
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
doFindTest(finder, isc::dns::Name("www.example.org."),
isc::dns::RRType::TXT(), isc::dns::RRType::TXT(),
isc::dns::RRTTL(3600),
- ZoneFinder::NXRRSET, 0, 0);
+ ZoneFinder::NXRRSET,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
+ expected_rdatas.push_back("www.example.org.");
doFindTest(finder, isc::dns::Name("cname.example.org."),
isc::dns::RRType::A(), isc::dns::RRType::CNAME(),
isc::dns::RRTTL(3600),
- ZoneFinder::CNAME, 1, 0);
+ ZoneFinder::CNAME,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
+ expected_rdatas.push_back("www.example.org.");
doFindTest(finder, isc::dns::Name("cname.example.org."),
isc::dns::RRType::CNAME(), isc::dns::RRType::CNAME(),
isc::dns::RRTTL(3600),
- ZoneFinder::SUCCESS, 1, 0);
+ ZoneFinder::SUCCESS,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
doFindTest(finder, isc::dns::Name("doesnotexist.example.org."),
isc::dns::RRType::A(), isc::dns::RRType::A(),
isc::dns::RRTTL(3600),
- ZoneFinder::NXDOMAIN, 0, 0);
+ ZoneFinder::NXDOMAIN,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
+ expected_rdatas.push_back("192.0.2.1");
+ expected_sig_rdatas.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
+ expected_sig_rdatas.push_back("A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE");
doFindTest(finder, isc::dns::Name("signed1.example.org."),
isc::dns::RRType::A(), isc::dns::RRType::A(),
isc::dns::RRTTL(3600),
- ZoneFinder::SUCCESS, 1, 2);
+ ZoneFinder::SUCCESS,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
+ expected_rdatas.push_back("2001:db8::1");
+ expected_rdatas.push_back("2001:db8::2");
+ expected_sig_rdatas.push_back("AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
doFindTest(finder, isc::dns::Name("signed1.example.org."),
isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
isc::dns::RRTTL(3600),
- ZoneFinder::SUCCESS, 2, 1);
+ ZoneFinder::SUCCESS,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
doFindTest(finder, isc::dns::Name("signed1.example.org."),
isc::dns::RRType::TXT(), isc::dns::RRType::TXT(),
isc::dns::RRTTL(3600),
- ZoneFinder::NXRRSET, 0, 0);
+ ZoneFinder::NXRRSET,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
+ expected_rdatas.push_back("www.example.org.");
+ expected_sig_rdatas.push_back("CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
doFindTest(finder, isc::dns::Name("signedcname1.example.org."),
isc::dns::RRType::A(), isc::dns::RRType::CNAME(),
isc::dns::RRTTL(3600),
- ZoneFinder::CNAME, 1, 1);
+ ZoneFinder::CNAME,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
+ expected_rdatas.push_back("192.0.2.1");
+ expected_sig_rdatas.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
+ expected_sig_rdatas.push_back("A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE");
doFindTest(finder, isc::dns::Name("signed2.example.org."),
isc::dns::RRType::A(), isc::dns::RRType::A(),
isc::dns::RRTTL(3600),
- ZoneFinder::SUCCESS, 1, 2);
+ ZoneFinder::SUCCESS,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
+ expected_rdatas.push_back("2001:db8::2");
+ expected_rdatas.push_back("2001:db8::1");
+ expected_sig_rdatas.push_back("AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
doFindTest(finder, isc::dns::Name("signed2.example.org."),
isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
isc::dns::RRTTL(3600),
- ZoneFinder::SUCCESS, 2, 1);
+ ZoneFinder::SUCCESS,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
doFindTest(finder, isc::dns::Name("signed2.example.org."),
isc::dns::RRType::TXT(), isc::dns::RRType::TXT(),
isc::dns::RRTTL(3600),
- ZoneFinder::NXRRSET, 0, 0);
+ ZoneFinder::NXRRSET,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
+ expected_rdatas.push_back("www.example.org.");
+ expected_sig_rdatas.push_back("CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
doFindTest(finder, isc::dns::Name("signedcname2.example.org."),
isc::dns::RRType::A(), isc::dns::RRType::CNAME(),
isc::dns::RRTTL(3600),
- ZoneFinder::CNAME, 1, 1);
+ ZoneFinder::CNAME,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
+ expected_rdatas.push_back("192.0.2.1");
+ expected_sig_rdatas.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
doFindTest(finder, isc::dns::Name("acnamesig1.example.org."),
isc::dns::RRType::A(), isc::dns::RRType::A(),
isc::dns::RRTTL(3600),
- ZoneFinder::SUCCESS, 1, 1);
+ ZoneFinder::SUCCESS,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
+ expected_rdatas.push_back("192.0.2.1");
+ expected_sig_rdatas.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
doFindTest(finder, isc::dns::Name("acnamesig2.example.org."),
isc::dns::RRType::A(), isc::dns::RRType::A(),
isc::dns::RRTTL(3600),
- ZoneFinder::SUCCESS, 1, 1);
+ ZoneFinder::SUCCESS,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
+ expected_rdatas.push_back("192.0.2.1");
+ expected_sig_rdatas.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
doFindTest(finder, isc::dns::Name("acnamesig3.example.org."),
isc::dns::RRType::A(), isc::dns::RRType::A(),
isc::dns::RRTTL(3600),
- ZoneFinder::SUCCESS, 1, 1);
+ ZoneFinder::SUCCESS,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
+ expected_rdatas.push_back("192.0.2.1");
+ expected_rdatas.push_back("192.0.2.2");
doFindTest(finder, isc::dns::Name("ttldiff1.example.org."),
isc::dns::RRType::A(), isc::dns::RRType::A(),
isc::dns::RRTTL(360),
- ZoneFinder::SUCCESS, 2, 0);
+ ZoneFinder::SUCCESS,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
+ expected_rdatas.push_back("192.0.2.1");
+ expected_rdatas.push_back("192.0.2.2");
doFindTest(finder, isc::dns::Name("ttldiff2.example.org."),
isc::dns::RRType::A(), isc::dns::RRType::A(),
isc::dns::RRTTL(360),
- ZoneFinder::SUCCESS, 2, 0);
+ ZoneFinder::SUCCESS,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
+
EXPECT_THROW(finder->find(isc::dns::Name("badcname1.example.org."),
isc::dns::RRType::A(),
NULL, ZoneFinder::FIND_DEFAULT),
@@ -487,7 +628,6 @@ TEST_F(DatabaseClientTest, find) {
EXPECT_FALSE(current_connection_->searchRunning());
// Trigger the hardcoded exceptions and see if find() has cleaned up
- /*
EXPECT_THROW(finder->find(isc::dns::Name("dsexception.in.search."),
isc::dns::RRType::A(),
NULL, ZoneFinder::FIND_DEFAULT),
@@ -503,7 +643,7 @@ TEST_F(DatabaseClientTest, find) {
NULL, ZoneFinder::FIND_DEFAULT),
std::exception);
EXPECT_FALSE(current_connection_->searchRunning());
- */
+
EXPECT_THROW(finder->find(isc::dns::Name("dsexception.in.getnext."),
isc::dns::RRType::A(),
NULL, ZoneFinder::FIND_DEFAULT),
@@ -523,12 +663,16 @@ TEST_F(DatabaseClientTest, find) {
// This RRSIG has the wrong sigtype field, which should be
// an error if we decide to keep using that field
// Right now the field is ignored, so it does not error
+ expected_rdatas.clear();
+ expected_sig_rdatas.clear();
+ expected_rdatas.push_back("192.0.2.1");
+ expected_sig_rdatas.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
doFindTest(finder, isc::dns::Name("badsigtype.example.org."),
isc::dns::RRType::A(), isc::dns::RRType::A(),
isc::dns::RRTTL(3600),
- ZoneFinder::SUCCESS, 1, 1);
+ ZoneFinder::SUCCESS,
+ expected_rdatas, expected_sig_rdatas);
EXPECT_FALSE(current_connection_->searchRunning());
-
}
}
diff --git a/src/lib/datasrc/tests/sqlite3_connection_unittest.cc b/src/lib/datasrc/tests/sqlite3_connection_unittest.cc
index 8fdbf9f..e864e25 100644
--- a/src/lib/datasrc/tests/sqlite3_connection_unittest.cc
+++ b/src/lib/datasrc/tests/sqlite3_connection_unittest.cc
@@ -17,7 +17,6 @@
#include <dns/rrclass.h>
#include <gtest/gtest.h>
-#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
using namespace isc::datasrc;
@@ -30,7 +29,9 @@ namespace {
// Some test data
std::string SQLITE_DBFILE_EXAMPLE = TEST_DATA_DIR "/test.sqlite3";
std::string SQLITE_DBFILE_EXAMPLE2 = TEST_DATA_DIR "/example2.com.sqlite3";
+std::string SQLITE_DBNAME_EXAMPLE2 = "sqlite3_example2.com.sqlite3";
std::string SQLITE_DBFILE_EXAMPLE_ROOT = TEST_DATA_DIR "/test-root.sqlite3";
+std::string SQLITE_DBNAME_EXAMPLE_ROOT = "sqlite3_test-root.sqlite3";
std::string SQLITE_DBFILE_BROKENDB = TEST_DATA_DIR "/brokendb.sqlite3";
std::string SQLITE_DBFILE_MEMORY = ":memory:";
@@ -101,6 +102,16 @@ TEST_F(SQLite3Conn, noClass) {
EXPECT_FALSE(conn->getZone(Name("example.com")).first);
}
+TEST(SQLite3Open, getDBNameExample2) {
+ SQLite3Connection conn(SQLITE_DBFILE_EXAMPLE2, RRClass::IN());
+ EXPECT_EQ(SQLITE_DBNAME_EXAMPLE2, conn.getDBName());
+}
+
+TEST(SQLite3Open, getDBNameExampleROOT) {
+ SQLite3Connection conn(SQLITE_DBFILE_EXAMPLE_ROOT, RRClass::IN());
+ EXPECT_EQ(SQLITE_DBNAME_EXAMPLE_ROOT, conn.getDBName());
+}
+
// Simple function to cound the number of records for
// any name
void
@@ -123,7 +134,7 @@ TEST_F(SQLite3Conn, getRecords) {
const int zone_id = zone_info.second;
ASSERT_EQ(1, zone_id);
- const size_t column_count = DatabaseConnection::RecordColumnCount;
+ const size_t column_count = DatabaseConnection::RECORDCOLUMNCOUNT;
std::string columns[column_count];
// without search, getNext() should return false
diff --git a/src/lib/datasrc/zone.h b/src/lib/datasrc/zone.h
index f67ed4b..0dacc5d 100644
--- a/src/lib/datasrc/zone.h
+++ b/src/lib/datasrc/zone.h
@@ -197,7 +197,7 @@ public:
const isc::dns::RRType& type,
isc::dns::RRsetList* target = NULL,
const FindOptions options
- = FIND_DEFAULT) const = 0;
+ = FIND_DEFAULT) = 0;
//@}
};
diff --git a/src/lib/util/filename.h b/src/lib/util/filename.h
index c9874ce..f625938 100644
--- a/src/lib/util/filename.h
+++ b/src/lib/util/filename.h
@@ -103,6 +103,11 @@ public:
return (extension_);
}
+ /// \return Name + extension of Given File Name
+ std::string nameAndExtension() const {
+ return (name_ + extension_);
+ }
+
/// \brief Expand Name with Default
///
/// A default file specified is supplied and used to fill in any missing
diff --git a/src/lib/util/tests/filename_unittest.cc b/src/lib/util/tests/filename_unittest.cc
index be29ff1..b17e374 100644
--- a/src/lib/util/tests/filename_unittest.cc
+++ b/src/lib/util/tests/filename_unittest.cc
@@ -51,42 +51,49 @@ TEST_F(FilenameTest, Components) {
EXPECT_EQ("/alpha/beta/", fname.directory());
EXPECT_EQ("gamma", fname.name());
EXPECT_EQ(".delta", fname.extension());
+ EXPECT_EQ("gamma.delta", fname.nameAndExtension());
// Directory only
fname.setName("/gamma/delta/");
EXPECT_EQ("/gamma/delta/", fname.directory());
EXPECT_EQ("", fname.name());
EXPECT_EQ("", fname.extension());
+ EXPECT_EQ("", fname.nameAndExtension());
// Filename only
fname.setName("epsilon");
EXPECT_EQ("", fname.directory());
EXPECT_EQ("epsilon", fname.name());
EXPECT_EQ("", fname.extension());
+ EXPECT_EQ("epsilon", fname.nameAndExtension());
// Extension only
fname.setName(".zeta");
EXPECT_EQ("", fname.directory());
EXPECT_EQ("", fname.name());
EXPECT_EQ(".zeta", fname.extension());
+ EXPECT_EQ(".zeta", fname.nameAndExtension());
// Missing directory
fname.setName("eta.theta");
EXPECT_EQ("", fname.directory());
EXPECT_EQ("eta", fname.name());
EXPECT_EQ(".theta", fname.extension());
+ EXPECT_EQ("eta.theta", fname.nameAndExtension());
// Missing filename
fname.setName("/iota/.kappa");
EXPECT_EQ("/iota/", fname.directory());
EXPECT_EQ("", fname.name());
EXPECT_EQ(".kappa", fname.extension());
+ EXPECT_EQ(".kappa", fname.nameAndExtension());
// Missing extension
fname.setName("lambda/mu/nu");
EXPECT_EQ("lambda/mu/", fname.directory());
EXPECT_EQ("nu", fname.name());
EXPECT_EQ("", fname.extension());
+ EXPECT_EQ("nu", fname.nameAndExtension());
// Check that the decomposition can occur in the presence of leading and
// trailing spaces
@@ -94,18 +101,21 @@ TEST_F(FilenameTest, Components) {
EXPECT_EQ("lambda/mu/", fname.directory());
EXPECT_EQ("nu", fname.name());
EXPECT_EQ("", fname.extension());
+ EXPECT_EQ("nu", fname.nameAndExtension());
// Empty string
fname.setName("");
EXPECT_EQ("", fname.directory());
EXPECT_EQ("", fname.name());
EXPECT_EQ("", fname.extension());
+ EXPECT_EQ("", fname.nameAndExtension());
// ... and just spaces
fname.setName(" ");
EXPECT_EQ("", fname.directory());
EXPECT_EQ("", fname.name());
EXPECT_EQ("", fname.extension());
+ EXPECT_EQ("", fname.nameAndExtension());
// Check corner cases - where separators are present, but strings are
// absent.
@@ -113,16 +123,19 @@ TEST_F(FilenameTest, Components) {
EXPECT_EQ("/", fname.directory());
EXPECT_EQ("", fname.name());
EXPECT_EQ("", fname.extension());
+ EXPECT_EQ("", fname.nameAndExtension());
fname.setName(".");
EXPECT_EQ("", fname.directory());
EXPECT_EQ("", fname.name());
EXPECT_EQ(".", fname.extension());
+ EXPECT_EQ(".", fname.nameAndExtension());
fname.setName("/.");
EXPECT_EQ("/", fname.directory());
EXPECT_EQ("", fname.name());
EXPECT_EQ(".", fname.extension());
+ EXPECT_EQ(".", fname.nameAndExtension());
// Note that the space is a valid filename here; only leading and trailing
// spaces should be trimmed.
@@ -130,11 +143,13 @@ TEST_F(FilenameTest, Components) {
EXPECT_EQ("/", fname.directory());
EXPECT_EQ(" ", fname.name());
EXPECT_EQ(".", fname.extension());
+ EXPECT_EQ(".", fname.nameAndExtension());
fname.setName(" / . ");
EXPECT_EQ("/", fname.directory());
EXPECT_EQ(" ", fname.name());
EXPECT_EQ(".", fname.extension());
+ EXPECT_EQ(".", fname.nameAndExtension());
}
// Check that the expansion with a default works.
More information about the bind10-changes
mailing list