From 5c7a22f27e2eb72d24a5015dd33ac0d0befbd1c5 Mon Sep 17 00:00:00 2001 From: Rob Swindell <rob@synchro.net> Date: Wed, 4 Jan 2023 21:33:37 -0800 Subject: [PATCH] Public log messages over MQTT with the 'retain' flag set to true This can be useful when debugging issues (e.g. crashes) and an MQTT consuming/logging client wasn't connected at the time. --- src/sbbs3/main.cpp | 2 +- src/sbbs3/mqtt.c | 8 ++++---- src/sbbs3/mqtt.h | 18 +++++++++--------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/sbbs3/main.cpp b/src/sbbs3/main.cpp index 3be3677e11..c022e9a7a5 100644 --- a/src/sbbs3/main.cpp +++ b/src/sbbs3/main.cpp @@ -2482,7 +2482,7 @@ void output_thread(void* arg) } /* Spy on the user remotely */ if(sbbs->cfg.mqtt.enabled) { - int result = mqtt_pub_message(&mqtt, TOPIC_BBS, spy_topic, buf+bufbot, i); + int result = mqtt_pub_message(&mqtt, TOPIC_BBS, spy_topic, buf+bufbot, i, /* retain: */false); if(result != MQTT_SUCCESS) lprintf(LOG_WARNING, "%s ERROR %d (%d) publishing node output (%u bytes): %s" ,node, result, errno, i, spy_topic); diff --git a/src/sbbs3/mqtt.c b/src/sbbs3/mqtt.c index 72ae2c17f6..8028e9ccd2 100644 --- a/src/sbbs3/mqtt.c +++ b/src/sbbs3/mqtt.c @@ -174,7 +174,7 @@ int mqtt_lputs(struct mqtt* mqtt, enum topic_depth depth, int level, const char* /* payloadlen */strlen(str), /* payload */str, /* qos */mqtt->cfg->mqtt.publish_qos, - /* retain */false, + /* retain */true, /* properties */NULL); mqtt_topic(mqtt, depth, sub, sizeof(sub), "log"); mosquitto_property* props = NULL; @@ -185,7 +185,7 @@ int mqtt_lputs(struct mqtt* mqtt, enum topic_depth depth, int level, const char* /* payloadlen */strlen(str), /* payload */str, /* qos */mqtt->cfg->mqtt.publish_qos, - /* retain */false, + /* retain */true, /* properties */props); mosquitto_property_free_all(&props); return result; @@ -266,7 +266,7 @@ int mqtt_pub_uintval(struct mqtt* mqtt, enum topic_depth depth, const char* key, return MQTT_FAILURE; } -int mqtt_pub_message(struct mqtt* mqtt, enum topic_depth depth, const char* key, const void* buf, size_t len) +int mqtt_pub_message(struct mqtt* mqtt, enum topic_depth depth, const char* key, const void* buf, size_t len, BOOL retain) { if(mqtt == NULL || mqtt->cfg == NULL) return MQTT_FAILURE; @@ -282,7 +282,7 @@ int mqtt_pub_message(struct mqtt* mqtt, enum topic_depth depth, const char* key, /* payloadlen */len, /* payload */buf, /* qos */mqtt->cfg->mqtt.publish_qos, - /* retain */false, + /* retain */retain, /* properties */NULL); } #endif diff --git a/src/sbbs3/mqtt.h b/src/sbbs3/mqtt.h index 1bfd57ecc6..9a0010d69f 100644 --- a/src/sbbs3/mqtt.h +++ b/src/sbbs3/mqtt.h @@ -53,14 +53,14 @@ struct mqtt { enum topic_depth { TOPIC_OTHER, - TOPIC_ROOT, // sbbs/* - TOPIC_BBS, // sbbs/BBS-ID/* - TOPIC_BBS_LEVEL, // sbbs/BBS-ID - TOPIC_HOST, // sbbs/BBS-ID/hostname/* - TOPIC_HOST_LEVEL, // sbbs/BBS-DI/hostname - TOPIC_EVENT, // sbbs/BBS-ID/event/* - TOPIC_SERVER, // sbbs/BBS-ID/server/* - TOPIC_SERVER_LEVEL, // sbbs/BBS-ID/server + TOPIC_ROOT, // sbbs/* + TOPIC_BBS, // sbbs/BBSID/* + TOPIC_BBS_LEVEL, // sbbs/BBSID + TOPIC_HOST, // sbbs/BBSID/host/HOSTNAME/* + TOPIC_HOST_LEVEL, // sbbs/BBSID/host/HOSTNAME + TOPIC_EVENT, // sbbs/BBSID/event/* + TOPIC_SERVER, // sbbs/BBSID/server/SERVER/* + TOPIC_SERVER_LEVEL, // sbbs/BBSID/server/SERVER }; #define MQTT_SUCCESS 0 // Same as MOSQ_ERR_SUCCESS @@ -85,7 +85,7 @@ DLLEXPORT int mqtt_lputs(struct mqtt*, enum topic_depth, int level, const char* DLLEXPORT int mqtt_pub_noval(struct mqtt*, enum topic_depth, const char* key); DLLEXPORT int mqtt_pub_strval(struct mqtt*, enum topic_depth, const char* key, const char* str); DLLEXPORT int mqtt_pub_uintval(struct mqtt*, enum topic_depth, const char* key, ulong value); -DLLEXPORT int mqtt_pub_message(struct mqtt*, enum topic_depth, const char* key, const void* buf, size_t len); +DLLEXPORT int mqtt_pub_message(struct mqtt*, enum topic_depth, const char* key, const void* buf, size_t len, BOOL retain); DLLEXPORT int mqtt_open(struct mqtt*); DLLEXPORT void mqtt_close(struct mqtt*); DLLEXPORT int mqtt_connect(struct mqtt*, const char* bind_address); -- GitLab