data_source_static.cc 3.45 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23


#include "data_source_static.h"

#include <dns/cpp/name.h>
#include <dns/cpp/rdata.h>
#include <dns/cpp/rdataclass.h>
#include <dns/cpp/rrclass.h>
#include <dns/cpp/rrset.h>
#include <dns/cpp/rrtype.h>
#include <dns/cpp/rrttl.h>

#include <iostream>

namespace isc {
namespace dns {

using namespace isc::dns;
using namespace isc::dns::rdata;

StaticDataSrc::StaticDataSrc() : authors_name("authors.bind"),
                                 version_name("version.bind")
{
24
    authors = RRsetPtr(new RRset(authors_name, RRClass::CH(),
25
26
27
28
29
30
31
32
33
34
35
36
37
                                          RRType::TXT(), RRTTL(3600)));
    authors->addRdata(generic::TXT("Evan Hunt"));
    authors->addRdata(generic::TXT("Han Feng"));
    authors->addRdata(generic::TXT("Jelte Jansen"));
    authors->addRdata(generic::TXT("Jeremy C. Reed")); 
    authors->addRdata(generic::TXT("Jin Jian"));
    authors->addRdata(generic::TXT("JINMEI Tatuya"));
    authors->addRdata(generic::TXT("Kazunori Fujiwara"));
    authors->addRdata(generic::TXT("Michael Graff"));
    authors->addRdata(generic::TXT("Naoki Kambe"));
    authors->addRdata(generic::TXT("Shane Kerr")); 
    authors->addRdata(generic::TXT("Zhang Likun"));

38
    version = RRsetPtr(new RRset(version_name, RRClass::CH(),
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
                                          RRType::TXT(), RRTTL(3600)));
    version->addRdata(generic::TXT("BIND10 0.0.0 (pre-alpha)"));
}

const DataSrc*
StaticDataSrc::findClosestEnclosure(const Name& qname, Name& container, bool& found) const {
    NameComparisonResult::NameRelation version_cmp = 
        qname.compare(version_name).getRelation();

    if (version_cmp == NameComparisonResult::EQUAL ||
        version_cmp == NameComparisonResult::SUBDOMAIN) {
        NameComparisonResult::NameRelation sub_cmp = 
           version_name.compare(container).getRelation();

        if (sub_cmp == NameComparisonResult::SUBDOMAIN) {
            container = authors_name;
            found = true;
            return this;
        } else if (!found && sub_cmp == NameComparisonResult::EQUAL) {
            found = true;
            return this;
        } else {
            return NULL;
        }
    }

    NameComparisonResult::NameRelation authors_cmp = 
        qname.compare(authors_name).getRelation();

    if (authors_cmp == NameComparisonResult::EQUAL ||
        authors_cmp == NameComparisonResult::SUBDOMAIN) {
        NameComparisonResult::NameRelation sub_cmp = 
            authors_name.compare(container).getRelation();

        if (sub_cmp == NameComparisonResult::SUBDOMAIN) {
            container = authors_name;
            found = true;
            return this;
        } else if (!found && sub_cmp == NameComparisonResult::EQUAL) {
            found = true;
            return this;
        } else {
            return NULL;
        }
    }

    return NULL;
}

DSResult
StaticDataSrc::findRRset(const Name& qname,
                         const RRClass& qclass,
                         const RRType& qtype,
                         RRsetList& target) const
{
    if (qname == version_name) {
        target.push_back(version);
        return SUCCESS;
    } else if (qname == authors_name) {
        target.push_back(authors);
        return SUCCESS;
    }
    return NAME_NOT_FOUND;
}

DSResult
StaticDataSrc::findRRset(const Name& qname,
                         const RRClass& qclass,
                         const RRType& qtype,
                         RRsetList& target, RRsetList& sigs) const
{
    return findRRset(qname, qclass, qtype, target);
}

}
}