Add internal copy of the Xerces net accessor for libcurl, to get SSL support.
[shibboleth/cpp-xmltooling.git] / xmltooling / util / CurlURLInputStream.h
1 /*\r
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
8  * \r
9  *      http://www.apache.org/licenses/LICENSE-2.0\r
10  * \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
16  */\r
17 \r
18 /*\r
19  * $Id: CurlURLInputStream.hpp 527149 2007-04-10 14:56:39Z amassari $\r
20  */\r
21 \r
22 #if !defined(XERCESC_INCLUDE_GUARD_CURLURLINPUTSTREAM_HPP)\r
23 #define XERCESC_INCLUDE_GUARD_CURLURLINPUTSTREAM_HPP\r
24 \r
25 #include <curl/curl.h>\r
26 #include <curl/multi.h>\r
27 #include <curl/easy.h>\r
28 \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
34 \r
35 namespace xmltooling {\r
36 \r
37 //\r
38 // This class implements the BinInputStream interface specified by the XML\r
39 // parser.\r
40 //\r
41 \r
42 class XMLTOOL_DLLLOCAL CurlURLInputStream : public BinInputStream\r
43 {\r
44 public :\r
45     CurlURLInputStream(const XMLURL&  urlSource, const XMLNetHTTPInfo* httpInfo=0);\r
46     ~CurlURLInputStream();\r
47 \r
48     unsigned int curPos() const;\r
49     unsigned int readBytes\r
50     (\r
51                 XMLByte* const  toFill\r
52         , const unsigned int    maxToRead\r
53     );\r
54 \r
55 \r
56 private :\r
57     // -----------------------------------------------------------------------\r
58     //  Unimplemented constructors and operators\r
59     // -----------------------------------------------------------------------\r
60     CurlURLInputStream(const CurlURLInputStream&);\r
61     CurlURLInputStream& operator=(const CurlURLInputStream&);\r
62     \r
63     static size_t staticWriteCallback(char *buffer,\r
64                                       size_t size,\r
65                                       size_t nitems,\r
66                                       void *outstream);\r
67     size_t writeCallback(                         char *buffer,\r
68                                       size_t size,\r
69                                       size_t nitems);\r
70 \r
71 \r
72     // -----------------------------------------------------------------------\r
73     //  Private data members\r
74     //\r
75     //  fSocket\r
76     //      The socket representing the connection to the remote file.\r
77     //  fBytesProcessed\r
78     //      Its a rolling count of the number of bytes processed off this\r
79     //      input stream.\r
80     //  fBuffer\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
88         \r
89     CURLM*                              fMulti;\r
90     CURL*                               fEasy;\r
91     \r
92     MemoryManager*      fMemoryManager;\r
93     \r
94     XMLURL                              fURLSource;\r
95     ArrayJanitor<char>  fURL;\r
96     \r
97     unsigned long       fTotalBytesRead;\r
98     XMLByte*                    fWritePtr;\r
99     unsigned long               fBytesRead;\r
100     unsigned long               fBytesToRead;\r
101     bool                                fDataAvailable;\r
102     \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
108     \r
109 }; // CurlURLInputStream\r
110 \r
111 \r
112 inline unsigned int\r
113 CurlURLInputStream::curPos() const\r
114 {\r
115     return fTotalBytesRead;\r
116 }\r
117 \r
118 };\r
119 \r
120 #endif // CURLURLINPUTSTREAM_HPP\r
121 \r