]> git.stg.codes - stg.git/blobdiff - stglibs/srvconf.lib/servconf.cpp
Added corporations management.
[stg.git] / stglibs / srvconf.lib / servconf.cpp
index 01f2179020a09ececae16fb6cff3d6839fd54bfa..e80c3ffa7f889e8371ba1417a5ccde65197c8305 100644 (file)
@@ -16,6 +16,7 @@
 
 /*
  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
  */
 
 #include "stg/servconf.h"
 #include "parsers/get_admin.h"
 #include "parsers/chg_admin.h"
 
+#include "parsers/get_tariffs.h"
+#include "parsers/get_tariff.h"
+#include "parsers/chg_tariff.h"
+
 #include "parsers/auth_by.h"
 #include "parsers/get_users.h"
 #include "parsers/get_user.h"
 #include "parsers/chg_user.h"
 
+#include "parsers/get_services.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"
@@ -99,7 +112,7 @@ if (XML_Parse(sc->parser, chunk.c_str(), chunk.length(), final) == XML_STATUS_ER
 return true;
 }
 
-bool SERVCONF::IMPL::SimpleRecv(void * data, const std::string & chunk, bool final)
+bool SERVCONF::IMPL::SimpleRecv(void * data, const std::string & chunk, bool /*final*/)
 {
 *static_cast<std::string *>(data) += chunk;
 return true;
@@ -123,6 +136,7 @@ return pImpl->Exec<SERVER_INFO::PARSER>("<GetServerInfo/>", f, data);
 
 int SERVCONF::RawXML(const std::string & request, RAW_XML::CALLBACK f, void * data)
 {
+return pImpl->RawXML(request, f, data);
 }
 
 // -- Admins --
@@ -157,6 +171,38 @@ int SERVCONF::DelAdmin(const std::string & login, SIMPLE::CALLBACK f, void * dat
 return pImpl->Exec<SIMPLE::PARSER>("DelAdmin", "<DelAdmin login=\"" + login + "\"/>", f, data);
 }
 
+// -- Tariffs --
+
+int SERVCONF::GetTariffs(GET_TARIFFS::CALLBACK f, void * data)
+{
+return pImpl->Exec<GET_TARIFFS::PARSER>("<GetTariffs/>", f, data);
+}
+
+int SERVCONF::GetTariff(const std::string & name, GET_TARIFF::CALLBACK f, void * data)
+{
+return pImpl->Exec<GET_TARIFF::PARSER>("<GetTariff name=\"" + name + "\"/>", f, data);
+}
+
+int SERVCONF::ChgTariff(const TARIFF_DATA_RES & tariffData, SIMPLE::CALLBACK f, void * data)
+{
+return pImpl->Exec<SIMPLE::PARSER>("SetTariff", "<SetTariff name=\"" + tariffData.tariffConf.name.data() + "\">" + CHG_TARIFF::Serialize(tariffData) + "</SetTariff>", f, data);
+}
+
+int SERVCONF::AddTariff(const std::string & name,
+                       const TARIFF_DATA_RES & tariffData,
+                       SIMPLE::CALLBACK f, void * data)
+{
+int res = pImpl->Exec<SIMPLE::PARSER>("AddTariff", "<AddTariff name=\"" + name + "\"/>", f, data);
+if (res != st_ok)
+    return res;
+return pImpl->Exec<SIMPLE::PARSER>("SetTariff", "<SetTariff name=\"" + name + "\">" + CHG_TARIFF::Serialize(tariffData) + "</SetTariff>", f, data);
+}
+
+int SERVCONF::DelTariff(const std::string & name, SIMPLE::CALLBACK f, void * data)
+{
+return pImpl->Exec<SIMPLE::PARSER>("DelTariff", "<DelTariff name=\"" + name + "\"/>", f, data);
+}
+
 // -- Users --
 
 int SERVCONF::GetUsers(GET_USERS::CALLBACK f, void * data)
@@ -202,6 +248,70 @@ int SERVCONF::CheckUser(const std::string & login, const std::string & password,
 return pImpl->Exec<SIMPLE::PARSER>("CheckUser", "<CheckUser login=\"" + login + "\" password=\"" + password + "\"/>", f, data);
 }
 
+// -- Services --
+
+int SERVCONF::GetServices(GET_SERVICES::CALLBACK f, void * data)
+{
+return pImpl->Exec<GET_SERVICES::PARSER>("<GetServices/>", f, data);
+}
+
+int SERVCONF::GetService(const std::string & name, GET_SERVICE::CALLBACK f, void * data)
+{
+return pImpl->Exec<GET_SERVICE::PARSER>("<GetService name=\"" + name + "\"/>", f, data);
+}
+
+int SERVCONF::ChgService(const SERVICE_CONF_RES & conf, SIMPLE::CALLBACK f, void * data)
+{
+return pImpl->Exec<SIMPLE::PARSER>("SetService", "<SetService name=\"" + conf.name.data() + "\">" + CHG_SERVICE::Serialize(conf) + "</SetService>", f, data);
+}
+
+int SERVCONF::AddService(const std::string & name,
+                         const SERVICE_CONF_RES & conf,
+                         SIMPLE::CALLBACK f, void * data)
+{
+int res = pImpl->Exec<SIMPLE::PARSER>("AddService", "<AddService name=\"" + name + "\"/>", f, data);
+if (res != st_ok)
+    return res;
+return pImpl->Exec<SIMPLE::PARSER>("SetService", "<SetService name=\"" + name + "\">" + CHG_SERVICE::Serialize(conf) + "</SetService>", f, data);
+}
+
+int SERVCONF::DelService(const std::string & name, SIMPLE::CALLBACK f, void * data)
+{
+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();
@@ -259,7 +369,7 @@ if ((ret = nt.Disconnect()) != st_ok)
 return st_ok;
 }
 
-int SERVCONF::RawXML(const std::string & request, RAW_XML::CALLBACK f, void * data)
+int SERVCONF::IMPL::RawXML(const std::string & request, RAW_XML::CALLBACK f, void * data)
 {
 std::string response;
 nt.SetRxCallback(&response, SimpleRecv);