From: Michal 'vorner' Vaner Date: Mon, 18 Jun 2012 12:52:18 +0000 (+0200) Subject: [1976] Store the client list in server X-Git-Tag: trac2351_base~97^2~7^2~2^2~21^2~25 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c558fd6d7a67fa70d3ba78f43c6536f5c006fd3d;p=thirdparty%2Fkea.git [1976] Store the client list in server And provide accessor methods to them. --- diff --git a/src/bin/auth/auth_srv.cc b/src/bin/auth/auth_srv.cc index 2a47c38822..c0664294c1 100644 --- a/src/bin/auth/auth_srv.cc +++ b/src/bin/auth/auth_srv.cc @@ -46,6 +46,7 @@ #include #include #include +#include #include @@ -266,6 +267,9 @@ public: /// The TSIG keyring const boost::shared_ptr* keyring_; + /// The client list + boost::shared_ptr 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* keyring) { impl_->keyring_ = keyring; } + +void +AuthSrv::setClientList(const boost::shared_ptr& 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_); +} diff --git a/src/bin/auth/auth_srv.h b/src/bin/auth/auth_srv.h index 18d750331b..59955b0390 100644 --- a/src/bin/auth/auth_srv.h +++ b/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* 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& + 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_; diff --git a/src/bin/auth/tests/auth_srv_unittest.cc b/src/bin/auth/tests/auth_srv_unittest.cc index a5b6d2635c..e6ebad4c25 100644 --- a/src/bin/auth/tests/auth_srv_unittest.cc +++ b/src/bin/auth/tests/auth_srv_unittest.cc @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -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( + server.getClientList())) << "The client list has a wrong type"; + // Now prepare a new client list and replace it + boost::shared_ptr + 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::BadValue); + EXPECT_EQ(list.get(), &server.getClientList()); +} + }