database.cc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright (C) 2011 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. #include <datasrc/database.h>
  15. #include <exceptions/exceptions.h>
  16. #include <dns/name.h>
  17. using isc::dns::Name;
  18. namespace isc {
  19. namespace datasrc {
  20. DatabaseClient::DatabaseClient(boost::shared_ptr<DatabaseAccessor>
  21. database) :
  22. database_(database)
  23. {
  24. if (database_.get() == NULL) {
  25. isc_throw(isc::InvalidParameter,
  26. "No database provided to DatabaseClient");
  27. }
  28. }
  29. DataSourceClient::FindResult
  30. DatabaseClient::findZone(const Name& name) const {
  31. std::pair<bool, int> zone(database_->getZone(name));
  32. // Try exact first
  33. if (zone.first) {
  34. return (FindResult(result::SUCCESS,
  35. ZoneFinderPtr(new Finder(database_,
  36. zone.second))));
  37. }
  38. // Than super domains
  39. // Start from 1, as 0 is covered above
  40. for (size_t i(1); i < name.getLabelCount(); ++i) {
  41. zone = database_->getZone(name.split(i));
  42. if (zone.first) {
  43. return (FindResult(result::PARTIALMATCH,
  44. ZoneFinderPtr(new Finder(database_,
  45. zone.second))));
  46. }
  47. }
  48. // No, really nothing
  49. return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
  50. }
  51. DatabaseClient::Finder::Finder(boost::shared_ptr<DatabaseAccessor>
  52. database, int zone_id) :
  53. database_(database),
  54. zone_id_(zone_id)
  55. { }
  56. ZoneFinder::FindResult
  57. DatabaseClient::Finder::find(const isc::dns::Name&,
  58. const isc::dns::RRType&,
  59. isc::dns::RRsetList*,
  60. const FindOptions) const
  61. {
  62. // TODO Implement
  63. return (FindResult(SUCCESS, isc::dns::ConstRRsetPtr()));
  64. }
  65. Name
  66. DatabaseClient::Finder::getOrigin() const {
  67. // TODO Implement
  68. return (Name("."));
  69. }
  70. isc::dns::RRClass
  71. DatabaseClient::Finder::getClass() const {
  72. // TODO Implement
  73. return isc::dns::RRClass::IN();
  74. }
  75. }
  76. }