Branch data Line data Source code
1 : : // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
2 : : //
3 : : // Permission to use, copy, modify, and/or distribute this software for any
4 : : // purpose with or without fee is hereby granted, provided that the above
5 : : // copyright notice and this permission notice appear in all copies.
6 : : //
7 : : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
8 : : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9 : : // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
10 : : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11 : : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
12 : : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13 : : // PERFORMANCE OF THIS SOFTWARE.
14 : :
15 : : #ifndef __RBNODE_RRSET_H
16 : : #define __RBNODE_RRSET_H
17 : :
18 : : #include <dns/messagerenderer.h>
19 : : #include <dns/name.h>
20 : : #include <dns/rrclass.h>
21 : : #include <dns/rrset.h>
22 : : #include <dns/rrttl.h>
23 : : #include <dns/rrtype.h>
24 : : #include <util/buffer.h>
25 : :
26 : : #include <string>
27 : : #include <vector>
28 : :
29 : : namespace isc {
30 : : namespace datasrc {
31 : : namespace internal {
32 : :
33 : : /// \brief The actual content of \c RBNodeRRset
34 : : ///
35 : : /// This is defined in the namespace-scope (not hidden in the main class)
36 : : /// so that the In-memory data source implementation can refer to it.
37 : : struct RBNodeRRsetImpl;
38 : :
39 : : // Forward declaration of an opaque data type defined and used within the
40 : : // implementation. This is public only because it needs to be used within
41 : : // the in-memory data source implementation, but conceptually this is a
42 : : // private type for the in-memory data source implementation.
43 : : // Note that the definition of the structure is still hidden within the
44 : : // implementation, so, basically, a normal application should never be able
45 : : // to use it directly even if it peeks into the "internal" namespace.
46 : : struct AdditionalNodeInfo;
47 : :
48 : : /// \brief Special RRset for optimizing memory datasource requirement
49 : : ///
50 : : /// To speed up the performance of the in-memory data source, at load time
51 : : /// associate relevant "additional section" data with each RRset in the
52 : : /// data source.
53 : : ///
54 : : /// This class, derived from AbstractRRset, holds a "const" pointer to the
55 : : /// underlying RRset object. All calls to methods on the class are passed to
56 : : /// the underlying object. However, there are some restrictions:
57 : : ///
58 : : /// - Calls to methods that change attributes of the underlying RRset (such as
59 : : /// TTL or Name) cause an exception to be thrown. The in-memory data source
60 : : /// does not allow modification of these attributes. In theory, it is a bad
61 : : /// practice in that it doesn't preserve the assumed behavior of the base
62 : : /// class. In practice, however, it should be acceptable because this
63 : : /// class is effectively hidden from applications and will only be given
64 : : /// to them as a const pointer to the base class via find() variants.
65 : : /// So the application cannot call non const methods anyway unless it
66 : : /// intentionally breaks the constness.
67 : : ///
68 : : /// - Calls that add the pointer to the associated RRSIG to the RRset are
69 : : /// allowed (even though the pointer is to a "const" RRset). The reason here
70 : : /// is that RRSIGs are added to the in-memory data source after the
71 : : /// RBNodeRRset objects have been created. Thus there has to be the
72 : : /// capability of modifying this information.
73 : : ///
74 : : /// The class is not derived from RRset itself to simplify coding: part of the
75 : : /// loading of the memory data source is handled in the BIND 10 "libdns++"
76 : : /// code, which creates RRsets and passes them to the data source code. This
77 : : /// does not have to be altered if encapsulation, rather than inheritance, is
78 : : /// used.
79 : : ///
80 : : /// \note This class is exposed in this separate header file so that test code
81 : : /// can refer to its definition, and only for that purpose. Otherwise this is
82 : : /// essentially a private class of the in-memory data source implementation,
83 : : /// and an application shouldn't directly refer to this class.
84 : : ///
85 : : // Note: non-Doxygen-documented methods are documented in the base class.
86 : :
87 : : class RBNodeRRset : public isc::dns::AbstractRRset {
88 : :
89 : : private:
90 : : // Note: The copy constructor and the assignment operator are intentionally
91 : : // defined as private as we would normally not duplicate a RBNodeRRset.
92 : : // (We use the "private" method instead of inheriting from
93 : : // boost::noncopyable so as to avoid multiple inheritance.)
94 : : RBNodeRRset(const RBNodeRRset& source);
95 : : RBNodeRRset& operator=(const RBNodeRRset& source);
96 : :
97 : : public:
98 : : /// \brief Usual Constructor
99 : : ///
100 : : /// Creates an RBNodeRRset from the pointer to the RRset passed to it.
101 : : ///
102 : : /// \param rrset Pointer to underlying RRset encapsulated by this object.
103 : : explicit RBNodeRRset(const isc::dns::ConstRRsetPtr& rrset);
104 : :
105 : : /// \brief Destructor
106 : : virtual ~RBNodeRRset();
107 : :
108 : : // Getter and Setter Methods
109 : : //
110 : : // The getter methods pass the call through to the underlying RRset. The
111 : : // setter methods thrown an exception - this specialisation of the RRset
112 : : // object does not expect the underlying RRset to be modified.
113 : :
114 : : virtual unsigned int getRdataCount() const;
115 : :
116 : : virtual const isc::dns::Name& getName() const;
117 : :
118 : : virtual const isc::dns::RRClass& getClass() const;
119 : :
120 : : virtual const isc::dns::RRType& getType() const;
121 : :
122 : : virtual const isc::dns::RRTTL& getTTL() const;
123 : :
124 : : virtual void setName(const isc::dns::Name&);
125 : :
126 : : virtual void setTTL(const isc::dns::RRTTL&);
127 : :
128 : : virtual std::string toText() const;
129 : :
130 : 35 : virtual bool isSameKind(const AbstractRRset& other) const {
131 : : // This code is an optimisation for comparing
132 : : // RBNodeRRsets. However, in doing this optimisation,
133 : : // semantically the code is not "is same kind" but is instead
134 : : // "is identical object" in the case where RBNodeRRsets are compared.
135 : :
136 [ + - ]: 35 : const RBNodeRRset* rb = dynamic_cast<const RBNodeRRset*>(&other);
137 [ + + ]: 35 : if (rb != NULL) {
138 : 25 : return (this == rb);
139 : : } else {
140 : 35 : return (AbstractRRset::isSameKind(other));
141 : : }
142 : : }
143 : :
144 : : virtual unsigned int toWire(
145 : : isc::dns::AbstractMessageRenderer& renderer) const;
146 : :
147 : : virtual unsigned int toWire(isc::util::OutputBuffer& buffer) const;
148 : :
149 : : virtual void addRdata(isc::dns::rdata::ConstRdataPtr);
150 : :
151 : : virtual void addRdata(const isc::dns::rdata::Rdata&);
152 : :
153 : : virtual isc::dns::RdataIteratorPtr getRdataIterator() const;
154 : :
155 : : virtual isc::dns::RRsetPtr getRRsig() const;
156 : :
157 : : // With all the RRsig methods, we have the problem that we store the
158 : : // underlying RRset using a ConstRRsetPtr - a pointer to a "const" RRset -
159 : : // but we need to modify it by adding or removing an RRSIG. We overcome
160 : : // this by temporarily violating the "const" nature of the RRset to add the
161 : : // data.
162 : :
163 : : virtual void addRRsig(const isc::dns::rdata::ConstRdataPtr& rdata);
164 : :
165 : : virtual void addRRsig(const isc::dns::rdata::RdataPtr& rdata);
166 : :
167 : : virtual void addRRsig(const AbstractRRset& sigs);
168 : :
169 : : virtual void addRRsig(const isc::dns::ConstRRsetPtr& sigs);
170 : :
171 : : virtual void addRRsig(const isc::dns::RRsetPtr& sigs);
172 : :
173 : : virtual void removeRRsig();
174 : :
175 : : /// \brief Associate a link to an RB node of the additional record.
176 : : ///
177 : : /// This method adds a given opaque object that holds a link to an RB node
178 : : /// of the underlying in-memory data source that is corresponding to an
179 : : /// RDATA of this RRset.
180 : : ///
181 : : /// This method is exposed as public so it can be used within the in-memory
182 : : /// data source implementation, and only for that purpose.
183 : : ///
184 : : /// \param additional An opaque \c AdditionalNodeInfo object to be
185 : : /// associated with this RRset.
186 : : void addAdditionalNode(const AdditionalNodeInfo& additional);
187 : :
188 : : /// \brief Return a pointer to the list (vector) of additional RB nodes.
189 : : ///
190 : : /// This method returns a pointer to a vector storing the opaque
191 : : /// \c AdditionalNodeInfo object that may be possibly set in this RRset.
192 : : /// Not all RRsets are associated with additional nodes; if no
193 : : /// such node is stored, this method returns NULL.
194 : : ///
195 : : /// Like \c addAdditionalNode(), this method is exposed as public only for
196 : : /// the in-memory data source implementation.
197 : : ///
198 : : /// \return A pointer to the associated vector of \c AdditionalNodeInfo;
199 : : /// NULL if no additional nodes are associated to this RRset.
200 : : const std::vector<AdditionalNodeInfo>* getAdditionalNodes() const;
201 : :
202 : : /// \brief Copy the list of additional RB nodes to another RRset.
203 : : ///
204 : : /// This method copies the internal list (an STL vector in the actual
205 : : /// implementation) of additional RB nodes for this RRset to another
206 : : /// \c RBNodeRRset object. The copy destination is generally expected to
207 : : /// be newly created and have an empty list, but this method does not
208 : : /// check the condition. If the destination already has a non empty list,
209 : : /// the existing entries will be lost.
210 : : ///
211 : : /// \param dst The \c RBNodeRRset object to which the additional
212 : : /// RB node list is to be copied.
213 : : void copyAdditionalNodes(RBNodeRRset& dst) const;
214 : :
215 : : /// \brief Return underlying RRset pointer
216 : : ///
217 : : /// ... mainly for testing.
218 : : isc::dns::ConstRRsetPtr getUnderlyingRRset() const;
219 : :
220 : : private:
221 : : RBNodeRRsetImpl* impl_;
222 : : };
223 : :
224 : : } // namespace internal
225 : : } // namespace datasrc
226 : : } // namespace isc
227 : :
228 : : #endif // __RBNODE_RRSET_H
|