projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #1455 from rubenk/configure-ac-remove-dead-code
[collectd.git]
/
src
/
mqtt.c
diff --git
a/src/mqtt.c
b/src/mqtt.c
index
f8c1e0e
..
8bc412c
100644
(file)
--- a/
src/mqtt.c
+++ b/
src/mqtt.c
@@
-185,9
+185,10
@@
static void on_message (
char *payload;
int status;
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;
return;
+ }
topic = strdup (msg->topic);
name = strip_prefix (topic);
topic = strdup (msg->topic);
name = strip_prefix (topic);
@@
-216,7
+217,16
@@
static void on_message (
}
vl.values_len = ds->ds_num;
}
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.");
+ sfree (vl.values);
+ 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)
DEBUG ("mqtt plugin: payload = \"%s\"", payload);
status = parse_values (payload, &vl, ds);
if (status != 0)
@@
-535,7
+545,7
@@
static int mqtt_write (const data_set_t *ds, const value_list_t *vl,
* CACert "ca.pem" Enables TLS if set
* CertificateFile "client-cert.pem" optional
* CertificateKeyFile "client-key.pem" optional
* CACert "ca.pem" Enables TLS if set
* CertificateFile "client-cert.pem" optional
* CertificateKeyFile "client-key.pem" optional
- * TLS
p
rotocol "tlsv1.2" optional
+ * TLS
P
rotocol "tlsv1.2" optional
* </Publish>
*/
static int mqtt_config_publisher (oconfig_item_t *ci)
* </Publish>
*/
static int mqtt_config_publisher (oconfig_item_t *ci)
@@
-618,7
+628,7
@@
static int mqtt_config_publisher (oconfig_item_t *ci)
cf_util_get_string (child, &conf->certificatefile);
else if (strcasecmp ("CertificateKeyFile", child->key) == 0)
cf_util_get_string (child, &conf->certificatekeyfile);
cf_util_get_string (child, &conf->certificatefile);
else if (strcasecmp ("CertificateKeyFile", child->key) == 0)
cf_util_get_string (child, &conf->certificatekeyfile);
- else if (strcasecmp ("TLS
p
rotocol", child->key) == 0)
+ else if (strcasecmp ("TLS
P
rotocol", child->key) == 0)
cf_util_get_string (child, &conf->tlsprotocol);
else if (strcasecmp ("CipherSuite", child->key) == 0)
cf_util_get_string (child, &conf->ciphersuite);
cf_util_get_string (child, &conf->tlsprotocol);
else if (strcasecmp ("CipherSuite", child->key) == 0)
cf_util_get_string (child, &conf->ciphersuite);
@@
-642,7
+652,7
@@
static int mqtt_config_publisher (oconfig_item_t *ci)
* User "guest"
* Password "secret"
* Topic "collectd/#"
* User "guest"
* Password "secret"
* Topic "collectd/#"
- * </
Publish
>
+ * </
Subscribe
>
*/
static int mqtt_config_subscriber (oconfig_item_t *ci)
{
*/
static int mqtt_config_subscriber (oconfig_item_t *ci)
{
@@
-719,7
+729,7
@@
static int mqtt_config_subscriber (oconfig_item_t *ci)
ERROR ("mqtt plugin: Unknown config option: %s", child->key);
}
ERROR ("mqtt plugin: Unknown config option: %s", child->key);
}
- tmp = realloc (subscribers, sizeof (*subscribers) *
subscribers_num
);
+ tmp = realloc (subscribers, sizeof (*subscribers) *
(subscribers_num + 1)
);
if (tmp == NULL)
{
ERROR ("mqtt plugin: realloc failed.");
if (tmp == NULL)
{
ERROR ("mqtt plugin: realloc failed.");