2 * Licensed to the Apache Software Foundation (ASF) under one or more
\r
3 * contributor license agreements. See the NOTICE file distributed with
\r
4 * this work for additional information regarding copyright ownership.
\r
5 * The ASF licenses this file to You under the Apache License, Version 2.0
\r
6 * (the "License"); you may not use this file except in compliance with
\r
7 * the License. You may obtain a copy of the License at
\r
9 * http://www.apache.org/licenses/LICENSE-2.0
\r
11 * Unless required by applicable law or agreed to in writing, software
\r
12 * distributed under the License is distributed on an "AS IS" BASIS,
\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 * See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
19 * $Id: CurlURLInputStream.hpp 527149 2007-04-10 14:56:39Z amassari $
\r
22 #if !defined(XERCESC_INCLUDE_GUARD_CURLURLINPUTSTREAM_HPP)
\r
23 #define XERCESC_INCLUDE_GUARD_CURLURLINPUTSTREAM_HPP
\r
25 #include <curl/curl.h>
\r
26 #include <curl/multi.h>
\r
27 #include <curl/easy.h>
\r
29 #include <xercesc/util/XMLURL.hpp>
\r
30 #include <xercesc/util/XMLExceptMsgs.hpp>
\r
31 #include <xercesc/util/Janitor.hpp>
\r
32 #include <xercesc/util/BinInputStream.hpp>
\r
33 #include <xercesc/util/XMLNetAccessor.hpp>
\r
35 namespace xmltooling {
\r
38 // This class implements the BinInputStream interface specified by the XML
\r
42 class XMLTOOL_DLLLOCAL CurlURLInputStream : public BinInputStream
\r
45 CurlURLInputStream(const XMLURL& urlSource, const XMLNetHTTPInfo* httpInfo=0);
\r
46 ~CurlURLInputStream();
\r
48 unsigned int curPos() const;
\r
49 unsigned int readBytes
\r
51 XMLByte* const toFill
\r
52 , const unsigned int maxToRead
\r
57 // -----------------------------------------------------------------------
\r
58 // Unimplemented constructors and operators
\r
59 // -----------------------------------------------------------------------
\r
60 CurlURLInputStream(const CurlURLInputStream&);
\r
61 CurlURLInputStream& operator=(const CurlURLInputStream&);
\r
63 static size_t staticWriteCallback(char *buffer,
\r
67 size_t writeCallback( char *buffer,
\r
72 // -----------------------------------------------------------------------
\r
73 // Private data members
\r
76 // The socket representing the connection to the remote file.
\r
78 // Its a rolling count of the number of bytes processed off this
\r
81 // Holds the http header, plus the first part of the actual
\r
82 // data. Filled at the time the stream is opened, data goes
\r
83 // out to user in response to readBytes().
\r
84 // fBufferPos, fBufferEnd
\r
85 // Pointers into fBuffer, showing start and end+1 of content
\r
86 // that readBytes must return.
\r
87 // -----------------------------------------------------------------------
\r
92 MemoryManager* fMemoryManager;
\r
95 ArrayJanitor<char> fURL;
\r
97 unsigned long fTotalBytesRead;
\r
99 unsigned long fBytesRead;
\r
100 unsigned long fBytesToRead;
\r
101 bool fDataAvailable;
\r
103 // Overflow buffer for when curl writes more data to us
\r
104 // than we've asked for.
\r
105 XMLByte fBuffer[CURL_MAX_WRITE_SIZE];
\r
106 XMLByte* fBufferHeadPtr;
\r
107 XMLByte* fBufferTailPtr;
\r
109 }; // CurlURLInputStream
\r
112 inline unsigned int
\r
113 CurlURLInputStream::curPos() const
\r
115 return fTotalBytesRead;
\r
120 #endif // CURLURLINPUTSTREAM_HPP
\r