Browse Source

[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.

JINMEI Tatuya 14 years ago
parent
commit
28143beb0e

+ 21 - 8
src/lib/dns/edns.cc

@@ -110,19 +110,25 @@ EDNS::toText() const {
     return (ret);
     return (ret);
 }
 }
 
 
+namespace {
+/// Helper function to define unified implementation for the public versions
+/// of toWire().
 template <typename Output>
 template <typename Output>
 int
 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
     // Render EDNS OPT RR
     uint32_t extrcode_flags = extended_rcode << EXTRCODE_SHIFT;
     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;
         extrcode_flags |= EXTFLAG_DO;
     }
     }
 
 
     // Construct an RRset corresponding to the EDNS.
     // Construct an RRset corresponding to the EDNS.
     // We don't support any options for now, so the OPT RR can be empty.
     // 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)));
                                   RRType::OPT(), RRTTL(extrcode_flags)));
     edns_rrset->addRdata(ConstRdataPtr(new generic::OPT()));
     edns_rrset->addRdata(ConstRdataPtr(new generic::OPT()));
 
 
@@ -130,9 +136,12 @@ EDNS::toWire(Output& output, const uint8_t extended_rcode) const {
 
 
     return (1);
     return (1);
 }
 }
+}
 
 
 unsigned int
 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.
     // If adding the OPT RR would exceed the size limit, don't do it.
     // 11 = len(".") + type(2byte) + class(2byte) + TTL(4byte) + RDLEN(2byte)
     // 11 = len(".") + type(2byte) + class(2byte) + TTL(4byte) + RDLEN(2byte)
     // (RDATA is empty in this simple implementation)
     // (RDATA is empty in this simple implementation)
@@ -140,12 +149,16 @@ EDNS::toWire(MessageRenderer& renderer, const uint8_t extended_rcode) const {
         return (0);
         return (0);
     }
     }
 
 
-    return (toWire<MessageRenderer>(renderer, extended_rcode));
+    return (toWireCommon(renderer, version_, udp_size_, dnssec_aware_,
+                         extended_rcode));
 }
 }
 
 
 unsigned int
 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*
 EDNS*

+ 2 - 8
src/lib/dns/edns.h

@@ -32,7 +32,7 @@ namespace dns {
 
 
 class EDNS;
 class EDNS;
 class Name;
 class Name;
-class MessageRenderer;
+class AbstractMessageRenderer;
 class RRClass;
 class RRClass;
 class RRTTL;
 class RRTTL;
 class RRType;
 class RRType;
@@ -314,7 +314,7 @@ public:
     /// \param extended_rcode Upper 8 bits of extended RCODE to be rendered as
     /// \param extended_rcode Upper 8 bits of extended RCODE to be rendered as
     /// part of the EDNS OPT RR.
     /// part of the EDNS OPT RR.
     /// \return 1 if the OPT RR fits in the message size limit; otherwise 0.
     /// \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;
                         const uint8_t extended_rcode) const;
 
 
     /// \brief Render the \c EDNS in the wire format.
     /// \brief Render the \c EDNS in the wire format.
@@ -354,12 +354,6 @@ public:
     // something like this.
     // something like this.
     //void addOption();
     //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:
 public:
     /// \brief The highest EDNS version this implementation supports.
     /// \brief The highest EDNS version this implementation supports.
     static const uint8_t SUPPORTED_VERSION = 0;
     static const uint8_t SUPPORTED_VERSION = 0;

+ 6 - 6
src/lib/dns/message.cc

@@ -125,7 +125,7 @@ public:
     void setRcode(const Rcode& rcode);
     void setRcode(const Rcode& rcode);
     int parseQuestion(InputBuffer& buffer);
     int parseQuestion(InputBuffer& buffer);
     int parseSection(const Message::Section section, 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) :
 MessageImpl::MessageImpl(Message::Mode mode) :
@@ -170,7 +170,7 @@ MessageImpl::setRcode(const Rcode& rcode) {
 namespace {
 namespace {
 template <typename T>
 template <typename T>
 struct RenderSection {
 struct RenderSection {
-    RenderSection(MessageRenderer& renderer, const bool partial_ok) :
+    RenderSection(AbstractMessageRenderer& renderer, const bool partial_ok) :
         counter_(0), renderer_(renderer), partial_ok_(partial_ok),
         counter_(0), renderer_(renderer), partial_ok_(partial_ok),
         truncated_(false)
         truncated_(false)
     {}
     {}
@@ -191,14 +191,14 @@ struct RenderSection {
     }
     }
     unsigned int getTotalCount() { return (counter_); }
     unsigned int getTotalCount() { return (counter_); }
     unsigned int counter_;
     unsigned int counter_;
-    MessageRenderer& renderer_;
+    AbstractMessageRenderer& renderer_;
     const bool partial_ok_;
     const bool partial_ok_;
     bool truncated_;
     bool truncated_;
 };
 };
 }
 }
 
 
 void
 void
-MessageImpl::toWire(MessageRenderer& renderer, TSIGContext* tsig_ctx) {
+MessageImpl::toWire(AbstractMessageRenderer& renderer, TSIGContext* tsig_ctx) {
     if (mode_ != Message::RENDER) {
     if (mode_ != Message::RENDER) {
         isc_throw(InvalidMessageOperation,
         isc_throw(InvalidMessageOperation,
                   "Message rendering attempted in non render mode");
                   "Message rendering attempted in non render mode");
@@ -500,12 +500,12 @@ Message::addQuestion(const Question& question) {
 }
 }
 
 
 void
 void
-Message::toWire(MessageRenderer& renderer) {
+Message::toWire(AbstractMessageRenderer& renderer) {
     impl_->toWire(renderer, NULL);
     impl_->toWire(renderer, NULL);
 }
 }
 
 
 void
 void
-Message::toWire(MessageRenderer& renderer, TSIGContext& tsig_ctx) {
+Message::toWire(AbstractMessageRenderer& renderer, TSIGContext& tsig_ctx) {
     impl_->toWire(renderer, &tsig_ctx);
     impl_->toWire(renderer, &tsig_ctx);
 }
 }
 
 

+ 1 - 1
src/lib/dns/question.cc

@@ -56,7 +56,7 @@ Question::toWire(OutputBuffer& buffer) const {
 }
 }
 
 
 unsigned int
 unsigned int
-Question::toWire(MessageRenderer& renderer) const {
+Question::toWire(AbstractMessageRenderer& renderer) const {
     renderer.writeName(name_);
     renderer.writeName(name_);
     rrtype_.toWire(renderer);
     rrtype_.toWire(renderer);
     rrclass_.toWire(renderer);
     rrclass_.toWire(renderer);

+ 3 - 3
src/lib/dns/question.h

@@ -32,7 +32,7 @@ class OutputBuffer;
 
 
 namespace dns {
 namespace dns {
 
 
-class MessageRenderer;
+class AbstractMessageRenderer;
 class Question;
 class Question;
 
 
 /// \brief A pointer-like type pointing to an \c Question object.
 /// \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
     /// \param renderer DNS message rendering context that encapsulates the
     /// output buffer and name compression information.
     /// output buffer and name compression information.
     /// \return 1
     /// \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.
     /// \brief Render the Question in the wire format without name compression.
     ///
     ///
     /// This method behaves like the render version except it doesn't compress
     /// This method behaves like the render version except it doesn't compress
     /// the owner name.
     /// 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.
     /// \param buffer An output buffer to store the wire data.
     /// \return 1
     /// \return 1

+ 3 - 3
src/lib/dns/rrset.cc

@@ -104,8 +104,8 @@ AbstractRRset::toWire(OutputBuffer& buffer) const {
 }
 }
 
 
 unsigned int
 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());
         *this, renderer, renderer.getLengthLimit());
     if (getRdataCount() > rrs_written) {
     if (getRdataCount() > rrs_written) {
         renderer.setTruncated();
         renderer.setTruncated();
@@ -202,7 +202,7 @@ BasicRRset::toWire(OutputBuffer& buffer) const {
 }
 }
 
 
 unsigned int
 unsigned int
-BasicRRset::toWire(MessageRenderer& renderer) const {
+BasicRRset::toWire(AbstractMessageRenderer& renderer) const {
     return (AbstractRRset::toWire(renderer));
     return (AbstractRRset::toWire(renderer));
 }
 }
 
 

+ 3 - 3
src/lib/dns/rrset.h

@@ -47,7 +47,7 @@ class Name;
 class RRType;
 class RRType;
 class RRClass;
 class RRClass;
 class RRTTL;
 class RRTTL;
-class MessageRenderer;
+class AbstractMessageRenderer;
 class AbstractRRset;
 class AbstractRRset;
 class BasicRRset;
 class BasicRRset;
 class RdataIterator;
 class RdataIterator;
@@ -311,7 +311,7 @@ public:
     /// \return The number of RRs rendered.  If the truncation is necessary
     /// \return The number of RRs rendered.  If the truncation is necessary
     /// this value may be different from the number of RDATA objects contained
     /// this value may be different from the number of RDATA objects contained
     /// in the RRset.
     /// 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.
     /// \brief Render the RRset in the wire format without any compression.
     ///
     ///
@@ -617,7 +617,7 @@ public:
     ///
     ///
     /// This method simply uses the default implementation.
     /// This method simply uses the default implementation.
     /// See \c AbstractRRset::toWire(MessageRenderer&)const.
     /// 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.
     /// \brief Render the RRset in the wire format without any compression.
     ///
     ///

+ 1 - 1
src/lib/dns/rrttl.cc

@@ -63,7 +63,7 @@ RRTTL::toWire(OutputBuffer& buffer) const {
 }
 }
 
 
 void
 void
-RRTTL::toWire(MessageRenderer& renderer) const {
+RRTTL::toWire(AbstractMessageRenderer& renderer) const {
     renderer.writeUint32(ttlval_);
     renderer.writeUint32(ttlval_);
 }
 }
 
 

+ 2 - 2
src/lib/dns/rrttl.h

@@ -28,7 +28,7 @@ class OutputBuffer;
 namespace dns {
 namespace dns {
 
 
 // forward declarations
 // forward declarations
-class MessageRenderer;
+class AbstractMessageRenderer;
 
 
 ///
 ///
 /// \brief A standard DNS module exception that is thrown if an RRTTL object
 /// \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
     /// \param renderer DNS message rendering context that encapsulates the
     /// output buffer in which the RRTTL is to be stored.
     /// 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.
     /// \brief Render the \c RRTTL in the wire format.
     ///
     ///
     /// This method renders the TTL value in network byte order into the
     /// This method renders the TTL value in network byte order into the