5 #include "stg/servconf.h"
19 std::string Indent(size_t level)
21 return std::string(level * 4, ' ');
24 std::string PrintAttr(const char ** attr)
31 if (*(attr + 1) == NULL)
33 res += std::string(" ") + *attr + "=\"" + *(attr + 1) + "\"";
39 void Start(void * data, const char * el, const char ** attr)
41 ParserState * state = static_cast<ParserState *>(data);
43 std::cout << Indent(state->level) << "<" << el << PrintAttr(attr) << ">\n";
47 void End(void * data, const char * el)
49 ParserState * state = static_cast<ParserState *>(data);
52 std::cout << Indent(state->level) << "</" << el << ">\n";
55 void RawXMLCallback(bool result, const std::string & reason, const std::string & response, void * /*data*/)
59 std::cerr << "Failed to get raw XML response. Reason: '" << reason << "'." << std::endl;
62 SGCONF::PrintXML(response);
67 void SGCONF::PrintXML(const std::string& xml)
69 ParserState state = { 0 };
71 XML_Parser parser = XML_ParserCreate(NULL);
72 XML_ParserReset(parser, NULL);
73 XML_SetElementHandler(parser, Start, End);
74 XML_SetUserData(parser, &state);
76 if (XML_Parse(parser, xml.c_str(), xml.length(), true) == XML_STATUS_ERROR)
77 std::cerr << "XML parse error at line " << XML_GetCurrentLineNumber(parser)
78 << ": '" << XML_ErrorString(XML_GetErrorCode(parser)) << "'"
81 XML_ParserFree(parser);
84 bool SGCONF::RawXMLFunction(const SGCONF::CONFIG & config,
85 const std::string & arg,
86 const std::map<std::string, std::string> & /*options*/)
88 STG::SERVCONF proto(config.server.data(),
90 config.userName.data(),
91 config.userPass.data());
92 return proto.RawXML(arg, RawXMLCallback, NULL) == STG::st_ok;