data_source_static.cc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. // $Id$
  15. #include "data_source_static.h"
  16. #include <dns/name.h>
  17. #include <dns/rdata.h>
  18. #include <dns/rdataclass.h>
  19. #include <dns/rrclass.h>
  20. #include <dns/rrset.h>
  21. #include <dns/rrtype.h>
  22. #include <dns/rrttl.h>
  23. #include <iostream>
  24. using namespace std;
  25. using namespace isc::dns;
  26. using namespace isc::dns::rdata;
  27. namespace isc {
  28. namespace auth {
  29. StaticDataSrc::StaticDataSrc() : authors_name("authors.bind"),
  30. version_name("version.bind")
  31. {
  32. setClass(RRClass::CH());
  33. authors = RRsetPtr(new RRset(authors_name, RRClass::CH(),
  34. RRType::TXT(), RRTTL(0)));
  35. authors->addRdata(generic::TXT("Evan Hunt"));
  36. authors->addRdata(generic::TXT("Han Feng"));
  37. authors->addRdata(generic::TXT("Jelte Jansen"));
  38. authors->addRdata(generic::TXT("Jeremy C. Reed"));
  39. authors->addRdata(generic::TXT("Jin Jian"));
  40. authors->addRdata(generic::TXT("JINMEI Tatuya"));
  41. authors->addRdata(generic::TXT("Kazunori Fujiwara"));
  42. authors->addRdata(generic::TXT("Michael Graff"));
  43. authors->addRdata(generic::TXT("Naoki Kambe"));
  44. authors->addRdata(generic::TXT("Shane Kerr"));
  45. authors->addRdata(generic::TXT("Zhang Likun"));
  46. authors_ns = RRsetPtr(new RRset(authors_name, RRClass::CH(),
  47. RRType::NS(), RRTTL(0)));
  48. authors_ns->addRdata(generic::NS(authors_name));
  49. version = RRsetPtr(new RRset(version_name, RRClass::CH(),
  50. RRType::TXT(), RRTTL(0)));
  51. version->addRdata(generic::TXT("BIND10 0.0.0 (pre-alpha)"));
  52. version_ns = RRsetPtr(new RRset(version_name, RRClass::CH(),
  53. RRType::NS(), RRTTL(0)));
  54. version_ns->addRdata(generic::NS(version_name));
  55. }
  56. void
  57. StaticDataSrc::findClosestEnclosure(NameMatch& match) const {
  58. const Name& qname = match.qname();
  59. NameComparisonResult::NameRelation cmp;
  60. cmp = qname.compare(version_name).getRelation();
  61. if (cmp == NameComparisonResult::EQUAL ||
  62. cmp == NameComparisonResult::SUBDOMAIN) {
  63. match.update(*this, version_name);
  64. return;
  65. }
  66. cmp = qname.compare(authors_name).getRelation();
  67. if (cmp == NameComparisonResult::EQUAL ||
  68. cmp == NameComparisonResult::SUBDOMAIN) {
  69. match.update(*this, authors_name);
  70. return;
  71. }
  72. }
  73. DataSrc::Result
  74. StaticDataSrc::findRRset(const Query& q,
  75. const Name& qname,
  76. const RRClass& qclass,
  77. const RRType& qtype,
  78. RRsetList& target,
  79. uint32_t& flags,
  80. Name* zone) const
  81. {
  82. flags = 0;
  83. if (qclass != getClass()) {
  84. return (ERROR);
  85. }
  86. bool any = (qtype == RRType::ANY());
  87. if (qname == version_name) {
  88. if (qtype == RRType::TXT() || any) {
  89. target.addRRset(version);
  90. } else if (qtype == RRType::NS()) {
  91. target.addRRset(version_ns);
  92. } else {
  93. flags = TYPE_NOT_FOUND;
  94. }
  95. } else if (qname == authors_name) {
  96. if (qtype == RRType::TXT() || any) {
  97. target.addRRset(authors);
  98. return (SUCCESS);
  99. } else if (qtype == RRType::NS()) {
  100. target.addRRset(authors_ns);
  101. return (SUCCESS);
  102. } else {
  103. flags = TYPE_NOT_FOUND;
  104. }
  105. } else {
  106. flags = NAME_NOT_FOUND;
  107. }
  108. return (SUCCESS);
  109. }
  110. }
  111. }