X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fmqtt.c;h=48c34edc036897e7853599bfc6b0a6e197be2419;hp=d134c381b2ecfa875d7ecd31dd8dc25cf45e20d3;hb=ec51ddee94fa2ba1e01fe0e336ccc9c190a198ff;hpb=109aa67e9a982321af6547b92b5b2b6c8ae2c244 diff --git a/src/mqtt.c b/src/mqtt.c index d134c381..48c34edc 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -54,11 +54,11 @@ * Data types */ struct mqtt_client_conf { - _Bool publish; + bool publish; char *name; struct mosquitto *mosq; - _Bool connected; + bool connected; char *host; int port; @@ -74,22 +74,22 @@ struct mqtt_client_conf { /* For publishing */ char *topic_prefix; - _Bool store_rates; - _Bool retain; + bool store_rates; + bool retain; /* For subscribing */ pthread_t thread; - _Bool loop; + bool loop; char *topic; - _Bool clean_session; + bool clean_session; c_complain_t complaint_cantpublish; pthread_mutex_t lock; }; typedef struct mqtt_client_conf mqtt_client_conf_t; -static mqtt_client_conf_t **subscribers = NULL; -static size_t subscribers_num = 0; +static mqtt_client_conf_t **subscribers; +static size_t subscribers_num; /* * Functions @@ -141,7 +141,7 @@ static void mqtt_free(mqtt_client_conf_t *conf) { if (conf->connected) (void)mosquitto_disconnect(conf->mosq); - conf->connected = 0; + conf->connected = false; (void)mosquitto_destroy(conf->mosq); sfree(conf->host); @@ -252,7 +252,7 @@ static int mqtt_reconnect(mqtt_client_conf_t *conf) { return -1; } - conf->connected = 1; + conf->connected = true; c_release(LOG_INFO, &conf->complaint_cantpublish, "mqtt plugin: successfully reconnected to broker \"%s:%d\"", @@ -366,7 +366,7 @@ static int mqtt_connect(mqtt_client_conf_t *conf) { } } - conf->connected = 1; + conf->connected = true; return 0; } /* mqtt_connect */ @@ -393,14 +393,14 @@ static void *subscribers_thread(void *arg) { /* max_packets = */ 100); #endif if (status == MOSQ_ERR_CONN_LOST) { - conf->connected = 0; + conf->connected = false; continue; } else if (status != MOSQ_ERR_SUCCESS) { ERROR("mqtt plugin: mosquitto_loop failed: %s", mosquitto_strerror(status)); mosquitto_destroy(conf->mosq); conf->mosq = NULL; - conf->connected = 0; + conf->connected = false; continue; } @@ -438,7 +438,7 @@ static int publish(mqtt_client_conf_t *conf, char const *topic, /* Mark our connection "down" regardless of the error as a safety * measure; we will try to reconnect the next time we have to publish a * message */ - conf->connected = 0; + conf->connected = false; mosquitto_disconnect(conf->mosq); pthread_mutex_unlock(&conf->lock); @@ -532,7 +532,7 @@ static int mqtt_config_publisher(oconfig_item_t *ci) { ERROR("mqtt plugin: calloc failed."); return -1; } - conf->publish = 1; + conf->publish = true; conf->name = NULL; status = cf_util_get_string(ci, &conf->name); @@ -546,7 +546,7 @@ static int mqtt_config_publisher(oconfig_item_t *ci) { conf->client_id = NULL; conf->qos = 0; conf->topic_prefix = strdup(MQTT_DEFAULT_TOPIC_PREFIX); - conf->store_rates = 1; + conf->store_rates = true; status = pthread_mutex_init(&conf->lock, NULL); if (status != 0) { @@ -631,7 +631,7 @@ static int mqtt_config_subscriber(oconfig_item_t *ci) { ERROR("mqtt plugin: calloc failed."); return -1; } - conf->publish = 0; + conf->publish = false; conf->name = NULL; status = cf_util_get_string(ci, &conf->name); @@ -645,7 +645,7 @@ static int mqtt_config_subscriber(oconfig_item_t *ci) { conf->client_id = NULL; conf->qos = 2; conf->topic = strdup(MQTT_DEFAULT_TOPIC); - conf->clean_session = 1; + conf->clean_session = true; status = pthread_mutex_init(&conf->lock, NULL); if (status != 0) {