/usr/include/xmlrpc-c/base.hpp is in libxmlrpc-c++8-dev 1.33.14-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | #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>
/*
XMLRPC_LIBPP_EXPORTED marks a symbol in this file that is exported from
libxmlrpc++.
XMLRPC_BUILDING_LIBPP says this compilation is part of libxmlrpc++, as
opposed to something that _uses_ libxmlrpc++.
*/
#ifdef XMLRPC_BUILDING_LIBPP
#define XMLRPC_LIBPP_EXPORTED XMLRPC_DLLEXPORT
#else
#define XMLRPC_LIBPP_EXPORTED
#endif
namespace xmlrpc_c {
class XMLRPC_LIBPP_EXPORTED value {
// This is a handle. You don't want to create a pointer to this;
// it is in fact a pointer itself.
public:
value();
// This creates a placeholder. It can't be used for anything, but
// holds memory. instantiate() can turn it into a real object.
value(xmlrpc_c::value const &value); // copy constructor
~value();
enum type_t {
// These are designed to be identical to the values for
// enum xmlrpc_type in the C library.
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;
// The following are not meant to be public to users, but just to
// other Xmlrpc-c library modules. If we ever go to a pure C++
// implementation, not based on C xmlrpc_value objects, this shouldn't
// be necessary.
void
appendToCArray(xmlrpc_value * const arrayP) const;
void
addToCStruct(xmlrpc_value * const structP,
std::string const key) const;
xmlrpc_value *
cValue() const;
// Not to be confused with public 'cvalue' method that all the derived
// classes have.
value(xmlrpc_value * const valueP);
void
instantiate(xmlrpc_value * const valueP);
// Works only on a placeholder object created by the no-argument
// constructor.
xmlrpc_value * cValueP;
// NULL means this is merely a placeholder object.
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;
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);
// You can't cast to a vector because the compiler can't tell which
// constructor to use (complains about ambiguity). So we have this:
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);
// You can't cast to a vector because the compiler can't tell which
// constructor to use (complains about ambiguity). So we have this:
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_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) {
/*----------------------------------------------------------------------------
This does a null conversion; you use it to catch all the XML-RPC types that
have no usable C++ equivalent, so you can do a toValue() of any XML-RPC
type at all. In particular: 'value_datetime', 'value_nil'.
-----------------------------------------------------------------------------*/
return v;
}
template<class K, class V> xmlrpc_c::value_struct
toValue(std::map<K, V> const& in) {
/*----------------------------------------------------------------------------
convert C++ map to XML-RPC structure
-----------------------------------------------------------------------------*/
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) {
/*----------------------------------------------------------------------------
convert C++ iterator pair to XML-RPC array
-----------------------------------------------------------------------------*/
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) {
/*----------------------------------------------------------------------------
convert C++ vector to XML-RPC array
-----------------------------------------------------------------------------*/
return arrayValueSlice(in.begin(), in.end());
}
// fromValue() returns via reference argument instead of by return value
// so the compiler can tell which version of it to invoke based on the
// desired output type.
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(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) {
/*----------------------------------------------------------------------------
This does a null conversion; it's so you can use fromValue() with
an XML-RPC value or C++ value without having to know which it is.
One reason you would have an XML-RPC value lying around with C++ values
is that some XML-RPC values don't have a common C++ equivalent.
-----------------------------------------------------------------------------*/
y = x;
}
template<class K, class V> inline void
fromValue(std::map<K, V> & y, xmlrpc_c::value const& x) {
/*----------------------------------------------------------------------------
Convert XML-RPC structure to C++ map.
-----------------------------------------------------------------------------*/
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) {
/*----------------------------------------------------------------------------
Convert XML-RPC array to C++ vector.
-----------------------------------------------------------------------------*/
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) {
/*----------------------------------------------------------------------------
convert C++ array to XML-RPC array
-----------------------------------------------------------------------------*/
return arrayValueSlice(in, in + size);
}
class XMLRPC_LIBPP_EXPORTED fault {
/*----------------------------------------------------------------------------
This is an XML-RPC fault.
This object is not intended to be used to represent a fault in the
execution of XML-RPC client/server software -- just a fault in an
XML-RPC RPC as described by the XML-RPC spec.
There is no way to represent "no fault" with this object. The object is
meaningful only in the context of some 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 {
/*----------------------------------------------------------------------------
The outcome of a validly executed RPC -- either an XML-RPC fault
or an XML-RPC value of the result.
-----------------------------------------------------------------------------*/
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;
// This is false in a placeholder variable -- i.e. an object you
// create with the no-argument constructor, which is waiting to be
// assigned a value. When false, nothing below is valid.
bool _succeeded;
xmlrpc_c::value result; // valid if 'succeeded'
xmlrpc_c::fault fault; // valid if not 'succeeded'
};
class XMLRPC_LIBPP_EXPORTED paramList {
/*----------------------------------------------------------------------------
A parameter list of an XML-RPC call.
-----------------------------------------------------------------------------*/
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;
};
} // namespace
#endif
|