From: Michal 'vorner' Vaner Date: Fri, 14 Dec 2012 12:53:31 +0000 (+0100) Subject: [2427] Basic $ORIGIN handling X-Git-Tag: bind10-1.0.0-beta-release~13^2^2~19 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e47b08e8a356c1bf498aa5a615fcce86958f1fe0;p=thirdparty%2Fkea.git [2427] Basic $ORIGIN handling --- diff --git a/src/lib/dns/master_loader.cc b/src/lib/dns/master_loader.cc index 0a3db399cb..d82f462623 100644 --- a/src/lib/dns/master_loader.cc +++ b/src/lib/dns/master_loader.cc @@ -55,6 +55,7 @@ public: MasterLoader::Options options) : lexer_(), zone_origin_(zone_origin), + active_origin_(zone_origin), zone_class_(zone_class), callbacks_(callbacks), add_callback_(add_callback), @@ -138,13 +139,23 @@ public: pushSource(filename); } + void doOrigin() { + // Parse and create the new origin. It is relative to the previous + // one. + const MasterToken::StringRegion& + name_string(lexer_.getNextToken(MasterToken::QSTRING). + getStringRegion()); + active_origin_ = Name(name_string.beg, name_string.len, + &active_origin_); + // Make sure there's the EOLN + eatUntilEOL(true); + } + void handleDirective(const char* directive, size_t length) { if (iequals(directive, "INCLUDE")) { doInclude(); } else if (iequals(directive, "ORIGIN")) { - // TODO: Implement - isc_throw(isc::NotImplemented, - "Origin directive not implemented yet"); + doOrigin(); } else if (iequals(directive, "TTL")) { // TODO: Implement isc_throw(isc::NotImplemented, @@ -187,6 +198,8 @@ public: private: MasterLexer lexer_; const Name zone_origin_; + Name active_origin_; // The origin used during parsing + // (modifiable by $ORIGIN) const RRClass zone_class_; MasterLoaderCallbacks callbacks_; AddRRCallback add_callback_; @@ -255,7 +268,7 @@ MasterLoader::MasterLoaderImpl::loadIncremental(size_t count_limit) { } const Name name(name_string.beg, name_string.len, - &zone_origin_); + &active_origin_); // TODO: Some more flexibility. We don't allow omitting // anything yet @@ -275,7 +288,7 @@ MasterLoader::MasterLoaderImpl::loadIncremental(size_t count_limit) { const rdata::RdataPtr data(rdata::createRdata(rrtype, rrclass, lexer_, - &zone_origin_, + &active_origin_, options_, callbacks_)); // In case we get NULL, it means there was error creating diff --git a/src/lib/dns/tests/master_loader_unittest.cc b/src/lib/dns/tests/master_loader_unittest.cc index 3644f08fcc..f882def90e 100644 --- a/src/lib/dns/tests/master_loader_unittest.cc +++ b/src/lib/dns/tests/master_loader_unittest.cc @@ -201,7 +201,7 @@ TEST_F(MasterLoaderTest, origin) { const string input = "@ 1H IN A 192.0.2.1\n" + directive + " sub.example.org.\n" - "www 1H IN A 192.0.2.1\n" + + "\"www\" 1H IN A 192.0.2.1\n" + // Relative name in the origin directive + " relative\n" "@ 1H IN A 192.0.2.1\n"