92 default:
_value.asBinary = 0;
break;
103 else if (
int(
_value.asArray->size()) < size)
114 if (
int(
_value.asArray->size()) < size)
115 _value.asArray->resize(size);
152 default:
_value.asBinary = 0;
break;
160 static bool tmEq(
struct tm
const& t1,
struct tm
const& t2) {
161 return t1.tm_sec == t2.tm_sec && t1.tm_min == t2.tm_min &&
162 t1.tm_hour == t2.tm_hour && t1.tm_mday == t2.tm_mday &&
163 t1.tm_mon == t2.tm_mon && t1.tm_year == t2.tm_year;
187 ValueStruct::const_iterator it1=
_value.asStruct->begin();
189 while (it1 !=
_value.asStruct->end()) {
206 return !(*
this == other);
234 if (offset == NULL)
return false;
236 int savedOffset = *offset;
242 int afterValueOffset = *offset;
245 if (typeTag == BOOLEAN_TAG)
247 else if (typeTag == I4_TAG || typeTag == INT_TAG)
249 else if (typeTag == DOUBLE_TAG)
251 else if (typeTag.empty() || typeTag ==
STRING_TAG)
253 else if (typeTag == DATETIME_TAG)
255 else if (typeTag == BASE64_TAG)
257 else if (typeTag == ARRAY_TAG)
259 else if (typeTag == STRUCT_TAG)
262 else if (typeTag == VALUE_ETAG)
264 *offset = afterValueOffset;
271 *offset = savedOffset;
290 return std::string();
297 const char* valueStart = valueXml.c_str() + *offset;
299 long ivalue = strtol(valueStart, &valueEnd, 10);
300 if (valueEnd == valueStart || (ivalue != 0 && ivalue != 1))
304 _value.asBool = (ivalue == 1);
305 *offset += int(valueEnd - valueStart);
313 xml += (
_value.asBool ?
"1" :
"0");
322 const char* valueStart = valueXml.c_str() + *offset;
324 long ivalue = strtol(valueStart, &valueEnd, 10);
325 if (valueEnd == valueStart)
329 _value.asInt = int(ivalue);
330 *offset += int(valueEnd - valueStart);
337 std::snprintf(buf,
sizeof(buf)-1,
"%d",
_value.asInt);
338 buf[
sizeof(buf)-1] = 0;
350 const char* valueStart = valueXml.c_str() + *offset;
357 std::string tmplocale;
358 char* locale_cstr = setlocale(LC_NUMERIC, 0);
361 tmplocale = locale_cstr;
362 setlocale(LC_NUMERIC,
"POSIX");
365 double dvalue = strtod(valueStart, &valueEnd);
367 if (tmplocale.size() > 0) {
368 setlocale(LC_NUMERIC, tmplocale.c_str());
371 if (valueEnd == valueStart)
376 *offset += int(valueEnd - valueStart);
383 std::stringstream ss;
384 ss.imbue(std::locale::classic());
399 size_t valueEnd = valueXml.find(
'<', *offset);
400 if (valueEnd == std::string::npos)
405 *offset += int(
_value.asString->length());
422 size_t valueEnd = valueXml.find(
'<', *offset);
423 if (valueEnd == std::string::npos)
426 std::string stime = valueXml.substr(*offset, valueEnd-*offset);
430 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)
432 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)
438 _value.asTime =
new struct tm(t);
439 *offset += int(stime.length());
445 struct tm* t =
_value.asTime;
447 std::snprintf(buf,
sizeof(buf)-1,
"%4d%02d%02dT%02d:%02d:%02d",
448 t->tm_year,t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
449 buf[
sizeof(buf)-1] = 0;
460 std::size_t base64EncodedSize(std::size_t raw_size)
463 if (raw_size == 0)
return 1;
467 std::size_t encoded = (raw_size + 2) / 3 * 4;
468 encoded += (encoded + 71) / 72;
472 std::size_t base64DecodedSize(std::size_t encoded_size)
475 if (encoded_size == 0)
return 1;
478 return (encoded_size + 3) / 4 * 3;
486 size_t valueEnd = valueXml.find(
'<', *offset);
487 if (valueEnd == std::string::npos)
490 std::size_t encoded_size = valueEnd - *offset;
498 std::size_t
size = decoder.
decode(&valueXml[*offset], encoded_size, &(*
_value.asBinary)[0]);
499 _value.asBinary->resize(size);
501 *offset += encoded_size;
511 std::size_t offset = xml.size();
513 xml.resize(xml.size() + base64EncodedSize(
_value.asBinary->size()));
516 offset += encoder.
encode(
_value.asBinary->data(),
_value.asBinary->size(), &xml[offset]);
535 while (v.
fromXml(valueXml, offset))
536 _value.asArray->push_back(v);
552 int s = int(
_value.asArray->size());
553 for (
int i=0; i<
s; ++i)
554 xml +=
_value.asArray->at(i).toXml();
574 if ( ! val.
valid()) {
578 const std::pair<const std::string, XmlRpcValue> p(name, val);
579 _value.asStruct->insert(p);
594 ValueStruct::const_iterator it;
595 for (it=
_value.asStruct->begin(); it!=
_value.asStruct->end(); ++it) {
600 xml += it->second.toXml();
619 static std::once_flag once;
621 int required_size = std::snprintf(buf,
sizeof(buf)-1,
623 if (required_size < 0) {
627 }
else if (required_size < static_cast<int>(
sizeof(buf))) {
628 buf[
sizeof(buf)-1] = 0;
631 std::vector<char> required_buf(required_size+1);
632 std::snprintf(required_buf.data(), required_size,
634 required_buf[required_size] = 0;
635 os << required_buf.data();
642 struct tm* t =
_value.asTime;
644 std::snprintf(buf,
sizeof(buf)-1,
"%4d%02d%02dT%02d:%02d:%02d",
645 t->tm_year,t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
646 buf[
sizeof(buf)-1] = 0;
652 std::stringstream buffer;
653 buffer.write(
_value.asBinary->data(),
_value.asBinary->size());
655 encoder.
encode(buffer, os);
660 int s = int(
_value.asArray->size());
662 for (
int i=0; i<
s; ++i)
664 if (i > 0) os <<
',';
665 _value.asArray->at(i).write(os);
673 ValueStruct::const_iterator it;
674 for (it=
_value.asStruct->begin(); it!=
_value.asStruct->end(); ++it)
676 if (it!=
_value.asStruct->begin()) os <<
',';
677 os << it->first <<
':';
678 it->second.write(os);
static const char ARRAY_ETAG[]
bool intFromXml(std::string const &valueXml, int *offset)
static const char BASE64_TAG[]
static const char NAME_TAG[]
std::vector< XmlRpcValue > ValueArray
int decode(char value_in)
void assertArray(int size) const
int size() const
Return the size for string, base64, array, and struct values.
static const char DOUBLE_TAG[]
int encode_end(char *plaintext_out)
static const char DATA_ETAG[]
void assertTypeOrInvalid(Type t) const
RPC method arguments and results are represented by Values.
static std::string nextTagData(const char *tag, std::string const &xml, int *offset)
static const char STRUCT_ETAG[]
static const char VALUE_ETAG[]
static const char DOUBLE_ETAG[]
static const char BASE64_ETAG[]
static const char ARRAY_TAG[]
static const char DATA_TAG[]
static const char NAME_ETAG[]
static std::string getNextTag(std::string const &xml, int *offset)
XmlRpcValue & operator=(XmlRpcValue const &rhs)
std::string binaryToXml() const
bool valid() const
Return true if the value has been set to something.
std::string stringToXml() const
static void error(const char *fmt,...)
Dump error messages somewhere.
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.
int encode(char value_in)
std::string timeToXml() const
static const char MEMBER_ETAG[]
std::string intToXml() const
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
bool operator!=(XmlRpcValue const &other) const
static const char VALUE_TAG[]
std::string boolToXml() const
bool stringFromXml(std::string const &valueXml, int *offset)
std::string structToXml() const
static const char I4_ETAG[]
bool fromXml(std::string const &valueXml, int *offset)
Decode xml. Destroys any existing value.
static const char I4_TAG[]
void assertStruct() const
bool binaryFromXml(std::string const &valueXml, int *offset)
static const char DATETIME_ETAG[]
static bool tmEq(struct tm const &t1, struct tm const &t2)
std::string toXml() const
Encode the Value in xml.
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)
bool operator==(XmlRpcValue const &other) const
static const char INT_TAG[]
std::vector< char > BinaryData
static const char BOOLEAN_TAG[]
std::ostream & write(std::ostream &os) const
Write the value (no xml encoding)
std::ostream & operator<<(std::ostream &os, const XmlRpc::XmlRpcValue &v)
static std::string const & getDoubleFormat()
Return the format used to write double values.
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)
std::string doubleToXml() const
std::string arrayToXml() const
bool boolFromXml(std::string const &valueXml, int *offset)
bool hasMember(const std::string &name) const
Check for the existence of a struct member by name.
static const char MEMBER_TAG[]
static bool nextTagIs(const char *tag, std::string const &xml, int *offset)
static const char STRUCT_TAG[]