From 0e124f8e51ee347c52bb073a2acf130d5ff0c235 Mon Sep 17 00:00:00 2001 From: iranl Date: Sun, 28 Apr 2024 20:01:00 +0200 Subject: [PATCH] Fix authName --- NetworkLock.cpp | 27 +++++++++++++-------------- NetworkLock.h | 7 ++++--- NetworkOpener.cpp | 25 ++++++++++++------------- NetworkOpener.h | 7 ++++--- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/NetworkLock.cpp b/NetworkLock.cpp index a3e2439..6c57ec5 100644 --- a/NetworkLock.cpp +++ b/NetworkLock.cpp @@ -21,8 +21,6 @@ NetworkLock::NetworkLock(Network* network, Preferences* preferences, char* buffe _configTopics.push_back(mqtt_topic_config_auto_lock); _configTopics.push_back(mqtt_topic_config_single_lock); - memset(authName, 0, sizeof(authName)); - _network->registerMqttReceiver(this); } @@ -325,9 +323,9 @@ void NetworkLock::publishKeyTurnerState(const NukiLock::KeyTurnerState& keyTurne } } - json["auth_id"] = authId; - json["auth_name"] = authName; - + json["auth_id"] = _authId; + json["auth_name"] = _authName; + serializeJson(json, _buffer, _bufferSize); publishString(mqtt_topic_lock_json, _buffer); @@ -372,8 +370,9 @@ void NetworkLock::publishAuthorizationInfo(const std::list& { char str[50]; - bool authFound = false; - memset(authName, 0, sizeof(authName)); + _authId = 0; + _authName = ""; + _authFound = false; JsonDocument json; @@ -385,11 +384,11 @@ void NetworkLock::publishAuthorizationInfo(const std::list& break; } --i; - if((log.loggingType == NukiLock::LoggingType::LockAction || log.loggingType == NukiLock::LoggingType::KeypadAction) && ! authFound) + if((log.loggingType == NukiLock::LoggingType::LockAction || log.loggingType == NukiLock::LoggingType::KeypadAction) && ! _authFound) { - authFound = true; - authId = log.authId; - memcpy(authName, log.name, sizeof(log.name)); + _authFound = true; + _authId = log.authId; + _authName = (char*)log.name; } auto entry = json.add(); @@ -462,10 +461,10 @@ void NetworkLock::publishAuthorizationInfo(const std::list& serializeJson(json, _buffer, _bufferSize); publishString(mqtt_topic_lock_log, _buffer); - if(authFound) + if(_authFound) { - publishUInt(mqtt_topic_lock_auth_id, authId); - publishString(mqtt_topic_lock_auth_name, authName); + publishUInt(mqtt_topic_lock_auth_id, _authId); + publishString(mqtt_topic_lock_auth_name, _authName); } } diff --git a/NetworkLock.h b/NetworkLock.h index f259f38..a9bf3f2 100644 --- a/NetworkLock.h +++ b/NetworkLock.h @@ -84,9 +84,10 @@ private: String _keypadCommandCode = ""; uint _keypadCommandId = 0; int _keypadCommandEnabled = 1; - uint8_t _queryCommands = 0; - uint32_t authId = 0; - char authName[33]; + uint8_t _queryCommands = 0; + uint32_t _authId = 0; + String _authName = ""; + bool _authFound = false; char* _buffer; size_t _bufferSize; diff --git a/NetworkOpener.cpp b/NetworkOpener.cpp index a0d1d0a..c55cc04 100644 --- a/NetworkOpener.cpp +++ b/NetworkOpener.cpp @@ -17,8 +17,6 @@ NetworkOpener::NetworkOpener(Network* network, Preferences* preferences, char* b _configTopics.push_back(mqtt_topic_config_led_enabled); _configTopics.push_back(mqtt_topic_config_sound_level); - memset(authName, 0, sizeof(authName)); - _network->registerMqttReceiver(this); } @@ -297,8 +295,8 @@ void NetworkOpener::publishKeyTurnerState(const NukiOpener::OpenerState& keyTurn publishBool(mqtt_topic_battery_critical, critical); } - json["auth_id"] = authId; - json["auth_name"] = authName; + json["auth_id"] = _authId; + json["auth_name"] = _authName; serializeJson(json, _buffer, _bufferSize); publishString(mqtt_topic_lock_json, _buffer); @@ -359,8 +357,9 @@ void NetworkOpener::publishAuthorizationInfo(const std::list