+++ /dev/null
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#ifndef __STG_STGLIBS_SRVCONF_PARSER_H__
-#define __STG_STGLIBS_SRVCONF_PARSER_H__
-
-namespace STG
-{
-
-class PARSER
-{
-public:
- virtual ~PARSER() {}
- virtual int ParseStart(const char *el, const char **attr) = 0;
- virtual void ParseEnd(const char *el) = 0;
-};
-
-} // namespace STG
-
-#endif
+++ /dev/null
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#include "parser_auth_by.h"
-
-#include <cstddef>
-
-#include <strings.h> // strcasecmp
-
-using namespace STG;
-
-AUTH_BY::PARSER::PARSER()
- : callback(NULL),
- data(NULL),
- depth(0),
- parsingAnswer(false)
-{
-}
-//-----------------------------------------------------------------------------
-int AUTH_BY::PARSER::ParseStart(const char *el, const char **attr)
-{
-depth++;
-if (depth == 1)
- {
- if (strcasecmp(el, "AuthorizedBy") == 0)
- if (attr && attr[0] && attr[1])
- {
- if (strcasecmp(attr[1], "error") == 0)
- {
- if (attr[2] && attr[3])
- error = attr[3];
- else
- error = "User not found.";
- }
- else
- parsingAnswer = true;
- }
- }
-else
- {
- if (depth == 2)
- {
- if (parsingAnswer && strcasecmp(el, "Auth") == 0)
- {
- if (attr && attr[0] && attr[1] && strcasecmp(attr[0], "name") == 0)
- info.push_back(attr[1]);
- return 0;
- }
- }
- }
-return 0;
-}
-//-----------------------------------------------------------------------------
-void AUTH_BY::PARSER::ParseEnd(const char * /*el*/)
-{
-depth--;
-if (depth == 0)
- {
- if (callback)
- callback(error.empty(), error, info, data);
- info.clear();
- error.clear();
- }
-}
-//-----------------------------------------------------------------------------
-void AUTH_BY::PARSER::SetCallback(CALLBACK f, void * d)
-{
-callback = f;
-data = d;
-}
+++ /dev/null
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#ifndef __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__
-#define __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__
-
-#include "parser.h"
-
-#include "stg/servconf_types.h"
-
-#include <string>
-
-namespace STG
-{
-namespace AUTH_BY
-{
-
-class PARSER: public STG::PARSER
-{
-public:
- PARSER();
- int ParseStart(const char * el, const char ** attr);
- void ParseEnd(const char * el);
- void SetCallback(CALLBACK f, void * data);
-
-private:
- CALLBACK callback;
- void * data;
- int depth;
- bool parsingAnswer;
- INFO info;
- std::string error;
-};
-
-} // namespace AUTH_BY
-} // namespace STG
-
-#endif
+++ /dev/null
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#include "parser_check_user.h"
-
-#include <cstddef>
-
-#include <strings.h>
-
-using namespace STG;
-
-CHECK_USER::PARSER::PARSER()
- : callback(NULL),
- data(NULL),
- depth(0)
-{
-}
-//-----------------------------------------------------------------------------
-int CHECK_USER::PARSER::ParseStart(const char * el, const char ** attr)
-{
-depth++;
-if (depth == 1)
- if (strcasecmp(el, "CheckUser") == 0)
- ParseAnswer(el, attr);
-return 0;
-}
-//-----------------------------------------------------------------------------
-void CHECK_USER::PARSER::ParseEnd(const char *)
-{
-depth--;
-}
-//-----------------------------------------------------------------------------
-void CHECK_USER::PARSER::ParseAnswer(const char *, const char **attr)
-{
-if (!callback)
- return;
-if (attr && attr[0] && attr[1] && strcasecmp(attr[0], "value") == 0)
- callback(strcasecmp(attr[1], "ok") == 0, attr[2] && attr[3] ? attr[3] : "", data);
-else
- callback(false, "Invalid response.", data);
-}
-//-----------------------------------------------------------------------------
-void CHECK_USER::PARSER::SetCallback(CALLBACK f, void * d)
-{
-callback = f;
-data = d;
-}
+++ /dev/null
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#ifndef __STG_STGLIBS_SRVCONF_PARSER_CHECK_USER_H__
-#define __STG_STGLIBS_SRVCONF_PARSER_CHECK_USER_H__
-
-#include "parser.h"
-
-#include "stg/servconf_types.h"
-
-namespace STG
-{
-namespace CHECK_USER
-{
-
-class PARSER: public STG::PARSER
-{
-public:
- PARSER();
- int ParseStart(const char * el, const char ** attr);
- void ParseEnd(const char * el);
- void SetCallback(CALLBACK f, void * data);
-
-private:
- CALLBACK callback;
- void * data;
- int depth;
-
- void ParseAnswer(const char * el, const char ** attr);
-};
-
-} // namespace CHECK_USER
-} // namespace STG
-
-#endif
+++ /dev/null
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#include "parser_chg_user.h"
-
-#include <cstddef>
-
-#include <strings.h>
-
-using namespace STG;
-
-CHG_USER::PARSER::PARSER()
- : callback(NULL),
- data(NULL),
- depth(0)
-{
-}
-//-----------------------------------------------------------------------------
-int CHG_USER::PARSER::ParseStart(const char *el, const char **attr)
-{
-depth++;
-if (depth == 1)
- {
- if (strcasecmp(el, "SetUser") == 0)
- ParseAnswer(el, attr);
- else if (strcasecmp(el, "DelUser") == 0)
- ParseAnswer(el, attr);
- else if (strcasecmp(el, "AddUser") == 0)
- ParseAnswer(el, attr);
- }
-return 0;
-}
-//-----------------------------------------------------------------------------
-void CHG_USER::PARSER::ParseEnd(const char *)
-{
-depth--;
-}
-//-----------------------------------------------------------------------------
-void CHG_USER::PARSER::ParseAnswer(const char * /*el*/, const char ** attr)
-{
-if (!callback)
- return;
-if (attr && attr[0] && attr[1])
- callback(strcasecmp(attr[1], "ok") == 0, attr[2] && attr[3] ? attr[3] : "", data);
-else
- callback(false, "Invalid response.", data);
-}
-//-----------------------------------------------------------------------------
-void CHG_USER::PARSER::SetCallback(CALLBACK f, void * d)
-{
-callback = f;
-data = d;
-}
+++ /dev/null
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#ifndef __STG_STGLIBS_SRVCONF_PARSER_CHG_USER_H__
-#define __STG_STGLIBS_SRVCONF_PARSER_CHG_USER_H__
-
-#include "parser.h"
-
-#include "stg/servconf_types.h"
-
-namespace STG
-{
-namespace CHG_USER
-{
-
-class PARSER: public STG::PARSER
-{
-public:
- PARSER();
- int ParseStart(const char * el, const char ** attr);
- void ParseEnd(const char * el);
- void SetCallback(CALLBACK f, void * data);
-
-private:
- CALLBACK callback;
- void * data;
- int depth;
-
- void ParseAnswer(const char * el, const char ** attr);
-};
-
-} // namespace CHG_USER
-} // namespace STG
-
-#endif
+++ /dev/null
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#include "parser_get_user.h"
-
-#include "stg/common.h"
-
-#include <map>
-#include <utility>
-#include <cstddef>
-
-#include <strings.h>
-
-using namespace STG;
-
-namespace STG
-{
-
-template <>
-bool GetValue<GET_USER::STAT>(const char ** attr, GET_USER::STAT & value)
-{
-if (!attr)
- return false;
-std::map<std::string, long long *> props;
-for (size_t i = 0; i < DIR_NUM; ++i)
- {
- props.insert(std::pair<std::string, long long *>("su" + x2str(i), &value.su[i]));
- props.insert(std::pair<std::string, long long *>("sd" + x2str(i), &value.sd[i]));
- props.insert(std::pair<std::string, long long *>("mu" + x2str(i), &value.mu[i]));
- props.insert(std::pair<std::string, long long *>("md" + x2str(i), &value.md[i]));
- }
-size_t pos = 0;
-while (attr[pos])
- {
- std::string name(ToLower(attr[pos++]));
- std::map<std::string, long long *>::iterator it(props.find(name));
- if (it != props.end())
- if (str2x(attr[pos++], *it->second) < 0)
- return false;
- }
-return true;
-}
-
-}
-
-GET_USER::PARSER::PARSER()
- : callback(NULL),
- data(NULL),
- depth(0),
- parsingAnswer(false)
-{
- AddParser(propertyParsers, "login", info.login);
- AddParser(propertyParsers, "password", info.password);
- AddParser(propertyParsers, "cash", info.cash);
- AddParser(propertyParsers, "credit", info.credit);
- AddParser(propertyParsers, "creditExpire", info.creditExpire);
- AddParser(propertyParsers, "lastCash", info.lastCash);
- AddParser(propertyParsers, "prepaidTraff", info.prepaidTraff);
- AddParser(propertyParsers, "down", info.down);
- AddParser(propertyParsers, "passive", info.passive);
- AddParser(propertyParsers, "disableDetailStat", info.disableDetailStat);
- AddParser(propertyParsers, "connected", info.connected);
- AddParser(propertyParsers, "aonline", info.alwaysOnline);
- AddParser(propertyParsers, "currIP", info.ip, GetIPValue);
- AddParser(propertyParsers, "ip", info.ips);
- AddParser(propertyParsers, "tariff", info.tariff);
- AddParser(propertyParsers, "group", info.group, GetEncodedValue);
- AddParser(propertyParsers, "note", info.note, GetEncodedValue);
- AddParser(propertyParsers, "email", info.email, GetEncodedValue);
- AddParser(propertyParsers, "name", info.name, GetEncodedValue);
- AddParser(propertyParsers, "address", info.address, GetEncodedValue);
- AddParser(propertyParsers, "phone", info.phone, GetEncodedValue);
- AddParser(propertyParsers, "traff", info.stat);
-
- for (size_t i = 0; i < USERDATA_NUM; ++i)
- AddParser(propertyParsers, "userData" + x2str(i), info.userData[i], GetEncodedValue);
-}
-//-----------------------------------------------------------------------------
-GET_USER::PARSER::~PARSER()
-{
- PROPERTY_PARSERS::iterator it(propertyParsers.begin());
- while (it != propertyParsers.end())
- delete (it++)->second;
-}
-//-----------------------------------------------------------------------------
-int GET_USER::PARSER::ParseStart(const char * el, const char ** attr)
-{
-depth++;
-if (depth == 1)
- ParseUser(el, attr);
-
-if (depth == 2 && parsingAnswer)
- ParseUserParams(el, attr);
-
-return 0;
-}
-//-----------------------------------------------------------------------------
-void GET_USER::PARSER::ParseEnd(const char * /*el*/)
-{
-depth--;
-if (depth == 0 && parsingAnswer)
- {
- if (callback)
- callback(error.empty(), error, info, data);
- error.clear();
- parsingAnswer = false;
- }
-}
-//-----------------------------------------------------------------------------
-void GET_USER::PARSER::ParseUser(const char * el, const char ** attr)
-{
-if (strcasecmp(el, "user") == 0)
- if (attr && attr[0] && attr[1])
- {
- if (strcasecmp(attr[1], "error") == 0)
- {
- if (attr[2] && attr[3])
- error = attr[3];
- else
- error = "User not found.";
- }
- else
- parsingAnswer = true;
- }
- else
- parsingAnswer = true;
-}
-//-----------------------------------------------------------------------------
-void GET_USER::PARSER::ParseUserParams(const char * el, const char ** attr)
-{
-if (!TryParse(propertyParsers, ToLower(el), attr))
- error = "Invalid parameter.";
-}
-//-----------------------------------------------------------------------------
-void GET_USER::PARSER::SetCallback(CALLBACK f, void * d)
-{
-callback = f;
-data = d;
-}
+++ /dev/null
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_USER_H__
-#define __STG_STGLIBS_SRVCONF_PARSER_GET_USER_H__
-
-#include "parser.h"
-#include "property_parsers.h"
-
-#include "stg/servconf_types.h"
-
-#include <string>
-
-namespace STG
-{
-namespace GET_USER
-{
-
-class PARSER: public STG::PARSER
-{
-public:
- PARSER();
- virtual ~PARSER();
- int ParseStart(const char * el, const char ** attr);
- void ParseEnd(const char * el);
- void SetCallback(CALLBACK f, void * data);
-
-private:
- PROPERTY_PARSERS propertyParsers;
- CALLBACK callback;
- void * data;
- INFO info;
- int depth;
- bool parsingAnswer;
- std::string error;
-
- void ParseUser(const char * el, const char ** attr);
- void ParseUserParams(const char * el, const char ** attr);
-};
-
-} // namespace GET_USER
-} // namespace STG
-
-#endif
+++ /dev/null
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#include "parser_get_users.h"
-
-#include <cstddef>
-
-#include <strings.h>
-
-using namespace STG;
-
-GET_USERS::PARSER::PARSER()
- : callback(NULL),
- data(NULL),
- depth(0),
- parsingAnswer(false)
-{
- userParser.SetCallback(&GET_USERS::PARSER::UserCallback, this);
-}
-//-----------------------------------------------------------------------------
-int GET_USERS::PARSER::ParseStart(const char * el, const char ** attr)
-{
-depth++;
-if (depth == 1 && strcasecmp(el, "users") == 0)
- parsingAnswer = true;
-
-if (depth > 1 && parsingAnswer)
- userParser.ParseStart(el, attr);
-
-return 0;
-}
-//-----------------------------------------------------------------------------
-void GET_USERS::PARSER::ParseEnd(const char * el)
-{
-depth--;
-if (depth > 0 && parsingAnswer)
- userParser.ParseEnd(el);
-
-if (depth == 0 && parsingAnswer)
- {
- if (callback)
- callback(error.empty(), error, info, data);
- error.clear();
- info.clear();
- parsingAnswer = false;
- }
-}
-//-----------------------------------------------------------------------------
-void GET_USERS::PARSER::AddUser(const GET_USER::INFO & userInfo)
-{
-info.push_back(userInfo);
-}
-//-----------------------------------------------------------------------------
-void GET_USERS::PARSER::SetCallback(CALLBACK f, void * d)
-{
-callback = f;
-data = d;
-}
-//-----------------------------------------------------------------------------
-void GET_USERS::PARSER::UserCallback(bool result, const std::string & error, const GET_USER::INFO & info, void * data)
-{
- GET_USERS::PARSER * parser = static_cast<GET_USERS::PARSER *>(data);
- if (!result)
- parser->SetError(error);
- else
- parser->AddUser(info);
-}
+++ /dev/null
-
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_USERS_H__
-#define __STG_STGLIBS_SRVCONF_PARSER_GET_USERS_H__
-
-#include "parser.h"
-#include "parser_get_user.h"
-
-#include "stg/servconf_types.h"
-
-#include <string>
-
-namespace STG
-{
-namespace GET_USERS
-{
-
-class PARSER: public STG::PARSER
-{
-public:
- PARSER();
- int ParseStart(const char * el, const char ** attr);
- void ParseEnd(const char * el);
- void SetCallback(CALLBACK f, void * data);
-
-private:
- CALLBACK callback;
- void * data;
- GET_USER::PARSER userParser;
- INFO info;
- int depth;
- bool parsingAnswer;
- std::string error;
-
- void AddUser(const GET_USER::INFO & userInfo);
- void SetError(const std::string & e) { error = e; }
-
- static void UserCallback(bool result, const std::string& reason, const GET_USER::INFO & info, void * data);
-};
-
-} // namespace GET_USERS
-} // namespace STG
-
-#endif
+++ /dev/null
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#include "parser_send_message.h"
-
-#include <cstddef>
-
-#include <strings.h>
-
-using namespace STG;
-
-SEND_MESSAGE::PARSER::PARSER()
- : callback(NULL),
- data(NULL),
- depth(0)
-{
-}
-//-----------------------------------------------------------------------------
-int SEND_MESSAGE::PARSER::ParseStart(const char * el, const char ** attr)
-{
-depth++;
-if (depth == 1)
- if (strcasecmp(el, "SendMessageResult") == 0)
- ParseAnswer(el, attr);
-return 0;
-}
-//-----------------------------------------------------------------------------
-void SEND_MESSAGE::PARSER::ParseEnd(const char * /*el*/)
-{
-depth--;
-}
-//-----------------------------------------------------------------------------
-void SEND_MESSAGE::PARSER::ParseAnswer(const char * /*el*/, const char **attr)
-{
-if (!callback)
- return;
-if (attr && attr[0] && attr[1])
- callback(strcasecmp(attr[1], "ok") == 0, attr[1], data);
-else
- callback(false, "Invalid response.", data);
-}
-//-----------------------------------------------------------------------------
-void SEND_MESSAGE::PARSER::SetCallback(CALLBACK f, void * d)
-{
-callback = f;
-data = d;
-}
+++ /dev/null
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#ifndef __STG_STGLIBS_SRVCONF_PARSER_SEND_MESSAGE_H__
-#define __STG_STGLIBS_SRVCONF_PARSER_SEND_MESSAGE_H__
-
-#include "parser.h"
-
-#include "stg/servconf_types.h"
-
-namespace STG
-{
-namespace SEND_MESSAGE
-{
-
-class PARSER: public STG::PARSER
-{
-public:
- PARSER();
- int ParseStart(const char * el, const char ** attr);
- void ParseEnd(const char * el);
- void SetCallback(CALLBACK f, void * data);
-
-private:
- CALLBACK callback;
- void * data;
- int depth;
-
- void ParseAnswer(const char * el, const char ** attr);
-};
-
-} // namespace SEND_MESSAGE
-} // namespace STG
-
-#endif
+++ /dev/null
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#include "parser_server_info.h"
-
-#include "stg/common.h"
-
-#include <cstdio> // sprintf
-#include <cstddef>
-
-#include <strings.h>
-
-using namespace STG;
-
-namespace
-{
-
-const size_t UNAME_LEN = 256;
-const size_t SERV_VER_LEN = 64;
-const size_t DIRNAME_LEN = 16;
-
-}
-
-SERVER_INFO::PARSER::PARSER()
- : callback(NULL),
- data(NULL),
- depth(0),
- parsingAnswer(false)
-{
- AddParser(propertyParsers, "uname", info.uname);
- AddParser(propertyParsers, "version", info.version);
- AddParser(propertyParsers, "tariff", info.tariffType);
- AddParser(propertyParsers, "dir_num", info.dirNum);
- AddParser(propertyParsers, "users_num", info.usersNum);
- AddParser(propertyParsers, "tariff_num", info.tariffNum);
-
- for (size_t i = 0; i < DIR_NUM; i++)
- AddParser(propertyParsers, "dir_name_" + x2str(i), info.dirName[i], GetEncodedValue);
-}
-//-----------------------------------------------------------------------------
-int SERVER_INFO::PARSER::ParseStart(const char *el, const char **attr)
-{
-depth++;
-if (depth == 1)
- if (strcasecmp(el, "ServerInfo") == 0)
- parsingAnswer = true;
-else
- if (depth == 2 && parsingAnswer)
- if (!TryParse(propertyParsers, ToLower(el), attr))
- error = "Invalid parameter.";
-return 0;
-}
-//-----------------------------------------------------------------------------
-void SERVER_INFO::PARSER::ParseEnd(const char * /*el*/)
-{
-depth--;
-if (depth == 0 && parsingAnswer)
- {
- if (callback)
- callback(error.empty(), error, info, data);
- error.clear();
- parsingAnswer = false;
- }
-}
-//-----------------------------------------------------------------------------
-void SERVER_INFO::PARSER::SetCallback(CALLBACK f, void * d)
-{
-callback = f;
-data = d;
-}
+++ /dev/null
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#ifndef __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__
-#define __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__
-
-#include "parser.h"
-#include "property_parsers.h"
-
-#include "stg/servconf_types.h"
-
-#include <string>
-
-namespace STG
-{
-namespace SERVER_INFO
-{
-
-class PARSER: public STG::PARSER
-{
-public:
- PARSER();
- int ParseStart(const char * el, const char ** attr);
- void ParseEnd(const char * el);
- void SetCallback(CALLBACK f, void * data);
-
-private:
- PROPERTY_PARSERS propertyParsers;
- CALLBACK callback;
- void * data;
- int depth;
- bool parsingAnswer;
- INFO info;
- std::string error;
-};
-
-} // namespace SERVER_INFO
-} // namespace STG
-
-#endif
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#include "parser_auth_by.h"
+
+#include <cstddef>
+
+#include <strings.h> // strcasecmp
+
+using namespace STG;
+
+AUTH_BY::PARSER::PARSER()
+ : callback(NULL),
+ data(NULL),
+ depth(0),
+ parsingAnswer(false)
+{
+}
+//-----------------------------------------------------------------------------
+int AUTH_BY::PARSER::ParseStart(const char *el, const char **attr)
+{
+depth++;
+if (depth == 1)
+ {
+ if (strcasecmp(el, "AuthorizedBy") == 0)
+ if (attr && attr[0] && attr[1])
+ {
+ if (strcasecmp(attr[1], "error") == 0)
+ {
+ if (attr[2] && attr[3])
+ error = attr[3];
+ else
+ error = "User not found.";
+ }
+ else
+ parsingAnswer = true;
+ }
+ }
+else
+ {
+ if (depth == 2)
+ {
+ if (parsingAnswer && strcasecmp(el, "Auth") == 0)
+ {
+ if (attr && attr[0] && attr[1] && strcasecmp(attr[0], "name") == 0)
+ info.push_back(attr[1]);
+ return 0;
+ }
+ }
+ }
+return 0;
+}
+//-----------------------------------------------------------------------------
+void AUTH_BY::PARSER::ParseEnd(const char * /*el*/)
+{
+depth--;
+if (depth == 0)
+ {
+ if (callback)
+ callback(error.empty(), error, info, data);
+ info.clear();
+ error.clear();
+ }
+}
+//-----------------------------------------------------------------------------
+void AUTH_BY::PARSER::SetCallback(CALLBACK f, void * d)
+{
+callback = f;
+data = d;
+}
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__
+
+#include "parser.h"
+
+#include "stg/servconf_types.h"
+
+#include <string>
+
+namespace STG
+{
+namespace AUTH_BY
+{
+
+class PARSER: public STG::PARSER
+{
+public:
+ PARSER();
+ int ParseStart(const char * el, const char ** attr);
+ void ParseEnd(const char * el);
+ void SetCallback(CALLBACK f, void * data);
+
+private:
+ CALLBACK callback;
+ void * data;
+ int depth;
+ bool parsingAnswer;
+ INFO info;
+ std::string error;
+};
+
+} // namespace AUTH_BY
+} // namespace STG
+
+#endif
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PARSER_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_H__
+
+namespace STG
+{
+
+class PARSER
+{
+public:
+ virtual ~PARSER() {}
+ virtual int ParseStart(const char *el, const char **attr) = 0;
+ virtual void ParseEnd(const char *el) = 0;
+};
+
+} // namespace STG
+
+#endif
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#include "parser_check_user.h"
+
+#include <cstddef>
+
+#include <strings.h>
+
+using namespace STG;
+
+CHECK_USER::PARSER::PARSER()
+ : callback(NULL),
+ data(NULL),
+ depth(0)
+{
+}
+//-----------------------------------------------------------------------------
+int CHECK_USER::PARSER::ParseStart(const char * el, const char ** attr)
+{
+depth++;
+if (depth == 1)
+ if (strcasecmp(el, "CheckUser") == 0)
+ ParseAnswer(el, attr);
+return 0;
+}
+//-----------------------------------------------------------------------------
+void CHECK_USER::PARSER::ParseEnd(const char *)
+{
+depth--;
+}
+//-----------------------------------------------------------------------------
+void CHECK_USER::PARSER::ParseAnswer(const char *, const char **attr)
+{
+if (!callback)
+ return;
+if (attr && attr[0] && attr[1] && strcasecmp(attr[0], "value") == 0)
+ callback(strcasecmp(attr[1], "ok") == 0, attr[2] && attr[3] ? attr[3] : "", data);
+else
+ callback(false, "Invalid response.", data);
+}
+//-----------------------------------------------------------------------------
+void CHECK_USER::PARSER::SetCallback(CALLBACK f, void * d)
+{
+callback = f;
+data = d;
+}
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PARSER_CHECK_USER_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_CHECK_USER_H__
+
+#include "parser.h"
+
+#include "stg/servconf_types.h"
+
+namespace STG
+{
+namespace CHECK_USER
+{
+
+class PARSER: public STG::PARSER
+{
+public:
+ PARSER();
+ int ParseStart(const char * el, const char ** attr);
+ void ParseEnd(const char * el);
+ void SetCallback(CALLBACK f, void * data);
+
+private:
+ CALLBACK callback;
+ void * data;
+ int depth;
+
+ void ParseAnswer(const char * el, const char ** attr);
+};
+
+} // namespace CHECK_USER
+} // namespace STG
+
+#endif
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#include "parser_chg_user.h"
+
+#include <cstddef>
+
+#include <strings.h>
+
+using namespace STG;
+
+CHG_USER::PARSER::PARSER()
+ : callback(NULL),
+ data(NULL),
+ depth(0)
+{
+}
+//-----------------------------------------------------------------------------
+int CHG_USER::PARSER::ParseStart(const char *el, const char **attr)
+{
+depth++;
+if (depth == 1)
+ {
+ if (strcasecmp(el, "SetUser") == 0)
+ ParseAnswer(el, attr);
+ else if (strcasecmp(el, "DelUser") == 0)
+ ParseAnswer(el, attr);
+ else if (strcasecmp(el, "AddUser") == 0)
+ ParseAnswer(el, attr);
+ }
+return 0;
+}
+//-----------------------------------------------------------------------------
+void CHG_USER::PARSER::ParseEnd(const char *)
+{
+depth--;
+}
+//-----------------------------------------------------------------------------
+void CHG_USER::PARSER::ParseAnswer(const char * /*el*/, const char ** attr)
+{
+if (!callback)
+ return;
+if (attr && attr[0] && attr[1])
+ callback(strcasecmp(attr[1], "ok") == 0, attr[2] && attr[3] ? attr[3] : "", data);
+else
+ callback(false, "Invalid response.", data);
+}
+//-----------------------------------------------------------------------------
+void CHG_USER::PARSER::SetCallback(CALLBACK f, void * d)
+{
+callback = f;
+data = d;
+}
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PARSER_CHG_USER_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_CHG_USER_H__
+
+#include "parser.h"
+
+#include "stg/servconf_types.h"
+
+namespace STG
+{
+namespace CHG_USER
+{
+
+class PARSER: public STG::PARSER
+{
+public:
+ PARSER();
+ int ParseStart(const char * el, const char ** attr);
+ void ParseEnd(const char * el);
+ void SetCallback(CALLBACK f, void * data);
+
+private:
+ CALLBACK callback;
+ void * data;
+ int depth;
+
+ void ParseAnswer(const char * el, const char ** attr);
+};
+
+} // namespace CHG_USER
+} // namespace STG
+
+#endif
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#include "parser_get_user.h"
+
+#include "stg/common.h"
+
+#include <map>
+#include <utility>
+#include <cstddef>
+
+#include <strings.h>
+
+using namespace STG;
+
+namespace STG
+{
+
+template <>
+bool GetValue<GET_USER::STAT>(const char ** attr, GET_USER::STAT & value)
+{
+if (!attr)
+ return false;
+std::map<std::string, long long *> props;
+for (size_t i = 0; i < DIR_NUM; ++i)
+ {
+ props.insert(std::pair<std::string, long long *>("su" + x2str(i), &value.su[i]));
+ props.insert(std::pair<std::string, long long *>("sd" + x2str(i), &value.sd[i]));
+ props.insert(std::pair<std::string, long long *>("mu" + x2str(i), &value.mu[i]));
+ props.insert(std::pair<std::string, long long *>("md" + x2str(i), &value.md[i]));
+ }
+size_t pos = 0;
+while (attr[pos])
+ {
+ std::string name(ToLower(attr[pos++]));
+ std::map<std::string, long long *>::iterator it(props.find(name));
+ if (it != props.end())
+ if (str2x(attr[pos++], *it->second) < 0)
+ return false;
+ }
+return true;
+}
+
+}
+
+GET_USER::PARSER::PARSER()
+ : callback(NULL),
+ data(NULL),
+ depth(0),
+ parsingAnswer(false)
+{
+ AddParser(propertyParsers, "login", info.login);
+ AddParser(propertyParsers, "password", info.password);
+ AddParser(propertyParsers, "cash", info.cash);
+ AddParser(propertyParsers, "credit", info.credit);
+ AddParser(propertyParsers, "creditExpire", info.creditExpire);
+ AddParser(propertyParsers, "lastCash", info.lastCash);
+ AddParser(propertyParsers, "prepaidTraff", info.prepaidTraff);
+ AddParser(propertyParsers, "down", info.down);
+ AddParser(propertyParsers, "passive", info.passive);
+ AddParser(propertyParsers, "disableDetailStat", info.disableDetailStat);
+ AddParser(propertyParsers, "connected", info.connected);
+ AddParser(propertyParsers, "aonline", info.alwaysOnline);
+ AddParser(propertyParsers, "currIP", info.ip, GetIPValue);
+ AddParser(propertyParsers, "ip", info.ips);
+ AddParser(propertyParsers, "tariff", info.tariff);
+ AddParser(propertyParsers, "group", info.group, GetEncodedValue);
+ AddParser(propertyParsers, "note", info.note, GetEncodedValue);
+ AddParser(propertyParsers, "email", info.email, GetEncodedValue);
+ AddParser(propertyParsers, "name", info.name, GetEncodedValue);
+ AddParser(propertyParsers, "address", info.address, GetEncodedValue);
+ AddParser(propertyParsers, "phone", info.phone, GetEncodedValue);
+ AddParser(propertyParsers, "traff", info.stat);
+
+ for (size_t i = 0; i < USERDATA_NUM; ++i)
+ AddParser(propertyParsers, "userData" + x2str(i), info.userData[i], GetEncodedValue);
+}
+//-----------------------------------------------------------------------------
+GET_USER::PARSER::~PARSER()
+{
+ PROPERTY_PARSERS::iterator it(propertyParsers.begin());
+ while (it != propertyParsers.end())
+ delete (it++)->second;
+}
+//-----------------------------------------------------------------------------
+int GET_USER::PARSER::ParseStart(const char * el, const char ** attr)
+{
+depth++;
+if (depth == 1)
+ ParseUser(el, attr);
+
+if (depth == 2 && parsingAnswer)
+ ParseUserParams(el, attr);
+
+return 0;
+}
+//-----------------------------------------------------------------------------
+void GET_USER::PARSER::ParseEnd(const char * /*el*/)
+{
+depth--;
+if (depth == 0 && parsingAnswer)
+ {
+ if (callback)
+ callback(error.empty(), error, info, data);
+ error.clear();
+ parsingAnswer = false;
+ }
+}
+//-----------------------------------------------------------------------------
+void GET_USER::PARSER::ParseUser(const char * el, const char ** attr)
+{
+if (strcasecmp(el, "user") == 0)
+ if (attr && attr[0] && attr[1])
+ {
+ if (strcasecmp(attr[1], "error") == 0)
+ {
+ if (attr[2] && attr[3])
+ error = attr[3];
+ else
+ error = "User not found.";
+ }
+ else
+ parsingAnswer = true;
+ }
+ else
+ parsingAnswer = true;
+}
+//-----------------------------------------------------------------------------
+void GET_USER::PARSER::ParseUserParams(const char * el, const char ** attr)
+{
+if (!TryParse(propertyParsers, ToLower(el), attr))
+ error = "Invalid parameter.";
+}
+//-----------------------------------------------------------------------------
+void GET_USER::PARSER::SetCallback(CALLBACK f, void * d)
+{
+callback = f;
+data = d;
+}
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_USER_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_GET_USER_H__
+
+#include "parser.h"
+#include "property_parsers.h"
+
+#include "stg/servconf_types.h"
+
+#include <string>
+
+namespace STG
+{
+namespace GET_USER
+{
+
+class PARSER: public STG::PARSER
+{
+public:
+ PARSER();
+ virtual ~PARSER();
+ int ParseStart(const char * el, const char ** attr);
+ void ParseEnd(const char * el);
+ void SetCallback(CALLBACK f, void * data);
+
+private:
+ PROPERTY_PARSERS propertyParsers;
+ CALLBACK callback;
+ void * data;
+ INFO info;
+ int depth;
+ bool parsingAnswer;
+ std::string error;
+
+ void ParseUser(const char * el, const char ** attr);
+ void ParseUserParams(const char * el, const char ** attr);
+};
+
+} // namespace GET_USER
+} // namespace STG
+
+#endif
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#include "parser_get_users.h"
+
+#include <cstddef>
+
+#include <strings.h>
+
+using namespace STG;
+
+GET_USERS::PARSER::PARSER()
+ : callback(NULL),
+ data(NULL),
+ depth(0),
+ parsingAnswer(false)
+{
+ userParser.SetCallback(&GET_USERS::PARSER::UserCallback, this);
+}
+//-----------------------------------------------------------------------------
+int GET_USERS::PARSER::ParseStart(const char * el, const char ** attr)
+{
+depth++;
+if (depth == 1 && strcasecmp(el, "users") == 0)
+ parsingAnswer = true;
+
+if (depth > 1 && parsingAnswer)
+ userParser.ParseStart(el, attr);
+
+return 0;
+}
+//-----------------------------------------------------------------------------
+void GET_USERS::PARSER::ParseEnd(const char * el)
+{
+depth--;
+if (depth > 0 && parsingAnswer)
+ userParser.ParseEnd(el);
+
+if (depth == 0 && parsingAnswer)
+ {
+ if (callback)
+ callback(error.empty(), error, info, data);
+ error.clear();
+ info.clear();
+ parsingAnswer = false;
+ }
+}
+//-----------------------------------------------------------------------------
+void GET_USERS::PARSER::AddUser(const GET_USER::INFO & userInfo)
+{
+info.push_back(userInfo);
+}
+//-----------------------------------------------------------------------------
+void GET_USERS::PARSER::SetCallback(CALLBACK f, void * d)
+{
+callback = f;
+data = d;
+}
+//-----------------------------------------------------------------------------
+void GET_USERS::PARSER::UserCallback(bool result, const std::string & error, const GET_USER::INFO & info, void * data)
+{
+ GET_USERS::PARSER * parser = static_cast<GET_USERS::PARSER *>(data);
+ if (!result)
+ parser->SetError(error);
+ else
+ parser->AddUser(info);
+}
--- /dev/null
+
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_USERS_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_GET_USERS_H__
+
+#include "parser.h"
+#include "parser_get_user.h"
+
+#include "stg/servconf_types.h"
+
+#include <string>
+
+namespace STG
+{
+namespace GET_USERS
+{
+
+class PARSER: public STG::PARSER
+{
+public:
+ PARSER();
+ int ParseStart(const char * el, const char ** attr);
+ void ParseEnd(const char * el);
+ void SetCallback(CALLBACK f, void * data);
+
+private:
+ CALLBACK callback;
+ void * data;
+ GET_USER::PARSER userParser;
+ INFO info;
+ int depth;
+ bool parsingAnswer;
+ std::string error;
+
+ void AddUser(const GET_USER::INFO & userInfo);
+ void SetError(const std::string & e) { error = e; }
+
+ static void UserCallback(bool result, const std::string& reason, const GET_USER::INFO & info, void * data);
+};
+
+} // namespace GET_USERS
+} // namespace STG
+
+#endif
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#include "property_parsers.h"
+
+#include <strings.h>
+
+bool STG::CheckValue(const char ** attr)
+{
+return attr && attr[0] && attr[1] && strcasecmp(attr[0], "value") == 0;
+}
+
+bool STG::GetEncodedValue(const char ** attr, std::string & value)
+{
+if (!CheckValue(attr))
+ return false;
+Decode21str(value, attr[1]);
+return true;
+}
+
+bool STG::GetIPValue(const char ** attr, uint32_t & value)
+{
+if (!CheckValue(attr))
+ return false;
+std::string ip(attr[1]);
+value = inet_strington(attr[1]);
+if (value == 0 && ip != "0.0.0.0")
+ return false;
+return true;
+}
+
+bool STG::TryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr)
+{
+ PROPERTY_PARSERS::iterator it(parsers.find(name));
+ if (it != parsers.end())
+ return it->second->Parse(attr);
+ return true; // Assume that non-existing params are ok.
+}
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PROPERTY_PARSERS_H__
+#define __STG_STGLIBS_SRVCONF_PROPERTY_PARSERS_H__
+
+#include "stg/common.h"
+
+#include <map>
+#include <string>
+
+namespace STG
+{
+
+class BASE_PROPERTY_PARSER
+{
+ public:
+ virtual ~BASE_PROPERTY_PARSER() {}
+ virtual bool Parse(const char ** attr) = 0;
+};
+
+template <typename T>
+class PROPERTY_PARSER : public BASE_PROPERTY_PARSER
+{
+ public:
+ typedef bool (* FUNC)(const char **, T &);
+ PROPERTY_PARSER(T & v, FUNC f) : value(v), func(f) {}
+ virtual bool Parse(const char ** attr) { return func(attr, value); }
+ private:
+ T & value;
+ FUNC func;
+};
+
+typedef std::map<std::string, BASE_PROPERTY_PARSER *> PROPERTY_PARSERS;
+
+bool CheckValue(const char ** attr);
+
+template <typename T>
+inline
+bool GetValue(const char ** attr, T & value)
+{
+if (CheckValue(attr))
+ if (str2x(attr[1], value) < 0)
+ return false;
+return true;
+}
+
+template <>
+inline
+bool GetValue<std::string>(const char ** attr, std::string & value)
+{
+if (!CheckValue(attr))
+ return false;
+value = attr[1];
+return true;
+}
+
+template <>
+inline
+bool GetValue<double>(const char ** attr, double & value)
+{
+if (CheckValue(attr))
+ if (strtodouble2(attr[1], value))
+ return false;
+return true;
+}
+
+bool GetEncodedValue(const char ** attr, std::string & value);
+
+bool GetIPValue(const char ** attr, uint32_t& value);
+
+template <typename T>
+void AddParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, const typename PROPERTY_PARSER<T>::FUNC & func = GetValue<T>);
+
+template <typename T>
+inline
+void AddParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, const typename PROPERTY_PARSER<T>::FUNC & func)
+{
+ parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER<T>(value, func)));
+}
+
+bool TryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr);
+
+} // namespace STG
+
+#endif
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#include "parser_send_message.h"
+
+#include <cstddef>
+
+#include <strings.h>
+
+using namespace STG;
+
+SEND_MESSAGE::PARSER::PARSER()
+ : callback(NULL),
+ data(NULL),
+ depth(0)
+{
+}
+//-----------------------------------------------------------------------------
+int SEND_MESSAGE::PARSER::ParseStart(const char * el, const char ** attr)
+{
+depth++;
+if (depth == 1)
+ if (strcasecmp(el, "SendMessageResult") == 0)
+ ParseAnswer(el, attr);
+return 0;
+}
+//-----------------------------------------------------------------------------
+void SEND_MESSAGE::PARSER::ParseEnd(const char * /*el*/)
+{
+depth--;
+}
+//-----------------------------------------------------------------------------
+void SEND_MESSAGE::PARSER::ParseAnswer(const char * /*el*/, const char **attr)
+{
+if (!callback)
+ return;
+if (attr && attr[0] && attr[1])
+ callback(strcasecmp(attr[1], "ok") == 0, attr[1], data);
+else
+ callback(false, "Invalid response.", data);
+}
+//-----------------------------------------------------------------------------
+void SEND_MESSAGE::PARSER::SetCallback(CALLBACK f, void * d)
+{
+callback = f;
+data = d;
+}
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PARSER_SEND_MESSAGE_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_SEND_MESSAGE_H__
+
+#include "parser.h"
+
+#include "stg/servconf_types.h"
+
+namespace STG
+{
+namespace SEND_MESSAGE
+{
+
+class PARSER: public STG::PARSER
+{
+public:
+ PARSER();
+ int ParseStart(const char * el, const char ** attr);
+ void ParseEnd(const char * el);
+ void SetCallback(CALLBACK f, void * data);
+
+private:
+ CALLBACK callback;
+ void * data;
+ int depth;
+
+ void ParseAnswer(const char * el, const char ** attr);
+};
+
+} // namespace SEND_MESSAGE
+} // namespace STG
+
+#endif
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#include "parser_server_info.h"
+
+#include "stg/common.h"
+
+#include <cstdio> // sprintf
+#include <cstddef>
+
+#include <strings.h>
+
+using namespace STG;
+
+namespace
+{
+
+const size_t UNAME_LEN = 256;
+const size_t SERV_VER_LEN = 64;
+const size_t DIRNAME_LEN = 16;
+
+}
+
+SERVER_INFO::PARSER::PARSER()
+ : callback(NULL),
+ data(NULL),
+ depth(0),
+ parsingAnswer(false)
+{
+ AddParser(propertyParsers, "uname", info.uname);
+ AddParser(propertyParsers, "version", info.version);
+ AddParser(propertyParsers, "tariff", info.tariffType);
+ AddParser(propertyParsers, "dir_num", info.dirNum);
+ AddParser(propertyParsers, "users_num", info.usersNum);
+ AddParser(propertyParsers, "tariff_num", info.tariffNum);
+
+ for (size_t i = 0; i < DIR_NUM; i++)
+ AddParser(propertyParsers, "dir_name_" + x2str(i), info.dirName[i], GetEncodedValue);
+}
+//-----------------------------------------------------------------------------
+int SERVER_INFO::PARSER::ParseStart(const char *el, const char **attr)
+{
+depth++;
+if (depth == 1)
+ if (strcasecmp(el, "ServerInfo") == 0)
+ parsingAnswer = true;
+else
+ if (depth == 2 && parsingAnswer)
+ if (!TryParse(propertyParsers, ToLower(el), attr))
+ error = "Invalid parameter.";
+return 0;
+}
+//-----------------------------------------------------------------------------
+void SERVER_INFO::PARSER::ParseEnd(const char * /*el*/)
+{
+depth--;
+if (depth == 0 && parsingAnswer)
+ {
+ if (callback)
+ callback(error.empty(), error, info, data);
+ error.clear();
+ parsingAnswer = false;
+ }
+}
+//-----------------------------------------------------------------------------
+void SERVER_INFO::PARSER::SetCallback(CALLBACK f, void * d)
+{
+callback = f;
+data = d;
+}
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__
+
+#include "parser.h"
+#include "property_parsers.h"
+
+#include "stg/servconf_types.h"
+
+#include <string>
+
+namespace STG
+{
+namespace SERVER_INFO
+{
+
+class PARSER: public STG::PARSER
+{
+public:
+ PARSER();
+ int ParseStart(const char * el, const char ** attr);
+ void ParseEnd(const char * el);
+ void SetCallback(CALLBACK f, void * data);
+
+private:
+ PROPERTY_PARSERS propertyParsers;
+ CALLBACK callback;
+ void * data;
+ int depth;
+ bool parsingAnswer;
+ INFO info;
+ std::string error;
+};
+
+} // namespace SERVER_INFO
+} // namespace STG
+
+#endif
+++ /dev/null
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#include "property_parsers.h"
-
-#include <strings.h>
-
-bool STG::CheckValue(const char ** attr)
-{
-return attr && attr[0] && attr[1] && strcasecmp(attr[0], "value") == 0;
-}
-
-bool STG::GetEncodedValue(const char ** attr, std::string & value)
-{
-if (!CheckValue(attr))
- return false;
-Decode21str(value, attr[1]);
-return true;
-}
-
-bool STG::GetIPValue(const char ** attr, uint32_t & value)
-{
-if (!CheckValue(attr))
- return false;
-std::string ip(attr[1]);
-value = inet_strington(attr[1]);
-if (value == 0 && ip != "0.0.0.0")
- return false;
-return true;
-}
-
-bool STG::TryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr)
-{
- PROPERTY_PARSERS::iterator it(parsers.find(name));
- if (it != parsers.end())
- return it->second->Parse(attr);
- return true; // Assume that non-existing params are ok.
-}
+++ /dev/null
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#ifndef __STG_STGLIBS_SRVCONF_PROPERTY_PARSERS_H__
-#define __STG_STGLIBS_SRVCONF_PROPERTY_PARSERS_H__
-
-#include "stg/common.h"
-
-#include <map>
-#include <string>
-
-namespace STG
-{
-
-class BASE_PROPERTY_PARSER
-{
- public:
- virtual ~BASE_PROPERTY_PARSER() {}
- virtual bool Parse(const char ** attr) = 0;
-};
-
-template <typename T>
-class PROPERTY_PARSER : public BASE_PROPERTY_PARSER
-{
- public:
- typedef bool (* FUNC)(const char **, T &);
- PROPERTY_PARSER(T & v, FUNC f) : value(v), func(f) {}
- virtual bool Parse(const char ** attr) { return func(attr, value); }
- private:
- T & value;
- FUNC func;
-};
-
-typedef std::map<std::string, BASE_PROPERTY_PARSER *> PROPERTY_PARSERS;
-
-bool CheckValue(const char ** attr);
-
-template <typename T>
-inline
-bool GetValue(const char ** attr, T & value)
-{
-if (CheckValue(attr))
- if (str2x(attr[1], value) < 0)
- return false;
-return true;
-}
-
-template <>
-inline
-bool GetValue<std::string>(const char ** attr, std::string & value)
-{
-if (!CheckValue(attr))
- return false;
-value = attr[1];
-return true;
-}
-
-template <>
-inline
-bool GetValue<double>(const char ** attr, double & value)
-{
-if (CheckValue(attr))
- if (strtodouble2(attr[1], value))
- return false;
-return true;
-}
-
-bool GetEncodedValue(const char ** attr, std::string & value);
-
-bool GetIPValue(const char ** attr, uint32_t& value);
-
-template <typename T>
-void AddParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, const typename PROPERTY_PARSER<T>::FUNC & func = GetValue<T>);
-
-template <typename T>
-inline
-void AddParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, const typename PROPERTY_PARSER<T>::FUNC & func)
-{
- parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER<T>(value, func)));
-}
-
-bool TryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr);
-
-} // namespace STG
-
-#endif