[GME-commit] GMESRC/GME/Include/xercesc/util/NetAccessors/MacOSURLAccess MacOSURLAccess.cpp, NONE, 1.1 MacOSURLAccess.hpp, NONE, 1.1 Makefile.in, NONE, 1.1 URLAccessBinInputStream.cpp, NONE, 1.1 URLAccessBinInputStream.hpp, NONE, 1.1

Log messages of CVS commits gme-commit at list.isis.vanderbilt.edu
Tue Feb 19 14:16:30 CST 2008


Update of /project/gme-repository/GMESRC/GME/Include/xercesc/util/NetAccessors/MacOSURLAccess
In directory escher:/tmp/cvs-serv26529/util/NetAccessors/MacOSURLAccess

Added Files:
	MacOSURLAccess.cpp MacOSURLAccess.hpp Makefile.in 
	URLAccessBinInputStream.cpp URLAccessBinInputStream.hpp 
Log Message:
Xerces2.7 includes checkin.


CVS User: Zoltan Molnar, ISIS (zolmol)

--- NEW FILE: Makefile.in ---
#
# Copyright 1999-2000,2004 The Apache Software Foundation.
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#      http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
#
# $Log: Makefile.in,v $
# Revision 1.1  2008/02/19 20:16:28  zolmol
# Xerces2.7 includes checkin.
#
# Revision 1.4  2004/09/08 13:56:34  peiyongz
# Apache License Version 2.0
#
# Revision 1.3  2004/07/09 16:17:18  peiyongz
# Build on HP-Itanium, aCC A.05.52
#
# Revision 1.2  2002/07/26 16:49:28  tng
# [Bug 2681] Can't build with gcc/g++ not named 'gcc'/'g++'.  Patch from Jonathan Lennox.
#
# Revision 1.1.1.1  2002/02/01 22:22:23  peiyongz
# sane_include
#
# Revision 1.3  2001/07/06 17:12:00  tng
# Automatic build of single-threaded library.  By Martin Kalen.
#
#
#
PLATFORM = @platform@
CC  = @cc@
CXX = @cxx@
CXXVER = @cxxver@
GCC = @GCC@
GXX = @GXX@
CXXFLAGS = @cxxflags@
CFLAGS = @cflags@
PREFIX = @prefix@
PREFIX_INCLUDE = @prefix_include@
LDFLAGS = @ldflags@
LIBS = @libs@
OSVER = @osver@
USELIBWWW = @uselibwww@
MESSAGELOADER = @messageloader@
TRANSCODER = @transcoder@
NETACCESSOR = @netaccessor@
THREADS = @threads@

MODULE = util
SUBMODULE = NetAccessors/MacOSURLAccess

include ../../../Makefile.incl

CPP_PUBHEADERS = \
	MacOSURLAccess.hpp \
	URLAccessBinInputStream.hpp

CPP_OBJECTS = \
	MacOSURLAccess.$(TO) \
	URLAccessBinInputStream.$(TO)

include ../../Makefile.util.submodule

--- NEW FILE: URLAccessBinInputStream.hpp ---
/*
 * Copyright 1999-2000,2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * $Id: URLAccessBinInputStream.hpp,v 1.1 2008/02/19 20:16:28 zolmol Exp $
 */

#if !defined(URLACCESSBININPUTSTREAM_HPP)
#define URLACCESSBININPUTSTREAM_HPP


#include <xercesc/util/XMLURL.hpp>
#include <xercesc/util/XMLExceptMsgs.hpp>
#include <xercesc/util/BinInputStream.hpp>

#if defined(__APPLE__)
    //	Framework includes from ProjectBuilder
	#include <Carbon/Carbon.h>
#else
    //	Classic includes otherwise
	#include <URLAccess.h>
#endif

XERCES_CPP_NAMESPACE_BEGIN

//
// This class implements the BinInputStream interface specified by the XML
// parser.
//

class XMLUTIL_EXPORT URLAccessBinInputStream : public BinInputStream
{
public :
    URLAccessBinInputStream(const XMLURL&  urlSource);
    ~URLAccessBinInputStream();

    unsigned int curPos() const;
    unsigned int readBytes
    (
                XMLByte* const  toFill
        , const unsigned int    maxToRead
    );


private :
    unsigned int        mBytesProcessed;
    URLReference		mURLReference;
    void*				mBuffer;			// Current buffer from URLAccess (or NULL)
    char*				mBufPos;			// Read position in buffer
    Size				mBufAvailable;		// Bytes available
};


inline unsigned int
URLAccessBinInputStream::curPos() const
{
    return mBytesProcessed;
}

XERCES_CPP_NAMESPACE_END

#endif // URLACCESSBININPUTSTREAM_HPP

--- NEW FILE: URLAccessBinInputStream.cpp ---
/*
 * Copyright 1999-2000,2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * $Id: URLAccessBinInputStream.cpp,v 1.1 2008/02/19 20:16:28 zolmol Exp $
 */


#include <xercesc/util/XMLNetAccessor.hpp>
#include <xercesc/util/NetAccessors/MacOSURLAccess/URLAccessBinInputStream.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/XMLExceptMsgs.hpp>
#include <xercesc/util/Janitor.hpp>

#include <cstdlib>
#include <cstring>

XERCES_CPP_NAMESPACE_BEGIN

URLAccessBinInputStream::URLAccessBinInputStream(const XMLURL& urlSource)
      : mBytesProcessed(0),
        mURLReference(NULL),
        mBuffer(NULL),
        mBufPos(NULL),
        mBufAvailable(0)
{
	OSStatus status = noErr;
	
	//	Get the full URL from the source
    char*               url = XMLString::transcode(urlSource.getURLText(), urlSource.getMemoryManager());
    ArrayJanitor<char>  janBuf(url, urlSource.getMemoryManager());

	//	Create a URL reference from the URL
	status = URLNewReference(url, &mURLReference);
	
	//	Begin the transfer
	if (status == noErr)
		status = URLOpen(
					mURLReference,
					NULL,	// FSSpec* (not reading to file)
					0, 		// URLOpenFlags
					NULL,	// URLNotifyUPP
					0,		// URLEventMask
					0);		// userContext
	
	//	If we failed, we throw
	switch (status)
	{
		case noErr:
			break;
			
		case kURLInvalidURLError:
        	ThrowXML(MalformedURLException, XMLExcepts::URL_MalformedURL);
			break;
		case kURLUnsupportedSchemeError:
        	ThrowXML(MalformedURLException, XMLExcepts::URL_UnsupportedProto);
			break;
		
		default:
        	ThrowXML1(NetAccessorException, XMLExcepts::NetAcc_ConnSocket, urlSource.getURLText());
        	break;
	}
}



URLAccessBinInputStream::~URLAccessBinInputStream()
{
	OSStatus status = noErr;
	
	//	Release any buffer we've still got a hold of
	if (status == noErr && mBuffer)
	{
		status = URLReleaseBuffer(mURLReference, mBuffer);
		mBuffer = NULL;
	}

	//	Get the current state
	URLState state = 0;
	if (status == noErr)
		status = URLGetCurrentState(mURLReference, &state);
	
	//	Abort if we're not completed
	if (status == noErr && state != kURLNullState && state != kURLCompletedState)
		status = URLAbort(mURLReference);
		
	//	Loop til we reach a terminal state.
	//	This may be unneeded by URLAccess, but the docs are
	//	not very good.
	while (
			status == noErr
		 && state != kURLNullState
		 && state != kURLErrorOccurredState
		 && state != kURLCompletedState
		  )
	{
		status = URLIdle();
		if (status == noErr)
			status = URLGetCurrentState(mURLReference, &state);
	}
		
	//	Dispose the reference
	status = URLDisposeReference(mURLReference);
}


//
//	Call URLAccess to fullfill the read request. Since it
//	passes us back buffers full of data, our object maintains
//	a partial buffer across calls.
//
unsigned int
URLAccessBinInputStream::readBytes(XMLByte* const    toFill
                                    , const unsigned int    maxToRead)
{
	OSStatus status = noErr;

	XMLByte* writePos			= toFill;
	std::size_t bytesDesired	= maxToRead;
	URLState state				= kURLNullState;
	
	while (												// while...
			status == noErr								// there's been no error
		 && bytesDesired > 0							// more data is wanted
		 && (status = URLGetCurrentState(mURLReference, &state)) == noErr	// we can get the state
		 && (state != kURLErrorOccurredState)			// no error has occurred in the transaction
		 && (mBuffer || state != kURLCompletedState)	// we have data still buffered or the request isn't complete
		 && (mBuffer || bytesDesired == maxToRead)		// we have data still buffered or we've supplied absolutely none
		  )
	{
		//	Give time to URLAccess
		status = URLIdle();
		
		//	If we've got buffered data, use it
		if (status == noErr && mBuffer)
		{
			//	Supply as much as we can from the buffer
			std::size_t n = mBufAvailable;
			if (n > bytesDesired)
				n = bytesDesired;
				
			//	If we've got data, copy it over and update our pointers
			if (n > 0)
			{
				std::memcpy(writePos, mBufPos, n);
				
				writePos		+= n;
				bytesDesired	-= n;
				
				mBufPos			+= n;
				mBufAvailable	-= n;
				
				mBytesProcessed	+= n;
			}
			
			//	If we exhausted the buffer, release it
			if (mBufAvailable == 0)
			{
				status = URLReleaseBuffer(mURLReference, mBuffer);
				mBuffer = NULL;
			}
		}
		
		//	If the buffer is exhausted, get a new one
		if (status == noErr && !mBuffer)
		{
			status = URLGetBuffer(mURLReference, &mBuffer, &mBufAvailable);
			if (status == noErr)
				mBufPos = reinterpret_cast<char*>(mBuffer);
		}
	}
	
	//	Throw on any error
	if (status != noErr || state == kURLErrorOccurredState)
	    ThrowXML(NetAccessorException, XMLExcepts::NetAcc_ReadSocket);
	
	//	Return number of bytes delivered
	return maxToRead - bytesDesired;
}

XERCES_CPP_NAMESPACE_END

--- NEW FILE: MacOSURLAccess.hpp ---
/*
 * Copyright 1999-2000,2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * $Id: MacOSURLAccess.hpp,v 1.1 2008/02/19 20:16:28 zolmol Exp $
 */


#if !defined(MACOSURLACCESS_HPP)
#define MACOSURLACCESS_HPP


#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/util/XMLURL.hpp>
#include <xercesc/util/BinInputStream.hpp>
#include <xercesc/util/XMLNetAccessor.hpp>

XERCES_CPP_NAMESPACE_BEGIN

//
// This class is the wrapper for the Mac OS URLAccess code
// which provides access to network resources.
// It's being used here to add the ability to
// use HTTP URL's as the system id's in the XML decl clauses.
//

class XMLUTIL_EXPORT MacOSURLAccess : public XMLNetAccessor
{
public :
    MacOSURLAccess();
    ~MacOSURLAccess();

    BinInputStream* makeNew(const XMLURL&  urlSource, const XMLNetHTTPInfo* httpInfo=0);
    const XMLCh* getId() const;

private :
    static const XMLCh sMyID[];

    MacOSURLAccess(const MacOSURLAccess&);
    MacOSURLAccess& operator=(const MacOSURLAccess&);

};

inline const XMLCh*
MacOSURLAccess::getId() const
{
    return sMyID;
}


XERCES_CPP_NAMESPACE_END


#endif // MACOSURLACCESS_HPP

--- NEW FILE: MacOSURLAccess.cpp ---
/*
 * Copyright 1999-2000,2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * $Id: MacOSURLAccess.cpp,v 1.1 2008/02/19 20:16:28 zolmol Exp $
 */


#include <xercesc/util/XMLUni.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/XMLExceptMsgs.hpp>
#include <xercesc/util/NetAccessors/MacOSURLAccess/MacOSURLAccess.hpp>
#include <xercesc/util/NetAccessors/MacOSURLAccess/URLAccessBinInputStream.hpp>

XERCES_CPP_NAMESPACE_BEGIN

const XMLCh
MacOSURLAccess::sMyID[] =
{
    chLatin_M, chLatin_a, chLatin_c, chLatin_O, chLatin_S, chLatin_U,
    chLatin_R, chLatin_L, chLatin_A, chLatin_c, chLatin_c, chLatin_e,
    chLatin_s, chLatin_s,
    chNull
};


MacOSURLAccess::MacOSURLAccess()
{
	//	Ensure that we've got URLAccess
	if (!URLAccessAvailable())
        ThrowXML(NetAccessorException, XMLExcepts::NetAcc_InitFailed);
}


MacOSURLAccess::~MacOSURLAccess()
{
}


BinInputStream*
MacOSURLAccess::makeNew(const XMLURL&  urlSource, const XMLNetHTTPInfo* httpInfo/*=0*/)
{
	if(httpInfo!=0 && httpInfo->fHTTPMethod!=XMLNetHTTPInfo::GET)
		ThrowXML(NetAccessorException, XMLExcepts::NetAcc_UnsupportedMethod);
	//	We just go ahead and try to create a URLAccess stream
	//	from this source. That's the correct place to verify
	//	whether or not we can really handle this URL type...
	//	if it throws, well, it throws ;)
	BinInputStream* result = new (urlSource.getMemoryManager()) URLAccessBinInputStream(urlSource);
	return result;
}

XERCES_CPP_NAMESPACE_END




More information about the GME-commit mailing list