1 #include "stg/stg_message.h"
2 #include "stg/common.h"
4 #include "messages_methods.h"
7 extern const volatile time_t stgTime;
9 //------------------------------------------------------------------------------
11 void METHOD_MESSAGE_SEND::execute(xmlrpc_c::paramList const & paramList,
12 xmlrpc_c::value * const retvalPtr)
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);
21 if (config->GetAdminInfo(cookie, &adminInfo))
23 *retvalPtr = xmlrpc_c::value_boolean(false);
29 std::map<std::string, xmlrpc_c::value>::iterator it;
31 if ((it = msgInfo.find("version")) == msgInfo.end())
33 message.header.ver = 1; // Default value
37 message.header.ver = xmlrpc_c::value_int(it->second);
40 if ((it = msgInfo.find("type")) == msgInfo.end())
42 message.header.type = 1; // default value
46 message.header.type = xmlrpc_c::value_int(it->second);
49 if ((it = msgInfo.find("repeat")) == msgInfo.end())
51 *retvalPtr = xmlrpc_c::value_boolean(false);
54 message.header.repeat = xmlrpc_c::value_int(it->second);
56 if ((it = msgInfo.find("repeat_period")) == msgInfo.end())
58 *retvalPtr = xmlrpc_c::value_boolean(false);
61 message.header.repeatPeriod = xmlrpc_c::value_int(it->second);
63 if ((it = msgInfo.find("show_time")) == msgInfo.end())
65 *retvalPtr = xmlrpc_c::value_boolean(false);
68 message.header.showTime = xmlrpc_c::value_int(it->second);
70 if ((it = msgInfo.find("text")) == msgInfo.end())
72 *retvalPtr = xmlrpc_c::value_boolean(false);
75 message.text = IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "CP1251");
77 message.header.creationTime = stgTime;
78 message.header.lastSendTime = 0;
80 std::vector<xmlrpc_c::value>::iterator lit;
81 for (lit = logins.begin(); lit != logins.end(); ++lit)
84 if (users->FindByName(xmlrpc_c::value_string(*lit), &ui))
86 printfd(__FILE__, "METHOD_MESSAGE_SEND::execute(): 'User '%s' not found'\n", std::string(xmlrpc_c::value_string(*lit)).c_str());
90 ui->AddMessage(&message);
94 *retvalPtr = xmlrpc_c::value_boolean(true);