~ubuntu-branches/ubuntu/natty/xml-security-c/natty

« back to all changes in this revision

Viewing changes to src/canon/XSECCannon.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Russ Allbery
  • Date: 2009-08-05 14:11:52 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090805141152-a7xyrgur2sq3exkr
Tags: 1.5.1-1
* New upstream release.
  - Rename library package for upstream SONAME bump.
* Upstream now ships an older version of libtool, so run libtoolize and
  aclocal before the build.  Add build dependencies on automake and
  libtool.
* Build against Xerces-C 3.0.
* Stop building against Xalan.  The Xalan packages for Debian have been
  orphaned, the current Xalan release does not support Xerces-C 3.0, and
  porting it is not trivial.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2002-2005 The Apache Software Foundation.
3
 
 *
4
 
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 
 * you may not use this file except in compliance with the License.
6
 
 * You may obtain a copy of the License at
7
 
 *
8
 
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 
 *
10
 
 * Unless required by applicable law or agreed to in writing, software
11
 
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 
 * See the License for the specific language governing permissions and
14
 
 * limitations under the License.
15
 
 */
16
 
 
17
 
/*
18
 
 * XSEC
19
 
 *
20
 
 * XSECCanon := Base (virtual) class for canonicalisation objects
21
 
 *
22
 
 * Author(s): Berin Lautenbach
23
 
 *
24
 
 * $ID$
25
 
 *
26
 
 * $LOG$
27
 
 *
28
 
 */
29
 
 
30
 
#include <xsec/canon/XSECCanon.hpp>
31
 
#include <xsec/utils/XSECDOMUtils.hpp>
32
 
 
33
 
#include <memory.h>
34
 
 
35
 
XERCES_CPP_NAMESPACE_USE
36
 
 
37
 
// --------------------------------------------------------------------------------
38
 
//           XSECCanon Virtual Class implementation
39
 
// --------------------------------------------------------------------------------
40
 
 
41
 
 
42
 
// Constructors
43
 
 
44
 
XSECCanon::XSECCanon() {};
45
 
        
46
 
XSECCanon::XSECCanon(DOMDocument *newDoc) : m_buffer() {
47
 
                
48
 
        
49
 
        mp_doc = newDoc;
50
 
        mp_startNode = mp_nextNode = newDoc;            // By default, start from startNode
51
 
        m_bufferLength = m_bufferPoint = 0;     // Start with an empty buffer
52
 
        m_allNodesDone = false;
53
 
        
54
 
};
55
 
 
56
 
XSECCanon::XSECCanon(DOMDocument *newDoc, DOMNode *newStartNode) {
57
 
        
58
 
        mp_doc = newDoc;
59
 
        mp_startNode = mp_nextNode = newStartNode;
60
 
        m_bufferLength = m_bufferPoint = 0;     // Start with an empty buffer
61
 
        m_allNodesDone = false;
62
 
        
63
 
};
64
 
 
65
 
// Destructors
66
 
 
67
 
XSECCanon::~XSECCanon() {};
68
 
 
69
 
// Public Methods
70
 
 
71
 
int XSECCanon::outputBuffer(unsigned char *outBuffer, int numBytes) {
72
 
 
73
 
        // numBytes of data are required to be placed in outBuffer.
74
 
 
75
 
        // Calculate amount left in buffer
76
 
 
77
 
        int remaining = m_bufferLength - m_bufferPoint;
78
 
        int bytesToGo = numBytes;
79
 
        int i = 0;                                      // current point in outBuffer
80
 
 
81
 
 
82
 
        // While we don't have enough, and have not completed - 
83
 
 
84
 
        while (!m_allNodesDone && (remaining < bytesToGo)) {
85
 
 
86
 
                // Copy what we have and get some more in the buffer
87
 
                memcpy(&outBuffer[i], &m_buffer[m_bufferPoint], remaining);
88
 
                i += remaining;
89
 
                m_bufferPoint += remaining;
90
 
                bytesToGo -= remaining;
91
 
 
92
 
                // Get more
93
 
 
94
 
                processNextNode();
95
 
 
96
 
                remaining = m_bufferLength - m_bufferPoint;             // This will be reset by processNextElement
97
 
                                                                                                        // "-bufferPoint" is just in case.
98
 
 
99
 
        }
100
 
 
101
 
        if (m_allNodesDone && (remaining < bytesToGo)) {
102
 
 
103
 
                // Was not enough data to fill everything up
104
 
                memcpy (&outBuffer[i], &m_buffer[m_bufferPoint], remaining);
105
 
                m_bufferPoint += remaining;
106
 
                return i + remaining;
107
 
        }
108
 
        
109
 
        // Copy the tail of the buffer
110
 
 
111
 
        memcpy(&outBuffer[i], &m_buffer[m_bufferPoint], bytesToGo);
112
 
        m_bufferPoint += bytesToGo;
113
 
        return (bytesToGo + i);
114
 
        
115
 
}
116
 
 
117
 
// setStartNode sets the starting point for the output if it is a sub-document 
118
 
// that needs canonicalisation and we want to re-start
119
 
 
120
 
bool XSECCanon::setStartNode(DOMNode *newStartNode) {
121
 
 
122
 
        mp_startNode = newStartNode;
123
 
        m_bufferPoint = 0;
124
 
        m_bufferLength = 0;
125
 
        mp_nextNode = mp_startNode;
126
 
 
127
 
        m_allNodesDone = false;                 // Restart
128
 
 
129
 
        return true;                    // Should check to ensure that the StartNode is part of the doc.
130
 
 
131
 
}
132
 
 
133