mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-01 14:35:29 +00:00
[2382] Consume to end of line / file in createRdata().
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
#include <util/buffer.h>
|
#include <util/buffer.h>
|
||||||
#include <dns/name.h>
|
#include <dns/name.h>
|
||||||
#include <dns/messagerenderer.h>
|
#include <dns/messagerenderer.h>
|
||||||
|
#include <dns/master_lexer.h>
|
||||||
#include <dns/rdata.h>
|
#include <dns/rdata.h>
|
||||||
#include <dns/rrparamregistry.h>
|
#include <dns/rrparamregistry.h>
|
||||||
#include <dns/rrtype.h>
|
#include <dns/rrtype.h>
|
||||||
@@ -87,17 +88,17 @@ createRdata(const RRType& rrtype, const RRClass& rrclass,
|
|||||||
MasterLoader::Options options,
|
MasterLoader::Options options,
|
||||||
MasterLoaderCallbacks& callbacks)
|
MasterLoaderCallbacks& callbacks)
|
||||||
{
|
{
|
||||||
RdataPtr ret;
|
const RdataPtr rdata = RRParamRegistry::getRegistry().createRdata(
|
||||||
|
rrtype, rrclass, lexer, origin, options, callbacks);
|
||||||
|
|
||||||
try {
|
// Consume to end of line / file.
|
||||||
ret = RRParamRegistry::getRegistry().createRdata(rrtype, rrclass,
|
// If not at end of line initially set error code.
|
||||||
lexer, origin,
|
// Call callback via fromtext_error once if there was an error.
|
||||||
options, callbacks);
|
const MasterToken& token = lexer.getNextToken();
|
||||||
} catch (...) {
|
assert(token.getType() == MasterToken::END_OF_LINE ||
|
||||||
// ret is NULL here.
|
token.getType() == MasterToken::END_OF_FILE);
|
||||||
}
|
|
||||||
|
|
||||||
return (ret);
|
return (rdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@@ -82,6 +82,30 @@ createRdataUsingLexer(const RRType& rrtype, const RRClass& rrclass,
|
|||||||
|
|
||||||
} // end of namespace isc::dns::rdata::test
|
} // end of namespace isc::dns::rdata::test
|
||||||
|
|
||||||
|
// Test class/type-independent behavior of createRdata().
|
||||||
|
TEST_F(RdataTest, createRdataWithLexer) {
|
||||||
|
const generic::NS ns_rdata("ns.example.com.");
|
||||||
|
const in::AAAA aaaa_rdata("2001:db8::1");
|
||||||
|
|
||||||
|
stringstream ss;
|
||||||
|
ss << ns_rdata.toText() << "\n"; // valid case
|
||||||
|
ss << aaaa_rdata.toText() << " extra-token\n"; // extra token
|
||||||
|
lexer.pushSource(ss);
|
||||||
|
|
||||||
|
const MasterLoaderCallbacks::IssueCallback callback
|
||||||
|
(boost::bind(&test::dummyCallback, _1, _2, _3));
|
||||||
|
MasterLoaderCallbacks callbacks(callback, callback);
|
||||||
|
ConstRdataPtr rdata = createRdata(RRType::NS(), RRClass::IN(), lexer, NULL,
|
||||||
|
MasterLoader::MANY_ERRORS, callbacks);
|
||||||
|
EXPECT_EQ(0, ns_rdata.compare(*rdata));
|
||||||
|
|
||||||
|
#ifdef notyet
|
||||||
|
rdata = createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL,
|
||||||
|
MasterLoader::MANY_ERRORS, callbacks);
|
||||||
|
EXPECT_EQ(0, aaaa_rdata.compare(*rdata));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#include <dns/rrclass.h>
|
#include <dns/rrclass.h>
|
||||||
#include <dns/rrtype.h>
|
#include <dns/rrtype.h>
|
||||||
#include <dns/rdata.h>
|
#include <dns/rdata.h>
|
||||||
|
#include <dns/master_lexer.h>
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
@@ -40,6 +41,7 @@ protected:
|
|||||||
/// This is an RDATA object of some "unknown" RR type so that it can be
|
/// This is an RDATA object of some "unknown" RR type so that it can be
|
||||||
/// used to test the compare() method against a well-known RR type.
|
/// used to test the compare() method against a well-known RR type.
|
||||||
RdataPtr rdata_nomatch;
|
RdataPtr rdata_nomatch;
|
||||||
|
MasterLexer lexer;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace test {
|
namespace test {
|
||||||
|
Reference in New Issue
Block a user