LibreOffice Module xmlsecurity (master) 1
saxeventkeeperimpl.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include <com/sun/star/xml/crypto/sax/XSecuritySAXEventKeeper.hpp>
23#include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp>
24#include <com/sun/star/xml/crypto/sax/XSAXEventKeeperStatusChangeBroadcaster.hpp>
25#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
26#include <com/sun/star/lang/XInitialization.hpp>
27#include <com/sun/star/lang/XServiceInfo.hpp>
28#include <xmlsecuritydllapi.h>
30#include <vector>
31#include <memory>
32
33class BufferNode;
34class ElementMark;
36namespace com::sun::star::xml::crypto::sax { class XSAXEventKeeperStatusChangeListener; }
37namespace com::sun::star::xml::csax { class XCompressedDocumentHandler; }
38namespace com::sun::star::xml::wrapper { class XXMLDocumentWrapper; }
39
40
41class SAXEventKeeperImpl final : public cppu::WeakImplHelper
42<
43 css::xml::crypto::sax::XSecuritySAXEventKeeper,
44 css::xml::crypto::sax::XReferenceResolvedBroadcaster,
45 css::xml::crypto::sax::XSAXEventKeeperStatusChangeBroadcaster,
46 css::xml::sax::XDocumentHandler,
47 css::lang::XInitialization,
48 css::lang::XServiceInfo
49>
50/****** SAXEventKeeperImpl.hxx/CLASS SAXEventKeeperImpl ***********************
51 *
52 * NAME
53 * SAXEventKeeperImpl -- SAX events buffer controller
54 *
55 * FUNCTION
56 * Controls SAX events to be buffered, and controls buffered SAX events
57 * to be released.
58 ******************************************************************************/
59{
60private:
61 /*
62 * the XMLDocumentWrapper component which maintains all buffered SAX
63 * in DOM format.
64 */
65 css::uno::Reference< css::xml::wrapper::XXMLDocumentWrapper >
67
68 /*
69 * the document handler provided by the XMLDocumentWrapper component.
70 */
71 css::uno::Reference< css::xml::sax::XDocumentHandler > m_xDocumentHandler;
72
73 /*
74 * the compressed document handler provided by the XMLDocumentWrapper
75 * component, the handler has more efficient method definition that the
76 * normal document handler.
77 */
78 css::uno::Reference< css::xml::csax::XCompressedDocumentHandler >
80
81 /*
82 * a listener which receives this SAXEventKeeper's status change
83 * notification.
84 * Based on the status changes, the listener can decide whether the
85 * SAXEventKeeper should chain on/chain off the SAX chain, or whether
86 * the SAXEventKeeper is useless any long.
87 */
88 css::uno::Reference< css::xml::crypto::sax::XSAXEventKeeperStatusChangeListener >
90
91 /*
92 * the root node of the BufferNode tree.
93 * the BufferNode tree is used to keep track of all buffered elements,
94 * it has the same structure with the document which maintains those
95 * elements physically.
96 */
97 std::unique_ptr<BufferNode> m_pRootBufferNode;
98
99 /*
100 * the current active BufferNode.
101 * this is used to keep track the current location in the BufferNode tree,
102 * the next generated BufferNode will become a child BufferNode of it.
103 */
105
106 /*
107 * the next Id for a coming ElementMark.
108 * the variable is increased by 1 when a new ElementMark is generated,
109 * in this way, we can promise the Id of any ElementMark is unique.
110 */
112
113 /*
114 * maintains a collection of all ElementMarks.
115 */
116 std::vector<std::unique_ptr<const ElementMark>> m_vElementMarkBuffers;
117
118 /*
119 * maintains a list of new ElementCollectors that will be created
120 * on the element represented by the next incoming startElement SAX
121 * event.
122 * The reason that such the m_vNewElementCollectors is necessary
123 * is: when an ElementCollector is asked to create, it can't be
124 * created completely at once, because the BufferNode it will be
125 * working on has not been created until the next startElement
126 * SAX event comes.
127 */
128 std::vector< const ElementCollector* > m_vNewElementCollectors;
129
130 /*
131 * maintains the new Blocker that will be created
132 * on the element represented by the next incoming startElement SAX
133 * event.
134 */
136
137 /*
138 * the document handler to which all received SAX events will be
139 * forwarded.
140 */
141 css::uno::Reference< css::xml::sax::XDocumentHandler > m_xNextHandler;
142
143 /*
144 * the current BufferNode which prevents the SAX events to be
145 * forwarded to the m_xNextHandler.
146 */
148
149 /*
150 * maintains a list of ElementMark that has been asked to release.
151 * Because during processing a request of releasing an ElementMark,
152 * another releasing ElementMark request can be invoked. To avoid
153 * reentering the same method, a such request only add that ElementMark
154 * into this ElementMark list, then all ElementMarks will be processed in
155 * order.
156 */
157 std::vector< sal_Int32 > m_vReleasedElementMarkBuffers;
158
159 /*
160 * a flag to indicate whether the ElementMark releasing process is running.
161 * When a releasing request comes, the assigned ElementMark is added to
162 * the m_vReleasedElementMarkBuffers first, then this flag is checked.
163 * If the ElementMark releasing process is not running, then call that
164 * method.
165 */
167
168 /*
169 * a flag to indicate whether it is the "Forwarding" mode now.
170 * A "Forwarding" mode means that all received SAX events are from the
171 * XMLDocumentWrapper component, instead of up-stream component in the
172 * SAX chain.
173 * The difference between "Forwarding" mode and normal mode is that:
174 * no SAX events need to be transferred to the XMLDocumentWrapper component
175 * again even if a buffer request happens.
176 */
178
179 void setCurrentBufferNode(BufferNode* pBufferNode);
180
182
183 ElementMark* findElementMarkBuffer(sal_Int32 nId) const;
184
185 void removeElementMarkBuffer(sal_Int32 nId);
186
187 OUString printBufferNode(
188 BufferNode const * pBufferNode, sal_Int32 nIndent) const;
189
190 static css::uno::Sequence< css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > >
191 collectChildWorkingElement(BufferNode const * pBufferNode);
192
193 void smashBufferNode(
194 BufferNode* pBufferNode, bool bClearRoot) const;
195
197 BufferNode* pStartBufferNode);
198
199 static void diffuse(BufferNode* pBufferNode);
200
202
203 void markElementMarkBuffer(sal_Int32 nId);
204
205 sal_Int32 createElementCollector(
206 css::xml::crypto::sax::ElementMarkPriority nPriority,
207 bool bModifyElement,
208 const css::uno::Reference< css::xml::crypto::sax::XReferenceResolvedListener>& xReferenceResolvedListener);
209
210 sal_Int32 createBlocker();
211
212public:
214 virtual ~SAXEventKeeperImpl() override;
215
218
219 /* XSAXEventKeeper */
220 virtual sal_Int32 SAL_CALL addElementCollector( ) override;
221 virtual void SAL_CALL removeElementCollector( sal_Int32 id ) override;
222 virtual sal_Int32 SAL_CALL addBlocker( ) override;
223 virtual void SAL_CALL removeBlocker( sal_Int32 id ) override;
224 virtual sal_Bool SAL_CALL isBlocking( ) override;
225 virtual css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > SAL_CALL
226 getElement( sal_Int32 id ) override;
227 virtual void SAL_CALL setElement(
228 sal_Int32 id,
229 const css::uno::Reference< css::xml::wrapper::XXMLElementWrapper >& aElement ) override;
230 virtual css::uno::Reference<
231 css::xml::sax::XDocumentHandler > SAL_CALL
232 setNextHandler( const css::uno::Reference<
233 css::xml::sax::XDocumentHandler >& xNewHandler ) override;
234 virtual OUString SAL_CALL printBufferNodeTree() override;
235 virtual css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > SAL_CALL
236 getCurrentBlockingNode() override;
237
238 /* XSecuritySAXEventKeeper */
239 virtual sal_Int32 SAL_CALL addSecurityElementCollector(
240 css::xml::crypto::sax::ElementMarkPriority priority,
241 sal_Bool modifyElement ) override;
242 virtual void SAL_CALL setSecurityId( sal_Int32 id, sal_Int32 securityId ) override;
243
244 /* XReferenceResolvedBroadcaster */
245 virtual void SAL_CALL addReferenceResolvedListener(
246 sal_Int32 referenceId,
247 const css::uno::Reference< css::xml::crypto::sax::XReferenceResolvedListener >& listener ) override;
248 virtual void SAL_CALL removeReferenceResolvedListener(
249 sal_Int32 referenceId,
250 const css::uno::Reference< css::xml::crypto::sax::XReferenceResolvedListener >& listener ) override;
251
252 /* XSAXEventKeeperStatusChangeBroadcaster */
253 virtual void SAL_CALL addSAXEventKeeperStatusChangeListener(
254 const css::uno::Reference< css::xml::crypto::sax::XSAXEventKeeperStatusChangeListener >& listener ) override;
255 virtual void SAL_CALL removeSAXEventKeeperStatusChangeListener(
256 const css::uno::Reference< css::xml::crypto::sax::XSAXEventKeeperStatusChangeListener >& listener ) override;
257
258 /* XDocumentHandler */
259 virtual void SAL_CALL startDocument( ) override;
260 virtual void SAL_CALL endDocument( ) override;
261 virtual void SAL_CALL startElement(
262 const OUString& aName,
263 const css::uno::Reference< css::xml::sax::XAttributeList >&
264 xAttribs ) override;
265 virtual void SAL_CALL endElement( const OUString& aName ) override;
266 virtual void SAL_CALL characters( const OUString& aChars ) override;
267 virtual void SAL_CALL ignorableWhitespace( const OUString& aWhitespaces ) override;
268 virtual void SAL_CALL processingInstruction(
269 const OUString& aTarget, const OUString& aData ) override;
270 virtual void SAL_CALL setDocumentLocator(
271 const css::uno::Reference< css::xml::sax::XLocator >& xLocator ) override;
272
273 /* XInitialization */
274 virtual void SAL_CALL initialize(
275 const css::uno::Sequence< css::uno::Any >& aArguments ) override;
276
277 /* XServiceInfo */
278 virtual OUString SAL_CALL getImplementationName( ) override;
279 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
280 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
281};
282
285
287css::uno::Sequence< OUString > SAXEventKeeperImpl_getSupportedServiceNames( );
288
289
290/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAXEventKeeperImpl & operator=(const SAXEventKeeperImpl &)=delete
OUString printBufferNode(BufferNode const *pBufferNode, sal_Int32 nIndent) const
std::vector< const ElementCollector * > m_vNewElementCollectors
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void SAL_CALL removeSAXEventKeeperStatusChangeListener(const css::uno::Reference< css::xml::crypto::sax::XSAXEventKeeperStatusChangeListener > &listener) override
virtual void SAL_CALL addSAXEventKeeperStatusChangeListener(const css::uno::Reference< css::xml::crypto::sax::XSAXEventKeeperStatusChangeListener > &listener) override
virtual void SAL_CALL setElement(sal_Int32 id, const css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > &aElement) override
virtual void SAL_CALL setSecurityId(sal_Int32 id, sal_Int32 securityId) override
virtual void SAL_CALL removeBlocker(sal_Int32 id) override
virtual void SAL_CALL endDocument() override
virtual void SAL_CALL removeElementCollector(sal_Int32 id) override
virtual OUString SAL_CALL getImplementationName() override
css::uno::Reference< css::xml::sax::XDocumentHandler > m_xDocumentHandler
BufferNode * m_pCurrentBufferNode
virtual void SAL_CALL processingInstruction(const OUString &aTarget, const OUString &aData) override
virtual sal_Int32 SAL_CALL addBlocker() override
virtual void SAL_CALL startElement(const OUString &aName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttribs) override
virtual void SAL_CALL addReferenceResolvedListener(sal_Int32 referenceId, const css::uno::Reference< css::xml::crypto::sax::XReferenceResolvedListener > &listener) override
virtual css::uno::Reference< css::xml::sax::XDocumentHandler > SAL_CALL setNextHandler(const css::uno::Reference< css::xml::sax::XDocumentHandler > &xNewHandler) override
css::uno::Reference< css::xml::wrapper::XXMLDocumentWrapper > m_xXMLDocument
virtual css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > SAL_CALL getCurrentBlockingNode() override
void setCurrentBufferNode(BufferNode *pBufferNode)
sal_Int32 createElementCollector(css::xml::crypto::sax::ElementMarkPriority nPriority, bool bModifyElement, const css::uno::Reference< css::xml::crypto::sax::XReferenceResolvedListener > &xReferenceResolvedListener)
virtual sal_Int32 SAL_CALL addElementCollector() override
virtual void SAL_CALL startDocument() override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
ElementMark * findElementMarkBuffer(sal_Int32 nId) const
static css::uno::Sequence< css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > > collectChildWorkingElement(BufferNode const *pBufferNode)
virtual void SAL_CALL ignorableWhitespace(const OUString &aWhitespaces) override
std::vector< sal_Int32 > m_vReleasedElementMarkBuffers
BufferNode * addNewElementMarkBuffers()
css::uno::Reference< css::xml::sax::XDocumentHandler > m_xNextHandler
void smashBufferNode(BufferNode *pBufferNode, bool bClearRoot) const
virtual void SAL_CALL removeReferenceResolvedListener(sal_Int32 referenceId, const css::uno::Reference< css::xml::crypto::sax::XReferenceResolvedListener > &listener) override
SAXEventKeeperImpl(const SAXEventKeeperImpl &)=delete
virtual sal_Int32 SAL_CALL addSecurityElementCollector(css::xml::crypto::sax::ElementMarkPriority priority, sal_Bool modifyElement) override
css::uno::Reference< css::xml::crypto::sax::XSAXEventKeeperStatusChangeListener > m_xSAXEventKeeperStatusChangeListener
void removeElementMarkBuffer(sal_Int32 nId)
virtual OUString SAL_CALL printBufferNodeTree() override
std::unique_ptr< BufferNode > m_pRootBufferNode
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator > &xLocator) override
static BufferNode * findNextBlockingBufferNode(BufferNode *pStartBufferNode)
virtual void SAL_CALL endElement(const OUString &aName) override
virtual ~SAXEventKeeperImpl() override
virtual css::uno::Reference< css::xml::wrapper::XXMLElementWrapper > SAL_CALL getElement(sal_Int32 id) override
css::uno::Reference< css::xml::csax::XCompressedDocumentHandler > m_xCompressedDocumentHandler
virtual void SAL_CALL characters(const OUString &aChars) override
BufferNode * m_pCurrentBlockingBufferNode
virtual sal_Bool SAL_CALL isBlocking() override
static void diffuse(BufferNode *pBufferNode)
void markElementMarkBuffer(sal_Int32 nId)
std::vector< std::unique_ptr< const ElementMark > > m_vElementMarkBuffers
css::uno::Sequence< OUString > SAXEventKeeperImpl_getSupportedServiceNames()
OUString SAXEventKeeperImpl_getImplementationName()
unsigned char sal_Bool