-// Copyright (C) 2009-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2009-2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
const char *CONTROL_RESULT = "result";
const char *CONTROL_TEXT = "text";
const char *CONTROL_ARGUMENTS = "arguments";
+ const char *CONTROL_SERVICE = "service";
// Full version, with status, text and arguments
ConstElementPtr
ConstElementPtr
createCommand(const std::string& command) {
- return (createCommand(command, ElementPtr()));
+ return (createCommand(command, ElementPtr(), ""));
}
ConstElementPtr
createCommand(const std::string& command, ConstElementPtr arg) {
+ return (createCommand(command, arg, ""));
+}
+
+ConstElementPtr
+createCommand(const std::string& command, const std::string& service) {
+ return (createCommand(command, ElementPtr(), service));
+}
+
+ConstElementPtr
+createCommand(const std::string& command,
+ ConstElementPtr arg,
+ const std::string& service) {
ElementPtr query = Element::createMap();
ElementPtr cmd = Element::create(command);
query->set(CONTROL_COMMAND, cmd);
if (arg) {
query->set(CONTROL_ARGUMENTS, arg);
}
+ if (!service.empty()) {
+ ElementPtr services = Element::createList();
+ services->add(Element::create(service));
+ query->set(CONTROL_SERVICE, services);
+ }
return (query);
}
-// Copyright (C) 2009-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2009-2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
isc::data::ConstElementPtr createCommand(const std::string& command,
isc::data::ConstElementPtr arg);
+/// @brief Creates a standard config/command command message with no
+/// argument and with the given service (of the form
+/// { "command": "my_command", "service": [ service ] })
+///
+/// @param command The command string
+/// @param service The target service. May be empty.
+/// @return The created message
+ isc::data::ConstElementPtr createCommand(const std::string& command,
+ const std::string& service);
+
+/// @brief Creates a standard config/command command message with the
+/// given argument and given service (of the form
+/// { "command": "my_command", "arguments": arg, "service": [ service ] }
+///
+/// @param command The command string
+/// @param arg The optional argument for the command. This can be of
+/// any Element type. May be NULL.
+/// @param service The target service. May be empty.
+/// @return The created message
+isc::data::ConstElementPtr createCommand(const std::string& command,
+ isc::data::ConstElementPtr arg,
+ const std::string& service);
+
/// @brief Parses the given command into a string containing the actual
/// command and an ElementPtr containing the optional argument.
///
-// Copyright (C) 2009-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2009-2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
TEST(CommandInterpreterTest, createCommand) {
ConstElementPtr command;
ConstElementPtr arg;
+ string service;
command = createCommand("my_command");
ASSERT_EQ("{ \"command\": \"my_command\" }", command->str());
command = createCommand("foo", arg);
ASSERT_EQ("{ \"arguments\": { \"a\": \"map\" }, \"command\": \"foo\" }",
command->str());
+
+ command = createCommand("my_command", "my_service");
+ ASSERT_EQ("{ \"command\": \"my_command\", "
+ "\"service\": [ \"my_service\" ] }",
+ command->str());
+
+ arg = el("1");
+ command = createCommand("my_command", arg, "my_service");
+ ASSERT_EQ("{ \"arguments\": 1, \"command\": \"my_command\", "
+ "\"service\": [ \"my_service\" ] }",
+ command->str());
+
+ arg = el("[ \"a\", \"b\" ]");
+ command = createCommand("my_cmd", arg, "my_server");
+ ASSERT_EQ("{ \"arguments\": [ \"a\", \"b\" ], "
+ "\"command\": \"my_cmd\", "
+ "\"service\": [ \"my_server\" ] }",
+ command->str());
+
+ arg = el("{ \"a\": \"map\" }");
+ command = createCommand("foo", arg, "bar");
+ ASSERT_EQ("{ \"arguments\": { \"a\": \"map\" }, "
+ "\"command\": \"foo\", "
+ "\"service\": [ \"bar\" ] }",
+ command->str());
}
// This test checks whether parseCommand function is able to parse various valid