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 : : #include <cassert>
16 : :
17 : : #include <dns/name.h>
18 : :
19 : : #include <datasrc/zonetable.h>
20 : : #include <datasrc/rbtree.h>
21 : :
22 : : using namespace std;
23 : : using namespace isc::dns;
24 : :
25 : : namespace isc {
26 : : namespace datasrc {
27 : :
28 : : /// \short Private data and implementation of ZoneTable
29 : 316 : struct ZoneTable::ZoneTableImpl {
30 : : // Type aliases to make it shorter
31 : : typedef RBTree<ZoneFinder> ZoneTree;
32 : : typedef RBNode<ZoneFinder> ZoneNode;
33 : : // The actual storage
34 : : ZoneTree zones_;
35 : :
36 : : /*
37 : : * The implementation methods are here and just wrap-called in the
38 : : * ZoneTable. We have variables locally (without impl_->), have
39 : : * type aliases, etc. And they will get inlined anyway.
40 : : */
41 : :
42 : : // Implementation of ZoneTable::addZone
43 : 160 : result::Result addZone(ZoneFinderPtr zone) {
44 : : // Sanity check
45 [ - + ]: 160 : if (!zone) {
46 [ # # ]: 0 : isc_throw(InvalidParameter,
47 : : "Null pointer is passed to ZoneTable::addZone()");
48 : : }
49 : :
50 : : // Get the node where we put the zone
51 : 160 : ZoneNode* node(NULL);
52 [ + - ][ - + ]: 160 : switch (zones_.insert(zone->getOrigin(), &node)) {
53 : : // This is OK
54 : : case ZoneTree::SUCCESS:
55 : : case ZoneTree::ALREADYEXISTS:
56 : : break;
57 : : // Can Not Happen
58 : : default:
59 : 0 : assert(0);
60 : : }
61 : : // Can Not Happen
62 [ - + ]: 160 : assert(node);
63 : :
64 : : // Is it empty? We either just created it or it might be nonterminal
65 [ + + ]: 160 : if (node->isEmpty()) {
66 : 156 : node->setData(zone);
67 : 160 : return (result::SUCCESS);
68 : : } else { // There's something there already
69 : : return (result::EXIST);
70 : : }
71 : : }
72 : :
73 : : // Implementation of ZoneTable::findZone
74 : 185 : ZoneTable::FindResult findZone(const Name& name) const {
75 : 185 : ZoneNode *node(NULL);
76 : : result::Result my_result;
77 : :
78 : : // Translate the return codes
79 [ + + - + ]: 185 : switch (zones_.find(name, &node)) {
80 : : case ZoneTree::EXACTMATCH:
81 : : my_result = result::SUCCESS;
82 : : break;
83 : : case ZoneTree::PARTIALMATCH:
84 : 120 : my_result = result::PARTIALMATCH;
85 : 120 : break;
86 : : // We have no data there, so translate the pointer to NULL as well
87 : : case ZoneTree::NOTFOUND:
88 : : return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
89 : : // Can Not Happen
90 : : default:
91 : 0 : assert(0);
92 : : // Because of warning
93 : : return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
94 : : }
95 : :
96 : : // Can Not Happen (remember, NOTFOUND is handled)
97 [ - + ]: 167 : assert(node);
98 : :
99 : 167 : return (FindResult(my_result, node->getData()));
100 : : }
101 : : };
102 : :
103 : 158 : ZoneTable::ZoneTable() : impl_(new ZoneTableImpl)
104 : 158 : {}
105 : :
106 : 158 : ZoneTable::~ZoneTable() {
107 [ + - ]: 316 : delete impl_;
108 : 158 : }
109 : :
110 : : result::Result
111 : 160 : ZoneTable::addZone(ZoneFinderPtr zone) {
112 [ + - ]: 320 : return (impl_->addZone(zone));
113 : : }
114 : :
115 : : result::Result
116 : 0 : ZoneTable::removeZone(const Name&) {
117 : : // TODO Implement
118 : 0 : assert(0);
119 : : // This should not ever be returned, the assert should kill us by now
120 : : return (result::SUCCESS);
121 : : }
122 : :
123 : : ZoneTable::FindResult
124 : 185 : ZoneTable::findZone(const Name& name) const {
125 : 185 : return (impl_->findZone(name));
126 : : }
127 : :
128 : : } // end of namespace datasrc
129 [ # # ]: 107 : } // end of namespace isc
|