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"
35 bool GetValue<PARSER_GET_USER::STAT>(const char ** attr, PARSER_GET_USER::STAT & value)
39 std::map<std::string, long long *> props;
40 for (size_t i = 0; i < DIR_NUM; ++i)
42 props.insert(std::pair<std::string, long long *>("su" + x2str(i), &value.su[i]));
43 props.insert(std::pair<std::string, long long *>("sd" + x2str(i), &value.sd[i]));
44 props.insert(std::pair<std::string, long long *>("mu" + x2str(i), &value.mu[i]));
45 props.insert(std::pair<std::string, long long *>("md" + x2str(i), &value.md[i]));
50 std::string name(ToLower(attr[pos++]));
51 std::map<std::string, long long *>::iterator it(props.find(name));
52 if (it != props.end())
53 if (str2x(attr[pos++], *it->second) < 0)
59 PARSER_GET_USER::PARSER_GET_USER()
65 AddParser(propertyParsers, "login", info.login);
66 AddParser(propertyParsers, "password", info.password);
67 AddParser(propertyParsers, "cash", info.cash);
68 AddParser(propertyParsers, "credit", info.credit);
69 AddParser(propertyParsers, "creditExpire", info.creditExpire);
70 AddParser(propertyParsers, "lastCash", info.lastCash);
71 AddParser(propertyParsers, "prepaidTraff", info.prepaidTraff);
72 AddParser(propertyParsers, "down", info.down);
73 AddParser(propertyParsers, "passive", info.passive);
74 AddParser(propertyParsers, "disableDetailStat", info.disableDetailStat);
75 AddParser(propertyParsers, "connected", info.connected);
76 AddParser(propertyParsers, "aonline", info.alwaysOnline);
77 AddParser(propertyParsers, "currIP", info.ip, GetIPValue);
78 AddParser(propertyParsers, "ip", info.ips);
79 AddParser(propertyParsers, "tariff", info.tariff);
80 AddParser(propertyParsers, "group", info.group, GetEncodedValue);
81 AddParser(propertyParsers, "note", info.note, GetEncodedValue);
82 AddParser(propertyParsers, "email", info.email, GetEncodedValue);
83 AddParser(propertyParsers, "name", info.name, GetEncodedValue);
84 AddParser(propertyParsers, "address", info.address, GetEncodedValue);
85 AddParser(propertyParsers, "phone", info.phone, GetEncodedValue);
86 AddParser(propertyParsers, "traff", info.stat);
88 for (size_t i = 0; i < USERDATA_NUM; ++i)
89 AddParser(propertyParsers, "userData" + x2str(i), info.userData[i], GetEncodedValue);
91 //-----------------------------------------------------------------------------
92 PARSER_GET_USER::~PARSER_GET_USER()
94 PROPERTY_PARSERS::iterator it(propertyParsers.begin());
95 while (it != propertyParsers.end())
96 delete (it++)->second;
98 //-----------------------------------------------------------------------------
99 int PARSER_GET_USER::ParseStart(const char * el, const char ** attr)
105 if (depth == 2 && parsingAnswer)
106 ParseUserParams(el, attr);
110 //-----------------------------------------------------------------------------
111 void PARSER_GET_USER::ParseEnd(const char * /*el*/)
114 if (depth == 0 && parsingAnswer)
117 callback(error.empty(), error, info, data);
119 parsingAnswer = false;
122 //-----------------------------------------------------------------------------
123 void PARSER_GET_USER::ParseUser(const char * el, const char ** attr)
125 if (strcasecmp(el, "user") == 0)
126 if (attr && attr[0] && attr[1])
128 if (strcasecmp(attr[1], "error") == 0)
130 if (attr[2] && attr[3])
133 error = "User not found.";
136 parsingAnswer = true;
139 parsingAnswer = true;
141 //-----------------------------------------------------------------------------
142 void PARSER_GET_USER::ParseUserParams(const char * el, const char ** attr)
144 if (!TryParse(propertyParsers, ToLower(el), attr))
145 error = "Invalid parameter.";
147 //-----------------------------------------------------------------------------
148 void PARSER_GET_USER::SetCallback(CALLBACK f, void * d)