]> git.stg.codes - stg.git/blob - sgconf/info.cpp
Added optional DB port parameter for MySQL store.
[stg.git] / sgconf / info.cpp
1 #include "info.h"
2
3 #include "api_action.h"
4 #include "options.h"
5 #include "config.h"
6
7 #include "stg/servconf.h"
8
9 #include <iostream>
10 #include <string>
11 #include <map>
12
13 #include <expat.h>
14
15 namespace
16 {
17
18 void PrintInfo(const STG::ServerInfo::Info& info)
19 {
20     std::cout << "Server version: '" << info.version << "'\n"
21               << "Number of tariffs: " << info.tariffNum << "\n"
22               << "Tariff subsystem version: " << info.tariffType << "\n"
23               << "Number of users: " << info.usersNum << "\n"
24               << "UName: '" << info.uname << "\n"
25               << "Number of directions: " << info.dirNum << "\n"
26               << "Dirs:\n";
27     for (size_t i = 0; i < info.dirName.size(); ++i)
28         std::cout << "\t - '" << info.dirName[i] << "'\n";
29 }
30
31 void InfoCallback(bool result, const std::string & reason, const STG::ServerInfo::Info & info, void * /*data*/)
32 {
33 if (!result)
34     {
35     std::cerr << "Failed to get server info. Reason: '" << reason << "'." << std::endl;
36     return;
37     }
38 PrintInfo(info);
39 }
40
41 bool InfoFunction(const SGCONF::CONFIG & config,
42                   const std::string& /*arg*/,
43                   const std::map<std::string, std::string> & /*options*/)
44 {
45 STG::ServConf proto(config.server.data(),
46                     config.port.data(),
47                     config.localAddress.data(),
48                     config.localPort.data(),
49                     config.userName.data(),
50                     config.userPass.data());
51 return proto.ServerInfo(InfoCallback, NULL) == STG::st_ok;
52 }
53
54 }
55
56 void SGCONF::AppendServerInfoBlock(COMMANDS & commands, OPTION_BLOCKS & blocks)
57 {
58 blocks.Add("Server info")
59       .Add("server-info", SGCONF::MakeAPIAction(commands, InfoFunction), "\tget server info");
60 }