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 : Maxim Mamontov <faust@stargazer.dp.ua>
21 #include "parser_services.h"
23 #include "stg/services.h"
25 #include <strings.h> // strcasecmp
27 using STG::PARSER::GET_SERVICES;
28 using STG::PARSER::GET_SERVICE;
29 using STG::PARSER::ADD_SERVICE;
30 using STG::PARSER::DEL_SERVICE;
31 using STG::PARSER::CHG_SERVICE;
33 const char * GET_SERVICES::tag = "GetServices";
34 const char * GET_SERVICE::tag = "AddService";
35 const char * ADD_SERVICE::tag = "AddService";
36 const char * DEL_SERVICE::tag = "DelService";
37 const char * CHG_SERVICE::tag = "ChgService";
39 void GET_SERVICES::CreateAnswer()
41 // TODO: no priviledges implemented yet
42 /*const PRIV * priv = m_currAdmin.GetPriv();
43 if (!priv->serviceChg)
45 m_answer = "<Error Result=\"Error. Access denied.\"/>";
49 m_answer = "<Services>";
51 int h = m_services.OpenSearch();
52 while (m_services.SearchNext(h, &conf) == 0)
54 m_answer += "<Service name=\"" + conf.name +
55 "\" comment=\"" + Encode12str(conf.comment) +
56 "\" cost=\"" + x2str(conf.cost) +
57 "\" payDay=\"" + x2str(conf.payDay) + "\"/>";
59 m_services.CloseSearch(h);
60 m_answer += "</Services>";
63 int GET_SERVICE::Start(void *, const char * el, const char ** attr)
65 if (strcasecmp(el, m_tag.c_str()) == 0)
73 void GET_SERVICE::CreateAnswer()
75 // TODO: no priviledges implemented yet
76 /*const PRIV * priv = m_currAdmin.GetPriv();
77 if (!priv->serviceChg)
79 m_answer = "<Error Result=\"Error. Access denied.\"/>";
84 if (!m_services.Find(m_name, &conf))
85 m_answer = "<Error result=\"Service '" + m_name + "' does not exist.\"/>";
87 m_answer += "<" + m_tag + " name=\"" + conf.name +
88 "\" comment=\"" + Encode12str(conf.comment) +
89 "\" cost=\"" + x2str(conf.cost) +
90 "\" payDay=\"" + x2str(conf.payDay) + "\"/>";
93 int ADD_SERVICE::Start(void *, const char * el, const char ** attr)
95 if (strcasecmp(el, m_tag.c_str()) == 0)
103 void ADD_SERVICE::CreateAnswer()
105 SERVICE_CONF conf(m_name);
106 if (m_services.Add(conf, &m_currAdmin) == 0)
107 m_answer = "<" + m_tag + " result=\"Ok\"/>";
109 m_answer = "<" + m_tag + " result=\"Error. " + m_services.GetStrError() + "\"/>";
112 int DEL_SERVICE::Start(void *, const char * el, const char ** attr)
114 if (strcasecmp(el, m_tag.c_str()) == 0)
122 void DEL_SERVICE::CreateAnswer()
124 if (m_services.Del(m_name, &m_currAdmin) == 0)
125 m_answer = "<" + m_tag + " result=\"Ok\"/>";
127 m_answer = "<" + m_tag + " result=\"Error. " + m_services.GetStrError() + "\"/>";
130 int CHG_SERVICE::Start(void *, const char * el, const char ** attr)
132 if (strcasecmp(el, m_tag.c_str()) == 0)
134 for (size_t i = 0; i < 8; i += 2)
136 printfd(__FILE__, "PARSER_CHG_SERVICE::attr[%d] = %s\n", i, attr[i]);
140 if (strcasecmp(attr[i], "name") == 0)
142 m_service.name = attr[i + 1];
146 if (strcasecmp(attr[i], "comment") == 0)
148 m_service.comment = Decode21str(attr[i + 1]);
152 if (strcasecmp(attr[i], "cost") == 0)
155 if (str2x(attr[i + 1], cost) == 0)
156 m_service.cost = cost;
161 if (strcasecmp(attr[i], "payDay") == 0)
164 if (str2x(attr[i + 1], payDay) == 0)
165 m_service.payDay = payDay;
176 void CHG_SERVICE::CreateAnswer()
178 if (m_service.name.empty())
180 m_answer = "<" + m_tag + " result=\"Empty service name.\"/>";
184 if (!m_services.Exists(m_service.name.const_data()))
186 m_answer = "<" + m_tag + " result = \"Service '" + m_service.name.const_data() + "' does not exist.\"/>";
191 m_services.Find(m_service.name.const_data(), &orig);
193 m_service.Splice(orig);
195 if (m_services.Change(m_service.GetData(), &m_currAdmin) != 0)
196 m_answer = "<" + m_tag + " result = \"" + m_services.GetStrError() + "\"/>";
198 m_answer = "<" + m_tag + " result = \"Ok\"/>";