Skip to content

Commit

Permalink
fix for #2036
Browse files Browse the repository at this point in the history
  • Loading branch information
jomjol committed Feb 18, 2023
1 parent 7283bfd commit 008dba7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 30 additions & 0 deletions code/components/jomjol_helper/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,3 +898,33 @@ const char* get404(void) {
" You could try your <a href=index.html target=_parent>luck</a> here!</pre>\n"
"<script>document.cookie = \"page=overview.html\"</script>"; // 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<char>(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;
}
3 changes: 3 additions & 0 deletions code/components/jomjol_helper/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,7 @@ std::string getFormatedUptime(bool compact);

const char* get404(void);


std::string UrlDecode(const std::string& value);

#endif //HELPER_H
18 changes: 9 additions & 9 deletions code/main/softAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
};

Expand Down

0 comments on commit 008dba7

Please sign in to comment.