You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by jb...@locus.apache.org on 2000/07/29 07:30:01 UTC
cvs commit: xml-xerces/c/src/util/NetAccessors/MacOSURLAccess MacOSURLAccess.cpp MacOSURLAccess.hpp URLAccessBinInputStream.cpp URLAccessBinInputStream.hpp
jberry 00/07/28 22:30:01
Added: c/src/util/NetAccessors/MacOSURLAccess MacOSURLAccess.cpp
MacOSURLAccess.hpp URLAccessBinInputStream.cpp
URLAccessBinInputStream.hpp
Log:
Addition of NetAccessor functionality for MacOS, built on URLAccess library
Revision Changes Path
1.1 xml-xerces/c/src/util/NetAccessors/MacOSURLAccess/MacOSURLAccess.cpp
Index: MacOSURLAccess.cpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache\@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation, and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.ibm.com . For more information
* on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* Written by James D. Berry 7/20/00
* Critical Path Software, Inc.
*/
/*
* $Log: MacOSURLAccess.cpp,v $
* Revision 1.1 2000/07/29 05:30:00 jberry
* Addition of NetAccessor functionality for MacOS, built on URLAccess library
*
*
*/
#include <util/XMLUni.hpp>
#include <util/XMLUniDefs.hpp>
#include <util/XMLString.hpp>
#include <util/XMLExceptMsgs.hpp>
#include <util/NetAccessors/MacOSURLAccess/MacOSURLAccess.hpp>
#include <util/NetAccessors/MacOSURLAccess/URLAccessBinInputStream.hpp>
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)
{
// 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 URLAccessBinInputStream(urlSource);
return result;
}
1.1 xml-xerces/c/src/util/NetAccessors/MacOSURLAccess/MacOSURLAccess.hpp
Index: MacOSURLAccess.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache\@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation, and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.ibm.com . For more information
* on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* Written by James D. Berry 7/20/00
* Critical Path Software, Inc.
*/
/*
* $Log: MacOSURLAccess.hpp,v $
* Revision 1.1 2000/07/29 05:30:00 jberry
* Addition of NetAccessor functionality for MacOS, built on URLAccess library
*
*/
#if !defined(MACOSURLACCESS_HPP)
#define MACOSURLACCESS_HPP
#include <util/XercesDefs.hpp>
#include <util/XMLURL.hpp>
#include <util/BinInputStream.hpp>
#include <util/XMLNetAccessor.hpp>
//
// 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 XMLCh* getId() const;
private :
static const XMLCh sMyID[];
MacOSURLAccess(const MacOSURLAccess&);
void operator=(const MacOSURLAccess&);
};
inline const XMLCh*
MacOSURLAccess::getId() const
{
return sMyID;
}
#endif // MACOSURLACCESS_HPP
1.1 xml-xerces/c/src/util/NetAccessors/MacOSURLAccess/URLAccessBinInputStream.cpp
Index: URLAccessBinInputStream.cpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache\@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation, and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.ibm.com . For more information
* on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* Written by James D. Berry 7/20/00
* Critical Path Software, Inc.
*/
/*
* $Log: URLAccessBinInputStream.cpp,v $
* Revision 1.1 2000/07/29 05:30:00 jberry
* Addition of NetAccessor functionality for MacOS, built on URLAccess library
*
*
*/
#include <util/XMLNetAccessor.hpp>
#include <util/NetAccessors/MacOSURLAccess/URLAccessBinInputStream.hpp>
#include <util/XMLString.hpp>
#include <util/XMLExceptMsgs.hpp>
#include <util/Janitor.hpp>
#include <cstdlib>
#include <cstring>
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());
ArrayJanitor<char> janBuf(url);
// 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:
ThrowXML(NetAccessorException, XMLExcepts::NetAcc_ConnSocket);
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;
}
1.1 xml-xerces/c/src/util/NetAccessors/MacOSURLAccess/URLAccessBinInputStream.hpp
Index: URLAccessBinInputStream.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache\@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation, and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.ibm.com . For more information
* on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* Written by James D. Berry 7/20/00
* Critical Path Software, Inc.
*/
/*
* $Log: URLAccessBinInputStream.hpp,v $
* Revision 1.1 2000/07/29 05:30:00 jberry
* Addition of NetAccessor functionality for MacOS, built on URLAccess library
*
*
*/
#if !defined(URLACCESSBININPUTSTREAM_HPP)
#define URLACCESSBININPUTSTREAM_HPP
#include <util/XMLURL.hpp>
#include <util/XMLExceptMsgs.hpp>
#include <util/BinInputStream.hpp>
#include <URLAccess.h>
//
// 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;
}
#endif // URLACCESSBININPUTSTREAM_HPP