auth_srv.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // Copyright (C) 2009 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. // $Id$
  15. #ifndef __AUTH_SRV_H
  16. #define __AUTH_SRV_H 1
  17. #include <string>
  18. #include <cc/data.h>
  19. #include <config/ccsession.h>
  20. namespace isc {
  21. namespace dns {
  22. class InputBuffer;
  23. class Message;
  24. class MessageRenderer;
  25. }
  26. namespace xfr {
  27. class AbstractXfroutClient;
  28. };
  29. }
  30. namespace asio_link {
  31. class IOMessage;
  32. }
  33. /// \brief The implementation class for the \c AuthSrv class using the pimpl
  34. /// idiom.
  35. class AuthSrvImpl;
  36. /// \brief The authoritative nameserver class.
  37. ///
  38. /// \c AuthSrv is a concrete class that implements authoritative DNS server
  39. /// protocol processing.
  40. /// An \c AuthSrv object is primarily responsible for handling incoming DNS
  41. /// requests: It parses the request and dispatches subsequent processing to
  42. /// the corresponding module (which may be an internal library or a separate
  43. /// process) depending on the request type. For normal queries, the
  44. /// \c AuthSrv object searches configured data sources for the answer to the
  45. /// query, and builds a response containing the answer.
  46. ///
  47. /// This class uses the "pimpl" idiom, and hides detailed implementation
  48. /// through the \c impl_ pointer (which points to an instance of the
  49. /// \c AuthSrvImpl class). An \c AuthSrv object is supposed to exist for quite
  50. /// a long period, and only a few \c AuthSrv objects will be created (in fact,
  51. /// in this current implementation there will only be one object), so the
  52. /// construction overhead of this approach should be acceptable.
  53. ///
  54. /// The design of this class is still in flux. It's quite likely to change
  55. /// in future versions.
  56. class AuthSrv {
  57. ///
  58. /// \name Constructors, Assignment Operator and Destructor.
  59. ///
  60. /// Note: The copy constructor and the assignment operator are
  61. /// intentionally defined as private.
  62. //@{
  63. private:
  64. AuthSrv(const AuthSrv& source);
  65. AuthSrv& operator=(const AuthSrv& source);
  66. public:
  67. /// The constructor.
  68. ///
  69. /// \param use_cache Whether to enable hot spot cache for lookup results.
  70. /// \param xfrout_client Communication interface with a separate xfrout
  71. /// process. It's normally a reference to an xfr::XfroutClient object,
  72. /// but can refer to a local mock object for testing (or other
  73. /// experimental) purposes.
  74. AuthSrv(const bool use_cache,
  75. isc::xfr::AbstractXfroutClient& xfrout_client);
  76. ~AuthSrv();
  77. //@}
  78. /// \return \c true if the \message contains a response to be returned;
  79. /// otherwise \c false.
  80. bool processMessage(const asio_link::IOMessage& io_message,
  81. isc::dns::Message& message,
  82. isc::dns::MessageRenderer& response_renderer);
  83. /// \brief Enable or disable verbose logging.
  84. ///
  85. /// This method never throws an exception.
  86. ///
  87. /// \param on \c true to enable verbose logging; \c false to disable
  88. /// verbose logging.
  89. void setVerbose(const bool on);
  90. /// \brief Returns the logging verbosity of the \c AuthSrv object.
  91. ///
  92. /// This method never throws an exception.
  93. ///
  94. /// \return \c true if verbose logging is enabled; otherwise \c false.
  95. bool getVerbose() const;
  96. /// \brief Updates the data source for the \c AuthSrv object.
  97. ///
  98. /// This method installs or replaces the data source that the \c AuthSrv
  99. /// object refers to for query processing.
  100. /// Although the method name is generic, the only thing it does is to
  101. /// update the data source information.
  102. /// If there is a data source installed, it will be replaced with the
  103. /// new one.
  104. ///
  105. /// In the current implementation, the SQLite data source is assumed.
  106. /// The \c config parameter will simply be passed to the initialization
  107. /// routine of the \c Sqlite3DataSrc class.
  108. ///
  109. /// On success this method returns a data \c Element (in the form of a
  110. /// pointer like object) indicating the successful result,
  111. /// i.e., {"result": [0]}.
  112. /// Otherwise, it returns a data \c Element explaining the error:
  113. /// {"result": [1, <error-description>]}.
  114. ///
  115. /// This method is mostly exception free (error conditions are represented
  116. /// via the return value). But it may still throw a standard exception
  117. /// if memory allocation fails inside the method.
  118. /// When a standard exception is thrown or an implementation specific
  119. /// exception is triggered and caught internally, this function provides
  120. /// the strong exception guarantee: Unless everything succeeds, currently
  121. /// installed data source (if any) won't be replaced.
  122. ///
  123. /// \param config An immutable pointer-like object to a data \c Element,
  124. /// possibly containing the data source information to be used.
  125. /// \return An immutable pointer-like object to a data \c Element
  126. /// containing the result of the update operation.
  127. isc::data::ConstElementPtr updateConfig(isc::data::ConstElementPtr config);
  128. /// \param Returns the command and configuration session for the
  129. /// \c AuthSrv.
  130. ///
  131. /// This method never throws an exception.
  132. ///
  133. /// \return A pointer to \c ModuleCCSession object stored in the
  134. /// \c AuthSrv object. In this implementation it could be NULL.
  135. isc::config::ModuleCCSession* getConfigSession() const;
  136. /// \brief Set the command and configuration session for the \c AuthSrv.
  137. ///
  138. /// Note: this interface is tentative. We'll revisit the ASIO and session
  139. /// frameworks, at which point the session will probably be passed on
  140. /// construction of the server.
  141. /// In the current implementation, this method is expected to be called
  142. /// exactly once as part of initialization. If this method is called
  143. /// multiple times, previously specified session is silently overridden.
  144. ///
  145. /// This method never throws an exception.
  146. ///
  147. /// \param config_session A pointer to \c ModuleCCSession object to receive
  148. /// control commands and configuration updates.
  149. void setConfigSession(isc::config::ModuleCCSession* config_session);
  150. /// \brief Set the communication session with a separate process for
  151. /// outgoing zone transfers.
  152. ///
  153. /// Note: this interface is tentative. We'll revisit the ASIO and session
  154. /// frameworks, at which point the session will probably be passed on
  155. /// construction of the server.
  156. ///
  157. /// \param xfrin_session A Session object over which NOTIFY message
  158. /// information is exchanged with a XFRIN handler.
  159. /// The session must be established before setting in the server
  160. /// object.
  161. /// Ownership isn't transferred: the caller is responsible for keeping
  162. /// this object to be valid while the server object is working and for
  163. /// disconnecting the session and destroying the object when the server
  164. /// is shutdown.
  165. ///
  166. void setXfrinSession(isc::cc::AbstractSession* xfrin_session);
  167. private:
  168. AuthSrvImpl* impl_;
  169. };
  170. #endif // __AUTH_SRV_H
  171. // Local Variables:
  172. // mode: c++
  173. // End: