/* */ #include "XmlRpcResponse.h" #include #include #include "util.h" #ifdef HAVE_LIBZ # include "GZipEncoder.h" #endif // HAVE_LIBZ namespace aria2 { namespace xmlrpc { template static void encodeValue(const BDE& value, OutputStream& o); template static void encodeArray (InputIterator first, InputIterator last, OutputStream& o) { o << "" << ""; for(; first != last; ++first) { encodeValue(*first, o); } o << "" << ""; } template static void encodeStruct (InputIterator first, InputIterator last, OutputStream& o) { o << ""; for(; first != last; ++first) { o << "" << "" << util::htmlEscape((*first).first) << ""; encodeValue((*first).second, o); o << ""; } o << ""; } template static void encodeValue(const BDE& value, OutputStream& o) { o << ""; if(value.isString()) { o << "" << util::htmlEscape(value.s()) << ""; } else if(value.isInteger()) { o << "" << value.i() << ""; } else if(value.isList()) { encodeArray(value.listBegin(), value.listEnd(), o); } else if(value.isDict()) { encodeStruct(value.dictBegin(), value.dictEnd(), o); } o << ""; } template std::string encodeAll(OutputStream& o, int code, const BDE& param) { o << "" << ""; if(code == 0) { o << "" << ""; encodeValue(param, o); o << "" << ""; } else { o << ""; encodeValue(param, o); o << ""; } o << ""; return o.str(); } std::string XmlRpcResponse::toXml(bool gzip) const { if(gzip) { #ifdef HAVE_LIBZ GZipEncoder o; o.init(); return encodeAll(o, _code, _param); #else // !HAVE_LIBZ abort(); #endif // !HAVE_LIBZ } else { std::stringstream o; return encodeAll(o, _code, _param); } } } // namespace xmlrpc } // namespace aria2