From 008dba7e11a467be0f1a9742b8c041a9e9211fd0 Mon Sep 17 00:00:00 2001
From: jomjol <30766535+jomjol@users.noreply.github.com>
Date: Sat, 18 Feb 2023 11:44:56 +0100
Subject: [PATCH] fix for #2036
---
Changelog.md | 2 +-
code/components/jomjol_helper/Helper.cpp | 30 ++++++++++++++++++++++++
code/components/jomjol_helper/Helper.h | 3 +++
code/main/softAP.cpp | 18 +++++++-------
4 files changed, 43 insertions(+), 10 deletions(-)
diff --git a/Changelog.md b/Changelog.md
index 7a22e5c73..775533f88 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -14,7 +14,7 @@
#### Fixed
-- n.a.
+- [2036](https://github.com/jomjol/AI-on-the-edge-device/issues/2036) Initial AP-Mode now decodes the parameters correctly
#### Removed
diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp
index 0b8989caa..23fad5cb9 100644
--- a/code/components/jomjol_helper/Helper.cpp
+++ b/code/components/jomjol_helper/Helper.cpp
@@ -898,3 +898,33 @@ const char* get404(void) {
" You could try your luck here!\n"
""; // Make sure we load the overview page
}
+
+
+std::string UrlDecode(const std::string& value)
+{
+ std::string result;
+ result.reserve(value.size());
+
+ for (std::size_t i = 0; i < value.size(); ++i)
+ {
+ auto ch = value[i];
+
+ if (ch == '%' && (i + 2) < value.size())
+ {
+ auto hex = value.substr(i + 1, 2);
+ auto dec = static_cast(std::strtol(hex.c_str(), nullptr, 16));
+ result.push_back(dec);
+ i += 2;
+ }
+ else if (ch == '+')
+ {
+ result.push_back(' ');
+ }
+ else
+ {
+ result.push_back(ch);
+ }
+ }
+
+ return result;
+}
diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h
index 84171b861..6aac032fa 100644
--- a/code/components/jomjol_helper/Helper.h
+++ b/code/components/jomjol_helper/Helper.h
@@ -93,4 +93,7 @@ std::string getFormatedUptime(bool compact);
const char* get404(void);
+
+std::string UrlDecode(const std::string& value);
+
#endif //HELPER_H
diff --git a/code/main/softAP.cpp b/code/main/softAP.cpp
index 517ec1b8a..5fb716a87 100644
--- a/code/main/softAP.cpp
+++ b/code/main/softAP.cpp
@@ -213,55 +213,55 @@ esp_err_t config_ini_handler(httpd_req_t *req)
if (httpd_query_key_value(_query, "ssid", _valuechar, 30) == ESP_OK)
{
ESP_LOGD(TAG, "ssid is found: %s", _valuechar);
- ssid = std::string(_valuechar);
+ ssid = UrlDecode(std::string(_valuechar));
}
if (httpd_query_key_value(_query, "pwd", _valuechar, 30) == ESP_OK)
{
ESP_LOGD(TAG, "pwd is found: %s", _valuechar);
- pwd = std::string(_valuechar);
+ pwd = UrlDecode(std::string(_valuechar));
}
if (httpd_query_key_value(_query, "ssid", _valuechar, 30) == ESP_OK)
{
ESP_LOGD(TAG, "ssid is found: %s", _valuechar);
- ssid = std::string(_valuechar);
+ ssid = UrlDecode(std::string(_valuechar));
}
if (httpd_query_key_value(_query, "hn", _valuechar, 30) == ESP_OK)
{
ESP_LOGD(TAG, "hostname is found: %s", _valuechar);
- hn = std::string(_valuechar);
+ hn = UrlDecode(std::string(_valuechar));
}
if (httpd_query_key_value(_query, "ip", _valuechar, 30) == ESP_OK)
{
ESP_LOGD(TAG, "ip is found: %s", _valuechar);
- ip = std::string(_valuechar);
+ ip = UrlDecode(std::string(_valuechar));
}
if (httpd_query_key_value(_query, "gw", _valuechar, 30) == ESP_OK)
{
ESP_LOGD(TAG, "gateway is found: %s", _valuechar);
- gw = std::string(_valuechar);
+ gw = UrlDecode(std::string(_valuechar));
}
if (httpd_query_key_value(_query, "nm", _valuechar, 30) == ESP_OK)
{
ESP_LOGD(TAG, "netmask is found: %s", _valuechar);
- nm = std::string(_valuechar);
+ nm = UrlDecode(std::string(_valuechar));
}
if (httpd_query_key_value(_query, "dns", _valuechar, 30) == ESP_OK)
{
ESP_LOGD(TAG, "dns is found: %s", _valuechar);
- dns = std::string(_valuechar);
+ dns = UrlDecode(std::string(_valuechar));
}
if (httpd_query_key_value(_query, "rssi", _valuechar, 30) == ESP_OK)
{
ESP_LOGD(TAG, "rssi is found: %s", _valuechar);
- rssi = std::string(_valuechar);
+ rssi = UrlDecode(std::string(_valuechar));
}
};