[2674] | 1 | /* |
---|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
| 3 | * contributor license agreements. See the NOTICE file distributed with |
---|
| 4 | * this work for additional information regarding copyright ownership. |
---|
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
| 6 | * (the "License"); you may not use this file except in compliance with |
---|
| 7 | * the License. You may obtain a copy of the License at |
---|
| 8 | * |
---|
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 10 | * |
---|
| 11 | * Unless required by applicable law or agreed to in writing, software |
---|
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 14 | * See the License for the specific language governing permissions and |
---|
| 15 | * limitations under the License. |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | /* |
---|
| 19 | * $Id: BinHTTPURLInputStream.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #if !defined(BINHTTPURLINPUTSTREAM_HPP) |
---|
| 23 | #define BINHTTPURLINPUTSTREAM_HPP |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | #include <xercesc/util/XMLURL.hpp> |
---|
| 27 | #include <xercesc/util/XMLExceptMsgs.hpp> |
---|
| 28 | #include <xercesc/util/BinInputStream.hpp> |
---|
| 29 | #include <xercesc/util/Mutexes.hpp> |
---|
| 30 | #include <xercesc/util/XMLNetAccessor.hpp> |
---|
| 31 | |
---|
| 32 | // |
---|
| 33 | // This class implements the BinInputStream interface specified by the XML |
---|
| 34 | // parser. |
---|
| 35 | // |
---|
| 36 | struct hostent; |
---|
| 37 | struct sockaddr; |
---|
| 38 | |
---|
| 39 | XERCES_CPP_NAMESPACE_BEGIN |
---|
| 40 | |
---|
| 41 | class XMLUTIL_EXPORT BinHTTPURLInputStream : public BinInputStream |
---|
| 42 | { |
---|
| 43 | public : |
---|
| 44 | BinHTTPURLInputStream(const XMLURL& urlSource, const XMLNetHTTPInfo* httpInfo=0); |
---|
| 45 | ~BinHTTPURLInputStream(); |
---|
| 46 | |
---|
| 47 | unsigned int curPos() const; |
---|
| 48 | unsigned int readBytes |
---|
| 49 | ( |
---|
| 50 | XMLByte* const toFill |
---|
| 51 | , const unsigned int maxToRead |
---|
| 52 | ); |
---|
| 53 | |
---|
| 54 | static void Cleanup(); |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | private : |
---|
| 58 | // ----------------------------------------------------------------------- |
---|
| 59 | // Unimplemented constructors and operators |
---|
| 60 | // ----------------------------------------------------------------------- |
---|
| 61 | BinHTTPURLInputStream(const BinHTTPURLInputStream&); |
---|
| 62 | BinHTTPURLInputStream& operator=(const BinHTTPURLInputStream&); |
---|
| 63 | // ----------------------------------------------------------------------- |
---|
| 64 | // Private data members |
---|
| 65 | // |
---|
| 66 | // fSocketHandle |
---|
| 67 | // The socket representing the connection to the remote file. |
---|
| 68 | // We deliberately did not define the type to be SOCKET, so as to |
---|
| 69 | // avoid bringing in any Windows header into this file. |
---|
| 70 | // fBytesProcessed |
---|
| 71 | // Its a rolling count of the number of bytes processed off this |
---|
| 72 | // input stream. |
---|
| 73 | // fBuffer |
---|
| 74 | // Holds the http header, plus the first part of the actual |
---|
| 75 | // data. Filled at the time the stream is opened, data goes |
---|
| 76 | // out to user in response to readBytes(). |
---|
| 77 | // fBufferPos, fBufferEnd |
---|
| 78 | // Pointers into fBuffer, showing start and end+1 of content |
---|
| 79 | // that readBytes must return. |
---|
| 80 | // ----------------------------------------------------------------------- |
---|
| 81 | MemoryManager* fMemoryManager; |
---|
| 82 | unsigned int fSocketHandle; |
---|
| 83 | unsigned int fBytesProcessed; |
---|
| 84 | char fBuffer[4000]; |
---|
| 85 | char * fBufferEnd; |
---|
| 86 | char * fBufferPos; |
---|
| 87 | static bool fInitialized; |
---|
| 88 | static XMLMutex* fInitMutex; |
---|
| 89 | |
---|
| 90 | static void Initialize(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
---|
| 91 | |
---|
| 92 | inline static hostent* gethostbyname(const char* name); |
---|
| 93 | inline static unsigned long inet_addr(const char* cp); |
---|
| 94 | inline static hostent* gethostbyaddr(const char* addr,int len,int type); |
---|
| 95 | inline static unsigned short htons(unsigned short hostshort); |
---|
| 96 | inline static unsigned int socket(int af,int type,int protocol); |
---|
| 97 | inline static int connect(unsigned int s,const sockaddr* name,int namelen); |
---|
| 98 | inline static int send(unsigned int s,const char* buf,int len,int flags); |
---|
| 99 | inline static int recv(unsigned int s,char* buf,int len,int flags); |
---|
| 100 | inline static int shutdown(unsigned int s,int how); |
---|
| 101 | inline static int closesocket(unsigned int socket); |
---|
| 102 | |
---|
| 103 | friend class SocketJanitor; |
---|
| 104 | }; |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | inline unsigned int BinHTTPURLInputStream::curPos() const |
---|
| 108 | { |
---|
| 109 | return fBytesProcessed; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | XERCES_CPP_NAMESPACE_END |
---|
| 113 | |
---|
| 114 | #endif // BINHTTPURLINPUTSTREAM_HPP |
---|