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) 1999 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 // --------------------------------------------------------------------------------
00162 //           XSECC14n20010315 Object definition
00163 // --------------------------------------------------------------------------------
00164 
00165 class CANON_EXPORT XSECC14n20010315 : public XSECCanon {
00166 
00167 #if defined(XALAN_NO_NAMESPACES)
00168     typedef vector<char *>              CharListVectorType;
00169 #else
00170     typedef std::vector<char *>         CharListVectorType;
00171 #endif
00172 
00173 #if defined(XALAN_SIZE_T_IN_NAMESPACE_STD)
00174     typedef std::size_t     size_type;
00175 #else
00176     typedef size_t          size_type;
00177 #endif
00178 
00179 
00180 public:
00181 
00182     // Constructors
00183     XSECC14n20010315();
00184     XSECC14n20010315(DOMDocument *newDoc);
00185     XSECC14n20010315(DOMDocument *newDoc, DOMNode *newStartNode);
00186     virtual ~XSECC14n20010315();
00187 
00188     // XPath processor
00189 
00190     int XPathSelectNodes(const char * XPathExpr);
00191     void setXPathMap(const XSECXPathNodeList & map);
00192 
00193     // Comments processing
00194     void setCommentsProcessing(bool onoff);
00195     bool getCommentsProcessing(void);
00196 
00197     // Exclusive processing
00198     void setExclusive(void);
00199     void setExclusive(char * xmlnsList);
00200 
00201 protected:
00202 
00203     // Implementation of virtual function
00204     int processNextNode();
00205 
00206     // Test whether a name space is in the non-exclusive list
00207     bool inNonExclNSList(safeBuffer &ns);
00208 
00209 private:
00210 
00211     void XSECC14n20010315::init();
00212     bool checkRenderNameSpaceNode(DOMNode *e, DOMNode *a);
00213 
00214     // For formatting the buffers
00215     c14nFormatTarget *c14ntarget;
00216     XMLFormatter *formatter;
00217     safeBuffer formatBuffer;
00218 
00219     // For holding state whilst walking the DOM tree
00220     XSECNodeListElt * mp_attributes,                // Start of list
00221                     * mp_currentAttribute,          // Where we currently are in list
00222                     * mp_firstNonNsAttribute;       // First NON XMLNS element in list
00223     DOMNode         * mp_attributeParent;           // To return up the tree
00224     bool m_returnedFromChild;                       // Did we get to this node from below?
00225     DOMNode         * mp_firstElementNode;          // The root element of the document
00226     bool            m_firstElementProcessed;        // Has the first node been handled?
00227     unsigned char   * mp_charBuffer;
00228 
00229     // For XPath evaluation
00230     bool              m_XPathSelection;             // Are we doing an XPath?
00231     XSECXPathNodeList m_XPathMap;                   // The elements in the XPath
00232 
00233     // For comment processing
00234     bool            m_processComments;              // Whether comments are in or out (in by default)
00235 
00236     // For exclusive canonicalisation
00237     CharListVectorType      m_exclNSList;
00238     bool                    m_exclusive;
00239     bool                    m_exclusiveDefault;
00240 
00241 
00242 
00243 };
00244 
00245 
00246 #endif /* XSECC14n20010315_INCLUDE */
00247 
00248 

Generated on Thu May 8 20:17:02 2003 for XML-Security-C by doxygen1.2.15