dns_lookup.h 3.1 KB

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