dns_service.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_SERVICE_H
  15. #define __ASIOLINK_DNS_SERVICE_H 1
  16. #include <resolve/resolver_interface.h>
  17. #include <asiolink/io_service.h>
  18. namespace asiolink {
  19. class SimpleCallback;
  20. class DNSLookup;
  21. class DNSAnswer;
  22. class DNSServiceImpl;
  23. ///
  24. /// DNSService is the service that handles DNS queries and answers with
  25. /// a given IOService. This class is mainly intended to hold all the
  26. /// logic that is shared between the authoritative and the recursive
  27. /// server implementations. As such, it handles asio, including config
  28. /// updates (through the 'Checkinprovider'), and listening sockets.
  29. ///
  30. class DNSService {
  31. ///
  32. /// \name Constructors and Destructor
  33. ///
  34. /// Note: The copy constructor and the assignment operator are
  35. /// intentionally defined as private, making this class non-copyable.
  36. //@{
  37. private:
  38. DNSService(const DNSService& source);
  39. DNSService& operator=(const DNSService& source);
  40. public:
  41. /// \brief The constructor with a specific IP address and port on which
  42. /// the services listen on.
  43. ///
  44. /// \param io_service The IOService to work with
  45. /// \param port the port to listen on
  46. /// \param address the IP address to listen on
  47. /// \param checkin Provider for cc-channel events (see \c SimpleCallback)
  48. /// \param lookup The lookup provider (see \c DNSLookup)
  49. /// \param answer The answer provider (see \c DNSAnswer)
  50. DNSService(IOService& io_service, const char& port,
  51. const char& address, SimpleCallback* checkin,
  52. DNSLookup* lookup, DNSAnswer* answer);
  53. /// \brief The constructor with a specific port on which the services
  54. /// listen on.
  55. ///
  56. /// It effectively listens on "any" IPv4 and/or IPv6 addresses.
  57. /// IPv4/IPv6 services will be available if and only if \c use_ipv4
  58. /// or \c use_ipv6 is \c true, respectively.
  59. ///
  60. /// \param io_service The IOService to work with
  61. /// \param port the port to listen on
  62. /// \param ipv4 If true, listen on ipv4 'any'
  63. /// \param ipv6 If true, listen on ipv6 'any'
  64. /// \param checkin Provider for cc-channel events (see \c SimpleCallback)
  65. /// \param lookup The lookup provider (see \c DNSLookup)
  66. /// \param answer The answer provider (see \c DNSAnswer)
  67. DNSService(IOService& io_service, const char& port,
  68. const bool use_ipv4, const bool use_ipv6,
  69. SimpleCallback* checkin, DNSLookup* lookup,
  70. DNSAnswer* answer);
  71. /// \brief The constructor without any servers.
  72. ///
  73. /// Use addServer() to add some servers.
  74. DNSService(IOService& io_service, SimpleCallback* checkin,
  75. DNSLookup* lookup, DNSAnswer* answer);
  76. /// \brief The destructor.
  77. ~DNSService();
  78. //@}
  79. /// \brief Add another server to the service
  80. void addServer(uint16_t port, const std::string &address);
  81. void addServer(const char &port, const std::string &address);
  82. /// \brief Remove all servers from the service
  83. void clearServers();
  84. /// \brief Return the native \c io_service object used in this wrapper.
  85. ///
  86. /// This is a short term work around to support other BIND 10 modules
  87. /// that share the same \c io_service with the authoritative server.
  88. /// It will eventually be removed once the wrapper interface is
  89. /// generalized.
  90. asio::io_service& get_io_service() { return io_service_.get_io_service(); }
  91. /// \brief Return the IO Service Object
  92. ///
  93. /// \return IOService object for this DNS service.
  94. asiolink::IOService& getIOService() { return (io_service_);}
  95. private:
  96. DNSServiceImpl* impl_;
  97. IOService& io_service_;
  98. };
  99. } // namespace asiolink
  100. #endif // __ASIOLINK_DNS_SERVICE_H