1 #include "messages_methods.h"
6 #include "stg/message.h"
7 #include "stg/common.h"
9 #include <ostream> // xmlrpc-c devs have missed something :)
11 extern volatile time_t stgTime;
13 //------------------------------------------------------------------------------
15 void METHOD_MESSAGE_SEND::execute(xmlrpc_c::paramList const & paramList,
16 xmlrpc_c::value * const retvalPtr)
18 std::string cookie = paramList.getString(0);
19 std::vector<xmlrpc_c::value> logins(paramList.getArray(1));
20 std::map<std::string, xmlrpc_c::value> msgInfo(paramList.getStruct(2));
21 paramList.verifyEnd(3);
25 if (config->GetAdminInfo(cookie, &adminInfo))
27 *retvalPtr = xmlrpc_c::value_boolean(false);
33 std::map<std::string, xmlrpc_c::value>::iterator it;
35 if ((it = msgInfo.find("version")) == msgInfo.end())
37 message.header.ver = 1; // Default value
41 message.header.ver = xmlrpc_c::value_int(it->second);
44 if ((it = msgInfo.find("type")) == msgInfo.end())
46 message.header.type = 1; // default value
50 message.header.type = xmlrpc_c::value_int(it->second);
53 if ((it = msgInfo.find("repeat")) == msgInfo.end())
55 *retvalPtr = xmlrpc_c::value_boolean(false);
58 message.header.repeat = xmlrpc_c::value_int(it->second);
60 if ((it = msgInfo.find("repeat_period")) == msgInfo.end())
62 *retvalPtr = xmlrpc_c::value_boolean(false);
65 message.header.repeatPeriod = xmlrpc_c::value_int(it->second);
67 if ((it = msgInfo.find("show_time")) == msgInfo.end())
69 *retvalPtr = xmlrpc_c::value_boolean(false);
72 message.header.showTime = xmlrpc_c::value_int(it->second);
74 if ((it = msgInfo.find("text")) == msgInfo.end())
76 *retvalPtr = xmlrpc_c::value_boolean(false);
79 message.text = IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "CP1251");
81 message.header.creationTime = static_cast<int>(stgTime);
82 message.header.lastSendTime = 0;
84 std::vector<xmlrpc_c::value>::iterator lit;
85 for (lit = logins.begin(); lit != logins.end(); ++lit)
87 using UserPtr = STG::User*;
89 if (users->FindByName(xmlrpc_c::value_string(*lit), &ui))
91 printfd(__FILE__, "METHOD_MESSAGE_SEND::execute(): 'User '%s' not found'\n", std::string(xmlrpc_c::value_string(*lit)).c_str());
95 ui->AddMessage(&message);
99 *retvalPtr = xmlrpc_c::value_boolean(true);