source: icXML/icXML-devel/src/xercesc/util/NetAccessors/Curl/CurlURLInputStream.hpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 4.3 KB
Line 
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: CurlURLInputStream.hpp 835245 2009-11-12 05:57:31Z borisk $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_CURLURLINPUTSTREAM_HPP)
23#define XERCESC_INCLUDE_GUARD_CURLURLINPUTSTREAM_HPP
24
25#include <curl/curl.h>
26#include <curl/multi.h>
27#include <curl/easy.h>
28
29#include <xercesc/util/XMLURL.hpp>
30#include <xercesc/util/XMLExceptMsgs.hpp>
31#include <xercesc/util/Janitor.hpp>
32#include <xercesc/util/BinInputStream.hpp>
33#include <xercesc/util/XMLNetAccessor.hpp>
34
35XERCES_CPP_NAMESPACE_BEGIN
36
37//
38// This class implements the BinInputStream interface specified by the XML
39// parser.
40//
41
42class XMLUTIL_EXPORT CurlURLInputStream : public BinInputStream
43{
44public :
45    CurlURLInputStream(const XMLURL&  urlSource, const XMLNetHTTPInfo* httpInfo=0);
46    ~CurlURLInputStream();
47
48    virtual XMLFilePos curPos() const;
49    virtual XMLSize_t readBytes
50    (
51                XMLByte* const  toFill
52        , const XMLSize_t       maxToRead
53    );
54
55    virtual const XMLCh *getContentType() const;
56
57private :
58    // -----------------------------------------------------------------------
59    //  Unimplemented constructors and operators
60    // -----------------------------------------------------------------------
61    CurlURLInputStream(const CurlURLInputStream&);
62    CurlURLInputStream& operator=(const CurlURLInputStream&);
63   
64    static size_t staticWriteCallback(char *buffer,
65                                      size_t size,
66                                      size_t nitems,
67                                      void *outstream);
68    size_t writeCallback(                         char *buffer,
69                                      size_t size,
70                                      size_t nitems);
71
72    static size_t staticReadCallback(char *buffer,
73                                     size_t size,
74                                     size_t nitems,
75                                     void *stream);
76    size_t readCallback(             char *buffer,
77                                     size_t size,
78                                     size_t nitems);
79
80    bool readMore(int *runningHandles);
81
82    // -----------------------------------------------------------------------
83    //  Private data members
84    //
85    //  fSocket
86    //      The socket representing the connection to the remote file.
87    //  fBytesProcessed
88    //      Its a rolling count of the number of bytes processed off this
89    //      input stream.
90    //  fBuffer
91    //      Holds the http header, plus the first part of the actual
92    //      data.  Filled at the time the stream is opened, data goes
93    //      out to user in response to readBytes().
94    //  fBufferPos, fBufferEnd
95    //      Pointers into fBuffer, showing start and end+1 of content
96    //      that readBytes must return.
97    // -----------------------------------------------------------------------
98       
99    CURLM*                              fMulti;
100    CURL*                               fEasy;
101   
102    MemoryManager*      fMemoryManager;
103   
104    XMLURL                              fURLSource;
105   
106    XMLSize_t           fTotalBytesRead;
107    XMLByte*                    fWritePtr;
108    XMLSize_t           fBytesRead;
109    XMLSize_t           fBytesToRead;
110    bool                                fDataAvailable;
111   
112    // Overflow buffer for when curl writes more data to us
113    // than we've asked for.
114    XMLByte                             fBuffer[CURL_MAX_WRITE_SIZE];
115    XMLByte*                    fBufferHeadPtr;
116    XMLByte*                    fBufferTailPtr;
117
118    // Upload data
119    const char*         fPayload;
120    XMLSize_t           fPayloadLen;
121
122    XMLCh *             fContentType;
123   
124}; // CurlURLInputStream
125
126
127inline XMLFilePos
128CurlURLInputStream::curPos() const
129{
130    return fTotalBytesRead;
131}
132
133XERCES_CPP_NAMESPACE_END
134
135#endif // CURLURLINPUTSTREAM_HPP
136
Note: See TracBrowser for help on using the repository browser.