diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-07-20 18:27:48 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-07-21 08:51:13 +0200 |
commit | 3c6b2b734a00f4844e0bfd5707d14fd4a3d279b0 (patch) | |
tree | 40f521e74e3091e2c1115d0961a0308e509bab8c /xmlsecurity | |
parent | 3284309f19bc76f1778988c5314a795a95620e71 (diff) |
loplugin:referencecasting in xmlsecurity
Change-Id: Ic3daba9e6e94516ea4d80f25f73e9e46a50edb5c
Reviewed-on: https://gerrit.libreoffice.org/76035
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmlsecurity')
6 files changed, 23 insertions, 42 deletions
diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx index 19d233063ad7..e316a4dc7ef9 100644 --- a/xmlsecurity/qa/unit/signing/signing.cxx +++ b/xmlsecurity/qa/unit/signing/signing.cxx @@ -493,13 +493,11 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testOOXMLRemoveAll) // Make sure that the signature count is zero and the whole signature storage is removed completely. CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(0), rInformations.size()); - uno::Reference<container::XNameAccess> xNameAccess(xStorage, uno::UNO_QUERY); - CPPUNIT_ASSERT(!xNameAccess->hasByName("_xmlsignatures")); + CPPUNIT_ASSERT(!xStorage->hasByName("_xmlsignatures")); // And that content types no longer contains signature types. - uno::Reference<io::XStream> xStream( - xStorage->openStreamElement("[Content_Types].xml", embed::ElementModes::READWRITE), - uno::UNO_QUERY); + uno::Reference<io::XStream> xStream + = xStorage->openStreamElement("[Content_Types].xml", embed::ElementModes::READWRITE); uno::Reference<io::XInputStream> xInputStream = xStream->getInputStream(); uno::Sequence<uno::Sequence<beans::StringPair>> aContentTypeInfo = comphelper::OFOPXMLHelper::ReadContentTypeSequence(xInputStream, mxComponentContext); diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx index 03dcaca782e9..c2568eba803b 100644 --- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx +++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx @@ -227,7 +227,7 @@ bool DigitalSignaturesDialog::canAddRemove() //'canAdd' and 'canRemove' case bool ret = true; - uno::Reference<container::XNameAccess> xNameAccess(maSignatureManager.getStore(), uno::UNO_QUERY); + uno::Reference<container::XNameAccess> xNameAccess = maSignatureManager.getStore(); if (xNameAccess.is() && xNameAccess->hasByName("[Content_Types].xml")) // It's always possible to append an OOXML signature. return ret; diff --git a/xmlsecurity/source/helper/documentsignaturehelper.cxx b/xmlsecurity/source/helper/documentsignaturehelper.cxx index 37faa606c32f..6e173afdebff 100644 --- a/xmlsecurity/source/helper/documentsignaturehelper.cxx +++ b/xmlsecurity/source/helper/documentsignaturehelper.cxx @@ -86,8 +86,7 @@ static void ImplFillElementList( const OUString& rRootStorageName, const bool bRecursive, const DocumentSignatureAlgorithm mode) { - Reference < css::container::XNameAccess > xElements( rxStore, UNO_QUERY ); - Sequence< OUString > aElements = xElements->getElementNames(); + Sequence< OUString > aElements = rxStore->getElementNames(); for ( const auto& rName : aElements ) { @@ -214,8 +213,7 @@ DocumentSignatureHelper::CreateElementList( xSubStore.clear(); // Object folders... - Reference < css::container::XNameAccess > xElements( rxStore, UNO_QUERY ); - Sequence< OUString > aElementNames = xElements->getElementNames(); + Sequence< OUString > aElementNames = rxStore->getElementNames(); for ( const auto& rName : aElementNames ) { if ( ( rName.match( "Object " ) ) && rxStore->isStorageElement( rName ) ) @@ -288,8 +286,7 @@ DocumentSignatureHelper::CreateElementList( void DocumentSignatureHelper::AppendContentTypes(const uno::Reference<embed::XStorage>& xStorage, std::vector<OUString>& rElements) { - uno::Reference<container::XNameAccess> xNameAccess(xStorage, uno::UNO_QUERY); - if (!xNameAccess.is() || !xNameAccess->hasByName("[Content_Types].xml")) + if (!xStorage.is() || !xStorage->hasByName("[Content_Types].xml")) // ODF return; @@ -341,11 +338,10 @@ SignatureStreamHelper DocumentSignatureHelper::OpenSignatureStream( SignatureStreamHelper aHelper; - uno::Reference<container::XNameAccess> xNameAccess(rxStore, uno::UNO_QUERY); - if (!xNameAccess.is()) + if (!rxStore.is()) return aHelper; - if (xNameAccess->hasByName("META-INF")) + if (rxStore->hasByName("META-INF")) { try { @@ -369,11 +365,11 @@ SignatureStreamHelper DocumentSignatureHelper::OpenSignatureStream( SAL_WARN_IF( nOpenMode != css::embed::ElementModes::READ, "xmlsecurity.helper", "Error creating signature stream..." ); } } - else if(xNameAccess->hasByName("[Content_Types].xml")) + else if(rxStore->hasByName("[Content_Types].xml")) { try { - if (xNameAccess->hasByName("_xmlsignatures") && (nOpenMode & embed::ElementModes::TRUNCATE)) + if (rxStore->hasByName("_xmlsignatures") && (nOpenMode & embed::ElementModes::TRUNCATE)) // Truncate, then all signatures will be written -> remove previous ones. rxStore->removeElement("_xmlsignatures"); @@ -394,11 +390,10 @@ bool DocumentSignatureHelper::CanSignWithGPG( const Reference < css::embed::XStorage >& rxStore, const OUString& sOdfVersion) { - uno::Reference<container::XNameAccess> xNameAccess(rxStore, uno::UNO_QUERY); - if (!xNameAccess.is()) + if (!rxStore.is()) return false; - if (xNameAccess->hasByName("META-INF")) // ODF + if (rxStore->hasByName("META-INF")) // ODF { return !isODFPre_1_2(sOdfVersion); } diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx index 37f1baf10921..557557f6bae8 100644 --- a/xmlsecurity/source/helper/documentsignaturemanager.cxx +++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx @@ -145,11 +145,7 @@ bool DocumentSignatureManager::readManifest() uno::Reference<packages::manifest::XManifestReader> xReader = packages::manifest::ManifestReader::create(mxContext); - uno::Reference<container::XNameAccess> xNameAccess(mxStore, uno::UNO_QUERY); - if (!xNameAccess.is()) - return false; - - if (xNameAccess->hasByName("META-INF")) + if (mxStore->hasByName("META-INF")) { //Get the manifest.xml uno::Reference<embed::XStorage> xSubStore( @@ -231,12 +227,8 @@ SignatureStreamHelper DocumentSignatureManager::ImplOpenSignatureStream(sal_Int3 bool bTempStream) { SignatureStreamHelper aHelper; - if (mxStore.is()) - { - uno::Reference<container::XNameAccess> xNameAccess(mxStore, uno::UNO_QUERY); - if (xNameAccess.is() && xNameAccess->hasByName("[Content_Types].xml")) - aHelper.nStorageFormat = embed::StorageFormats::OFOPXML; - } + if (mxStore.is() && mxStore->hasByName("[Content_Types].xml")) + aHelper.nStorageFormat = embed::StorageFormats::OFOPXML; if (bTempStream) { diff --git a/xmlsecurity/source/helper/xmlsignaturehelper.cxx b/xmlsecurity/source/helper/xmlsignaturehelper.cxx index 0bc850b9af4f..6ec834053a17 100644 --- a/xmlsecurity/source/helper/xmlsignaturehelper.cxx +++ b/xmlsecurity/source/helper/xmlsignaturehelper.cxx @@ -230,8 +230,7 @@ void XMLSignatureHelper::ExportOOXMLSignature(const uno::Reference<embed::XStora xSaxWriter->setOutputStream(xOutputStream); xSaxWriter->startDocument(); - uno::Reference<xml::sax::XDocumentHandler> xDocumentHandler(xSaxWriter, uno::UNO_QUERY); - mpXSecController->exportOOXMLSignature(xRootStorage, xDocumentHandler, rInformation); + mpXSecController->exportOOXMLSignature(xRootStorage, xSaxWriter, rInformation); xSaxWriter->endDocument(); } @@ -318,8 +317,7 @@ bool lcl_isSignatureOriginType(const beans::StringPair& rPair) bool XMLSignatureHelper::ReadAndVerifySignatureStorage(const uno::Reference<embed::XStorage>& xStorage, bool bCacheLastSignature) { sal_Int32 nOpenMode = embed::ElementModes::READ; - uno::Reference<container::XNameAccess> xNameAccess(xStorage, uno::UNO_QUERY); - if (xNameAccess.is() && !xNameAccess->hasByName("_rels")) + if (xStorage.is() && !xStorage->hasByName("_rels")) { SAL_WARN("xmlsecurity.helper", "expected stream, in signature storage but not found: _rels"); return false; @@ -338,7 +336,7 @@ bool XMLSignatureHelper::ReadAndVerifySignatureStorage(const uno::Reference<embe std::vector<beans::StringPair>::iterator it = std::find_if(aRelation.begin(), aRelation.end(), [](const beans::StringPair& rPair) { return rPair.First == "Target"; }); if (it != aRelation.end()) { - if (xNameAccess.is() && !xNameAccess->hasByName(it->Second)) + if (xStorage.is() && !xStorage->hasByName(it->Second)) { SAL_WARN("xmlsecurity.helper", "expected stream, but not found: " << it->Second); continue; @@ -477,7 +475,7 @@ void XMLSignatureHelper::ExportSignatureRelations(const css::uno::Reference<css: xOriginStream->closeOutput(); // Write the relations. - uno::Reference<embed::XStorage> xSubStorage(xStorage->openStorageElement("_rels", nOpenMode), uno::UNO_QUERY); + uno::Reference<embed::XStorage> xSubStorage = xStorage->openStorageElement("_rels", nOpenMode); uno::Reference<io::XOutputStream> xRelStream(xSubStorage->openStreamElement("origin.sigs.rels", nOpenMode), uno::UNO_QUERY); std::vector< uno::Sequence<beans::StringPair> > aRelations; for (int i = 0; i < nSignatureCount; ++i) @@ -495,7 +493,7 @@ void XMLSignatureHelper::ExportSignatureRelations(const css::uno::Reference<css: void XMLSignatureHelper::ExportSignatureContentTypes(const css::uno::Reference<css::embed::XStorage>& xStorage, int nSignatureCount) { - uno::Reference<io::XStream> xStream(xStorage->openStreamElement("[Content_Types].xml", embed::ElementModes::READWRITE), uno::UNO_QUERY); + uno::Reference<io::XStream> xStream = xStorage->openStreamElement("[Content_Types].xml", embed::ElementModes::READWRITE); uno::Reference<io::XInputStream> xInputStream = xStream->getInputStream(); uno::Sequence< uno::Sequence<beans::StringPair> > aContentTypeInfo = comphelper::OFOPXMLHelper::ReadContentTypeSequence(xInputStream, mxCtx); if (aContentTypeInfo.getLength() < 2) @@ -542,8 +540,7 @@ void XMLSignatureHelper::CreateAndWriteOOXMLSignature(const uno::Reference<embed xSaxWriter->startDocument(); mbError = false; - uno::Reference<xml::sax::XDocumentHandler> xDocumentHandler(xSaxWriter, uno::UNO_QUERY); - if (!mpXSecController->WriteOOXMLSignature(xRootStorage, xDocumentHandler)) + if (!mpXSecController->WriteOOXMLSignature(xRootStorage, xSaxWriter)) mbError = true; xSaxWriter->endDocument(); diff --git a/xmlsecurity/source/helper/xmlsignaturehelper2.cxx b/xmlsecurity/source/helper/xmlsignaturehelper2.cxx index 3e5d01b44861..f733f3a6a4c1 100644 --- a/xmlsecurity/source/helper/xmlsignaturehelper2.cxx +++ b/xmlsecurity/source/helper/xmlsignaturehelper2.cxx @@ -88,8 +88,7 @@ uno::Reference < io::XInputStream > UriBindingHelper::OpenInputStream( const uno throw uno::Exception("Could not decode URI for stream element.", nullptr); uno::Reference< io::XStream > xStream; - uno::Reference<container::XNameAccess> xNameAccess(rxStore, uno::UNO_QUERY); - if (!xNameAccess->hasByName(sName)) + if (!rxStore->hasByName(sName)) SAL_WARN("xmlsecurity.helper", "expected stream, but not found: " << sName); else xStream = rxStore->cloneStreamElement( sName ); |