You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.0 KiB
C++
79 lines
2.0 KiB
C++
#include "webcc/soap_response.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include "webcc/soap_xml.h"
|
|
|
|
namespace webcc {
|
|
|
|
void SoapResponse::ToXmlBody(pugi::xml_node xbody) {
|
|
assert(!result_name_.empty());
|
|
|
|
pugi::xml_node xop = soap_xml::AddChild(xbody, service_ns_.name,
|
|
operation_ + "Response");
|
|
soap_xml::AddNSAttr(xop, service_ns_.name, service_ns_.url);
|
|
|
|
pugi::xml_node xresult = soap_xml::AddChild(xop, service_ns_.name,
|
|
result_name_);
|
|
|
|
// xresult.text().set() also works for PCDATA.
|
|
// TODO: Add SetText() to soap_xml.h|cpp.
|
|
xresult.append_child(is_cdata_ ? pugi::node_cdata : pugi::node_pcdata)
|
|
.set_value(result_.c_str());
|
|
}
|
|
|
|
bool SoapResponse::FromXmlBody(pugi::xml_node xbody) {
|
|
// Check Fault element.
|
|
|
|
pugi::xml_node xfault = soap_xml::GetChildNoNS(xbody, "Fault");
|
|
|
|
// TODO: service_ns_.url
|
|
|
|
if (xfault) {
|
|
fault_.reset(new SoapFault);
|
|
|
|
pugi::xml_node xfaultcode = soap_xml::GetChildNoNS(xfault, "faultcode");
|
|
pugi::xml_node xfaultstring = soap_xml::GetChildNoNS(xfault, "faultstring");
|
|
pugi::xml_node xdetail = soap_xml::GetChildNoNS(xfault, "detail");
|
|
|
|
if (xfaultcode) {
|
|
fault_->faultcode = xfaultcode.text().as_string();
|
|
}
|
|
if (xfaultstring) {
|
|
fault_->faultstring = xfaultstring.text().as_string();
|
|
}
|
|
if (xdetail) {
|
|
fault_->detail = xdetail.text().as_string();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// Check Response element.
|
|
|
|
pugi::xml_node xresponse = soap_xml::GetChildNoNS(xbody,
|
|
operation_ + "Response");
|
|
|
|
if (!xresponse) {
|
|
return false;
|
|
}
|
|
|
|
soap_xml::SplitName(xresponse, &service_ns_.name, nullptr);
|
|
service_ns_.url = soap_xml::GetNSAttr(xresponse, service_ns_.name);
|
|
|
|
// Call result parser on each child of the response node.
|
|
if (parser_) {
|
|
pugi::xml_node xchild = xresponse.first_child();
|
|
while (xchild) {
|
|
if (!parser_(xchild)) {
|
|
break;
|
|
}
|
|
xchild = xchild.next_sibling();
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
} // namespace webcc
|