master_loader_callbacks.cc 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright (C) 2012 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/master_loader_callbacks.h>
  15. #include <datasrc/zone.h>
  16. #include <datasrc/logger.h>
  17. #include <dns/name.h>
  18. #include <dns/rrclass.h>
  19. #include <dns/rrset.h>
  20. #include <string>
  21. #include <boost/bind.hpp>
  22. namespace isc {
  23. namespace datasrc {
  24. namespace {
  25. void
  26. logError(const isc::dns::Name& name, const isc::dns::RRClass& rrclass,
  27. bool* ok, const std::string& source, size_t line,
  28. const std::string& reason)
  29. {
  30. LOG_ERROR(logger, DATASRC_MASTER_LOAD_ERROR).arg(source).arg(line).
  31. arg(name).arg(rrclass).arg(reason);
  32. if (ok != NULL) {
  33. *ok = false;
  34. }
  35. }
  36. void
  37. logWarning(const isc::dns::Name& name, const isc::dns::RRClass& rrclass,
  38. const std::string& source, size_t line, const std::string& reason)
  39. {
  40. LOG_WARN(logger, DATASRC_MASTER_LOAD_WARN).arg(source).arg(line).
  41. arg(name).arg(rrclass).arg(reason);
  42. }
  43. void
  44. addRR(const isc::dns::Name& name, const isc::dns::RRClass& rrclass,
  45. const isc::dns::RRType& type, const isc::dns::RRTTL& ttl,
  46. const isc::dns::rdata::RdataPtr& data, ZoneUpdater* updater)
  47. {
  48. // We get description of one RR. The updater takes RRset, so we
  49. // wrap it up and push there. It should collate the RRsets of the
  50. // same name and type together, since the addRRset should "merge".
  51. isc::dns::BasicRRset rrset(name, rrclass, type, ttl);
  52. rrset.addRdata(data);
  53. updater->addRRset(rrset);
  54. }
  55. }
  56. isc::dns::MasterLoaderCallbacks
  57. createMasterLoaderCallbacks(const isc::dns::Name& name,
  58. const isc::dns::RRClass& rrclass, bool* ok)
  59. {
  60. return (isc::dns::MasterLoaderCallbacks(boost::bind(&logError, name,
  61. rrclass, ok, _1, _2,
  62. _3),
  63. boost::bind(&logWarning, name,
  64. rrclass, _1, _2, _3)));
  65. }
  66. isc::dns::AddRRCallback
  67. createMasterLoaderAddCallback(ZoneUpdater& updater) {
  68. return (boost::bind(addRR, _1, _2, _3, _4, _5, &updater));
  69. }
  70. }
  71. }