]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/rpcconfig/info_methods.cpp
Don't compile c-file s with cxx-compiler. Clang doesn't like it.
[stg.git] / projects / stargazer / plugins / configuration / rpcconfig / info_methods.cpp
1 #include <sys/utsname.h>
2
3 #include <ostream> // xmlrpc-c devs have missed something :)
4
5 #include "stg/version.h"
6 #include "stg/common.h"
7 #include "info_methods.h"
8 #include "rpcconfig.h"
9
10 void METHOD_INFO::execute(xmlrpc_c::paramList const & paramList,
11                           xmlrpc_c::value *   const   retvalPtr)
12 {
13 paramList.verifyEnd(0);
14 std::map<std::string, xmlrpc_c::value> structVal;
15
16 std::string un;
17 struct utsname utsn;
18
19 uname(&utsn);
20 un[0] = 0;
21
22 un += utsn.sysname;
23 un += " ";
24 un += utsn.release;
25 un += " ";
26 un += utsn.machine;
27 un += " ";
28 un += utsn.nodename;
29
30 structVal["version"] = xmlrpc_c::value_string(SERVER_VERSION);
31 structVal["tariff_num"] = xmlrpc_c::value_int(static_cast<int>(tariffs->Count()));
32 structVal["tariff"] = xmlrpc_c::value_int(2);
33 structVal["users_num"] = xmlrpc_c::value_int(static_cast<int>(users->Count()));
34 structVal["uname"] = xmlrpc_c::value_string(un);
35 structVal["dir_num"] = xmlrpc_c::value_int(DIR_NUM);
36 structVal["day_fee"] = xmlrpc_c::value_int(static_cast<int>(dayFee));
37
38 std::vector<xmlrpc_c::value> dirnameVal;
39
40 for (int i = 0; i< DIR_NUM; i++)
41     {
42     dirnameVal.push_back(xmlrpc_c::value_string(IconvString(dirNames[i], "KOI8-RU", "UTF-8")));
43     }
44
45 structVal["dir_names"] = xmlrpc_c::value_array(dirnameVal);
46
47 *retvalPtr = xmlrpc_c::value_struct(structVal);
48 }
49
50 void METHOD_LOGIN::execute(xmlrpc_c::paramList const & paramList,
51                            xmlrpc_c::value *   const   retvalPtr)
52 {
53 std::string login = paramList.getString(0);
54 std::string password = paramList.getString(1);
55 paramList.verifyEnd(2);
56
57 std::map<std::string, xmlrpc_c::value> structVal;
58
59 std::string cookie;
60 if (config->CheckAdmin(login, password, &cookie))
61     {
62     structVal["result"] = xmlrpc_c::value_boolean(false);
63     structVal["cookie"] = xmlrpc_c::value_string("");
64     }
65 else
66     {
67     structVal["result"] = xmlrpc_c::value_boolean(true);
68     structVal["cookie"] = xmlrpc_c::value_string(cookie);
69     }
70
71 *retvalPtr = xmlrpc_c::value_struct(structVal);
72 }
73
74 void METHOD_LOGOUT::execute(xmlrpc_c::paramList const & paramList,
75                             xmlrpc_c::value *   const   retvalPtr)
76 {
77 std::string cookie = paramList.getString(0);
78 paramList.verifyEnd(1);
79
80 if (config->LogoutAdmin(cookie))
81     {
82     *retvalPtr = xmlrpc_c::value_boolean(false);
83     }
84 else
85     {
86     *retvalPtr = xmlrpc_c::value_boolean(true);
87     }
88 }