Merge pull request #1220 from rubenk/set-package-bugreport-and-homepage
[collectd.git] / src / mqtt.c
index 403b0d3..7003fcc 100644 (file)
@@ -185,9 +185,10 @@ static void on_message (
     char *payload;
     int status;
 
-    if ((msg->payloadlen <= 0)
-            || (((uint8_t *) msg->payload)[msg->payloadlen - 1] != 0))
+    if (msg->payloadlen <= 0) {
+        DEBUG ("mqtt plugin: message has empty payload");
         return;
+    }
 
     topic = strdup (msg->topic);
     name = strip_prefix (topic);
@@ -216,7 +217,15 @@ static void on_message (
     }
     vl.values_len = ds->ds_num;
 
-    payload = strdup ((void *) msg->payload);
+    payload = malloc (msg->payloadlen+1);
+    if (payload == NULL)
+    {
+        ERROR ("mqtt plugin: malloc for payload buffer failed.");
+        return;
+    }
+    memmove (payload, msg->payload, msg->payloadlen);
+    payload[msg->payloadlen] = 0;
+
     DEBUG ("mqtt plugin: payload = \"%s\"", payload);
     status = parse_values (payload, &vl, ds);
     if (status != 0)
@@ -532,10 +541,10 @@ static int mqtt_write (const data_set_t *ds, const value_list_t *vl,
  *   StoreRates true
  *   Retain false
  *   QoS 0
- *   CACertificateFile "ca.pem"                        Enables TLS if set
+ *   CACert "ca.pem"                   Enables TLS if set
  *   CertificateFile "client-cert.pem"         optional
  *   CertificateKeyFile "client-key.pem"               optional
- *   TLSprotocol "tlsv1.2"             optional
+ *   TLSProtocol "tlsv1.2"             optional
  * </Publish>
  */
 static int mqtt_config_publisher (oconfig_item_t *ci)
@@ -612,13 +621,13 @@ static int mqtt_config_publisher (oconfig_item_t *ci)
             cf_util_get_boolean (child, &conf->store_rates);
         else if (strcasecmp ("Retain", child->key) == 0)
             cf_util_get_boolean (child, &conf->retain);
-        else if (strcasecmp ("CACertificateFile", child->key) == 0)
+        else if (strcasecmp ("CACert", child->key) == 0)
             cf_util_get_string (child, &conf->cacertificatefile);
         else if (strcasecmp ("CertificateFile", child->key) == 0)
             cf_util_get_string (child, &conf->certificatefile);
         else if (strcasecmp ("CertificateKeyFile", child->key) == 0)
             cf_util_get_string (child, &conf->certificatekeyfile);
-        else if (strcasecmp ("TLSprotocol", child->key) == 0)
+        else if (strcasecmp ("TLSProtocol", child->key) == 0)
             cf_util_get_string (child, &conf->tlsprotocol);
         else if (strcasecmp ("CipherSuite", child->key) == 0)
             cf_util_get_string (child, &conf->ciphersuite);
@@ -642,7 +651,7 @@ static int mqtt_config_publisher (oconfig_item_t *ci)
  *   User "guest"
  *   Password "secret"
  *   Topic "collectd/#"
- * </Publish>
+ * </Subscribe>
  */
 static int mqtt_config_subscriber (oconfig_item_t *ci)
 {