You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by bl...@apache.org on 2003/04/23 09:34:17 UTC

cvs commit: xml-security/c/src/utils XSECNameSpaceExpander.cpp XSECNameSpaceExpander.hpp

blautenb    2003/04/23 00:34:17

  Modified:    c/src/canon XSECC14n20010315.cpp
               c/src/utils XSECNameSpaceExpander.cpp
                        XSECNameSpaceExpander.hpp
  Log:
  Updates to allow canonicalisation of fragments
  
  Revision  Changes    Path
  1.7       +5 -1      xml-security/c/src/canon/XSECC14n20010315.cpp
  
  Index: XSECC14n20010315.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/canon/XSECC14n20010315.cpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XSECC14n20010315.cpp	30 Mar 2003 06:54:30 -0000	1.6
  +++ XSECC14n20010315.cpp	23 Apr 2003 07:34:17 -0000	1.7
  @@ -466,6 +466,10 @@
   	XercesDOMSupport theDOMSupport;
   	XercesParserLiaison theParserLiaison(theDOMSupport);
   
  +	if (mp_doc == 0) {
  +		throw XSECException(XSECException::UnsupportedFunction,
  +			"XPath selection only supported in C14n for full documents");
  +	}
   	XalanDocument* theDoc = theParserLiaison.createDocument(mp_doc);
   
   	XalanElement * xe = theDoc->createElement(XalanDOMString("ns"));
  
  
  
  1.3       +14 -2     xml-security/c/src/utils/XSECNameSpaceExpander.cpp
  
  Index: XSECNameSpaceExpander.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/utils/XSECNameSpaceExpander.cpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XSECNameSpaceExpander.cpp	9 Feb 2003 11:13:52 -0000	1.2
  +++ XSECNameSpaceExpander.cpp	23 Apr 2003 07:34:17 -0000	1.3
  @@ -82,6 +82,18 @@
   XSECNameSpaceExpander::XSECNameSpaceExpander(DOMDocument *d) {
   
   	mp_doc = d;
  +	mp_fragment = d->getDocumentElement();
  +	XSECnew(mp_formatter, XSECSafeBufferFormatter("UTF-8",XMLFormatter::NoEscapes, 
  +												XMLFormatter::UnRep_CharRef));
  +
  +	m_expanded = false;
  +	
  +}
  +
  +XSECNameSpaceExpander::XSECNameSpaceExpander(DOMElement *f) {
  +
  +	mp_doc = NULL;
  +	mp_fragment = f;
   	XSECnew(mp_formatter, XSECSafeBufferFormatter("UTF-8",XMLFormatter::NoEscapes, 
   												XMLFormatter::UnRep_CharRef));
   
  @@ -189,7 +201,7 @@
   
   	DOMElement	*docElt;		// The document element - do not expand it's namespaces
   	
  -	docElt = mp_doc->getDocumentElement();
  +	docElt = mp_fragment; //mp_doc->getDocumentElement();
   	int count = attNodeCount(docElt);
   
   	DOMNode *c;
  @@ -214,7 +226,7 @@
   	NameSpaceEntryListVectorType::size_type size = m_lst.size();
   	XSECNameSpaceEntry *e;
   
  -	DOMElement *docElt = mp_doc->getDocumentElement();
  +	DOMElement *docElt = mp_fragment; //mp_doc->getDocumentElement();
   	int 	count = attNodeCount(docElt);
   
   	NameSpaceEntryListVectorType::size_type i;
  
  
  
  1.4       +75 -1     xml-security/c/src/utils/XSECNameSpaceExpander.hpp
  
  Index: XSECNameSpaceExpander.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/utils/XSECNameSpaceExpander.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XSECNameSpaceExpander.hpp	22 Feb 2003 08:47:26 -0000	1.3
  +++ XSECNameSpaceExpander.hpp	23 Apr 2003 07:34:17 -0000	1.4
  @@ -101,6 +101,39 @@
   //           Class definition for the list
   // --------------------------------------------------------------------------------
   
  +/**
  + * @ingroup pubsig
  + */
  +/*\@{*/
  +
  +/**
  + * @brief Class to "expand" name spaces
  + *
  + * For most things, a DOM model interoperates well with XPath.  Unfortunately,
  + * name-spaces are the one main problem.  In particular, the XPath spec
  + * states that every element node has an attribute node for its own 
  + * namespaces, and one for namespaces above that are in scope.
  + *
  + * In the DOM scheme of things, a namespace is only available in the node in
  + * which it is defined.  Normally this is not a problem, you can just just
  + * refer backwards until you find the namespace you need.  However, for XPath
  + * expressions that select namespace nodes, we need to actually promulgate
  + * the name-spaces down to every node where they are visible so that the XPath
  + * selection will work properly.
  + *
  + * This is important for Canonicalisation of the found nodes, but we cannot
  + * do this only in the canonicaliser as it does not internally understand how
  + * to do DSIG style XPath.  So the XPath is done externally, and the 
  + * resultant node set (including any selected "Expanded" attribute nodes).
  + * are passed in.
  + *
  + * The expander therefore handles the propogation of the namespace nodes, and
  + * removes the propogated nodes when it goes out of scope (or when
  + * deleteAddedNamespaces() is called).
  + *
  + */
  +
  +
   class CANON_EXPORT XSECNameSpaceExpander {
   
   
  @@ -113,11 +146,51 @@
   
   public:
   
  +    /** @name Constructors and Destructors */
  +    //@{
  +	
  +    /**
  +	 * \brief Main constructure
  +	 *
  +	 * Use this constructor to expand namespaces through an entire document.
  +	 *
  +	 * @param d The DOM document to be expanded.
  +	 */
  +
   	XSECNameSpaceExpander(DOMDocument *d);			// Constructor
  +
  +    /**
  +	 * \brief Fragment constructor
  +	 *
  +	 * Use this constructor to expand namespaces in a given fragment only.
  +	 * @note The fragment does not need to be rooted in an actual document.
  +	 *
  +	 * @param f The starting element of the fragment to be expanded.
  +	 */
  +
  +	XSECNameSpaceExpander(DOMElement *f);		    // frag Constructor
  +
   	~XSECNameSpaceExpander();						// Default destructor
   
  +	//@}
  +
   	// Operate 
  +
  +	/**
  +	 * \brief Expand namespaces.
  +	 *
  +	 * Perform the expansion operation and create a list of all added nodes.
  +	 */
  +
   	void expandNameSpaces(void);
  +
  +	/**
  +	 * \brief Collapse name-spaces
  +	 *
  +	 * Delete all namespaces added in exandNameSpaces() (using the list that
  +	 * was created at that time
  +	 */
  +
   	void deleteAddedNamespaces(void);
   
   	// Check if a node is an added node
  @@ -132,6 +205,7 @@
   	
   	NameSpaceEntryListVectorType	m_lst;			// List of added name spaces
   	DOMDocument						* mp_doc;		// The owner document
  +	DOMElement                      * mp_fragment;  // If we are doing a fragment
   	bool							m_expanded;		// Have we expanded already?
   	XSECSafeBufferFormatter			* mp_formatter;