X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/0b99486a23b690671632c665065cc17ac6d6ca2c..3261ecc2503f45394eb3b9df97c36b08fb14fb1d:/projects/sgconf/xml.cpp diff --git a/projects/sgconf/xml.cpp b/projects/sgconf/xml.cpp index bf5589fe..abf2ccc6 100644 --- a/projects/sgconf/xml.cpp +++ b/projects/sgconf/xml.cpp @@ -1,6 +1,14 @@ #include "xml.h" +#include "api_action.h" +#include "options.h" +#include "config.h" + +#include "stg/servconf.h" + #include +#include +#include #include @@ -48,9 +56,7 @@ if (el != NULL) std::cout << Indent(state->level) << "\n"; } -} - -void SGCONF::PrintXML(const std::string& xml) +void PrintXML(const std::string& xml) { ParserState state = { 0 }; @@ -66,3 +72,34 @@ if (XML_Parse(parser, xml.c_str(), xml.length(), true) == XML_STATUS_ERROR) XML_ParserFree(parser); } + +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; + } +PrintXML(response); +} + +bool RawXMLFunction(const SGCONF::CONFIG & config, + const std::string & arg, + const std::map & /*options*/) +{ +STG::SERVCONF proto(config.server.data(), + config.port.data(), + config.localAddress.data(), + config.localPort.data(), + config.userName.data(), + config.userPass.data()); +return proto.RawXML(arg, RawXMLCallback, NULL) == STG::st_ok; +} + +} + +void SGCONF::AppendXMLOptionBlock(COMMANDS & commands, OPTION_BLOCKS & blocks) +{ +blocks.Add("Raw XML") + .Add("r", "raw", SGCONF::MakeAPIAction(commands, "", RawXMLFunction), "\tmake raw XML request"); +}