SRCS = ./main.cpp \
./common_sg.cpp \
./options.cpp \
- ./actions.cpp
+ ./actions.cpp \
+ ./xml.cpp
STGLIBS = conffiles \
srvconf \
#include "common_sg.h"
#include "sg_error_codes.h"
+#include "xml.h"
#include "options.h"
#include "actions.h"
#include "config.h"
return true;
}
+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);
+}
+
void Usage();
void UsageAll();
void UsageImpl(bool full);
.Add("w", "userpass", SGCONF::MakeParamAction(config.userPass, "<password>"), "\tpassword for the administrative login")
.Add("a", "address", SGCONF::MakeParamAction(config, "<connection string>"), "connection params as a single string in format: <login>:<password>@<host>:<port>");
blocks.Add("Raw XML")
- .Add("r", "raw", SGCONF::MakeConfAction(), "\t\tmake raw XML request")
+ .Add("r", "raw", SGCONF::MakeFunc1Action(), "\t\tmake raw XML request")
/*blocks.Add("Admins management options")
.Add("get-admins", SGCONF::MakeConfAction())
.Add("get-admin", SGCONF::MakeConfAction())
--- /dev/null
+#include "xml.h"
+
+#include <expat.h>
+
+namespace
+{
+
+struct ParserState
+{
+size_t level;
+};
+
+std::string Indent(size_t size)
+{
+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<ParserState *>(data);
+if (el != NULL)
+ std::cout << Indent(state->level) << "<" << el << PrintAttrs(attr) << ">\n";
+++state->level;
+}
+
+void End(void * data, const char * el)
+{
+ParserState * state = static_cast<ParserState *>(data);
+if (el != NULL)
+ std::cout << Indent(state->level) << "</" << el << ">\n";
+--state->level;
+}
+
+}
+
+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(sc->parser)
+ << ": '" << XML_ErrorString(XML_GetErrorCode(sc->parser)) << "'"
+ << std::endl;
+
+XML_ParserFree(parser);
+}
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_SGCONF_XML_H__
+#define __STG_SGCONF_XML_H__
+
+#include <string>
+
+namespace SGCONF
+{
+
+void PrintXML(const std::string& xml);
+
+}
+
+#endif
public:
IMPL(const std::string & server, uint16_t port,
const std::string & login, const std::string & password);
+ ~IMPL() { XML_ParserFree(parser); }
const std::string & GetStrError() const;
static void Start(void * data, const char * el, const char ** attr);