From: Florian Forster Date: Thu, 20 Nov 2014 16:42:42 +0000 (+0100) Subject: mqtt plugin: Compile fixes. X-Git-Tag: collectd-5.6.0~637^2~19 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ad9e0d17162a12d176d3dfce086268301d4c8e54;p=collectd.git mqtt plugin: Compile fixes. This compiles with libmosquitto 0.15.0. It appears newer versions of the library have some interface changes, so we should add a version check. Luckily, libmosquitto provides everything we need. --- diff --git a/src/mqtt.c b/src/mqtt.c index 3bed0a5e..7adc7f71 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -56,6 +56,30 @@ struct mqtt_client_conf pthread_mutex_t lock; }; +static char const *mosquitto_strerror (int code) +{ + switch (code) + { + case MOSQ_ERR_SUCCESS: return "MOSQ_ERR_SUCCESS"; + case MOSQ_ERR_NOMEM: return "MOSQ_ERR_NOMEM"; + case MOSQ_ERR_PROTOCOL: return "MOSQ_ERR_PROTOCOL"; + case MOSQ_ERR_INVAL: return "MOSQ_ERR_INVAL"; + case MOSQ_ERR_NO_CONN: return "MOSQ_ERR_NO_CONN"; + case MOSQ_ERR_CONN_REFUSED: return "MOSQ_ERR_CONN_REFUSED"; + case MOSQ_ERR_NOT_FOUND: return "MOSQ_ERR_NOT_FOUND"; + case MOSQ_ERR_CONN_LOST: return "MOSQ_ERR_CONN_LOST"; + case MOSQ_ERR_SSL: return "MOSQ_ERR_SSL"; + case MOSQ_ERR_PAYLOAD_SIZE: return "MOSQ_ERR_PAYLOAD_SIZE"; + case MOSQ_ERR_NOT_SUPPORTED: return "MOSQ_ERR_NOT_SUPPORTED"; + case MOSQ_ERR_AUTH: return "MOSQ_ERR_AUTH"; + case MOSQ_ERR_ACL_DENIED: return "MOSQ_ERR_ACL_DENIED"; + case MOSQ_ERR_UNKNOWN: return "MOSQ_ERR_UNKNOWN"; + case MOSQ_ERR_ERRNO: return "MOSQ_ERR_ERRNO"; + } + + return "UNKNOWN ERROR CODE"; +} + /* * Functions */ @@ -91,7 +115,7 @@ static int mqtt_reconnect_broker (struct mqtt_client_conf *conf) } /* mqtt_reconnect_broker */ static int mqtt_publish_message (struct mqtt_client_conf *conf, char *topic, - char *payload, size_t payload_len) + void const *payload, size_t payload_len) { char errbuf[1024]; int status; @@ -329,13 +353,16 @@ static int mqtt_config (oconfig_item_t *ci) memset (&user_data, 0, sizeof (user_data)); user_data.data = conf; - if ((conf->mosq = mosquitto_new (conf->client_id, true, NULL)) == NULL) { - ERROR ("mqtt_config: mosquitto_new failed"); + conf->mosq = mosquitto_new (conf->client_id, /* user data = */ conf); + if (conf->mosq == NULL) + { + ERROR ("mqtt plugin: mosquitto_new failed"); + free (conf); return (-1); } - status = mosquitto_connect (conf->mosq, conf->host, conf->port, 10); - + status = mosquitto_connect (conf->mosq, conf->host, conf->port, + /* keepalive = */ 10, /* clean session = */ 1); if (status != MOSQ_ERR_SUCCESS) { ERROR ("mqtt_config: mosquitto_connect failed: %s", (status == MOSQ_ERR_ERRNO ?