00001
00002 #ifndef _XMLRPCCLIENT_H_
00003 #define _XMLRPCCLIENT_H_
00004
00005
00006
00007 #if defined(_MSC_VER)
00008 # pragma warning(disable:4786) // identifier was truncated in debug info
00009 #endif
00010
00011
00012 #ifndef MAKEDEPEND
00013 # include <string>
00014 #endif
00015
00016 #include "XmlRpcDispatch.h"
00017 #include "XmlRpcSource.h"
00018
00019 namespace XmlRpc {
00020
00021
00022 class XmlRpcValue;
00023
00025 class XmlRpcClient : public XmlRpcSource {
00026 public:
00027
00028 static const char REQUEST_BEGIN[];
00029 static const char REQUEST_END_METHODNAME[];
00030 static const char PARAMS_TAG[];
00031 static const char PARAMS_ETAG[];
00032 static const char PARAM_TAG[];
00033 static const char PARAM_ETAG[];
00034 static const char REQUEST_END[];
00035
00036 static const char METHODRESPONSE_TAG[];
00037 static const char FAULT_TAG[];
00038
00043 XmlRpcClient(const char* host, int port, const char* uri=0);
00044
00046 virtual ~XmlRpcClient();
00047
00058 bool execute(const char* method, XmlRpcValue const& params, XmlRpcValue& result);
00059
00061 bool isFault() const { return _isFault; }
00062
00063
00064
00066
00067
00071 virtual unsigned handleEvent(unsigned eventType);
00072
00073 protected:
00074
00075 virtual bool doConnect();
00076 virtual bool setupConnection();
00077
00078 virtual bool generateRequest(const char* method, XmlRpcValue const& params);
00079 virtual std::string generateHeader(std::string const& body);
00080 virtual bool writeRequest();
00081 virtual bool readHeader();
00082 virtual bool readResponse();
00083 virtual bool parseResponse(XmlRpcValue& result);
00084
00085
00086 enum ClientConnectionState { NO_CONNECTION, CONNECTING, WRITE_REQUEST, READ_HEADER, READ_RESPONSE, IDLE };
00087 ClientConnectionState _connectionState;
00088
00089
00090 std::string _host;
00091 std::string _uri;
00092 int _port;
00093
00094
00095 std::string _request;
00096 std::string _header;
00097 std::string _response;
00098
00099
00100 int _sendAttempts;
00101
00102
00103 int _bytesWritten;
00104
00105
00106
00107 bool _executing;
00108
00109
00110 bool _eof;
00111
00112
00113
00114
00115 bool _isFault;
00116
00117
00118
00119 int _contentLength;
00120
00121
00122 XmlRpcDispatch _disp;
00123
00124 };
00125
00126 }
00127
00128 #endif // _XMLRPCCLIENT_H_