BIND 10 trac2862, updated. 114fc9c5ee887ea847011070568fc408c2b8e265 [2862] Hack in a way to receive foreign commands
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Jul 12 09:08:46 UTC 2013
The branch, trac2862 has been updated
via 114fc9c5ee887ea847011070568fc408c2b8e265 (commit)
from 65805a60410390ead4f52dc89d259999a65f0af0 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 114fc9c5ee887ea847011070568fc408c2b8e265
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Fri Jul 12 11:05:29 2013 +0200
[2862] Hack in a way to receive foreign commands
Provide a callback to receive commands for foreign modules. The current
implementation is somewhat broken and unsatisfactory, but let's leave
that up for later. We need a way now.
-----------------------------------------------------------------------
Summary of changes:
src/lib/config/ccsession.cc | 2 ++
src/lib/config/ccsession.h | 32 +++++++++++++++++++++++++++
src/lib/config/tests/ccsession_unittests.cc | 26 ++++++++++++++++++++++
3 files changed, 60 insertions(+)
-----------------------------------------------------------------------
diff --git a/src/lib/config/ccsession.cc b/src/lib/config/ccsession.cc
index 0d43b27..780fe95 100644
--- a/src/lib/config/ccsession.cc
+++ b/src/lib/config/ccsession.cc
@@ -595,6 +595,8 @@ ModuleCCSession::checkModuleCommand(const std::string& cmd_str,
"Command given but no "
"command handler for module"));
}
+ } else if (unhandled_callback_) {
+ unhandled_callback_(cmd_str, target_module, arg);
}
return (ElementPtr());
}
diff --git a/src/lib/config/ccsession.h b/src/lib/config/ccsession.h
index 5c614e6..c536861 100644
--- a/src/lib/config/ccsession.h
+++ b/src/lib/config/ccsession.h
@@ -589,6 +589,36 @@ public:
session_.unsubscribe(group, isc::cc::CC_INSTANCE_WILDCARD);
}
+ /// \brief Callback type for unhandled commands
+ ///
+ /// The type of functions that are not handled by the ModuleCCSession
+ /// because they are not aimed at the module.
+ ///
+ /// The parameters are:
+ /// - Name of the command.
+ /// - The module it was aimed for (may be empty).
+ /// - The parameters of the command.
+ typedef boost::function<void (const std::string&, const std::string&,
+ const isc::data::ConstElementPtr&)>
+ UnhandledCallback;
+
+ /// \brief Register a callback for messages sent to foreign modules.
+ ///
+ /// Usually, a command aimed at foreign module (or sent directly)
+ /// is discarded. By registering a callback here, these can be
+ /// examined.
+ ///
+ /// \note A callback overwrites the previous one set.
+ /// \todo This is a temporary, unclean, solution. A more generic
+ /// one needs to be designed. Also, a solution that is able
+ /// to send an answer would be great.
+ ///
+ /// \param callback The new callback to use. It may be an empty
+ /// function.
+ void setUnhandledCallback(const UnhandledCallback& callback) {
+ unhandled_callback_ = callback;
+ }
+
private:
ModuleSpec readModuleSpecification(const std::string& filename);
void startCheck();
@@ -638,6 +668,8 @@ private:
isc::data::ConstElementPtr new_config);
ModuleSpec fetchRemoteSpec(const std::string& module, bool is_filename);
+
+ UnhandledCallback unhandled_callback_;
};
/// \brief Default handler for logging config updates
diff --git a/src/lib/config/tests/ccsession_unittests.cc b/src/lib/config/tests/ccsession_unittests.cc
index d958529..4a04412 100644
--- a/src/lib/config/tests/ccsession_unittests.cc
+++ b/src/lib/config/tests/ccsession_unittests.cc
@@ -697,6 +697,16 @@ TEST_F(CCSessionTest, remoteConfig) {
}
}
+void
+callback(std::string* command, std::string* target, ConstElementPtr *params,
+ const std::string& command_real, const std::string& target_real,
+ const ConstElementPtr& params_real)
+{
+ *command = command_real;
+ *target = target_real;
+ *params = params_real;
+}
+
TEST_F(CCSessionTest, ignoreRemoteConfigCommands) {
// client will ask for config
session.getMessages()->add(createAnswer(0, el("{ }")));
@@ -732,6 +742,22 @@ TEST_F(CCSessionTest, ignoreRemoteConfigCommands) {
result = mccs.checkCommand();
EXPECT_EQ(0, session.getMsgQueue()->size());
EXPECT_EQ(0, result);
+
+ // Check that we can get the ignored commands by registering a callback
+ std::string command, target;
+ ConstElementPtr params;
+ mccs.setUnhandledCallback(boost::bind(&callback, &command, &target,
+ ¶ms, _1, _2, _3));
+ session.addMessage(el("{ \"command\": [ \"good_command\","
+ "{\"param\": true} ] }"), "Spec1", "*");
+ EXPECT_EQ(1, session.getMsgQueue()->size());
+ result = mccs.checkCommand();
+ EXPECT_EQ(0, session.getMsgQueue()->size());
+ EXPECT_EQ(0, result);
+
+ EXPECT_EQ("good_command", command);
+ EXPECT_EQ("Spec1", target);
+ EXPECT_TRUE(params && el("{\"param\": true}")->equals(*params));
}
TEST_F(CCSessionTest, initializationFail) {
More information about the bind10-changes
mailing list