nss: upgrade to release 3.73
[LibreOffice.git] / xmlsecurity / inc / framework / saxeventkeeperimpl.hxx
blobe3edb857934fb98e5db5ad35e6431ddab16c2cb4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_XMLSECURITY_INC_FRAMEWORK_SAXEVENTKEEPERIMPL_HXX
21 #define INCLUDED_XMLSECURITY_INC_FRAMEWORK_SAXEVENTKEEPERIMPL_HXX
23 #include <com/sun/star/xml/crypto/sax/XSecuritySAXEventKeeper.hpp>
24 #include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp>
25 #include <com/sun/star/xml/crypto/sax/XSAXEventKeeperStatusChangeBroadcaster.hpp>
26 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
27 #include <com/sun/star/lang/XInitialization.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <xmlsecuritydllapi.h>
30 #include <cppuhelper/implbase.hxx>
32 class BufferNode;
33 class ElementMark;
34 class ElementCollector;
36 #include <vector>
37 #include <memory>
39 namespace com::sun::star::xml::crypto::sax { class XSAXEventKeeperStatusChangeListener; }
40 namespace com::sun::star::xml::csax { class XCompressedDocumentHandler; }
41 namespace com::sun::star::xml::wrapper { class XXMLDocumentWrapper; }
43 class SAXEventKeeperImpl final : public cppu::WeakImplHelper
45 css::xml::crypto::sax::XSecuritySAXEventKeeper,
46 css::xml::crypto::sax::XReferenceResolvedBroadcaster,
47 css::xml::crypto::sax::XSAXEventKeeperStatusChangeBroadcaster,
48 css::xml::sax::XDocumentHandler,
49 css::lang::XInitialization,
50 css::lang::XServiceInfo
52 /****** SAXEventKeeperImpl.hxx/CLASS SAXEventKeeperImpl ***********************
54 * NAME
55 * SAXEventKeeperImpl -- SAX events buffer controller
57 * FUNCTION
58 * Controls SAX events to be buffered, and controls buffered SAX events
59 * to be released.
60 ******************************************************************************/
62 private:
64 * the XMLDocumentWrapper component which maintains all buffered SAX
65 * in DOM format.
67 css::uno::Reference< css::xml::wrapper::XXMLDocumentWrapper >
68 m_xXMLDocument;
71 * the document handler provided by the XMLDocumentWrapper component.
73 css::uno::Reference< css::xml::sax::XDocumentHandler > m_xDocumentHandler;
76 * the compressed document handler provided by the XMLDocumentWrapper
77 * component, the handler has more efficient method definition that the
78 * normal document handler.
80 css::uno::Reference< css::xml::csax::XCompressedDocumentHandler >
81 m_xCompressedDocumentHandler;
84 * a listener which receives this SAXEventKeeper's status change
85 * notification.
86 * Based on the status changes, the listener can decide whether the
87 * SAXEventKeeper should chain on/chain off the SAX chain, or whether
88 * the SAXEventKeeper is useless any long.
90 css::uno::Reference< css::xml::crypto::sax::XSAXEventKeeperStatusChangeListener >
91 m_xSAXEventKeeperStatusChangeListener;
94 * the root node of the BufferNode tree.
95 * the BufferNode tree is used to keep track of all buffered elements,
96 * it has the same structure with the document which maintains those
97 * elements physically.
99 std::unique_ptr<BufferNode> m_pRootBufferNode;
102 * the current active BufferNode.
103 * this is used to keep track the current location in the BufferNode tree,
104 * the next generated BufferNode will become a child BufferNode of it.
106 BufferNode* m_pCurrentBufferNode;
109 * the next Id for a coming ElementMark.
110 * the variable is increased by 1 when a new ElementMark is generated,
111 * in this way, we can promise the Id of any ElementMark is unique.
113 sal_Int32 m_nNextElementMarkId;
116 * maintains a collection of all ElementMarks.
118 std::vector<std::unique_ptr<const ElementMark>> m_vElementMarkBuffers;
121 * maintains a list of new ElementCollectors that will be created
122 * on the element represented by the next incoming startElement SAX
123 * event.
124 * The reason that such the m_vNewElementCollectors is necessary
125 * is: when an ElementCollector is asked to create, it can't be
126 * created completely at once, because the BufferNode it will be
127 * working on has not been created until the next startElement
128 * SAX event comes.
130 std::vector< const ElementCollector* > m_vNewElementCollectors;
133 * maintains the new Blocker that will be created
134 * on the element represented by the next incoming startElement SAX
135 * event.
137 ElementMark* m_pNewBlocker;
140 * the document handler to which all received SAX events will be
141 * forwarded.
143 css::uno::Reference< css::xml::sax::XDocumentHandler > m_xNextHandler;
146 * the current BufferNode which prevents the SAX events to be
147 * forwarded to the m_xNextHandler.
149 BufferNode* m_pCurrentBlockingBufferNode;
152 * maintains a list of ElementMark that has been asked to release.
153 * Because during processing a request of releasing an ElementMark,
154 * another releasing ElementMark request can be invoked. To avoid
155 * reentering the same method, a such request only add that ElementMark
156 * into this ElementMark list, then all ElementMarks will be processed in
157 * order.
159 std::vector< sal_Int32 > m_vReleasedElementMarkBuffers;
162 * a flag to indicate whether the ElementMark releasing process is running.
163 * When a releasing request comes, the assigned ElementMark is added to
164 * the m_vReleasedElementMarkBuffers first, then this flag is checked.
165 * If the ElementMark releasing process is not running, then call that
166 * method.
168 bool m_bIsReleasing;
171 * a flag to indicate whether it is the "Forwarding" mode now.
172 * A "Forwarding" mode means that all received SAX events are from the
173 * XMLDocumentWrapper component, instead of up-stream component in the
174 * SAX chain.
175 * The difference between "Forwarding" mode and normal mode is that:
176 * no SAX events need to be transferred to the XMLDocumentWrapper component
177 * again even if a buffer request happens.
179 bool m_bIsForwarding;
181 void setCurrentBufferNode(BufferNode* pBufferNode);
183 BufferNode* addNewElementMarkBuffers();
185 ElementMark* findElementMarkBuffer(sal_Int32 nId) const;
187 void removeElementMarkBuffer(sal_Int32 nId);
189 OUString printBufferNode(
190 BufferNode const * pBufferNode, sal_Int32 nIndent) const;
192 static css::uno::Sequence< css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > >
193 collectChildWorkingElement(BufferNode const * pBufferNode);
195 void smashBufferNode(
196 BufferNode* pBufferNode, bool bClearRoot) const;
198 static BufferNode* findNextBlockingBufferNode(
199 BufferNode* pStartBufferNode);
201 static void diffuse(BufferNode* pBufferNode);
203 void releaseElementMarkBuffer();
205 void markElementMarkBuffer(sal_Int32 nId);
207 sal_Int32 createElementCollector(
208 css::xml::crypto::sax::ElementMarkPriority nPriority,
209 bool bModifyElement,
210 const css::uno::Reference< css::xml::crypto::sax::XReferenceResolvedListener>& xReferenceResolvedListener);
212 sal_Int32 createBlocker();
214 public:
215 SAXEventKeeperImpl();
216 virtual ~SAXEventKeeperImpl() override;
218 SAXEventKeeperImpl(const SAXEventKeeperImpl&) = delete;
219 SAXEventKeeperImpl& operator=(const SAXEventKeeperImpl&) = delete;
221 /* XSAXEventKeeper */
222 virtual sal_Int32 SAL_CALL addElementCollector( ) override;
223 virtual void SAL_CALL removeElementCollector( sal_Int32 id ) override;
224 virtual sal_Int32 SAL_CALL addBlocker( ) override;
225 virtual void SAL_CALL removeBlocker( sal_Int32 id ) override;
226 virtual sal_Bool SAL_CALL isBlocking( ) override;
227 virtual css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > SAL_CALL
228 getElement( sal_Int32 id ) override;
229 virtual void SAL_CALL setElement(
230 sal_Int32 id,
231 const css::uno::Reference< css::xml::wrapper::XXMLElementWrapper >& aElement ) override;
232 virtual css::uno::Reference<
233 css::xml::sax::XDocumentHandler > SAL_CALL
234 setNextHandler( const css::uno::Reference<
235 css::xml::sax::XDocumentHandler >& xNewHandler ) override;
236 virtual OUString SAL_CALL printBufferNodeTree() override;
237 virtual css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > SAL_CALL
238 getCurrentBlockingNode() override;
240 /* XSecuritySAXEventKeeper */
241 virtual sal_Int32 SAL_CALL addSecurityElementCollector(
242 css::xml::crypto::sax::ElementMarkPriority priority,
243 sal_Bool modifyElement ) override;
244 virtual void SAL_CALL setSecurityId( sal_Int32 id, sal_Int32 securityId ) override;
246 /* XReferenceResolvedBroadcaster */
247 virtual void SAL_CALL addReferenceResolvedListener(
248 sal_Int32 referenceId,
249 const css::uno::Reference< css::xml::crypto::sax::XReferenceResolvedListener >& listener ) override;
250 virtual void SAL_CALL removeReferenceResolvedListener(
251 sal_Int32 referenceId,
252 const css::uno::Reference< css::xml::crypto::sax::XReferenceResolvedListener >& listener ) override;
254 /* XSAXEventKeeperStatusChangeBroadcaster */
255 virtual void SAL_CALL addSAXEventKeeperStatusChangeListener(
256 const css::uno::Reference< css::xml::crypto::sax::XSAXEventKeeperStatusChangeListener >& listener ) override;
257 virtual void SAL_CALL removeSAXEventKeeperStatusChangeListener(
258 const css::uno::Reference< css::xml::crypto::sax::XSAXEventKeeperStatusChangeListener >& listener ) override;
260 /* XDocumentHandler */
261 virtual void SAL_CALL startDocument( ) override;
262 virtual void SAL_CALL endDocument( ) override;
263 virtual void SAL_CALL startElement(
264 const OUString& aName,
265 const css::uno::Reference< css::xml::sax::XAttributeList >&
266 xAttribs ) override;
267 virtual void SAL_CALL endElement( const OUString& aName ) override;
268 virtual void SAL_CALL characters( const OUString& aChars ) override;
269 virtual void SAL_CALL ignorableWhitespace( const OUString& aWhitespaces ) override;
270 virtual void SAL_CALL processingInstruction(
271 const OUString& aTarget, const OUString& aData ) override;
272 virtual void SAL_CALL setDocumentLocator(
273 const css::uno::Reference< css::xml::sax::XLocator >& xLocator ) override;
275 /* XInitialization */
276 virtual void SAL_CALL initialize(
277 const css::uno::Sequence< css::uno::Any >& aArguments ) override;
279 /* XServiceInfo */
280 virtual OUString SAL_CALL getImplementationName( ) override;
281 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
282 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
285 /// @throws css::uno::RuntimeException
286 OUString SAXEventKeeperImpl_getImplementationName();
288 /// @throws css::uno::RuntimeException
289 css::uno::Sequence< OUString > SAXEventKeeperImpl_getSupportedServiceNames( );
291 #endif
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */