parsers/get_services.cpp \
parsers/get_service.cpp \
parsers/chg_service.cpp \
+ parsers/get_corporations.cpp \
+ parsers/get_corp.cpp \
+ parsers/chg_corp.cpp \
netunit.cpp \
servconf.cpp
/*
* Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- */
-
- /*
- $Revision: 1.10 $
- $Date: 2009/03/17 09:52:35 $
- $Author: faust $
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
*/
#ifndef __STG_STGLIBS_SERVCONF_H__
struct USER_STAT_RES;
struct TARIFF_DATA_RES;
struct SERVICE_CONF_RES;
+struct CORP_CONF_RES;
namespace STG
{
SIMPLE::CALLBACK f, void * data);
int DelService(const std::string & name, SIMPLE::CALLBACK f, void * data);
+ int GetCorporations(GET_CORPORATIONS::CALLBACK f, void * data);
+ int GetCorp(const std::string & name, GET_CORP::CALLBACK f, void * data);
+ int ChgCorp(const CORP_CONF_RES & conf, SIMPLE::CALLBACK f, void * data);
+ int AddCorp(const std::string & name,
+ const CORP_CONF_RES & conf,
+ SIMPLE::CALLBACK f, void * data);
+ int DelCorp(const std::string & name, SIMPLE::CALLBACK f, void * data);
+
const std::string & GetStrError() const;
private:
struct ADMIN_CONF;
struct TARIFF_DATA;
struct SERVICE_CONF;
+struct CORP_CONF;
namespace STG
{
}
+namespace GET_CORP
+{
+
+typedef CORP_CONF INFO;
+typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data);
+
+}
+
+namespace GET_CORPORATIONS
+{
+
+typedef std::vector<GET_CORP::INFO> INFO;
+typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data);
+
+}
+
} // namespace STG
#endif
--- /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>
+ */
+
+#include "chg_corp.h"
+
+#include "stg/corp_conf.h"
+#include "stg/common.h"
+
+#include <sstream>
+
+using namespace STG;
+
+namespace
+{
+
+template <typename T>
+void appendResetable(std::ostream & stream, const std::string & name, const T & value)
+{
+if (!value.empty())
+ stream << "<" << name << " value=\"" << value.data() << "\"/>";
+}
+
+} // namespace anonymous
+
+std::string CHG_CORP::Serialize(const CORP_CONF_RES & conf)
+{
+std::ostringstream stream;
+
+appendResetable(stream, "name", conf.name);
+appendResetable(stream, "cash", conf.cash);
+
+return stream.str();
+}
--- /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_STGLIBS_SRVCONF_PARSER_CHG_CORP_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_CHG_CORP_H__
+
+#include "base.h"
+
+#include "stg/servconf_types.h"
+
+#include <string>
+
+struct CORP_CONF_RES;
+
+namespace STG
+{
+namespace CHG_CORP
+{
+
+std::string Serialize(const CORP_CONF_RES & conf);
+
+} // namespace CHG_CORP
+} // namespace STG
+
+#endif
--- /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>
+ */
+
+#include "get_corp.h"
+
+#include "parsers/property.h"
+
+#include "stg/common.h"
+
+#include <strings.h>
+
+using namespace STG;
+
+GET_CORP::PARSER::PARSER(CALLBACK f, void * d)
+ : callback(f),
+ data(d),
+ depth(0),
+ parsingAnswer(false)
+{
+ AddParser(propertyParsers, "name", info.name);
+ AddParser(propertyParsers, "cash", info.cash);
+}
+//-----------------------------------------------------------------------------
+GET_CORP::PARSER::~PARSER()
+{
+ PROPERTY_PARSERS::iterator it(propertyParsers.begin());
+ while (it != propertyParsers.end())
+ delete (it++)->second;
+}
+//-----------------------------------------------------------------------------
+int GET_CORP::PARSER::ParseStart(const char * el, const char ** attr)
+{
+depth++;
+if (depth == 1)
+ ParseCorp(el, attr);
+
+if (depth == 2 && parsingAnswer)
+ ParseCorpParams(el, attr);
+
+return 0;
+}
+//-----------------------------------------------------------------------------
+void GET_CORP::PARSER::ParseEnd(const char * /*el*/)
+{
+depth--;
+if (depth == 0 && parsingAnswer)
+ {
+ if (callback)
+ callback(error.empty(), error, info, data);
+ error.clear();
+ parsingAnswer = false;
+ }
+}
+//-----------------------------------------------------------------------------
+void GET_CORP::PARSER::ParseCorp(const char * el, const char ** attr)
+{
+if (strcasecmp(el, "corp") == 0)
+ {
+ if (attr && attr[0] && attr[1])
+ {
+ if (strcasecmp(attr[1], "error") == 0)
+ {
+ if (attr[2] && attr[3])
+ error = attr[3];
+ else
+ error = "Corp not found.";
+ }
+ else
+ parsingAnswer = true;
+ }
+ else
+ parsingAnswer = true;
+ }
+}
+//-----------------------------------------------------------------------------
+void GET_CORP::PARSER::ParseCorpParams(const char * el, const char ** attr)
+{
+if (!TryParse(propertyParsers, ToLower(el), attr))
+ error = "Invalid parameter.";
+}
--- /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_STGLIBS_SRVCONF_PARSER_GET_CORP_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_GET_CORP_H__
+
+#include "base.h"
+#include "property.h"
+
+#include "stg/corp_conf.h"
+#include "stg/servconf_types.h"
+
+#include <string>
+
+namespace STG
+{
+namespace GET_CORP
+{
+
+class PARSER: public STG::PARSER
+{
+public:
+ PARSER(CALLBACK f, void * data);
+ virtual ~PARSER();
+ int ParseStart(const char * el, const char ** attr);
+ void ParseEnd(const char * el);
+
+private:
+ PROPERTY_PARSERS propertyParsers;
+ CALLBACK callback;
+ void * data;
+ INFO info;
+ int depth;
+ bool parsingAnswer;
+ std::string error;
+
+ void ParseCorp(const char * el, const char ** attr);
+ void ParseCorpParams(const char * el, const char ** attr);
+};
+
+} // namespace GET_CORP
+} // namespace STG
+
+#endif
--- /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>
+ */
+
+#include "get_corporations.h"
+
+#include "stg/corp_conf.h"
+
+#include <strings.h>
+
+using namespace STG;
+
+GET_CORPORATIONS::PARSER::PARSER(CALLBACK f, void * d)
+ : callback(f),
+ data(d),
+ corpParser(&GET_CORPORATIONS::PARSER::CorpCallback, this),
+ depth(0),
+ parsingAnswer(false)
+{
+}
+//-----------------------------------------------------------------------------
+int GET_CORPORATIONS::PARSER::ParseStart(const char * el, const char ** attr)
+{
+depth++;
+if (depth == 1 && strcasecmp(el, "corporations") == 0)
+ parsingAnswer = true;
+
+if (depth > 1 && parsingAnswer)
+ corpParser.ParseStart(el, attr);
+
+return 0;
+}
+//-----------------------------------------------------------------------------
+void GET_CORPORATIONS::PARSER::ParseEnd(const char * el)
+{
+depth--;
+if (depth > 0 && parsingAnswer)
+ corpParser.ParseEnd(el);
+
+if (depth == 0 && parsingAnswer)
+ {
+ if (callback)
+ callback(error.empty(), error, info, data);
+ error.clear();
+ info.clear();
+ parsingAnswer = false;
+ }
+}
+//-----------------------------------------------------------------------------
+void GET_CORPORATIONS::PARSER::AddCorp(const GET_CORP::INFO & corpInfo)
+{
+info.push_back(corpInfo);
+}
+//-----------------------------------------------------------------------------
+void GET_CORPORATIONS::PARSER::CorpCallback(bool result, const std::string & error, const GET_CORP::INFO & info, void * data)
+{
+ GET_CORPORATIONS::PARSER * parser = static_cast<GET_CORPORATIONS::PARSER *>(data);
+ if (!result)
+ parser->SetError(error);
+ else
+ parser->AddCorp(info);
+}
--- /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_STGLIBS_SRVCONF_PARSER_GET_CORPORATIONS_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_GET_CORPORATIONS_H__
+
+#include "base.h"
+#include "get_corp.h"
+
+#include "stg/corp_conf.h"
+#include "stg/servconf_types.h"
+
+#include <string>
+
+namespace STG
+{
+namespace GET_CORPORATIONS
+{
+
+class PARSER: public STG::PARSER
+{
+public:
+ PARSER(CALLBACK f, void * data);
+ int ParseStart(const char * el, const char ** attr);
+ void ParseEnd(const char * el);
+
+private:
+ CALLBACK callback;
+ void * data;
+ GET_CORP::PARSER corpParser;
+ INFO info;
+ int depth;
+ bool parsingAnswer;
+ std::string error;
+
+ void AddCorp(const GET_CORP::INFO & corpInfo);
+ void SetError(const std::string & e) { error = e; }
+
+ static void CorpCallback(bool result, const std::string& reason, const GET_CORP::INFO & info, void * data);
+};
+
+} // namespace GET_CORPORATIONS
+} // namespace STG
+
+#endif
/*
* Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
*/
#include "stg/servconf.h"
#include "parsers/get_service.h"
#include "parsers/chg_service.h"
+#include "parsers/get_corporations.h"
+#include "parsers/get_corp.h"
+#include "parsers/chg_corp.h"
+
#include "parsers/base.h"
#include "stg/common.h"
return pImpl->Exec<SIMPLE::PARSER>("DelService", "<DelService name=\"" + name + "\"/>", f, data);
}
+// -- Corporations --
+
+int SERVCONF::GetCorporations(GET_CORPORATIONS::CALLBACK f, void * data)
+{
+return pImpl->Exec<GET_CORPORATIONS::PARSER>("<GetCorporations/>", f, data);
+}
+
+int SERVCONF::GetCorp(const std::string & name, GET_CORP::CALLBACK f, void * data)
+{
+return pImpl->Exec<GET_CORP::PARSER>("<GetCorp name=\"" + name + "\"/>", f, data);
+}
+
+int SERVCONF::ChgCorp(const CORP_CONF_RES & conf, SIMPLE::CALLBACK f, void * data)
+{
+return pImpl->Exec<SIMPLE::PARSER>("SetCorp", "<SetCorp name=\"" + conf.name.data() + "\">" + CHG_CORP::Serialize(conf) + "</SetCorp>", f, data);
+}
+
+int SERVCONF::AddCorp(const std::string & name,
+ const CORP_CONF_RES & conf,
+ SIMPLE::CALLBACK f, void * data)
+{
+int res = pImpl->Exec<SIMPLE::PARSER>("AddCorp", "<AddCorp name=\"" + name + "\"/>", f, data);
+if (res != st_ok)
+ return res;
+return pImpl->Exec<SIMPLE::PARSER>("SetCorp", "<SetCorp name=\"" + name + "\">" + CHG_CORP::Serialize(conf) + "</SetCorp>", f, data);
+}
+
+int SERVCONF::DelCorp(const std::string & name, SIMPLE::CALLBACK f, void * data)
+{
+return pImpl->Exec<SIMPLE::PARSER>("DelCorp", "<DelCorp name=\"" + name + "\"/>", f, data);
+}
+
const std::string & SERVCONF::GetStrError() const
{
return pImpl->GetStrError();