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 "stg/parser_get_user.h"
24 #include "stg/common.h"
33 bool GetValue<PARSER_GET_USER::STAT>(const char ** attr, PARSER_GET_USER::STAT & value)
37 std::map<std::string, long long *> props;
38 for (size_t i = 0; i < DIR_NUM; ++i)
40 props.insert(std::pair<std::string, long long *>("su" + x2str(i), &value.su[i]));
41 props.insert(std::pair<std::string, long long *>("sd" + x2str(i), &value.sd[i]));
42 props.insert(std::pair<std::string, long long *>("mu" + x2str(i), &value.mu[i]));
43 props.insert(std::pair<std::string, long long *>("md" + x2str(i), &value.md[i]));
48 std::string name(ToLower(attr[pos++]));
49 std::map<std::string, long long *>::iterator it(props.find(name));
50 if (it != props.end())
51 if (str2x(attr[pos++], *it->second) < 0)
57 PARSER_GET_USER::PARSER_GET_USER()
63 AddParser(propertyParsers, "login", info.login);
64 AddParser(propertyParsers, "password", info.password);
65 AddParser(propertyParsers, "cash", info.cash);
66 AddParser(propertyParsers, "credit", info.credit);
67 AddParser(propertyParsers, "creditExpire", info.creditExpire);
68 AddParser(propertyParsers, "lastCash", info.lastCash);
69 AddParser(propertyParsers, "prepaidTraff", info.prepaidTraff);
70 AddParser(propertyParsers, "down", info.down);
71 AddParser(propertyParsers, "passive", info.passive);
72 AddParser(propertyParsers, "disableDetailStat", info.disableDetailStat);
73 AddParser(propertyParsers, "connected", info.connected);
74 AddParser(propertyParsers, "alwaysOnline", info.alwaysOnline);
75 AddParser(propertyParsers, "currIP", info.ip, GetIPValue);
76 AddParser(propertyParsers, "ip", info.ips);
77 AddParser(propertyParsers, "tariff", info.tariff);
78 AddParser(propertyParsers, "group", info.group, GetEncodedValue);
79 AddParser(propertyParsers, "note", info.note, GetEncodedValue);
80 AddParser(propertyParsers, "email", info.email, GetEncodedValue);
81 AddParser(propertyParsers, "name", info.name, GetEncodedValue);
82 AddParser(propertyParsers, "address", info.address, GetEncodedValue);
83 AddParser(propertyParsers, "phone", info.phone, GetEncodedValue);
84 AddParser(propertyParsers, "traff", info.stat);
86 for (size_t i = 0; i < USERDATA_NUM; ++i)
87 AddParser(propertyParsers, "userData" + x2str(i), info.userData[i], GetEncodedValue);
89 //-----------------------------------------------------------------------------
90 PARSER_GET_USER::~PARSER_GET_USER()
92 PROPERTY_PARSERS::iterator it(propertyParsers.begin());
93 while (it != propertyParsers.end())
94 delete (it++)->second;
96 //-----------------------------------------------------------------------------
97 int PARSER_GET_USER::ParseStart(const char * el, const char ** attr)
103 if (depth == 2 && parsingAnswer)
104 ParseUserParams(el, attr);
108 //-----------------------------------------------------------------------------
109 void PARSER_GET_USER::ParseEnd(const char * /*el*/)
112 if (depth == 0 && parsingAnswer)
115 callback(error.empty(), error, info, data);
117 parsingAnswer = false;
120 //-----------------------------------------------------------------------------
121 void PARSER_GET_USER::ParseUser(const char * el, const char ** attr)
123 if (strcasecmp(el, "user") == 0)
124 if (attr && attr[0] && attr[1])
126 if (strcasecmp(attr[1], "error") == 0)
128 if (attr[2] && attr[3])
131 error = "User not found.";
134 parsingAnswer = true;
137 parsingAnswer = true;
139 //-----------------------------------------------------------------------------
140 void PARSER_GET_USER::ParseUserParams(const char * el, const char ** attr)
142 if (!TryParse(propertyParsers, ToLower(el), attr))
143 error = "Invalid parameter.";
145 //-----------------------------------------------------------------------------
146 void PARSER_GET_USER::SetCallback(CALLBACK f, void * d)