1 // Copyright (C) 2013-2021 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef D2_ZONE_H
8 #define D2_ZONE_H
9 
10 #include <dns/name.h>
11 #include <dns/rrclass.h>
12 
13 #include <boost/shared_ptr.hpp>
14 
15 namespace isc {
16 namespace d2 {
17 
18 /// @brief The @c D2Zone encapsulates the Zone section in DNS Update message.
19 ///
20 /// This class is used by the @c D2UpdateMessage to encapsulate the Zone section
21 /// of the DNS Update message. Class members hold corresponding values of
22 /// section's fields: NAME, CLASS. This class does not hold the RTYPE field
23 /// value because RTYPE is always equal to SOA for DNS Update message (see
24 /// RFC 2136, section 2.3).
25 ///
26 /// Note, that this @c D2Zone class neither exposes functions to decode messages
27 /// from wire format nor to encode to wire format. This is not needed, because
28 /// @c isc::d2::D2UpdateMessage class uses @c D2Zone only to return the parsed
29 /// Zone information to the caller. Internally, D2UpdateMessage parses and
30 /// stores Zone section using @c isc::dns::Question class, and the @c toWire
31 /// and @c fromWire functions of the @c isc::dns::Question class are used.
32 class D2Zone {
33 public:
34     /// @brief Constructor from Name and RRClass.
35     ///
36     /// @param name The name of the Zone.
37     /// @param rrclass The RR class of the Zone.
38     D2Zone(const dns::Name& name, const dns::RRClass& rrclass);
39 
40     ///
41     /// @name Getters
42     ///
43     //@{
44     /// @brief Returns the Zone name.
45     ///
46     /// @return A reference to the Zone name.
getName()47     const dns::Name& getName() const { return (name_); }
48 
49     /// @brief Returns the Zone class.
50     ///
51     /// @return A reference to the Zone class.
getClass()52     const dns::RRClass& getClass() const { return (rrclass_); }
53     //@}
54 
55     /// @brief Returns text representation of the Zone.
56     ///
57     /// This function concatenates the name of the Zone, Class and Type.
58     /// The type is always SOA.
59     ///
60     /// @return A text representation of the Zone.
61     std::string toText() const;
62 
63     ///
64     /// @name Comparison Operators
65     ///
66     //@{
67     /// @brief Equality operator to compare @c D2Zone objects in query and
68     /// response messages.
69     ///
70     /// @param rhs Zone to compare against.
71     ///
72     /// @return true if name and class are equal, false otherwise.
73     bool operator==(const D2Zone& rhs) const {
74         return ((rrclass_ == rhs.rrclass_) && (name_ == rhs.name_));
75     }
76 
77     /// @brief Inequality operator to compare @c D2Zone objects in query and
78     /// response messages.
79     ///
80     /// @param rhs Zone to compare against.
81     ///
82     /// @return true if any of name or class are unequal, false otherwise.
83     bool operator!=(const D2Zone& rhs) const {
84         return (!operator==(rhs));
85     }
86     //@}
87 
88 private:
89     dns::Name name_;       ///< Holds the Zone name.
90     dns::RRClass rrclass_; ///< Holds the Zone class.
91 };
92 
93 typedef boost::shared_ptr<D2Zone> D2ZonePtr;
94 
95 /// @brief Insert the @c D2Zone as a string into stream.
96 ///
97 /// @param os A @c std::ostream object on which the insertion operation is
98 /// performed.
99 /// @param zone A reference to the @c D2Zone object output by the
100 /// operation.
101 ///
102 /// @return A reference to the same @c std::ostream object referenced by
103 /// parameter @c os after the insertion operation.
104 std::ostream& operator<<(std::ostream& os, const D2Zone& zone);
105 
106 } // namespace d2
107 } // namespace isc
108 
109 #endif // D2_ZONE_H
110