SRCS = ./main.cpp \
./options.cpp \
+ ./api_action.cpp \
./actions.cpp \
./admins.cpp \
./tariffs.cpp \
#define __STG_SGCONF_ACTION_H__
#include <string>
+#include <map>
#include <stdexcept>
namespace SGCONF
class OPTION_BLOCK;
struct PARSER_STATE;
+struct CONFIG;
class ACTION
{
#include "admins.h"
+#include "api_action.h"
+#include "options.h"
#include "config.h"
#include "stg/servconf.h"
#include "stg/os_int.h"
#include <iostream>
+#include <string>
+#include <map>
#include <cassert>
namespace
PrintAdmin(info[i]);
}
-} // namespace anonymous
-
-bool SGCONF::GetAdminsFunction(const SGCONF::CONFIG & config,
- const std::string & /*arg*/,
- const std::map<std::string, std::string> & /*options*/)
+bool GetAdminsFunction(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(),
return proto.GetAdmins(GetAdminsCallback, NULL) == STG::st_ok;
}
-bool SGCONF::GetAdminFunction(const SGCONF::CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & /*options*/)
+bool GetAdminFunction(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(),
return proto.GetAdmins(GetAdminCallback, &login) == STG::st_ok;
}
-bool SGCONF::DelAdminFunction(const SGCONF::CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & /*options*/)
+bool DelAdminFunction(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(),
return proto.DelAdmin(arg, SimpleCallback, NULL) == STG::st_ok;
}
-bool SGCONF::AddAdminFunction(const SGCONF::CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & /*options*/)
+bool AddAdminFunction(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::ChgAdminFunction(const SGCONF::CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & options)
+bool ChgAdminFunction(const SGCONF::CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options)
{
// TODO
std::cerr << "Unimplemented.\n";
return false;
}
+
+} // namespace anonymous
+
+void SGCONF::AppendAdminsOptionBlock(COMMANDS & commands, OPTION_BLOCKS & blocks)
+{
+blocks.Add("Admin management options")
+ .Add("get-admins", SGCONF::MakeAPIAction(commands, GetAdminsFunction), "\tget admin list")
+ .Add("get-admin", SGCONF::MakeAPIAction(commands, "<login>", true, GetAdminFunction), "get admin")
+ .Add("add-admin", SGCONF::MakeAPIAction(commands, "<login>", true, AddAdminFunction), "add admin")
+ .Add("del-admin", SGCONF::MakeAPIAction(commands, "<login>", true, DelAdminFunction), "del admin")
+ .Add("chg-admin", SGCONF::MakeAPIAction(commands, "<login>", true, ChgAdminFunction), "change admin");
+}
#ifndef __STG_SGCONF_ADMINS_H__
#define __STG_SGCONF_ADMINS_H__
-#include <string>
-#include <map>
-
namespace SGCONF
{
-struct CONFIG;
-
-bool GetAdminsFunction(const CONFIG & config,
- const std::string & /*arg*/,
- const std::map<std::string, std::string> & /*options*/);
-
-bool GetAdminFunction(const CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & /*options*/);
-
-bool DelAdminFunction(const CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & /*options*/);
-
-bool AddAdminFunction(const CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & options);
+class OPTION_BLOCKS;
+class COMMANDS;
-bool ChgAdminFunction(const CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & options);
+void AppendAdminsOptionBlock(COMMANDS & commands, OPTION_BLOCKS & blocks);
} // namespace SGCONF
--- /dev/null
+#include "api_action.h"
+
+#include "parser_state.h"
+
+SGCONF::PARSER_STATE SGCONF::API_ACTION::Parse(int argc, char ** argv)
+{
+PARSER_STATE state(false, argc, argv);
+if (!m_argument.empty())
+ {
+ if (argc == 0 ||
+ argv == NULL ||
+ *argv == NULL)
+ throw ERROR("Missing argument.");
+ m_argument = *argv;
+ --state.argc;
+ ++state.argv;
+ }
+m_suboptions.Parse(state.argc, state.argv);
+m_commands.Add(m_funPtr, m_argument, m_params);
+return state;
+}
--- /dev/null
+#ifndef __STG_SGCONF_API_ACTION_H__
+#define __STG_SGCONF_API_ACTION_H__
+
+#include "action.h"
+
+#include "options.h"
+
+#include <string>
+#include <map>
+#include <vector>
+
+namespace SGCONF
+{
+
+typedef bool (* API_FUNCTION) (const CONFIG &,
+ const std::string &,
+ const std::map<std::string, std::string> &);
+
+class COMMAND
+{
+ public:
+ COMMAND(API_FUNCTION funPtr,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options)
+ : m_funPtr(funPtr),
+ m_arg(arg),
+ m_options(options)
+ {}
+ bool Execute(const SGCONF::CONFIG & config) const
+ {
+ return m_funPtr(config, m_arg, m_options);
+ }
+
+ private:
+ API_FUNCTION m_funPtr;
+ std::string m_arg;
+ std::map<std::string, std::string> m_options;
+};
+
+class COMMANDS
+{
+ public:
+ void Add(API_FUNCTION funPtr,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options) { m_commands.push_back(COMMAND(funPtr, arg, options)); }
+ bool Execute(const SGCONF::CONFIG & config) const
+ {
+ std::vector<COMMAND>::const_iterator it(m_commands.begin());
+ bool res = true;
+ while (it != m_commands.end() && res)
+ {
+ res = res && it->Execute(config);
+ ++it;
+ }
+ return res;
+ }
+ private:
+ std::vector<COMMAND> m_commands;
+};
+
+class API_ACTION : public ACTION
+{
+ public:
+ API_ACTION(COMMANDS & commands,
+ const std::string & paramDescription,
+ bool needArgument,
+ const OPTION_BLOCK& suboptions,
+ API_FUNCTION funPtr)
+ : m_commands(commands),
+ m_description(paramDescription),
+ m_argument(needArgument ? "1" : ""), // Hack
+ m_suboptions(suboptions),
+ m_funPtr(funPtr)
+ {}
+ API_ACTION(COMMANDS & commands,
+ const std::string & paramDescription,
+ bool needArgument,
+ API_FUNCTION funPtr)
+ : m_commands(commands),
+ m_description(paramDescription),
+ m_argument(needArgument ? "1" : ""), // Hack
+ m_funPtr(funPtr)
+ {}
+
+ virtual ACTION * Clone() const { return new API_ACTION(*this); }
+
+ virtual std::string ParamDescription() const { return m_description; }
+ virtual std::string DefaultDescription() const { return ""; }
+ virtual OPTION_BLOCK & Suboptions() { return m_suboptions; }
+ virtual PARSER_STATE Parse(int argc, char ** argv);
+
+ private:
+ COMMANDS & m_commands;
+ std::string m_description;
+ std::string m_argument;
+ OPTION_BLOCK m_suboptions;
+ std::map<std::string, std::string> m_params;
+ API_FUNCTION m_funPtr;
+};
+
+inline
+ACTION * MakeAPIAction(COMMANDS & commands,
+ const std::string & paramDescription,
+ bool needArgument,
+ API_FUNCTION funPtr)
+{
+return new API_ACTION(commands, paramDescription, needArgument, funPtr);
+}
+
+inline
+ACTION * MakeAPIAction(COMMANDS & commands,
+ API_FUNCTION funPtr)
+{
+return new API_ACTION(commands, "", false, funPtr);
+}
+
+}
+
+#endif
#include "corps.h"
+#include "api_action.h"
+#include "options.h"
#include "config.h"
#include "stg/servconf.h"
#include "stg/common.h"
#include <iostream>
+#include <string>
+#include <map>
namespace
{
PrintCorp(info);
}
-} // namespace anonymous
-
-bool SGCONF::GetCorpsFunction(const SGCONF::CONFIG & config,
- const std::string & /*arg*/,
- const std::map<std::string, std::string> & /*options*/)
+bool 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(),
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*/)
+bool 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(),
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*/)
+bool 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(),
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*/)
+bool 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)
+bool ChgCorpFunction(const SGCONF::CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options)
{
// TODO
std::cerr << "Unimplemented.\n";
return false;
}
+
+} // namespace anonymous
+
+void SGCONF::AppendCorpsOptionBlock(COMMANDS & commands, OPTION_BLOCKS & blocks)
+{
+blocks.Add("Corporation management options")
+ .Add("get-corps", SGCONF::MakeAPIAction(commands, GetCorpsFunction), "\tget corporation list")
+ .Add("get-corp", SGCONF::MakeAPIAction(commands, "<name>", true, GetCorpFunction), "get corporation")
+ .Add("add-corp", SGCONF::MakeAPIAction(commands, "<name>", true, AddCorpFunction), "add corporation")
+ .Add("del-corp", SGCONF::MakeAPIAction(commands, "<name>", true, DelCorpFunction), "del corporation")
+ .Add("chg-corp", SGCONF::MakeAPIAction(commands, "<name>", true, ChgCorpFunction), "change corporation");
+}
#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);
+class OPTION_BLOCKS;
+class COMMANDS;
-bool ChgCorpFunction(const CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & options);
+void AppendCorpsOptionBlock(COMMANDS & commands, OPTION_BLOCKS & blocks);
} // namespace SGCONF
#include "services.h"
#include "corps.h"
+#include "api_action.h"
#include "options.h"
#include "actions.h"
#include "config.h"
void ParseHostAndPort(const std::string & hostAndPort);
};
-typedef bool (* API_FUNCTION) (const SGCONF::CONFIG &,
- const std::string &,
- const std::map<std::string, std::string> &);
-
-class COMMAND
-{
- public:
- COMMAND(API_FUNCTION funPtr,
- const std::string & arg,
- const std::map<std::string, std::string> & options)
- : m_funPtr(funPtr),
- m_arg(arg),
- m_options(options)
- {}
- bool Execute(const SGCONF::CONFIG & config) const
- {
- return m_funPtr(config, m_arg, m_options);
- }
-
- private:
- API_FUNCTION m_funPtr;
- std::string m_arg;
- std::map<std::string, std::string> m_options;
-};
-
-class COMMANDS
-{
- public:
- void Add(API_FUNCTION funPtr,
- const std::string & arg,
- const std::map<std::string, std::string> & options) { m_commands.push_back(COMMAND(funPtr, arg, options)); }
- bool Execute(const SGCONF::CONFIG & config) const
- {
- std::list<COMMAND>::const_iterator it(m_commands.begin());
- bool res = true;
- while (it != m_commands.end() && res)
- {
- res = res && it->Execute(config);
- ++it;
- }
- return res;
- }
- private:
- std::list<COMMAND> m_commands;
-};
-
-class API_ACTION : public ACTION
-{
- public:
- API_ACTION(COMMANDS & commands,
- const std::string & paramDescription,
- bool needArgument,
- const OPTION_BLOCK& suboptions,
- API_FUNCTION funPtr)
- : m_commands(commands),
- m_description(paramDescription),
- m_argument(needArgument ? "1" : ""), // Hack
- m_suboptions(suboptions),
- m_funPtr(funPtr)
- {}
- API_ACTION(COMMANDS & commands,
- const std::string & paramDescription,
- bool needArgument,
- API_FUNCTION funPtr)
- : m_commands(commands),
- m_description(paramDescription),
- m_argument(needArgument ? "1" : ""), // Hack
- m_funPtr(funPtr)
- {}
-
- virtual ACTION * Clone() const { return new API_ACTION(*this); }
-
- virtual std::string ParamDescription() const { return m_description; }
- virtual std::string DefaultDescription() const { return ""; }
- virtual OPTION_BLOCK & Suboptions() { return m_suboptions; }
- virtual PARSER_STATE Parse(int argc, char ** argv)
- {
- PARSER_STATE state(false, argc, argv);
- if (!m_argument.empty())
- {
- if (argc == 0 ||
- argv == NULL ||
- *argv == NULL)
- throw ERROR("Missing argument.");
- m_argument = *argv;
- --state.argc;
- ++state.argv;
- }
- m_suboptions.Parse(state.argc, state.argv);
- m_commands.Add(m_funPtr, m_argument, m_params);
- return state;
- }
-
- private:
- COMMANDS & m_commands;
- std::string m_description;
- std::string m_argument;
- OPTION_BLOCK m_suboptions;
- std::map<std::string, std::string> m_params;
- API_FUNCTION m_funPtr;
-};
PARSER_STATE CONFIG_ACTION::Parse(int argc, char ** argv)
{
return new CONFIG_ACTION(config, paramDescription);
}
-inline
-ACTION * MakeAPIAction(COMMANDS & commands,
- const std::string & paramDescription,
- bool needArgument,
- API_FUNCTION funPtr)
-{
-return new API_ACTION(commands, paramDescription, needArgument, funPtr);
-}
-
-inline
-ACTION * MakeAPIAction(COMMANDS & commands,
- API_FUNCTION funPtr)
-{
-return new API_ACTION(commands, "", false, funPtr);
-}
-
} // namespace SGCONF
-time_t stgTime;
-
//-----------------------------------------------------------------------------
int main(int argc, char **argv)
{
.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::MakeAPIAction(commands, "<xml>", true, SGCONF::RawXMLFunction), "\tmake raw XML request");
-blocks.Add("Admin management options")
- .Add("get-admins", SGCONF::MakeAPIAction(commands, SGCONF::GetAdminsFunction), "\tget admin list")
- .Add("get-admin", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::GetAdminFunction), "get admin")
- .Add("add-admin", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::AddAdminFunction), "add admin")
- .Add("del-admin", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::DelAdminFunction), "del admin")
- .Add("chg-admin", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::ChgAdminFunction), "change admin");
-blocks.Add("Tariff management options")
- .Add("get-tariffs", SGCONF::MakeAPIAction(commands, SGCONF::GetTariffsFunction), "\tget tariff list")
- .Add("get-tariff", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::GetTariffFunction), "get tariff")
- .Add("add-tariff", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::AddTariffFunction), "add tariff")
- .Add("del-tariff", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::DelTariffFunction), "del tariff")
- .Add("chg-tariff", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::ChgTariffFunction), "change tariff");
-blocks.Add("User management options")
- .Add("get-users", SGCONF::MakeAPIAction(commands, SGCONF::GetUsersFunction), "\tget user list")
- .Add("get-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::GetUserFunction), "get user")
- .Add("add-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::AddUserFunction), "add user")
- .Add("del-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::DelUserFunction), "del user")
- .Add("chg-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::ChgUserFunction), "change user")
- .Add("check-user", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::CheckUserFunction), "check user existance and credentials")
- .Add("send-message", SGCONF::MakeAPIAction(commands, "<login>", true, SGCONF::SendMessageFunction), "send 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), "get service")
- .Add("add-service", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::AddServiceFunction), "add service")
- .Add("del-service", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::DelServiceFunction), "del service")
- .Add("chg-service", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::ChgServiceFunction), "change 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), "get corporation")
- .Add("add-corp", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::AddCorpFunction), "add corporation")
- .Add("del-corp", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::DelCorpFunction), "del corporation")
- .Add("chg-corp", SGCONF::MakeAPIAction(commands, "<name>", true, SGCONF::ChgCorpFunction), "change corporation");
+SGCONF::AppendXMLOptionBlock(commands, blocks);
+SGCONF::AppendAdminsOptionBlock(commands, blocks);
+SGCONF::AppendTariffsOptionBlock(commands, blocks);
+SGCONF::AppendUsersOptionBlock(commands, blocks);
+SGCONF::AppendServicesOptionBlock(commands, blocks);
+SGCONF::AppendCorpsOptionBlock(commands, blocks);
SGCONF::PARSER_STATE state(false, argc, argv);
public:
OPTION_BLOCK & Add(const std::string & description)
{ m_blocks.push_back(OPTION_BLOCK(description)); return m_blocks.back(); }
+ void Add(const OPTION_BLOCK & block) { m_blocks.push_back(block); }
void Help(size_t level) const;
PARSER_STATE Parse(int argc, char ** argv);
#include "services.h"
+#include "api_action.h"
+#include "options.h"
#include "config.h"
#include "stg/servconf.h"
#include "stg/common.h"
#include <iostream>
+#include <string>
+#include <map>
namespace
{
PrintService(info);
}
-} // namespace anonymous
-
-bool SGCONF::GetServicesFunction(const SGCONF::CONFIG & config,
- const std::string & /*arg*/,
- const std::map<std::string, std::string> & /*options*/)
+bool 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(),
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*/)
+bool 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(),
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*/)
+bool 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(),
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*/)
+bool 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)
+bool ChgServiceFunction(const SGCONF::CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options)
{
// TODO
std::cerr << "Unimplemented.\n";
return false;
}
+
+} // namespace anonymous
+
+void SGCONF::AppendServicesOptionBlock(COMMANDS & commands, OPTION_BLOCKS & blocks)
+{
+blocks.Add("Service management options")
+ .Add("get-services", SGCONF::MakeAPIAction(commands, GetServicesFunction), "\tget service list")
+ .Add("get-service", SGCONF::MakeAPIAction(commands, "<name>", true, GetServiceFunction), "get service")
+ .Add("add-service", SGCONF::MakeAPIAction(commands, "<name>", true, AddServiceFunction), "add service")
+ .Add("del-service", SGCONF::MakeAPIAction(commands, "<name>", true, DelServiceFunction), "del service")
+ .Add("chg-service", SGCONF::MakeAPIAction(commands, "<name>", true, ChgServiceFunction), "change service");
+}
#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);
+class OPTION_BLOCKS;
+class COMMANDS;
-bool ChgServiceFunction(const CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & options);
+void AppendServicesOptionBlock(COMMANDS & commands, OPTION_BLOCKS & blocks);
} // namespace SGCONF
#include "tariffs.h"
+#include "api_action.h"
+#include "options.h"
#include "config.h"
#include "stg/servconf.h"
#include <iostream>
#include <sstream>
+#include <string>
+#include <map>
#include <cassert>
namespace
PrintTariff(info[i]);
}
-} // namespace anonymous
-
-bool SGCONF::GetTariffsFunction(const SGCONF::CONFIG & config,
- const std::string & /*arg*/,
- const std::map<std::string, std::string> & /*options*/)
+bool GetTariffsFunction(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(),
return proto.GetTariffs(GetTariffsCallback, NULL) == STG::st_ok;
}
-bool SGCONF::GetTariffFunction(const SGCONF::CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & /*options*/)
+bool GetTariffFunction(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(),
return proto.GetTariffs(GetTariffCallback, &name) == STG::st_ok;
}
-bool SGCONF::DelTariffFunction(const SGCONF::CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & /*options*/)
+bool DelTariffFunction(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(),
return proto.DelTariff(arg, SimpleCallback, NULL) == STG::st_ok;
}
-bool SGCONF::AddTariffFunction(const SGCONF::CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & /*options*/)
+bool AddTariffFunction(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::ChgTariffFunction(const SGCONF::CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & options)
+bool ChgTariffFunction(const SGCONF::CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options)
{
// TODO
std::cerr << "Unimplemented.\n";
return false;
}
+
+} // namespace anonymous
+
+void SGCONF::AppendTariffsOptionBlock(COMMANDS & commands, OPTION_BLOCKS & blocks)
+{
+blocks.Add("Tariff management options")
+ .Add("get-tariffs", SGCONF::MakeAPIAction(commands, GetTariffsFunction), "\tget tariff list")
+ .Add("get-tariff", SGCONF::MakeAPIAction(commands, "<name>", true, GetTariffFunction), "get tariff")
+ .Add("add-tariff", SGCONF::MakeAPIAction(commands, "<name>", true, AddTariffFunction), "add tariff")
+ .Add("del-tariff", SGCONF::MakeAPIAction(commands, "<name>", true, DelTariffFunction), "del tariff")
+ .Add("chg-tariff", SGCONF::MakeAPIAction(commands, "<name>", true, ChgTariffFunction), "change tariff");
+}
#ifndef __STG_SGCONF_TARIFFS_H__
#define __STG_SGCONF_TARIFFS_H__
-#include <string>
-#include <map>
-
namespace SGCONF
{
-struct CONFIG;
-
-bool GetTariffsFunction(const CONFIG & config,
- const std::string & /*arg*/,
- const std::map<std::string, std::string> & /*options*/);
-
-bool GetTariffFunction(const CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & /*options*/);
-
-bool DelTariffFunction(const CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & /*options*/);
-
-bool AddTariffFunction(const CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & options);
+class OPTION_BLOCKS;
+class COMMANDS;
-bool ChgTariffFunction(const CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & options);
+void AppendTariffsOptionBlock(COMMANDS & commands, OPTION_BLOCKS & blocks);
} // namespace SGCONF
#include "users.h"
+#include "api_action.h"
+#include "options.h"
#include "config.h"
#include "stg/servconf.h"
#include "stg/common.h"
#include <iostream>
+#include <string>
+#include <map>
namespace
{
PrintUser(info);
}
-} // namespace anonymous
-
-bool SGCONF::GetUsersFunction(const SGCONF::CONFIG & config,
- const std::string & /*arg*/,
- const std::map<std::string, std::string> & /*options*/)
+bool GetUsersFunction(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(),
return proto.GetUsers(GetUsersCallback, NULL) == STG::st_ok;
}
-bool SGCONF::GetUserFunction(const SGCONF::CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & /*options*/)
+bool GetUserFunction(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(),
return proto.GetUser(arg, GetUserCallback, NULL) == STG::st_ok;
}
-bool SGCONF::DelUserFunction(const SGCONF::CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & /*options*/)
+bool DelUserFunction(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(),
return proto.DelUser(arg, SimpleCallback, NULL) == STG::st_ok;
}
-bool SGCONF::AddUserFunction(const SGCONF::CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & /*options*/)
+bool AddUserFunction(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::ChgUserFunction(const SGCONF::CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & options)
+bool 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)
+bool CheckUserFunction(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::SendMessageFunction(const SGCONF::CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & options)
+bool SendMessageFunction(const SGCONF::CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options)
{
// TODO
std::cerr << "Unimplemented.\n";
return false;
}
+
+} // namespace anonymous
+
+void SGCONF::AppendUsersOptionBlock(COMMANDS & commands, OPTION_BLOCKS & blocks)
+{
+blocks.Add("User management options")
+ .Add("get-users", SGCONF::MakeAPIAction(commands, GetUsersFunction), "\tget user list")
+ .Add("get-user", SGCONF::MakeAPIAction(commands, "<login>", true, GetUserFunction), "get user")
+ .Add("add-user", SGCONF::MakeAPIAction(commands, "<login>", true, AddUserFunction), "add user")
+ .Add("del-user", SGCONF::MakeAPIAction(commands, "<login>", true, DelUserFunction), "del user")
+ .Add("chg-user", SGCONF::MakeAPIAction(commands, "<login>", true, ChgUserFunction), "change user")
+ .Add("check-user", SGCONF::MakeAPIAction(commands, "<login>", true, CheckUserFunction), "check user existance and credentials")
+ .Add("send-message", SGCONF::MakeAPIAction(commands, "<login>", true, SendMessageFunction), "send message");
+}
#ifndef __STG_SGCONF_USERS_H__
#define __STG_SGCONF_USERS_H__
-#include <string>
-#include <map>
-
namespace SGCONF
{
-struct CONFIG;
-
-bool GetUsersFunction(const CONFIG & config,
- const std::string & /*arg*/,
- const std::map<std::string, std::string> & /*options*/);
-
-bool GetUserFunction(const CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & /*options*/);
-
-bool DelUserFunction(const CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & /*options*/);
-
-bool AddUserFunction(const CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & options);
-
-bool ChgUserFunction(const CONFIG & config,
- 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);
+class OPTION_BLOCKS;
+class COMMANDS;
-bool SendMessageFunction(const CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & options);
+void AppendUsersOptionBlock(COMMANDS & commands, OPTION_BLOCKS & blocks);
}
#include "xml.h"
+#include "api_action.h"
+#include "options.h"
#include "config.h"
#include "stg/servconf.h"
#include <iostream>
+#include <string>
+#include <map>
#include <expat.h>
std::cout << Indent(state->level) << "</" << el << ">\n";
}
-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;
- }
-SGCONF::PrintXML(response);
-}
-
-}
-
-void SGCONF::PrintXML(const std::string& xml)
+void PrintXML(const std::string& xml)
{
ParserState state = { 0 };
XML_ParserFree(parser);
}
-bool SGCONF::RawXMLFunction(const SGCONF::CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & /*options*/)
+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);
+}
+
+bool RawXMLFunction(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.RawXML(arg, RawXMLCallback, NULL) == STG::st_ok;
+}
+
+}
+
+void SGCONF::AppendXMLOptionBlock(COMMANDS & commands, OPTION_BLOCKS & blocks)
{
- STG::SERVCONF proto(config.server.data(),
- config.port.data(),
- config.userName.data(),
- config.userPass.data());
- return proto.RawXML(arg, RawXMLCallback, NULL) == STG::st_ok;
+blocks.Add("Raw XML")
+ .Add("r", "raw", SGCONF::MakeAPIAction(commands, "<xml>", true, RawXMLFunction), "\tmake raw XML request");
}
#ifndef __STG_SGCONF_XML_H__
#define __STG_SGCONF_XML_H__
-#include <string>
-#include <map>
-
namespace SGCONF
{
-struct CONFIG;
-
-void PrintXML(const std::string& xml);
+class OPTION_BLOCKS;
+class COMMANDS;
-bool RawXMLFunction(const SGCONF::CONFIG & config,
- const std::string & arg,
- const std::map<std::string, std::string> & /*options*/);
+void AppendXMLOptionBlock(COMMANDS & commands, OPTION_BLOCKS & blocks);
}