[svn] commit: r800 - in /branches/each-ds/src/lib/auth/cpp: data_source.cc data_source_sqlite3.cc data_source_sqlite3.h
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Feb 11 04:21:44 UTC 2010
Author: each
Date: Thu Feb 11 04:21:44 2010
New Revision: 800
Log:
checkpoint: noerror/nodata replies now work correctly
Modified:
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/data_source.cc
==============================================================================
--- branches/each-ds/src/lib/auth/cpp/data_source.cc (original)
+++ branches/each-ds/src/lib/auth/cpp/data_source.cc Thu Feb 11 04:21:44 2010
@@ -87,7 +87,14 @@
continue;
case NAME_NOT_FOUND:
+ case TYPE_NOT_FOUND:
q.setStatus(QUERY_NODATA);
+
+ if (result == NAME_NOT_FOUND) {
+ m.setRcode(Rcode::NXDOMAIN());
+ } else {
+ m.setRcode(Rcode::NOERROR());
+ }
if (q.wantDnssec()) {
result = ds->findRRset(Name(*match.closestName()),
@@ -104,16 +111,11 @@
return (ERROR);
}
- m.setRcode(Rcode::NXDOMAIN());
m.addRRset(Section::AUTHORITY(), data[0]);
if (q.wantDnssec() && sigs.size() == 1) {
m.addRRset(Section::AUTHORITY(), sigs[0]);
}
- return (SUCCESS);
- case TYPE_NOT_FOUND:
- m.setRcode(Rcode::NOERROR());
- q.setStatus(QUERY_NODATA);
return (result);
case ZONE_NOT_FOUND:
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 Thu Feb 11 04:21:44 2010
@@ -64,7 +64,11 @@
}
-int Sqlite3DataSrc::findRecords(const Name& name, const RRType& rdtype, RRsetList& target) const {
+int
+Sqlite3DataSrc::
+findRecords(const Name& name, const RRType& rdtype,
+ RRsetList& target, bool& node_exists) const
+{
int rc;
const string s_name = name.toText();
const char *c_name = s_name.c_str();
@@ -84,21 +88,22 @@
rc = sqlite3_bind_int(q_record, 1, zone_id);
if (rc != SQLITE_OK) {
- throw("Could not bind 1");
+ throw("Could not bind 1 (record)");
}
rc = sqlite3_bind_text(q_record, 2, c_name, -1, SQLITE_STATIC);
if (rc != SQLITE_OK) {
- throw("Could not bind 2");
+ throw("Could not bind 2 (record)");
}
rc = sqlite3_bind_text(q_record, 3, c_rdtype, -1, SQLITE_STATIC);
if (rc != SQLITE_OK) {
- throw("Could not bind 3");
+ throw("Could not bind 3 (record)");
}
// loop
int target_ttl = -1;
int sig_ttl = -1;
int rows = 0;
+
rc = sqlite3_step(q_record);
while (rc == SQLITE_ROW) {
rows++;
@@ -126,6 +131,29 @@
if (rows > 0) {
rrset->setTTL(RRTTL(target_ttl));
target.push_back(rrset);
+ node_exists = true;
+ } else {
+ node_exists = false;
+ sqlite3_reset(q_count);
+ sqlite3_clear_bindings(q_count);
+
+ rc = sqlite3_bind_int(q_count, 1, zone_id);
+ if (rc != SQLITE_OK) {
+ throw("Could not bind 1 (count)");
+ }
+
+ rc = sqlite3_bind_text(q_count, 2, c_name, -1, SQLITE_STATIC);
+ if (rc != SQLITE_OK) {
+ throw("Could not bind 2 (count)");
+ }
+
+ rc = sqlite3_step(q_count);
+ if(rc == SQLITE_ROW) {
+ int count = sqlite3_column_int(q_count, 0);
+ if (count != 0) {
+ node_exists = true;
+ }
+ }
}
return (rows);
@@ -173,9 +201,8 @@
}
void Sqlite3DataSrc::setupPreparedStatements(void) {
+
const char *q_zone_str = "SELECT id FROM zones WHERE name=?1";
- const char *q_record_str = "SELECT rdtype, ttl, sigtype, rdata FROM records WHERE zone_id=?1 AND name=?2 AND ((rdtype=?3 OR sigtype=?3) OR (rdtype='CNAME' OR sigtype='CNAME'))";
-
try {
q_zone = prepare(q_zone_str);
} catch (const char *e) {
@@ -183,10 +210,25 @@
cout << sqlite3_errmsg(db) << endl;
throw(e);
}
+
+ const char *q_record_str = "SELECT rdtype, ttl, sigtype, rdata "
+ "FROM records WHERE zone_id=?1 AND name=?2 AND "
+ "((rdtype=?3 OR sigtype=?3) OR "
+ "(rdtype='CNAME' OR sigtype='CNAME'))";
try {
q_record = prepare(q_record_str);
} catch (const char *e) {
cout << e << endl << q_record_str << endl;
+ cout << sqlite3_errmsg(db) << endl;
+ throw(e);
+ }
+
+ const char *q_count_str = "SELECT COUNT(*) FROM records "
+ "WHERE zone_id=?1 AND name=?2";
+ try {
+ q_count = prepare(q_count_str);
+ } catch (const char *e) {
+ cout << e << endl << q_count_str << endl;
cout << sqlite3_errmsg(db) << endl;
throw(e);
}
@@ -239,6 +281,7 @@
database_version = -1;
q_zone = NULL;
q_record = NULL;
+ q_count = NULL;
}
Sqlite3DataSrc::~Sqlite3DataSrc()
@@ -280,8 +323,11 @@
const RRType& qtype,
RRsetList& target) const
{
- int rows = findRecords(qname, qtype, target);
- if (rows == 0) {
+ bool node_exists;
+ int rows = findRecords(qname, qtype, target, node_exists);
+ if (rows == 0 && node_exists) {
+ return (TYPE_NOT_FOUND);
+ } else if (rows == 0) {
return (NAME_NOT_FOUND);
} else {
return (SUCCESS);
@@ -334,6 +380,11 @@
q_record = NULL;
}
+ if (q_count) {
+ release(q_count);
+ q_count = NULL;
+ }
+
sqlite3_close(db);
db = 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 Thu Feb 11 04:21:44 2010
@@ -50,7 +50,7 @@
void release(sqlite3_stmt* prepared);
int getVersion(void);
int hasExactZone(const char *name) const;
- int findRecords(const Name& name, const RRType& rdtype, RRsetList& target) const;
+ int findRecords(const Name& name, const RRType& rdtype, RRsetList& target, bool& node_exists) const;
int findClosest(const char *name, const char **position) const;
void loadVersion(void);
void setupPreparedStatements(void);
@@ -66,6 +66,7 @@
//
sqlite3_stmt *q_zone;
sqlite3_stmt *q_record;
+ sqlite3_stmt *q_count;
};
}
More information about the bind10-changes
mailing list