20#include <boost/lexical_cast.hpp>
21#include <boost/shared_ptr.hpp>
36using boost::lexical_cast;
55 const std::string& rdata_string) {
89fromtextError(
bool& error_issued,
const MasterLexer& lexer,
100 "createRdata from text failed: " +
string(reason));
108 "createRdata from text failed near '" +
109 token->
getString() +
"': " +
string(reason));
113 "createRdata from text failed: " +
133 bool error_issued =
false;
136 rrtype, rrclass, lexer, origin, options, callbacks);
138 fromtextError(error_issued, lexer, callbacks, &error.token_,
"");
143 fromtextError(error_issued, lexer, callbacks, 0, ex.
what());
158 "file does not end with newline");
162 fromtextError(error_issued, lexer, callbacks, &token,
177 size_t cmplen = min(len1, len2);
179 for (
size_t i = 0; i < cmplen; ++i) {
180 uint8_t c1 = tolower(n1.
at(i));
181 uint8_t c2 = tolower(n2.
at(i));
184 }
else if (c1 > c2) {
189 return ((len1 == len2) ? 0 : (len1 < len2) ? -1 : 1);
203 vector<uint8_t> data(rdata_len);
205 buffer.
readData(&data[0], rdata_len);
211std::unique_ptr<GenericImpl>
216 "Missing the special token (\\#) for "
217 "unknown RDATA encoding");
221 uint32_t rdlen = 65536;
227 "Unknown RDATA length is invalid");
232 "Unknown RDATA length is out of range: " << rdlen);
235 vector<uint8_t> data;
242 const MasterToken& rdtoken =
253 hex_txt.append(hex_part);
260 "Invalid hex encoding of generic RDATA: " << ex.
what());
264 if (data.size() != rdlen) {
266 "Size of unknown RDATA hex data doesn't match RDLENGTH: "
267 << data.size() <<
" vs. " << rdlen);
270 return (std::unique_ptr<GenericImpl>(
new GenericImpl(data)));
275 std::istringstream ss(rdata_string);
279 impl_ = constructFromLexer(lexer);
287 "from '" << rdata_string <<
"': " << ex.
what());
294 impl_ = constructFromLexer(lexer);
309 if (impl_ == source.impl_) {
319class UnknownRdataDumper {
321 UnknownRdataDumper(ostringstream& oss) : oss_(&oss) {}
322 void operator()(
const unsigned char d)
324 *oss_ << setw(2) << static_cast<unsigned int>(d);
335 oss <<
"\\# " << impl_->data_.size() <<
" ";
338 for_each(impl_->data_.begin(), impl_->data_.end(), UnknownRdataDumper(oss));
345 buffer.
writeData(&impl_->data_[0], impl_->data_.size());
350 renderer.
writeData(&impl_->data_[0], impl_->data_.size());
356 size_t this_len = lhs.
data_.size();
357 size_t other_len = rhs.
data_.size();
358 size_t len = (this_len < other_len) ? this_len : other_len;
364 ((cmp = memcmp(&lhs.
data_[0], &rhs.
data_[0], len)) != 0)) {
367 return ((this_len == other_len) ? 0 :
368 (this_len < other_len) ? -1 : 1);
377 return (compare_internal(*impl_, *other_rdata.impl_));
382 return (os << rdata.
toText());
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when an unexpected error condition occurs.
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the internal buffer of the renderer object.
Exception thrown from a wrapper version of MasterLexer::getNextToken() for non fatal errors.
Tokenizer for parsing DNS master files.
void ungetToken()
Return the last token back to the lexer.
bool pushSource(const char *filename, std::string *error=0)
Open a file and make it the current input source of MasterLexer.
std::string getSourceName() const
Return the name of the current input source name.
const MasterToken & getNextToken(Options options=NONE)
Parse and return another token from the input.
size_t getSourceLine() const
Return the input source line number.
Set of issue callbacks for a loader.
void error(const std::string &source_name, size_t source_line, const std::string &reason) const
Call callback for serious errors.
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.
uint32_t getNumber() const
Return the value of a string-variant token as a string object.
std::string getString() const
Return the value of a string-variant token as a string object.
@ ERROR
Error detected in getting a token.
@ NUMBER
A decimal number (unsigned 32-bit)
@ END_OF_LINE
End of line detected.
@ QSTRING
A single string quoted by double-quotes (").
@ END_OF_FILE
End of file detected.
Type getType() const
Return the token type.
std::string getErrorText() const
Return a textual description of the error of a error type token.
The Name class encapsulates DNS names.
uint8_t at(size_t pos) const
Provides one-byte name data in wire format at the specified position.
size_t getLength() const
Gets the length of the Name in its wire format.
The RRClass class encapsulates DNS resource record classes.
rdata::RdataPtr createRdata(const RRType &rrtype, const RRClass &rrclass, const std::string &rdata_string)
Create RDATA of a given pair of RR type and class from a string.
static RRParamRegistry & getRegistry()
Return the singleton instance of RRParamRegistry.
The RRType class encapsulates DNS resource record types.
A standard DNS module exception that is thrown if RDATA parser encounters an invalid or inconsistent ...
A standard DNS module exception that is thrown if RDATA parser fails to recognize a given textual rep...
The Rdata class is an abstract base class that provides a set of common interfaces to manipulate conc...
virtual uint16_t getLength() const
Get the wire format length of an Rdata.
virtual void toWire(isc::util::OutputBuffer &buff) const =0
Render the Rdata in the wire format into a buffer.
The generic::Generic class represents generic "unknown" RDATA.
virtual ~Generic()
The destructor.
Generic & operator=(const Generic &source)
The assignment operator.
Generic(const std::string &rdata_string)
Constructor from a string.
virtual std::string toText() const
Convert an generic::Generic object to a string.
virtual void toWire(isc::util::OutputBuffer &buff) const
Render the generic::Generic in the wire format into a buffer.
virtual int compare(const Rdata &other) const
Compare two instances of generic::Generic objects.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the buffer.
size_t getLength() const
Return the length of data written in the buffer.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define isc_throw_assert(expr)
Replacement for assert() that throws if the expression is false.
std::ostream & operator<<(std::ostream &os, const Generic &rdata)
Insert the name as a string into stream.
int compareNames(const Name &n1, const Name &n2)
Gives relative ordering of two names in terms of DNSSEC RDATA ordering.
RdataPtr createRdata(const RRType &rrtype, const RRClass &rrclass, const std::string &rdata_string)
Create RDATA of a given pair of RR type and class from a string.
const size_t MAX_RDLENGTH
Possible maximum length of RDATA, which is the maximum unsigned 16 bit value.
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 decodeHex(const string &encoded_str, vector< uint8_t > &output)
Decode a base16 encoded string into binary data.
Defines the logger used by the top-level component of kea-lfc.
GenericImpl(const vector< uint8_t > &data)