You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by su...@apache.org on 2004/11/12 03:53:20 UTC

cvs commit: ws-axis/c/src/xml/tspp Array.hpp AxisInputStream.cpp Buffer.cpp Buffer.hpp InputStream.hpp XMLParserAxis.cpp XMLParserAxis.hpp XmlPullParser.cpp XmlPullParser.hpp XmlPullParserException.cpp XmlPullParserException.hpp

susantha    2004/11/11 18:53:20

  Modified:    c/src/xml/tspp Array.hpp AxisInputStream.cpp Buffer.cpp
                        Buffer.hpp InputStream.hpp XMLParserAxis.cpp
                        XMLParserAxis.hpp XmlPullParser.cpp
                        XmlPullParser.hpp XmlPullParserException.cpp
                        XmlPullParserException.hpp
  Log:
  Fixed crashing bugs in tspp
  
  Revision  Changes    Path
  1.2       +9 -5      ws-axis/c/src/xml/tspp/Array.hpp
  
  Index: Array.hpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/xml/tspp/Array.hpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Array.hpp	8 Nov 2004 11:24:45 -0000	1.1
  +++ Array.hpp	12 Nov 2004 02:53:20 -0000	1.2
  @@ -16,7 +16,11 @@
    *                                                                         
    ***************************************************************************/
   
  - #if !defined(_ARRAY_HPP__INCLUDED_)
  +/*
  + *    @author Dasarath Weerathunga
  + */
  +
  +#if !defined(_ARRAY_HPP__INCLUDED_)
   #define _ARRAY_HPP__INCLUDED_
   
    #include "Buffer.hpp"
  @@ -28,7 +32,7 @@
   	int last;
   	
   public:
  -	Array(int size): Buffer<T>(size)
  +	Array(int iSize): Buffer<T>(iSize)
   	{
   		last= -1;
   	}
  @@ -59,12 +63,12 @@
   		return buffer[last];
   	}
   
  -	int trunc(int size)
  +	int trunc(int iSize)
   	{
  -		if ((size > 0 && last < size) || size < 0)
  +		if ((iSize > 0 && last < iSize) || iSize < 0)
   			throw new XmlPullParserException();
   		else
  -			return last= size-1;
  +			return last= iSize-1;
   	}
   
   	int chip()
  
  
  
  1.3       +5 -1      ws-axis/c/src/xml/tspp/AxisInputStream.cpp
  
  Index: AxisInputStream.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/xml/tspp/AxisInputStream.cpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AxisInputStream.cpp	9 Nov 2004 10:29:05 -0000	1.2
  +++ AxisInputStream.cpp	12 Nov 2004 02:53:20 -0000	1.3
  @@ -13,7 +13,11 @@
    *   See the License for the specific language governing permissions and
    *   limitations under the License.
    */
  - 
  +
  +/*
  + *    @author Susantha Kumara (susantha@opensource.lk)
  + */
  +
   #include "AxisInputStream.hpp"
   
   AxisInputStream::AxisInputStream(AxisIOStream* pInputStream)
  
  
  
  1.2       +5 -0      ws-axis/c/src/xml/tspp/Buffer.cpp
  
  Index: Buffer.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/xml/tspp/Buffer.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Buffer.cpp	8 Nov 2004 11:24:45 -0000	1.1
  +++ Buffer.cpp	12 Nov 2004 02:53:20 -0000	1.2
  @@ -15,5 +15,10 @@
    *   limitations under the License.                                              
    *                                                                         
    ***************************************************************************/
  +/*
  + *    @author Susantha Kumara (susantha@opensource.lk)
  + *    @author Dasarath Weerathunga
  + */
  +
   #include "Buffer.hpp"
   
  
  
  
  1.2       +7 -2      ws-axis/c/src/xml/tspp/Buffer.hpp
  
  Index: Buffer.hpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/xml/tspp/Buffer.hpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Buffer.hpp	8 Nov 2004 11:24:45 -0000	1.1
  +++ Buffer.hpp	12 Nov 2004 02:53:20 -0000	1.2
  @@ -15,6 +15,11 @@
    *   limitations under the License.                                              
    *                                                                         
    ***************************************************************************/
  +
  +/*
  + *    @author Dasarath Weerathunga
  + */
  +
   #if !defined(_BUFFER_HPP__INCLUDED_)
   #define _BUFFER_HPP__INCLUDED_
   
  @@ -45,9 +50,9 @@
   };
   
   template <class T>
  -Buffer<T>::Buffer(int size)
  +Buffer<T>::Buffer(int iSize)
   {
  -	this->size= size;
  +	size= iSize;
   	buffer= (T *)malloc(sizeof(T)*size);
   	if (!buffer)
   		throw new XmlPullParserException();
  
  
  
  1.2       +5 -1      ws-axis/c/src/xml/tspp/InputStream.hpp
  
  Index: InputStream.hpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/xml/tspp/InputStream.hpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InputStream.hpp	8 Nov 2004 11:24:45 -0000	1.1
  +++ InputStream.hpp	12 Nov 2004 02:53:20 -0000	1.2
  @@ -16,7 +16,11 @@
    *                                                                         
    ***************************************************************************/
   
  - #if !defined(_INPUTSTREAM_HPP__INCLUDED_)
  +/*
  + *    @author Dasarath Weerathunga
  + */
  +
  +#if !defined(_INPUTSTREAM_HPP__INCLUDED_)
   #define _INPUTSTREAM_HPP__INCLUDED_
   
    class InputStream
  
  
  
  1.2       +98 -65    ws-axis/c/src/xml/tspp/XMLParserAxis.cpp
  
  Index: XMLParserAxis.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/xml/tspp/XMLParserAxis.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XMLParserAxis.cpp	8 Nov 2004 11:24:45 -0000	1.1
  +++ XMLParserAxis.cpp	12 Nov 2004 02:53:20 -0000	1.2
  @@ -25,13 +25,16 @@
   #endif
   
   #include "XMLParserAxis.hpp"
  - #include "AxisInputStream.hpp"
  +#include "AxisInputStream.hpp"
    
   XMLParserAxis::XMLParserAxis()
   {
   	m_bEndElementFollows = false;	
  -	m_pParser = NULL;
  -    m_pInputStream = NULL;
  +	m_pParser = 0;
  +    m_pInputStream = 0;
  +    m_Element.m_pchNamespace = 0;
  +    m_Element.m_pchNameOrValue = 0;
  +    m_Element.m_pchAttributes[0] = 0;
   }
   
   XMLParserAxis::~XMLParserAxis()
  @@ -39,27 +42,42 @@
       if (m_pParser)
           delete m_pParser;
   	if (m_pInputStream)
  -    	delete m_pParser;
  +    	delete m_pInputStream;
   }
   
   int XMLParserAxis::setInputStream(AxisIOStream* pInputStream)
   {
  -	m_bEndElementFollows = false;
  -    if (m_pInputStream)
  -        delete m_pInputStream;
  -    m_pInputStream = new AxisInputStream(pInputStream);
  -	//TODO : Reusing the same parser object should be possible. Improve the
  -	// parser and then remove the following.
  -	if (m_pParser)
  -		delete m_pParser;
  -	m_pParser = new XmlPullParser(m_pInputStream);
  -    return AXIS_SUCCESS;
  +    try 
  +    {
  +	    m_bEndElementFollows = false;
  +        if (m_pInputStream)
  +            delete m_pInputStream;
  +        m_pInputStream = new AxisInputStream(pInputStream);
  +	    //TODO : Reusing the same parser object should be possible. Improve the
  +	    // parser and then remove the following.
  +	    if (m_pParser)
  +		    delete m_pParser;
  +	    m_pParser = new XmlPullParser(m_pInputStream);
  +        return AXIS_SUCCESS;
  +    }
  +    catch(XmlPullParserException* pException)
  +    {
  +        delete pException;
  +        throw new AxisParseException();
  +    }
   }
   
   const XML_Ch* XMLParserAxis::getNS4Prefix(const XML_Ch* prefix)
   {
  -	//TODO : implement this correctly
  -    return NULL;
  +    try
  +    {
  +	    return m_pParser->getNamespace4Prefix(prefix);
  +    }
  +    catch(XmlPullParserException* pException)
  +    {
  +        delete pException;
  +        throw new AxisParseException();
  +    }
   }
   
   int XMLParserAxis::getStatus()
  @@ -124,53 +142,61 @@
   const AnyElement* XMLParserAxis::next(bool isCharData)
   {
   	int nType;
  -	freeElement();
  -	if (m_bEndElementFollows)
  -	{
  -		m_bEndElementFollows = false;
  -		return &m_Element;
  -	}
  -	while (true)
  -		{
  -			if ((nType= m_pParser->next()) != -1) 
  -			{
  -				if (!isCharData && (XmlPullParser::Content == nType))
  -				{ // ignorable white space
  -					continue;
  -				}			
  -				switch (nType)
  -				{
  -				case XmlPullParser::STag:
  -					m_Element.m_type = START_ELEMENT;
  -					m_Element.m_pchNameOrValue = m_pParser->getName();
  -					m_Element.m_pchNamespace = m_pParser->getNamespaceUri();
  -					setAttributes();
  -					break;
  -				case XmlPullParser::EmptyElemTag:
  -					m_Element.m_type = START_ELEMENT;
  -					m_Element.m_pchNameOrValue = m_pParser->getName();
  -					m_Element.m_pchNamespace = m_pParser->getNamespaceUri();
  -					setAttributes();
  -					m_bEndElementFollows = true;
  -					break;
  -				case XmlPullParser::ETag:
  -					m_Element.m_type = END_ELEMENT;
  -					m_Element.m_pchNameOrValue = m_pParser->getName();
  -					m_Element.m_pchNamespace = m_pParser->getNamespaceUri();
  -					break;
  -				case XmlPullParser::Content:
  -					m_Element.m_type = CHARACTER_ELEMENT;
  -					m_Element.m_pchNameOrValue = m_pParser->getCharData();
  -					break;
  -				default:;
  -				}
  -				return &m_Element;
  -			}
  -			else 
  -			{
  -				return NULL;
  -			}
  -		}
  +    try 
  +    {
  +	    freeElement();
  +	    if (m_bEndElementFollows)
  +	    {
  +		    m_bEndElementFollows = false;
  +		    return &m_Element;
  +	    }
  +	    while (true)
  +	    {
  +		    if ((nType= m_pParser->next()) != -1) 
  +		    {
  +			    if (!isCharData && (XmlPullParser::Content == nType))
  +			    { // ignorable white space
  +				    continue;
  +			    }			
  +			    switch (nType)
  +			    {
  +			    case XmlPullParser::STag:
  +				    m_Element.m_type = START_ELEMENT;
  +				    m_Element.m_pchNameOrValue = m_pParser->getName();
  +				    m_Element.m_pchNamespace = m_pParser->getNamespaceUri();
  +				    setAttributes();
  +				    break;
  +			    case XmlPullParser::EmptyElemTag:
  +				    m_Element.m_type = START_ELEMENT;
  +				    m_Element.m_pchNameOrValue = m_pParser->getName();
  +				    m_Element.m_pchNamespace = m_pParser->getNamespaceUri();
  +				    setAttributes();
  +				    m_bEndElementFollows = true;
  +				    break;
  +			    case XmlPullParser::ETag:
  +				    m_Element.m_type = END_ELEMENT;
  +				    m_Element.m_pchNameOrValue = m_pParser->getName();
  +				    m_Element.m_pchNamespace = m_pParser->getNamespaceUri();
  +				    break;
  +			    case XmlPullParser::Content:
  +				    m_Element.m_type = CHARACTER_ELEMENT;
  +				    m_Element.m_pchNameOrValue = m_pParser->getCharData();
  +				    break;
  +			    default:;
  +			    }
  +			    return &m_Element;
  +		    }
  +		    else 
  +		    {
  +			    return NULL;
  +		    }
  +	    }
  +    }
  +    catch(XmlPullParserException* pException)
  +    {
  +        delete pException;
  +        throw new AxisParseException();
  +    }
   }
   
   const AnyElement* XMLParserAxis::anyNext()
  @@ -182,7 +208,14 @@
   
   const XML_Ch* XMLParserAxis::getPrefix4NS(const XML_Ch* pcNS)
   {
  -	//TODO : implement this correctly
  -    return NULL;
  +    try
  +    {
  +        return m_pParser->getPrefix4Namespace(pcNS);
  +    }
  +    catch(XmlPullParserException* pException)
  +    {
  +        delete pException;
  +        throw new AxisParseException();
  +    }
   }
   
  
  
  
  1.3       +1 -4      ws-axis/c/src/xml/tspp/XMLParserAxis.hpp
  
  Index: XMLParserAxis.hpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/xml/tspp/XMLParserAxis.hpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XMLParserAxis.hpp	9 Nov 2004 10:29:05 -0000	1.2
  +++ XMLParserAxis.hpp	12 Nov 2004 02:53:20 -0000	1.3
  @@ -26,11 +26,8 @@
   #if !defined(__XMLPARSERAXIS_H_OF_AXIS_INCLUDED__)
   #define __XMLPARSERAXIS_H_OF_AXIS_INCLUDED__
   
  -// #include <axis/server/Packet.hpp>
  -// #include "../QName.h"
  -// #include "../Event.h"
   #include "../XMLParser.h"
  -// #include "../AxisParseException.h"
  +#include "../AxisParseException.h"
   
   #include "XmlPullParser.hpp"
   
  
  
  
  1.2       +47 -7     ws-axis/c/src/xml/tspp/XmlPullParser.cpp
  
  Index: XmlPullParser.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/xml/tspp/XmlPullParser.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XmlPullParser.cpp	8 Nov 2004 11:24:45 -0000	1.1
  +++ XmlPullParser.cpp	12 Nov 2004 02:53:20 -0000	1.2
  @@ -15,13 +15,19 @@
    *   limitations under the License.                                              
    *                                                                         
    ***************************************************************************/
  +
  +/*
  + *    @author Susantha Kumara (susantha@opensource.lk)
  + *    @author Dasarath Weerathunga
  + */
  +
   #include "XmlPullParser.hpp"
    
  - void XmlPullParser::relocateTokens(int offset)
  +void XmlPullParser::relocateTokens(int ioffset)
   {
   	int size= token->count();
   	for (int ii= 0; ii < size; ii++)
  -		(*token)[ii].relocate(offset);	
  +		(*token)[ii].relocate(ioffset);	
   }
   
   void XmlPullParser::shift()
  @@ -107,9 +113,9 @@
   }
   
   
  -XmlPullParser::XmlPullParser(InputStream *s)
  +XmlPullParser::XmlPullParser(InputStream *pStream)
   {
  -	this->s= s;
  +	this->s= pStream;
   	state= S_1;
   	offset= 0;
   	last= -1;
  @@ -388,6 +394,12 @@
   			}
   			_ns= resolve(_ns == -1 ? NULL : token->get());
   		}
  +        else if (XMLDecl == event) 
  +        {
  +            //Do not return this event. Process it for internal use only
  +            //Get and return next event.
  +            return next();
  +        }
   		return event;
   	}
   	return -1;
  @@ -437,7 +449,7 @@
   	ATTR &t= (*attr)[ii];
   	if (t.ns == -1)
   		t.ns= resolve(t.prefix == -1 ? NULL : token->get()+t.prefix);
  -	return strdup((*ns)[t.ns].uri);
  +    return (t.ns == -1) ? NULL : strdup((*ns)[t.ns].uri);
   }
   
   
  @@ -456,7 +468,11 @@
   		ii--;
   		p--;
   	}
  -	throw new XmlPullParserException();
  +//FIXME : Commented out following line because the parser fails when there are 
  +//        unqualified elements in xml which is IMO possible in SOAP - Susantha 
  +//        11/11/2004
  +//	throw new XmlPullParserException();
  +    return -1; //not resolved
   }
   
   
  @@ -510,6 +526,30 @@
   	else
   		if (_ns == 0xffff)
   			_ns= resolve(token->get());
  -	return strdup((*ns)[_ns].uri);
  +        return _ns == -1 ? NULL : strdup((*ns)[_ns].uri);
   }
   
  +
  +char* XmlPullParser::getNamespace4Prefix(const char *pcPrefix)
  +{
  +    for (int ix=ns->count()-1; ix >= 0; ix--)
  +    {
  +        if ((*ns)[ix].prefix && (0 == strcmp(pcPrefix, (*ns)[ix].prefix)))
  +        {
  +            return strdup((*ns)[ix].uri);
  +        }
  +    }
  +    return 0;
  +}
  +
  +char* XmlPullParser::getPrefix4Namespace(const char *pcNs)
  +{
  +    for (int ix=ns->count()-1; ix >= 0; ix--)
  +    {
  +        if ((*ns)[ix].uri && (0 == strcmp(pcNs, (*ns)[ix].uri)))
  +        {
  +            return strdup((*ns)[ix].prefix);
  +        }
  +    }
  +    return 0;
  +}
  
  
  
  1.2       +7 -0      ws-axis/c/src/xml/tspp/XmlPullParser.hpp
  
  Index: XmlPullParser.hpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/xml/tspp/XmlPullParser.hpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XmlPullParser.hpp	8 Nov 2004 11:24:45 -0000	1.1
  +++ XmlPullParser.hpp	12 Nov 2004 02:53:20 -0000	1.2
  @@ -16,6 +16,11 @@
    *                                                                         
    ***************************************************************************/
   
  +/*
  + *    @author Dasarath Weerathunga
  + *    @author Susantha Kumara (susantha@opensource.lk)
  + */
  +
   #if !defined(_XMLPULLPARSER_HPP__INCLUDED_)
   #define _XMLPULLPARSER_HPP__INCLUDED_
   
  @@ -127,6 +132,8 @@
   	int parseCharData();
   
   public:	
  +	char* getPrefix4Namespace(const char* pcNs);
  +	char* getNamespace4Prefix(const char* pcPrefix);
   	enum {
   		XMLDecl, STag, EmptyElemTag, ETag, Content
   	};
  
  
  
  1.2       +5 -0      ws-axis/c/src/xml/tspp/XmlPullParserException.cpp
  
  Index: XmlPullParserException.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/xml/tspp/XmlPullParserException.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XmlPullParserException.cpp	8 Nov 2004 11:24:45 -0000	1.1
  +++ XmlPullParserException.cpp	12 Nov 2004 02:53:20 -0000	1.2
  @@ -15,3 +15,8 @@
    *   limitations under the License.                                              
    *                                                                         
    ***************************************************************************/
  +
  +/*
  + *    @author Susantha Kumara (susantha@opensource.lk)
  + *    @author Dasarath Weerathunga
  + */
  
  
  
  1.2       +5 -0      ws-axis/c/src/xml/tspp/XmlPullParserException.hpp
  
  Index: XmlPullParserException.hpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/xml/tspp/XmlPullParserException.hpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XmlPullParserException.hpp	8 Nov 2004 11:24:45 -0000	1.1
  +++ XmlPullParserException.hpp	12 Nov 2004 02:53:20 -0000	1.2
  @@ -16,6 +16,11 @@
    *                                                                         
    ***************************************************************************/
   
  +/*
  + *    @author Susantha Kumara (susantha@opensource.lk)
  + *    @author Dasarath Weerathunga
  + */
  +
   #if !defined(_XMLPULLPARSEREXCEPTION_HPP__INCLUDED_)
   #define _XMLPULLPARSEREXCEPTION_HPP__INCLUDED_