mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-01 14:35:29 +00:00
[2442] supported lexer version of constructor for TXTLike RR types
it's incomplete, but pass some tests
This commit is contained in:
@@ -32,7 +32,8 @@ import sys
|
|||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
# new_rdata_factory_users = [('a', 'in'), ('a', 'ch'), ('soa', 'generic')]
|
# new_rdata_factory_users = [('a', 'in'), ('a', 'ch'), ('soa', 'generic')]
|
||||||
new_rdata_factory_users = []
|
new_rdata_factory_users = [('aaaa', 'in'), ('txt', 'generic'),
|
||||||
|
('spf', 'generic')]
|
||||||
|
|
||||||
re_typecode = re.compile('([\da-z]+)_(\d+)')
|
re_typecode = re.compile('([\da-z]+)_(\d+)')
|
||||||
classcode2txt = {}
|
classcode2txt = {}
|
||||||
|
@@ -15,6 +15,11 @@
|
|||||||
#ifndef TXT_LIKE_H
|
#ifndef TXT_LIKE_H
|
||||||
#define TXT_LIKE_H 1
|
#define TXT_LIKE_H 1
|
||||||
|
|
||||||
|
#include <dns/master_lexer.h>
|
||||||
|
#include <dns/master_loader.h>
|
||||||
|
#include <dns/master_loader_callbacks.h>
|
||||||
|
#include <dns/rdata/generic/detail/char_string.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -113,6 +118,23 @@ public:
|
|||||||
string_list_.push_back(data);
|
string_list_.push_back(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TXTLikeImpl(MasterLexer& lexer, const Name*,
|
||||||
|
MasterLoader::Options,
|
||||||
|
MasterLoaderCallbacks&)
|
||||||
|
{
|
||||||
|
while (true) {
|
||||||
|
const MasterToken& token = lexer.getNextToken(
|
||||||
|
MasterToken::QSTRING, true);
|
||||||
|
if (token.getType() != MasterToken::STRING &&
|
||||||
|
token.getType() != MasterToken::QSTRING) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
string_list_.push_back(std::vector<uint8_t>());
|
||||||
|
strToCharString(token.getStringRegion(), string_list_.back());
|
||||||
|
}
|
||||||
|
lexer.ungetToken();
|
||||||
|
}
|
||||||
|
|
||||||
/// \brief The copy constructor.
|
/// \brief The copy constructor.
|
||||||
///
|
///
|
||||||
/// Trivial for now, we could've used the default one.
|
/// Trivial for now, we could've used the default one.
|
||||||
|
@@ -66,6 +66,13 @@ SPF::SPF(InputBuffer& buffer, size_t rdata_len) :
|
|||||||
impl_(new SPFImpl(buffer, rdata_len))
|
impl_(new SPFImpl(buffer, rdata_len))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief Constructor from TBD
|
||||||
|
SPF::SPF(MasterLexer& lexer, const Name* origin,
|
||||||
|
MasterLoader::Options options, MasterLoaderCallbacks& callbacks) :
|
||||||
|
impl_(new SPFImpl(lexer, origin, options, callbacks))
|
||||||
|
{}
|
||||||
|
|
||||||
/// \brief Constructor from string.
|
/// \brief Constructor from string.
|
||||||
///
|
///
|
||||||
/// It internally allocates a resource, and if it fails a corresponding
|
/// It internally allocates a resource, and if it fails a corresponding
|
||||||
|
@@ -52,6 +52,11 @@ TXT::TXT(InputBuffer& buffer, size_t rdata_len) :
|
|||||||
impl_(new TXTImpl(buffer, rdata_len))
|
impl_(new TXTImpl(buffer, rdata_len))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
TXT::TXT(MasterLexer& lexer, const Name* origin,
|
||||||
|
MasterLoader::Options options, MasterLoaderCallbacks& callbacks) :
|
||||||
|
impl_(new TXTImpl(lexer, origin, options, callbacks))
|
||||||
|
{}
|
||||||
|
|
||||||
TXT::TXT(const std::string& txtstr) :
|
TXT::TXT(const std::string& txtstr) :
|
||||||
impl_(new TXTImpl(txtstr))
|
impl_(new TXTImpl(txtstr))
|
||||||
{}
|
{}
|
||||||
|
@@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <boost/bind.hpp>
|
||||||
|
|
||||||
using isc::UnitTestUtil;
|
using isc::UnitTestUtil;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace isc::dns;
|
using namespace isc::dns;
|
||||||
@@ -47,10 +49,17 @@ const uint8_t wiredata_txt_like[] = {
|
|||||||
|
|
||||||
const uint8_t wiredata_nulltxt[] = { 0 };
|
const uint8_t wiredata_nulltxt[] = { 0 };
|
||||||
|
|
||||||
|
// For lexer-based constructor
|
||||||
|
void
|
||||||
|
dummyCallback(const string&, size_t, const string&) {
|
||||||
|
}
|
||||||
|
|
||||||
template<class TXT_LIKE>
|
template<class TXT_LIKE>
|
||||||
class Rdata_TXT_LIKE_Test : public RdataTest {
|
class Rdata_TXT_LIKE_Test : public RdataTest {
|
||||||
protected:
|
protected:
|
||||||
Rdata_TXT_LIKE_Test() :
|
Rdata_TXT_LIKE_Test() :
|
||||||
|
callback(boost::bind(&dummyCallback, _1, _2, _3)),
|
||||||
|
loader_cb(callback, callback),
|
||||||
wiredata_longesttxt(256, 'a'),
|
wiredata_longesttxt(256, 'a'),
|
||||||
rdata_txt_like("Test-String"),
|
rdata_txt_like("Test-String"),
|
||||||
rdata_txt_like_empty("\"\""),
|
rdata_txt_like_empty("\"\""),
|
||||||
@@ -59,10 +68,16 @@ protected:
|
|||||||
wiredata_longesttxt[0] = 255; // adjust length
|
wiredata_longesttxt[0] = 255; // adjust length
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const MasterLoaderCallbacks::IssueCallback callback;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
MasterLoaderCallbacks loader_cb;
|
||||||
vector<uint8_t> wiredata_longesttxt;
|
vector<uint8_t> wiredata_longesttxt;
|
||||||
const TXT_LIKE rdata_txt_like;
|
const TXT_LIKE rdata_txt_like;
|
||||||
const TXT_LIKE rdata_txt_like_empty;
|
const TXT_LIKE rdata_txt_like_empty;
|
||||||
const TXT_LIKE rdata_txt_like_quoted;
|
const TXT_LIKE rdata_txt_like_quoted;
|
||||||
|
ConstRdataPtr rdata_txt_like_fromwire;
|
||||||
};
|
};
|
||||||
|
|
||||||
// The list of types we want to test.
|
// The list of types we want to test.
|
||||||
@@ -71,10 +86,27 @@ typedef testing::Types<generic::TXT, generic::SPF> Implementations;
|
|||||||
TYPED_TEST_CASE(Rdata_TXT_LIKE_Test, Implementations);
|
TYPED_TEST_CASE(Rdata_TXT_LIKE_Test, Implementations);
|
||||||
|
|
||||||
TYPED_TEST(Rdata_TXT_LIKE_Test, createFromText) {
|
TYPED_TEST(Rdata_TXT_LIKE_Test, createFromText) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Test-String\n";
|
||||||
|
ss << "\"Test-String\"\n"; // explicitly surrounded by '"'s
|
||||||
|
this->lexer.pushSource(ss);
|
||||||
|
|
||||||
// normal case is covered in toWireBuffer.
|
// normal case is covered in toWireBuffer.
|
||||||
|
this->rdata_txt_like_fromwire =
|
||||||
|
this->rdataFactoryFromFile(RRTYPE<TypeParam>(),
|
||||||
|
RRClass("IN"), "rdata_txt_fromWire1");
|
||||||
|
EXPECT_EQ(0, this->rdata_txt_like.compare(*this->rdata_txt_like_fromwire));
|
||||||
|
EXPECT_EQ(0, TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS,
|
||||||
|
this->loader_cb).compare(
|
||||||
|
*this->rdata_txt_like_fromwire));
|
||||||
|
EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType());
|
||||||
|
|
||||||
// surrounding double-quotes shouldn't change the result.
|
// surrounding double-quotes shouldn't change the result.
|
||||||
EXPECT_EQ(0, this->rdata_txt_like.compare(this->rdata_txt_like_quoted));
|
EXPECT_EQ(0, this->rdata_txt_like_quoted.compare(
|
||||||
|
*this->rdata_txt_like_fromwire));
|
||||||
|
EXPECT_EQ(0, TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS,
|
||||||
|
this->loader_cb).compare(
|
||||||
|
*this->rdata_txt_like_fromwire));
|
||||||
|
|
||||||
// Null character-string.
|
// Null character-string.
|
||||||
this->obuffer.clear();
|
this->obuffer.clear();
|
||||||
|
Reference in New Issue
Block a user