zone_loader_util.cc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright (C) 2013 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/tests/memory/zone_loader_util.h>
  15. #include <datasrc/zone_iterator.h>
  16. #include <datasrc/cache_config.h>
  17. #include <datasrc/memory/zone_table_segment.h>
  18. #include <datasrc/memory/zone_data_loader.h>
  19. #include <datasrc/memory/zone_writer.h>
  20. #include <dns/dns_fwd.h>
  21. #include <cc/data.h>
  22. #include <boost/bind.hpp>
  23. #include <boost/scoped_ptr.hpp>
  24. #include <string>
  25. namespace isc {
  26. namespace datasrc {
  27. namespace memory {
  28. namespace test {
  29. void
  30. loadZoneIntoTable(ZoneTableSegment& zt_sgmt, const dns::Name& zname,
  31. const dns::RRClass& zclass, const std::string& zone_file)
  32. {
  33. const isc::datasrc::internal::CacheConfig cache_conf(
  34. "MasterFiles", NULL, *data::Element::fromJSON(
  35. "{\"cache-enable\": true,"
  36. " \"params\": {\"" + zname.toText() + "\": \"" + zone_file +
  37. "\"}}"), true);
  38. boost::scoped_ptr<memory::ZoneWriter> writer(
  39. zt_sgmt.getZoneWriter(cache_conf.getLoadAction(zclass, zname),
  40. zname, zclass));
  41. writer->load();
  42. writer->install();
  43. writer->cleanup();
  44. }
  45. namespace {
  46. // borrowed from CacheConfig's internal
  47. class IteratorLoader {
  48. public:
  49. IteratorLoader(const dns::RRClass& rrclass, const dns::Name& name,
  50. ZoneIterator& iterator) :
  51. rrclass_(rrclass),
  52. name_(name),
  53. iterator_(iterator)
  54. {}
  55. memory::ZoneData* operator()(util::MemorySegment& segment) {
  56. return (memory::loadZoneData(segment, rrclass_, name_, iterator_));
  57. }
  58. private:
  59. const dns::RRClass rrclass_;
  60. const dns::Name name_;
  61. ZoneIterator& iterator_;
  62. };
  63. }
  64. void
  65. loadZoneIntoTable(ZoneTableSegment& zt_sgmt, const dns::Name& zname,
  66. const dns::RRClass& zclass, ZoneIterator& iterator)
  67. {
  68. boost::scoped_ptr<memory::ZoneWriter> writer(
  69. zt_sgmt.getZoneWriter(IteratorLoader(zclass, zname, iterator),
  70. zname, zclass));
  71. writer->load();
  72. writer->install();
  73. writer->cleanup();
  74. }
  75. } // namespace test
  76. } // namespace memory
  77. } // namespace datasrc
  78. } // namespace isc
  79. // Local Variables:
  80. // mode: c++
  81. // End: