diff --git a/src/sbbs3/mqtt.c b/src/sbbs3/mqtt.c index 6ca2e8ca1929406ffe57f8ae40e5a885b5d78e12..cebbcf23e4931ef218e187ff80083e5a7e862665 100644 --- a/src/sbbs3/mqtt.c +++ b/src/sbbs3/mqtt.c @@ -242,7 +242,14 @@ int mqtt_connect(struct mqtt* mqtt, const char* bind_address) return MQTT_FAILURE; #ifdef USE_MOSQUITTO - mosquitto_int_option(mqtt->handle, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5); + char* username = mqtt->cfg->mqtt.username; + char* password = mqtt->cfg->mqtt.password; + if(*username == '\0') + username = NULL; + if(*password == '\0') + password = NULL; + mosquitto_int_option(mqtt->handle, MOSQ_OPT_PROTOCOL_VERSION, mqtt->cfg->mqtt.protocol_version); + mosquitto_username_pw_set(mqtt->handle, username, password); return mosquitto_connect_bind(mqtt->handle, mqtt->cfg->mqtt.broker_addr, mqtt->cfg->mqtt.broker_port, diff --git a/src/sbbs3/scfgdefs.h b/src/sbbs3/scfgdefs.h index 8e52cf0ff09dc22f09d094b340edd5059e83afe3..2a8c0592ee1e798f5f59fadc07fa9e99a9ce048f 100644 --- a/src/sbbs3/scfgdefs.h +++ b/src/sbbs3/scfgdefs.h @@ -367,8 +367,11 @@ struct mqtt_cfg { BOOL enabled; char broker_addr[128]; uint16_t broker_port; + char username[256]; + char password[256]; int keepalive; int qos; + int protocol_version; }; typedef struct diff --git a/src/sbbs3/scfglib1.c b/src/sbbs3/scfglib1.c index 8aa48038341eaf18cf445219dcc7954f0be9acd7..6ec35eb96ce95a8a7083fba183e23fcc8027d298 100644 --- a/src/sbbs3/scfglib1.c +++ b/src/sbbs3/scfglib1.c @@ -204,10 +204,13 @@ BOOL read_main_cfg(scfg_t* cfg, char* error, size_t maxerrlen) /*****************/ section = iniGetParsedSection(sections, "mqtt", /* cut: */TRUE); cfg->mqtt.enabled = iniGetBool(section, NULL, "enabled", FALSE); + SAFECOPY(cfg->mqtt.username, iniGetString(section, NULL, "username", "", value)); + SAFECOPY(cfg->mqtt.password, iniGetString(section, NULL, "password", "", value)); SAFECOPY(cfg->mqtt.broker_addr, iniGetString(section, NULL, "broker_addr", "127.0.0.1", value)); cfg->mqtt.broker_port = iniGetUInt16(section, NULL, "broker_port", IPPORT_MQTT); cfg->mqtt.keepalive = iniGetInteger(section, NULL, "keepalive", 10); cfg->mqtt.qos = iniGetInteger(section, NULL, "qos", 0); + cfg->mqtt.protocol_version = iniGetInteger(section, NULL, "protocol_version", 5); /***********/ /* Modules */ diff --git a/src/sbbs3/scfgsave.c b/src/sbbs3/scfgsave.c index 58379747add8591af01d7e8b42cb7fd39f68652b..8a4bf23c9807874964232d3eca6d82085020a9f2 100644 --- a/src/sbbs3/scfgsave.c +++ b/src/sbbs3/scfgsave.c @@ -212,8 +212,11 @@ BOOL write_main_cfg(scfg_t* cfg, int backup_level) iniSetBool(&ini, name, "enabled", cfg->mqtt.enabled, NULL); iniSetString(&ini, name, "broker_addr", cfg->mqtt.broker_addr, NULL); iniSetUInt16(&ini, name, "broker_port", cfg->mqtt.broker_port, NULL); + iniSetInteger(&ini, name, "protocol_version", cfg->mqtt.protocol_version, NULL); iniSetInteger(&ini, name, "keepalive", cfg->mqtt.keepalive, NULL); iniSetInteger(&ini, name, "qos", cfg->mqtt.qos, NULL); + iniSetString(&ini, name, "username", cfg->mqtt.username, NULL); + iniSetString(&ini, name, "password", cfg->mqtt.password, NULL); } {