dns_lookup.h 3.3 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. #ifndef __ASIOLINK_DNS_LOOKUP_H
  15. #define __ASIOLINK_DNS_LOOKUP_H 1
  16. #include <asiolink/io_message.h>
  17. #include <asiodns/dns_server.h>
  18. #include <dns/message.h>
  19. #include <util/buffer.h>
  20. namespace isc {
  21. namespace asiodns {
  22. /// \brief The \c DNSLookup class is an abstract base class for a DNS
  23. /// Lookup provider function.
  24. ///
  25. /// Specific derived class implementations are hidden within the
  26. /// implementation. Instances of the derived classes can be called
  27. /// as functions via the operator() interface. Pointers to these
  28. /// instances can then be provided to the \c IOService class
  29. /// via its constructor.
  30. ///
  31. /// A DNS Lookup provider function obtains the data needed to answer
  32. /// a DNS query (e.g., from authoritative data source, cache, or upstream
  33. /// query). After it has run, the OutputBuffer object passed to it
  34. /// should contain the answer to the query, in an internal representation.
  35. class DNSLookup {
  36. ///
  37. /// \name Constructors and Destructor
  38. ///
  39. /// Note: The copy constructor and the assignment operator are
  40. /// intentionally defined as private, making this class non-copyable.
  41. //@{
  42. private:
  43. DNSLookup(const DNSLookup& source);
  44. DNSLookup& operator=(const DNSLookup& source);
  45. protected:
  46. /// \brief The default constructor.
  47. ///
  48. /// This is intentionally defined as \c protected as this base class
  49. /// should never be instantiated (except as part of a derived class).
  50. DNSLookup() {
  51. self_ = this;
  52. }
  53. public:
  54. /// \brief The destructor
  55. virtual ~DNSLookup() {}
  56. //@}
  57. /// \brief The function operator
  58. ///
  59. /// This makes its call indirectly via the "self" pointer, ensuring
  60. /// that the function ultimately invoked will be the one in the derived
  61. /// class.
  62. ///
  63. /// \param io_message The event message to handle
  64. /// \param message The DNS MessagePtr that needs handling
  65. /// \param answer_message The final answer will be constructed in
  66. /// this MessagePtr
  67. /// \param buffer The final answer is put here
  68. /// \param server DNSServer object to use
  69. virtual void operator()(const asiolink::IOMessage& io_message,
  70. isc::dns::MessagePtr message,
  71. isc::dns::MessagePtr answer_message,
  72. isc::util::OutputBufferPtr buffer,
  73. DNSServer* server) const
  74. {
  75. (*self_)(io_message, message, answer_message, buffer, server);
  76. }
  77. private:
  78. DNSLookup* self_;
  79. };
  80. } // namespace asiodns
  81. } // namespace isc
  82. #endif // __ASIOLINK_DNS_LOOKUP_H