00001 00002 #ifndef XMLRPC_DOCUMENT_H 00003 #define XMLRPC_DOCUMENT_H 00004 00005 #include "xercesDomUtil.h" 00006 00007 BOREALIS_NAMESPACE_BEGIN; 00008 00009 class XmlRpcParams { 00010 public: 00011 void setParams(const DOMElement* elt) throw (AuroraException); 00012 00013 enum Type { 00014 STRING, 00015 INT, 00016 BOOL, 00017 DOUBLE, 00018 BINARY 00019 }; 00020 00021 Type getParameterType(unsigned int index) const; 00022 00023 unsigned int getSize() const { return _params.size(); } 00024 00025 string getStringParameter(unsigned int index) const throw (AuroraException); 00026 int getIntParameter(unsigned int index) const throw (AuroraException); 00027 bool getBoolParameter(unsigned int index) const throw (AuroraException); 00028 double getDoubleParameter(unsigned int index) const throw (AuroraException); 00029 string getBinaryParameter(unsigned int index) const throw (AuroraException); 00030 00031 void addParameter(const char *param) { addParameter(string(param)); } 00032 void addParameter(string param); 00033 void addParameter(int param); 00034 void addParameter(bool param); 00035 void addParameter(double param); 00036 void addBinaryParameter(string data); 00037 00038 string as_string() const { return to_string(_params); } 00039 string as_xml() const; 00040 00041 private: 00042 struct Param { 00043 Type _type; 00044 string _val; 00045 union { 00046 int _int_val; 00047 bool _bool_val; 00048 double _double_val; 00049 }; 00050 00051 string as_string() const { 00052 if (_type == STRING) { 00053 return "\"" + to_escaped_string(_val) + "\""; 00054 } else if (_type == INT) { 00055 return to_string(_int_val); 00056 } else if (_type == BOOL) { 00057 return _bool_val ? "true" : "false"; 00058 } else if (_type == BINARY) { 00059 return to_hex_string(_val.data(), _val.length()); 00060 } else { 00061 return "?"; 00062 } 00063 } 00064 00065 string as_xml() const; 00066 }; 00067 00068 vector<Param> _params; 00069 }; 00070 00071 class XmlRpcRequest { 00072 public: 00073 XmlRpcRequest(string method_name); 00074 XmlRpcRequest(const void *input, unsigned int length) 00075 throw (AuroraException); 00076 ~XmlRpcRequest(); 00077 00078 string getMethodName() const { return _method_name; } 00079 XmlRpcParams& getParams() { return _params; } 00080 const XmlRpcParams& getParams() const { return _params; } 00081 00082 string as_string() const; 00083 string as_xml() const; 00084 00085 private: 00086 string _method_name; 00087 XmlRpcParams _params; 00088 }; 00089 00090 00091 class XmlRpcResponse { 00092 public: 00093 XmlRpcResponse(); 00094 XmlRpcResponse(const void *input, unsigned int length) 00095 throw (AuroraException); 00096 ~XmlRpcResponse(); 00097 00098 XmlRpcParams& getParams() { return _params; } 00099 const XmlRpcParams& getParams() const { return _params; } 00100 00101 bool isFault() { return _fault; } 00102 unsigned int getFaultCode() { return _fault_code; } 00103 string getFault() { return _fault_string; } 00104 00105 void setFault(int fault_code, string fault_string) { 00106 _fault = true; 00107 _fault_code = fault_code; 00108 _fault_string = fault_string; 00109 } 00110 00111 string as_string() const; 00112 string as_xml() const; 00113 00114 void from_xml(const void *input, unsigned int length) 00115 throw (AuroraException); 00116 00117 private: 00118 bool _fault; 00119 int _fault_code; 00120 string _fault_string; 00121 00122 XmlRpcParams _params; 00123 }; 00124 00125 BOREALIS_NAMESPACE_END; 00126 00127 #endif