[svn] commit: r893 - in /branches/each-ds/src/lib/auth/cpp: TODO data_source.cc data_source_sqlite3.cc data_source_sqlite3.h
BIND 10 source code commits
bind10-changes at lists.isc.org
Sat Feb 20 05:19:33 UTC 2010
Author: each
Date: Sat Feb 20 05:19:33 2010
New Revision: 893
Log:
add findAddrs() and findReferral() methods in the SQL data source.
(this should be a little more efficient than using the upper-level
routine, which does multiple selects instead of only one.)
Modified:
branches/each-ds/src/lib/auth/cpp/TODO
branches/each-ds/src/lib/auth/cpp/data_source.cc
branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.cc
branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.h
Modified: branches/each-ds/src/lib/auth/cpp/TODO
==============================================================================
--- branches/each-ds/src/lib/auth/cpp/TODO (original)
+++ branches/each-ds/src/lib/auth/cpp/TODO Sat Feb 20 05:19:33 2010
@@ -1,6 +1,2 @@
-Data source:
- change filenames so we don't have everything starting with "data_source_"?
-
-SQL data source:
-- should implement findAddrs() and findReferral() directly instead of
- using the implementation in DataSrc.
+- clean up SQL data source code
Modified: branches/each-ds/src/lib/auth/cpp/data_source.cc
==============================================================================
--- branches/each-ds/src/lib/auth/cpp/data_source.cc (original)
+++ branches/each-ds/src/lib/auth/cpp/data_source.cc Sat Feb 20 05:19:33 2010
@@ -401,10 +401,6 @@
chaseCname(q, task, rrset);
}
} else {
- // XXX: since this is a SIMPLE_QUERY, there can
- // only be one rrset returned in wild. But
- // eventually this will need to handle ANY queries,
- // so wrap it in a BOOST_FOREACH statement anyway.
BOOST_FOREACH (RRsetPtr rrset, wild) {
rrset->setName(task.qname);
m.addRRset(Section::ANSWER(), rrset,
@@ -445,6 +441,7 @@
}
if (t.flags == 0) {
+ // There should only be one NSEC record.
m.addRRset(Section::AUTHORITY(), nsec[0], true);
}
@@ -477,6 +474,7 @@
return;
}
+ // There should only be one SOA record
m.addRRset(Section::AUTHORITY(), soa[0], q.wantDnssec());
}
@@ -493,6 +491,7 @@
}
if (t.flags == 0) {
+ // There should only be one NSEC record
m.addRRset(Section::AUTHORITY(), nsec[0], true);
}
}
Modified: branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.cc
==============================================================================
--- branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.cc (original)
+++ branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.cc Sat Feb 20 05:19:33 2010
@@ -69,19 +69,31 @@
int
Sqlite3DataSrc::
findRecords(const Name& name, const RRType& rdtype, RRsetList& target,
- Name* zone, uint32_t& flags) const
+ Name* zone, const Mode mode, uint32_t& flags) const
{
int rc;
const string s_name = name.toText();
const char *c_name = s_name.c_str();
const string s_rdtype = rdtype.toText();
const char *c_rdtype = s_rdtype.c_str();
- sqlite3_stmt *query = q_record;
-
- if (rdtype == RRType::ANY()) {
- query = q_any;
- }
-
+ sqlite3_stmt *query;
+
+ switch (mode) {
+ case ADDRESS:
+ query = q_addrs;
+ break;
+ case REFERRAL:
+ query = q_referral;
+ break;
+ default:
+ if (rdtype == RRType::ANY()) {
+ query = q_any;
+ } else {
+ query = q_record;
+ }
+ break;
+ }
+
flags = 0;
int zone_id;
@@ -285,8 +297,31 @@
throw(e);
}
+ const char *q_addrs_str = "SELECT rdtype, ttl, sigtype, rdata "
+ "FROM records WHERE zone_id=?1 AND name=?2 AND "
+ "(rdtype='A' OR sigtype='A' OR "
+ "rdtype='AAAA' OR sigtype='AAAA')";
+ try {
+ q_addrs = prepare(q_addrs_str);
+ } catch (const char *e) {
+ cout << e << endl << q_addrs_str << endl;
+ cout << sqlite3_errmsg(db) << endl;
+ throw(e);
+ }
+ const char *q_referral_str = "SELECT rdtype, ttl, sigtype, rdata FROM "
+ "records WHERE zone_id=?1 AND name=?2 AND"
+ "(rdtype='NS' OR sigtype='NS' OR "
+ "rdtype='DS' OR sigtype='DS' OR "
+ "rdtype='DNAME' OR sigtype='DNAME')";
+ try {
+ q_referral = prepare(q_referral_str);
+ } catch (const char *e) {
+ cout << e << endl << q_referral_str << endl;
+ cout << sqlite3_errmsg(db) << endl;
+ throw(e);
+ }
const char *q_any_str = "SELECT rdtype, ttl, sigtype, rdata "
- "FROM records WHERE zone_id=?1 AND name=?2";
+ "FROM records WHERE zone_id=?1 AND name=?2";
try {
q_any = prepare(q_any_str);
} catch (const char *e) {
@@ -366,6 +401,8 @@
database_version = -1;
q_zone = NULL;
q_record = NULL;
+ q_addrs = NULL;
+ q_referral = NULL;
q_any = NULL;
q_count = NULL;
q_previous = NULL;
@@ -456,7 +493,7 @@
uint32_t& flags,
Name* zone) const
{
- findRecords(qname, qtype, target, zone, flags);
+ findRecords(qname, qtype, target, zone, NORMAL, flags);
return (SUCCESS);
}
@@ -469,7 +506,7 @@
uint32_t& flags,
Name* zone) const
{
- findRecords(qname, qtype, target, zone, flags);
+ findRecords(qname, qtype, target, zone, NORMAL, flags);
// Ignore referrals in this case
flags &= ~REFERRAL;
@@ -483,6 +520,27 @@
return (SUCCESS);
}
+DataSrc::Result
+Sqlite3DataSrc::findAddrs(const Query& q,
+ const Name& qname,
+ const RRClass& qclass,
+ RRsetList& target,
+ uint32_t& flags,
+ Name* zone) const {
+ findRecords(qname, RRType::ANY(), target, zone, ADDRESS, flags);
+ return (SUCCESS);
+}
+
+DataSrc::Result
+Sqlite3DataSrc::findReferral(const Query& q,
+ const Name& qname,
+ const RRClass& qclass,
+ RRsetList& target,
+ uint32_t& flags,
+ Name* zone) const {
+ findRecords(qname, RRType::ANY(), target, zone, REFERRAL, flags);
+ return (SUCCESS);
+}
//
// Open the database.
//
@@ -520,6 +578,16 @@
q_record = NULL;
}
+ if (q_addrs) {
+ release(q_addrs);
+ q_addrs = NULL;
+ }
+
+ if (q_referral) {
+ release(q_referral);
+ q_referral = NULL;
+ }
+
if (q_any) {
release(q_any);
q_any = NULL;
Modified: branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.h
==============================================================================
--- branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.h (original)
+++ branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.h Sat Feb 20 05:19:33 2010
@@ -49,6 +49,20 @@
uint32_t& flags,
Name* zone = NULL) const;
+ virtual Result findAddrs(const Query& q,
+ const Name& qname,
+ const RRClass& qclass,
+ RRsetList& target,
+ uint32_t& flags,
+ Name* zone = NULL) const;
+
+ virtual Result findReferral(const Query& q,
+ const Name& qname,
+ const RRClass& qclass,
+ RRsetList& target,
+ uint32_t& flags,
+ Name* zone = NULL) const;
+
virtual DataSrc::Result findPreviousName(const Query& q,
const Name& qname,
Name& target,
@@ -58,13 +72,20 @@
virtual Result close();
private:
+ enum Mode {
+ NORMAL,
+ ADDRESS,
+ REFERRAL
+ };
+
void open(const std::string& name);
sqlite3_stmt* prepare(const char *statement);
void release(sqlite3_stmt* prepared);
int getVersion(void);
int hasExactZone(const char *name) const;
- int findRecords(const Name& name, const RRType& rdtype, RRsetList& target,
- Name* zone, uint32_t& flags) const;
+ int findRecords(const Name& name, const RRType& rdtype,
+ RRsetList& target, Name* zone,
+ const Mode mode, uint32_t& flags) const;
int findClosest(const char *name, const char **position) const;
void loadVersion(void);
void setupPreparedStatements(void);
@@ -80,6 +101,8 @@
//
sqlite3_stmt *q_zone;
sqlite3_stmt *q_record;
+ sqlite3_stmt *q_addrs;
+ sqlite3_stmt *q_referral;
sqlite3_stmt *q_any;
sqlite3_stmt *q_count;
sqlite3_stmt *q_previous;
More information about the bind10-changes
mailing list