Skip to content
Snippets Groups Projects
Commit eb353f57 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Resolve off-by-one issue in MQTT node status publishing

Make mqtt_putnodedat() use a 1-based node number, like the other putnodedat()
functions.

The bug (misuse of mqtt_putnodedat) was actually in js_system.c, but fixed the
API to match the common expectation.
parent 0e9e499f
No related branches found
No related tags found
No related merge requests found
......@@ -923,7 +923,7 @@ int mqtt_file_download(struct mqtt* mqtt, user_t* user, int dirnum, const char*
return mqtt_file_xfer(mqtt, user, dirnum, fname, bytes, client, "download");
}
// number is zero-based
// number is one-based
int mqtt_putnodedat(struct mqtt* mqtt, int number, node_t* node)
{
if(mqtt == NULL || node == NULL)
......@@ -941,12 +941,12 @@ int mqtt_putnodedat(struct mqtt* mqtt, int number, node_t* node)
,node->errors
);
char topic[128];
SAFEPRINTF(topic, "node/%u/status", number + 1);
SAFEPRINTF(topic, "node/%u/status", number);
int result = mqtt_pub_strval(mqtt, TOPIC_BBS, topic, str);
if(result == MQTT_SUCCESS && mqtt->cfg->mqtt.verbose) {
SAFEPRINTF(topic, "node/%u", number + 1);
SAFEPRINTF(topic, "node/%u", number);
result = mqtt_pub_strval(mqtt, TOPIC_BBS, topic
,nodestatus(mqtt->cfg, node, str, sizeof(str), number + 1));
,nodestatus(mqtt->cfg, node, str, sizeof(str), number));
}
return result;
}
......@@ -91,7 +91,7 @@ int sbbs_t::putnodedat(uint number, node_t* node)
pthread_mutex_unlock(&nodefile_mutex);
if(cfg.mqtt.enabled && mqtt->handle != NULL) {
int result = mqtt_putnodedat(mqtt, number, node);
int result = mqtt_putnodedat(mqtt, number + 1, node);
if(result != MQTT_SUCCESS)
lprintf(LOG_WARNING, "ERROR %d (%d) publishing node status", result, errno);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment