diff --git a/man/mosquitto.conf.5.xml b/man/mosquitto.conf.5.xml index 2a4f6189..5cd1dd04 100644 --- a/man/mosquitto.conf.5.xml +++ b/man/mosquitto.conf.5.xml @@ -1088,6 +1088,15 @@ connection has failed. Defaults to true. + + + [ true | false ] + + If set to true, only publish + notification messages to the local broker giving + information about the state of the bridge connection. + Defaults to false. + topic diff --git a/src/bridge.c b/src/bridge.c index 006d3095..6037e9dd 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -149,10 +149,13 @@ int bridge__connect(struct mosquitto_db *db, struct mosquitto *context) db__messages_easy_queue(db, context, context->bridge->notification_topic, 1, 1, ¬ification_payload, 1); context->bridge->initial_notification_done = true; } - notification_payload = '0'; - rc = will__set(context, context->bridge->notification_topic, 1, ¬ification_payload, 1, true); - if(rc != MOSQ_ERR_SUCCESS){ - return rc; + + if (!context->bridge->notifications_local_only) { + notification_payload = '0'; + rc = will__set(context, context->bridge->notification_topic, 1, ¬ification_payload, 1, true); + if(rc != MOSQ_ERR_SUCCESS){ + return rc; + } } }else{ notification_topic_len = strlen(context->bridge->remote_clientid)+strlen("$SYS/broker/connection//state"); @@ -167,11 +170,13 @@ int bridge__connect(struct mosquitto_db *db, struct mosquitto *context) context->bridge->initial_notification_done = true; } - notification_payload = '0'; - rc = will__set(context, notification_topic, 1, ¬ification_payload, 1, true); - mosquitto__free(notification_topic); - if(rc != MOSQ_ERR_SUCCESS){ - return rc; + if (!context->bridge->notifications_local_only) { + notification_payload = '0'; + rc = will__set(context, notification_topic, 1, ¬ification_payload, 1, true); + mosquitto__free(notification_topic); + if(rc != MOSQ_ERR_SUCCESS){ + return rc; + } } } } diff --git a/src/conf.c b/src/conf.c index fd6e015c..e7a1d8a7 100644 --- a/src/conf.c +++ b/src/conf.c @@ -968,6 +968,7 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, const } cur_bridge->keepalive = 60; cur_bridge->notifications = true; + cur_bridge->notifications_local_only = false; cur_bridge->start_type = bst_automatic; cur_bridge->idle_timeout = 60; cur_bridge->restart_timeout = 30; @@ -1355,6 +1356,17 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, const if(conf__parse_bool(&token, "notifications", &cur_bridge->notifications, saveptr)) return MOSQ_ERR_INVAL; #else log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge support not available."); +#endif + }else if(!strcmp(token, "notifications_local_only")){ +#ifdef WITH_BRIDGE + if(reload) continue; // FIXME + if(!cur_bridge){ + log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge configuration"); + return MOSQ_ERR_INVAL; + } + if(conf__parse_bool(&token, "notifications_local_only", &cur_bridge->notifications_local_only, saveptr)) return MOSQ_ERR_INVAL; +#else + log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge support not available."); #endif }else if(!strcmp(token, "notification_topic")){ #ifdef WITH_BRIDGE diff --git a/src/handle_connack.c b/src/handle_connack.c index 508e22cb..9ec385aa 100644 --- a/src/handle_connack.c +++ b/src/handle_connack.c @@ -46,10 +46,12 @@ int handle__connack(struct mosquitto_db *db, struct mosquitto *context) if(context->bridge->notifications){ notification_payload = '1'; if(context->bridge->notification_topic){ - if(send__real_publish(context, mosquitto__mid_generate(context), - context->bridge->notification_topic, 1, ¬ification_payload, 1, true, 0)){ + if(!context->bridge->notifications_local_only){ + if(send__real_publish(context, mosquitto__mid_generate(context), + context->bridge->notification_topic, 1, ¬ification_payload, 1, true, 0)){ - return 1; + return 1; + } } db__messages_easy_queue(db, context, context->bridge->notification_topic, 1, 1, ¬ification_payload, 1); }else{ @@ -59,11 +61,13 @@ int handle__connack(struct mosquitto_db *db, struct mosquitto *context) snprintf(notification_topic, notification_topic_len+1, "$SYS/broker/connection/%s/state", context->bridge->remote_clientid); notification_payload = '1'; - if(send__real_publish(context, mosquitto__mid_generate(context), - notification_topic, 1, ¬ification_payload, 1, true, 0)){ + if(!context->bridge->notifications_local_only){ + if(send__real_publish(context, mosquitto__mid_generate(context), + notification_topic, 1, ¬ification_payload, 1, true, 0)){ - mosquitto__free(notification_topic); - return 1; + mosquitto__free(notification_topic); + return 1; + } } db__messages_easy_queue(db, context, notification_topic, 1, 1, ¬ification_payload, 1); mosquitto__free(notification_topic); diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index f9a0636b..32563425 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -422,6 +422,7 @@ struct mosquitto__bridge{ char *local_username; char *local_password; bool notifications; + bool notifications_local_only; char *notification_topic; enum mosquitto_bridge_start_type start_type; int idle_timeout;