[188] | 1 | /*
|
---|
| 2 | * The Apache Software License, Version 1.1
|
---|
| 3 | *
|
---|
| 4 | * Copyright (c) 1999-2000 The Apache Software Foundation. All rights
|
---|
| 5 | * reserved.
|
---|
| 6 | *
|
---|
| 7 | * Redistribution and use in source and binary forms, with or without
|
---|
| 8 | * modification, are permitted provided that the following conditions
|
---|
| 9 | * are met:
|
---|
| 10 | *
|
---|
| 11 | * 1. Redistributions of source code must retain the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer.
|
---|
| 13 | *
|
---|
| 14 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
| 15 | * notice, this list of conditions and the following disclaimer in
|
---|
| 16 | * the documentation and/or other materials provided with the
|
---|
| 17 | * distribution.
|
---|
| 18 | *
|
---|
| 19 | * 3. The end-user documentation included with the redistribution,
|
---|
| 20 | * if any, must include the following acknowledgment:
|
---|
| 21 | * "This product includes software developed by the
|
---|
| 22 | * Apache Software Foundation (http://www.apache.org/)."
|
---|
| 23 | * Alternately, this acknowledgment may appear in the software itself,
|
---|
| 24 | * if and wherever such third-party acknowledgments normally appear.
|
---|
| 25 | *
|
---|
| 26 | * 4. The names "Xerces" and "Apache Software Foundation" must
|
---|
| 27 | * not be used to endorse or promote products derived from this
|
---|
| 28 | * software without prior written permission. For written
|
---|
| 29 | * permission, please contact apache\@apache.org.
|
---|
| 30 | *
|
---|
| 31 | * 5. Products derived from this software may not be called "Apache",
|
---|
| 32 | * nor may "Apache" appear in their name, without prior written
|
---|
| 33 | * permission of the Apache Software Foundation.
|
---|
| 34 | *
|
---|
| 35 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
---|
| 36 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 37 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
| 38 | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
---|
| 39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
| 40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
| 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
---|
| 42 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
| 43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
| 44 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
---|
| 45 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
| 46 | * SUCH DAMAGE.
|
---|
| 47 | * ====================================================================
|
---|
| 48 | *
|
---|
| 49 | * This software consists of voluntary contributions made by many
|
---|
| 50 | * individuals on behalf of the Apache Software Foundation, and was
|
---|
| 51 | * originally based on software copyright (c) 1999, International
|
---|
| 52 | * Business Machines, Inc., http://www.ibm.com . For more information
|
---|
| 53 | * on the Apache Software Foundation, please see
|
---|
| 54 | * <http://www.apache.org/>.
|
---|
| 55 | */
|
---|
| 56 |
|
---|
| 57 | /*
|
---|
| 58 | * $Log: BinHTTPURLInputStream.hpp,v $
|
---|
| 59 | * Revision 1.4 2004/01/29 11:51:20 cargilld
|
---|
| 60 | * Code cleanup changes to get rid of various compiler diagnostic messages.
|
---|
| 61 | *
|
---|
| 62 | * Revision 1.3 2003/12/17 00:18:37 cargilld
|
---|
| 63 | * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
|
---|
| 64 | *
|
---|
| 65 | * Revision 1.2 2002/11/04 15:11:39 tng
|
---|
| 66 | * C++ Namespace Support.
|
---|
| 67 | *
|
---|
| 68 | * Revision 1.1.1.1 2002/02/01 22:22:23 peiyongz
|
---|
| 69 | * sane_include
|
---|
| 70 | *
|
---|
| 71 | * Revision 1.5 2001/10/25 16:26:39 tng
|
---|
| 72 | * [Bug 4213] BinHTTPURLInputStream initialisation not thread safe. By Mark Weaver.
|
---|
| 73 | *
|
---|
| 74 | * Revision 1.4 2001/01/22 16:43:39 tng
|
---|
| 75 | * Loads winsock dynamically. Fixed by Curt Arnold.
|
---|
| 76 | * Winsock2 is not initialized unless an http URL is used. If an http
|
---|
| 77 | * URL is used and the Winsock 2 DLL is not installed, then an NetAccessor
|
---|
| 78 | * initialization exception is thrown.
|
---|
| 79 | *
|
---|
| 80 | * Revision 1.3 2000/07/21 03:22:45 andyh
|
---|
| 81 | * Improved (but still weak) http access by the parser.
|
---|
| 82 | * Windows only. UNIX will follow, probably tomorrow.
|
---|
| 83 | *
|
---|
| 84 | * Revision 1.2 2000/03/22 00:21:10 rahulj
|
---|
| 85 | * Now we throw exceptions when errors occur.
|
---|
| 86 | * Simplified the code, based on the assumption that
|
---|
| 87 | * the calling function will make sure that the buffer into
|
---|
| 88 | * which the data has to be read is large enough.
|
---|
| 89 | *
|
---|
| 90 | * Revision 1.1 2000/03/17 02:37:54 rahulj
|
---|
| 91 | * First cut at adding HTTP capability via native sockets.
|
---|
| 92 | * Still need to add:
|
---|
| 93 | * error handling capability, ports other than 80,
|
---|
| 94 | * escaped URL's
|
---|
| 95 | * Will add options in project file only when I am done with these
|
---|
| 96 | * above changes.
|
---|
| 97 | *
|
---|
| 98 | */
|
---|
| 99 |
|
---|
| 100 | #if !defined(BINHTTPURLINPUTSTREAM_HPP)
|
---|
| 101 | #define BINHTTPURLINPUTSTREAM_HPP
|
---|
| 102 |
|
---|
| 103 |
|
---|
| 104 | #include <xercesc/util/XMLURL.hpp>
|
---|
| 105 | #include <xercesc/util/XMLExceptMsgs.hpp>
|
---|
| 106 | #include <xercesc/util/BinInputStream.hpp>
|
---|
| 107 | #include <xercesc/util/Mutexes.hpp>
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 | //
|
---|
| 111 | // This class implements the BinInputStream interface specified by the XML
|
---|
| 112 | // parser.
|
---|
| 113 | //
|
---|
| 114 | struct hostent;
|
---|
| 115 | struct sockaddr;
|
---|
| 116 |
|
---|
| 117 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
| 118 |
|
---|
| 119 | class XMLUTIL_EXPORT BinHTTPURLInputStream : public BinInputStream
|
---|
| 120 | {
|
---|
| 121 | public :
|
---|
| 122 | BinHTTPURLInputStream(const XMLURL& urlSource);
|
---|
| 123 | ~BinHTTPURLInputStream();
|
---|
| 124 |
|
---|
| 125 | unsigned int curPos() const;
|
---|
| 126 | unsigned int readBytes
|
---|
| 127 | (
|
---|
| 128 | XMLByte* const toFill
|
---|
| 129 | , const unsigned int maxToRead
|
---|
| 130 | );
|
---|
| 131 |
|
---|
| 132 | static void Cleanup();
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 | private :
|
---|
| 136 | // -----------------------------------------------------------------------
|
---|
| 137 | // Unimplemented constructors and operators
|
---|
| 138 | // -----------------------------------------------------------------------
|
---|
| 139 | BinHTTPURLInputStream(const BinHTTPURLInputStream&);
|
---|
| 140 | BinHTTPURLInputStream& operator=(const BinHTTPURLInputStream&);
|
---|
| 141 | // -----------------------------------------------------------------------
|
---|
| 142 | // Private data members
|
---|
| 143 | //
|
---|
| 144 | // fSocketHandle
|
---|
| 145 | // The socket representing the connection to the remote file.
|
---|
| 146 | // We deliberately did not define the type to be SOCKET, so as to
|
---|
| 147 | // avoid bringing in any Windows header into this file.
|
---|
| 148 | // fBytesProcessed
|
---|
| 149 | // Its a rolling count of the number of bytes processed off this
|
---|
| 150 | // input stream.
|
---|
| 151 | // fBuffer
|
---|
| 152 | // Holds the http header, plus the first part of the actual
|
---|
| 153 | // data. Filled at the time the stream is opened, data goes
|
---|
| 154 | // out to user in response to readBytes().
|
---|
| 155 | // fBufferPos, fBufferEnd
|
---|
| 156 | // Pointers into fBuffer, showing start and end+1 of content
|
---|
| 157 | // that readBytes must return.
|
---|
| 158 | // -----------------------------------------------------------------------
|
---|
| 159 | MemoryManager* fMemoryManager;
|
---|
| 160 | unsigned int fSocketHandle;
|
---|
| 161 | unsigned int fBytesProcessed;
|
---|
| 162 | char fBuffer[4000];
|
---|
| 163 | char * fBufferEnd;
|
---|
| 164 | char * fBufferPos;
|
---|
| 165 | static bool fInitialized;
|
---|
| 166 | static XMLMutex* fInitMutex;
|
---|
| 167 |
|
---|
| 168 | static void Initialize(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
| 169 |
|
---|
| 170 | inline static hostent* gethostbyname(const char* name);
|
---|
| 171 | inline static unsigned long inet_addr(const char* cp);
|
---|
| 172 | inline static hostent* gethostbyaddr(const char* addr,int len,int type);
|
---|
| 173 | inline static unsigned short htons(unsigned short hostshort);
|
---|
| 174 | inline static unsigned short socket(int af,int type,int protocol);
|
---|
| 175 | inline static int connect(unsigned short s,const sockaddr* name,int namelen);
|
---|
| 176 | inline static int send(unsigned short s,const char* buf,int len,int flags);
|
---|
| 177 | inline static int recv(unsigned short s,char* buf,int len,int flags);
|
---|
| 178 | inline static int shutdown(unsigned int s,int how);
|
---|
| 179 | inline static int closesocket(unsigned int socket);
|
---|
| 180 | };
|
---|
| 181 |
|
---|
| 182 |
|
---|
| 183 | inline unsigned int BinHTTPURLInputStream::curPos() const
|
---|
| 184 | {
|
---|
| 185 | return fBytesProcessed;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | XERCES_CPP_NAMESPACE_END
|
---|
| 189 |
|
---|
| 190 | #endif // BINHTTPURLINPUTSTREAM_HPP
|
---|