Commit 28143beb authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[trac812next] made straightforward changes to toWire() methods so that

they use AbstractMessageRenderer.
not related to the subject of this branch, but we'll need this change anyway,
and touching some toWire()s is a good opportunity to make this happen.
parent 76705c8f
......@@ -110,19 +110,25 @@ EDNS::toText() const {
return (ret);
}
namespace {
/// Helper function to define unified implementation for the public versions
/// of toWire().
template <typename Output>
int
EDNS::toWire(Output& output, const uint8_t extended_rcode) const {
toWireCommon(Output& output, const uint8_t version,
const uint16_t udp_size, const bool dnssec_aware,
const uint8_t extended_rcode)
{
// Render EDNS OPT RR
uint32_t extrcode_flags = extended_rcode << EXTRCODE_SHIFT;
extrcode_flags |= (version_ << VERSION_SHIFT) & VERSION_MASK;
if (dnssec_aware_) {
extrcode_flags |= (version << VERSION_SHIFT) & VERSION_MASK;
if (dnssec_aware) {
extrcode_flags |= EXTFLAG_DO;
}
// Construct an RRset corresponding to the EDNS.
// We don't support any options for now, so the OPT RR can be empty.
RRsetPtr edns_rrset(new RRset(Name::ROOT_NAME(), RRClass(udp_size_),
RRsetPtr edns_rrset(new RRset(Name::ROOT_NAME(), RRClass(udp_size),
RRType::OPT(), RRTTL(extrcode_flags)));
edns_rrset->addRdata(ConstRdataPtr(new generic::OPT()));
......@@ -130,9 +136,12 @@ EDNS::toWire(Output& output, const uint8_t extended_rcode) const {
return (1);
}
}
unsigned int
EDNS::toWire(MessageRenderer& renderer, const uint8_t extended_rcode) const {
EDNS::toWire(AbstractMessageRenderer& renderer,
const uint8_t extended_rcode) const
{
// If adding the OPT RR would exceed the size limit, don't do it.
// 11 = len(".") + type(2byte) + class(2byte) + TTL(4byte) + RDLEN(2byte)
// (RDATA is empty in this simple implementation)
......@@ -140,12 +149,16 @@ EDNS::toWire(MessageRenderer& renderer, const uint8_t extended_rcode) const {
return (0);
}
return (toWire<MessageRenderer>(renderer, extended_rcode));
return (toWireCommon(renderer, version_, udp_size_, dnssec_aware_,
extended_rcode));
}
unsigned int
EDNS::toWire(isc::util::OutputBuffer& buffer, const uint8_t extended_rcode) const {
return (toWire<isc::util::OutputBuffer>(buffer, extended_rcode));
EDNS::toWire(isc::util::OutputBuffer& buffer,
const uint8_t extended_rcode) const
{
return (toWireCommon(buffer, version_, udp_size_, dnssec_aware_,
extended_rcode));
}
EDNS*
......
......@@ -32,7 +32,7 @@ namespace dns {
class EDNS;
class Name;
class MessageRenderer;
class AbstractMessageRenderer;
class RRClass;
class RRTTL;
class RRType;
......@@ -314,7 +314,7 @@ public:
/// \param extended_rcode Upper 8 bits of extended RCODE to be rendered as
/// part of the EDNS OPT RR.
/// \return 1 if the OPT RR fits in the message size limit; otherwise 0.
unsigned int toWire(MessageRenderer& renderer,
unsigned int toWire(AbstractMessageRenderer& renderer,
const uint8_t extended_rcode) const;
/// \brief Render the \c EDNS in the wire format.
......@@ -354,12 +354,6 @@ public:
// something like this.
//void addOption();
private:
/// Helper method to define unified implementation for the public versions
/// of toWire().
template <typename Output>
int toWire(Output& output, const uint8_t extended_rcode) const;
public:
/// \brief The highest EDNS version this implementation supports.
static const uint8_t SUPPORTED_VERSION = 0;
......
......@@ -125,7 +125,7 @@ public:
void setRcode(const Rcode& rcode);
int parseQuestion(InputBuffer& buffer);
int parseSection(const Message::Section section, InputBuffer& buffer);
void toWire(MessageRenderer& renderer, TSIGContext* tsig_ctx);
void toWire(AbstractMessageRenderer& renderer, TSIGContext* tsig_ctx);
};
MessageImpl::MessageImpl(Message::Mode mode) :
......@@ -170,7 +170,7 @@ MessageImpl::setRcode(const Rcode& rcode) {
namespace {
template <typename T>
struct RenderSection {
RenderSection(MessageRenderer& renderer, const bool partial_ok) :
RenderSection(AbstractMessageRenderer& renderer, const bool partial_ok) :
counter_(0), renderer_(renderer), partial_ok_(partial_ok),
truncated_(false)
{}
......@@ -191,14 +191,14 @@ struct RenderSection {
}
unsigned int getTotalCount() { return (counter_); }
unsigned int counter_;
MessageRenderer& renderer_;
AbstractMessageRenderer& renderer_;
const bool partial_ok_;
bool truncated_;
};
}
void
MessageImpl::toWire(MessageRenderer& renderer, TSIGContext* tsig_ctx) {
MessageImpl::toWire(AbstractMessageRenderer& renderer, TSIGContext* tsig_ctx) {
if (mode_ != Message::RENDER) {
isc_throw(InvalidMessageOperation,
"Message rendering attempted in non render mode");
......@@ -500,12 +500,12 @@ Message::addQuestion(const Question& question) {
}
void
Message::toWire(MessageRenderer& renderer) {
Message::toWire(AbstractMessageRenderer& renderer) {
impl_->toWire(renderer, NULL);
}
void
Message::toWire(MessageRenderer& renderer, TSIGContext& tsig_ctx) {
Message::toWire(AbstractMessageRenderer& renderer, TSIGContext& tsig_ctx) {
impl_->toWire(renderer, &tsig_ctx);
}
......
......@@ -56,7 +56,7 @@ Question::toWire(OutputBuffer& buffer) const {
}
unsigned int
Question::toWire(MessageRenderer& renderer) const {
Question::toWire(AbstractMessageRenderer& renderer) const {
renderer.writeName(name_);
rrtype_.toWire(renderer);
rrclass_.toWire(renderer);
......
......@@ -32,7 +32,7 @@ class OutputBuffer;
namespace dns {
class MessageRenderer;
class AbstractMessageRenderer;
class Question;
/// \brief A pointer-like type pointing to an \c Question object.
......@@ -218,13 +218,13 @@ public:
/// \param renderer DNS message rendering context that encapsulates the
/// output buffer and name compression information.
/// \return 1
unsigned int toWire(MessageRenderer& renderer) const;
unsigned int toWire(AbstractMessageRenderer& renderer) const;
/// \brief Render the Question in the wire format without name compression.
///
/// This method behaves like the render version except it doesn't compress
/// the owner name.
/// See \c toWire(MessageRenderer& renderer)const.
/// See \c toWire(AbstractMessageRenderer& renderer)const.
///
/// \param buffer An output buffer to store the wire data.
/// \return 1
......
......@@ -104,8 +104,8 @@ AbstractRRset::toWire(OutputBuffer& buffer) const {
}
unsigned int
AbstractRRset::toWire(MessageRenderer& renderer) const {
const unsigned int rrs_written = rrsetToWire<MessageRenderer>(
AbstractRRset::toWire(AbstractMessageRenderer& renderer) const {
const unsigned int rrs_written = rrsetToWire<AbstractMessageRenderer>(
*this, renderer, renderer.getLengthLimit());
if (getRdataCount() > rrs_written) {
renderer.setTruncated();
......@@ -202,7 +202,7 @@ BasicRRset::toWire(OutputBuffer& buffer) const {
}
unsigned int
BasicRRset::toWire(MessageRenderer& renderer) const {
BasicRRset::toWire(AbstractMessageRenderer& renderer) const {
return (AbstractRRset::toWire(renderer));
}
......
......@@ -47,7 +47,7 @@ class Name;
class RRType;
class RRClass;
class RRTTL;
class MessageRenderer;
class AbstractMessageRenderer;
class AbstractRRset;
class BasicRRset;
class RdataIterator;
......@@ -311,7 +311,7 @@ public:
/// \return The number of RRs rendered. If the truncation is necessary
/// this value may be different from the number of RDATA objects contained
/// in the RRset.
virtual unsigned int toWire(MessageRenderer& renderer) const = 0;
virtual unsigned int toWire(AbstractMessageRenderer& renderer) const = 0;
/// \brief Render the RRset in the wire format without any compression.
///
......@@ -617,7 +617,7 @@ public:
///
/// This method simply uses the default implementation.
/// See \c AbstractRRset::toWire(MessageRenderer&)const.
virtual unsigned int toWire(MessageRenderer& renderer) const;
virtual unsigned int toWire(AbstractMessageRenderer& renderer) const;
/// \brief Render the RRset in the wire format without any compression.
///
......
......@@ -63,7 +63,7 @@ RRTTL::toWire(OutputBuffer& buffer) const {
}
void
RRTTL::toWire(MessageRenderer& renderer) const {
RRTTL::toWire(AbstractMessageRenderer& renderer) const {
renderer.writeUint32(ttlval_);
}
......
......@@ -28,7 +28,7 @@ class OutputBuffer;
namespace dns {
// forward declarations
class MessageRenderer;
class AbstractMessageRenderer;
///
/// \brief A standard DNS module exception that is thrown if an RRTTL object
......@@ -123,7 +123,7 @@ public:
///
/// \param renderer DNS message rendering context that encapsulates the
/// output buffer in which the RRTTL is to be stored.
void toWire(MessageRenderer& renderer) const;
void toWire(AbstractMessageRenderer& renderer) const;
/// \brief Render the \c RRTTL in the wire format.
///
/// This method renders the TTL value in network byte order into the
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment