|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef XMLRPCCPP_H_INCLUDED |
|
|
#define XMLRPCCPP_H_INCLUDED |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef XMLRPC_BUILDING_OLDCPPWRAPPER |
|
|
#define XMLRPC_OLDCPPWRAPPER_EXPORTED XMLRPC_DLLEXPORT |
|
|
#else |
|
|
#define XMLRPC_OLDCPPWRAPPER_EXPORTED |
|
|
#endif |
|
|
|
|
|
#include <cstdlib> |
|
|
#include <string> |
|
|
|
|
|
#include <xmlrpc-c/c_util.h> |
|
|
#include <xmlrpc-c/base.h> |
|
|
#include <xmlrpc-c/client.h> |
|
|
#include <xmlrpc-c/server.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class XMLRPC_OLDCPPWRAPPER_EXPORTED XmlRpcFault { |
|
|
|
|
|
private: |
|
|
xmlrpc_env mFault; |
|
|
|
|
|
XmlRpcFault& operator= (XmlRpcFault const& f) |
|
|
{ if (true || f.getFaultCode()) abort(); return (XmlRpcFault&) f; } |
|
|
|
|
|
public: |
|
|
XmlRpcFault (const XmlRpcFault &fault); |
|
|
XmlRpcFault (const int faultCode, const std::string faultString); |
|
|
XmlRpcFault (const xmlrpc_env *env); |
|
|
~XmlRpcFault (void); |
|
|
|
|
|
inline int getFaultCode (void) const; |
|
|
std::string getFaultString (void) const; |
|
|
inline xmlrpc_env * getFaultEnv (void); |
|
|
}; |
|
|
|
|
|
inline int XmlRpcFault::getFaultCode (void) const { |
|
|
return mFault.fault_code; |
|
|
} |
|
|
|
|
|
inline xmlrpc_env *XmlRpcFault::getFaultEnv (void) { |
|
|
return &mFault; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class XMLRPC_OLDCPPWRAPPER_EXPORTED XmlRpcEnv { |
|
|
|
|
|
private: |
|
|
xmlrpc_env mEnv; |
|
|
|
|
|
void throwMe (void) const; |
|
|
XmlRpcEnv& operator= (XmlRpcEnv const& e) |
|
|
{ if (true || e.faultOccurred()) abort(); return (XmlRpcEnv&) e;} |
|
|
|
|
|
public: |
|
|
XmlRpcEnv (const XmlRpcEnv &env); |
|
|
XmlRpcEnv (void) { xmlrpc_env_init(&mEnv); } |
|
|
~XmlRpcEnv (void) { xmlrpc_env_clean(&mEnv); } |
|
|
|
|
|
bool faultOccurred (void) const {return (mEnv.fault_occurred != 0);}; |
|
|
bool hasFaultOccurred (void) const { return faultOccurred(); }; |
|
|
|
|
|
|
|
|
|
|
|
std::string getFaultString() const { return mEnv.fault_string; }; |
|
|
XmlRpcFault getFault (void) const; |
|
|
|
|
|
void throwIfFaultOccurred (void) const; |
|
|
|
|
|
operator xmlrpc_env * (void) { return &mEnv; } |
|
|
}; |
|
|
|
|
|
inline void XmlRpcEnv::throwIfFaultOccurred (void) const { |
|
|
if (faultOccurred()) |
|
|
throwMe(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class XMLRPC_OLDCPPWRAPPER_EXPORTED XmlRpcValue { |
|
|
|
|
|
private: |
|
|
xmlrpc_value *mValue; |
|
|
|
|
|
public: |
|
|
enum ReferenceBehavior { |
|
|
MAKE_REFERENCE, |
|
|
CONSUME_REFERENCE |
|
|
}; |
|
|
|
|
|
typedef xmlrpc_int32 int32; |
|
|
|
|
|
XmlRpcValue (void); |
|
|
XmlRpcValue (xmlrpc_value *value, |
|
|
ReferenceBehavior behavior = MAKE_REFERENCE); |
|
|
XmlRpcValue (const XmlRpcValue& value); |
|
|
~XmlRpcValue (void); |
|
|
|
|
|
XmlRpcValue& operator= (const XmlRpcValue& value); |
|
|
|
|
|
|
|
|
xmlrpc_type getType(void) const; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xmlrpc_value *makeReference (void) const; |
|
|
xmlrpc_value *borrowReference (void) const; |
|
|
|
|
|
|
|
|
static XmlRpcValue makeInt (const XmlRpcValue::int32 i); |
|
|
static XmlRpcValue makeBool (const bool b); |
|
|
static XmlRpcValue makeDouble (const double d); |
|
|
static XmlRpcValue makeDateTime (const std::string& dateTime); |
|
|
static XmlRpcValue makeString (const std::string& str); |
|
|
static XmlRpcValue makeString (const char *const str); |
|
|
static XmlRpcValue makeString (const char *const str, size_t len); |
|
|
static XmlRpcValue makeArray (void); |
|
|
static XmlRpcValue makeStruct (void); |
|
|
static XmlRpcValue makeBase64 (const unsigned char *const data, |
|
|
size_t len); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XmlRpcValue::int32 getInt (void) const; |
|
|
bool getBool (void) const; |
|
|
double getDouble (void) const; |
|
|
std::string getRawDateTime (void) const; |
|
|
std::string getString (void) const; |
|
|
XmlRpcValue getArray (void) const; |
|
|
XmlRpcValue getStruct (void) const; |
|
|
|
|
|
|
|
|
|
|
|
void getBase64 (const unsigned char *& out_data, |
|
|
size_t& out_len) const; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t arraySize (void) const; |
|
|
void arrayAppendItem (const XmlRpcValue& value); |
|
|
XmlRpcValue arrayGetItem (int index) const; |
|
|
|
|
|
|
|
|
|
|
|
size_t structSize (void) const; |
|
|
bool structHasKey (const std::string& key) const; |
|
|
XmlRpcValue structGetValue (const std::string& key) const; |
|
|
void structSetValue (const std::string& key, |
|
|
const XmlRpcValue& value); |
|
|
void structGetKeyAndValue (const int index, |
|
|
std::string& out_key, |
|
|
XmlRpcValue& out_value) const; |
|
|
}; |
|
|
|
|
|
inline XmlRpcValue::XmlRpcValue (xmlrpc_value *value, |
|
|
ReferenceBehavior behavior) |
|
|
{ |
|
|
mValue = value; |
|
|
|
|
|
if (behavior == MAKE_REFERENCE) |
|
|
xmlrpc_INCREF(value); |
|
|
} |
|
|
|
|
|
inline XmlRpcValue::XmlRpcValue (const XmlRpcValue& value) { |
|
|
mValue = value.mValue; |
|
|
xmlrpc_INCREF(mValue); |
|
|
} |
|
|
|
|
|
inline XmlRpcValue::~XmlRpcValue (void) { |
|
|
xmlrpc_DECREF(mValue); |
|
|
} |
|
|
|
|
|
inline XmlRpcValue& XmlRpcValue::operator= (const XmlRpcValue& value) { |
|
|
|
|
|
xmlrpc_INCREF(value.mValue); |
|
|
xmlrpc_DECREF(mValue); |
|
|
mValue = value.mValue; |
|
|
return *this; |
|
|
} |
|
|
|
|
|
inline xmlrpc_type XmlRpcValue::getType (void) const { |
|
|
return xmlrpc_value_type(mValue); |
|
|
} |
|
|
|
|
|
inline xmlrpc_value *XmlRpcValue::makeReference (void) const { |
|
|
xmlrpc_INCREF(mValue); |
|
|
return mValue; |
|
|
} |
|
|
|
|
|
inline xmlrpc_value *XmlRpcValue::borrowReference (void) const { |
|
|
return mValue; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class XMLRPC_OLDCPPWRAPPER_EXPORTED XmlRpcClient { |
|
|
|
|
|
private: |
|
|
std::string mServerUrl; |
|
|
|
|
|
public: |
|
|
static void Initialize (std::string appname, std::string appversion); |
|
|
static void Terminate (void); |
|
|
|
|
|
XmlRpcClient (const std::string& server_url) : mServerUrl(server_url) {} |
|
|
~XmlRpcClient (void) {} |
|
|
|
|
|
XmlRpcClient (const XmlRpcClient& client); |
|
|
XmlRpcClient& operator= (const XmlRpcClient& client); |
|
|
|
|
|
XmlRpcValue call (std::string method_name, XmlRpcValue param_array); |
|
|
void call_asynch (std::string method_name, |
|
|
XmlRpcValue param_array, |
|
|
xmlrpc_response_handler callback, |
|
|
void* user_data); |
|
|
void event_loop_asynch (unsigned long milliseconds); |
|
|
}; |
|
|
|
|
|
inline void XmlRpcClient::call_asynch(std::string method_name, |
|
|
XmlRpcValue param_array, |
|
|
xmlrpc_response_handler callback, |
|
|
void* user_data) |
|
|
{ |
|
|
xmlrpc_client_call_asynch_params( |
|
|
mServerUrl.c_str(), |
|
|
method_name.c_str(), |
|
|
callback, |
|
|
user_data, |
|
|
param_array.borrowReference()); |
|
|
} |
|
|
|
|
|
inline void XmlRpcClient::event_loop_asynch(unsigned long milliseconds) |
|
|
{ |
|
|
xmlrpc_client_event_loop_finish_asynch_timeout(milliseconds); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline XmlRpcClient::XmlRpcClient (const XmlRpcClient& client) |
|
|
: mServerUrl(client.mServerUrl) |
|
|
{ |
|
|
} |
|
|
|
|
|
inline XmlRpcClient& XmlRpcClient::operator= (const XmlRpcClient& client) { |
|
|
if (this != &client) |
|
|
mServerUrl = client.mServerUrl; |
|
|
return *this; |
|
|
} |
|
|
|
|
|
inline void XmlRpcClient::Initialize (std::string appname, |
|
|
std::string appversion) { |
|
|
xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, |
|
|
appname.c_str(), |
|
|
appversion.c_str()); |
|
|
} |
|
|
|
|
|
inline void XmlRpcClient::Terminate (void) { |
|
|
xmlrpc_client_cleanup(); |
|
|
} |
|
|
|
|
|
inline XmlRpcValue XmlRpcClient::call (std::string method_name, |
|
|
XmlRpcValue param_array) |
|
|
{ |
|
|
XmlRpcEnv env; |
|
|
xmlrpc_value *result = |
|
|
xmlrpc_client_call_params(env, |
|
|
mServerUrl.c_str(), |
|
|
method_name.c_str(), |
|
|
param_array.borrowReference()); |
|
|
env.throwIfFaultOccurred(); |
|
|
return XmlRpcValue(result, XmlRpcValue::CONSUME_REFERENCE); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class XMLRPC_OLDCPPWRAPPER_EXPORTED XmlRpcGenSrv { |
|
|
|
|
|
private: |
|
|
|
|
|
xmlrpc_registry* mRegistry; |
|
|
|
|
|
xmlrpc_mem_block* alloc (XmlRpcEnv& env, const std::string& body) const; |
|
|
|
|
|
public: |
|
|
|
|
|
XmlRpcGenSrv (int flags); |
|
|
~XmlRpcGenSrv (void); |
|
|
|
|
|
xmlrpc_registry* getRegistry (void) const; |
|
|
|
|
|
XmlRpcGenSrv& addMethod (const std::string& name, |
|
|
xmlrpc_method method, |
|
|
void *data); |
|
|
XmlRpcGenSrv& addMethod (const std::string& name, |
|
|
xmlrpc_method method, |
|
|
void* data, |
|
|
const std::string& signature, |
|
|
const std::string& help); |
|
|
|
|
|
std::string handle (const std::string& body) const; |
|
|
}; |
|
|
|
|
|
inline XmlRpcGenSrv::XmlRpcGenSrv (int) { |
|
|
|
|
|
XmlRpcEnv env; |
|
|
|
|
|
mRegistry = xmlrpc_registry_new (env); |
|
|
env.throwIfFaultOccurred(); |
|
|
} |
|
|
|
|
|
inline XmlRpcGenSrv::~XmlRpcGenSrv (void) { |
|
|
|
|
|
xmlrpc_registry_free (mRegistry); |
|
|
} |
|
|
|
|
|
inline xmlrpc_registry* XmlRpcGenSrv::getRegistry () const { |
|
|
|
|
|
return mRegistry; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif |
|
|
|