]> git.stg.codes - stg.git/commitdiff
Added --server-info parameter for sgconf.
authorMaxim Mamontov <faust.madf@gmail.com>
Sun, 23 Nov 2014 09:47:03 +0000 (11:47 +0200)
committerMaxim Mamontov <faust.madf@gmail.com>
Sun, 23 Nov 2014 09:47:03 +0000 (11:47 +0200)
projects/sgconf/Makefile
projects/sgconf/info.cpp [new file with mode: 0644]
projects/sgconf/info.h [new file with mode: 0644]
projects/sgconf/main.cpp

index 52a70ae8fdc49d569985f02500cc188c2d36c2e0..803035df22dcb39f7f60d738b4eb03c625df08c2 100644 (file)
@@ -15,6 +15,7 @@ SRCS = ./main.cpp \
        ./users.cpp \
        ./services.cpp \
        ./corps.cpp \
+       ./info.cpp \
        ./xml.cpp
 
 STGLIBS = srvconf \
diff --git a/projects/sgconf/info.cpp b/projects/sgconf/info.cpp
new file mode 100644 (file)
index 0000000..0e98d3d
--- /dev/null
@@ -0,0 +1,60 @@
+#include "info.h"
+
+#include "api_action.h"
+#include "options.h"
+#include "config.h"
+
+#include "stg/servconf.h"
+
+#include <iostream>
+#include <string>
+#include <map>
+
+#include <expat.h>
+
+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<std::string, std::string> & /*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");
+}
diff --git a/projects/sgconf/info.h b/projects/sgconf/info.h
new file mode 100644 (file)
index 0000000..86e4a9e
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_SGCONF_SERVER_INFO_H__
+#define __STG_SGCONF_SERVER_INFO_H__
+
+namespace SGCONF
+{
+
+class OPTION_BLOCKS;
+class COMMANDS;
+
+void AppendServerInfoBlock(COMMANDS & commands, OPTION_BLOCKS & blocks);
+
+}
+
+#endif
index 97e46d1b1837365a134948288bafa97df700d22c..979081953464c40316b60c8b9708bef2098499a5 100644 (file)
@@ -25,6 +25,7 @@
 #include "users.h"
 #include "services.h"
 #include "corps.h"
+#include "info.h"
 
 #include "api_action.h"
 #include "options.h"
@@ -259,6 +260,7 @@ SGCONF::OPTION_BLOCK & block = blocks.Add("Connection options")
 blocks.Add("Debug options")
       .Add("show-config", SGCONF::MakeParamAction(config.showConfig), "\tshow config and exit");
 SGCONF::AppendXMLOptionBlock(commands, blocks);
+SGCONF::AppendServerInfoBlock(commands, blocks);
 SGCONF::AppendAdminsOptionBlock(commands, blocks);
 SGCONF::AppendTariffsOptionBlock(commands, blocks);
 SGCONF::AppendUsersOptionBlock(commands, blocks);