|
|
#ifndef XMLRPC_BASE_HPP_INCLUDED |
|
|
#define XMLRPC_BASE_HPP_INCLUDED |
|
|
|
|
|
#include <xmlrpc-c/config.h> |
|
|
|
|
|
#include <climits> |
|
|
#include <cfloat> |
|
|
#include <ctime> |
|
|
#include <vector> |
|
|
#include <map> |
|
|
#include <string> |
|
|
#if defined(__GNUC__) && __GNUC__ < 3 |
|
|
#include <iostream> |
|
|
#else |
|
|
#include <ostream> |
|
|
#endif |
|
|
#if XMLRPC_HAVE_TIMEVAL |
|
|
#include <sys/time.h> |
|
|
#endif |
|
|
|
|
|
#include <xmlrpc-c/c_util.h> |
|
|
#include <xmlrpc-c/base.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef XMLRPC_BUILDING_LIBPP |
|
|
#define XMLRPC_LIBPP_EXPORTED XMLRPC_DLLEXPORT |
|
|
#else |
|
|
#define XMLRPC_LIBPP_EXPORTED |
|
|
#endif |
|
|
|
|
|
namespace xmlrpc_c { |
|
|
|
|
|
class XMLRPC_LIBPP_EXPORTED value { |
|
|
|
|
|
|
|
|
public: |
|
|
value(); |
|
|
|
|
|
|
|
|
|
|
|
value(xmlrpc_c::value const &value); |
|
|
|
|
|
~value(); |
|
|
|
|
|
enum type_t { |
|
|
|
|
|
|
|
|
TYPE_INT = 0, |
|
|
TYPE_BOOLEAN = 1, |
|
|
TYPE_DOUBLE = 2, |
|
|
TYPE_DATETIME = 3, |
|
|
TYPE_STRING = 4, |
|
|
TYPE_BYTESTRING = 5, |
|
|
TYPE_ARRAY = 6, |
|
|
TYPE_STRUCT = 7, |
|
|
TYPE_C_PTR = 8, |
|
|
TYPE_NIL = 9, |
|
|
TYPE_I8 = 10, |
|
|
TYPE_DEAD = 0xDEAD |
|
|
}; |
|
|
|
|
|
type_t type() const; |
|
|
|
|
|
xmlrpc_c::value& |
|
|
operator=(xmlrpc_c::value const&); |
|
|
|
|
|
bool |
|
|
isInstantiated() const; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
appendToCArray(xmlrpc_value * const arrayP) const; |
|
|
|
|
|
void |
|
|
addToCStruct(xmlrpc_value * const structP, |
|
|
std::string const key) const; |
|
|
|
|
|
xmlrpc_value * |
|
|
cValue() const; |
|
|
|
|
|
|
|
|
|
|
|
value(xmlrpc_value * const valueP); |
|
|
|
|
|
void |
|
|
instantiate(xmlrpc_value * const valueP); |
|
|
|
|
|
|
|
|
|
|
|
xmlrpc_value * cValueP; |
|
|
|
|
|
|
|
|
protected: |
|
|
void |
|
|
validateInstantiated() const; |
|
|
}; |
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& out, |
|
|
xmlrpc_c::value::type_t const& type); |
|
|
|
|
|
|
|
|
class XMLRPC_LIBPP_EXPORTED value_int : public value { |
|
|
public: |
|
|
value_int(int const cvalue); |
|
|
|
|
|
value_int(xmlrpc_c::value const baseValue); |
|
|
|
|
|
operator int() const; |
|
|
|
|
|
int cvalue() const; |
|
|
}; |
|
|
|
|
|
|
|
|
class XMLRPC_LIBPP_EXPORTED value_boolean : public value { |
|
|
public: |
|
|
value_boolean(bool const cvalue); |
|
|
|
|
|
value_boolean(xmlrpc_c::value const baseValue); |
|
|
|
|
|
operator bool() const; |
|
|
|
|
|
bool cvalue() const; |
|
|
}; |
|
|
|
|
|
|
|
|
class XMLRPC_LIBPP_EXPORTED value_string : public value { |
|
|
public: |
|
|
enum nlCode {nlCode_all, nlCode_lf}; |
|
|
|
|
|
value_string(std::string const& cppvalue, |
|
|
nlCode const nlCode); |
|
|
|
|
|
value_string(std::string const& cppvalue); |
|
|
|
|
|
value_string(xmlrpc_c::value const baseValue); |
|
|
|
|
|
std::string |
|
|
crlfValue() const; |
|
|
|
|
|
void |
|
|
validate() const; |
|
|
|
|
|
operator std::string() const; |
|
|
|
|
|
std::string cvalue() const; |
|
|
}; |
|
|
|
|
|
|
|
|
class XMLRPC_LIBPP_EXPORTED value_double : public value { |
|
|
public: |
|
|
value_double(double const cvalue); |
|
|
|
|
|
value_double(xmlrpc_c::value const baseValue); |
|
|
|
|
|
operator double() const; |
|
|
|
|
|
double cvalue() const; |
|
|
}; |
|
|
|
|
|
|
|
|
class XMLRPC_LIBPP_EXPORTED value_datetime : public value { |
|
|
public: |
|
|
value_datetime(std::string const cvalue); |
|
|
|
|
|
value_datetime(xmlrpc_datetime const cvalue); |
|
|
operator xmlrpc_datetime() const; |
|
|
|
|
|
value_datetime(time_t const cvalue); |
|
|
operator time_t() const; |
|
|
|
|
|
#if XMLRPC_HAVE_TIMEVAL |
|
|
value_datetime(struct timeval const& cvalue); |
|
|
operator timeval() const; |
|
|
#endif |
|
|
#if XMLRPC_HAVE_TIMESPEC |
|
|
value_datetime(struct timespec const& cvalue); |
|
|
operator timespec() const; |
|
|
#endif |
|
|
|
|
|
value_datetime(xmlrpc_c::value const baseValue); |
|
|
|
|
|
time_t cvalue() const; |
|
|
|
|
|
std::string iso8601Value() const; |
|
|
}; |
|
|
|
|
|
|
|
|
typedef std::vector<unsigned char> cbytestring; |
|
|
|
|
|
class XMLRPC_LIBPP_EXPORTED value_bytestring : public value { |
|
|
public: |
|
|
value_bytestring(cbytestring const& cvalue); |
|
|
|
|
|
value_bytestring(xmlrpc_c::value const baseValue); |
|
|
|
|
|
|
|
|
|
|
|
cbytestring |
|
|
vectorUcharValue() const; |
|
|
|
|
|
cbytestring cvalue() const; |
|
|
|
|
|
size_t |
|
|
length() const; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
typedef std::map<std::string, xmlrpc_c::value> cstruct; |
|
|
|
|
|
class XMLRPC_LIBPP_EXPORTED value_struct : public value { |
|
|
public: |
|
|
value_struct(cstruct const& cvalue); |
|
|
|
|
|
value_struct(xmlrpc_c::value const baseValue); |
|
|
|
|
|
operator cstruct() const; |
|
|
|
|
|
cstruct cvalue() const; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
typedef std::vector<xmlrpc_c::value> carray; |
|
|
|
|
|
class XMLRPC_LIBPP_EXPORTED value_array : public value { |
|
|
public: |
|
|
value_array(carray const& cvalue); |
|
|
|
|
|
value_array(xmlrpc_c::value const baseValue); |
|
|
|
|
|
|
|
|
|
|
|
carray |
|
|
vectorValueValue() const; |
|
|
|
|
|
carray cvalue() const; |
|
|
|
|
|
size_t |
|
|
size() const; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class XMLRPC_LIBPP_EXPORTED value_nil : public value { |
|
|
public: |
|
|
value_nil(); |
|
|
|
|
|
value_nil(xmlrpc_c::value const baseValue); |
|
|
|
|
|
void * cvalue() const; |
|
|
}; |
|
|
|
|
|
|
|
|
class XMLRPC_LIBPP_EXPORTED value_i8 : public value { |
|
|
public: |
|
|
value_i8(xmlrpc_int64 const cvalue); |
|
|
|
|
|
value_i8(xmlrpc_c::value const baseValue); |
|
|
|
|
|
operator xmlrpc_int64() const; |
|
|
|
|
|
xmlrpc_int64 cvalue() const; |
|
|
}; |
|
|
|
|
|
|
|
|
inline xmlrpc_c::value_string |
|
|
toValue(const char * const x) { |
|
|
return xmlrpc_c::value_string(x); |
|
|
} |
|
|
|
|
|
inline xmlrpc_c::value_string |
|
|
toValue(std::string const& x) { |
|
|
return xmlrpc_c::value_string(x); |
|
|
} |
|
|
|
|
|
inline xmlrpc_c::value_int |
|
|
toValue(int const x) { |
|
|
return xmlrpc_c::value_int(x); |
|
|
} |
|
|
|
|
|
inline xmlrpc_c::value_i8 |
|
|
toValue(xmlrpc_int64 const x) { |
|
|
return xmlrpc_c::value_i8(x); |
|
|
} |
|
|
|
|
|
inline xmlrpc_c::value_boolean |
|
|
toValue(bool const x) { |
|
|
return xmlrpc_c::value_boolean(x); |
|
|
} |
|
|
|
|
|
inline xmlrpc_c::value_double |
|
|
toValue(double const x) { |
|
|
return xmlrpc_c::value_double(x); |
|
|
} |
|
|
|
|
|
inline xmlrpc_c::value_bytestring |
|
|
toValue(cbytestring const& x) { |
|
|
return xmlrpc_c::value_bytestring(x); |
|
|
} |
|
|
|
|
|
inline const xmlrpc_c::value & |
|
|
toValue(xmlrpc_c::value const& v) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return v; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T> inline xmlrpc_c::value_array |
|
|
toValue(std::vector<T> const& in); |
|
|
|
|
|
template<class K, class V> xmlrpc_c::value_struct |
|
|
toValue(std::map<K, V> const& in); |
|
|
|
|
|
template<class K, class V> xmlrpc_c::value_struct |
|
|
toValue(std::map<K, V> const& in) { |
|
|
|
|
|
|
|
|
|
|
|
cstruct ret; |
|
|
for (typename std::map<std::string, V>::const_iterator p = in.begin(); |
|
|
p != in.end(); |
|
|
++p) { |
|
|
ret[p->first] = toValue(p->second); |
|
|
} |
|
|
return xmlrpc_c::value_struct(ret); |
|
|
} |
|
|
|
|
|
template<class InputIterator> xmlrpc_c::value_array |
|
|
arrayValueSlice(InputIterator begin, |
|
|
InputIterator end) { |
|
|
|
|
|
|
|
|
|
|
|
carray ret; |
|
|
for (InputIterator p = begin; p != end; ++p) { |
|
|
ret.push_back(toValue(*p)); |
|
|
} |
|
|
return xmlrpc_c::value_array(ret); |
|
|
} |
|
|
|
|
|
template<class T> inline xmlrpc_c::value_array |
|
|
toValue(std::vector<T> const& in) { |
|
|
|
|
|
|
|
|
|
|
|
return arrayValueSlice(in.begin(), in.end()); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline void |
|
|
fromValue(std::string & y, xmlrpc_c::value const& x) { |
|
|
y = xmlrpc_c::value_string(x); |
|
|
} |
|
|
|
|
|
inline void |
|
|
fromValue(int & y, xmlrpc_c::value const& x) { |
|
|
y = xmlrpc_c::value_int(x); |
|
|
} |
|
|
|
|
|
inline void |
|
|
fromValue(xmlrpc_int64 & y, xmlrpc_c::value const& x) { |
|
|
y = xmlrpc_c::value_i8(x); |
|
|
} |
|
|
|
|
|
inline void |
|
|
fromValue(bool & y, xmlrpc_c::value const& x) { |
|
|
y = xmlrpc_c::value_boolean(x); |
|
|
} |
|
|
|
|
|
inline void |
|
|
fromValue(double & y, xmlrpc_c::value const& x) { |
|
|
y = xmlrpc_c::value_double(x); |
|
|
} |
|
|
|
|
|
inline void |
|
|
fromValue(cbytestring & y, xmlrpc_c::value const& x) { |
|
|
y = xmlrpc_c::value_bytestring(x).vectorUcharValue(); |
|
|
} |
|
|
|
|
|
inline void |
|
|
fromValue(xmlrpc_c::value & y, xmlrpc_c::value const& x) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
y = x; |
|
|
} |
|
|
|
|
|
template<class K, class V> inline void |
|
|
fromValue(std::map<K, V> & y, xmlrpc_c::value const& x) { |
|
|
|
|
|
|
|
|
|
|
|
cstruct m = xmlrpc_c::value_struct(x); |
|
|
y.clear(); |
|
|
for (std::map<std::string, xmlrpc_c::value>::const_iterator p = m.begin(); |
|
|
p != m.end(); |
|
|
++p) { |
|
|
fromValue(y[p->first], p->second); |
|
|
} |
|
|
} |
|
|
|
|
|
template<class T> inline void |
|
|
fromValue(std::vector<T> & y, xmlrpc_c::value const& x) { |
|
|
|
|
|
|
|
|
|
|
|
carray v = xmlrpc_c::value_array(x).vectorValueValue(); |
|
|
y.resize(v.size()); |
|
|
for (unsigned int i = 0; i < v.size(); ++i) { |
|
|
fromValue(y[i], v[i]); |
|
|
} |
|
|
} |
|
|
|
|
|
template<class MemberClass> inline xmlrpc_c::value_array |
|
|
arrayValueArray(const MemberClass * const in, |
|
|
size_t const size) { |
|
|
|
|
|
|
|
|
|
|
|
return arrayValueSlice(in, in + size); |
|
|
} |
|
|
|
|
|
class XMLRPC_LIBPP_EXPORTED fault { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
enum code_t { |
|
|
CODE_UNSPECIFIED = 0, |
|
|
CODE_INTERNAL = -500, |
|
|
CODE_TYPE = -501, |
|
|
CODE_INDEX = -502, |
|
|
CODE_PARSE = -503, |
|
|
CODE_NETWORK = -504, |
|
|
CODE_TIMEOUT = -505, |
|
|
CODE_NO_SUCH_METHOD = -506, |
|
|
CODE_REQUEST_REFUSED = -507, |
|
|
CODE_INTROSPECTION_DISABLED = -508, |
|
|
CODE_LIMIT_EXCEEDED = -509, |
|
|
CODE_INVALID_UTF8 = -510 |
|
|
}; |
|
|
|
|
|
fault(); |
|
|
|
|
|
fault(std::string const _faultString, |
|
|
xmlrpc_c::fault::code_t const _faultCode |
|
|
= xmlrpc_c::fault::CODE_UNSPECIFIED |
|
|
); |
|
|
|
|
|
xmlrpc_c::fault::code_t getCode() const; |
|
|
|
|
|
std::string getDescription() const; |
|
|
|
|
|
private: |
|
|
bool valid; |
|
|
xmlrpc_c::fault::code_t code; |
|
|
std::string description; |
|
|
}; |
|
|
|
|
|
class XMLRPC_LIBPP_EXPORTED rpcOutcome { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
rpcOutcome(); |
|
|
rpcOutcome(xmlrpc_c::value const result); |
|
|
rpcOutcome(xmlrpc_c::fault const fault); |
|
|
bool succeeded() const; |
|
|
xmlrpc_c::fault getFault() const; |
|
|
xmlrpc_c::value getResult() const; |
|
|
private: |
|
|
bool valid; |
|
|
|
|
|
|
|
|
|
|
|
bool _succeeded; |
|
|
xmlrpc_c::value result; |
|
|
xmlrpc_c::fault fault; |
|
|
}; |
|
|
|
|
|
class XMLRPC_LIBPP_EXPORTED paramList { |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
paramList(unsigned int const paramCount = 0); |
|
|
|
|
|
paramList& |
|
|
add(xmlrpc_c::value const param); |
|
|
|
|
|
paramList& |
|
|
addx(xmlrpc_c::value const param); |
|
|
|
|
|
template<class T > paramList& addc(const T & x) { |
|
|
xmlrpc_c::paramList::add(toValue(x)); |
|
|
return *this; |
|
|
} |
|
|
|
|
|
unsigned int |
|
|
size() const; |
|
|
|
|
|
xmlrpc_c::value operator[](unsigned int const subscript) const; |
|
|
|
|
|
int |
|
|
getInt(unsigned int const paramNumber, |
|
|
int const minimum = INT_MIN, |
|
|
int const maximum = INT_MAX) const; |
|
|
|
|
|
bool |
|
|
getBoolean(unsigned int const paramNumber) const; |
|
|
|
|
|
double |
|
|
getDouble(unsigned int const paramNumber, |
|
|
double const minimum = -DBL_MAX, |
|
|
double const maximum = DBL_MAX) const; |
|
|
|
|
|
enum timeConstraint {TC_ANY, TC_NO_PAST, TC_NO_FUTURE}; |
|
|
|
|
|
time_t |
|
|
getDatetime_sec(unsigned int const paramNumber, |
|
|
timeConstraint const constraint |
|
|
= paramList::TC_ANY) const; |
|
|
|
|
|
std::string |
|
|
getString(unsigned int const paramNumber) const; |
|
|
|
|
|
cbytestring |
|
|
getBytestring(unsigned int const paramNumber) const; |
|
|
|
|
|
carray |
|
|
getArray(unsigned int const paramNumber, |
|
|
unsigned int const minSize = 0, |
|
|
unsigned int const maxSize = UINT_MAX) const; |
|
|
|
|
|
cstruct |
|
|
getStruct(unsigned int const paramNumber) const; |
|
|
|
|
|
void |
|
|
getNil(unsigned int const paramNumber) const; |
|
|
|
|
|
xmlrpc_int64 |
|
|
getI8(unsigned int const paramNumber, |
|
|
xmlrpc_int64 const minimum = XMLRPC_INT64_MIN, |
|
|
xmlrpc_int64 const maximum = XMLRPC_INT64_MAX) const; |
|
|
|
|
|
void |
|
|
verifyEnd(unsigned int const paramNumber) const; |
|
|
|
|
|
private: |
|
|
std::vector<xmlrpc_c::value> paramVector; |
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
#endif |
|
|
|