./admins.cpp \
./tariffs.cpp \
./users.cpp \
+ ./services.cpp \
+ ./corps.cpp \
./xml.cpp
STGLIBS = srvconf \
$(CXX) $^ $(LDFLAGS) $(LIBS) -o $(PROG)
clean:
- rm -f deps $(PROG) *.o tags *.*~ .OS
- rm -f .OS
- rm -f .store
- rm -f .db.sql
- rm -f core*
+ rm -f deps $(PROG) *.o
$(MAKE) -C $(DIR_LIBSRC) clean
distclean: clean
--- /dev/null
+#include "corps.h"
+
+#include "config.h"
+
+#include "stg/servconf.h"
+#include "stg/servconf_types.h"
+#include "stg/corp_conf.h"
+#include "stg/common.h"
+
+#include <iostream>
+
+namespace
+{
+
+std::string Indent(size_t level, bool dash = false)
+{
+if (level == 0)
+ return "";
+return dash ? std::string(level * 4 - 2, ' ') + "- " : std::string(level * 4, ' ');
+}
+
+void PrintCorp(const STG::GET_CORP::INFO & info, size_t level = 0)
+{
+std::cout << Indent(level, true) << "name: " << info.name << "\n"
+ << Indent(level) << "cash: " << info.cash << "\n";
+}
+
+void SimpleCallback(bool result,
+ const std::string & reason,
+ void * /*data*/)
+{
+if (!result)
+ {
+ std::cerr << "Operation failed. Reason: '" << reason << "'." << std::endl;
+ return;
+ }
+std::cout << "Success.\n";
+}
+
+void GetCorpsCallback(bool result,
+ const std::string & reason,
+ const std::vector<STG::GET_CORP::INFO> & info,
+ void * /*data*/)
+{
+if (!result)
+ {
+ std::cerr << "Failed to get corp list. Reason: '" << reason << "'." << std::endl;
+ return;
+ }
+std::cout << "Corps:\n";
+for (size_t i = 0; i < info.size(); ++i)
+ PrintCorp(info[i], 1);
+}
+
+void GetCorpCallback(bool result,
+ const std::string & reason,
+ const STG::GET_CORP::INFO & info,
+ void * /*data*/)
+{
+if (!result)
+ {
+ std::cerr << "Failed to get corp. Reason: '" << reason << "'." << std::endl;
+ return;
+ }
+PrintCorp(info);
+}
+
+} // namespace anonymous
+
+bool SGCONF::GetCorpsFunction(const SGCONF::CONFIG & config,
+ const std::string & /*arg*/,
+ const std::map<std::string, std::string> & /*options*/)
+{
+STG::SERVCONF proto(config.server.data(),
+ config.port.data(),
+ config.userName.data(),
+ config.userPass.data());
+return proto.GetCorporations(GetCorpsCallback, NULL) == STG::st_ok;
+}
+
+bool SGCONF::GetCorpFunction(const SGCONF::CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & /*options*/)
+{
+STG::SERVCONF proto(config.server.data(),
+ config.port.data(),
+ config.userName.data(),
+ config.userPass.data());
+return proto.GetCorp(arg, GetCorpCallback, NULL) == STG::st_ok;
+}
+
+bool SGCONF::DelCorpFunction(const SGCONF::CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & /*options*/)
+{
+STG::SERVCONF proto(config.server.data(),
+ config.port.data(),
+ config.userName.data(),
+ config.userPass.data());
+return proto.DelCorp(arg, SimpleCallback, NULL) == STG::st_ok;
+}
+
+bool SGCONF::AddCorpFunction(const SGCONF::CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & /*options*/)
+{
+// TODO
+std::cerr << "Unimplemented.\n";
+return false;
+}
+
+bool SGCONF::ChgCorpFunction(const SGCONF::CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options)
+{
+// TODO
+std::cerr << "Unimplemented.\n";
+return false;
+}
--- /dev/null
+#ifndef __STG_SGCONF_CORPS_H__
+#define __STG_SGCONF_CORPS_H__
+
+#include <string>
+#include <map>
+
+namespace SGCONF
+{
+
+struct CONFIG;
+
+bool GetCorpsFunction(const CONFIG & config,
+ const std::string & /*arg*/,
+ const std::map<std::string, std::string> & /*options*/);
+
+bool GetCorpFunction(const CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & /*options*/);
+
+bool DelCorpFunction(const CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & /*options*/);
+
+bool AddCorpFunction(const CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options);
+
+bool ChgCorpFunction(const CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options);
+
+} // namespace SGCONF
+
+#endif
#include "admins.h"
#include "tariffs.h"
#include "users.h"
+#include "services.h"
+#include "corps.h"
+
#include "options.h"
#include "actions.h"
#include "config.h"
.Add("chg-tariff", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::ChgTariffFunction), "\tchange tariff");
blocks.Add("User management options")
.Add("get-users", SGCONF::MakeAPIAction(commands, SGCONF::GetUsersFunction), "\tget user list")
- .Add("get-user", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::GetUserFunction), "\tget user")
- .Add("add-user", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::AddUserFunction), "\tadd user")
- .Add("del-user", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::DelUserFunction), "\tdel user")
- .Add("chg-user", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::ChgUserFunction), "\tchange user");
+ .Add("get-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::GetUserFunction), "\tget user")
+ .Add("add-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::AddUserFunction), "\tadd user")
+ .Add("del-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::DelUserFunction), "\tdel user")
+ .Add("chg-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::ChgUserFunction), "\tchange user")
+ .Add("check-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::CheckUserFunction), "\tcheck user existance and credentials")
+ .Add("send-message", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::SendMessageFunction), "\tsend message");
+blocks.Add("Service management options")
+ .Add("get-services", SGCONF::MakeAPIAction(commands, SGCONF::GetServicesFunction), "\tget service list")
+ .Add("get-service", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::GetServiceFunction), "\tget service")
+ .Add("add-service", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::AddServiceFunction), "\tadd service")
+ .Add("del-service", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::DelServiceFunction), "\tdel service")
+ .Add("chg-service", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::ChgServiceFunction), "\tchange service");
+blocks.Add("Corporation management options")
+ .Add("get-corps", SGCONF::MakeAPIAction(commands, SGCONF::GetCorpsFunction), "\tget corporation list")
+ .Add("get-corp", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::GetCorpFunction), "\tget corporation")
+ .Add("add-corp", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::AddCorpFunction), "\tadd corporation")
+ .Add("del-corp", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::DelCorpFunction), "\tdel corporation")
+ .Add("chg-corp", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::ChgCorpFunction), "\tchange corporation");
SGCONF::PARSER_STATE state(false, argc, argv);
--- /dev/null
+#include "services.h"
+
+#include "config.h"
+
+#include "stg/servconf.h"
+#include "stg/servconf_types.h"
+#include "stg/service_conf.h"
+#include "stg/common.h"
+
+#include <iostream>
+
+namespace
+{
+
+std::string Indent(size_t level, bool dash = false)
+{
+if (level == 0)
+ return "";
+return dash ? std::string(level * 4 - 2, ' ') + "- " : std::string(level * 4, ' ');
+}
+
+void PrintService(const STG::GET_SERVICE::INFO & info, size_t level = 0)
+{
+std::cout << Indent(level, true) << "name: " << info.name << "\n"
+ << Indent(level) << "cost: " << info.cost << "\n"
+ << Indent(level) << "payment day: " << info.payDay << "\n"
+ << Indent(level) << "comment: " << info.comment << "\n";
+}
+
+void SimpleCallback(bool result,
+ const std::string & reason,
+ void * /*data*/)
+{
+if (!result)
+ {
+ std::cerr << "Operation failed. Reason: '" << reason << "'." << std::endl;
+ return;
+ }
+std::cout << "Success.\n";
+}
+
+void GetServicesCallback(bool result,
+ const std::string & reason,
+ const std::vector<STG::GET_SERVICE::INFO> & info,
+ void * /*data*/)
+{
+if (!result)
+ {
+ std::cerr << "Failed to get service list. Reason: '" << reason << "'." << std::endl;
+ return;
+ }
+std::cout << "Services:\n";
+for (size_t i = 0; i < info.size(); ++i)
+ PrintService(info[i], 1);
+}
+
+void GetServiceCallback(bool result,
+ const std::string & reason,
+ const STG::GET_SERVICE::INFO & info,
+ void * /*data*/)
+{
+if (!result)
+ {
+ std::cerr << "Failed to get service. Reason: '" << reason << "'." << std::endl;
+ return;
+ }
+PrintService(info);
+}
+
+} // namespace anonymous
+
+bool SGCONF::GetServicesFunction(const SGCONF::CONFIG & config,
+ const std::string & /*arg*/,
+ const std::map<std::string, std::string> & /*options*/)
+{
+STG::SERVCONF proto(config.server.data(),
+ config.port.data(),
+ config.userName.data(),
+ config.userPass.data());
+return proto.GetServices(GetServicesCallback, NULL) == STG::st_ok;
+}
+
+bool SGCONF::GetServiceFunction(const SGCONF::CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & /*options*/)
+{
+STG::SERVCONF proto(config.server.data(),
+ config.port.data(),
+ config.userName.data(),
+ config.userPass.data());
+return proto.GetService(arg, GetServiceCallback, NULL) == STG::st_ok;
+}
+
+bool SGCONF::DelServiceFunction(const SGCONF::CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & /*options*/)
+{
+STG::SERVCONF proto(config.server.data(),
+ config.port.data(),
+ config.userName.data(),
+ config.userPass.data());
+return proto.DelService(arg, SimpleCallback, NULL) == STG::st_ok;
+}
+
+bool SGCONF::AddServiceFunction(const SGCONF::CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & /*options*/)
+{
+// TODO
+std::cerr << "Unimplemented.\n";
+return false;
+}
+
+bool SGCONF::ChgServiceFunction(const SGCONF::CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options)
+{
+// TODO
+std::cerr << "Unimplemented.\n";
+return false;
+}
--- /dev/null
+#ifndef __STG_SGCONF_SERVICES_H__
+#define __STG_SGCONF_SERVICES_H__
+
+#include <string>
+#include <map>
+
+namespace SGCONF
+{
+
+struct CONFIG;
+
+bool GetServicesFunction(const CONFIG & config,
+ const std::string & /*arg*/,
+ const std::map<std::string, std::string> & /*options*/);
+
+bool GetServiceFunction(const CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & /*options*/);
+
+bool DelServiceFunction(const CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & /*options*/);
+
+bool AddServiceFunction(const CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options);
+
+bool ChgServiceFunction(const CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options);
+
+} // namespace SGCONF
+
+#endif
}
bool SGCONF::AddUserFunction(const SGCONF::CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & /*options*/)
+ const std::string & arg,
+ const std::map<std::string, std::string> & /*options*/)
{
// TODO
std::cerr << "Unimplemented.\n";
}
bool SGCONF::ChgUserFunction(const SGCONF::CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options)
+{
+// TODO
+std::cerr << "Unimplemented.\n";
+return false;
+}
+
+bool SGCONF::CheckUserFunction(const SGCONF::CONFIG & config,
const std::string & arg,
const std::map<std::string, std::string> & options)
{
std::cerr << "Unimplemented.\n";
return false;
}
+
+bool SGCONF::SendMessageFunction(const SGCONF::CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options)
+{
+// TODO
+std::cerr << "Unimplemented.\n";
+return false;
+}
const std::string & arg,
const std::map<std::string, std::string> & options);
+bool CheckUserFunction(const CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options);
+
+bool SendMessageFunction(const CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options);
+
}
#endif