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("u", "username", SGCONF::MakeParamAction(config.userName, std::string("admin"), "<username>"), "\tadministrative login")
.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::MakeFunc1Action(), "\t\tmake raw XML request")
+/*blocks.Add("Admins management options")
+ .Add("get-admins", SGCONF::MakeConfAction())
+ .Add("get-admin", SGCONF::MakeConfAction())
+ .Add("add-admin", SGCONF::MakeConfAction())
+ .Add("del-admin", SGCONF::MakeConfAction())
+ .Add("chg-admin", SGCONF::MakeConfAction());*/
SGCONF::PARSER_STATE state(false, argc, argv);
--- /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
res = "INSERT INTO users SET login='test',Address='',AlwaysOnline=0,"\
"Credit=0.0,CreditExpire=0,Down=0,Email='',DisabledDetailStat=0,"\
"StgGroup='',IP='192.168.1.1',Note='',Passive=0,Password='123456',"\
- "Phone='', RealName='',Tariff='tariff',TariffChange='',Userdata0='',"\
- "Userdata1='',";
+ "Phone='', RealName='',Tariff='tariff',TariffChange='',NAS='',";
+
+ for (int i = 0; i < USERDATA_NUM; i++)
+ {
+ strprintf(¶m, " Userdata%d='',", i);
+ res += param;
+ }
for (int i = 0; i < DIR_NUM; i++)
{
//-----------------------------------------------------------------------------
int MYSQL_STORE::AddUser(const std::string & login) const
{
-sprintf(qbuf,"INSERT INTO users SET login='%s'", login.c_str());
-
-if(MysqlSetQuery(qbuf))
+std::string query = "INSERT INTO users SET login='" + login + "',Note='',NAS=''";
+
+for (int i = 0; i < USERDATA_NUM; i++)
+ query += ",Userdata" + x2str(i) + "=''";
+
+if(MysqlSetQuery(query.c_str()))
{
errorStr = "Couldn't add user:\n";
//errorStr += mysql_error(sock);
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);