From 1d46beadab0396ff75bd1fbad32fb7924ed11aa7 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Tue, 27 Jun 2023 16:13:58 +0200 Subject: RC: handle nonexistent module in showjson --- lib/RemoteControl.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/RemoteControl.cpp b/lib/RemoteControl.cpp index 16359ad..dcae682 100644 --- a/lib/RemoteControl.cpp +++ b/lib/RemoteControl.cpp @@ -590,7 +590,7 @@ void RemoteControllerZmq::process() } } else if (msg.size() == 2 && command == "show") { - std::string module((char*) msg[1].data(), msg[1].size()); + const std::string module((char*) msg[1].data(), msg[1].size()); try { list< vector > r = rcs.get_param_list_values(module); size_t r_size = r.size(); @@ -608,17 +608,22 @@ void RemoteControllerZmq::process() } } else if (msg.size() == 2 && command == "showjson") { - std::string module((char*) msg[1].data(), msg[1].size()); - std::string json = rcs.get_params_json(module); + const std::string module((char*) msg[1].data(), msg[1].size()); + try { + std::string json = rcs.get_params_json(module); - zmq::message_t zmsg(json.size()); - memcpy(zmsg.data(), json.data(), json.size()); + zmq::message_t zmsg(json.size()); + memcpy(zmsg.data(), json.data(), json.size()); - repSocket.send(zmsg, zmq::send_flags::none); + repSocket.send(zmsg, zmq::send_flags::none); + } + catch (const ParameterError &err) { + send_fail_reply(repSocket, err.what()); + } } else if (msg.size() == 3 && command == "get") { - std::string module((char*) msg[1].data(), msg[1].size()); - std::string parameter((char*) msg[2].data(), msg[2].size()); + const std::string module((char*) msg[1].data(), msg[1].size()); + const std::string parameter((char*) msg[2].data(), msg[2].size()); try { std::string value = rcs.get_param(module, parameter); @@ -631,9 +636,9 @@ void RemoteControllerZmq::process() } } else if (msg.size() == 4 && command == "set") { - std::string module((char*) msg[1].data(), msg[1].size()); - std::string parameter((char*) msg[2].data(), msg[2].size()); - std::string value((char*) msg[3].data(), msg[3].size()); + const std::string module((char*) msg[1].data(), msg[1].size()); + const std::string parameter((char*) msg[2].data(), msg[2].size()); + const std::string value((char*) msg[3].data(), msg[3].size()); try { rcs.set_param(module, parameter, value); -- cgit v1.2.3