X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/8c6fa3fbaccc22127280bf77a48fab5a3ee0716e..46b0747592074017ff0ea4b33d4a7194235886e5:/sgconf/info.cpp diff --git a/sgconf/info.cpp b/sgconf/info.cpp new file mode 100644 index 00000000..0e98d3dc --- /dev/null +++ b/sgconf/info.cpp @@ -0,0 +1,60 @@ +#include "info.h" + +#include "api_action.h" +#include "options.h" +#include "config.h" + +#include "stg/servconf.h" + +#include +#include +#include + +#include + +namespace +{ + +void PrintInfo(const STG::SERVER_INFO::INFO& info) +{ + std::cout << "Server version: '" << info.version << "'\n" + << "Number of tariffs: " << info.tariffNum << "\n" + << "Tariff subsystem version: " << info.tariffType << "\n" + << "Number of users: " << info.usersNum << "\n" + << "UName: '" << info.uname << "\n" + << "Number of directions: " << info.dirNum << "\n" + << "Dirs:\n"; + for (size_t i = 0; i < info.dirName.size(); ++i) + std::cout << "\t - '" << info.dirName[i] << "'\n"; +} + +void InfoCallback(bool result, const std::string & reason, const STG::SERVER_INFO::INFO & info, void * /*data*/) +{ +if (!result) + { + std::cerr << "Failed to get server info. Reason: '" << reason << "'." << std::endl; + return; + } +PrintInfo(info); +} + +bool InfoFunction(const SGCONF::CONFIG & config, + const std::string& /*arg*/, + const std::map & /*options*/) +{ +STG::SERVCONF proto(config.server.data(), + config.port.data(), + config.localAddress.data(), + config.localPort.data(), + config.userName.data(), + config.userPass.data()); +return proto.ServerInfo(InfoCallback, NULL) == STG::st_ok; +} + +} + +void SGCONF::AppendServerInfoBlock(COMMANDS & commands, OPTION_BLOCKS & blocks) +{ +blocks.Add("Server info") + .Add("server-info", SGCONF::MakeAPIAction(commands, InfoFunction), "\tget server info"); +}