[svn] commit: r801 - 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 06:04:41 UTC 2010
Author: each
Date: Thu Feb 11 06:04:41 2010
New Revision: 801
Log:
checkpoint: CNAME processing works
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 06:04:41 2010
@@ -1,9 +1,10 @@
#include <iostream>
#include <dns/buffer.h>
+#include <dns/message.h>
#include <dns/name.h>
+#include <dns/rdataclass.h>
#include <dns/rrset.h>
-#include <dns/message.h>
#include <cc/data.h>
@@ -18,6 +19,7 @@
Message& m = q.message();
while (!q.tasks().empty()) {
+ RdataIteratorPtr it;
RRsetList data, sigs;
QueryTask task = q.tasks().front();
q.tasks().pop();
@@ -52,7 +54,7 @@
case QUERY_GETANSWER:
case QUERY_GETADDITIONAL:
case QUERY_GETCNAME:
- // if are no more work items, add authority section
+ // if no more work items, add authority section now
if (q.tasks().empty() &&
data[0]->getType() != RRType("NS")) {
q.tasks().push(QueryTask(Name(*match.closestName()),
@@ -71,30 +73,36 @@
}
case CNAME:
+ if (data[0]->getType() != RRType("CNAME")) {
+ dns_throw (Unexpected, "unexpected query status");
+ }
+
m.addRRset(task.section, data[0]);
if (q.wantDnssec() && sigs.size() == 1) {
m.addRRset(task.section, sigs[0]);
}
- if (data[0]->getType() == RRType("CNAME")) {
- // HERE pull out target name
- // q.tasks().push(QueryTask(cname_target, task.qclass,
- // task.qtype, Section::ANSWER()));
+ it = data[0]->getRdataIterator();
+ for (it->first(); !it->isLast(); it->next()) {
+ const rdata::Rdata& rd(it->getCurrent());
+ const rdata::generic::CNAME& cname =
+ dynamic_cast<const rdata::generic::CNAME&>(rd);
+ const Name& target(cname.getCname());
q.setStatus(QUERY_GETCNAME);
- } else {
- dns_throw (Unexpected, "unexpected query status");
+ q.tasks().push(QueryTask(target, task.qclass, task.qtype,
+ Section::ANSWER()));
+ break;
}
continue;
case NAME_NOT_FOUND:
case TYPE_NOT_FOUND:
+ if (q.status() == QUERY_GETANSWER) {
+ if (result == NAME_NOT_FOUND) {
+ m.setRcode(Rcode::NXDOMAIN());
+ }
+ }
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()),
@@ -119,11 +127,14 @@
return (result);
case ZONE_NOT_FOUND:
- m.setRcode(Rcode::REFUSED());
+ if (q.status() == QUERY_GETANSWER) {
+ m.setRcode(Rcode::REFUSED());
+ }
q.setStatus(QUERY_NODATA);
return (result);
- default:
+ case NOT_IMPLEMENTED:
+ case ERROR:
m.setRcode(Rcode::SERVFAIL());
q.setStatus(QUERY_NODATA);
return (result);
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 06:04:41 2010
@@ -67,7 +67,7 @@
int
Sqlite3DataSrc::
findRecords(const Name& name, const RRType& rdtype,
- RRsetList& target, bool& node_exists) const
+ RRsetList& target, bool& node_exists, bool& found_cname) const
{
int rc;
const string s_name = name.toText();
@@ -80,9 +80,6 @@
return (0);
}
- RRsetPtr rrset = RRsetPtr(new RRset(name, RRClass("IN"), rdtype,
- RRTTL(3600)));
-
sqlite3_reset(q_record);
sqlite3_clear_bindings(q_record);
@@ -103,6 +100,8 @@
int target_ttl = -1;
int sig_ttl = -1;
int rows = 0;
+ found_cname = false;
+ RRsetPtr rrset;
rc = sqlite3_step(q_record);
while (rc == SQLITE_ROW) {
@@ -113,9 +112,22 @@
const char *sigtype = (const char *)sqlite3_column_text(q_record, 2);
const char *rdata = (const char *)sqlite3_column_text(q_record, 3);
+ // looking for something else but found a CNAME
+ if (strcmp(type, "CNAME") == 0 && strcmp(c_rdtype, "CNAME") != 0) {
+ found_cname = true;
+ }
+
+ // first time through the loop, initialize RRset
+ if (rows == 1) {
+ rrset = RRsetPtr(new RRset(name, RRClass("IN"),
+ found_cname ? RRType("CNAME") : rdtype,
+ RRTTL(3600)));
+ }
+
if (sigtype == NULL) {
RdataPtr item = createRdata(RRType(type), RRClass("IN"), rdata);
rrset->addRdata(item);
+
if (target_ttl == -1 || target_ttl > ttl) {
target_ttl = ttl;
}
@@ -132,31 +144,36 @@
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);
+ return (rows);
+ }
+
+ //
+ // No rows were found. We need to find out whether there are
+ // any RRs with that name to determine whether this is NXDOMAIN or
+ // NXRRSET
+ //
+ 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 (0);
}
//
@@ -323,12 +340,14 @@
const RRType& qtype,
RRsetList& target) const
{
- bool node_exists;
- int rows = findRecords(qname, qtype, target, node_exists);
+ bool node_exists, found_cname;
+ int rows = findRecords(qname, qtype, target, node_exists, found_cname);
if (rows == 0 && node_exists) {
return (TYPE_NOT_FOUND);
} else if (rows == 0) {
return (NAME_NOT_FOUND);
+ } else if (found_cname) {
+ return (CNAME);
} else {
return (SUCCESS);
}
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 06:04:41 2010
@@ -50,7 +50,8 @@
void release(sqlite3_stmt* prepared);
int getVersion(void);
int hasExactZone(const char *name) const;
- int findRecords(const Name& name, const RRType& rdtype, RRsetList& target, bool& node_exists) const;
+ int findRecords(const Name& name, const RRType& rdtype, RRsetList& target,
+ bool& node_exists, bool& found_cname) const;
int findClosest(const char *name, const char **position) const;
void loadVersion(void);
void setupPreparedStatements(void);
More information about the bind10-changes
mailing list