1 #include <ostream> // xmlrpc-c devs have missed something :)
3 #include "stg/message.h"
4 #include "stg/common.h"
5 #include "messages_methods.h"
8 extern const volatile time_t stgTime;
10 //------------------------------------------------------------------------------
12 void METHOD_MESSAGE_SEND::execute(xmlrpc_c::paramList const & paramList,
13 xmlrpc_c::value * const retvalPtr)
15 std::string cookie = paramList.getString(0);
16 std::vector<xmlrpc_c::value> logins(paramList.getArray(1));
17 std::map<std::string, xmlrpc_c::value> msgInfo(paramList.getStruct(2));
18 paramList.verifyEnd(3);
22 if (config->GetAdminInfo(cookie, &adminInfo))
24 *retvalPtr = xmlrpc_c::value_boolean(false);
30 std::map<std::string, xmlrpc_c::value>::iterator it;
32 if ((it = msgInfo.find("version")) == msgInfo.end())
34 message.header.ver = 1; // Default value
38 message.header.ver = xmlrpc_c::value_int(it->second);
41 if ((it = msgInfo.find("type")) == msgInfo.end())
43 message.header.type = 1; // default value
47 message.header.type = xmlrpc_c::value_int(it->second);
50 if ((it = msgInfo.find("repeat")) == msgInfo.end())
52 *retvalPtr = xmlrpc_c::value_boolean(false);
55 message.header.repeat = xmlrpc_c::value_int(it->second);
57 if ((it = msgInfo.find("repeat_period")) == msgInfo.end())
59 *retvalPtr = xmlrpc_c::value_boolean(false);
62 message.header.repeatPeriod = xmlrpc_c::value_int(it->second);
64 if ((it = msgInfo.find("show_time")) == msgInfo.end())
66 *retvalPtr = xmlrpc_c::value_boolean(false);
69 message.header.showTime = xmlrpc_c::value_int(it->second);
71 if ((it = msgInfo.find("text")) == msgInfo.end())
73 *retvalPtr = xmlrpc_c::value_boolean(false);
76 message.text = IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "CP1251");
78 message.header.creationTime = stgTime;
79 message.header.lastSendTime = 0;
81 std::vector<xmlrpc_c::value>::iterator lit;
82 for (lit = logins.begin(); lit != logins.end(); ++lit)
85 if (users->FindByName(xmlrpc_c::value_string(*lit), &ui))
87 printfd(__FILE__, "METHOD_MESSAGE_SEND::execute(): 'User '%s' not found'\n", std::string(xmlrpc_c::value_string(*lit)).c_str());
91 ui->AddMessage(&message);
95 *retvalPtr = xmlrpc_c::value_boolean(true);