84 default:
_value.asBinary = 0;
break;
95 else if (
int(
_value.asArray->size()) < size)
106 if (
int(
_value.asArray->size()) < size)
107 _value.asArray->resize(size);
138 default:
_value.asBinary = 0;
break;
146 static bool tmEq(
struct tm
const& t1,
struct tm
const& t2) {
147 return t1.tm_sec == t2.tm_sec && t1.tm_min == t2.tm_min &&
148 t1.tm_hour == t2.tm_hour && t1.tm_mday == t2.tm_mday &&
149 t1.tm_mon == t2.tm_mon && t1.tm_year == t2.tm_year;
173 ValueStruct::const_iterator it1=
_value.asStruct->begin();
175 while (it1 !=
_value.asStruct->end()) {
192 return !(*
this == other);
220 int savedOffset = *offset;
226 int afterValueOffset = *offset;
229 if (typeTag == BOOLEAN_TAG)
231 else if (typeTag == I4_TAG || typeTag == INT_TAG)
233 else if (typeTag == DOUBLE_TAG)
235 else if (typeTag.empty() || typeTag ==
STRING_TAG)
237 else if (typeTag == DATETIME_TAG)
239 else if (typeTag == BASE64_TAG)
241 else if (typeTag == ARRAY_TAG)
243 else if (typeTag == STRUCT_TAG)
246 else if (typeTag == VALUE_ETAG)
248 *offset = afterValueOffset;
255 *offset = savedOffset;
274 return std::string();
281 const char* valueStart = valueXml.c_str() + *offset;
283 long ivalue = strtol(valueStart, &valueEnd, 10);
284 if (valueEnd == valueStart || (ivalue != 0 && ivalue != 1))
288 _value.asBool = (ivalue == 1);
289 *offset += int(valueEnd - valueStart);
297 xml += (
_value.asBool ?
"1" :
"0");
306 const char* valueStart = valueXml.c_str() + *offset;
308 long ivalue = strtol(valueStart, &valueEnd, 10);
309 if (valueEnd == valueStart)
313 _value.asInt = int(ivalue);
314 *offset += int(valueEnd - valueStart);
321 snprintf(buf,
sizeof(buf)-1,
"%d",
_value.asInt);
322 buf[
sizeof(buf)-1] = 0;
334 const char* valueStart = valueXml.c_str() + *offset;
341 std::string tmplocale;
342 char* locale_cstr = setlocale(LC_NUMERIC, 0);
345 tmplocale = locale_cstr;
346 setlocale(LC_NUMERIC,
"POSIX");
349 double dvalue = strtod(valueStart, &valueEnd);
351 if (tmplocale.size() > 0) {
352 setlocale(LC_NUMERIC, tmplocale.c_str());
355 if (valueEnd == valueStart)
360 *offset += int(valueEnd - valueStart);
367 std::stringstream ss;
368 ss.imbue(std::locale::classic());
383 size_t valueEnd = valueXml.find(
'<', *offset);
384 if (valueEnd == std::string::npos)
389 *offset += int(
_value.asString->length());
406 size_t valueEnd = valueXml.find(
'<', *offset);
407 if (valueEnd == std::string::npos)
410 std::string stime = valueXml.substr(*offset, valueEnd-*offset);
414 if (sscanf_s(stime.c_str(),
"%4d%2d%2dT%2d:%2d:%2d",&t.tm_year,&t.tm_mon,&t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec) != 6)
416 if (sscanf(stime.c_str(),
"%4d%2d%2dT%2d:%2d:%2d",&t.tm_year,&t.tm_mon,&t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec) != 6)
422 _value.asTime =
new struct tm(t);
423 *offset += int(stime.length());
429 struct tm* t =
_value.asTime;
431 snprintf(buf,
sizeof(buf)-1,
"%4d%02d%02dT%02d:%02d:%02d",
432 t->tm_year,t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
433 buf[
sizeof(buf)-1] = 0;
444 std::size_t base64EncodedSize(std::size_t raw_size)
447 if (raw_size == 0)
return 1;
451 std::size_t encoded = (raw_size + 2) / 3 * 4;
452 encoded += (encoded + 71) / 72;
456 std::size_t base64DecodedSize(std::size_t encoded_size)
459 if (encoded_size == 0)
return 1;
462 return (encoded_size + 3) / 4 * 3;
470 size_t valueEnd = valueXml.find(
'<', *offset);
471 if (valueEnd == std::string::npos)
474 std::size_t encoded_size = valueEnd - *offset;
482 std::size_t
size = decoder.
decode(&valueXml[*offset], encoded_size, &(*
_value.asBinary)[0]);
483 _value.asBinary->resize(size);
485 *offset += encoded_size;
495 std::size_t offset = xml.size();
497 xml.resize(xml.size() + base64EncodedSize(
_value.asBinary->size()));
500 offset += encoder.
encode(&(*
_value.asBinary)[0],
_value.asBinary->size(), &xml[offset]);
519 while (v.
fromXml(valueXml, offset))
520 _value.asArray->push_back(v);
536 int s = int(
_value.asArray->size());
537 for (
int i=0; i<
s; ++i)
538 xml +=
_value.asArray->at(i).toXml();
558 if ( ! val.
valid()) {
562 const std::pair<const std::string, XmlRpcValue> p(name, val);
563 _value.asStruct->insert(p);
578 ValueStruct::const_iterator it;
579 for (it=
_value.asStruct->begin(); it!=
_value.asStruct->end(); ++it) {
584 xml += it->second.toXml();
605 struct tm* t =
_value.asTime;
607 snprintf(buf,
sizeof(buf)-1,
"%4d%02d%02dT%02d:%02d:%02d",
608 t->tm_year,t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
609 buf[
sizeof(buf)-1] = 0;
615 std::stringstream buffer;
616 buffer.write(&(*
_value.asBinary)[0],
_value.asBinary->size());
618 encoder.
encode(buffer, os);
623 int s = int(
_value.asArray->size());
625 for (
int i=0; i<
s; ++i)
627 if (i > 0) os <<
',';
628 _value.asArray->at(i).write(os);
636 ValueStruct::const_iterator it;
637 for (it=
_value.asStruct->begin(); it!=
_value.asStruct->end(); ++it)
639 if (it!=
_value.asStruct->begin()) os <<
',';
640 os << it->first <<
':';
641 it->second.write(os);
static const char ARRAY_ETAG[]
bool intFromXml(std::string const &valueXml, int *offset)
static const char BASE64_TAG[]
std::string arrayToXml() const
static const char NAME_TAG[]
std::vector< XmlRpcValue > ValueArray
int decode(char value_in)
static const char DOUBLE_TAG[]
int encode_end(char *plaintext_out)
static const char DATA_ETAG[]
RPC method arguments and results are represented by Values.
std::string doubleToXml() const
static const char STRUCT_ETAG[]
static const char VALUE_ETAG[]
void assertTypeOrInvalid(Type t)
static const char DOUBLE_ETAG[]
std::string timeToXml() const
std::string stringToXml() const
static const char BASE64_ETAG[]
std::string intToXml() const
static const char ARRAY_TAG[]
static const char DATA_TAG[]
int size() const
Return the size for string, base64, array, and struct values.
static const char NAME_ETAG[]
static std::string getNextTag(std::string const &xml, int *offset)
static std::string parseTag(const char *tag, std::string const &xml, int *offset)
Returns contents between <tag> and </tag>, updates offset to char after </tag>
XmlRpcValue & operator=(XmlRpcValue const &rhs)
bool valid() const
Return true if the value has been set to something.
static bool findTag(const char *tag, std::string const &xml, int *offset)
Returns true if the tag is found and updates offset to the char after the tag.
std::string boolToXml() const
int encode(char value_in)
static const char MEMBER_ETAG[]
static const char BOOLEAN_ETAG[]
static const char STRING_TAG[]
union XmlRpc::XmlRpcValue::@0 _value
static const char DATETIME_TAG[]
std::map< std::string, XmlRpcValue > ValueStruct
std::string toXml() const
Encode the Value in xml.
void assertArray(int size) const
static const char VALUE_TAG[]
std::string structToXml() const
std::string binaryToXml() const
bool stringFromXml(std::string const &valueXml, int *offset)
static const char I4_ETAG[]
bool fromXml(std::string const &valueXml, int *offset)
Decode xml. Destroys any existing value.
bool operator==(XmlRpcValue const &other) const
static const char I4_TAG[]
bool hasMember(const std::string &name) const
Check for the existence of a struct member by name.
std::ostream & write(std::ostream &os) const
Write the value (no xml encoding)
bool binaryFromXml(std::string const &valueXml, int *offset)
static const char DATETIME_ETAG[]
static bool tmEq(struct tm const &t1, struct tm const &t2)
bool doubleFromXml(std::string const &valueXml, int *offset)
static std::string xmlEncode(const std::string &raw)
Convert raw text to encoded xml.
bool timeFromXml(std::string const &valueXml, int *offset)
static const char INT_TAG[]
std::vector< char > BinaryData
static const char BOOLEAN_TAG[]
bool operator!=(XmlRpcValue const &other) const
std::ostream & operator<<(std::ostream &os, const XmlRpc::XmlRpcValue &v)
static std::string _doubleFormat
bool arrayFromXml(std::string const &valueXml, int *offset)
static std::string xmlDecode(const std::string &encoded)
Convert encoded xml to raw text.
bool structFromXml(std::string const &valueXml, int *offset)
bool boolFromXml(std::string const &valueXml, int *offset)
static const char MEMBER_TAG[]
static bool nextTagIs(const char *tag, std::string const &xml, int *offset)
static const char STRUCT_TAG[]