Skip to content

Commit 033c4cf

Browse files
authored
Merge pull request #193 from c-jimenez/fix/config_case_insensitive
[chargepoint] Handle configurations keys name as case insensitive
2 parents db379c0 + 5027159 commit 033c4cf

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

src/chargepoint/ChargePoint.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ void ChargePoint::rcpMessageSent(const std::string& msg)
990990
void ChargePoint::configurationValueChanged(const std::string& key)
991991
{
992992
// Check configuration key
993-
if (key == "AuthorizationKey")
993+
if (key == "authorizationkey")
994994
{
995995
// Reconnect with new authorization key
996996
if (m_ocpp_config.securityProfile() != 3)
@@ -1001,7 +1001,7 @@ void ChargePoint::configurationValueChanged(const std::string& key)
10011001

10021002
m_security_manager.logSecurityEvent(SECEVT_RECONFIG_SECURITY_PARAMETER, "AuthorizationKey");
10031003
}
1004-
else if (key == "SecurityProfile")
1004+
else if (key == "securityprofile")
10051005
{
10061006
// Reconnect with new profile
10071007
LOG_INFO << "SecurityProfile modified, reconnect with new security profile";

src/chargepoint/config/ConfigManager.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ ConfigManager::~ConfigManager() { }
4949
/** @copydoc void registerCheckFunction(const std::string&, ConfigurationValueCheckFunc) */
5050
void ConfigManager::registerCheckFunction(const std::string& key, ConfigurationValueCheckFunc func)
5151
{
52-
m_specific_checks[key] = func;
52+
auto lower_case_key = ocpp::helpers::tolower(key);
53+
m_specific_checks[lower_case_key] = func;
5354
}
5455

5556
/** @copydoc void IConfigManager::registerConfigChangedListener(const std::string&, IConfigChangedListener&) */
5657
void ConfigManager::registerConfigChangedListener(const std::string& key, IConfigChangedListener& listener)
5758
{
58-
m_listeners[key] = &listener;
59+
auto lower_case_key = ocpp::helpers::tolower(key);
60+
m_listeners[lower_case_key] = &listener;
5961
}
6062

6163
/** @copydoc bool GenericMessageHandler<RequestType, ResponseType>::handleMessage(const RequestType& request,
@@ -93,10 +95,11 @@ bool ConfigManager::handleMessage(const ocpp::messages::ChangeConfigurationReq&
9395
response.status = ConfigurationStatus::Accepted;
9496

9597
// Specific check
96-
auto it = m_specific_checks.find(request.key);
98+
auto lower_case_key = ocpp::helpers::tolower(request.key);
99+
auto it = m_specific_checks.find(lower_case_key);
97100
if (it != m_specific_checks.end())
98101
{
99-
response.status = it->second(request.key, request.value);
102+
response.status = it->second(lower_case_key, request.value);
100103
}
101104
if (response.status == ConfigurationStatus::Accepted)
102105
{
@@ -105,10 +108,10 @@ bool ConfigManager::handleMessage(const ocpp::messages::ChangeConfigurationReq&
105108
if (response.status == ConfigurationStatus::Accepted)
106109
{
107110
// Notify change
108-
auto iter = m_listeners.find(request.key);
111+
auto iter = m_listeners.find(lower_case_key);
109112
if (iter != m_listeners.end())
110113
{
111-
iter->second->configurationValueChanged(request.key);
114+
iter->second->configurationValueChanged(lower_case_key);
112115
}
113116
}
114117
}

src/tools/helpers/StringHelpers.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ along with OpenOCPP. If not, see <http://www.gnu.org/licenses/>.
1818

1919
#include "StringHelpers.h"
2020

21+
#include <algorithm>
2122
#include <iomanip>
2223
#include <sstream>
2324

@@ -29,6 +30,14 @@ namespace helpers
2930
/** @brief Space */
3031
const std::string SPACE_STRING = " ";
3132

33+
/** @brief Helper function to convert a string to lowercase */
34+
std::string tolower(const std::string& str)
35+
{
36+
std::string ret = str;
37+
std::transform(ret.begin(), ret.end(), ret.begin(), [](unsigned char c) { return std::tolower(c); });
38+
return ret;
39+
}
40+
3241
/** @brief Helper function to trim a string */
3342
std::string& trim(std::string& str, const std::string& chars)
3443
{

src/tools/helpers/StringHelpers.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ namespace helpers
3131
/** @brief Space */
3232
extern const std::string SPACE_STRING;
3333

34+
/**
35+
* @brief Helper function to convert a string to lowercase
36+
* /!\ Works only on ASCII strings /!\
37+
* @param str String to convert
38+
* @return Reference to the converted string
39+
*/
40+
std::string tolower(const std::string& str);
41+
3442
/**
3543
* @brief Helper function to trim a string
3644
* @param str String to trim

0 commit comments

Comments
 (0)