util_internal.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #ifndef DATASRC_MEMORY_UTIL_INTERNAL_H
  15. #define DATASRC_MEMORY_UTIL_INTERNAL_H 1
  16. #include <dns/rdataclass.h>
  17. #include <dns/rrset.h>
  18. #include <dns/rrtype.h>
  19. namespace isc {
  20. namespace datasrc {
  21. namespace memory {
  22. namespace detail {
  23. /// \brief Return the covered RR type of an RRSIG RRset.
  24. ///
  25. /// This is a commonly used helper to extract the type covered field of an
  26. /// RRSIG RRset and return it in the form of an RRType object.
  27. ///
  28. /// Normally, an empty RRSIG shouldn't be passed to this function, whether
  29. /// it comes from a master file or another data source iterator, but it could
  30. /// still happen in some buggy situations. This function catches and rejects
  31. /// such cases.
  32. inline dns::RRType
  33. getCoveredType(const dns::ConstRRsetPtr& sig_rrset) {
  34. dns::RdataIteratorPtr it = sig_rrset->getRdataIterator();
  35. if (it->isLast()) {
  36. isc_throw(isc::Unexpected,
  37. "Empty RRset is passed in-memory loader, name: "
  38. << sig_rrset->getName());
  39. }
  40. return (dynamic_cast<const dns::rdata::generic::RRSIG&>(it->getCurrent()).
  41. typeCovered());
  42. }
  43. } // namespace detail
  44. } // namespace memory
  45. } // namespace datasrc
  46. } // namespace isc
  47. #endif // DATASRC_MEMORY_UTIL_INTERNAL_H
  48. // Local Variables:
  49. // mode: c++
  50. // End: