summaryrefslogtreecommitdiffstats
path: root/xmlsecurity/source/framework/buffernode.cxx
blob: 0a0a58421dbb601193d1c3fb2a5449995440d144 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */


#include "elementmark.hxx"
#include "elementcollector.hxx"
#include "buffernode.hxx"
#include <com/sun/star/xml/crypto/sax/ConstOfSecurityId.hpp>
#include <osl/diagnose.h>
#include <rtl/ustrbuf.hxx>

BufferNode::BufferNode( const css::uno::Reference< css::xml::wrapper::XXMLElementWrapper >& xXMLElement )
    :m_pParent(nullptr),
     m_pBlocker(nullptr),
     m_bAllReceived(false),
     m_xXMLElement(xXMLElement)
{
}

bool BufferNode::isECOfBeforeModifyIncluded(sal_Int32 nIgnoredSecurityId) const
/****** BufferNode/isECOfBeforeModifyIncluded ********************************
 *
 *   NAME
 *  isECOfBeforeModifyIncluded -- checks whether there is some
 *  ElementCollector on this BufferNode, that has BEFORE-MODIFY priority.
 *
 *   SYNOPSIS
 *  bExist = isECOfBeforeModifyIncluded(nIgnoredSecurityId);
 *
 *   FUNCTION
 *  checks each ElementCollector on this BufferNode, if all following
 *  conditions are satisfied, then returns true:
 *  1. the ElementCollector's priority is BEFOREMODIFY;
 *  2. the ElementCollector's securityId can't be ignored.
 *  otherwise, returns false.
 *
 *   INPUTS
 *  nIgnoredSecurityId -    the security Id to be ignored. If it equals
 *                          to UNDEFINEDSECURITYID, then no security Id
 *                          will be ignored.
 *
 *   RESULT
 *  bExist - true if a match found, false otherwise
 ******************************************************************************/
{
    return std::any_of(m_vElementCollectors.cbegin(), m_vElementCollectors.cend(),
        [nIgnoredSecurityId](const ElementCollector* pElementCollector) {
            return (nIgnoredSecurityId == css::xml::crypto::sax::ConstOfSecurityId::UNDEFINEDSECURITYID ||
                    pElementCollector->getSecurityId() != nIgnoredSecurityId) &&
                   (pElementCollector->getPriority() == css::xml::crypto::sax::ElementMarkPriority_BEFOREMODIFY);
        });
}

void BufferNode::setReceivedAll()
/****** BufferNode/setReceiveAll *********************************************
 *
 *   NAME
 *  setReceivedAll -- indicates that the element in this BufferNode has
 *  been completely buffered.
 *
 *   SYNOPSIS
 *  setReceivedAll();
 *
 *   FUNCTION
 *  sets the all-received flag and launches ElementCollector's notify
 *  process.
 *
 *   INPUTS
 *  empty
 *
 *   RESULT
 *  empty
 ******************************************************************************/
{
    m_bAllReceived = true;
    elementCollectorNotify();
}


void BufferNode::addElementCollector(const ElementCollector* pElementCollector)
/****** BufferNode/addElementCollector ***************************************
 *
 *   NAME
 *  addElementCollector -- adds a new ElementCollector to this BufferNode.
 *
 *   SYNOPSIS
 *  addElementCollector(pElementCollector);
 *
 *   FUNCTION
 *  see NAME
 *
 *   INPUTS
 *  pElementCollector - the ElementCollector to be added
 *
 *   RESULT
 *  empty
 ******************************************************************************/
{
    m_vElementCollectors.push_back( pElementCollector );
    const_cast<ElementCollector*>(pElementCollector)->setBufferNode(this);
}

void BufferNode::removeElementCollector(const ElementCollector* pElementCollector)
/****** BufferNode/removeElementCollector ************************************
 *
 *   NAME
 *  removeElementCollector -- removes an ElementCollector from this
 *  BufferNode.
 *
 *   SYNOPSIS
 *  removeElementCollector(pElementCollector);
 *
 *   FUNCTION
 *  see NAME
 *
 *   INPUTS
 *  pElementCollector - the ElementCollector to be removed
 *
 *   RESULT
 *  empty
 ******************************************************************************/
{
    auto ii = std::find(m_vElementCollectors.begin(), m_vElementCollectors.end(), pElementCollector);
    if (ii != m_vElementCollectors.end())
    {
        m_vElementCollectors.erase( ii );
        const_cast<ElementCollector*>(pElementCollector)->setBufferNode(nullptr);
    }
}


void BufferNode::setBlocker(const ElementMark* pBlocker)
/****** BufferNode/setBlocker ************************************************
 *
 *   NAME
 *  setBlocker -- adds a blocker to this BufferNode.
 *
 *   SYNOPSIS
 *  setBlocker(pBlocker);
 *
 *   FUNCTION
 *  see NAME
 *
 *   INPUTS
 *  pBlocker - the new blocker to be attached
 *
 *   RESULT
 *  empty
 *
 *   NOTES
 *  Because there is only one blocker permitted for a BufferNode, so the
 *  old blocker on this BufferNode, if there is one, will be overcasted.
 ******************************************************************************/
{
    OSL_ASSERT(!(m_pBlocker != nullptr && pBlocker != nullptr));

    m_pBlocker = const_cast<ElementMark*>(pBlocker);
    if (m_pBlocker != nullptr)
    {
        m_pBlocker->setBufferNode(this);
    }
}

OUString BufferNode::printChildren() const
/****** BufferNode/printChildren *********************************************
 *
 *   NAME
 *  printChildren -- prints children information into a string.
 *
 *   SYNOPSIS
 *  result = printChildren();
 *
 *   FUNCTION
 *  see NAME
 *
 *   INPUTS
 *  empty
 *
 *   RESULT
 *  result - the information string
 ******************************************************************************/
{
    OUStringBuffer rc;

    for( const ElementCollector* ii : m_vElementCollectors )
    {
        rc.append("BufID=").append(OUString::number(ii->getBufferId()));

        if (ii->getModify())
        {
            rc.append("[M]");
        }

        rc.append(",Pri=");

        switch (ii->getPriority())
        {
            case css::xml::crypto::sax::ElementMarkPriority_BEFOREMODIFY:
                rc.append("BEFOREMODIFY");
                break;
            case css::xml::crypto::sax::ElementMarkPriority_AFTERMODIFY:
                rc.append("AFTERMODIFY");
                break;
            default:
                rc.append("UNKNOWN");
                break;
        }

        rc.append("(SecID=").append(OUString::number(ii->getSecurityId())).append(") ");
    }

    return rc.makeStringAndClear();
}

bool BufferNode::hasAnything() const
/****** BufferNode/hasAnything ***********************************************
 *
 *   NAME
 *  hasAnything -- checks whether there is any ElementCollector or blocker
 *  on this BufferNode.
 *
 *   SYNOPSIS
 *  bExist = hasAnything();
 *
 *   FUNCTION
 *  see NAME
 *
 *   INPUTS
 *  empty
 *
 *   RESULT
 *  bExist - true if there is, false otherwise.
 ******************************************************************************/
{
    return (m_pBlocker || !m_vElementCollectors.empty());
}

bool BufferNode::hasChildren() const
/****** BufferNode/hasChildren ***********************************************
 *
 *   NAME
 *  hasChildren -- checks whether this BufferNode has any child
 *  BufferNode.
 *
 *   SYNOPSIS
 *  bExist = hasChildren();
 *
 *   FUNCTION
 *  see NAME
 *
 *   INPUTS
 *  empty
 *
 *   RESULT
 *  bExist - true if there is, false otherwise.
 ******************************************************************************/
{
    return (!m_vChildren.empty());
}

std::vector< std::unique_ptr<BufferNode> > const & BufferNode::getChildren() const
{
    return m_vChildren;
}

std::vector< std::unique_ptr<BufferNode> > BufferNode::releaseChildren()
{
    return std::move(m_vChildren);
}

const BufferNode* BufferNode::getFirstChild() const
/****** BufferNode/getFirstChild *********************************************
 *
 *   NAME
 *  getFirstChild -- retrieves the first child BufferNode.
 *
 *   SYNOPSIS
 *  child = getFirstChild();
 *
 *   FUNCTION
 *  see NAME
 *
 *   INPUTS
 *  empty
 *
 *   RESULT
 *  child - the first child BufferNode, or NULL if there is no child
 *          BufferNode.
 ******************************************************************************/
{
    BufferNode* rc = nullptr;

    if (!m_vChildren.empty())
    {
        rc = m_vChildren.front().get();
    }

    return rc;
}

void BufferNode::addChild(std::unique_ptr<BufferNode> pChild, sal_Int32 nPosition)
/****** BufferNode/addChild(pChild,nPosition) ********************************
 *
 *   NAME
 *  addChild -- inserts a child BufferNode at specific position.
 *
 *   SYNOPSIS
 *  addChild(pChild, nPosition);
 *
 *   FUNCTION
 *  see NAME
 *
 *   INPUTS
 *  pChild -    the child BufferNode to be added.
 *  nPosition - the position where the new child locates.
 *
 *   RESULT
 *  empty
 *
 *   NOTES
 *  If the nPosition is -1, then the new child BufferNode is appended
 *  at the end.
 ******************************************************************************/
{
    if (nPosition == -1)
    {
        m_vChildren.push_back( std::move(pChild) );
    }
    else
    {
        m_vChildren.insert(m_vChildren.begin() + nPosition, std::move(pChild));
    }
}

void BufferNode::addChild(std::unique_ptr<BufferNode> pChild)
/****** BufferNode/addChild() ************************************************
 *
 *   NAME
 *  addChild -- add a new child BufferNode.
 *
 *   SYNOPSIS
 *  addChild(pChild);
 *
 *   FUNCTION
 *  see NAME
 *
 *   INPUTS
 *  pChild -    the child BufferNode to be added.
 *
 *   RESULT
 *  empty
 *
 *   NOTES
 *  The new child BufferNode is appended at the end.
 ******************************************************************************/
{
    addChild(std::move(pChild), -1);
}

void BufferNode::removeChild(const BufferNode* pChild)
/****** BufferNode/removeChild ***********************************************
 *
 *   NAME
 *  removeChild -- removes and deletes a child BufferNode from the children list.
 *
 *   SYNOPSIS
 *  removeChild(pChild);
 *
 *   FUNCTION
 *  see NAME
 *
 *   INPUTS
 *  pChild - the child BufferNode to be removed
 *
 *   RESULT
 *  empty
 ******************************************************************************/
{
    auto ii = std::find_if(m_vChildren.begin(), m_vChildren.end(),
                [pChild] (const std::unique_ptr<BufferNode>& i)
                { return i.get() == pChild; });
    if (ii != m_vChildren.end())
        m_vChildren.erase( ii );
}

sal_Int32 BufferNode::indexOfChild(const BufferNode* pChild) const
/****** BufferNode/indexOfChild **********************************************
 *
 *   NAME
 *  indexOfChild -- gets the index of a child BufferNode.
 *
 *   SYNOPSIS
 *  index = indexOfChild(pChild);
 *
 *   FUNCTION
 *  see NAME
 *
 *   INPUTS
 *  pChild - the child BufferNode whose index to be gotten
 *
 *   RESULT
 *  index - the index of that child BufferNode. If that child BufferNode
 *          is not found, -1 is returned.
 ******************************************************************************/
{
    auto ii = std::find_if(m_vChildren.begin(), m_vChildren.end(),
            [pChild] (const std::unique_ptr<BufferNode>& i)
            { return i.get() == pChild; });
    if (ii == m_vChildren.end())
        return -1;

    return std::distance(m_vChildren.begin(), ii);
}


void BufferNode::setParent(const BufferNode* pParent)
{
    m_pParent = const_cast<BufferNode*>(pParent);
}

const BufferNode* BufferNode::getNextSibling() const
/****** BufferNode/getNextSibling ********************************************
 *
 *   NAME
 *  getNextSibling -- retrieves the next sibling BufferNode.
 *
 *   SYNOPSIS
 *  sibling = getNextSibling();
 *
 *   FUNCTION
 *  see NAME
 *
 *   INPUTS
 *  empty
 *
 *   RESULT
 *  sibling - the next sibling BufferNode, or NULL if there is none.
 ******************************************************************************/
{
    BufferNode* rc = nullptr;

    if (m_pParent != nullptr)
    {
        rc = const_cast<BufferNode*>(m_pParent->getNextChild(this));
    }

    return rc;
}

const BufferNode* BufferNode::isAncestor(const BufferNode* pDescendant) const
/****** BufferNode/isAncestor ************************************************
 *
 *   NAME
 *  isAncestor -- checks whether this BufferNode is an ancestor of another
 *  BufferNode.
 *
 *   SYNOPSIS
 *  bIs = isAncestor(pDescendant);
 *
 *   FUNCTION
 *  see NAME
 *
 *   INPUTS
 *  pDescendant -   the BufferNode to be checked as a descendant
 *
 *   RESULT
 *  bIs -   true if this BufferNode is an ancestor of the pDescendant,
 *          false otherwise.
 ******************************************************************************/
{
    BufferNode* rc = nullptr;

    if (pDescendant != nullptr)
    {
        auto ii = std::find_if(m_vChildren.cbegin(), m_vChildren.cend(),
            [&pDescendant](const std::unique_ptr<BufferNode>& pChild) {
                return (pChild.get() == pDescendant) || (pChild->isAncestor(pDescendant) != nullptr);
            });

        if (ii != m_vChildren.end())
            rc = ii->get();
    }

    return rc;
}

bool BufferNode::isPrevious(const BufferNode* pFollowing) const
/****** BufferNode/isPrevious ************************************************
 *
 *   NAME
 *  isPrevious -- checks whether this BufferNode is ahead of another
 *  BufferNode in the tree order.
 *
 *   SYNOPSIS
 *  bIs = isPrevious(pFollowing);
 *
 *   FUNCTION
 *  see NAME
 *
 *   INPUTS
 *  pFollowing -    the BufferNode to be checked as a following
 *
 *   RESULT
 *  bIs -   true if this BufferNode is ahead in the tree order, false
 *          otherwise.
 ******************************************************************************/
{
    bool rc = false;

    BufferNode* pNextBufferNode = const_cast<BufferNode*>(getNextNodeByTreeOrder());
    while (pNextBufferNode != nullptr)
    {
        if (pNextBufferNode == pFollowing)
        {
            rc = true;
            break;
        }

        pNextBufferNode = const_cast<BufferNode*>(pNextBufferNode->getNextNodeByTreeOrder());
    }

    return rc;
}

const BufferNode* BufferNode::getNextNodeByTreeOrder() const
/****** BufferNode/getNextNodeByTreeOrder ************************************
 *
 *   NAME
 *  getNextNodeByTreeOrder -- retrieves the next BufferNode in the tree
 *  order.
 *
 *   SYNOPSIS
 *  next = getNextNodeByTreeOrder();
 *
 *   FUNCTION
 *  see NAME
 *
 *   INPUTS
 *  empty
 *
 *   RESULT
 *  next -  the BufferNode following this BufferNode in the tree order,
 *          or NULL if there is none.
 *
 *   NOTES
 *  The "next" node in tree order is defined as:
 *  1. If a node has children, then the first child is;
 *  2. otherwise, if it has a following sibling, then this sibling node is;
 *  3. otherwise, if it has a parent node, the parent's next sibling
 *     node is;
 *  4. otherwise, no "next" node exists.
 ******************************************************************************/
{
    /*
     * If this buffer node has m_vChildren, then return the first
     * child.
     */
    if (hasChildren())
    {
        return getFirstChild();
    }

    /*
     * Otherwise, it this buffer node has a following sibling,
     * then return that sibling.
     */
    BufferNode* pNextSibling = const_cast<BufferNode*>(getNextSibling());
    if (pNextSibling != nullptr)
    {
        return pNextSibling;
    }

    /*
     * Otherwise, it this buffer node has parent, then return
     * its parent's following sibling.
     */
    BufferNode* pNode = const_cast<BufferNode*>(this);
    BufferNode* pParent;
    BufferNode* pNextSiblingParent = nullptr;

    do
    {
        if (pNode == nullptr)
        {
            break;
        }

        pParent = const_cast<BufferNode*>(pNode->getParent());
        if (pParent != nullptr)
        {
            pNextSiblingParent = const_cast<BufferNode*>(pParent->getNextSibling());
        }
        pNode = pParent;

    } while (pNextSiblingParent == nullptr);

    return pNextSiblingParent;
}


void BufferNode::setXMLElement( const css::uno::Reference< css::xml::wrapper::XXMLElementWrapper >& xXMLElement )
{
    m_xXMLElement = xXMLElement;
}

void BufferNode::notifyBranch()
/****** BufferNode/notifyBranch **********************************************
 *
 *   NAME
 *  notifyBranch -- notifies each BufferNode in the branch of this
 *  BufferNode in the tree order.
 *
 *   SYNOPSIS
 *  notifyBranch();
 *
 *   FUNCTION
 *  see NAME
 *
 *   INPUTS
 *  empty
 *
 *   RESULT
 *  empty
 ******************************************************************************/
{
    for( std::unique_ptr<BufferNode>& pBufferNode : m_vChildren )
    {
        pBufferNode->elementCollectorNotify();
        pBufferNode->notifyBranch();
    }
}

void BufferNode::elementCollectorNotify()
/****** BufferNode/elementCollectorNotify ************************************
 *
 *   NAME
 *  elementCollectorNotify -- notifies this BufferNode.
 *
 *   SYNOPSIS
 *  elementCollectorNotify();
 *
 *   FUNCTION
 *  Notifies this BufferNode if the notification is not suppressed.
 *
 *   INPUTS
 *  empty
 *
 *   RESULT
 *  child - the first child BufferNode, or NULL if there is no child
 *          BufferNode.
 ******************************************************************************/
{
    if (!m_vElementCollectors.empty())
    {
        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)
            {
                nMaxPriority = nPriority;
            }
        }

        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();

            /*
             * 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())))
            {
                /*
                 * 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();
                }
            }
        }
    }
}

bool BufferNode::isECInSubTreeIncluded(sal_Int32 nIgnoredSecurityId) const
/****** BufferNode/isECInSubTreeIncluded *************************************
 *
 *   NAME
 *  isECInSubTreeIncluded -- checks whether there is any ElementCollector
 *  in the branch of this BufferNode.
 *
 *   SYNOPSIS
 *  bExist = isECInSubTreeIncluded(nIgnoredSecurityId);
 *
 *   FUNCTION
 *  checks each BufferNode in the branch of this BufferNode, if there is
 *  an ElementCollector whose signatureId is not ignored, then return
 *  true, otherwise, false returned.
 *
 *   INPUTS
 *  nIgnoredSecurityId -    the security Id to be ignored. If it equals
 *                          to UNDEFINEDSECURITYID, then no security Id
 *                          will be ignored.
 *
 *   RESULT
 *  bExist - true if a match found, false otherwise.
 ******************************************************************************/
{
    bool rc = std::any_of(m_vElementCollectors.begin(), m_vElementCollectors.end(),
        [nIgnoredSecurityId](const ElementCollector* pElementCollector) {
            return nIgnoredSecurityId == css::xml::crypto::sax::ConstOfSecurityId::UNDEFINEDSECURITYID ||
                pElementCollector->getSecurityId() != nIgnoredSecurityId;
    });

    if ( !rc )
    {
        rc = std::any_of(m_vChildren.begin(), m_vChildren.end(),
            [nIgnoredSecurityId](const std::unique_ptr<BufferNode>& pBufferNode) {
                return pBufferNode->isECInSubTreeIncluded(nIgnoredSecurityId);
        });
    }

    return rc;
}

bool BufferNode::isECOfBeforeModifyInAncestorIncluded(sal_Int32 nIgnoredSecurityId) const
/****** BufferNode/isECOfBeforeModifyInAncestorIncluded **********************
 *
 *   NAME
 *  isECOfBeforeModifyInAncestorIncluded -- checks whether there is some
 *  ancestor BufferNode which has ElementCollector with PRI_BEFPREMODIFY
 *  priority.
 *
 *   SYNOPSIS
 *  bExist = isECOfBeforeModifyInAncestorIncluded(nIgnoredSecurityId);
 *
 *   FUNCTION
 *  checks each ancestor BufferNode through the parent link, if there is
 *  an ElementCollector with PRI_BEFPREMODIFY priority and its
 *  signatureId is not ignored, then return true, otherwise, false
 *  returned.
 *
 *   INPUTS
 *  nIgnoredSecurityId -    the security Id to be ignored. If it equals
 *                          to UNDEFINEDSECURITYID, then no security Id
 *                          will be ignored.
 *
 *   RESULT
 *  bExist - true if a match found, false otherwise.
 ******************************************************************************/
{
    bool rc = false;

    BufferNode* pParentNode = m_pParent;
    while (pParentNode != nullptr)
    {
        if (pParentNode->isECOfBeforeModifyIncluded(nIgnoredSecurityId))
        {
            rc = true;
            break;
        }

        pParentNode = const_cast<BufferNode*>(pParentNode->getParent());
    }

    return rc;
}

bool BufferNode::isBlockerInSubTreeIncluded(sal_Int32 nIgnoredSecurityId) const
/****** BufferNode/isBlockerInSubTreeIncluded ********************************
 *
 *   NAME
 *  isBlockerInSubTreeIncluded -- checks whether there is some BufferNode
 *  which has blocker on it
 *
 *   SYNOPSIS
 *  bExist = isBlockerInSubTreeIncluded(nIgnoredSecurityId);
 *
 *   FUNCTION
 *  checks each BufferNode in the branch of this BufferNode, if one has
 *  a blocker on it, and the blocker's securityId is not ignored, then
 *  returns true; otherwise, false returns.
 *
 *   INPUTS
 *  nIgnoredSecurityId -    the security Id to be ignored. If it equals
 *                          to UNDEFINEDSECURITYID, then no security Id
 *                          will be ignored.
 *
 *   RESULT
 *  bExist - true if a match found, false otherwise.
 ******************************************************************************/
{
    return std::any_of(m_vChildren.begin(), m_vChildren.end(),
        [nIgnoredSecurityId](const std::unique_ptr<BufferNode>& pBufferNode) {
            ElementMark* pBlocker = pBufferNode->getBlocker();
            return (pBlocker != nullptr &&
                (nIgnoredSecurityId == css::xml::crypto::sax::ConstOfSecurityId::UNDEFINEDSECURITYID ||
                 pBlocker->getSecurityId() != nIgnoredSecurityId )) ||
                pBufferNode->isBlockerInSubTreeIncluded(nIgnoredSecurityId);
    });
}

const BufferNode* BufferNode::getNextChild(const BufferNode* pChild) const
/****** BufferNode/getNextChild **********************************************
 *
 *   NAME
 *  getNextChild -- get the next child BufferNode.
 *
 *   SYNOPSIS
 *  nextChild = getNextChild();
 *
 *   FUNCTION
 *  see NAME
 *
 *   INPUTS
 *  pChild - the child BufferNode whose next node is retrieved.
 *
 *   RESULT
 *  nextChild - the next child BufferNode after the pChild, or NULL if
 *  there is none.
 ******************************************************************************/
{
    BufferNode* rc = nullptr;
    bool bChildFound = false;

    for( std::unique_ptr<BufferNode> const & i : m_vChildren )
    {
        if (bChildFound)
        {
            rc = i.get();
            break;
        }

        if( i.get() == pChild )
        {
            bChildFound = true;
        }
    }

    return rc;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */