initial load of upstream version 1.06.32
[xmlrpc-c] / include / xmlrpc-c / client_transport.hpp
1 #ifndef CLIENT_TRANSPORT_HPP_INCLUDED
2 #define CLIENT_TRANSPORT_HPP_INCLUDED
3
4 #include <string>
5 #include <vector>
6 #include <xmlrpc-c/util.h>
7 #include <xmlrpc-c/client.h>
8 #include <xmlrpc-c/girerr.hpp>
9 #include <xmlrpc-c/girmem.hpp>
10 #include <xmlrpc-c/timeout.hpp>
11
12 namespace xmlrpc_c {
13
14 class carriageParmPtr;
15
16 class carriageParm : public girmem::autoObject {
17 /*----------------------------------------------------------------------------
18    The parameter to a client for an individual RPC.  It tells specifics
19    of how to carry the call to the server and the response back.  For
20    example, it may identify the server.  It may identify communication
21    protocols to use.  It may indicate permission and accounting
22    information.
23
24    This is a base class; the carriage parameter is specific to the
25    class of client.  For example, an HTTP-based client would have a
26    URL and HTTP basic authentication info as parameter.
27 -----------------------------------------------------------------------------*/
28 protected:
29     virtual ~carriageParm();
30     carriageParm();
31 };
32
33 class carriageParmPtr : public girmem::autoObjectPtr {
34
35 public:
36     carriageParmPtr();
37
38     explicit carriageParmPtr(xmlrpc_c::carriageParm * const carriageParmP);
39
40     xmlrpc_c::carriageParm *
41     operator->() const;
42
43     xmlrpc_c::carriageParm *
44     get() const;
45 };
46
47 class carriageParm_http0 : public xmlrpc_c::carriageParm {
48
49 public:
50     carriageParm_http0(std::string const serverUrl);
51
52     ~carriageParm_http0();
53
54     void
55     setBasicAuth(std::string const userid,
56                  std::string const password);
57
58     xmlrpc_server_info * c_serverInfoP;
59
60 protected:
61     // Only a derived class is allowed to create an object with no
62     // server URL, and the derived class is expected to follow it up
63     // with an instantiate() to establish the server URL.
64
65     carriageParm_http0();
66
67     void
68     instantiate(std::string const serverUrl);
69 };
70
71 class carriageParm_http0Ptr : public xmlrpc_c::carriageParmPtr {
72
73 public:
74     carriageParm_http0Ptr();
75     carriageParm_http0Ptr(xmlrpc_c::carriageParm_http0 * const carriageParmP);
76
77     xmlrpc_c::carriageParm_http0 *
78     operator->() const;
79 };
80
81 class carriageParm_curl0 : public xmlrpc_c::carriageParm_http0 {
82
83 public:
84     carriageParm_curl0(std::string const serverUrl);
85
86 };
87
88 class carriageParm_curl0Ptr : public xmlrpc_c::carriageParm_http0Ptr {
89
90 public:
91     carriageParm_curl0Ptr();
92     carriageParm_curl0Ptr(xmlrpc_c::carriageParm_curl0 * const carriageParmP);
93
94     xmlrpc_c::carriageParm_curl0 *
95     operator->() const;
96 };
97
98 class carriageParm_libwww0 : public xmlrpc_c::carriageParm_http0 {
99
100 public:
101     carriageParm_libwww0(std::string const serverUrl);
102
103 };
104
105 class carriageParm_libwww0Ptr : public xmlrpc_c::carriageParm_http0Ptr {
106
107 public:
108     carriageParm_libwww0Ptr();
109     carriageParm_libwww0Ptr(xmlrpc_c::carriageParm_libwww0 * const);
110
111     xmlrpc_c::carriageParm_libwww0 *
112     operator->() const;
113 };
114
115 class carriageParm_wininet0 : public xmlrpc_c::carriageParm_http0 {
116
117 public:
118     carriageParm_wininet0(std::string const serverUrl);
119
120 };
121
122 class carriageParm_wininet0Ptr : public xmlrpc_c::carriageParm_http0Ptr {
123
124 public:
125     carriageParm_wininet0Ptr();
126     carriageParm_wininet0Ptr(xmlrpc_c::carriageParm_wininet0 * const);
127
128     xmlrpc_c::carriageParm_wininet0 *
129     operator->() const;
130 };
131
132 //----------------------------------------------------------------------------
133
134 class xmlTransactionPtr;
135
136 class xmlTransaction : public girmem::autoObject {
137
138     friend class xmlTransactionPtr;
139
140 public:
141     virtual void
142     finish(std::string const& responseXml) const;
143
144     virtual void
145     finishErr(girerr::error const& error) const;
146
147 protected:
148     xmlTransaction();
149 };
150
151 class xmlTransactionPtr : public girmem::autoObjectPtr {
152 public:
153     xmlTransactionPtr();
154
155     xmlrpc_c::xmlTransaction *
156     operator->() const;
157 };
158
159 //----------------------------------------------------------------------------
160
161 class clientXmlTransport : public girmem::autoObject {
162 /*----------------------------------------------------------------------------
163    An object which transports XML to and from an XML-RPC server for an
164    XML-RPC client.
165
166    This is a base class.  Derived classes define methods to perform the
167    transportation in particular ways.
168 -----------------------------------------------------------------------------*/
169 public:
170     virtual ~clientXmlTransport();
171
172     virtual void
173     call(xmlrpc_c::carriageParm * const  carriageParmP,
174          std::string              const& callXml,
175          std::string *            const  responseXmlP) = 0;
176
177     virtual void
178     start(xmlrpc_c::carriageParm *    const  carriageParmP,
179           std::string                 const& callXml,
180           xmlrpc_c::xmlTransactionPtr const& xmlTranP);
181
182     virtual void
183     finishAsync(xmlrpc_c::timeout const timeout);
184
185     static void
186     asyncComplete(
187         struct xmlrpc_call_info * const callInfoP,
188         xmlrpc_mem_block *        const responseXmlMP,
189         xmlrpc_env                const transportEnv);
190 };
191
192 class clientXmlTransportPtr : public girmem::autoObjectPtr {
193     
194 public:
195     clientXmlTransportPtr();
196
197     clientXmlTransportPtr(xmlrpc_c::clientXmlTransport * const transportP);
198
199     xmlrpc_c::clientXmlTransport *
200     operator->() const;
201
202     xmlrpc_c::clientXmlTransport *
203     get() const;
204 };
205
206 class clientXmlTransport_http : public xmlrpc_c::clientXmlTransport {
207 /*----------------------------------------------------------------------------
208    A base class for client XML transports that use the simple, classic
209    C HTTP transports.
210 -----------------------------------------------------------------------------*/
211 public:
212     virtual ~clientXmlTransport_http();
213     
214     void
215     call(xmlrpc_c::carriageParm * const  carriageParmP,
216          std::string              const& callXml,
217          std::string *            const  responseXmlP);
218     
219     void
220     start(xmlrpc_c::carriageParm *    const  carriageParmP,
221           std::string                 const& callXml,
222           xmlrpc_c::xmlTransactionPtr const& xmlTranP);
223         
224     virtual void
225     finishAsync(xmlrpc_c::timeout const timeout);
226
227     static std::vector<std::string>
228     availableTypes();
229
230     static clientXmlTransportPtr
231     create();
232
233 protected:
234     clientXmlTransport_http() {} // ensure no one can create
235     struct xmlrpc_client_transport *           c_transportP;
236     const struct xmlrpc_client_transport_ops * c_transportOpsP;
237 };
238
239
240 class clientXmlTransport_curl : public xmlrpc_c::clientXmlTransport_http {
241
242 public:
243     class constrOpt {
244     public:
245         constrOpt();
246
247         constrOpt & network_interface (std::string const& arg);
248         constrOpt & no_ssl_verifypeer (bool        const& arg);
249         constrOpt & no_ssl_verifyhost (bool        const& arg);
250         constrOpt & user_agent        (std::string const& arg);
251         constrOpt & ssl_cert          (std::string const& arg);
252         constrOpt & sslcerttype       (std::string const& arg);
253         constrOpt & sslcertpasswd     (std::string const& arg);
254         constrOpt & sslkey            (std::string const& arg);
255         constrOpt & sslkeytype        (std::string const& arg);
256         constrOpt & sslkeypasswd      (std::string const& arg);
257         constrOpt & sslengine         (std::string const& arg);
258         constrOpt & sslengine_default (bool        const& arg);
259         constrOpt & sslversion        (xmlrpc_sslversion const& arg);
260         constrOpt & cainfo            (std::string const& arg);
261         constrOpt & capath            (std::string const& arg);
262         constrOpt & randomfile        (std::string const& arg);
263         constrOpt & egdsocket         (std::string const& arg);
264         constrOpt & ssl_cipher_list   (std::string const& arg);
265
266         struct {
267             std::string network_interface;
268             bool        no_ssl_verifypeer;
269             bool        no_ssl_verifyhost;
270             std::string user_agent;
271             std::string ssl_cert;
272             std::string sslcerttype;
273             std::string sslcertpasswd;
274             std::string sslkey;
275             std::string sslkeytype;
276             std::string sslkeypasswd;
277             std::string sslengine;
278             bool        sslengine_default;
279             xmlrpc_sslversion sslversion;
280             std::string cainfo;
281             std::string capath;
282             std::string randomfile;
283             std::string egdsocket;
284             std::string ssl_cipher_list;
285         } value;
286         struct {
287             bool network_interface;
288             bool no_ssl_verifypeer;
289             bool no_ssl_verifyhost;
290             bool user_agent;
291             bool ssl_cert;
292             bool sslcerttype;
293             bool sslcertpasswd;
294             bool sslkey;
295             bool sslkeytype;
296             bool sslkeypasswd;
297             bool sslengine;
298             bool sslengine_default;
299             bool sslversion;
300             bool cainfo;
301             bool capath;
302             bool randomfile;
303             bool egdsocket;
304             bool ssl_cipher_list;
305         } present;
306     };
307
308     clientXmlTransport_curl(constrOpt const& opt);
309
310     clientXmlTransport_curl(std::string const networkInterface = "",
311                             bool        const noSslVerifyPeer = false,
312                             bool        const noSslVerifyHost = false,
313                             std::string const userAgent = "");
314
315     ~clientXmlTransport_curl();
316
317 private:
318     void
319     initialize(constrOpt const& opt);
320 };
321
322 class clientXmlTransport_libwww : public xmlrpc_c::clientXmlTransport_http {
323     
324 public:
325     clientXmlTransport_libwww(std::string const appname = "",
326                               std::string const appversion = "");
327
328     ~clientXmlTransport_libwww();
329 };
330
331 class clientXmlTransport_wininet : public xmlrpc_c::clientXmlTransport_http {
332
333 public:
334     clientXmlTransport_wininet(bool const allowInvalidSslCerts = false);
335
336     ~clientXmlTransport_wininet();
337 };
338
339
340
341 } // namespace
342 #endif