21 #include <boost/lexical_cast.hpp>
22 #include <boost/shared_ptr.hpp>
37 using boost::lexical_cast;
45 Rdata::getLength()
const {
57 const std::string& rdata_string)
59 return (RRParamRegistry::getRegistry().
createRdata(rrtype, rrclass,
74 RRParamRegistry::getRegistry().createRdata(rrtype, rrclass, buffer,
88 return (RRParamRegistry::getRegistry().
createRdata(rrtype, rrclass,
94 fromtextError(
bool& error_issued,
const MasterLexer& lexer,
106 "createRdata from text failed: " + string(reason));
111 case MasterToken::STRING:
112 case MasterToken::QSTRING:
114 "createRdata from text failed near '" +
115 token->
getString() +
"': " + string(reason));
119 "createRdata from text failed: " +
127 isc_throw(Unexpected,
"bug: createRdata() saw unexpected token type");
140 bool error_issued =
false;
142 rdata = RRParamRegistry::getRegistry().createRdata(
143 rrtype, rrclass, lexer, origin, options, callbacks);
145 fromtextError(error_issued, lexer, callbacks, &error.
token_,
"");
150 fromtextError(error_issued, lexer, callbacks, NULL, ex.
what());
161 case MasterToken::END_OF_LINE:
163 case MasterToken::END_OF_FILE:
165 "file does not end with newline");
169 fromtextError(error_issued, lexer, callbacks, &token,
184 size_t cmplen = min(len1, len2);
186 for (
size_t i = 0; i < cmplen; ++i) {
187 uint8_t c1 = tolower(n1.
at(i));
188 uint8_t c2 = tolower(n2.
at(i));
191 }
else if (c1 > c2) {
196 return ((len1 == len2) ? 0 : (len1 < len2) ? -1 : 1);
210 vector<uint8_t> data(rdata_len);
212 buffer.
readData(&data[0], rdata_len);
223 "Missing the special token (\\#) for "
224 "unknown RDATA encoding");
228 uint32_t rdlen = 65536;
234 "Unknown RDATA length is invalid");
239 "Unknown RDATA length is out of range: " << rdlen);
242 vector<uint8_t> data;
249 const MasterToken& token =
251 if ((token.getType() == MasterToken::END_OF_FILE) ||
252 (token.getType() == MasterToken::END_OF_LINE)) {
259 token.getString(hex_part);
260 hex_txt.append(hex_part);
267 "Invalid hex encoding of generic RDATA: " << ex.
what());
271 if (data.size() != rdlen) {
273 "Size of unknown RDATA hex data doesn't match RDLENGTH: "
274 << data.size() <<
" vs. " << rdlen);
277 return (
new GenericImpl(data));
280 Generic::Generic(
const std::string& rdata_string) :
286 std::unique_ptr<GenericImpl> impl_ptr;
289 std::istringstream ss(rdata_string);
293 impl_ptr.reset(constructFromLexer(lexer));
301 "from '" << rdata_string <<
"': " << ex.
what());
304 impl_ = impl_ptr.release();
310 impl_(constructFromLexer(lexer))
327 if (impl_ == source.impl_) {
339 class UnknownRdataDumper {
341 UnknownRdataDumper(ostringstream& oss) :
oss_(&oss) {}
342 void operator()(
const unsigned char d)
344 *oss_ << setw(2) << static_cast<unsigned int>(d);
355 oss <<
"\\# " << impl_->
data_.size() <<
" ";
358 for_each(impl_->
data_.begin(), impl_->
data_.end(), UnknownRdataDumper(oss));
376 size_t this_len = lhs.
data_.size();
377 size_t other_len = rhs.
data_.size();
378 size_t len = (this_len < other_len) ? this_len : other_len;
384 ((cmp = memcmp(&lhs.
data_[0], &rhs.
data_[0], len)) != 0)) {
387 return ((this_len == other_len) ? 0 :
388 (this_len < other_len) ? -1 : 1);
397 return (compare_internal(*impl_, *other_rdata.impl_));
402 return (os << rdata.
toText());
The Name class encapsulates DNS names.
const size_t MAX_RDLENGTH
Possible maximum length of RDATA, which is the maximum unsigned 16 bit value.
bool pushSource(const char *filename, std::string *error=NULL)
Open a file and make it the current input source of MasterLexer.
virtual ~Generic()
The destructor.
virtual std::string toText() const
Convert an generic::Generic object to a string.
size_t getSourceLine() const
Return the input source line number.
Generic & operator=(const Generic &source)
The assignment operator.
Exception thrown from a wrapper version of MasterLexer::getNextToken() for non fatal errors...
The Rdata class is an abstract base class that provides a set of common interfaces to manipulate conc...
uint8_t at(size_t pos) const
Provides one-byte name data in wire format at the specified position.
The generic::Generic class represents generic "unknown" RDATA.
std::ostream & operator<<(std::ostream &os, const Generic &rdata)
Insert the name as a string into stream.
GenericImpl(const vector< uint8_t > &data)
The RRClass class encapsulates DNS resource record classes.
void warning(const std::string &source_name, size_t source_line, const std::string &reason) const
Call callback for potential problems.
Options
Options how the parsing should work.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the buffer.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
A standard DNS module exception that is thrown if RDATA parser fails to recognize a given textual rep...
void decodeHex(const string &input, vector< uint8_t > &result)
Decode a text encoded in the base16 ('hex') format into the original data.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the internal buffer of the renderer object. ...
RdataPtr createRdata(const RRType &rrtype, const RRClass &rrclass, MasterLexer &lexer, const Name *origin, MasterLoader::Options options, MasterLoaderCallbacks &callbacks)
Create RDATA of a given pair of RR type and class using the master lexer.
std::string getSourceName() const
Return the name of the current input source name.
A standard DNS module exception that is thrown if RDATA parser encounters an invalid or inconsistent ...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
const MasterToken & getNextToken(Options options=NONE)
Parse and return another token from the input.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Generic(const std::string &rdata_string)
Constructor from a string.
std::string getErrorText() const
Return a textual description of the error of a error type token.
Defines the logger used by the top-level component of kea-dhcp-ddns.
void ungetToken()
Return the last token back to the lexer.
virtual int compare(const Rdata &other) const
Compare two instances of generic::Generic objects.
int compareNames(const Name &n1, const Name &n2)
Gives relative ordering of two names in terms of DNSSEC RDATA ordering.
size_t getLength() const
Gets the length of the Name in its wire format.
The RRType class encapsulates DNS resource record types.
uint32_t getNumber() const
Return the value of a string-variant token as a string object.
Type getType() const
Return the token type.
virtual void toWire(isc::util::OutputBuffer &buffer) const
Render the generic::Generic in the wire format into a buffer.
size_t getLength() const
Return the length of data written in the buffer.
std::string getString() const
Return the value of a string-variant token as a string object.
Tokenizer for parsing DNS master files.
Set of issue callbacks for a loader.
boost::shared_ptr< Rdata > RdataPtr
The RdataPtr type is a pointer-like type, pointing to an object of some concrete derived class of Rda...
void error(const std::string &source_name, size_t source_line, const std::string &reason) const
Call callback for serious errors.