Change handleSetOwner parameter to const reference and improve long name handling
This commit is contained in:
@@ -620,19 +620,20 @@ void AdminModule::handleGetModuleConfigResponse(const meshtastic_MeshPacket &mp,
|
|||||||
* Setter methods
|
* Setter methods
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void AdminModule::handleSetOwner(meshtastic_User &o)
|
void AdminModule::handleSetOwner(const meshtastic_User &o)
|
||||||
{
|
{
|
||||||
int changed = 0;
|
int changed = 0;
|
||||||
|
|
||||||
// Apps built against the older 39-byte limit may send longer names; clamp
|
|
||||||
// before the changed-compare so re-sending the same long name is a no-op.
|
|
||||||
clampLongName(o.long_name);
|
|
||||||
|
|
||||||
if (*o.long_name) {
|
if (*o.long_name) {
|
||||||
changed |= strcmp(owner.long_name, o.long_name);
|
// Apps built against the older 39-byte limit may send longer names; clamp
|
||||||
strncpy(owner.long_name, o.long_name, sizeof(owner.long_name));
|
// before the changed-compare so re-sending the same long name is a no-op.
|
||||||
|
char longName[sizeof(o.long_name)];
|
||||||
|
strncpy(longName, o.long_name, sizeof(longName));
|
||||||
|
longName[sizeof(longName) - 1] = '\0';
|
||||||
|
clampLongName(longName);
|
||||||
|
changed |= strcmp(owner.long_name, longName);
|
||||||
|
strncpy(owner.long_name, longName, sizeof(owner.long_name));
|
||||||
owner.long_name[sizeof(owner.long_name) - 1] = '\0';
|
owner.long_name[sizeof(owner.long_name) - 1] = '\0';
|
||||||
sanitizeUtf8(owner.long_name, sizeof(owner.long_name));
|
|
||||||
}
|
}
|
||||||
if (*o.short_name) {
|
if (*o.short_name) {
|
||||||
changed |= strcmp(owner.short_name, o.short_name);
|
changed |= strcmp(owner.short_name, o.short_name);
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class AdminModule : public ProtobufModule<meshtastic_AdminMessage>, public Obser
|
|||||||
/**
|
/**
|
||||||
* Setters
|
* Setters
|
||||||
*/
|
*/
|
||||||
void handleSetOwner(meshtastic_User &o);
|
void handleSetOwner(const meshtastic_User &o);
|
||||||
void handleSetChannel(const meshtastic_Channel &cc);
|
void handleSetChannel(const meshtastic_Channel &cc);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
Reference in New Issue
Block a user