Skip to content

Commit

Permalink
Merge pull request #1150 from deXol/develop
Browse files Browse the repository at this point in the history
[BLE] Remove empty service during integrity check, fix #1127
  • Loading branch information
limpkin authored Feb 20, 2023
2 parents 747651d + 5d354e3 commit 1561719
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
43 changes: 41 additions & 2 deletions src/MPDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2993,6 +2993,35 @@ bool MPDevice::removeEmptyParentFromDB(MPNode* parentNodePt, bool isDataParent,
}
}

bool MPDevice::removeEmptyServiceNode()
{
bool return_bool = true;
MPNode* tempNextParentNodePt = nullptr;
QByteArray tempParentAddress = startNode[Common::CRED_ADDR_IDX];
quint32 tempVirtualParentAddress = virtualStartNode[Common::CRED_ADDR_IDX];
/* Loop through the parent nodes */
while ((tempParentAddress != MPNode::EmptyAddress) || (tempParentAddress.isNull() && tempVirtualParentAddress != 0))
{
tempNextParentNodePt = findNodeWithAddressInList(loginNodes, tempParentAddress, tempVirtualParentAddress);
if (!tempNextParentNodePt)
{
break;
}
if (MPNode::EmptyAddress == tempNextParentNodePt->getStartChildAddress())
{
qWarning() << "Parent " << tempNextParentNodePt->getService() << " has no children, erasing.";
MPNode *toDelete = tempNextParentNodePt;
tempParentAddress = tempNextParentNodePt->getNextParentAddress();
tempVirtualParentAddress = tempNextParentNodePt->getNextParentVirtualAddress();
return_bool = !removeEmptyParentFromDB(toDelete, false);
continue;
}
tempParentAddress = tempNextParentNodePt->getNextParentAddress();
tempVirtualParentAddress = tempNextParentNodePt->getNextParentVirtualAddress();
}
return return_bool;
}

bool MPDevice::removeChildFromDB(MPNode* parentNodePt, MPNode* childNodePt, bool deleteEmptyParent, bool deleteFromList, Common::AddressType addrType /*= Common::CRED_ADDR_IDX*/)
{
if (deleteFromList)
Expand Down Expand Up @@ -3161,6 +3190,10 @@ bool MPDevice::checkLoadedNodes(bool checkCredentials, bool checkData, bool repa
/* Tag pointed nodes, also detects DB errors */
if (checkCredentials || checkData)
{
if (checkCredentials && repairAllowed)
{
return_bool &= removeEmptyServiceNode();
}
return_bool &= tagPointedNodes(checkCredentials, checkData, repairAllowed);
}

Expand Down Expand Up @@ -8122,13 +8155,19 @@ void MPDevice::setMMCredentials(const QJsonArray &creds, bool noDelete,
}
}
}
removeChildFromDB(nodeItem, curNode, false, true);
packet_send_needed = true;

if (renamedNode)
{
loginChildNodes.append(renamedNode);
addChildToDB(nodeItem, renamedNode);
removeChildFromDB(nodeItem, curNode, false, true);
}
else
{
//If not renamed node delete empty parent
removeChildFromDB(nodeItem, curNode, true, true);
}
packet_send_needed = true;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/MPDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ private slots:
Common::DataAddressType dataAddrType = Common::DATA_ADDR_IDX);
bool removeEmptyParentFromDB(MPNode* parentNodePt, bool isDataParent, Common::AddressType addrType = Common::CRED_ADDR_IDX,
Common::DataAddressType dataAddrType = Common::DATA_ADDR_IDX);
bool removeEmptyServiceNode();
bool readExportFile(const QByteArray &fileData, QString &errorString);
void readExportNodes(QJsonArray &&nodes, ExportPayloadData id, bool fromMiniToBle = false, bool isData = false);
void readExportDataChildNodes(QJsonArray &&nodes, ExportPayloadData id, bool fromMiniToBle = false);
Expand Down

0 comments on commit 1561719

Please sign in to comment.