1 #include <ostream> // xmlrpc-c devs have missed something :)
3 #include "stg/message.h"
4 #include "stg/common.h"
6 #include "messages_methods.h"
9 extern const volatile time_t stgTime;
11 //------------------------------------------------------------------------------
13 void METHOD_MESSAGE_SEND::execute(xmlrpc_c::paramList const & paramList,
14 xmlrpc_c::value * const retvalPtr)
16 std::string cookie = paramList.getString(0);
17 std::vector<xmlrpc_c::value> logins(paramList.getArray(1));
18 std::map<std::string, xmlrpc_c::value> msgInfo(paramList.getStruct(2));
19 paramList.verifyEnd(3);
23 if (config->GetAdminInfo(cookie, &adminInfo))
25 *retvalPtr = xmlrpc_c::value_boolean(false);
31 std::map<std::string, xmlrpc_c::value>::iterator it;
33 if ((it = msgInfo.find("version")) == msgInfo.end())
35 message.header.ver = 1; // Default value
39 message.header.ver = xmlrpc_c::value_int(it->second);
42 if ((it = msgInfo.find("type")) == msgInfo.end())
44 message.header.type = 1; // default value
48 message.header.type = xmlrpc_c::value_int(it->second);
51 if ((it = msgInfo.find("repeat")) == msgInfo.end())
53 *retvalPtr = xmlrpc_c::value_boolean(false);
56 message.header.repeat = xmlrpc_c::value_int(it->second);
58 if ((it = msgInfo.find("repeat_period")) == msgInfo.end())
60 *retvalPtr = xmlrpc_c::value_boolean(false);
63 message.header.repeatPeriod = xmlrpc_c::value_int(it->second);
65 if ((it = msgInfo.find("show_time")) == msgInfo.end())
67 *retvalPtr = xmlrpc_c::value_boolean(false);
70 message.header.showTime = xmlrpc_c::value_int(it->second);
72 if ((it = msgInfo.find("text")) == msgInfo.end())
74 *retvalPtr = xmlrpc_c::value_boolean(false);
77 message.text = IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "CP1251");
79 message.header.creationTime = stgTime;
80 message.header.lastSendTime = 0;
82 std::vector<xmlrpc_c::value>::iterator lit;
83 for (lit = logins.begin(); lit != logins.end(); ++lit)
86 if (users->FindByName(xmlrpc_c::value_string(*lit), &ui))
88 printfd(__FILE__, "METHOD_MESSAGE_SEND::execute(): 'User '%s' not found'\n", std::string(xmlrpc_c::value_string(*lit)).c_str());
92 ui->AddMessage(&message);
96 *retvalPtr = xmlrpc_c::value_boolean(true);