Browse Source

[1976] Store the client list in server

And provide accessor methods to them.
Michal 'vorner' Vaner 13 years ago
parent
commit
c558fd6d7a
3 changed files with 59 additions and 0 deletions
  1. 20 0
      src/bin/auth/auth_srv.cc
  2. 17 0
      src/bin/auth/auth_srv.h
  3. 22 0
      src/bin/auth/tests/auth_srv_unittest.cc

+ 20 - 0
src/bin/auth/auth_srv.cc

@@ -46,6 +46,7 @@
 #include <datasrc/memory_datasrc.h>
 #include <datasrc/static_datasrc.h>
 #include <datasrc/sqlite3_datasrc.h>
+#include <datasrc/client_list.h>
 
 #include <xfr/xfrout_client.h>
 
@@ -266,6 +267,9 @@ public:
     /// The TSIG keyring
     const boost::shared_ptr<TSIGKeyRing>* keyring_;
 
+    /// The client list
+    boost::shared_ptr<ClientList> client_list_;
+
     /// Bind the ModuleSpec object in config_session_ with
     /// isc:config::ModuleSpec::validateStatistics.
     void registerStatisticsValidator();
@@ -331,6 +335,9 @@ AuthSrvImpl::AuthSrvImpl(const bool use_cache,
 
     // enable or disable the cache
     cache_.setEnabled(use_cache);
+
+    // Create the (yet empty) data source list
+    client_list_.reset(new ConfigurableClientList());
 }
 
 AuthSrvImpl::~AuthSrvImpl() {
@@ -1024,3 +1031,16 @@ void
 AuthSrv::setTSIGKeyRing(const boost::shared_ptr<TSIGKeyRing>* keyring) {
     impl_->keyring_ = keyring;
 }
+
+void
+AuthSrv::setClientList(const boost::shared_ptr<ClientList>& list) {
+    if (!list) {
+        isc_throw(BadValue, "The client list must not be NULL");
+    }
+    impl_->client_list_ = list;
+}
+
+const ClientList&
+AuthSrv::getClientList() const {
+    return (*impl_->client_list_);
+}

+ 17 - 0
src/bin/auth/auth_srv.h

@@ -44,6 +44,7 @@ class BaseSocketSessionForwarder;
 }
 namespace datasrc {
 class InMemoryClient;
+class ClientList;
 }
 namespace xfr {
 class AbstractXfroutClient;
@@ -418,6 +419,22 @@ public:
     void setTSIGKeyRing(const boost::shared_ptr<isc::dns::TSIGKeyRing>*
                         keyring);
 
+    /// \brief Replaces the current client list with a different one.
+    ///
+    /// Replaces the internally used client list with a new one.
+    //
+    /// \param list Shared pointer to the client list. Must not be NULL.
+    ///
+    /// \throw BadValue if it is NULL.
+    void setClientList(const boost::shared_ptr<isc::datasrc::ClientList>&
+                       list);
+
+    /// \brief Returns the currently used client list.
+    ///
+    /// Note that the server is constructed with an empty one, so this
+    /// is always valid, even before calling setClientList.
+    const isc::datasrc::ClientList& getClientList() const;
+
 private:
     AuthSrvImpl* impl_;
     isc::asiolink::SimpleCallback* checkin_;

+ 22 - 0
src/bin/auth/tests/auth_srv_unittest.cc

@@ -30,6 +30,7 @@
 #include <server_common/keyring.h>
 
 #include <datasrc/memory_datasrc.h>
+#include <datasrc/client_list.h>
 #include <auth/auth_srv.h>
 #include <auth/common.h>
 #include <auth/statistics.h>
@@ -1644,4 +1645,25 @@ TEST_F(AuthSrvTest, DDNSForwardClose) {
     EXPECT_FALSE(ddns_forwarder.isConnected());
 }
 
+// Check the client list accessors
+TEST_F(AuthSrvTest, clientList) {
+    // The server is created with a working client list. So calling the
+    // function will not crash.
+    server.getClientList();
+    // It is the correct type
+    EXPECT_NO_THROW(dynamic_cast<const isc::datasrc::ConfigurableClientList&>(
+        server.getClientList())) << "The client list has a wrong type";
+    // Now prepare a new client list and replace it
+    boost::shared_ptr<isc::datasrc::ConfigurableClientList>
+        list(new isc::datasrc::ConfigurableClientList());
+    server.setClientList(list);
+    // And it is kept there.
+    EXPECT_EQ(list.get(), &server.getClientList());
+    // But putting NULL there would not work and the original is preserved
+    EXPECT_THROW(server.setClientList(
+        boost::shared_ptr<isc::datasrc::ConfigurableClientList>()),
+                 isc::BadValue);
+    EXPECT_EQ(list.get(), &server.getClientList());
+}
+
 }