Main Page | Modules | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

XSECC14n20010315.hpp

Go to the documentation of this file.
00001 /*
00002  * The Apache Software License, Version 1.1
00003  *
00004  *
00005  * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights 
00006  * reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer. 
00014  *
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in
00017  *    the documentation and/or other materials provided with the
00018  *    distribution.
00019  *
00020  * 3. The end-user documentation included with the redistribution,
00021  *    if any, must include the following acknowledgment:  
00022  *       "This product includes software developed by the
00023  *        Apache Software Foundation (http://www.apache.org/)."
00024  *    Alternately, this acknowledgment may appear in the software itself,
00025  *    if and wherever such third-party acknowledgments normally appear.
00026  *
00027  * 4. The names "<WebSig>" and "Apache Software Foundation" must
00028  *    not be used to endorse or promote products derived from this
00029  *    software without prior written permission. For written 
00030  *    permission, please contact apache@apache.org.
00031  *
00032  * 5. Products derived from this software may not be called "Apache",
00033  *    nor may "Apache" appear in their name, without prior written
00034  *    permission of the Apache Software Foundation.
00035  *
00036  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00038  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00039  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00040  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00041  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00042  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00043  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00044  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00045  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00046  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00047  * SUCH DAMAGE.
00048  * ====================================================================
00049  *
00050  * This software consists of voluntary contributions made by many
00051  * individuals on behalf of the Apache Software Foundation and was
00052  * originally based on software copyright (c) 2001, Institute for
00053  * Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
00054  * The development of this software was partly funded by the European 
00055  * Commission in the <WebSig> project in the ISIS Programme. 
00056  * For more information on the Apache Software Foundation, please see
00057  * <http://www.apache.org/>.
00058  */
00059 
00060 /*
00061  * XSEC
00062  *
00063  * XSECC14n20010315 := Canonicaliser object to process XML document in line with
00064  *                       RFC 3076
00065  *
00066  * Author(s): Berin Lautenbach
00067  *
00068  * $ID$
00069  *
00070  * $LOG$
00071  *
00072  */
00073 
00074 #ifndef XSECC14n20010315_INCLUDE
00075 #define XSECC14n20010315_INCLUDE
00076 
00077 //XSEC includes
00078 #include <xsec/framework/XSECDefs.hpp>
00079 #include <xsec/utils/XSECSafeBuffer.hpp>
00080 #include <xsec/utils/XSECXPathNodeList.hpp>
00081 #include <xsec/canon/XSECCanon.hpp>
00082 
00083 #include <xercesc/framework/XMLFormatter.hpp>
00084 
00085 // General includes
00086 #include <memory.h>
00087 #include <vector>
00088 
00089 XSEC_USING_XERCES(XMLFormatter);
00090 XSEC_USING_XERCES(XMLFormatTarget);
00091 
00092 // --------------------------------------------------------------------------------
00093 //           Object definitions needed for formatting Xerces objects
00094 // --------------------------------------------------------------------------------
00095 
00096 
00097 class c14nFormatTarget : public XMLFormatTarget
00098 {
00099 public:
00100     
00101     safeBuffer * buffer;        // Buffer to write to
00102 
00103     c14nFormatTarget()  {};
00104     ~c14nFormatTarget() {};
00105 
00106     void setBuffer (safeBuffer * toSet) {buffer = toSet;};
00107 
00108 
00109     // -----------------------------------------------------------------------
00110     //  Implementations of the format target interface
00111     // -----------------------------------------------------------------------
00112 
00113     void writeChars(const   XMLByte* const  toWrite,
00114                     const   unsigned int    count,
00115                             XMLFormatter * const formatter)
00116     {
00117         // Surprisingly, Solaris was the only platform on which
00118         // required the char* cast to print out the string correctly.
00119         // Without the cast, it was pinting the pointer value in hex.
00120         // Quite annoying, considering every other platform printed
00121         // the string with the explicit cast to char* below.
00122         buffer->sbMemcpyIn((char *) toWrite, (int) count);
00123         (*buffer)[count] = '\0';
00124         buffer->setBufferType(safeBuffer::BUFFER_CHAR);
00125     };
00126 
00127 private:
00128     // -----------------------------------------------------------------------
00129     //  Unimplemented methods.
00130     // -----------------------------------------------------------------------
00131     c14nFormatTarget(const c14nFormatTarget& other);
00132     void operator=(const c14nFormatTarget& rhs);
00133 
00134     
00135 };
00136 
00137 // --------------------------------------------------------------------------------
00138 //           Simple structure for holding a list of nodes
00139 // --------------------------------------------------------------------------------
00140 
00141 // NOTE: We don't use NamedNodeMap or DOMNodeList as we are unsure what might happen
00142 // to them in the future.  Also, to add items we would have to delve into the inards
00143 // of Xerces (and use the "...impl" classes).  Such an approach might not be supported
00144 // in the future.
00145 
00146 struct XSECNodeListElt {
00147 
00148     DOMNode     *element;           // Element referred to
00149     safeBuffer  sortString;         // The string that is used to sort the nodes
00150 
00151     XSECNodeListElt     *next,
00152                         *last;      // For the list
00153 
00154 };
00155 
00156 // Used for the sorting function
00157 
00158 #define XMLNS_PREFIX        "a"
00159 #define ATTRIBUTE_PREFIX    "b"
00160 
00161 #define NOURI_PREFIX         "a"
00162 #define HAVEURI_PREFIX       "b"
00163 
00164 // --------------------------------------------------------------------------------
00165 //           XSECC14n20010315 Object definition
00166 // --------------------------------------------------------------------------------
00167 
00168 class CANON_EXPORT XSECC14n20010315 : public XSECCanon {
00169 
00170 #if defined(XALAN_NO_NAMESPACES)
00171     typedef vector<char *>              CharListVectorType;
00172 #else
00173     typedef std::vector<char *>         CharListVectorType;
00174 #endif
00175 
00176 #if defined(XALAN_SIZE_T_IN_NAMESPACE_STD)
00177     typedef std::size_t     size_type;
00178 #else
00179     typedef size_t          size_type;
00180 #endif
00181 
00182 
00183 public:
00184 
00185     // Constructors
00186     XSECC14n20010315();
00187     XSECC14n20010315(DOMDocument *newDoc);
00188     XSECC14n20010315(DOMDocument *newDoc, DOMNode *newStartNode);
00189     virtual ~XSECC14n20010315();
00190 
00191     // XPath processor
00192 
00193     int XPathSelectNodes(const char * XPathExpr);
00194     void setXPathMap(const XSECXPathNodeList & map);
00195 
00196     // Comments processing
00197     void setCommentsProcessing(bool onoff);
00198     bool getCommentsProcessing(void);
00199 
00200     // Exclusive processing
00201     void setExclusive(void);
00202     void setExclusive(char * xmlnsList);
00203 
00204 protected:
00205 
00206     // Implementation of virtual function
00207     int processNextNode();
00208 
00209     // Test whether a name space is in the non-exclusive list
00210     bool inNonExclNSList(safeBuffer &ns);
00211 
00212 private:
00213 
00214     void XSECC14n20010315::init();
00215     bool checkRenderNameSpaceNode(DOMNode *e, DOMNode *a);
00216 
00217     // For formatting the buffers
00218     c14nFormatTarget *c14ntarget;
00219     XMLFormatter *formatter;
00220     safeBuffer formatBuffer;
00221 
00222     // For holding state whilst walking the DOM tree
00223     XSECNodeListElt * mp_attributes,                // Start of list
00224                     * mp_currentAttribute,          // Where we currently are in list
00225                     * mp_firstNonNsAttribute;       // First NON XMLNS element in list
00226     DOMNode         * mp_attributeParent;           // To return up the tree
00227     bool m_returnedFromChild;                       // Did we get to this node from below?
00228     DOMNode         * mp_firstElementNode;          // The root element of the document
00229     bool            m_firstElementProcessed;        // Has the first node been handled?
00230     unsigned char   * mp_charBuffer;
00231 
00232     // For XPath evaluation
00233     bool              m_XPathSelection;             // Are we doing an XPath?
00234     XSECXPathNodeList m_XPathMap;                   // The elements in the XPath
00235 
00236     // For comment processing
00237     bool            m_processComments;              // Whether comments are in or out (in by default)
00238 
00239     // For exclusive canonicalisation
00240     CharListVectorType      m_exclNSList;
00241     bool                    m_exclusive;
00242     bool                    m_exclusiveDefault;
00243 
00244 
00245 
00246 };
00247 
00248 
00249 #endif /* XSECC14n20010315_INCLUDE */
00250 
00251 

Generated on Sun Aug 10 06:24:29 2003 for XML-Security-C by doxygen 1.3.2