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
34 const size_t UNAME_LEN = 256;
35 const size_t SERV_VER_LEN = 64;
36 const size_t DIRNAME_LEN = 16;
38 bool checkValue(const char ** attr)
40 return attr && attr[0] && attr[1] && strcasecmp(attr[0], "value") == 0;
43 int getIntValue(const char ** attr)
47 if (str2x(attr[1], value) < 0)
52 std::string getStringValue(const char ** attr)
61 PARSER_SERVER_INFO::PARSER_SERVER_INFO()
67 //-----------------------------------------------------------------------------
68 int PARSER_SERVER_INFO::ParseStart(const char *el, const char **attr)
73 if (strcasecmp(el, "ServerInfo") != 0)
82 if (strcasecmp(el, "uname") == 0)
84 info.uname = getStringValue(attr);
87 if (strcasecmp(el, "version") == 0)
89 info.version = getStringValue(attr);
92 if (strcasecmp(el, "tariff") == 0)
94 info.tariffType = getIntValue(attr);
97 if (strcasecmp(el, "dir_num") == 0)
99 info.dirNum = getIntValue(attr);
102 if (strcasecmp(el, "users_num") == 0)
104 info.usersNum = getIntValue(attr);
107 if (strcasecmp(el, "tariff_num") == 0)
109 info.tariffNum = getIntValue(attr);
113 for (int j = 0; j < DIR_NUM; j++)
116 sprintf(str, "dir_name_%d", j);
117 if (strcasecmp(el, str) == 0)
118 ParseDirName(attr, j);
125 //-----------------------------------------------------------------------------
126 void PARSER_SERVER_INFO::ParseEnd(const char * /*el*/)
129 if (depth == 0 && callback)
130 callback(info, data);
132 //-----------------------------------------------------------------------------
133 void PARSER_SERVER_INFO::SetCallback(CALLBACK f, void * d)
138 //-----------------------------------------------------------------------------
139 void PARSER_SERVER_INFO::ParseDirName(const char **attr, int d)
141 if (checkValue(attr))
143 char str[2 * DIRNAME_LEN + 1];
144 Decode21(str, attr[1]);
145 info.dirName[d] = str;