From d6a690aa8d10070db8a75417560056998a39b6aa Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sun, 3 Feb 2019 22:01:33 +0000 Subject: [PATCH] Fix Will not being sent for Websockets clients. Closes #1143. Thanks to salcedo. --- ChangeLog.txt | 1 + lib/mosquitto_internal.h | 3 +-- src/context.c | 14 +++++++++----- src/loop.c | 10 ++-------- src/mosquitto_broker_internal.h | 1 + 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index e72b9211..46e45e39 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -32,6 +32,7 @@ Broker: #1131. - Allow broker to always restart on Windows when using `log_dest file`. Closes #1080. +- Fix Will not being sent for Websockets clients. Closes #1143. Library: - Fix TLS connections not working over SOCKS. diff --git a/lib/mosquitto_internal.h b/lib/mosquitto_internal.h index c6b3d6e5..55d38626 100644 --- a/lib/mosquitto_internal.h +++ b/lib/mosquitto_internal.h @@ -208,8 +208,7 @@ struct mosquitto { #endif bool clean_session; #ifdef WITH_BROKER - char *old_id; /* for when a duplicate client connects, but we still want to - know what the id was */ + bool removed_from_by_id; /* True if removed from by_id hash */ bool is_dropping; bool is_bridge; struct mosquitto__bridge *bridge; diff --git a/src/context.c b/src/context.c index e8cbfdfc..b7e47565 100644 --- a/src/context.c +++ b/src/context.c @@ -157,14 +157,10 @@ void context__cleanup(struct mosquitto_db *db, struct mosquitto *context, bool d assert(db); /* db can only be NULL here if the client hasn't sent a CONNECT and hence wouldn't have an id. */ - HASH_DELETE(hh_id, db->contexts_by_id, context); + context__remove_from_by_id(db, context); mosquitto__free(context->id); context->id = NULL; } - if(context->old_id){ - mosquitto__free(context->old_id); - context->old_id = NULL; - } packet__cleanup(&(context->in_packet)); if(context->current_out_packet){ packet__cleanup(context->current_out_packet); @@ -260,3 +256,11 @@ void context__free_disused(struct mosquitto_db *db) db->ll_for_free = NULL; } + +void context__remove_from_by_id(struct mosquitto_db *db, struct mosquitto *context) +{ + if(context->removed_from_by_id == false && context->id){ + HASH_DELETE(hh_id, db->contexts_by_id, context); + context->removed_from_by_id = true; + } +} diff --git a/src/loop.c b/src/loop.c index 8d084749..980de518 100644 --- a/src/loop.c +++ b/src/loop.c @@ -644,19 +644,13 @@ void do_disconnect(struct mosquitto_db *db, struct mosquitto *context) context->sock = INVALID_SOCKET; context->pollfd_index = -1; } - if(context->id){ - HASH_DELETE(hh_id, db->contexts_by_id, context); - context->old_id = context->id; - context->id = NULL; - } + context__remove_from_by_id(db, context); }else #endif { if(db->config->connection_messages == true){ if(context->id){ id = context->id; - }else if(context->old_id){ - id = context->old_id; }else{ id = ""; } @@ -681,7 +675,7 @@ void do_disconnect(struct mosquitto_db *db, struct mosquitto *context) #endif context__add_to_disused(db, context); if(context->id){ - HASH_DELETE(hh_id, db->contexts_by_id, context); + context__remove_from_by_id(db, context); mosquitto__free(context->id); context->id = NULL; } diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index c3655981..31305841 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -587,6 +587,7 @@ void context__disconnect(struct mosquitto_db *db, struct mosquitto *context); void context__add_to_disused(struct mosquitto_db *db, struct mosquitto *context); void context__free_disused(struct mosquitto_db *db); void context__send_will(struct mosquitto_db *db, struct mosquitto *context); +void context__remove_from_by_id(struct mosquitto_db *db, struct mosquitto *context); /* ============================================================ * Logging functions