From: Naffanya Date: Mon, 17 Mar 2014 21:08:43 +0000 (+0200) Subject: Merge branch 'master' into naffanya-dev X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/69aaa0bd928ece0837c8e88441c80f1f8cf1fe38?hp=9421e4b0be3a6a59e93ad092e3904b3ff8092e84 Merge branch 'master' into naffanya-dev --- diff --git a/projects/sgconf/Makefile b/projects/sgconf/Makefile index 0098ff5e..e564b246 100644 --- a/projects/sgconf/Makefile +++ b/projects/sgconf/Makefile @@ -9,7 +9,8 @@ PROG = sgconf SRCS = ./main.cpp \ ./common_sg.cpp \ ./options.cpp \ - ./actions.cpp + ./actions.cpp \ + ./xml.cpp STGLIBS = conffiles \ srvconf \ diff --git a/projects/sgconf/main.cpp b/projects/sgconf/main.cpp index a0ef89a1..2d39cb2c 100644 --- a/projects/sgconf/main.cpp +++ b/projects/sgconf/main.cpp @@ -23,6 +23,7 @@ #include "common_sg.h" #include "sg_error_codes.h" +#include "xml.h" #include "options.h" #include "actions.h" #include "config.h" @@ -134,6 +135,16 @@ array[pos] = value; 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); @@ -1239,6 +1250,14 @@ SGCONF::OPTION_BLOCK & block = blocks.Add("Connection options") .Add("u", "username", SGCONF::MakeParamAction(config.userName, std::string("admin"), ""), "\tadministrative login") .Add("w", "userpass", SGCONF::MakeParamAction(config.userPass, ""), "\tpassword for the administrative login") .Add("a", "address", SGCONF::MakeParamAction(config, ""), "connection params as a single string in format: :@:"); +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); diff --git a/projects/sgconf/xml.cpp b/projects/sgconf/xml.cpp new file mode 100644 index 00000000..9e1d8f80 --- /dev/null +++ b/projects/sgconf/xml.cpp @@ -0,0 +1,66 @@ +#include "xml.h" + +#include + +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(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(data); +if (el != NULL) + std::cout << Indent(state->level) << "\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); +} diff --git a/projects/sgconf/xml.h b/projects/sgconf/xml.h new file mode 100644 index 00000000..25ee35c3 --- /dev/null +++ b/projects/sgconf/xml.h @@ -0,0 +1,33 @@ +/* + * 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 + */ + +#ifndef __STG_SGCONF_XML_H__ +#define __STG_SGCONF_XML_H__ + +#include + +namespace SGCONF +{ + +void PrintXML(const std::string& xml); + +} + +#endif diff --git a/projects/stargazer/plugins/store/mysql/mysql_store.cpp b/projects/stargazer/plugins/store/mysql/mysql_store.cpp index 53de158a..995ed538 100644 --- a/projects/stargazer/plugins/store/mysql/mysql_store.cpp +++ b/projects/stargazer/plugins/store/mysql/mysql_store.cpp @@ -500,8 +500,13 @@ if(!IsTablePresent("users",sock)) 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++) { @@ -676,9 +681,12 @@ return 0; //----------------------------------------------------------------------------- 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); diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index 430de3c1..c7bf3d00 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -60,6 +60,7 @@ class SERVCONF::IMPL 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);