diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-02 20:07:17 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-02 22:44:36 +0200 |
commit | f0da01e59ffe1f7f1b5446f111994be6cf6f7d4a (patch) | |
tree | eea592416cf701d1f45b2fe5b2d410f20b7643de /xmlsecurity/source/framework | |
parent | 5ef5c1b294063d1d2d6554d5fcf1d4cfb4d3f06d (diff) |
loplugin:flatten in xmlsecurity
Change-Id: Ic9e410c77a04edbd58485d4177da22e17efa8720
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99964
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmlsecurity/source/framework')
-rw-r--r-- | xmlsecurity/source/framework/buffernode.cxx | 90 | ||||
-rw-r--r-- | xmlsecurity/source/framework/saxeventkeeperimpl.cxx | 229 | ||||
-rw-r--r-- | xmlsecurity/source/framework/signatureengine.cxx | 46 |
3 files changed, 182 insertions, 183 deletions
diff --git a/xmlsecurity/source/framework/buffernode.cxx b/xmlsecurity/source/framework/buffernode.cxx index 0a0a58421dbb..359c4a2f3f44 100644 --- a/xmlsecurity/source/framework/buffernode.cxx +++ b/xmlsecurity/source/framework/buffernode.cxx @@ -666,60 +666,60 @@ void BufferNode::elementCollectorNotify() * BufferNode. ******************************************************************************/ { - if (!m_vElementCollectors.empty()) - { - css::xml::crypto::sax::ElementMarkPriority nMaxPriority = css::xml::crypto::sax::ElementMarkPriority_MINIMUM; - css::xml::crypto::sax::ElementMarkPriority nPriority; + if (m_vElementCollectors.empty()) + return; - /* - * get the max priority among ElementCollectors on this BufferNode - */ - for( const ElementCollector* pElementCollector : m_vElementCollectors ) + css::xml::crypto::sax::ElementMarkPriority nMaxPriority = css::xml::crypto::sax::ElementMarkPriority_MINIMUM; + css::xml::crypto::sax::ElementMarkPriority nPriority; + + /* + * get the max priority among ElementCollectors on this BufferNode + */ + for( const ElementCollector* pElementCollector : m_vElementCollectors ) + { + nPriority = pElementCollector->getPriority(); + if (nPriority > nMaxPriority) { - nPriority = pElementCollector->getPriority(); - if (nPriority > nMaxPriority) - { - nMaxPriority = nPriority; - } + nMaxPriority = nPriority; } + } - std::vector< const ElementCollector* > vElementCollectors( m_vElementCollectors ); + std::vector< const ElementCollector* > vElementCollectors( m_vElementCollectors ); - for( const ElementCollector* ii : vElementCollectors ) - { - ElementCollector* pElementCollector = const_cast<ElementCollector*>(ii); - nPriority = pElementCollector->getPriority(); - bool bToModify = pElementCollector->getModify(); + for( const ElementCollector* ii : vElementCollectors ) + { + ElementCollector* pElementCollector = const_cast<ElementCollector*>(ii); + nPriority = pElementCollector->getPriority(); + bool bToModify = pElementCollector->getModify(); + /* + * Only ElementCollector with the max priority can + * perform notify operation. + * Moreover, if any blocker exists in the subtree of + * this BufferNode, this ElementCollector can't do notify + * unless its priority is BEFOREMODIFY. + */ + if (nPriority == nMaxPriority && + (nPriority == css::xml::crypto::sax::ElementMarkPriority_BEFOREMODIFY || + !isBlockerInSubTreeIncluded(pElementCollector->getSecurityId()))) + { /* - * Only ElementCollector with the max priority can - * perform notify operation. - * Moreover, if any blocker exists in the subtree of - * this BufferNode, this ElementCollector can't do notify - * unless its priority is BEFOREMODIFY. + * If this ElementCollector will modify the buffered element, then + * special attention must be paid. + * + * If there is any ElementCollector in the subtree or any ancestor + * ElementCollector with PRI_BEFPREMODIFY priority, this + * ElementCollector can't perform notify operation, otherwise, it + * will destroy the buffered element, in turn, ElementCollectors + * mentioned above can't perform their mission. */ - if (nPriority == nMaxPriority && - (nPriority == css::xml::crypto::sax::ElementMarkPriority_BEFOREMODIFY || - !isBlockerInSubTreeIncluded(pElementCollector->getSecurityId()))) + //if (!(nMaxPriority == css::xml::crypto::sax::ElementMarkPriority_PRI_MODIFY && + if (!(bToModify && + (isECInSubTreeIncluded(pElementCollector->getSecurityId()) || + isECOfBeforeModifyInAncestorIncluded(pElementCollector->getSecurityId())) + )) { - /* - * If this ElementCollector will modify the buffered element, then - * special attention must be paid. - * - * If there is any ElementCollector in the subtree or any ancestor - * ElementCollector with PRI_BEFPREMODIFY priority, this - * ElementCollector can't perform notify operation, otherwise, it - * will destroy the buffered element, in turn, ElementCollectors - * mentioned above can't perform their mission. - */ - //if (!(nMaxPriority == css::xml::crypto::sax::ElementMarkPriority_PRI_MODIFY && - if (!(bToModify && - (isECInSubTreeIncluded(pElementCollector->getSecurityId()) || - isECOfBeforeModifyInAncestorIncluded(pElementCollector->getSecurityId())) - )) - { - pElementCollector->notifyListener(); - } + pElementCollector->notifyListener(); } } } diff --git a/xmlsecurity/source/framework/saxeventkeeperimpl.cxx b/xmlsecurity/source/framework/saxeventkeeperimpl.cxx index cde39d929959..fee60ce925bd 100644 --- a/xmlsecurity/source/framework/saxeventkeeperimpl.cxx +++ b/xmlsecurity/source/framework/saxeventkeeperimpl.cxx @@ -83,22 +83,22 @@ void SAXEventKeeperImpl::setCurrentBufferNode(BufferNode* pBufferNode) * pBufferNode - a BufferNode which will be the new active BufferNode ******************************************************************************/ { - if (pBufferNode != m_pCurrentBufferNode) - { - if ( m_pCurrentBufferNode == m_pRootBufferNode.get() && - m_xSAXEventKeeperStatusChangeListener.is()) - { - m_xSAXEventKeeperStatusChangeListener->collectionStatusChanged(true); - } + if (pBufferNode == m_pCurrentBufferNode) + return; - if (pBufferNode->getParent() == nullptr) - { - m_pCurrentBufferNode->addChild(std::unique_ptr<BufferNode>(pBufferNode)); - pBufferNode->setParent(m_pCurrentBufferNode); - } + if ( m_pCurrentBufferNode == m_pRootBufferNode.get() && + m_xSAXEventKeeperStatusChangeListener.is()) + { + m_xSAXEventKeeperStatusChangeListener->collectionStatusChanged(true); + } - m_pCurrentBufferNode = pBufferNode; + if (pBufferNode->getParent() == nullptr) + { + m_pCurrentBufferNode->addChild(std::unique_ptr<BufferNode>(pBufferNode)); + pBufferNode->setParent(m_pCurrentBufferNode); } + + m_pCurrentBufferNode = pBufferNode; } BufferNode* SAXEventKeeperImpl::addNewElementMarkBuffers() @@ -389,110 +389,109 @@ void SAXEventKeeperImpl::smashBufferNode( * needed by the Blocker to be deleted. ******************************************************************************/ { - if (!pBufferNode->hasAnything()) + if (pBufferNode->hasAnything()) + return; + + BufferNode* pParent = const_cast<BufferNode*>(pBufferNode->getParent()); + + /* + * delete the XML data + */ + if (pParent == m_pRootBufferNode.get()) { - BufferNode* pParent = const_cast<BufferNode*>(pBufferNode->getParent()); + bool bIsNotBlocking = (m_pCurrentBlockingBufferNode == nullptr); + bool bIsBlockInside = false; + bool bIsBlockingAfterward = false; /* - * delete the XML data + * If this is a blocker, then remove any out-element data + * which caused by blocking. The removal process will stop + * at the next blocker to avoid removing any useful data. */ - if (pParent == m_pRootBufferNode.get()) + if (bClearRoot) { - bool bIsNotBlocking = (m_pCurrentBlockingBufferNode == nullptr); - bool bIsBlockInside = false; - bool bIsBlockingAfterward = false; + css::uno::Sequence< css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > > + aChildElements = collectChildWorkingElement(m_pRootBufferNode.get()); /* - * If this is a blocker, then remove any out-element data - * which caused by blocking. The removal process will stop - * at the next blocker to avoid removing any useful data. + * the clearUselessData only clearup the content in the + * node, not the node itself. */ - if (bClearRoot) - { - css::uno::Sequence< css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > > - aChildElements = collectChildWorkingElement(m_pRootBufferNode.get()); + m_xXMLDocument->clearUselessData(m_pRootBufferNode->getXMLElement(), + aChildElements, + bIsNotBlocking?nullptr: + (m_pCurrentBlockingBufferNode->getXMLElement())); - /* - * the clearUselessData only clearup the content in the - * node, not the node itself. - */ - m_xXMLDocument->clearUselessData(m_pRootBufferNode->getXMLElement(), - aChildElements, - bIsNotBlocking?nullptr: - (m_pCurrentBlockingBufferNode->getXMLElement())); + /* + * remove the node if it is empty, then if its parent is also + * empty, remove it, then if the next parent is also empty, + * remove it,..., until parent become null. + */ + m_xXMLDocument->collapse( m_pRootBufferNode->getXMLElement() ); + } - /* - * remove the node if it is empty, then if its parent is also - * empty, remove it, then if the next parent is also empty, - * remove it,..., until parent become null. - */ - m_xXMLDocument->collapse( m_pRootBufferNode->getXMLElement() ); - } + /* + * if blocking, check the relationship between this BufferNode and + * the current blocking BufferNode. + */ + if ( !bIsNotBlocking ) + { + /* + * the current blocking BufferNode is a descendant of this BufferNode. + */ + bIsBlockInside = (nullptr != pBufferNode->isAncestor(m_pCurrentBlockingBufferNode)); /* - * if blocking, check the relationship between this BufferNode and - * the current blocking BufferNode. + * the current blocking BufferNode locates behind this BufferNode in tree + * order. */ - if ( !bIsNotBlocking ) - { - /* - * the current blocking BufferNode is a descendant of this BufferNode. - */ - bIsBlockInside = (nullptr != pBufferNode->isAncestor(m_pCurrentBlockingBufferNode)); + bIsBlockingAfterward = pBufferNode->isPrevious(m_pCurrentBlockingBufferNode); + } - /* - * the current blocking BufferNode locates behind this BufferNode in tree - * order. - */ - bIsBlockingAfterward = pBufferNode->isPrevious(m_pCurrentBlockingBufferNode); - } + /* + * this BufferNode's working element needs to be deleted only when + * 1. there is no blocking, or + * 2. the current blocking BufferNode is a descendant of this BufferNode, + * (then in the BufferNode's working element, the useless data before the blocking + * element should be deleted.) or + * 3. the current blocking BufferNode is locates behind this BufferNode in tree, + * (then the useless data between the blocking element and the working element + * should be deleted.). + * Otherwise, this working element should not be deleted. + */ + if ( bIsNotBlocking || bIsBlockInside || bIsBlockingAfterward ) + { + css::uno::Sequence< css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > > + aChildElements = collectChildWorkingElement(pBufferNode); /* - * this BufferNode's working element needs to be deleted only when - * 1. there is no blocking, or - * 2. the current blocking BufferNode is a descendant of this BufferNode, - * (then in the BufferNode's working element, the useless data before the blocking - * element should be deleted.) or - * 3. the current blocking BufferNode is locates behind this BufferNode in tree, - * (then the useless data between the blocking element and the working element - * should be deleted.). - * Otherwise, this working element should not be deleted. + * the clearUselessData only clearup the content in the + * node, not the node itself. */ - if ( bIsNotBlocking || bIsBlockInside || bIsBlockingAfterward ) - { - css::uno::Sequence< css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > > - aChildElements = collectChildWorkingElement(pBufferNode); - - /* - * the clearUselessData only clearup the content in the - * node, not the node itself. - */ - m_xXMLDocument->clearUselessData(pBufferNode->getXMLElement(), - aChildElements, - bIsBlockInside?(m_pCurrentBlockingBufferNode->getXMLElement()): - nullptr); + m_xXMLDocument->clearUselessData(pBufferNode->getXMLElement(), + aChildElements, + bIsBlockInside?(m_pCurrentBlockingBufferNode->getXMLElement()): + nullptr); - /* - * remove the node if it is empty, then if its parent is also - * empty, remove it, then if the next parent is also empty, - * remove it,..., until parent become null. - */ - m_xXMLDocument->collapse( pBufferNode->getXMLElement() ); - } + /* + * remove the node if it is empty, then if its parent is also + * empty, remove it, then if the next parent is also empty, + * remove it,..., until parent become null. + */ + m_xXMLDocument->collapse( pBufferNode->getXMLElement() ); } + } - sal_Int32 nIndex = pParent->indexOfChild(pBufferNode); + sal_Int32 nIndex = pParent->indexOfChild(pBufferNode); - std::vector< std::unique_ptr<BufferNode> > vChildren = pBufferNode->releaseChildren(); - pParent->removeChild(pBufferNode); // delete buffernode - - for( auto& i : vChildren ) - { - i->setParent(pParent); - pParent->addChild(std::move(i), nIndex); - nIndex++; - } + std::vector< std::unique_ptr<BufferNode> > vChildren = pBufferNode->releaseChildren(); + pParent->removeChild(pBufferNode); // delete buffernode + for( auto& i : vChildren ) + { + i->setParent(pParent); + pParent->addChild(std::move(i), nIndex); + nIndex++; } } @@ -1072,18 +1071,18 @@ void SAL_CALL SAXEventKeeperImpl::endElement( const OUString& aName ) void SAL_CALL SAXEventKeeperImpl::characters( const OUString& aChars ) { - if (!m_bIsForwarding) + if (m_bIsForwarding) + return; + + if ((m_pCurrentBlockingBufferNode == nullptr) && m_xNextHandler.is()) { - if ((m_pCurrentBlockingBufferNode == nullptr) && m_xNextHandler.is()) - { - m_xNextHandler->characters(aChars); - } + m_xNextHandler->characters(aChars); + } - if ((m_pCurrentBlockingBufferNode != nullptr) || - (m_pCurrentBufferNode != m_pRootBufferNode.get())) - { - m_xCompressedDocumentHandler->compressedCharacters(aChars); - } + if ((m_pCurrentBlockingBufferNode != nullptr) || + (m_pCurrentBufferNode != m_pRootBufferNode.get())) + { + m_xCompressedDocumentHandler->compressedCharacters(aChars); } } @@ -1095,18 +1094,18 @@ void SAL_CALL SAXEventKeeperImpl::ignorableWhitespace( const OUString& aWhitespa void SAL_CALL SAXEventKeeperImpl::processingInstruction( const OUString& aTarget, const OUString& aData ) { - if (!m_bIsForwarding) + if (m_bIsForwarding) + return; + + if ((m_pCurrentBlockingBufferNode == nullptr) && m_xNextHandler.is()) { - if ((m_pCurrentBlockingBufferNode == nullptr) && m_xNextHandler.is()) - { - m_xNextHandler->processingInstruction(aTarget, aData); - } + m_xNextHandler->processingInstruction(aTarget, aData); + } - if ((m_pCurrentBlockingBufferNode != nullptr) || - (m_pCurrentBufferNode != m_pRootBufferNode.get())) - { - m_xCompressedDocumentHandler->compressedProcessingInstruction(aTarget, aData); - } + if ((m_pCurrentBlockingBufferNode != nullptr) || + (m_pCurrentBufferNode != m_pRootBufferNode.get())) + { + m_xCompressedDocumentHandler->compressedProcessingInstruction(aTarget, aData); } } diff --git a/xmlsecurity/source/framework/signatureengine.cxx b/xmlsecurity/source/framework/signatureengine.cxx index 095b2d04d4d7..0390ea7e61c1 100644 --- a/xmlsecurity/source/framework/signatureengine.cxx +++ b/xmlsecurity/source/framework/signatureengine.cxx @@ -86,37 +86,37 @@ void SignatureEngine::tryToPerform( ) * 5. sets the "accomplishment" flag. ******************************************************************************/ { - if (checkReady()) - { - rtl::Reference<XMLSignatureTemplateImpl> xSignatureTemplate = new XMLSignatureTemplateImpl(); + if (!checkReady()) + return; - css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > - xXMLElement = m_xSAXEventKeeper->getElement( m_nIdOfTemplateEC ); + rtl::Reference<XMLSignatureTemplateImpl> xSignatureTemplate = new XMLSignatureTemplateImpl(); - xSignatureTemplate->setTemplate(xXMLElement); + css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > + xXMLElement = m_xSAXEventKeeper->getElement( m_nIdOfTemplateEC ); - for( const auto i : m_vReferenceIds ) - { - xXMLElement = m_xSAXEventKeeper->getElement( i ); - xSignatureTemplate->setTarget(xXMLElement); - } + xSignatureTemplate->setTemplate(xXMLElement); - /* - * set the Uri binding - */ - xSignatureTemplate->setBinding( this ); + for( const auto i : m_vReferenceIds ) + { + xXMLElement = m_xSAXEventKeeper->getElement( i ); + xSignatureTemplate->setTarget(xXMLElement); + } - startEngine(xSignatureTemplate); + /* + * set the Uri binding + */ + xSignatureTemplate->setBinding( this ); - /* - * done - */ - clearUp( ); + startEngine(xSignatureTemplate); - notifyResultListener(); + /* + * done + */ + clearUp( ); - m_bMissionDone = true; - } + notifyResultListener(); + + m_bMissionDone = true; } void SignatureEngine::clearUp( ) const |