Merge branch 'collectd-5.6' into collectd-5.7
[collectd.git] / src / mqtt.c
index b578b99..315974b 100644 (file)
@@ -448,6 +448,7 @@ static int publish(mqtt_client_conf_t *conf, char const *topic,
      * measure; we will try to reconnect the next time we have to publish a
      * message */
     conf->connected = 0;
+    mosquitto_disconnect(conf->mosq);
 
     pthread_mutex_unlock(&conf->lock);
     return (-1);
@@ -461,6 +462,7 @@ static int format_topic(char *buf, size_t buf_len, data_set_t const *ds,
                         value_list_t const *vl, mqtt_client_conf_t *conf) {
   char name[MQTT_MAX_TOPIC_SIZE];
   int status;
+  char *c;
 
   if ((conf->topic_prefix == NULL) || (conf->topic_prefix[0] == 0))
     return (FORMAT_VL(buf, buf_len, vl));
@@ -473,6 +475,10 @@ static int format_topic(char *buf, size_t buf_len, data_set_t const *ds,
   if ((status < 0) || (((size_t)status) >= buf_len))
     return (ENOMEM);
 
+  while((c = strchr(buf, '#')) || (c = strchr(buf, '+'))) {
+       *c = '_';
+  }
+
   return (0);
 } /* int format_topic */