]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/rpcconfig/messages_methods.cpp
Fix rpcconfig plugin compilation errors
[stg.git] / projects / stargazer / plugins / configuration / rpcconfig / messages_methods.cpp
1 #include "stg/stg_message.h"
2 #include "stg/common.h"
3 #include "utils.h"
4 #include "messages_methods.h"
5 #include "rpcconfig.h"
6
7 extern const volatile time_t stgTime;
8
9 //------------------------------------------------------------------------------
10
11 void METHOD_MESSAGE_SEND::execute(xmlrpc_c::paramList const & paramList,
12                                   xmlrpc_c::value *   const   retvalPtr)
13 {
14 std::string cookie = paramList.getString(0);
15 std::vector<xmlrpc_c::value> logins(paramList.getArray(1));
16 std::map<std::string, xmlrpc_c::value> msgInfo(paramList.getStruct(2));
17 paramList.verifyEnd(3);
18
19 ADMIN_INFO adminInfo;
20
21 if (config->GetAdminInfo(cookie, &adminInfo))
22     {
23     *retvalPtr = xmlrpc_c::value_boolean(false);
24     return;
25     }
26
27 STG_MSG message;
28
29 std::map<std::string, xmlrpc_c::value>::iterator it;
30
31 if ((it = msgInfo.find("version")) == msgInfo.end())
32     {
33     message.header.ver = 1; // Default value
34     }
35 else
36     {
37     message.header.ver = xmlrpc_c::value_int(it->second);
38     }
39
40 if ((it = msgInfo.find("type")) == msgInfo.end())
41     {
42     message.header.type = 1; // default value
43     }
44 else
45     {
46     message.header.type = xmlrpc_c::value_int(it->second);
47     }
48
49 if ((it = msgInfo.find("repeat")) == msgInfo.end())
50     {
51     *retvalPtr = xmlrpc_c::value_boolean(false);
52     return;
53     }
54 message.header.repeat = xmlrpc_c::value_int(it->second);
55
56 if ((it = msgInfo.find("repeat_period")) == msgInfo.end())
57     {
58     *retvalPtr = xmlrpc_c::value_boolean(false);
59     return;
60     }
61 message.header.repeatPeriod = xmlrpc_c::value_int(it->second);
62
63 if ((it = msgInfo.find("show_time")) == msgInfo.end())
64     {
65     *retvalPtr = xmlrpc_c::value_boolean(false);
66     return;
67     }
68 message.header.showTime = xmlrpc_c::value_int(it->second);
69
70 if ((it = msgInfo.find("text")) == msgInfo.end())
71     {
72     *retvalPtr = xmlrpc_c::value_boolean(false);
73     return;
74     }
75 message.text = IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "CP1251");
76
77 message.header.creationTime = stgTime;
78 message.header.lastSendTime = 0;
79
80 std::vector<xmlrpc_c::value>::iterator lit;
81 for (lit = logins.begin(); lit != logins.end(); ++lit)
82     {
83     USER_PTR ui;
84     if (users->FindByName(xmlrpc_c::value_string(*lit), &ui))
85         {
86         printfd(__FILE__, "METHOD_MESSAGE_SEND::execute(): 'User '%s' not found'\n", std::string(xmlrpc_c::value_string(*lit)).c_str());
87         }
88     else
89         {
90         ui->AddMessage(&message);
91         }
92     }
93
94 *retvalPtr = xmlrpc_c::value_boolean(true);
95 }