[PR #1773] WiFiManagerParameter API Changes #1827

Open
opened 2026-02-28 02:13:08 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/tzapu/WiFiManager/pull/1773
Author: @dmadison
Created: 10/30/2024
Status: 🔄 Open

Base: masterHead: params-api


📝 Commits (7)

  • 0df7c77 Refactor parameter 'length' as 'maxLength'
  • f75dd98 Change param value length function name
  • dd38239 Change param getID to getName
  • b002b03 Add setValueReceived function to params
  • c781390 Remove parameter friendship with WiFiManager
  • 2703370 Add negative check to param max length
  • 246d521 Make param destructor virtual

📊 Changes

4 files changed (+67 additions, -46 deletions)

View changed files

📝 WiFiManager.cpp (+49 -31)
📝 WiFiManager.h (+15 -12)
📝 examples/NonBlocking/AutoConnectNonBlockingwParams/AutoConnectNonBlockingwParams.ino (+1 -1)
📝 keywords.txt (+2 -2)

📄 Description

This PR makes some small API changes to the WiFiManagerParameter class to improve clarity, usability, and encapsulation:

Length to Max Length

  • All length arguments have been changed to maxLength
  • getValueLength() has been changed to getValueMaxLength()

When used as an argument, this refers to the max length of the form and the size of the internal buffer, not the length of the string passed as an argument as expected.

Similarly, the value returned is the max length of the form and the size of the internal buffer, not the length of the value stored.

The internal name (_length) has not been changed to maintain compatibility with user code, as it's exposed as a protected value. This should be changed in the next major version.

ID to Name

  • getID() has been changed to getName()

In HTML forms, names and IDs are two different attributes. Although this value is applied to both, when submitted the form data corresponds to the name, not the ID. This causes confusion if we want the name and ID to differ, since we are currently calling the name the ID internally.

The internal name (_id) has not been changed to maintain compatibility with user code, as it's exposed as a protected value. This should be changed in the next major version.

Value Received Function

  • Created a setValueReceived() function to receive data from the server

Currently the user can set the parameter value and max length via the setValue(const char *defaultValue, int maxLength) function, and in WiFiManager::doParamSave() the server sets the value directly to the buffer pointer using the existing max length.

This function provides a standardized way for the server (and any user code) to set a new value while respecting the existing max length value. This is also virtual, so derived parameter classes can intercept the received value and perform additional logic or sanitization if necessary.

WiFiManager friendship removed

There is no reason for the WiFiManager class to have a friendship with the parameter class. The internal calls have been replaced with the corresponding public functions and the friendship has been removed.

Incidental Bugfixes

  • setValue() now checks if a max length argument is negative
  • WiFiManagerParameter's destructor is now virtual

Although PR contains API changes there should be no breaking changes. The few items marked deprecated should be removed on the next major release.

If this is merged, here are the changes to make on the next major release:

  • WiFiManagerParameter::_length should be refactored to _maxLength
  • WiFiManagerParameter::getValueLength() const should be removed
  • WiFiManagerParameter::_id should be refactored to _name
  • WiFiManagerParameter::getID() const should be removed

This is a reworked version of PR #1772 that will serve as a basis for other WiFiManagerParameter related PRs.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/tzapu/WiFiManager/pull/1773 **Author:** [@dmadison](https://github.com/dmadison) **Created:** 10/30/2024 **Status:** 🔄 Open **Base:** `master` ← **Head:** `params-api` --- ### 📝 Commits (7) - [`0df7c77`](https://github.com/tzapu/WiFiManager/commit/0df7c77b9d813329101b449ff7a8dfbab6ec2e17) Refactor parameter 'length' as 'maxLength' - [`f75dd98`](https://github.com/tzapu/WiFiManager/commit/f75dd98f61032deb17378dc78a9465d7fbf8349e) Change param value length function name - [`dd38239`](https://github.com/tzapu/WiFiManager/commit/dd38239d91a9b9ad895479ea20f6115d523daedb) Change param getID to getName - [`b002b03`](https://github.com/tzapu/WiFiManager/commit/b002b03ea3013a1c2e73e798b217e56dc11a49e9) Add setValueReceived function to params - [`c781390`](https://github.com/tzapu/WiFiManager/commit/c78139047cc866d3e08543b21d701d419cdfc6c4) Remove parameter friendship with WiFiManager - [`2703370`](https://github.com/tzapu/WiFiManager/commit/2703370f4792171aef98c13f91fe868eaeffbb38) Add negative check to param max length - [`246d521`](https://github.com/tzapu/WiFiManager/commit/246d5216a79c1c4b5fa387c91a85ca62f3bb6c1c) Make param destructor virtual ### 📊 Changes **4 files changed** (+67 additions, -46 deletions) <details> <summary>View changed files</summary> 📝 `WiFiManager.cpp` (+49 -31) 📝 `WiFiManager.h` (+15 -12) 📝 `examples/NonBlocking/AutoConnectNonBlockingwParams/AutoConnectNonBlockingwParams.ino` (+1 -1) 📝 `keywords.txt` (+2 -2) </details> ### 📄 Description This PR makes some small API changes to the `WiFiManagerParameter` class to improve clarity, usability, and encapsulation: #### Length to Max Length * All `length` arguments have been changed to `maxLength` * `getValueLength()` has been changed to `getValueMaxLength()` When used as an argument, this refers to the max length of the form and the size of the internal buffer, *not* the length of the string passed as an argument as expected. Similarly, the value returned is the max length of the form and the size of the internal buffer, *not* the length of the value stored. The internal name (`_length`) has not been changed to maintain compatibility with user code, as it's exposed as a protected value. This should be changed in the next major version. #### ID to Name * `getID()` has been changed to `getName()` In HTML forms, names and IDs are two different attributes. Although this value is applied to both, when submitted the form data corresponds to the name, *not* the ID. This causes confusion if we want the name and ID to differ, since we are currently calling the name the ID internally. The internal name (`_id`) has not been changed to maintain compatibility with user code, as it's exposed as a protected value. This should be changed in the next major version. #### Value Received Function * Created a `setValueReceived()` function to receive data from the server Currently the user can set the parameter value and max length via the `setValue(const char *defaultValue, int maxLength)` function, and in `WiFiManager::doParamSave()` the server sets the value directly to the buffer pointer using the existing max length. This function provides a standardized way for the server (and any user code) to set a new value while respecting the existing max length value. This is also virtual, so derived parameter classes can intercept the received value and perform additional logic or sanitization if necessary. #### WiFiManager friendship removed There is no reason for the `WiFiManager` class to have a friendship with the parameter class. The internal calls have been replaced with the corresponding public functions and the friendship has been removed. #### Incidental Bugfixes * `setValue()` now checks if a max length argument is negative * `WiFiManagerParameter`'s destructor is now virtual --- Although PR contains API changes there should be **no breaking changes**. The few items marked deprecated should be removed on the next major release. If this is merged, here are the changes to make on the next major release: * `WiFiManagerParameter::_length` should be refactored to `_maxLength` * `WiFiManagerParameter::getValueLength() const` should be removed * `WiFiManagerParameter::_id` should be refactored to `_name` * `WiFiManagerParameter::getID() const` should be removed This is a reworked version of PR #1772 that will serve as a basis for other `WiFiManagerParameter` related PRs. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1827
No description provided.