OverSim
XmlRpcClient.h
Go to the documentation of this file.
1 
2 #ifndef _XMLRPCCLIENT_H_
3 #define _XMLRPCCLIENT_H_
4 //
5 // XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
6 //
7 
14 #if defined(_MSC_VER)
15 # pragma warning(disable:4786) // identifier was truncated in debug info
16 #endif
17 
18 
19 #ifndef MAKEDEPEND
20 # include <string>
21 #endif
22 
23 #include "XmlRpcDispatch.h"
24 #include "XmlRpcSource.h"
25 
26 namespace XmlRpc {
27 
28  // Arguments and results are represented by XmlRpcValues
29  class XmlRpcValue;
30 
32  class XmlRpcClient : public XmlRpcSource {
33  public:
34  // Static data
35  static const char REQUEST_BEGIN[];
36  static const char REQUEST_END_METHODNAME[];
37  static const char PARAMS_TAG[];
38  static const char PARAMS_ETAG[];
39  static const char PARAM_TAG[];
40  static const char PARAM_ETAG[];
41  static const char REQUEST_END[];
42  // Result tags
43  static const char METHODRESPONSE_TAG[];
44  static const char FAULT_TAG[];
45 
51  XmlRpcClient(const char* host, int port, const char* uri=0);
52  XmlRpcClient(const char* host, int port, const char* uri=0, bool ssl=false);
53 
60  XmlRpcClient(const char* host, int port, const char* login, const char* password, const char* uri=0);
61  XmlRpcClient(const char* host, int port, const char* login, const char* password, const char* uri=0, bool ssl=false);
62 
64  virtual ~XmlRpcClient();
65 
76  bool execute(const char* method, XmlRpcValue const& params, XmlRpcValue& result);
77 
79  bool isFault() const { return _isFault; }
80 
82  const char* const host() const { return _host.c_str(); }
83 
85  int getPort() const { return _port; }
86 
88  const char* const uri() const { return _uri.c_str(); }
89 
90  // XmlRpcSource interface implementation
92  virtual void close();
93 
97  virtual unsigned handleEvent(unsigned eventType);
98 
99  protected:
100  // Execution processing helpers
101  virtual bool doConnect();
102  virtual bool setupConnection();
103 
104  virtual bool generateRequest(const char* method, XmlRpcValue const& params);
105  virtual std::string generateHeader(std::string const& body);
106  virtual bool writeRequest();
107  virtual bool readHeader();
108  virtual bool readResponse();
109  virtual bool parseResponse(XmlRpcValue& result);
110 
111  // Possible IO states for the connection
114 
115  // Server location
116  std::string _host;
117  std::string _uri;
118  int _port;
119 
120  // Login information for HTTP authentication
121  std::string _login;
122  std::string _password;
123 
124  // The xml-encoded request, http header of response, and response xml
125  std::string _request;
126  std::string _header;
127  std::string _response;
128 
129  // Number of times the client has attempted to send the request
131 
132  // Number of bytes of the request that have been written to the socket so far
134 
135  // True if we are currently executing a request. If you want to multithread,
136  // each thread should have its own client.
138 
139  // True if the server closed the connection
140  bool _eof;
141 
142  // True if a fault response was returned by the server
143  bool _isFault;
144 
145  // Number of bytes expected in the response body (parsed from response header)
147 
148  // Event dispatcher
150 
151  }; // class XmlRpcClient
152 
153 } // namespace XmlRpc
154 
155 #endif // _XMLRPCCLIENT_H_