Branch data Line data Source code
1 : : // Copyright (C) 2010 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 __ZONETABLE_H
16 : : #define __ZONETABLE_H 1
17 : :
18 : : #include <boost/shared_ptr.hpp>
19 : :
20 : : #include <dns/rrset.h>
21 : :
22 : : #include <datasrc/zone.h>
23 : :
24 : : namespace isc {
25 : : namespace dns {
26 : : class Name;
27 : : class RRClass;
28 : : }
29 : :
30 : : namespace datasrc {
31 : :
32 : : /// \brief A set of authoritative zones.
33 : : ///
34 : : /// \c ZoneTable class is primarily intended to be used as a backend for the
35 : : /// \c MemoryDataSrc class, but is exposed as a separate class in case some
36 : : /// application wants to use it directly (e.g. for a customized data source
37 : : /// implementation).
38 : : ///
39 : : /// For more descriptions about its struct and interfaces, please refer to the
40 : : /// corresponding struct and interfaces of \c MemoryDataSrc.
41 : : class ZoneTable {
42 : : public:
43 : 185 : struct FindResult {
44 : : FindResult(result::Result param_code, const ZoneFinderPtr param_zone) :
45 : 185 : code(param_code), zone(param_zone)
46 : : {}
47 : : const result::Result code;
48 : : const ZoneFinderPtr zone;
49 : : };
50 : : ///
51 : : /// \name Constructors and Destructor.
52 : : ///
53 : : /// \b Note:
54 : : /// The copy constructor and the assignment operator are intentionally
55 : : /// defined as private, making this class non copyable.
56 : : //@{
57 : : private:
58 : : ZoneTable(const ZoneTable& source);
59 : : ZoneTable& operator=(const ZoneTable& source);
60 : :
61 : : public:
62 : : /// Default constructor.
63 : : ///
64 : : /// This constructor internally involves resource allocation, and if
65 : : /// it fails, a corresponding standard exception will be thrown.
66 : : /// It never throws an exception otherwise.
67 : : ZoneTable();
68 : :
69 : : /// The destructor.
70 : : ~ZoneTable();
71 : : //@}
72 : :
73 : : /// Add a \c Zone to the \c ZoneTable.
74 : : ///
75 : : /// \c Zone must not be associated with a NULL pointer; otherwise
76 : : /// an exception of class \c InvalidParameter will be thrown.
77 : : /// If internal resource allocation fails, a corresponding standard
78 : : /// exception will be thrown.
79 : : /// This method never throws an exception otherwise.
80 : : ///
81 : : /// \param zone A \c Zone object to be added.
82 : : /// \return \c result::SUCCESS If the zone is successfully
83 : : /// added to the zone table.
84 : : /// \return \c result::EXIST The zone table already contains
85 : : /// zone of the same origin.
86 : : result::Result addZone(ZoneFinderPtr zone);
87 : :
88 : : /// Remove a \c Zone of the given origin name from the \c ZoneTable.
89 : : ///
90 : : /// This method never throws an exception.
91 : : ///
92 : : /// \param origin The origin name of the zone to be removed.
93 : : /// \return \c result::SUCCESS If the zone is successfully
94 : : /// removed from the zone table.
95 : : /// \return \c result::NOTFOUND The zone table does not
96 : : /// store the zone that matches \c origin.
97 : : result::Result removeZone(const isc::dns::Name& origin);
98 : :
99 : : /// Find a \c Zone that best matches the given name in the \c ZoneTable.
100 : : ///
101 : : /// It searches the internal storage for a \c Zone that gives the
102 : : /// longest match against \c name, and returns the result in the
103 : : /// form of a \c FindResult object as follows:
104 : : /// - \c code: The result code of the operation.
105 : : /// - \c result::SUCCESS: A zone that gives an exact match
106 : : /// is found
107 : : /// - \c result::PARTIALMATCH: A zone whose origin is a
108 : : /// super domain of \c name is found (but there is no exact match)
109 : : /// - \c result::NOTFOUND: For all other cases.
110 : : /// - \c zone: A "Boost" shared pointer to the found \c Zone object if one
111 : : /// is found; otherwise \c NULL.
112 : : ///
113 : : /// This method never throws an exception.
114 : : ///
115 : : /// \param name A domain name for which the search is performed.
116 : : /// \return A \c FindResult object enclosing the search result (see above).
117 : : FindResult findZone(const isc::dns::Name& name) const;
118 : :
119 : : private:
120 : : struct ZoneTableImpl;
121 : : ZoneTableImpl* impl_;
122 : : };
123 : : }
124 : : }
125 : : #endif // __ZONETABLE_H
126 : :
127 : : // Local Variables:
128 : : // mode: c++
129 : : // End:
|