2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
19 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
22 #include "parser_message.h"
24 #include "stg/users.h"
29 extern volatile time_t stgTime; // So sad...
31 using STG::PARSER::SEND_MESSAGE;
33 const char * SEND_MESSAGE::tag = "Message";
35 int SEND_MESSAGE::Start(void *, const char *el, const char **attr)
37 if (strcasecmp(el, m_tag.c_str()) != 0)
40 for (size_t i = 0; i < 14; i++)
43 m_result = res_params_error;
45 printfd(__FILE__, "To few parameters\n");
49 for (size_t i = 0; i < 14; i += 2)
51 if (strcasecmp(attr[i], "login") == 0)
52 ParseLogins(attr[i + 1]);
54 if (strcasecmp(attr[i], "MsgVer") == 0)
56 str2x(attr[i + 1], m_msg.header.ver);
57 if (m_msg.header.ver != 1)
58 m_result = res_params_error;
61 if (strcasecmp(attr[i], "MsgType") == 0)
63 str2x(attr[i + 1], m_msg.header.type);
64 if (m_msg.header.type != 1)
65 m_result = res_params_error;
68 if (strcasecmp(attr[i], "Repeat") == 0)
70 str2x(attr[i + 1], m_msg.header.repeat);
71 if (m_msg.header.repeat < 0)
72 m_result = res_params_error;
75 if (strcasecmp(attr[i], "RepeatPeriod") == 0)
76 str2x(attr[i + 1], m_msg.header.repeatPeriod);
78 if (strcasecmp(attr[i], "ShowTime") == 0)
79 str2x(attr[i + 1], m_msg.header.showTime);
81 if (strcasecmp(attr[i], "Text") == 0)
83 Decode21str(m_msg.text, attr[i + 1]);
90 int SEND_MESSAGE::End(void *, const char *el)
92 if (strcasecmp(el, m_tag.c_str()) != 0)
95 m_result = res_unknown;
96 for (unsigned i = 0; i < m_logins.size(); i++)
98 if (m_users.FindByName(m_logins[i], &m_user))
100 printfd(__FILE__, "User not found. %s\n", m_logins[i].c_str());
103 m_msg.header.creationTime = static_cast<unsigned int>(stgTime);
104 m_user->AddMessage(&m_msg);
111 int SEND_MESSAGE::ParseLogins(const char * login)
114 char * l = new char[strlen(login) + 1];
120 m_logins.push_back(p);
121 p = strtok(NULL, ":");
128 void SEND_MESSAGE::CreateAnswer()
133 m_answer = "<SendMessageResult value=\"ok\"/>";
135 case res_params_error:
136 m_answer = "<SendMessageResult value=\"Parameters error.\"/>";
139 m_answer = "<SendMessageResult value=\"Unknown user.\"/>";