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_server_info.h"
24 #include "stg/common.h"
26 #include <cstdio> // sprintf
33 const size_t UNAME_LEN = 256;
34 const size_t SERV_VER_LEN = 64;
35 const size_t DIRNAME_LEN = 16;
37 bool checkValue(const char ** attr)
39 return attr && attr[0] && attr[1] && strcasecmp(attr[0], "value") == 0;
42 int getIntValue(const char ** attr)
46 if (str2x(attr[1], value) < 0)
51 std::string getStringValue(const char ** attr)
60 PARSER_SERVER_INFO::PARSER_SERVER_INFO()
66 //-----------------------------------------------------------------------------
67 int PARSER_SERVER_INFO::ParseStart(const char *el, const char **attr)
72 if (strcasecmp(el, "ServerInfo") != 0)
81 if (strcasecmp(el, "uname") == 0)
83 info.uname = getStringValue(attr);
86 if (strcasecmp(el, "version") == 0)
88 info.version = getStringValue(attr);
91 if (strcasecmp(el, "tariff") == 0)
93 info.tariffType = getIntValue(attr);
96 if (strcasecmp(el, "dir_num") == 0)
98 info.dirNum = getIntValue(attr);
101 if (strcasecmp(el, "users_num") == 0)
103 info.usersNum = getIntValue(attr);
106 if (strcasecmp(el, "tariff_num") == 0)
108 info.tariffNum = getIntValue(attr);
112 for (int j = 0; j < DIR_NUM; j++)
115 sprintf(str, "dir_name_%d", j);
116 if (strcasecmp(el, str) == 0)
117 ParseDirName(attr, j);
124 //-----------------------------------------------------------------------------
125 void PARSER_SERVER_INFO::ParseEnd(const char * /*el*/)
128 if (depth == 0 && callback)
129 callback(info, data);
131 //-----------------------------------------------------------------------------
132 void PARSER_SERVER_INFO::SetCallback(CALLBACK f, void * d)
137 //-----------------------------------------------------------------------------
138 void PARSER_SERVER_INFO::ParseDirName(const char **attr, int d)
140 if (checkValue(attr))
142 char str[2 * DIRNAME_LEN + 1];
143 Decode21(str, attr[1]);
144 info.dirName[d] = str;