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

XSECC14n20010315.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2002-2005 The Apache Software Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 /*
00018  * XSEC
00019  *
00020  * XSECC14n20010315 := Canonicaliser object to process XML document in line with
00021  *                       RFC 3076
00022  *
00023  * Author(s): Berin Lautenbach
00024  *
00025  * $Id: XSECC14n20010315.hpp 394035 2006-04-14 06:53:07Z blautenb $
00026  *
00027  */
00028 
00029 #ifndef XSECC14n20010315_INCLUDE
00030 #define XSECC14n20010315_INCLUDE
00031 
00032 //XSEC includes
00033 #include <xsec/framework/XSECDefs.hpp>
00034 #include <xsec/utils/XSECSafeBuffer.hpp>
00035 #include <xsec/utils/XSECXPathNodeList.hpp>
00036 #include <xsec/canon/XSECCanon.hpp>
00037 #include <xsec/canon/XSECXMLNSStack.hpp>
00038 
00039 #include <xercesc/framework/XMLFormatter.hpp>
00040 
00041 // General includes
00042 #include <memory.h>
00043 #include <vector>
00044 
00045 XSEC_USING_XERCES(XMLFormatter);
00046 XSEC_USING_XERCES(XMLFormatTarget);
00047 
00048 class XSECSafeBufferFormatter;
00049 
00050 // --------------------------------------------------------------------------------
00051 //           Simple structure for holding a list of nodes
00052 // --------------------------------------------------------------------------------
00053 
00054 // NOTE: We don't use NamedNodeMap or DOMNodeList as we are unsure what might happen
00055 // to them in the future.  Also, to add items we would have to delve into the inards
00056 // of Xerces (and use the "...impl" classes).  Such an approach might not be supported
00057 // in the future.
00058 
00059 struct XSECNodeListElt {
00060 
00061     XERCES_CPP_NAMESPACE_QUALIFIER DOMNode  *element;   // Element referred to
00062     safeBuffer                      sortString; // The string that is used to sort the nodes
00063 
00064     XSECNodeListElt                 *next,
00065                                     *last;      // For the list
00066 
00067 };
00068 
00069 // Used for the sorting function
00070 
00071 #define XMLNS_PREFIX        "a"
00072 #define ATTRIBUTE_PREFIX    "b"
00073 
00074 #define NOURI_PREFIX         "a"
00075 #define HAVEURI_PREFIX       "b"
00076 
00077 // --------------------------------------------------------------------------------
00078 //           XSECC14n20010315 Object definition
00079 // --------------------------------------------------------------------------------
00080 
00081 class CANON_EXPORT XSECC14n20010315 : public XSECCanon {
00082 
00083 #if defined(XALAN_NO_NAMESPACES)
00084     typedef vector<char *>              CharListVectorType;
00085 #else
00086     typedef std::vector<char *>         CharListVectorType;
00087 #endif
00088 
00089 #if defined(XALAN_SIZE_T_IN_NAMESPACE_STD)
00090     typedef std::size_t     size_type;
00091 #else
00092     typedef size_t          size_type;
00093 #endif
00094 
00095 
00096 public:
00097 
00098     // Constructors
00099     XSECC14n20010315();
00100     XSECC14n20010315(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *newDoc);
00101     XSECC14n20010315(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *newDoc, 
00102                      XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *newStartNode);
00103     virtual ~XSECC14n20010315();
00104 
00105     // XPath processor
00106 
00107     int XPathSelectNodes(const char * XPathExpr);
00108     void setXPathMap(const XSECXPathNodeList & map);
00109 
00110     // Comments processing
00111     void setCommentsProcessing(bool onoff);
00112     bool getCommentsProcessing(void);
00113 
00114     // Exclusive processing
00115     void setExclusive(void);
00116     void setExclusive(char * xmlnsList);
00117 
00118     // Namespace processing
00119     void setUseNamespaceStack(bool flag) {m_useNamespaceStack = flag;}
00120 
00121 protected:
00122 
00123     // Implementation of virtual function
00124     int processNextNode();
00125 
00126     // Test whether a name space is in the non-exclusive list
00127     bool inNonExclNSList(safeBuffer &ns);
00128 
00129 private:
00130 
00131     void init();
00132     bool checkRenderNameSpaceNode(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *e, 
00133                                   XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *a);
00134     void stackInit(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode * n);
00135 
00136     // For formatting the buffers
00137     XSECSafeBufferFormatter     * mp_formatter;
00138     safeBuffer                  m_formatBuffer;
00139 
00140     // For holding state whilst walking the DOM tree
00141     XSECNodeListElt * mp_attributes,                // Start of list
00142                     * mp_currentAttribute,          // Where we currently are in list
00143                     * mp_firstNonNsAttribute;       // First NON XMLNS element in list
00144     XERCES_CPP_NAMESPACE_QUALIFIER DOMNode * mp_attributeParent;            // To return up the tree
00145     bool m_returnedFromChild;                       // Did we get to this node from below?
00146     XERCES_CPP_NAMESPACE_QUALIFIER DOMNode * mp_firstElementNode;           // The root element of the document
00147     bool            m_firstElementProcessed;        // Has the first node been handled?
00148     unsigned char   * mp_charBuffer;
00149 
00150     // For XPath evaluation
00151     bool              m_XPathSelection;             // Are we doing an XPath?
00152     XSECXPathNodeList m_XPathMap;                   // The elements in the XPath
00153 
00154     // For comment processing
00155     bool            m_processComments;              // Whether comments are in or out (in by default)
00156 
00157     // For exclusive canonicalisation
00158     CharListVectorType      m_exclNSList;
00159     bool                    m_exclusive;
00160     bool                    m_exclusiveDefault;
00161 
00162     // How do we handle namespaces?
00163     // Use the namespace stack if name space expansion has not been run on the document.
00164     // NOTE : Using the name space stack *will* cause problems if a full XPath expression
00165     // has been run to select the input nodeset.  Otherwise we should be fine.
00166 
00167     bool                    m_useNamespaceStack;
00168     XSECXMLNSStack          m_nsStack;
00169 
00170 
00171 
00172 };
00173 
00174 
00175 #endif /* XSECC14n20010315_INCLUDE */
00176 
00177 

Generated on Sun Jan 28 19:37:24 2007 for XML-Security-C by  doxygen 1.4.2