]> git.stg.codes - stg.git/blobdiff - projects/sgconf/xml.cpp
Fight Optional
[stg.git] / projects / sgconf / xml.cpp
index bf5589fe856511d0e7539e3f09343e9450b582eb..93a06e23197926b2967b17af88214bddd793ebe4 100644 (file)
@@ -1,6 +1,15 @@
 #include "xml.h"
 
+#include "api_action.h"
+#include "options.h"
+#include "makeproto.h"
+#include "config.h"
+
+#include "stg/servconf.h"
+
 #include <iostream>
+#include <string>
+#include <map>
 
 #include <expat.h>
 
@@ -48,9 +57,7 @@ if (el != NULL)
     std::cout << Indent(state->level) << "</" << el << ">\n";
 }
 
-}
-
-void SGCONF::PrintXML(const std::string& xml)
+void PrintXML(const std::string& xml)
 {
 ParserState state = { 0 };
 
@@ -66,3 +73,28 @@ 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<std::string, std::string> & /*options*/)
+{
+return makeProto(config).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, "<xml>", RawXMLFunction), "\tmake raw XML request");
+}