X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/186fb2b18b89a0280b8cc4b5ea8f7a59d3bd0853..29e9a2de0b45893850bbf56ee38e7fd235a6df15:/projects/sgconf/xml.cpp diff --git a/projects/sgconf/xml.cpp b/projects/sgconf/xml.cpp deleted file mode 100644 index ec8b9178..00000000 --- a/projects/sgconf/xml.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include "xml.h" - -#include "config.h" - -#include "stg/servconf.h" - -#include - -#include - -namespace -{ - -struct ParserState -{ -size_t level; -}; - -std::string Indent(size_t level) -{ -return std::string(level * 4, ' '); -} - -std::string PrintAttr(const char ** attr) -{ -std::string res; -if (attr == NULL) - return res; -while (*attr) - { - if (*(attr + 1) == NULL) - return res; - res += std::string(" ") + *attr + "=\"" + *(attr + 1) + "\""; - ++attr; ++attr; - } -return res; -} - -void Start(void * data, const char * el, const char ** attr) -{ -ParserState * state = static_cast(data); -if (el != NULL) - std::cout << Indent(state->level) << "<" << el << PrintAttr(attr) << ">\n"; -++state->level; -} - -void End(void * data, const char * el) -{ -ParserState * state = static_cast(data); ---state->level; -if (el != NULL) - std::cout << Indent(state->level) << "\n"; -} - -void RawXMLCallback(bool result, const std::string & reason, const std::string & response, void * /*data*/) -{ -if (!result) - { - std::cerr << "Failed to get raw XML response. Reason: '" << reason << "'." << std::endl; - return; - } -SGCONF::PrintXML(response); -} - -} - -void SGCONF::PrintXML(const std::string& xml) -{ -ParserState state = { 0 }; - -XML_Parser parser = XML_ParserCreate(NULL); -XML_ParserReset(parser, NULL); -XML_SetElementHandler(parser, Start, End); -XML_SetUserData(parser, &state); - -if (XML_Parse(parser, xml.c_str(), xml.length(), true) == XML_STATUS_ERROR) - std::cerr << "XML parse error at line " << XML_GetCurrentLineNumber(parser) - << ": '" << XML_ErrorString(XML_GetErrorCode(parser)) << "'" - << std::endl; - -XML_ParserFree(parser); -} - -bool SGCONF::RawXMLFunction(const SGCONF::CONFIG & config, - const std::string & arg, - const std::map & /*options*/) -{ - STG::SERVCONF proto(config.server.data(), - config.port.data(), - config.userName.data(), - config.userPass.data()); - return proto.RawXML(arg, RawXMLCallback, NULL) == STG::st_ok; -}