]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1976] Store the client list in server
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Mon, 18 Jun 2012 12:52:18 +0000 (14:52 +0200)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Mon, 18 Jun 2012 12:52:18 +0000 (14:52 +0200)
And provide accessor methods to them.

src/bin/auth/auth_srv.cc
src/bin/auth/auth_srv.h
src/bin/auth/tests/auth_srv_unittest.cc

index 2a47c3882208b98281ad9358310d68a9ae00f8bc..c0664294c12a55631d82cf530e478400c440fb20 100644 (file)
@@ -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_);
+}
index 18d750331baf6a422b20403696fa6dabaf351451..59955b039083403ea9c65f1051ffcc0c89ff58fa 100644 (file)
@@ -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_;
index a5b6d2635c8bb922a1281b7cd375318a78c0f503..e6ebad4c25f3bae442ae44d3d385912ac7717a57 100644 (file)
@@ -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());
+}
+
 }