1 #ifndef XMLRPC_BASE_HPP_INCLUDED
2 #define XMLRPC_BASE_HPP_INCLUDED
11 #include <xmlrpc-c/base.h>
17 // This is a handle. You don't want to create a pointer to this;
18 // it is in fact a pointer itself.
21 // This creates a placeholder. It can't be used for anything, but
22 // holds memory. instantiate() can turn it into a real object.
24 value(xmlrpc_c::value const &value); // copy constructor
45 operator=(xmlrpc_c::value const&);
47 // The following are not meant to be public to users, but just to
48 // other Xmlrpc-c library modules. If we ever go to a pure C++
49 // implementation, not based on C xmlrpc_value objects, this shouldn't
53 appendToCArray(xmlrpc_value * const arrayP) const;
56 addToCStruct(xmlrpc_value * const structP,
57 std::string const key) const;
62 value(xmlrpc_value * const valueP);
65 instantiate(xmlrpc_value * const valueP);
66 // Work only on a placeholder object created by the no-argument
69 xmlrpc_value * cValueP;
70 // NULL means this is merely a placeholder object.
75 class value_int : public value {
77 value_int(int const cvalue);
79 value_int(xmlrpc_c::value const baseValue);
86 class value_boolean : public value {
88 value_boolean(bool const cvalue);
90 value_boolean(xmlrpc_c::value const baseValue);
92 operator bool() const;
97 class value_string : public value {
99 value_string(std::string const& cvalue);
101 value_string(xmlrpc_c::value const baseValue);
103 operator std::string() const;
108 class value_double : public value {
110 value_double(double const cvalue);
112 value_double(xmlrpc_c::value const baseValue);
114 operator double() const;
119 class value_datetime : public value {
121 value_datetime(std::string const cvalue);
122 value_datetime(time_t const cvalue);
123 value_datetime(struct timeval const& cvalue);
124 value_datetime(struct timespec const& cvalue);
126 value_datetime(xmlrpc_c::value const baseValue);
128 operator time_t() const;
133 class value_bytestring : public value {
135 value_bytestring(std::vector<unsigned char> const& cvalue);
137 value_bytestring(xmlrpc_c::value const baseValue);
139 // You can't cast to a vector because the compiler can't tell which
140 // constructor to use (complains about ambiguity). So we have this:
141 std::vector<unsigned char>
142 vectorUcharValue() const;
150 class value_nil : public value {
154 value_nil(xmlrpc_c::value const baseValue);
159 class value_struct : public value {
161 value_struct(std::map<std::string, xmlrpc_c::value> const& cvalue);
163 value_struct(xmlrpc_c::value const baseValue);
165 operator std::map<std::string, xmlrpc_c::value>() const;
170 class value_array : public value {
172 value_array(std::vector<xmlrpc_c::value> const& cvalue);
174 value_array(xmlrpc_c::value const baseValue);
176 std::vector<xmlrpc_c::value>
177 vectorValueValue() const;
186 /*----------------------------------------------------------------------------
187 This is an XML-RPC fault.
189 This object is not intended to be used to represent a fault in the
190 execution of XML-RPC client/server software -- just a fault in an
191 XML-RPC RPC as described by the XML-RPC spec.
193 There is no way to represent "no fault" with this object. The object is
194 meaningful only in the context of some fault.
195 -----------------------------------------------------------------------------*/
198 CODE_UNSPECIFIED = 0,
199 CODE_INTERNAL = -500,
205 CODE_NO_SUCH_METHOD = -506,
206 CODE_REQUEST_REFUSED = -507,
207 CODE_INTROSPECTION_DISABLED = -508,
208 CODE_LIMIT_EXCEEDED = -509,
209 CODE_INVALID_UTF8 = -510
214 fault(std::string const _faultString,
215 xmlrpc_c::fault::code_t const _faultCode
216 = xmlrpc_c::fault::CODE_UNSPECIFIED
219 xmlrpc_c::fault::code_t getCode() const;
221 std::string getDescription() const;
225 xmlrpc_c::fault::code_t code;
226 std::string description;
230 /*----------------------------------------------------------------------------
231 The outcome of a validly executed RPC -- either an XML-RPC fault
232 or an XML-RPC value of the result.
233 -----------------------------------------------------------------------------*/
236 rpcOutcome(xmlrpc_c::value const result);
237 rpcOutcome(xmlrpc_c::fault const fault);
238 bool succeeded() const;
239 xmlrpc_c::fault getFault() const;
240 xmlrpc_c::value getResult() const;
243 // This is false in a placeholder variable -- i.e. an object you
244 // create with the no-argument constructor, which is waiting to be
245 // assigned a value. When false, nothing below is valid.
247 xmlrpc_c::value result; // valid if 'succeeded'
248 xmlrpc_c::fault fault; // valid if not 'succeeded'
252 /*----------------------------------------------------------------------------
253 A parameter list of an XML-RPC call.
254 -----------------------------------------------------------------------------*/
256 paramList(unsigned int const paramCount = 0);
259 add(xmlrpc_c::value const param);
264 xmlrpc_c::value operator[](unsigned int const subscript) const;
267 getInt(unsigned int const paramNumber,
268 int const minimum = INT_MIN,
269 int const maximum = INT_MAX) const;
272 getBoolean(unsigned int const paramNumber) const;
275 getDouble(unsigned int const paramNumber,
276 double const minimum = -DBL_MAX,
277 double const maximum = DBL_MAX) const;
279 enum timeConstraint {TC_ANY, TC_NO_PAST, TC_NO_FUTURE};
282 getDatetime_sec(unsigned int const paramNumber,
283 timeConstraint const constraint
284 = paramList::TC_ANY) const;
287 getString(unsigned int const paramNumber) const;
289 std::vector<unsigned char>
290 getBytestring(unsigned int const paramNumber) const;
292 std::vector<xmlrpc_c::value>
293 getArray(unsigned int const paramNumber,
294 unsigned int const minSize = 0,
295 unsigned int const maxSize = UINT_MAX) const;
297 std::map<std::string, xmlrpc_c::value>
298 getStruct(unsigned int const paramNumber) const;
301 getNil(unsigned int const paramNumber) const;
304 verifyEnd(unsigned int const paramNumber) const;
307 std::vector<xmlrpc_c::value> paramVector;