From 576df42e42c6ef599d626021d69455a3f58d15cd Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 7 Mar 2024 16:26:43 +0000 Subject: [PATCH] mqtt: Do not attempt validating topics if they are not set Signed-off-by: Steffen Vogel --- lib/nodes/mqtt.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/nodes/mqtt.cpp b/lib/nodes/mqtt.cpp index 851b36a66..6266b4b4a 100644 --- a/lib/nodes/mqtt.cpp +++ b/lib/nodes/mqtt.cpp @@ -246,15 +246,19 @@ int villas::node::mqtt_check(NodeCompat *n) { int ret; auto *m = n->getData(); - ret = mosquitto_sub_topic_check(m->subscribe); - if (ret != MOSQ_ERR_SUCCESS) - throw RuntimeError("Invalid subscribe topic: '{}': {}", m->subscribe, - mosquitto_strerror(ret)); + if (m->subscribe) { + ret = mosquitto_sub_topic_check(m->subscribe); + if (ret != MOSQ_ERR_SUCCESS) + throw RuntimeError("Invalid subscribe topic: '{}': {}", m->subscribe, + mosquitto_strerror(ret)); + } - ret = mosquitto_pub_topic_check(m->publish); - if (ret != MOSQ_ERR_SUCCESS) - throw RuntimeError("Invalid publish topic: '{}': {}", m->publish, - mosquitto_strerror(ret)); + if (m->publish) { + ret = mosquitto_pub_topic_check(m->publish); + if (ret != MOSQ_ERR_SUCCESS) + throw RuntimeError("Invalid publish topic: '{}': {}", m->publish, + mosquitto_strerror(ret)); + } return 0; }