XmlRpcClient.h

Go to the documentation of this file.
00001 
00002 #ifndef _XMLRPCCLIENT_H_
00003 #define _XMLRPCCLIENT_H_
00004 //
00005 // XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
00006 //
00007 
00014 #if defined(_MSC_VER)
00015 # pragma warning(disable:4786)    // identifier was truncated in debug info
00016 #endif
00017 
00018 
00019 #ifndef MAKEDEPEND
00020 # include <string>
00021 #endif
00022 
00023 #include "XmlRpcDispatch.h"
00024 #include "XmlRpcSource.h"
00025 
00026 namespace XmlRpc {
00027 
00028   // Arguments and results are represented by XmlRpcValues
00029   class XmlRpcValue;
00030 
00032   class XmlRpcClient : public XmlRpcSource {
00033   public:
00034     // Static data
00035     static const char REQUEST_BEGIN[];
00036     static const char REQUEST_END_METHODNAME[];
00037     static const char PARAMS_TAG[];
00038     static const char PARAMS_ETAG[];
00039     static const char PARAM_TAG[];
00040     static const char PARAM_ETAG[];
00041     static const char REQUEST_END[];
00042     // Result tags
00043     static const char METHODRESPONSE_TAG[];
00044     static const char FAULT_TAG[];
00045 
00051     XmlRpcClient(const char* host, int port, const char* uri=0);
00052     XmlRpcClient(const char* host, int port, const char* uri=0, bool ssl=false);
00053 
00060     XmlRpcClient(const char* host, int port, const char* login, const char* password, const char* uri=0);
00061     XmlRpcClient(const char* host, int port, const char* login, const char* password, const char* uri=0, bool ssl=false);
00062 
00064     virtual ~XmlRpcClient();
00065 
00076     bool execute(const char* method, XmlRpcValue const& params, XmlRpcValue& result);
00077 
00079     bool isFault() const { return _isFault; }
00080 
00082     const char* const host() const { return _host.c_str(); }
00083 
00085     int getPort() const { return _port; }
00086 
00088     const char* const uri() const { return _uri.c_str(); }
00089 
00090     // XmlRpcSource interface implementation
00092     virtual void close();
00093 
00097     virtual unsigned handleEvent(unsigned eventType);
00098 
00099   protected:
00100     // Execution processing helpers
00101     virtual bool doConnect();
00102     virtual bool setupConnection();
00103 
00104     virtual bool generateRequest(const char* method, XmlRpcValue const& params);
00105     virtual std::string generateHeader(std::string const& body);
00106     virtual bool writeRequest();
00107     virtual bool readHeader();
00108     virtual bool readResponse();
00109     virtual bool parseResponse(XmlRpcValue& result);
00110 
00111     // Possible IO states for the connection
00112     enum ClientConnectionState { NO_CONNECTION, CONNECTING, WRITE_REQUEST, READ_HEADER, READ_RESPONSE, IDLE };
00113     ClientConnectionState _connectionState;
00114 
00115     // Server location
00116     std::string _host;
00117     std::string _uri;
00118     int _port;
00119 
00120     // Login information for HTTP authentication
00121     std::string _login;
00122     std::string _password;
00123 
00124     // The xml-encoded request, http header of response, and response xml
00125     std::string _request;
00126     std::string _header;
00127     std::string _response;
00128 
00129     // Number of times the client has attempted to send the request
00130     int _sendAttempts;
00131 
00132     // Number of bytes of the request that have been written to the socket so far
00133     int _bytesWritten;
00134 
00135     // True if we are currently executing a request. If you want to multithread,
00136     // each thread should have its own client.
00137     bool _executing;
00138 
00139     // True if the server closed the connection
00140     bool _eof;
00141 
00142     // True if a fault response was returned by the server
00143     bool _isFault;
00144 
00145     // Number of bytes expected in the response body (parsed from response header)
00146     int _contentLength;
00147 
00148     // Event dispatcher
00149     XmlRpcDispatch _disp;
00150 
00151   };    // class XmlRpcClient
00152 
00153 }       // namespace XmlRpc
00154 
00155 #endif  // _XMLRPCCLIENT_H_
Generated on Wed May 26 16:21:15 2010 for OverSim by  doxygen 1.6.3