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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #if !defined(XERCESC_INCLUDE_GUARD_CURLURLINPUTSTREAM_HPP) && !defined(XMLTOOLING_LITE)
23 #define XERCESC_INCLUDE_GUARD_CURLURLINPUTSTREAM_HPP
25 #include <xmltooling/logging.h>
27 #include <curl/curl.h>
28 #include <curl/multi.h>
29 #include <curl/easy.h>
31 #include <xercesc/util/XMLURL.hpp>
32 #include <xercesc/util/XMLExceptMsgs.hpp>
33 #include <xercesc/util/Janitor.hpp>
34 #include <xercesc/util/BinInputStream.hpp>
35 #include <xercesc/util/XMLNetAccessor.hpp>
37 namespace xmltooling {
40 // This class implements the BinInputStream interface specified by the XML
44 class XMLTOOL_API CurlURLInputStream : public BinInputStream
47 CurlURLInputStream(const XMLURL& urlSource, const XMLNetHTTPInfo* httpInfo=0);
48 ~CurlURLInputStream();
50 unsigned int curPos() const;
51 unsigned int readBytes
54 , const unsigned int maxToRead
59 // -----------------------------------------------------------------------
60 // Unimplemented constructors and operators
61 // -----------------------------------------------------------------------
62 CurlURLInputStream(const CurlURLInputStream&);
63 CurlURLInputStream& operator=(const CurlURLInputStream&);
65 static size_t staticWriteCallback(char *buffer,
69 size_t writeCallback( char *buffer,
74 // -----------------------------------------------------------------------
75 // Private data members
78 // The socket representing the connection to the remote file.
80 // Its a rolling count of the number of bytes processed off this
83 // Holds the http header, plus the first part of the actual
84 // data. Filled at the time the stream is opened, data goes
85 // out to user in response to readBytes().
86 // fBufferPos, fBufferEnd
87 // Pointers into fBuffer, showing start and end+1 of content
88 // that readBytes must return.
89 // -----------------------------------------------------------------------
94 MemoryManager* fMemoryManager;
97 ArrayJanitor<char> fURL;
99 unsigned long fTotalBytesRead;
101 unsigned long fBytesRead;
102 unsigned long fBytesToRead;
105 // Overflow buffer for when curl writes more data to us
106 // than we've asked for.
107 XMLByte fBuffer[CURL_MAX_WRITE_SIZE];
108 XMLByte* fBufferHeadPtr;
109 XMLByte* fBufferTailPtr;
111 logging::Category& m_log;
113 }; // CurlURLInputStream
117 CurlURLInputStream::curPos() const
119 return fTotalBytesRead;
124 #endif // CURLURLINPUTSTREAM_HPP